xref: /linux/sound/pci/asihpi/hpifunc.c (revision 5a498ef1732ee3cc19b319bf7edcf428c5fad6fd)
1719f82d3SEliot Blennerhassett 
2719f82d3SEliot Blennerhassett #include "hpi_internal.h"
3719f82d3SEliot Blennerhassett #include "hpimsginit.h"
4719f82d3SEliot Blennerhassett 
5719f82d3SEliot Blennerhassett #include "hpidebug.h"
6719f82d3SEliot Blennerhassett 
7719f82d3SEliot Blennerhassett struct hpi_handle {
8719f82d3SEliot Blennerhassett 	unsigned int obj_index:12;
9719f82d3SEliot Blennerhassett 	unsigned int obj_type:4;
10719f82d3SEliot Blennerhassett 	unsigned int adapter_index:14;
11719f82d3SEliot Blennerhassett 	unsigned int spare:1;
12719f82d3SEliot Blennerhassett 	unsigned int read_only:1;
13719f82d3SEliot Blennerhassett };
14719f82d3SEliot Blennerhassett 
15719f82d3SEliot Blennerhassett union handle_word {
16719f82d3SEliot Blennerhassett 	struct hpi_handle h;
17719f82d3SEliot Blennerhassett 	u32 w;
18719f82d3SEliot Blennerhassett };
19719f82d3SEliot Blennerhassett 
20719f82d3SEliot Blennerhassett u32 hpi_indexes_to_handle(const char c_object, const u16 adapter_index,
21719f82d3SEliot Blennerhassett 	const u16 object_index)
22719f82d3SEliot Blennerhassett {
23719f82d3SEliot Blennerhassett 	union handle_word handle;
24719f82d3SEliot Blennerhassett 
25719f82d3SEliot Blennerhassett 	handle.h.adapter_index = adapter_index;
26719f82d3SEliot Blennerhassett 	handle.h.spare = 0;
27719f82d3SEliot Blennerhassett 	handle.h.read_only = 0;
28719f82d3SEliot Blennerhassett 	handle.h.obj_type = c_object;
29719f82d3SEliot Blennerhassett 	handle.h.obj_index = object_index;
30719f82d3SEliot Blennerhassett 	return handle.w;
31719f82d3SEliot Blennerhassett }
32719f82d3SEliot Blennerhassett 
33719f82d3SEliot Blennerhassett void hpi_handle_to_indexes(const u32 handle, u16 *pw_adapter_index,
34719f82d3SEliot Blennerhassett 	u16 *pw_object_index)
35719f82d3SEliot Blennerhassett {
36719f82d3SEliot Blennerhassett 	union handle_word uhandle;
37719f82d3SEliot Blennerhassett 	uhandle.w = handle;
38719f82d3SEliot Blennerhassett 
39719f82d3SEliot Blennerhassett 	if (pw_adapter_index)
40719f82d3SEliot Blennerhassett 		*pw_adapter_index = (u16)uhandle.h.adapter_index;
41719f82d3SEliot Blennerhassett 	if (pw_object_index)
42719f82d3SEliot Blennerhassett 		*pw_object_index = (u16)uhandle.h.obj_index;
43719f82d3SEliot Blennerhassett }
44719f82d3SEliot Blennerhassett 
45719f82d3SEliot Blennerhassett char hpi_handle_object(const u32 handle)
46719f82d3SEliot Blennerhassett {
47719f82d3SEliot Blennerhassett 	union handle_word uhandle;
48719f82d3SEliot Blennerhassett 	uhandle.w = handle;
49719f82d3SEliot Blennerhassett 	return (char)uhandle.h.obj_type;
50719f82d3SEliot Blennerhassett }
51719f82d3SEliot Blennerhassett 
52719f82d3SEliot Blennerhassett #define u32TOINDEX(h, i1) \
53719f82d3SEliot Blennerhassett do {\
54719f82d3SEliot Blennerhassett 	if (h == 0) \
55719f82d3SEliot Blennerhassett 		return HPI_ERROR_INVALID_OBJ; \
56719f82d3SEliot Blennerhassett 	else \
57719f82d3SEliot Blennerhassett 		hpi_handle_to_indexes(h, i1, NULL); \
58719f82d3SEliot Blennerhassett } while (0)
59719f82d3SEliot Blennerhassett 
60719f82d3SEliot Blennerhassett #define u32TOINDEXES(h, i1, i2) \
61719f82d3SEliot Blennerhassett do {\
62719f82d3SEliot Blennerhassett 	if (h == 0) \
63719f82d3SEliot Blennerhassett 		return HPI_ERROR_INVALID_OBJ; \
64719f82d3SEliot Blennerhassett 	else \
65719f82d3SEliot Blennerhassett 		hpi_handle_to_indexes(h, i1, i2);\
66719f82d3SEliot Blennerhassett } while (0)
67719f82d3SEliot Blennerhassett 
68719f82d3SEliot Blennerhassett void hpi_format_to_msg(struct hpi_msg_format *pMF,
69719f82d3SEliot Blennerhassett 	const struct hpi_format *pF)
70719f82d3SEliot Blennerhassett {
71719f82d3SEliot Blennerhassett 	pMF->sample_rate = pF->sample_rate;
72719f82d3SEliot Blennerhassett 	pMF->bit_rate = pF->bit_rate;
73719f82d3SEliot Blennerhassett 	pMF->attributes = pF->attributes;
74719f82d3SEliot Blennerhassett 	pMF->channels = pF->channels;
75719f82d3SEliot Blennerhassett 	pMF->format = pF->format;
76719f82d3SEliot Blennerhassett }
77719f82d3SEliot Blennerhassett 
78719f82d3SEliot Blennerhassett static void hpi_msg_to_format(struct hpi_format *pF,
79719f82d3SEliot Blennerhassett 	struct hpi_msg_format *pMF)
80719f82d3SEliot Blennerhassett {
81719f82d3SEliot Blennerhassett 	pF->sample_rate = pMF->sample_rate;
82719f82d3SEliot Blennerhassett 	pF->bit_rate = pMF->bit_rate;
83719f82d3SEliot Blennerhassett 	pF->attributes = pMF->attributes;
84719f82d3SEliot Blennerhassett 	pF->channels = pMF->channels;
85719f82d3SEliot Blennerhassett 	pF->format = pMF->format;
86719f82d3SEliot Blennerhassett 	pF->mode_legacy = 0;
87719f82d3SEliot Blennerhassett 	pF->unused = 0;
88719f82d3SEliot Blennerhassett }
89719f82d3SEliot Blennerhassett 
90719f82d3SEliot Blennerhassett void hpi_stream_response_to_legacy(struct hpi_stream_res *pSR)
91719f82d3SEliot Blennerhassett {
92719f82d3SEliot Blennerhassett 	pSR->u.legacy_stream_info.auxiliary_data_available =
93719f82d3SEliot Blennerhassett 		pSR->u.stream_info.auxiliary_data_available;
94719f82d3SEliot Blennerhassett 	pSR->u.legacy_stream_info.state = pSR->u.stream_info.state;
95719f82d3SEliot Blennerhassett }
96719f82d3SEliot Blennerhassett 
97719f82d3SEliot Blennerhassett static struct hpi_hsubsys gh_subsys;
98719f82d3SEliot Blennerhassett 
99719f82d3SEliot Blennerhassett struct hpi_hsubsys *hpi_subsys_create(void
100719f82d3SEliot Blennerhassett 	)
101719f82d3SEliot Blennerhassett {
102719f82d3SEliot Blennerhassett 	struct hpi_message hm;
103719f82d3SEliot Blennerhassett 	struct hpi_response hr;
104719f82d3SEliot Blennerhassett 
105719f82d3SEliot Blennerhassett 	memset(&gh_subsys, 0, sizeof(struct hpi_hsubsys));
106719f82d3SEliot Blennerhassett 
107719f82d3SEliot Blennerhassett 	{
108719f82d3SEliot Blennerhassett 		hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
109719f82d3SEliot Blennerhassett 			HPI_SUBSYS_OPEN);
110719f82d3SEliot Blennerhassett 		hpi_send_recv(&hm, &hr);
111719f82d3SEliot Blennerhassett 
112719f82d3SEliot Blennerhassett 		if (hr.error == 0)
113719f82d3SEliot Blennerhassett 			return &gh_subsys;
114719f82d3SEliot Blennerhassett 
115719f82d3SEliot Blennerhassett 	}
116719f82d3SEliot Blennerhassett 	return NULL;
117719f82d3SEliot Blennerhassett }
118719f82d3SEliot Blennerhassett 
119719f82d3SEliot Blennerhassett void hpi_subsys_free(const struct hpi_hsubsys *ph_subsys)
120719f82d3SEliot Blennerhassett {
121719f82d3SEliot Blennerhassett 	struct hpi_message hm;
122719f82d3SEliot Blennerhassett 	struct hpi_response hr;
123719f82d3SEliot Blennerhassett 
124719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
125719f82d3SEliot Blennerhassett 		HPI_SUBSYS_CLOSE);
126719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
127719f82d3SEliot Blennerhassett 
128719f82d3SEliot Blennerhassett }
129719f82d3SEliot Blennerhassett 
130719f82d3SEliot Blennerhassett u16 hpi_subsys_get_version(const struct hpi_hsubsys *ph_subsys, u32 *pversion)
131719f82d3SEliot Blennerhassett {
132719f82d3SEliot Blennerhassett 	struct hpi_message hm;
133719f82d3SEliot Blennerhassett 	struct hpi_response hr;
134719f82d3SEliot Blennerhassett 
135719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
136719f82d3SEliot Blennerhassett 		HPI_SUBSYS_GET_VERSION);
137719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
138719f82d3SEliot Blennerhassett 	*pversion = hr.u.s.version;
139719f82d3SEliot Blennerhassett 	return hr.error;
140719f82d3SEliot Blennerhassett }
141719f82d3SEliot Blennerhassett 
142719f82d3SEliot Blennerhassett u16 hpi_subsys_get_version_ex(const struct hpi_hsubsys *ph_subsys,
143719f82d3SEliot Blennerhassett 	u32 *pversion_ex)
144719f82d3SEliot Blennerhassett {
145719f82d3SEliot Blennerhassett 	struct hpi_message hm;
146719f82d3SEliot Blennerhassett 	struct hpi_response hr;
147719f82d3SEliot Blennerhassett 
148719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
149719f82d3SEliot Blennerhassett 		HPI_SUBSYS_GET_VERSION);
150719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
151719f82d3SEliot Blennerhassett 	*pversion_ex = hr.u.s.data;
152719f82d3SEliot Blennerhassett 	return hr.error;
153719f82d3SEliot Blennerhassett }
154719f82d3SEliot Blennerhassett 
155719f82d3SEliot Blennerhassett u16 hpi_subsys_get_info(const struct hpi_hsubsys *ph_subsys, u32 *pversion,
156719f82d3SEliot Blennerhassett 	u16 *pw_num_adapters, u16 aw_adapter_list[], u16 list_length)
157719f82d3SEliot Blennerhassett {
158719f82d3SEliot Blennerhassett 	struct hpi_message hm;
159719f82d3SEliot Blennerhassett 	struct hpi_response hr;
160719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
161719f82d3SEliot Blennerhassett 		HPI_SUBSYS_GET_INFO);
162719f82d3SEliot Blennerhassett 
163719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
164719f82d3SEliot Blennerhassett 
165719f82d3SEliot Blennerhassett 	*pversion = hr.u.s.version;
166719f82d3SEliot Blennerhassett 	if (list_length > HPI_MAX_ADAPTERS)
167719f82d3SEliot Blennerhassett 		memcpy(aw_adapter_list, &hr.u.s.aw_adapter_list,
168719f82d3SEliot Blennerhassett 			HPI_MAX_ADAPTERS);
169719f82d3SEliot Blennerhassett 	else
170719f82d3SEliot Blennerhassett 		memcpy(aw_adapter_list, &hr.u.s.aw_adapter_list, list_length);
171719f82d3SEliot Blennerhassett 	*pw_num_adapters = hr.u.s.num_adapters;
172719f82d3SEliot Blennerhassett 	return hr.error;
173719f82d3SEliot Blennerhassett }
174719f82d3SEliot Blennerhassett 
175719f82d3SEliot Blennerhassett u16 hpi_subsys_find_adapters(const struct hpi_hsubsys *ph_subsys,
176719f82d3SEliot Blennerhassett 	u16 *pw_num_adapters, u16 aw_adapter_list[], u16 list_length)
177719f82d3SEliot Blennerhassett {
178719f82d3SEliot Blennerhassett 	struct hpi_message hm;
179719f82d3SEliot Blennerhassett 	struct hpi_response hr;
180719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
181719f82d3SEliot Blennerhassett 		HPI_SUBSYS_FIND_ADAPTERS);
182719f82d3SEliot Blennerhassett 
183719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
184719f82d3SEliot Blennerhassett 
185719f82d3SEliot Blennerhassett 	if (list_length > HPI_MAX_ADAPTERS) {
186719f82d3SEliot Blennerhassett 		memcpy(aw_adapter_list, &hr.u.s.aw_adapter_list,
187719f82d3SEliot Blennerhassett 			HPI_MAX_ADAPTERS * sizeof(u16));
188719f82d3SEliot Blennerhassett 		memset(&aw_adapter_list[HPI_MAX_ADAPTERS], 0,
189719f82d3SEliot Blennerhassett 			(list_length - HPI_MAX_ADAPTERS) * sizeof(u16));
190719f82d3SEliot Blennerhassett 	} else
191719f82d3SEliot Blennerhassett 		memcpy(aw_adapter_list, &hr.u.s.aw_adapter_list,
192719f82d3SEliot Blennerhassett 			list_length * sizeof(u16));
193719f82d3SEliot Blennerhassett 	*pw_num_adapters = hr.u.s.num_adapters;
194719f82d3SEliot Blennerhassett 
195719f82d3SEliot Blennerhassett 	return hr.error;
196719f82d3SEliot Blennerhassett }
197719f82d3SEliot Blennerhassett 
198719f82d3SEliot Blennerhassett u16 hpi_subsys_create_adapter(const struct hpi_hsubsys *ph_subsys,
199719f82d3SEliot Blennerhassett 	const struct hpi_resource *p_resource, u16 *pw_adapter_index)
200719f82d3SEliot Blennerhassett {
201719f82d3SEliot Blennerhassett 	struct hpi_message hm;
202719f82d3SEliot Blennerhassett 	struct hpi_response hr;
203719f82d3SEliot Blennerhassett 
204719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
205719f82d3SEliot Blennerhassett 		HPI_SUBSYS_CREATE_ADAPTER);
206719f82d3SEliot Blennerhassett 	hm.u.s.resource = *p_resource;
207719f82d3SEliot Blennerhassett 
208719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
209719f82d3SEliot Blennerhassett 
210719f82d3SEliot Blennerhassett 	*pw_adapter_index = hr.u.s.adapter_index;
211719f82d3SEliot Blennerhassett 	return hr.error;
212719f82d3SEliot Blennerhassett }
213719f82d3SEliot Blennerhassett 
214719f82d3SEliot Blennerhassett u16 hpi_subsys_delete_adapter(const struct hpi_hsubsys *ph_subsys,
215719f82d3SEliot Blennerhassett 	u16 adapter_index)
216719f82d3SEliot Blennerhassett {
217719f82d3SEliot Blennerhassett 	struct hpi_message hm;
218719f82d3SEliot Blennerhassett 	struct hpi_response hr;
219719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
220719f82d3SEliot Blennerhassett 		HPI_SUBSYS_DELETE_ADAPTER);
221719f82d3SEliot Blennerhassett 	hm.adapter_index = adapter_index;
222719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
223719f82d3SEliot Blennerhassett 	return hr.error;
224719f82d3SEliot Blennerhassett }
225719f82d3SEliot Blennerhassett 
226719f82d3SEliot Blennerhassett u16 hpi_subsys_get_num_adapters(const struct hpi_hsubsys *ph_subsys,
227719f82d3SEliot Blennerhassett 	int *pn_num_adapters)
228719f82d3SEliot Blennerhassett {
229719f82d3SEliot Blennerhassett 	struct hpi_message hm;
230719f82d3SEliot Blennerhassett 	struct hpi_response hr;
231719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
232719f82d3SEliot Blennerhassett 		HPI_SUBSYS_GET_NUM_ADAPTERS);
233719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
234719f82d3SEliot Blennerhassett 	*pn_num_adapters = (int)hr.u.s.num_adapters;
235719f82d3SEliot Blennerhassett 	return hr.error;
236719f82d3SEliot Blennerhassett }
237719f82d3SEliot Blennerhassett 
238719f82d3SEliot Blennerhassett u16 hpi_subsys_get_adapter(const struct hpi_hsubsys *ph_subsys, int iterator,
239719f82d3SEliot Blennerhassett 	u32 *padapter_index, u16 *pw_adapter_type)
240719f82d3SEliot Blennerhassett {
241719f82d3SEliot Blennerhassett 	struct hpi_message hm;
242719f82d3SEliot Blennerhassett 	struct hpi_response hr;
243719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
244719f82d3SEliot Blennerhassett 		HPI_SUBSYS_GET_ADAPTER);
245719f82d3SEliot Blennerhassett 	hm.adapter_index = (u16)iterator;
246719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
247719f82d3SEliot Blennerhassett 	*padapter_index = (int)hr.u.s.adapter_index;
248719f82d3SEliot Blennerhassett 	*pw_adapter_type = hr.u.s.aw_adapter_list[0];
249719f82d3SEliot Blennerhassett 	return hr.error;
250719f82d3SEliot Blennerhassett }
251719f82d3SEliot Blennerhassett 
252719f82d3SEliot Blennerhassett u16 hpi_subsys_set_host_network_interface(const struct hpi_hsubsys *ph_subsys,
253719f82d3SEliot Blennerhassett 	const char *sz_interface)
254719f82d3SEliot Blennerhassett {
255719f82d3SEliot Blennerhassett 	struct hpi_message hm;
256719f82d3SEliot Blennerhassett 	struct hpi_response hr;
257719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
258719f82d3SEliot Blennerhassett 		HPI_SUBSYS_SET_NETWORK_INTERFACE);
259719f82d3SEliot Blennerhassett 	if (sz_interface == NULL)
260719f82d3SEliot Blennerhassett 		return HPI_ERROR_INVALID_RESOURCE;
261719f82d3SEliot Blennerhassett 	hm.u.s.resource.r.net_if = sz_interface;
262719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
263719f82d3SEliot Blennerhassett 	return hr.error;
264719f82d3SEliot Blennerhassett }
265719f82d3SEliot Blennerhassett 
266719f82d3SEliot Blennerhassett u16 hpi_adapter_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index)
267719f82d3SEliot Blennerhassett {
268719f82d3SEliot Blennerhassett 	struct hpi_message hm;
269719f82d3SEliot Blennerhassett 	struct hpi_response hr;
270719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
271719f82d3SEliot Blennerhassett 		HPI_ADAPTER_OPEN);
272719f82d3SEliot Blennerhassett 	hm.adapter_index = adapter_index;
273719f82d3SEliot Blennerhassett 
274719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
275719f82d3SEliot Blennerhassett 
276719f82d3SEliot Blennerhassett 	return hr.error;
277719f82d3SEliot Blennerhassett 
278719f82d3SEliot Blennerhassett }
279719f82d3SEliot Blennerhassett 
280719f82d3SEliot Blennerhassett u16 hpi_adapter_close(const struct hpi_hsubsys *ph_subsys, u16 adapter_index)
281719f82d3SEliot Blennerhassett {
282719f82d3SEliot Blennerhassett 	struct hpi_message hm;
283719f82d3SEliot Blennerhassett 	struct hpi_response hr;
284719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
285719f82d3SEliot Blennerhassett 		HPI_ADAPTER_CLOSE);
286719f82d3SEliot Blennerhassett 	hm.adapter_index = adapter_index;
287719f82d3SEliot Blennerhassett 
288719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
289719f82d3SEliot Blennerhassett 
290719f82d3SEliot Blennerhassett 	return hr.error;
291719f82d3SEliot Blennerhassett }
292719f82d3SEliot Blennerhassett 
293719f82d3SEliot Blennerhassett u16 hpi_adapter_set_mode(const struct hpi_hsubsys *ph_subsys,
294719f82d3SEliot Blennerhassett 	u16 adapter_index, u32 adapter_mode)
295719f82d3SEliot Blennerhassett {
296719f82d3SEliot Blennerhassett 	return hpi_adapter_set_mode_ex(ph_subsys, adapter_index, adapter_mode,
297719f82d3SEliot Blennerhassett 		HPI_ADAPTER_MODE_SET);
298719f82d3SEliot Blennerhassett }
299719f82d3SEliot Blennerhassett 
300719f82d3SEliot Blennerhassett u16 hpi_adapter_set_mode_ex(const struct hpi_hsubsys *ph_subsys,
301719f82d3SEliot Blennerhassett 	u16 adapter_index, u32 adapter_mode, u16 query_or_set)
302719f82d3SEliot Blennerhassett {
303719f82d3SEliot Blennerhassett 	struct hpi_message hm;
304719f82d3SEliot Blennerhassett 	struct hpi_response hr;
305719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
306719f82d3SEliot Blennerhassett 		HPI_ADAPTER_SET_MODE);
307719f82d3SEliot Blennerhassett 	hm.adapter_index = adapter_index;
308719f82d3SEliot Blennerhassett 	hm.u.a.adapter_mode = adapter_mode;
309719f82d3SEliot Blennerhassett 	hm.u.a.assert_id = query_or_set;
310719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
311719f82d3SEliot Blennerhassett 	return hr.error;
312719f82d3SEliot Blennerhassett }
313719f82d3SEliot Blennerhassett 
314719f82d3SEliot Blennerhassett u16 hpi_adapter_get_mode(const struct hpi_hsubsys *ph_subsys,
315719f82d3SEliot Blennerhassett 	u16 adapter_index, u32 *padapter_mode)
316719f82d3SEliot Blennerhassett {
317719f82d3SEliot Blennerhassett 	struct hpi_message hm;
318719f82d3SEliot Blennerhassett 	struct hpi_response hr;
319719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
320719f82d3SEliot Blennerhassett 		HPI_ADAPTER_GET_MODE);
321719f82d3SEliot Blennerhassett 	hm.adapter_index = adapter_index;
322719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
323719f82d3SEliot Blennerhassett 	if (padapter_mode)
324719f82d3SEliot Blennerhassett 		*padapter_mode = hr.u.a.serial_number;
325719f82d3SEliot Blennerhassett 	return hr.error;
326719f82d3SEliot Blennerhassett }
327719f82d3SEliot Blennerhassett 
328719f82d3SEliot Blennerhassett u16 hpi_adapter_get_info(const struct hpi_hsubsys *ph_subsys,
329719f82d3SEliot Blennerhassett 	u16 adapter_index, u16 *pw_num_outstreams, u16 *pw_num_instreams,
330719f82d3SEliot Blennerhassett 	u16 *pw_version, u32 *pserial_number, u16 *pw_adapter_type)
331719f82d3SEliot Blennerhassett {
332719f82d3SEliot Blennerhassett 	struct hpi_message hm;
333719f82d3SEliot Blennerhassett 	struct hpi_response hr;
334719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
335719f82d3SEliot Blennerhassett 		HPI_ADAPTER_GET_INFO);
336719f82d3SEliot Blennerhassett 	hm.adapter_index = adapter_index;
337719f82d3SEliot Blennerhassett 
338719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
339719f82d3SEliot Blennerhassett 
340719f82d3SEliot Blennerhassett 	*pw_adapter_type = hr.u.a.adapter_type;
341719f82d3SEliot Blennerhassett 	*pw_num_outstreams = hr.u.a.num_outstreams;
342719f82d3SEliot Blennerhassett 	*pw_num_instreams = hr.u.a.num_instreams;
343719f82d3SEliot Blennerhassett 	*pw_version = hr.u.a.version;
344719f82d3SEliot Blennerhassett 	*pserial_number = hr.u.a.serial_number;
345719f82d3SEliot Blennerhassett 	return hr.error;
346719f82d3SEliot Blennerhassett }
347719f82d3SEliot Blennerhassett 
348719f82d3SEliot Blennerhassett u16 hpi_adapter_get_module_by_index(const struct hpi_hsubsys *ph_subsys,
349719f82d3SEliot Blennerhassett 	u16 adapter_index, u16 module_index, u16 *pw_num_outputs,
350719f82d3SEliot Blennerhassett 	u16 *pw_num_inputs, u16 *pw_version, u32 *pserial_number,
351719f82d3SEliot Blennerhassett 	u16 *pw_module_type, u32 *ph_module)
352719f82d3SEliot Blennerhassett {
353719f82d3SEliot Blennerhassett 	struct hpi_message hm;
354719f82d3SEliot Blennerhassett 	struct hpi_response hr;
355719f82d3SEliot Blennerhassett 
356719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
357719f82d3SEliot Blennerhassett 		HPI_ADAPTER_MODULE_INFO);
358719f82d3SEliot Blennerhassett 	hm.adapter_index = adapter_index;
359719f82d3SEliot Blennerhassett 	hm.u.ax.module_info.index = module_index;
360719f82d3SEliot Blennerhassett 
361719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
362719f82d3SEliot Blennerhassett 
363719f82d3SEliot Blennerhassett 	*pw_module_type = hr.u.a.adapter_type;
364719f82d3SEliot Blennerhassett 	*pw_num_outputs = hr.u.a.num_outstreams;
365719f82d3SEliot Blennerhassett 	*pw_num_inputs = hr.u.a.num_instreams;
366719f82d3SEliot Blennerhassett 	*pw_version = hr.u.a.version;
367719f82d3SEliot Blennerhassett 	*pserial_number = hr.u.a.serial_number;
368719f82d3SEliot Blennerhassett 	*ph_module = 0;
369719f82d3SEliot Blennerhassett 
370719f82d3SEliot Blennerhassett 	return hr.error;
371719f82d3SEliot Blennerhassett }
372719f82d3SEliot Blennerhassett 
373719f82d3SEliot Blennerhassett u16 hpi_adapter_get_assert(const struct hpi_hsubsys *ph_subsys,
374719f82d3SEliot Blennerhassett 	u16 adapter_index, u16 *assert_present, char *psz_assert,
375719f82d3SEliot Blennerhassett 	u16 *pw_line_number)
376719f82d3SEliot Blennerhassett {
377719f82d3SEliot Blennerhassett 	struct hpi_message hm;
378719f82d3SEliot Blennerhassett 	struct hpi_response hr;
379719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
380719f82d3SEliot Blennerhassett 		HPI_ADAPTER_GET_ASSERT);
381719f82d3SEliot Blennerhassett 	hm.adapter_index = adapter_index;
382719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
383719f82d3SEliot Blennerhassett 
384719f82d3SEliot Blennerhassett 	*assert_present = 0;
385719f82d3SEliot Blennerhassett 
386719f82d3SEliot Blennerhassett 	if (!hr.error) {
387719f82d3SEliot Blennerhassett 
388719f82d3SEliot Blennerhassett 		*pw_line_number = (u16)hr.u.a.serial_number;
389719f82d3SEliot Blennerhassett 		if (*pw_line_number) {
390719f82d3SEliot Blennerhassett 
391719f82d3SEliot Blennerhassett 			int i;
392719f82d3SEliot Blennerhassett 			char *src = (char *)hr.u.a.sz_adapter_assert;
393719f82d3SEliot Blennerhassett 			char *dst = psz_assert;
394719f82d3SEliot Blennerhassett 
395719f82d3SEliot Blennerhassett 			*assert_present = 1;
396719f82d3SEliot Blennerhassett 
397719f82d3SEliot Blennerhassett 			for (i = 0; i < HPI_STRING_LEN; i++) {
398719f82d3SEliot Blennerhassett 				char c;
399719f82d3SEliot Blennerhassett 				c = *src++;
400719f82d3SEliot Blennerhassett 				*dst++ = c;
401719f82d3SEliot Blennerhassett 				if (c == 0)
402719f82d3SEliot Blennerhassett 					break;
403719f82d3SEliot Blennerhassett 			}
404719f82d3SEliot Blennerhassett 
405719f82d3SEliot Blennerhassett 		}
406719f82d3SEliot Blennerhassett 	}
407719f82d3SEliot Blennerhassett 	return hr.error;
408719f82d3SEliot Blennerhassett }
409719f82d3SEliot Blennerhassett 
410719f82d3SEliot Blennerhassett u16 hpi_adapter_get_assert_ex(const struct hpi_hsubsys *ph_subsys,
411719f82d3SEliot Blennerhassett 	u16 adapter_index, u16 *assert_present, char *psz_assert,
412719f82d3SEliot Blennerhassett 	u32 *pline_number, u16 *pw_assert_on_dsp)
413719f82d3SEliot Blennerhassett {
414719f82d3SEliot Blennerhassett 	struct hpi_message hm;
415719f82d3SEliot Blennerhassett 	struct hpi_response hr;
416719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
417719f82d3SEliot Blennerhassett 		HPI_ADAPTER_GET_ASSERT);
418719f82d3SEliot Blennerhassett 	hm.adapter_index = adapter_index;
419719f82d3SEliot Blennerhassett 
420719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
421719f82d3SEliot Blennerhassett 
422719f82d3SEliot Blennerhassett 	*assert_present = 0;
423719f82d3SEliot Blennerhassett 
424719f82d3SEliot Blennerhassett 	if (!hr.error) {
425719f82d3SEliot Blennerhassett 
426719f82d3SEliot Blennerhassett 		*pline_number = hr.u.a.serial_number;
427719f82d3SEliot Blennerhassett 
428719f82d3SEliot Blennerhassett 		*assert_present = hr.u.a.adapter_type;
429719f82d3SEliot Blennerhassett 
430719f82d3SEliot Blennerhassett 		*pw_assert_on_dsp = hr.u.a.adapter_index;
431719f82d3SEliot Blennerhassett 
432719f82d3SEliot Blennerhassett 		if (!*assert_present && *pline_number)
433719f82d3SEliot Blennerhassett 
434719f82d3SEliot Blennerhassett 			*assert_present = 1;
435719f82d3SEliot Blennerhassett 
436719f82d3SEliot Blennerhassett 		if (*assert_present) {
437719f82d3SEliot Blennerhassett 
438719f82d3SEliot Blennerhassett 			int i;
439719f82d3SEliot Blennerhassett 			char *src = (char *)hr.u.a.sz_adapter_assert;
440719f82d3SEliot Blennerhassett 			char *dst = psz_assert;
441719f82d3SEliot Blennerhassett 
442719f82d3SEliot Blennerhassett 			for (i = 0; i < HPI_STRING_LEN; i++) {
443719f82d3SEliot Blennerhassett 				char c;
444719f82d3SEliot Blennerhassett 				c = *src++;
445719f82d3SEliot Blennerhassett 				*dst++ = c;
446719f82d3SEliot Blennerhassett 				if (c == 0)
447719f82d3SEliot Blennerhassett 					break;
448719f82d3SEliot Blennerhassett 			}
449719f82d3SEliot Blennerhassett 
450719f82d3SEliot Blennerhassett 		} else {
451719f82d3SEliot Blennerhassett 			*psz_assert = 0;
452719f82d3SEliot Blennerhassett 		}
453719f82d3SEliot Blennerhassett 	}
454719f82d3SEliot Blennerhassett 	return hr.error;
455719f82d3SEliot Blennerhassett }
456719f82d3SEliot Blennerhassett 
457719f82d3SEliot Blennerhassett u16 hpi_adapter_test_assert(const struct hpi_hsubsys *ph_subsys,
458719f82d3SEliot Blennerhassett 	u16 adapter_index, u16 assert_id)
459719f82d3SEliot Blennerhassett {
460719f82d3SEliot Blennerhassett 	struct hpi_message hm;
461719f82d3SEliot Blennerhassett 	struct hpi_response hr;
462719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
463719f82d3SEliot Blennerhassett 		HPI_ADAPTER_TEST_ASSERT);
464719f82d3SEliot Blennerhassett 	hm.adapter_index = adapter_index;
465719f82d3SEliot Blennerhassett 	hm.u.a.assert_id = assert_id;
466719f82d3SEliot Blennerhassett 
467719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
468719f82d3SEliot Blennerhassett 
469719f82d3SEliot Blennerhassett 	return hr.error;
470719f82d3SEliot Blennerhassett }
471719f82d3SEliot Blennerhassett 
472719f82d3SEliot Blennerhassett u16 hpi_adapter_enable_capability(const struct hpi_hsubsys *ph_subsys,
473719f82d3SEliot Blennerhassett 	u16 adapter_index, u16 capability, u32 key)
474719f82d3SEliot Blennerhassett {
475719f82d3SEliot Blennerhassett 	struct hpi_message hm;
476719f82d3SEliot Blennerhassett 	struct hpi_response hr;
477719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
478719f82d3SEliot Blennerhassett 		HPI_ADAPTER_ENABLE_CAPABILITY);
479719f82d3SEliot Blennerhassett 	hm.adapter_index = adapter_index;
480719f82d3SEliot Blennerhassett 	hm.u.a.assert_id = capability;
481719f82d3SEliot Blennerhassett 	hm.u.a.adapter_mode = key;
482719f82d3SEliot Blennerhassett 
483719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
484719f82d3SEliot Blennerhassett 
485719f82d3SEliot Blennerhassett 	return hr.error;
486719f82d3SEliot Blennerhassett }
487719f82d3SEliot Blennerhassett 
488719f82d3SEliot Blennerhassett u16 hpi_adapter_self_test(const struct hpi_hsubsys *ph_subsys,
489719f82d3SEliot Blennerhassett 	u16 adapter_index)
490719f82d3SEliot Blennerhassett {
491719f82d3SEliot Blennerhassett 	struct hpi_message hm;
492719f82d3SEliot Blennerhassett 	struct hpi_response hr;
493719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
494719f82d3SEliot Blennerhassett 		HPI_ADAPTER_SELFTEST);
495719f82d3SEliot Blennerhassett 	hm.adapter_index = adapter_index;
496719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
497719f82d3SEliot Blennerhassett 	return hr.error;
498719f82d3SEliot Blennerhassett }
499719f82d3SEliot Blennerhassett 
500719f82d3SEliot Blennerhassett u16 hpi_adapter_debug_read(const struct hpi_hsubsys *ph_subsys,
501719f82d3SEliot Blennerhassett 	u16 adapter_index, u32 dsp_address, char *p_buffer, int *count_bytes)
502719f82d3SEliot Blennerhassett {
503719f82d3SEliot Blennerhassett 	struct hpi_message hm;
504719f82d3SEliot Blennerhassett 	struct hpi_response hr;
505719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
506719f82d3SEliot Blennerhassett 		HPI_ADAPTER_DEBUG_READ);
507719f82d3SEliot Blennerhassett 
508719f82d3SEliot Blennerhassett 	hr.size = sizeof(hr);
509719f82d3SEliot Blennerhassett 
510719f82d3SEliot Blennerhassett 	hm.adapter_index = adapter_index;
511719f82d3SEliot Blennerhassett 	hm.u.ax.debug_read.dsp_address = dsp_address;
512719f82d3SEliot Blennerhassett 
513719f82d3SEliot Blennerhassett 	if (*count_bytes > sizeof(hr.u.bytes))
514719f82d3SEliot Blennerhassett 		*count_bytes = sizeof(hr.u.bytes);
515719f82d3SEliot Blennerhassett 
516719f82d3SEliot Blennerhassett 	hm.u.ax.debug_read.count_bytes = *count_bytes;
517719f82d3SEliot Blennerhassett 
518719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
519719f82d3SEliot Blennerhassett 
520719f82d3SEliot Blennerhassett 	if (!hr.error) {
521719f82d3SEliot Blennerhassett 		*count_bytes = hr.size - 12;
522719f82d3SEliot Blennerhassett 		memcpy(p_buffer, &hr.u.bytes, *count_bytes);
523719f82d3SEliot Blennerhassett 	} else
524719f82d3SEliot Blennerhassett 		*count_bytes = 0;
525719f82d3SEliot Blennerhassett 	return hr.error;
526719f82d3SEliot Blennerhassett }
527719f82d3SEliot Blennerhassett 
528719f82d3SEliot Blennerhassett u16 hpi_adapter_set_property(const struct hpi_hsubsys *ph_subsys,
529719f82d3SEliot Blennerhassett 	u16 adapter_index, u16 property, u16 parameter1, u16 parameter2)
530719f82d3SEliot Blennerhassett {
531719f82d3SEliot Blennerhassett 	struct hpi_message hm;
532719f82d3SEliot Blennerhassett 	struct hpi_response hr;
533719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
534719f82d3SEliot Blennerhassett 		HPI_ADAPTER_SET_PROPERTY);
535719f82d3SEliot Blennerhassett 	hm.adapter_index = adapter_index;
536719f82d3SEliot Blennerhassett 	hm.u.ax.property_set.property = property;
537719f82d3SEliot Blennerhassett 	hm.u.ax.property_set.parameter1 = parameter1;
538719f82d3SEliot Blennerhassett 	hm.u.ax.property_set.parameter2 = parameter2;
539719f82d3SEliot Blennerhassett 
540719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
541719f82d3SEliot Blennerhassett 
542719f82d3SEliot Blennerhassett 	return hr.error;
543719f82d3SEliot Blennerhassett }
544719f82d3SEliot Blennerhassett 
545719f82d3SEliot Blennerhassett u16 hpi_adapter_get_property(const struct hpi_hsubsys *ph_subsys,
546719f82d3SEliot Blennerhassett 	u16 adapter_index, u16 property, u16 *pw_parameter1,
547719f82d3SEliot Blennerhassett 	u16 *pw_parameter2)
548719f82d3SEliot Blennerhassett {
549719f82d3SEliot Blennerhassett 	struct hpi_message hm;
550719f82d3SEliot Blennerhassett 	struct hpi_response hr;
551719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
552719f82d3SEliot Blennerhassett 		HPI_ADAPTER_GET_PROPERTY);
553719f82d3SEliot Blennerhassett 	hm.adapter_index = adapter_index;
554719f82d3SEliot Blennerhassett 	hm.u.ax.property_set.property = property;
555719f82d3SEliot Blennerhassett 
556719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
557719f82d3SEliot Blennerhassett 	if (!hr.error) {
558719f82d3SEliot Blennerhassett 		if (pw_parameter1)
559719f82d3SEliot Blennerhassett 			*pw_parameter1 = hr.u.ax.property_get.parameter1;
560719f82d3SEliot Blennerhassett 		if (pw_parameter2)
561719f82d3SEliot Blennerhassett 			*pw_parameter2 = hr.u.ax.property_get.parameter2;
562719f82d3SEliot Blennerhassett 	}
563719f82d3SEliot Blennerhassett 
564719f82d3SEliot Blennerhassett 	return hr.error;
565719f82d3SEliot Blennerhassett }
566719f82d3SEliot Blennerhassett 
567719f82d3SEliot Blennerhassett u16 hpi_adapter_enumerate_property(const struct hpi_hsubsys *ph_subsys,
568719f82d3SEliot Blennerhassett 	u16 adapter_index, u16 index, u16 what_to_enumerate,
569719f82d3SEliot Blennerhassett 	u16 property_index, u32 *psetting)
570719f82d3SEliot Blennerhassett {
571719f82d3SEliot Blennerhassett 	return 0;
572719f82d3SEliot Blennerhassett }
573719f82d3SEliot Blennerhassett 
574719f82d3SEliot Blennerhassett u16 hpi_format_create(struct hpi_format *p_format, u16 channels, u16 format,
575719f82d3SEliot Blennerhassett 	u32 sample_rate, u32 bit_rate, u32 attributes)
576719f82d3SEliot Blennerhassett {
577719f82d3SEliot Blennerhassett 	u16 error = 0;
578719f82d3SEliot Blennerhassett 	struct hpi_msg_format fmt;
579719f82d3SEliot Blennerhassett 
580719f82d3SEliot Blennerhassett 	switch (channels) {
581719f82d3SEliot Blennerhassett 	case 1:
582719f82d3SEliot Blennerhassett 	case 2:
583719f82d3SEliot Blennerhassett 	case 4:
584719f82d3SEliot Blennerhassett 	case 6:
585719f82d3SEliot Blennerhassett 	case 8:
586719f82d3SEliot Blennerhassett 	case 16:
587719f82d3SEliot Blennerhassett 		break;
588719f82d3SEliot Blennerhassett 	default:
589719f82d3SEliot Blennerhassett 		error = HPI_ERROR_INVALID_CHANNELS;
590719f82d3SEliot Blennerhassett 		return error;
591719f82d3SEliot Blennerhassett 	}
592719f82d3SEliot Blennerhassett 	fmt.channels = channels;
593719f82d3SEliot Blennerhassett 
594719f82d3SEliot Blennerhassett 	switch (format) {
595719f82d3SEliot Blennerhassett 	case HPI_FORMAT_PCM16_SIGNED:
596719f82d3SEliot Blennerhassett 	case HPI_FORMAT_PCM24_SIGNED:
597719f82d3SEliot Blennerhassett 	case HPI_FORMAT_PCM32_SIGNED:
598719f82d3SEliot Blennerhassett 	case HPI_FORMAT_PCM32_FLOAT:
599719f82d3SEliot Blennerhassett 	case HPI_FORMAT_PCM16_BIGENDIAN:
600719f82d3SEliot Blennerhassett 	case HPI_FORMAT_PCM8_UNSIGNED:
601719f82d3SEliot Blennerhassett 	case HPI_FORMAT_MPEG_L1:
602719f82d3SEliot Blennerhassett 	case HPI_FORMAT_MPEG_L2:
603719f82d3SEliot Blennerhassett 	case HPI_FORMAT_MPEG_L3:
604719f82d3SEliot Blennerhassett 	case HPI_FORMAT_DOLBY_AC2:
605719f82d3SEliot Blennerhassett 	case HPI_FORMAT_AA_TAGIT1_HITS:
606719f82d3SEliot Blennerhassett 	case HPI_FORMAT_AA_TAGIT1_INSERTS:
607719f82d3SEliot Blennerhassett 	case HPI_FORMAT_RAW_BITSTREAM:
608719f82d3SEliot Blennerhassett 	case HPI_FORMAT_AA_TAGIT1_HITS_EX1:
609719f82d3SEliot Blennerhassett 	case HPI_FORMAT_OEM1:
610719f82d3SEliot Blennerhassett 	case HPI_FORMAT_OEM2:
611719f82d3SEliot Blennerhassett 		break;
612719f82d3SEliot Blennerhassett 	default:
613719f82d3SEliot Blennerhassett 		error = HPI_ERROR_INVALID_FORMAT;
614719f82d3SEliot Blennerhassett 		return error;
615719f82d3SEliot Blennerhassett 	}
616719f82d3SEliot Blennerhassett 	fmt.format = format;
617719f82d3SEliot Blennerhassett 
618719f82d3SEliot Blennerhassett 	if (sample_rate < 8000L) {
619719f82d3SEliot Blennerhassett 		error = HPI_ERROR_INCOMPATIBLE_SAMPLERATE;
620719f82d3SEliot Blennerhassett 		sample_rate = 8000L;
621719f82d3SEliot Blennerhassett 	}
622719f82d3SEliot Blennerhassett 	if (sample_rate > 200000L) {
623719f82d3SEliot Blennerhassett 		error = HPI_ERROR_INCOMPATIBLE_SAMPLERATE;
624719f82d3SEliot Blennerhassett 		sample_rate = 200000L;
625719f82d3SEliot Blennerhassett 	}
626719f82d3SEliot Blennerhassett 	fmt.sample_rate = sample_rate;
627719f82d3SEliot Blennerhassett 
628719f82d3SEliot Blennerhassett 	switch (format) {
629719f82d3SEliot Blennerhassett 	case HPI_FORMAT_MPEG_L1:
630719f82d3SEliot Blennerhassett 	case HPI_FORMAT_MPEG_L2:
631719f82d3SEliot Blennerhassett 	case HPI_FORMAT_MPEG_L3:
632719f82d3SEliot Blennerhassett 		fmt.bit_rate = bit_rate;
633719f82d3SEliot Blennerhassett 		break;
634719f82d3SEliot Blennerhassett 	case HPI_FORMAT_PCM16_SIGNED:
635719f82d3SEliot Blennerhassett 	case HPI_FORMAT_PCM16_BIGENDIAN:
636719f82d3SEliot Blennerhassett 		fmt.bit_rate = channels * sample_rate * 2;
637719f82d3SEliot Blennerhassett 		break;
638719f82d3SEliot Blennerhassett 	case HPI_FORMAT_PCM32_SIGNED:
639719f82d3SEliot Blennerhassett 	case HPI_FORMAT_PCM32_FLOAT:
640719f82d3SEliot Blennerhassett 		fmt.bit_rate = channels * sample_rate * 4;
641719f82d3SEliot Blennerhassett 		break;
642719f82d3SEliot Blennerhassett 	case HPI_FORMAT_PCM8_UNSIGNED:
643719f82d3SEliot Blennerhassett 		fmt.bit_rate = channels * sample_rate;
644719f82d3SEliot Blennerhassett 		break;
645719f82d3SEliot Blennerhassett 	default:
646719f82d3SEliot Blennerhassett 		fmt.bit_rate = 0;
647719f82d3SEliot Blennerhassett 	}
648719f82d3SEliot Blennerhassett 
649719f82d3SEliot Blennerhassett 	switch (format) {
650719f82d3SEliot Blennerhassett 	case HPI_FORMAT_MPEG_L2:
651719f82d3SEliot Blennerhassett 		if ((channels == 1)
652719f82d3SEliot Blennerhassett 			&& (attributes != HPI_MPEG_MODE_DEFAULT)) {
653719f82d3SEliot Blennerhassett 			attributes = HPI_MPEG_MODE_DEFAULT;
654719f82d3SEliot Blennerhassett 			error = HPI_ERROR_INVALID_FORMAT;
655719f82d3SEliot Blennerhassett 		} else if (attributes > HPI_MPEG_MODE_DUALCHANNEL) {
656719f82d3SEliot Blennerhassett 			attributes = HPI_MPEG_MODE_DEFAULT;
657719f82d3SEliot Blennerhassett 			error = HPI_ERROR_INVALID_FORMAT;
658719f82d3SEliot Blennerhassett 		}
659719f82d3SEliot Blennerhassett 		fmt.attributes = attributes;
660719f82d3SEliot Blennerhassett 		break;
661719f82d3SEliot Blennerhassett 	default:
662719f82d3SEliot Blennerhassett 		fmt.attributes = attributes;
663719f82d3SEliot Blennerhassett 	}
664719f82d3SEliot Blennerhassett 
665719f82d3SEliot Blennerhassett 	hpi_msg_to_format(p_format, &fmt);
666719f82d3SEliot Blennerhassett 	return error;
667719f82d3SEliot Blennerhassett }
668719f82d3SEliot Blennerhassett 
669719f82d3SEliot Blennerhassett u16 hpi_stream_estimate_buffer_size(struct hpi_format *p_format,
670719f82d3SEliot Blennerhassett 	u32 host_polling_rate_in_milli_seconds, u32 *recommended_buffer_size)
671719f82d3SEliot Blennerhassett {
672719f82d3SEliot Blennerhassett 
673719f82d3SEliot Blennerhassett 	u32 bytes_per_second;
674719f82d3SEliot Blennerhassett 	u32 size;
675719f82d3SEliot Blennerhassett 	u16 channels;
676719f82d3SEliot Blennerhassett 	struct hpi_format *pF = p_format;
677719f82d3SEliot Blennerhassett 
678719f82d3SEliot Blennerhassett 	channels = pF->channels;
679719f82d3SEliot Blennerhassett 
680719f82d3SEliot Blennerhassett 	switch (pF->format) {
681719f82d3SEliot Blennerhassett 	case HPI_FORMAT_PCM16_BIGENDIAN:
682719f82d3SEliot Blennerhassett 	case HPI_FORMAT_PCM16_SIGNED:
683719f82d3SEliot Blennerhassett 		bytes_per_second = pF->sample_rate * 2L * channels;
684719f82d3SEliot Blennerhassett 		break;
685719f82d3SEliot Blennerhassett 	case HPI_FORMAT_PCM24_SIGNED:
686719f82d3SEliot Blennerhassett 		bytes_per_second = pF->sample_rate * 3L * channels;
687719f82d3SEliot Blennerhassett 		break;
688719f82d3SEliot Blennerhassett 	case HPI_FORMAT_PCM32_SIGNED:
689719f82d3SEliot Blennerhassett 	case HPI_FORMAT_PCM32_FLOAT:
690719f82d3SEliot Blennerhassett 		bytes_per_second = pF->sample_rate * 4L * channels;
691719f82d3SEliot Blennerhassett 		break;
692719f82d3SEliot Blennerhassett 	case HPI_FORMAT_PCM8_UNSIGNED:
693719f82d3SEliot Blennerhassett 		bytes_per_second = pF->sample_rate * 1L * channels;
694719f82d3SEliot Blennerhassett 		break;
695719f82d3SEliot Blennerhassett 	case HPI_FORMAT_MPEG_L1:
696719f82d3SEliot Blennerhassett 	case HPI_FORMAT_MPEG_L2:
697719f82d3SEliot Blennerhassett 	case HPI_FORMAT_MPEG_L3:
698719f82d3SEliot Blennerhassett 		bytes_per_second = pF->bit_rate / 8L;
699719f82d3SEliot Blennerhassett 		break;
700719f82d3SEliot Blennerhassett 	case HPI_FORMAT_DOLBY_AC2:
701719f82d3SEliot Blennerhassett 
702719f82d3SEliot Blennerhassett 		bytes_per_second = 256000L / 8L;
703719f82d3SEliot Blennerhassett 		break;
704719f82d3SEliot Blennerhassett 	default:
705719f82d3SEliot Blennerhassett 		return HPI_ERROR_INVALID_FORMAT;
706719f82d3SEliot Blennerhassett 	}
707719f82d3SEliot Blennerhassett 	size = (bytes_per_second * host_polling_rate_in_milli_seconds * 2) /
708719f82d3SEliot Blennerhassett 		1000L;
709719f82d3SEliot Blennerhassett 
710719f82d3SEliot Blennerhassett 	*recommended_buffer_size =
711719f82d3SEliot Blennerhassett 		roundup_pow_of_two(((size + 4095L) & ~4095L));
712719f82d3SEliot Blennerhassett 	return 0;
713719f82d3SEliot Blennerhassett }
714719f82d3SEliot Blennerhassett 
715719f82d3SEliot Blennerhassett u16 hpi_outstream_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index,
716719f82d3SEliot Blennerhassett 	u16 outstream_index, u32 *ph_outstream)
717719f82d3SEliot Blennerhassett {
718719f82d3SEliot Blennerhassett 	struct hpi_message hm;
719719f82d3SEliot Blennerhassett 	struct hpi_response hr;
720719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
721719f82d3SEliot Blennerhassett 		HPI_OSTREAM_OPEN);
722719f82d3SEliot Blennerhassett 	hm.adapter_index = adapter_index;
723719f82d3SEliot Blennerhassett 	hm.obj_index = outstream_index;
724719f82d3SEliot Blennerhassett 
725719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
726719f82d3SEliot Blennerhassett 
727719f82d3SEliot Blennerhassett 	if (hr.error == 0)
728719f82d3SEliot Blennerhassett 		*ph_outstream =
729719f82d3SEliot Blennerhassett 			hpi_indexes_to_handle(HPI_OBJ_OSTREAM, adapter_index,
730719f82d3SEliot Blennerhassett 			outstream_index);
731719f82d3SEliot Blennerhassett 	else
732719f82d3SEliot Blennerhassett 		*ph_outstream = 0;
733719f82d3SEliot Blennerhassett 	return hr.error;
734719f82d3SEliot Blennerhassett }
735719f82d3SEliot Blennerhassett 
736719f82d3SEliot Blennerhassett u16 hpi_outstream_close(const struct hpi_hsubsys *ph_subsys, u32 h_outstream)
737719f82d3SEliot Blennerhassett {
738719f82d3SEliot Blennerhassett 	struct hpi_message hm;
739719f82d3SEliot Blennerhassett 	struct hpi_response hr;
740719f82d3SEliot Blennerhassett 
741719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
742719f82d3SEliot Blennerhassett 		HPI_OSTREAM_HOSTBUFFER_FREE);
743719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
744719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
745719f82d3SEliot Blennerhassett 
746719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
747719f82d3SEliot Blennerhassett 		HPI_OSTREAM_GROUP_RESET);
748719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
749719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
750719f82d3SEliot Blennerhassett 
751719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
752719f82d3SEliot Blennerhassett 		HPI_OSTREAM_CLOSE);
753719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
754719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
755719f82d3SEliot Blennerhassett 
756719f82d3SEliot Blennerhassett 	return hr.error;
757719f82d3SEliot Blennerhassett }
758719f82d3SEliot Blennerhassett 
759719f82d3SEliot Blennerhassett u16 hpi_outstream_get_info_ex(const struct hpi_hsubsys *ph_subsys,
760719f82d3SEliot Blennerhassett 	u32 h_outstream, u16 *pw_state, u32 *pbuffer_size, u32 *pdata_to_play,
761719f82d3SEliot Blennerhassett 	u32 *psamples_played, u32 *pauxiliary_data_to_play)
762719f82d3SEliot Blennerhassett {
763719f82d3SEliot Blennerhassett 	struct hpi_message hm;
764719f82d3SEliot Blennerhassett 	struct hpi_response hr;
765719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
766719f82d3SEliot Blennerhassett 		HPI_OSTREAM_GET_INFO);
767719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
768719f82d3SEliot Blennerhassett 
769719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
770719f82d3SEliot Blennerhassett 
771719f82d3SEliot Blennerhassett 	if (pw_state)
772719f82d3SEliot Blennerhassett 		*pw_state = hr.u.d.u.stream_info.state;
773719f82d3SEliot Blennerhassett 	if (pbuffer_size)
774719f82d3SEliot Blennerhassett 		*pbuffer_size = hr.u.d.u.stream_info.buffer_size;
775719f82d3SEliot Blennerhassett 	if (pdata_to_play)
776719f82d3SEliot Blennerhassett 		*pdata_to_play = hr.u.d.u.stream_info.data_available;
777719f82d3SEliot Blennerhassett 	if (psamples_played)
778719f82d3SEliot Blennerhassett 		*psamples_played = hr.u.d.u.stream_info.samples_transferred;
779719f82d3SEliot Blennerhassett 	if (pauxiliary_data_to_play)
780719f82d3SEliot Blennerhassett 		*pauxiliary_data_to_play =
781719f82d3SEliot Blennerhassett 			hr.u.d.u.stream_info.auxiliary_data_available;
782719f82d3SEliot Blennerhassett 	return hr.error;
783719f82d3SEliot Blennerhassett }
784719f82d3SEliot Blennerhassett 
785719f82d3SEliot Blennerhassett u16 hpi_outstream_write_buf(const struct hpi_hsubsys *ph_subsys,
786719f82d3SEliot Blennerhassett 	u32 h_outstream, const u8 *pb_data, u32 bytes_to_write,
787719f82d3SEliot Blennerhassett 	const struct hpi_format *p_format)
788719f82d3SEliot Blennerhassett {
789719f82d3SEliot Blennerhassett 	struct hpi_message hm;
790719f82d3SEliot Blennerhassett 	struct hpi_response hr;
791719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
792719f82d3SEliot Blennerhassett 		HPI_OSTREAM_WRITE);
793719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
794719f82d3SEliot Blennerhassett 	hm.u.d.u.data.pb_data = (u8 *)pb_data;
795719f82d3SEliot Blennerhassett 	hm.u.d.u.data.data_size = bytes_to_write;
796719f82d3SEliot Blennerhassett 
797719f82d3SEliot Blennerhassett 	hpi_format_to_msg(&hm.u.d.u.data.format, p_format);
798719f82d3SEliot Blennerhassett 
799719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
800719f82d3SEliot Blennerhassett 
801719f82d3SEliot Blennerhassett 	return hr.error;
802719f82d3SEliot Blennerhassett }
803719f82d3SEliot Blennerhassett 
804719f82d3SEliot Blennerhassett u16 hpi_outstream_start(const struct hpi_hsubsys *ph_subsys, u32 h_outstream)
805719f82d3SEliot Blennerhassett {
806719f82d3SEliot Blennerhassett 	struct hpi_message hm;
807719f82d3SEliot Blennerhassett 	struct hpi_response hr;
808719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
809719f82d3SEliot Blennerhassett 		HPI_OSTREAM_START);
810719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
811719f82d3SEliot Blennerhassett 
812719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
813719f82d3SEliot Blennerhassett 
814719f82d3SEliot Blennerhassett 	return hr.error;
815719f82d3SEliot Blennerhassett }
816719f82d3SEliot Blennerhassett 
817719f82d3SEliot Blennerhassett u16 hpi_outstream_wait_start(const struct hpi_hsubsys *ph_subsys,
818719f82d3SEliot Blennerhassett 	u32 h_outstream)
819719f82d3SEliot Blennerhassett {
820719f82d3SEliot Blennerhassett 	struct hpi_message hm;
821719f82d3SEliot Blennerhassett 	struct hpi_response hr;
822719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
823719f82d3SEliot Blennerhassett 		HPI_OSTREAM_WAIT_START);
824719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
825719f82d3SEliot Blennerhassett 
826719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
827719f82d3SEliot Blennerhassett 
828719f82d3SEliot Blennerhassett 	return hr.error;
829719f82d3SEliot Blennerhassett }
830719f82d3SEliot Blennerhassett 
831719f82d3SEliot Blennerhassett u16 hpi_outstream_stop(const struct hpi_hsubsys *ph_subsys, u32 h_outstream)
832719f82d3SEliot Blennerhassett {
833719f82d3SEliot Blennerhassett 	struct hpi_message hm;
834719f82d3SEliot Blennerhassett 	struct hpi_response hr;
835719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
836719f82d3SEliot Blennerhassett 		HPI_OSTREAM_STOP);
837719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
838719f82d3SEliot Blennerhassett 
839719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
840719f82d3SEliot Blennerhassett 
841719f82d3SEliot Blennerhassett 	return hr.error;
842719f82d3SEliot Blennerhassett }
843719f82d3SEliot Blennerhassett 
844719f82d3SEliot Blennerhassett u16 hpi_outstream_sinegen(const struct hpi_hsubsys *ph_subsys,
845719f82d3SEliot Blennerhassett 	u32 h_outstream)
846719f82d3SEliot Blennerhassett {
847719f82d3SEliot Blennerhassett 	struct hpi_message hm;
848719f82d3SEliot Blennerhassett 	struct hpi_response hr;
849719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
850719f82d3SEliot Blennerhassett 		HPI_OSTREAM_SINEGEN);
851719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
852719f82d3SEliot Blennerhassett 
853719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
854719f82d3SEliot Blennerhassett 
855719f82d3SEliot Blennerhassett 	return hr.error;
856719f82d3SEliot Blennerhassett }
857719f82d3SEliot Blennerhassett 
858719f82d3SEliot Blennerhassett u16 hpi_outstream_reset(const struct hpi_hsubsys *ph_subsys, u32 h_outstream)
859719f82d3SEliot Blennerhassett {
860719f82d3SEliot Blennerhassett 	struct hpi_message hm;
861719f82d3SEliot Blennerhassett 	struct hpi_response hr;
862719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
863719f82d3SEliot Blennerhassett 		HPI_OSTREAM_RESET);
864719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
865719f82d3SEliot Blennerhassett 
866719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
867719f82d3SEliot Blennerhassett 
868719f82d3SEliot Blennerhassett 	return hr.error;
869719f82d3SEliot Blennerhassett }
870719f82d3SEliot Blennerhassett 
871719f82d3SEliot Blennerhassett u16 hpi_outstream_query_format(const struct hpi_hsubsys *ph_subsys,
872719f82d3SEliot Blennerhassett 	u32 h_outstream, struct hpi_format *p_format)
873719f82d3SEliot Blennerhassett {
874719f82d3SEliot Blennerhassett 	struct hpi_message hm;
875719f82d3SEliot Blennerhassett 	struct hpi_response hr;
876719f82d3SEliot Blennerhassett 
877719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
878719f82d3SEliot Blennerhassett 		HPI_OSTREAM_QUERY_FORMAT);
879719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
880719f82d3SEliot Blennerhassett 
881719f82d3SEliot Blennerhassett 	hpi_format_to_msg(&hm.u.d.u.data.format, p_format);
882719f82d3SEliot Blennerhassett 
883719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
884719f82d3SEliot Blennerhassett 
885719f82d3SEliot Blennerhassett 	return hr.error;
886719f82d3SEliot Blennerhassett }
887719f82d3SEliot Blennerhassett 
888719f82d3SEliot Blennerhassett u16 hpi_outstream_set_format(const struct hpi_hsubsys *ph_subsys,
889719f82d3SEliot Blennerhassett 	u32 h_outstream, struct hpi_format *p_format)
890719f82d3SEliot Blennerhassett {
891719f82d3SEliot Blennerhassett 	struct hpi_message hm;
892719f82d3SEliot Blennerhassett 	struct hpi_response hr;
893719f82d3SEliot Blennerhassett 
894719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
895719f82d3SEliot Blennerhassett 		HPI_OSTREAM_SET_FORMAT);
896719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
897719f82d3SEliot Blennerhassett 
898719f82d3SEliot Blennerhassett 	hpi_format_to_msg(&hm.u.d.u.data.format, p_format);
899719f82d3SEliot Blennerhassett 
900719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
901719f82d3SEliot Blennerhassett 
902719f82d3SEliot Blennerhassett 	return hr.error;
903719f82d3SEliot Blennerhassett }
904719f82d3SEliot Blennerhassett 
905719f82d3SEliot Blennerhassett u16 hpi_outstream_set_velocity(const struct hpi_hsubsys *ph_subsys,
906719f82d3SEliot Blennerhassett 	u32 h_outstream, short velocity)
907719f82d3SEliot Blennerhassett {
908719f82d3SEliot Blennerhassett 	struct hpi_message hm;
909719f82d3SEliot Blennerhassett 	struct hpi_response hr;
910719f82d3SEliot Blennerhassett 
911719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
912719f82d3SEliot Blennerhassett 		HPI_OSTREAM_SET_VELOCITY);
913719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
914719f82d3SEliot Blennerhassett 	hm.u.d.u.velocity = velocity;
915719f82d3SEliot Blennerhassett 
916719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
917719f82d3SEliot Blennerhassett 
918719f82d3SEliot Blennerhassett 	return hr.error;
919719f82d3SEliot Blennerhassett }
920719f82d3SEliot Blennerhassett 
921719f82d3SEliot Blennerhassett u16 hpi_outstream_set_punch_in_out(const struct hpi_hsubsys *ph_subsys,
922719f82d3SEliot Blennerhassett 	u32 h_outstream, u32 punch_in_sample, u32 punch_out_sample)
923719f82d3SEliot Blennerhassett {
924719f82d3SEliot Blennerhassett 	struct hpi_message hm;
925719f82d3SEliot Blennerhassett 	struct hpi_response hr;
926719f82d3SEliot Blennerhassett 
927719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
928719f82d3SEliot Blennerhassett 		HPI_OSTREAM_SET_PUNCHINOUT);
929719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
930719f82d3SEliot Blennerhassett 
931719f82d3SEliot Blennerhassett 	hm.u.d.u.pio.punch_in_sample = punch_in_sample;
932719f82d3SEliot Blennerhassett 	hm.u.d.u.pio.punch_out_sample = punch_out_sample;
933719f82d3SEliot Blennerhassett 
934719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
935719f82d3SEliot Blennerhassett 
936719f82d3SEliot Blennerhassett 	return hr.error;
937719f82d3SEliot Blennerhassett }
938719f82d3SEliot Blennerhassett 
939719f82d3SEliot Blennerhassett u16 hpi_outstream_ancillary_reset(const struct hpi_hsubsys *ph_subsys,
940719f82d3SEliot Blennerhassett 	u32 h_outstream, u16 mode)
941719f82d3SEliot Blennerhassett {
942719f82d3SEliot Blennerhassett 	struct hpi_message hm;
943719f82d3SEliot Blennerhassett 	struct hpi_response hr;
944719f82d3SEliot Blennerhassett 
945719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
946719f82d3SEliot Blennerhassett 		HPI_OSTREAM_ANC_RESET);
947719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
948719f82d3SEliot Blennerhassett 	hm.u.d.u.data.format.channels = mode;
949719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
950719f82d3SEliot Blennerhassett 	return hr.error;
951719f82d3SEliot Blennerhassett }
952719f82d3SEliot Blennerhassett 
953719f82d3SEliot Blennerhassett u16 hpi_outstream_ancillary_get_info(const struct hpi_hsubsys *ph_subsys,
954719f82d3SEliot Blennerhassett 	u32 h_outstream, u32 *pframes_available)
955719f82d3SEliot Blennerhassett {
956719f82d3SEliot Blennerhassett 	struct hpi_message hm;
957719f82d3SEliot Blennerhassett 	struct hpi_response hr;
958719f82d3SEliot Blennerhassett 
959719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
960719f82d3SEliot Blennerhassett 		HPI_OSTREAM_ANC_GET_INFO);
961719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
962719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
963719f82d3SEliot Blennerhassett 	if (hr.error == 0) {
964719f82d3SEliot Blennerhassett 		if (pframes_available)
965719f82d3SEliot Blennerhassett 			*pframes_available =
966719f82d3SEliot Blennerhassett 				hr.u.d.u.stream_info.data_available /
967719f82d3SEliot Blennerhassett 				sizeof(struct hpi_anc_frame);
968719f82d3SEliot Blennerhassett 	}
969719f82d3SEliot Blennerhassett 	return hr.error;
970719f82d3SEliot Blennerhassett }
971719f82d3SEliot Blennerhassett 
972719f82d3SEliot Blennerhassett u16 hpi_outstream_ancillary_read(const struct hpi_hsubsys *ph_subsys,
973719f82d3SEliot Blennerhassett 	u32 h_outstream, struct hpi_anc_frame *p_anc_frame_buffer,
974719f82d3SEliot Blennerhassett 	u32 anc_frame_buffer_size_in_bytes,
975719f82d3SEliot Blennerhassett 	u32 number_of_ancillary_frames_to_read)
976719f82d3SEliot Blennerhassett {
977719f82d3SEliot Blennerhassett 	struct hpi_message hm;
978719f82d3SEliot Blennerhassett 	struct hpi_response hr;
979719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
980719f82d3SEliot Blennerhassett 		HPI_OSTREAM_ANC_READ);
981719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
982719f82d3SEliot Blennerhassett 	hm.u.d.u.data.pb_data = (u8 *)p_anc_frame_buffer;
983719f82d3SEliot Blennerhassett 	hm.u.d.u.data.data_size =
984719f82d3SEliot Blennerhassett 		number_of_ancillary_frames_to_read *
985719f82d3SEliot Blennerhassett 		sizeof(struct hpi_anc_frame);
986719f82d3SEliot Blennerhassett 	if (hm.u.d.u.data.data_size <= anc_frame_buffer_size_in_bytes)
987719f82d3SEliot Blennerhassett 		hpi_send_recv(&hm, &hr);
988719f82d3SEliot Blennerhassett 	else
989719f82d3SEliot Blennerhassett 		hr.error = HPI_ERROR_INVALID_DATA_TRANSFER;
990719f82d3SEliot Blennerhassett 	return hr.error;
991719f82d3SEliot Blennerhassett }
992719f82d3SEliot Blennerhassett 
993719f82d3SEliot Blennerhassett u16 hpi_outstream_set_time_scale(const struct hpi_hsubsys *ph_subsys,
994719f82d3SEliot Blennerhassett 	u32 h_outstream, u32 time_scale)
995719f82d3SEliot Blennerhassett {
996719f82d3SEliot Blennerhassett 	struct hpi_message hm;
997719f82d3SEliot Blennerhassett 	struct hpi_response hr;
998719f82d3SEliot Blennerhassett 
999719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
1000719f82d3SEliot Blennerhassett 		HPI_OSTREAM_SET_TIMESCALE);
1001719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
1002719f82d3SEliot Blennerhassett 
1003719f82d3SEliot Blennerhassett 	hm.u.d.u.time_scale = time_scale;
1004719f82d3SEliot Blennerhassett 
1005719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
1006719f82d3SEliot Blennerhassett 
1007719f82d3SEliot Blennerhassett 	return hr.error;
1008719f82d3SEliot Blennerhassett }
1009719f82d3SEliot Blennerhassett 
1010719f82d3SEliot Blennerhassett u16 hpi_outstream_host_buffer_allocate(const struct hpi_hsubsys *ph_subsys,
1011719f82d3SEliot Blennerhassett 	u32 h_outstream, u32 size_in_bytes)
1012719f82d3SEliot Blennerhassett {
1013719f82d3SEliot Blennerhassett 	struct hpi_message hm;
1014719f82d3SEliot Blennerhassett 	struct hpi_response hr;
1015719f82d3SEliot Blennerhassett 
1016719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
1017719f82d3SEliot Blennerhassett 		HPI_OSTREAM_HOSTBUFFER_ALLOC);
1018719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
1019719f82d3SEliot Blennerhassett 	hm.u.d.u.data.data_size = size_in_bytes;
1020719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
1021719f82d3SEliot Blennerhassett 	return hr.error;
1022719f82d3SEliot Blennerhassett }
1023719f82d3SEliot Blennerhassett 
1024719f82d3SEliot Blennerhassett u16 hpi_outstream_host_buffer_get_info(const struct hpi_hsubsys *ph_subsys,
1025719f82d3SEliot Blennerhassett 	u32 h_outstream, u8 **pp_buffer,
1026719f82d3SEliot Blennerhassett 	struct hpi_hostbuffer_status **pp_status)
1027719f82d3SEliot Blennerhassett {
1028719f82d3SEliot Blennerhassett 	struct hpi_message hm;
1029719f82d3SEliot Blennerhassett 	struct hpi_response hr;
1030719f82d3SEliot Blennerhassett 
1031719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
1032719f82d3SEliot Blennerhassett 		HPI_OSTREAM_HOSTBUFFER_GET_INFO);
1033719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
1034719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
1035719f82d3SEliot Blennerhassett 
1036719f82d3SEliot Blennerhassett 	if (hr.error == 0) {
1037719f82d3SEliot Blennerhassett 		if (pp_buffer)
1038719f82d3SEliot Blennerhassett 			*pp_buffer = hr.u.d.u.hostbuffer_info.p_buffer;
1039719f82d3SEliot Blennerhassett 		if (pp_status)
1040719f82d3SEliot Blennerhassett 			*pp_status = hr.u.d.u.hostbuffer_info.p_status;
1041719f82d3SEliot Blennerhassett 	}
1042719f82d3SEliot Blennerhassett 	return hr.error;
1043719f82d3SEliot Blennerhassett }
1044719f82d3SEliot Blennerhassett 
1045719f82d3SEliot Blennerhassett u16 hpi_outstream_host_buffer_free(const struct hpi_hsubsys *ph_subsys,
1046719f82d3SEliot Blennerhassett 	u32 h_outstream)
1047719f82d3SEliot Blennerhassett {
1048719f82d3SEliot Blennerhassett 	struct hpi_message hm;
1049719f82d3SEliot Blennerhassett 	struct hpi_response hr;
1050719f82d3SEliot Blennerhassett 
1051719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
1052719f82d3SEliot Blennerhassett 		HPI_OSTREAM_HOSTBUFFER_FREE);
1053719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
1054719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
1055719f82d3SEliot Blennerhassett 	return hr.error;
1056719f82d3SEliot Blennerhassett }
1057719f82d3SEliot Blennerhassett 
1058719f82d3SEliot Blennerhassett u16 hpi_outstream_group_add(const struct hpi_hsubsys *ph_subsys,
1059719f82d3SEliot Blennerhassett 	u32 h_outstream, u32 h_stream)
1060719f82d3SEliot Blennerhassett {
1061719f82d3SEliot Blennerhassett 	struct hpi_message hm;
1062719f82d3SEliot Blennerhassett 	struct hpi_response hr;
1063719f82d3SEliot Blennerhassett 	u16 adapter;
1064719f82d3SEliot Blennerhassett 	char c_obj_type;
1065719f82d3SEliot Blennerhassett 
1066719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
1067719f82d3SEliot Blennerhassett 		HPI_OSTREAM_GROUP_ADD);
1068719f82d3SEliot Blennerhassett 	hr.error = 0;
1069719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
1070719f82d3SEliot Blennerhassett 	c_obj_type = hpi_handle_object(h_stream);
1071719f82d3SEliot Blennerhassett 	switch (c_obj_type) {
1072719f82d3SEliot Blennerhassett 	case HPI_OBJ_OSTREAM:
1073719f82d3SEliot Blennerhassett 		hm.u.d.u.stream.object_type = HPI_OBJ_OSTREAM;
1074719f82d3SEliot Blennerhassett 		u32TOINDEXES(h_stream, &adapter,
1075719f82d3SEliot Blennerhassett 			&hm.u.d.u.stream.stream_index);
1076719f82d3SEliot Blennerhassett 		break;
1077719f82d3SEliot Blennerhassett 	case HPI_OBJ_ISTREAM:
1078719f82d3SEliot Blennerhassett 		hm.u.d.u.stream.object_type = HPI_OBJ_ISTREAM;
1079719f82d3SEliot Blennerhassett 		u32TOINDEXES(h_stream, &adapter,
1080719f82d3SEliot Blennerhassett 			&hm.u.d.u.stream.stream_index);
1081719f82d3SEliot Blennerhassett 		break;
1082719f82d3SEliot Blennerhassett 	default:
1083719f82d3SEliot Blennerhassett 		return HPI_ERROR_INVALID_STREAM;
1084719f82d3SEliot Blennerhassett 	}
1085719f82d3SEliot Blennerhassett 	if (adapter != hm.adapter_index)
1086719f82d3SEliot Blennerhassett 		return HPI_ERROR_NO_INTERADAPTER_GROUPS;
1087719f82d3SEliot Blennerhassett 
1088719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
1089719f82d3SEliot Blennerhassett 	return hr.error;
1090719f82d3SEliot Blennerhassett }
1091719f82d3SEliot Blennerhassett 
1092719f82d3SEliot Blennerhassett u16 hpi_outstream_group_get_map(const struct hpi_hsubsys *ph_subsys,
1093719f82d3SEliot Blennerhassett 	u32 h_outstream, u32 *poutstream_map, u32 *pinstream_map)
1094719f82d3SEliot Blennerhassett {
1095719f82d3SEliot Blennerhassett 	struct hpi_message hm;
1096719f82d3SEliot Blennerhassett 	struct hpi_response hr;
1097719f82d3SEliot Blennerhassett 
1098719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
1099719f82d3SEliot Blennerhassett 		HPI_OSTREAM_GROUP_GETMAP);
1100719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
1101719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
1102719f82d3SEliot Blennerhassett 
1103719f82d3SEliot Blennerhassett 	if (poutstream_map)
1104719f82d3SEliot Blennerhassett 		*poutstream_map = hr.u.d.u.group_info.outstream_group_map;
1105719f82d3SEliot Blennerhassett 	if (pinstream_map)
1106719f82d3SEliot Blennerhassett 		*pinstream_map = hr.u.d.u.group_info.instream_group_map;
1107719f82d3SEliot Blennerhassett 
1108719f82d3SEliot Blennerhassett 	return hr.error;
1109719f82d3SEliot Blennerhassett }
1110719f82d3SEliot Blennerhassett 
1111719f82d3SEliot Blennerhassett u16 hpi_outstream_group_reset(const struct hpi_hsubsys *ph_subsys,
1112719f82d3SEliot Blennerhassett 	u32 h_outstream)
1113719f82d3SEliot Blennerhassett {
1114719f82d3SEliot Blennerhassett 	struct hpi_message hm;
1115719f82d3SEliot Blennerhassett 	struct hpi_response hr;
1116719f82d3SEliot Blennerhassett 
1117719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
1118719f82d3SEliot Blennerhassett 		HPI_OSTREAM_GROUP_RESET);
1119719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
1120719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
1121719f82d3SEliot Blennerhassett 	return hr.error;
1122719f82d3SEliot Blennerhassett }
1123719f82d3SEliot Blennerhassett 
1124719f82d3SEliot Blennerhassett u16 hpi_instream_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index,
1125719f82d3SEliot Blennerhassett 	u16 instream_index, u32 *ph_instream)
1126719f82d3SEliot Blennerhassett {
1127719f82d3SEliot Blennerhassett 	struct hpi_message hm;
1128719f82d3SEliot Blennerhassett 	struct hpi_response hr;
1129719f82d3SEliot Blennerhassett 
1130719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1131719f82d3SEliot Blennerhassett 		HPI_ISTREAM_OPEN);
1132719f82d3SEliot Blennerhassett 	hm.adapter_index = adapter_index;
1133719f82d3SEliot Blennerhassett 	hm.obj_index = instream_index;
1134719f82d3SEliot Blennerhassett 
1135719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
1136719f82d3SEliot Blennerhassett 
1137719f82d3SEliot Blennerhassett 	if (hr.error == 0)
1138719f82d3SEliot Blennerhassett 		*ph_instream =
1139719f82d3SEliot Blennerhassett 			hpi_indexes_to_handle(HPI_OBJ_ISTREAM, adapter_index,
1140719f82d3SEliot Blennerhassett 			instream_index);
1141719f82d3SEliot Blennerhassett 	else
1142719f82d3SEliot Blennerhassett 		*ph_instream = 0;
1143719f82d3SEliot Blennerhassett 
1144719f82d3SEliot Blennerhassett 	return hr.error;
1145719f82d3SEliot Blennerhassett }
1146719f82d3SEliot Blennerhassett 
1147719f82d3SEliot Blennerhassett u16 hpi_instream_close(const struct hpi_hsubsys *ph_subsys, u32 h_instream)
1148719f82d3SEliot Blennerhassett {
1149719f82d3SEliot Blennerhassett 	struct hpi_message hm;
1150719f82d3SEliot Blennerhassett 	struct hpi_response hr;
1151719f82d3SEliot Blennerhassett 
1152719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1153719f82d3SEliot Blennerhassett 		HPI_ISTREAM_HOSTBUFFER_FREE);
1154719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
1155719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
1156719f82d3SEliot Blennerhassett 
1157719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1158719f82d3SEliot Blennerhassett 		HPI_ISTREAM_GROUP_RESET);
1159719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
1160719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
1161719f82d3SEliot Blennerhassett 
1162719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1163719f82d3SEliot Blennerhassett 		HPI_ISTREAM_CLOSE);
1164719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
1165719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
1166719f82d3SEliot Blennerhassett 
1167719f82d3SEliot Blennerhassett 	return hr.error;
1168719f82d3SEliot Blennerhassett }
1169719f82d3SEliot Blennerhassett 
1170719f82d3SEliot Blennerhassett u16 hpi_instream_query_format(const struct hpi_hsubsys *ph_subsys,
1171719f82d3SEliot Blennerhassett 	u32 h_instream, const struct hpi_format *p_format)
1172719f82d3SEliot Blennerhassett {
1173719f82d3SEliot Blennerhassett 	struct hpi_message hm;
1174719f82d3SEliot Blennerhassett 	struct hpi_response hr;
1175719f82d3SEliot Blennerhassett 
1176719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1177719f82d3SEliot Blennerhassett 		HPI_ISTREAM_QUERY_FORMAT);
1178719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
1179719f82d3SEliot Blennerhassett 	hpi_format_to_msg(&hm.u.d.u.data.format, p_format);
1180719f82d3SEliot Blennerhassett 
1181719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
1182719f82d3SEliot Blennerhassett 
1183719f82d3SEliot Blennerhassett 	return hr.error;
1184719f82d3SEliot Blennerhassett }
1185719f82d3SEliot Blennerhassett 
1186719f82d3SEliot Blennerhassett u16 hpi_instream_set_format(const struct hpi_hsubsys *ph_subsys,
1187719f82d3SEliot Blennerhassett 	u32 h_instream, const struct hpi_format *p_format)
1188719f82d3SEliot Blennerhassett {
1189719f82d3SEliot Blennerhassett 	struct hpi_message hm;
1190719f82d3SEliot Blennerhassett 	struct hpi_response hr;
1191719f82d3SEliot Blennerhassett 
1192719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1193719f82d3SEliot Blennerhassett 		HPI_ISTREAM_SET_FORMAT);
1194719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
1195719f82d3SEliot Blennerhassett 	hpi_format_to_msg(&hm.u.d.u.data.format, p_format);
1196719f82d3SEliot Blennerhassett 
1197719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
1198719f82d3SEliot Blennerhassett 
1199719f82d3SEliot Blennerhassett 	return hr.error;
1200719f82d3SEliot Blennerhassett }
1201719f82d3SEliot Blennerhassett 
1202719f82d3SEliot Blennerhassett u16 hpi_instream_read_buf(const struct hpi_hsubsys *ph_subsys, u32 h_instream,
1203719f82d3SEliot Blennerhassett 	u8 *pb_data, u32 bytes_to_read)
1204719f82d3SEliot Blennerhassett {
1205719f82d3SEliot Blennerhassett 	struct hpi_message hm;
1206719f82d3SEliot Blennerhassett 	struct hpi_response hr;
1207719f82d3SEliot Blennerhassett 
1208719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1209719f82d3SEliot Blennerhassett 		HPI_ISTREAM_READ);
1210719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
1211719f82d3SEliot Blennerhassett 	hm.u.d.u.data.data_size = bytes_to_read;
1212719f82d3SEliot Blennerhassett 	hm.u.d.u.data.pb_data = pb_data;
1213719f82d3SEliot Blennerhassett 
1214719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
1215719f82d3SEliot Blennerhassett 
1216719f82d3SEliot Blennerhassett 	return hr.error;
1217719f82d3SEliot Blennerhassett }
1218719f82d3SEliot Blennerhassett 
1219719f82d3SEliot Blennerhassett u16 hpi_instream_start(const struct hpi_hsubsys *ph_subsys, u32 h_instream)
1220719f82d3SEliot Blennerhassett {
1221719f82d3SEliot Blennerhassett 	struct hpi_message hm;
1222719f82d3SEliot Blennerhassett 	struct hpi_response hr;
1223719f82d3SEliot Blennerhassett 
1224719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1225719f82d3SEliot Blennerhassett 		HPI_ISTREAM_START);
1226719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
1227719f82d3SEliot Blennerhassett 
1228719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
1229719f82d3SEliot Blennerhassett 
1230719f82d3SEliot Blennerhassett 	return hr.error;
1231719f82d3SEliot Blennerhassett }
1232719f82d3SEliot Blennerhassett 
1233719f82d3SEliot Blennerhassett u16 hpi_instream_wait_start(const struct hpi_hsubsys *ph_subsys,
1234719f82d3SEliot Blennerhassett 	u32 h_instream)
1235719f82d3SEliot Blennerhassett {
1236719f82d3SEliot Blennerhassett 	struct hpi_message hm;
1237719f82d3SEliot Blennerhassett 	struct hpi_response hr;
1238719f82d3SEliot Blennerhassett 
1239719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1240719f82d3SEliot Blennerhassett 		HPI_ISTREAM_WAIT_START);
1241719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
1242719f82d3SEliot Blennerhassett 
1243719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
1244719f82d3SEliot Blennerhassett 
1245719f82d3SEliot Blennerhassett 	return hr.error;
1246719f82d3SEliot Blennerhassett }
1247719f82d3SEliot Blennerhassett 
1248719f82d3SEliot Blennerhassett u16 hpi_instream_stop(const struct hpi_hsubsys *ph_subsys, u32 h_instream)
1249719f82d3SEliot Blennerhassett {
1250719f82d3SEliot Blennerhassett 	struct hpi_message hm;
1251719f82d3SEliot Blennerhassett 	struct hpi_response hr;
1252719f82d3SEliot Blennerhassett 
1253719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1254719f82d3SEliot Blennerhassett 		HPI_ISTREAM_STOP);
1255719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
1256719f82d3SEliot Blennerhassett 
1257719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
1258719f82d3SEliot Blennerhassett 
1259719f82d3SEliot Blennerhassett 	return hr.error;
1260719f82d3SEliot Blennerhassett }
1261719f82d3SEliot Blennerhassett 
1262719f82d3SEliot Blennerhassett u16 hpi_instream_reset(const struct hpi_hsubsys *ph_subsys, u32 h_instream)
1263719f82d3SEliot Blennerhassett {
1264719f82d3SEliot Blennerhassett 	struct hpi_message hm;
1265719f82d3SEliot Blennerhassett 	struct hpi_response hr;
1266719f82d3SEliot Blennerhassett 
1267719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1268719f82d3SEliot Blennerhassett 		HPI_ISTREAM_RESET);
1269719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
1270719f82d3SEliot Blennerhassett 
1271719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
1272719f82d3SEliot Blennerhassett 
1273719f82d3SEliot Blennerhassett 	return hr.error;
1274719f82d3SEliot Blennerhassett }
1275719f82d3SEliot Blennerhassett 
1276719f82d3SEliot Blennerhassett u16 hpi_instream_get_info_ex(const struct hpi_hsubsys *ph_subsys,
1277719f82d3SEliot Blennerhassett 	u32 h_instream, u16 *pw_state, u32 *pbuffer_size, u32 *pdata_recorded,
1278719f82d3SEliot Blennerhassett 	u32 *psamples_recorded, u32 *pauxiliary_data_recorded)
1279719f82d3SEliot Blennerhassett {
1280719f82d3SEliot Blennerhassett 	struct hpi_message hm;
1281719f82d3SEliot Blennerhassett 	struct hpi_response hr;
1282719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1283719f82d3SEliot Blennerhassett 		HPI_ISTREAM_GET_INFO);
1284719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
1285719f82d3SEliot Blennerhassett 
1286719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
1287719f82d3SEliot Blennerhassett 
1288719f82d3SEliot Blennerhassett 	if (pw_state)
1289719f82d3SEliot Blennerhassett 		*pw_state = hr.u.d.u.stream_info.state;
1290719f82d3SEliot Blennerhassett 	if (pbuffer_size)
1291719f82d3SEliot Blennerhassett 		*pbuffer_size = hr.u.d.u.stream_info.buffer_size;
1292719f82d3SEliot Blennerhassett 	if (pdata_recorded)
1293719f82d3SEliot Blennerhassett 		*pdata_recorded = hr.u.d.u.stream_info.data_available;
1294719f82d3SEliot Blennerhassett 	if (psamples_recorded)
1295719f82d3SEliot Blennerhassett 		*psamples_recorded = hr.u.d.u.stream_info.samples_transferred;
1296719f82d3SEliot Blennerhassett 	if (pauxiliary_data_recorded)
1297719f82d3SEliot Blennerhassett 		*pauxiliary_data_recorded =
1298719f82d3SEliot Blennerhassett 			hr.u.d.u.stream_info.auxiliary_data_available;
1299719f82d3SEliot Blennerhassett 	return hr.error;
1300719f82d3SEliot Blennerhassett }
1301719f82d3SEliot Blennerhassett 
1302719f82d3SEliot Blennerhassett u16 hpi_instream_ancillary_reset(const struct hpi_hsubsys *ph_subsys,
1303719f82d3SEliot Blennerhassett 	u32 h_instream, u16 bytes_per_frame, u16 mode, u16 alignment,
1304719f82d3SEliot Blennerhassett 	u16 idle_bit)
1305719f82d3SEliot Blennerhassett {
1306719f82d3SEliot Blennerhassett 	struct hpi_message hm;
1307719f82d3SEliot Blennerhassett 	struct hpi_response hr;
1308719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1309719f82d3SEliot Blennerhassett 		HPI_ISTREAM_ANC_RESET);
1310719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
1311719f82d3SEliot Blennerhassett 	hm.u.d.u.data.format.attributes = bytes_per_frame;
1312719f82d3SEliot Blennerhassett 	hm.u.d.u.data.format.format = (mode << 8) | (alignment & 0xff);
1313719f82d3SEliot Blennerhassett 	hm.u.d.u.data.format.channels = idle_bit;
1314719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
1315719f82d3SEliot Blennerhassett 	return hr.error;
1316719f82d3SEliot Blennerhassett }
1317719f82d3SEliot Blennerhassett 
1318719f82d3SEliot Blennerhassett u16 hpi_instream_ancillary_get_info(const struct hpi_hsubsys *ph_subsys,
1319719f82d3SEliot Blennerhassett 	u32 h_instream, u32 *pframe_space)
1320719f82d3SEliot Blennerhassett {
1321719f82d3SEliot Blennerhassett 	struct hpi_message hm;
1322719f82d3SEliot Blennerhassett 	struct hpi_response hr;
1323719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1324719f82d3SEliot Blennerhassett 		HPI_ISTREAM_ANC_GET_INFO);
1325719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
1326719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
1327719f82d3SEliot Blennerhassett 	if (pframe_space)
1328719f82d3SEliot Blennerhassett 		*pframe_space =
1329719f82d3SEliot Blennerhassett 			(hr.u.d.u.stream_info.buffer_size -
1330719f82d3SEliot Blennerhassett 			hr.u.d.u.stream_info.data_available) /
1331719f82d3SEliot Blennerhassett 			sizeof(struct hpi_anc_frame);
1332719f82d3SEliot Blennerhassett 	return hr.error;
1333719f82d3SEliot Blennerhassett }
1334719f82d3SEliot Blennerhassett 
1335719f82d3SEliot Blennerhassett u16 hpi_instream_ancillary_write(const struct hpi_hsubsys *ph_subsys,
1336719f82d3SEliot Blennerhassett 	u32 h_instream, const struct hpi_anc_frame *p_anc_frame_buffer,
1337719f82d3SEliot Blennerhassett 	u32 anc_frame_buffer_size_in_bytes,
1338719f82d3SEliot Blennerhassett 	u32 number_of_ancillary_frames_to_write)
1339719f82d3SEliot Blennerhassett {
1340719f82d3SEliot Blennerhassett 	struct hpi_message hm;
1341719f82d3SEliot Blennerhassett 	struct hpi_response hr;
1342719f82d3SEliot Blennerhassett 
1343719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1344719f82d3SEliot Blennerhassett 		HPI_ISTREAM_ANC_WRITE);
1345719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
1346719f82d3SEliot Blennerhassett 	hm.u.d.u.data.pb_data = (u8 *)p_anc_frame_buffer;
1347719f82d3SEliot Blennerhassett 	hm.u.d.u.data.data_size =
1348719f82d3SEliot Blennerhassett 		number_of_ancillary_frames_to_write *
1349719f82d3SEliot Blennerhassett 		sizeof(struct hpi_anc_frame);
1350719f82d3SEliot Blennerhassett 	if (hm.u.d.u.data.data_size <= anc_frame_buffer_size_in_bytes)
1351719f82d3SEliot Blennerhassett 		hpi_send_recv(&hm, &hr);
1352719f82d3SEliot Blennerhassett 	else
1353719f82d3SEliot Blennerhassett 		hr.error = HPI_ERROR_INVALID_DATA_TRANSFER;
1354719f82d3SEliot Blennerhassett 	return hr.error;
1355719f82d3SEliot Blennerhassett }
1356719f82d3SEliot Blennerhassett 
1357719f82d3SEliot Blennerhassett u16 hpi_instream_host_buffer_allocate(const struct hpi_hsubsys *ph_subsys,
1358719f82d3SEliot Blennerhassett 	u32 h_instream, u32 size_in_bytes)
1359719f82d3SEliot Blennerhassett {
1360719f82d3SEliot Blennerhassett 
1361719f82d3SEliot Blennerhassett 	struct hpi_message hm;
1362719f82d3SEliot Blennerhassett 	struct hpi_response hr;
1363719f82d3SEliot Blennerhassett 
1364719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1365719f82d3SEliot Blennerhassett 		HPI_ISTREAM_HOSTBUFFER_ALLOC);
1366719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
1367719f82d3SEliot Blennerhassett 	hm.u.d.u.data.data_size = size_in_bytes;
1368719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
1369719f82d3SEliot Blennerhassett 	return hr.error;
1370719f82d3SEliot Blennerhassett }
1371719f82d3SEliot Blennerhassett 
1372719f82d3SEliot Blennerhassett u16 hpi_instream_host_buffer_get_info(const struct hpi_hsubsys *ph_subsys,
1373719f82d3SEliot Blennerhassett 	u32 h_instream, u8 **pp_buffer,
1374719f82d3SEliot Blennerhassett 	struct hpi_hostbuffer_status **pp_status)
1375719f82d3SEliot Blennerhassett {
1376719f82d3SEliot Blennerhassett 	struct hpi_message hm;
1377719f82d3SEliot Blennerhassett 	struct hpi_response hr;
1378719f82d3SEliot Blennerhassett 
1379719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1380719f82d3SEliot Blennerhassett 		HPI_ISTREAM_HOSTBUFFER_GET_INFO);
1381719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
1382719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
1383719f82d3SEliot Blennerhassett 
1384719f82d3SEliot Blennerhassett 	if (hr.error == 0) {
1385719f82d3SEliot Blennerhassett 		if (pp_buffer)
1386719f82d3SEliot Blennerhassett 			*pp_buffer = hr.u.d.u.hostbuffer_info.p_buffer;
1387719f82d3SEliot Blennerhassett 		if (pp_status)
1388719f82d3SEliot Blennerhassett 			*pp_status = hr.u.d.u.hostbuffer_info.p_status;
1389719f82d3SEliot Blennerhassett 	}
1390719f82d3SEliot Blennerhassett 	return hr.error;
1391719f82d3SEliot Blennerhassett }
1392719f82d3SEliot Blennerhassett 
1393719f82d3SEliot Blennerhassett u16 hpi_instream_host_buffer_free(const struct hpi_hsubsys *ph_subsys,
1394719f82d3SEliot Blennerhassett 	u32 h_instream)
1395719f82d3SEliot Blennerhassett {
1396719f82d3SEliot Blennerhassett 
1397719f82d3SEliot Blennerhassett 	struct hpi_message hm;
1398719f82d3SEliot Blennerhassett 	struct hpi_response hr;
1399719f82d3SEliot Blennerhassett 
1400719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1401719f82d3SEliot Blennerhassett 		HPI_ISTREAM_HOSTBUFFER_FREE);
1402719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
1403719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
1404719f82d3SEliot Blennerhassett 	return hr.error;
1405719f82d3SEliot Blennerhassett }
1406719f82d3SEliot Blennerhassett 
1407719f82d3SEliot Blennerhassett u16 hpi_instream_group_add(const struct hpi_hsubsys *ph_subsys,
1408719f82d3SEliot Blennerhassett 	u32 h_instream, u32 h_stream)
1409719f82d3SEliot Blennerhassett {
1410719f82d3SEliot Blennerhassett 	struct hpi_message hm;
1411719f82d3SEliot Blennerhassett 	struct hpi_response hr;
1412719f82d3SEliot Blennerhassett 	u16 adapter;
1413719f82d3SEliot Blennerhassett 	char c_obj_type;
1414719f82d3SEliot Blennerhassett 
1415719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1416719f82d3SEliot Blennerhassett 		HPI_ISTREAM_GROUP_ADD);
1417719f82d3SEliot Blennerhassett 	hr.error = 0;
1418719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
1419719f82d3SEliot Blennerhassett 	c_obj_type = hpi_handle_object(h_stream);
1420719f82d3SEliot Blennerhassett 
1421719f82d3SEliot Blennerhassett 	switch (c_obj_type) {
1422719f82d3SEliot Blennerhassett 	case HPI_OBJ_OSTREAM:
1423719f82d3SEliot Blennerhassett 		hm.u.d.u.stream.object_type = HPI_OBJ_OSTREAM;
1424719f82d3SEliot Blennerhassett 		u32TOINDEXES(h_stream, &adapter,
1425719f82d3SEliot Blennerhassett 			&hm.u.d.u.stream.stream_index);
1426719f82d3SEliot Blennerhassett 		break;
1427719f82d3SEliot Blennerhassett 	case HPI_OBJ_ISTREAM:
1428719f82d3SEliot Blennerhassett 		hm.u.d.u.stream.object_type = HPI_OBJ_ISTREAM;
1429719f82d3SEliot Blennerhassett 		u32TOINDEXES(h_stream, &adapter,
1430719f82d3SEliot Blennerhassett 			&hm.u.d.u.stream.stream_index);
1431719f82d3SEliot Blennerhassett 		break;
1432719f82d3SEliot Blennerhassett 	default:
1433719f82d3SEliot Blennerhassett 		return HPI_ERROR_INVALID_STREAM;
1434719f82d3SEliot Blennerhassett 	}
1435719f82d3SEliot Blennerhassett 
1436719f82d3SEliot Blennerhassett 	if (adapter != hm.adapter_index)
1437719f82d3SEliot Blennerhassett 		return HPI_ERROR_NO_INTERADAPTER_GROUPS;
1438719f82d3SEliot Blennerhassett 
1439719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
1440719f82d3SEliot Blennerhassett 	return hr.error;
1441719f82d3SEliot Blennerhassett }
1442719f82d3SEliot Blennerhassett 
1443719f82d3SEliot Blennerhassett u16 hpi_instream_group_get_map(const struct hpi_hsubsys *ph_subsys,
1444719f82d3SEliot Blennerhassett 	u32 h_instream, u32 *poutstream_map, u32 *pinstream_map)
1445719f82d3SEliot Blennerhassett {
1446719f82d3SEliot Blennerhassett 	struct hpi_message hm;
1447719f82d3SEliot Blennerhassett 	struct hpi_response hr;
1448719f82d3SEliot Blennerhassett 
1449719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1450719f82d3SEliot Blennerhassett 		HPI_ISTREAM_HOSTBUFFER_FREE);
1451719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
1452719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
1453719f82d3SEliot Blennerhassett 
1454719f82d3SEliot Blennerhassett 	if (poutstream_map)
1455719f82d3SEliot Blennerhassett 		*poutstream_map = hr.u.d.u.group_info.outstream_group_map;
1456719f82d3SEliot Blennerhassett 	if (pinstream_map)
1457719f82d3SEliot Blennerhassett 		*pinstream_map = hr.u.d.u.group_info.instream_group_map;
1458719f82d3SEliot Blennerhassett 
1459719f82d3SEliot Blennerhassett 	return hr.error;
1460719f82d3SEliot Blennerhassett }
1461719f82d3SEliot Blennerhassett 
1462719f82d3SEliot Blennerhassett u16 hpi_instream_group_reset(const struct hpi_hsubsys *ph_subsys,
1463719f82d3SEliot Blennerhassett 	u32 h_instream)
1464719f82d3SEliot Blennerhassett {
1465719f82d3SEliot Blennerhassett 	struct hpi_message hm;
1466719f82d3SEliot Blennerhassett 	struct hpi_response hr;
1467719f82d3SEliot Blennerhassett 
1468719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1469719f82d3SEliot Blennerhassett 		HPI_ISTREAM_GROUP_RESET);
1470719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
1471719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
1472719f82d3SEliot Blennerhassett 	return hr.error;
1473719f82d3SEliot Blennerhassett }
1474719f82d3SEliot Blennerhassett 
1475719f82d3SEliot Blennerhassett u16 hpi_mixer_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index,
1476719f82d3SEliot Blennerhassett 	u32 *ph_mixer)
1477719f82d3SEliot Blennerhassett {
1478719f82d3SEliot Blennerhassett 	struct hpi_message hm;
1479719f82d3SEliot Blennerhassett 	struct hpi_response hr;
1480719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER, HPI_MIXER_OPEN);
1481719f82d3SEliot Blennerhassett 	hm.adapter_index = adapter_index;
1482719f82d3SEliot Blennerhassett 
1483719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
1484719f82d3SEliot Blennerhassett 
1485719f82d3SEliot Blennerhassett 	if (hr.error == 0)
1486719f82d3SEliot Blennerhassett 		*ph_mixer =
1487719f82d3SEliot Blennerhassett 			hpi_indexes_to_handle(HPI_OBJ_MIXER, adapter_index,
1488719f82d3SEliot Blennerhassett 			0);
1489719f82d3SEliot Blennerhassett 	else
1490719f82d3SEliot Blennerhassett 		*ph_mixer = 0;
1491719f82d3SEliot Blennerhassett 	return hr.error;
1492719f82d3SEliot Blennerhassett }
1493719f82d3SEliot Blennerhassett 
1494719f82d3SEliot Blennerhassett u16 hpi_mixer_close(const struct hpi_hsubsys *ph_subsys, u32 h_mixer)
1495719f82d3SEliot Blennerhassett {
1496719f82d3SEliot Blennerhassett 	struct hpi_message hm;
1497719f82d3SEliot Blennerhassett 	struct hpi_response hr;
1498719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER, HPI_MIXER_CLOSE);
1499719f82d3SEliot Blennerhassett 	u32TOINDEX(h_mixer, &hm.adapter_index);
1500719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
1501719f82d3SEliot Blennerhassett 	return hr.error;
1502719f82d3SEliot Blennerhassett }
1503719f82d3SEliot Blennerhassett 
1504719f82d3SEliot Blennerhassett u16 hpi_mixer_get_control(const struct hpi_hsubsys *ph_subsys, u32 h_mixer,
1505719f82d3SEliot Blennerhassett 	u16 src_node_type, u16 src_node_type_index, u16 dst_node_type,
1506719f82d3SEliot Blennerhassett 	u16 dst_node_type_index, u16 control_type, u32 *ph_control)
1507719f82d3SEliot Blennerhassett {
1508719f82d3SEliot Blennerhassett 	struct hpi_message hm;
1509719f82d3SEliot Blennerhassett 	struct hpi_response hr;
1510719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER,
1511719f82d3SEliot Blennerhassett 		HPI_MIXER_GET_CONTROL);
1512719f82d3SEliot Blennerhassett 	u32TOINDEX(h_mixer, &hm.adapter_index);
1513719f82d3SEliot Blennerhassett 	hm.u.m.node_type1 = src_node_type;
1514719f82d3SEliot Blennerhassett 	hm.u.m.node_index1 = src_node_type_index;
1515719f82d3SEliot Blennerhassett 	hm.u.m.node_type2 = dst_node_type;
1516719f82d3SEliot Blennerhassett 	hm.u.m.node_index2 = dst_node_type_index;
1517719f82d3SEliot Blennerhassett 	hm.u.m.control_type = control_type;
1518719f82d3SEliot Blennerhassett 
1519719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
1520719f82d3SEliot Blennerhassett 
1521719f82d3SEliot Blennerhassett 	if (hr.error == 0)
1522719f82d3SEliot Blennerhassett 		*ph_control =
1523719f82d3SEliot Blennerhassett 			hpi_indexes_to_handle(HPI_OBJ_CONTROL,
1524719f82d3SEliot Blennerhassett 			hm.adapter_index, hr.u.m.control_index);
1525719f82d3SEliot Blennerhassett 	else
1526719f82d3SEliot Blennerhassett 		*ph_control = 0;
1527719f82d3SEliot Blennerhassett 	return hr.error;
1528719f82d3SEliot Blennerhassett }
1529719f82d3SEliot Blennerhassett 
1530719f82d3SEliot Blennerhassett u16 hpi_mixer_get_control_by_index(const struct hpi_hsubsys *ph_subsys,
1531719f82d3SEliot Blennerhassett 	u32 h_mixer, u16 control_index, u16 *pw_src_node_type,
1532719f82d3SEliot Blennerhassett 	u16 *pw_src_node_index, u16 *pw_dst_node_type, u16 *pw_dst_node_index,
1533719f82d3SEliot Blennerhassett 	u16 *pw_control_type, u32 *ph_control)
1534719f82d3SEliot Blennerhassett {
1535719f82d3SEliot Blennerhassett 	struct hpi_message hm;
1536719f82d3SEliot Blennerhassett 	struct hpi_response hr;
1537719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER,
1538719f82d3SEliot Blennerhassett 		HPI_MIXER_GET_CONTROL_BY_INDEX);
1539719f82d3SEliot Blennerhassett 	u32TOINDEX(h_mixer, &hm.adapter_index);
1540719f82d3SEliot Blennerhassett 	hm.u.m.control_index = control_index;
1541719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
1542719f82d3SEliot Blennerhassett 
1543719f82d3SEliot Blennerhassett 	if (pw_src_node_type) {
1544719f82d3SEliot Blennerhassett 		*pw_src_node_type =
1545719f82d3SEliot Blennerhassett 			hr.u.m.src_node_type + HPI_SOURCENODE_NONE;
1546719f82d3SEliot Blennerhassett 		*pw_src_node_index = hr.u.m.src_node_index;
1547719f82d3SEliot Blennerhassett 		*pw_dst_node_type = hr.u.m.dst_node_type + HPI_DESTNODE_NONE;
1548719f82d3SEliot Blennerhassett 		*pw_dst_node_index = hr.u.m.dst_node_index;
1549719f82d3SEliot Blennerhassett 	}
1550719f82d3SEliot Blennerhassett 	if (pw_control_type)
1551719f82d3SEliot Blennerhassett 		*pw_control_type = hr.u.m.control_index;
1552719f82d3SEliot Blennerhassett 
1553719f82d3SEliot Blennerhassett 	if (ph_control) {
1554719f82d3SEliot Blennerhassett 		if (hr.error == 0)
1555719f82d3SEliot Blennerhassett 			*ph_control =
1556719f82d3SEliot Blennerhassett 				hpi_indexes_to_handle(HPI_OBJ_CONTROL,
1557719f82d3SEliot Blennerhassett 				hm.adapter_index, control_index);
1558719f82d3SEliot Blennerhassett 		else
1559719f82d3SEliot Blennerhassett 			*ph_control = 0;
1560719f82d3SEliot Blennerhassett 	}
1561719f82d3SEliot Blennerhassett 	return hr.error;
1562719f82d3SEliot Blennerhassett }
1563719f82d3SEliot Blennerhassett 
1564719f82d3SEliot Blennerhassett u16 hpi_mixer_store(const struct hpi_hsubsys *ph_subsys, u32 h_mixer,
1565719f82d3SEliot Blennerhassett 	enum HPI_MIXER_STORE_COMMAND command, u16 index)
1566719f82d3SEliot Blennerhassett {
1567719f82d3SEliot Blennerhassett 	struct hpi_message hm;
1568719f82d3SEliot Blennerhassett 	struct hpi_response hr;
1569719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER, HPI_MIXER_STORE);
1570719f82d3SEliot Blennerhassett 	u32TOINDEX(h_mixer, &hm.adapter_index);
1571719f82d3SEliot Blennerhassett 	hm.u.mx.store.command = command;
1572719f82d3SEliot Blennerhassett 	hm.u.mx.store.index = index;
1573719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
1574719f82d3SEliot Blennerhassett 	return hr.error;
1575719f82d3SEliot Blennerhassett }
1576719f82d3SEliot Blennerhassett 
1577719f82d3SEliot Blennerhassett static
1578719f82d3SEliot Blennerhassett u16 hpi_control_param_set(const struct hpi_hsubsys *ph_subsys,
1579719f82d3SEliot Blennerhassett 	const u32 h_control, const u16 attrib, const u32 param1,
1580719f82d3SEliot Blennerhassett 	const u32 param2)
1581719f82d3SEliot Blennerhassett {
1582719f82d3SEliot Blennerhassett 	struct hpi_message hm;
1583719f82d3SEliot Blennerhassett 	struct hpi_response hr;
1584719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
1585719f82d3SEliot Blennerhassett 		HPI_CONTROL_SET_STATE);
1586719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
1587719f82d3SEliot Blennerhassett 	hm.u.c.attribute = attrib;
1588719f82d3SEliot Blennerhassett 	hm.u.c.param1 = param1;
1589719f82d3SEliot Blennerhassett 	hm.u.c.param2 = param2;
1590719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
1591719f82d3SEliot Blennerhassett 	return hr.error;
1592719f82d3SEliot Blennerhassett }
1593719f82d3SEliot Blennerhassett 
1594719f82d3SEliot Blennerhassett static
1595719f82d3SEliot Blennerhassett u16 hpi_control_param_get(const struct hpi_hsubsys *ph_subsys,
1596719f82d3SEliot Blennerhassett 	const u32 h_control, const u16 attrib, u32 param1, u32 param2,
1597719f82d3SEliot Blennerhassett 	u32 *pparam1, u32 *pparam2)
1598719f82d3SEliot Blennerhassett {
1599719f82d3SEliot Blennerhassett 	struct hpi_message hm;
1600719f82d3SEliot Blennerhassett 	struct hpi_response hr;
1601719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
1602719f82d3SEliot Blennerhassett 		HPI_CONTROL_GET_STATE);
1603719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
1604719f82d3SEliot Blennerhassett 	hm.u.c.attribute = attrib;
1605719f82d3SEliot Blennerhassett 	hm.u.c.param1 = param1;
1606719f82d3SEliot Blennerhassett 	hm.u.c.param2 = param2;
1607719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
1608719f82d3SEliot Blennerhassett 	if (pparam1)
1609719f82d3SEliot Blennerhassett 		*pparam1 = hr.u.c.param1;
1610719f82d3SEliot Blennerhassett 	if (pparam2)
1611719f82d3SEliot Blennerhassett 		*pparam2 = hr.u.c.param2;
1612719f82d3SEliot Blennerhassett 
1613719f82d3SEliot Blennerhassett 	return hr.error;
1614719f82d3SEliot Blennerhassett }
1615719f82d3SEliot Blennerhassett 
1616719f82d3SEliot Blennerhassett #define hpi_control_param1_get(s, h, a, p1) \
1617719f82d3SEliot Blennerhassett 		hpi_control_param_get(s, h, a, 0, 0, p1, NULL)
1618719f82d3SEliot Blennerhassett #define hpi_control_param2_get(s, h, a, p1, p2) \
1619719f82d3SEliot Blennerhassett 		hpi_control_param_get(s, h, a, 0, 0, p1, p2)
1620719f82d3SEliot Blennerhassett #define hpi_control_ex_param1_get(s, h, a, p1) \
1621719f82d3SEliot Blennerhassett 		hpi_control_ex_param_get(s, h, a, 0, 0, p1, NULL)
1622719f82d3SEliot Blennerhassett #define hpi_control_ex_param2_get(s, h, a, p1, p2) \
1623719f82d3SEliot Blennerhassett 		hpi_control_ex_param_get(s, h, a, 0, 0, p1, p2)
1624719f82d3SEliot Blennerhassett 
1625719f82d3SEliot Blennerhassett static
1626719f82d3SEliot Blennerhassett u16 hpi_control_query(const struct hpi_hsubsys *ph_subsys,
1627719f82d3SEliot Blennerhassett 	const u32 h_control, const u16 attrib, const u32 index,
1628719f82d3SEliot Blennerhassett 	const u32 param, u32 *psetting)
1629719f82d3SEliot Blennerhassett {
1630719f82d3SEliot Blennerhassett 	struct hpi_message hm;
1631719f82d3SEliot Blennerhassett 	struct hpi_response hr;
1632719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
1633719f82d3SEliot Blennerhassett 		HPI_CONTROL_GET_INFO);
1634719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
1635719f82d3SEliot Blennerhassett 
1636719f82d3SEliot Blennerhassett 	hm.u.c.attribute = attrib;
1637719f82d3SEliot Blennerhassett 	hm.u.c.param1 = index;
1638719f82d3SEliot Blennerhassett 	hm.u.c.param2 = param;
1639719f82d3SEliot Blennerhassett 
1640719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
1641719f82d3SEliot Blennerhassett 	*psetting = hr.u.c.param1;
1642719f82d3SEliot Blennerhassett 
1643719f82d3SEliot Blennerhassett 	return hr.error;
1644719f82d3SEliot Blennerhassett }
1645719f82d3SEliot Blennerhassett 
1646719f82d3SEliot Blennerhassett static u16 hpi_control_get_string(const struct hpi_hsubsys *ph_subsys,
1647719f82d3SEliot Blennerhassett 	const u32 h_control, const u16 attribute, char *psz_string,
1648719f82d3SEliot Blennerhassett 	const u32 string_length)
1649719f82d3SEliot Blennerhassett {
1650719f82d3SEliot Blennerhassett 	unsigned int sub_string_index = 0, j = 0;
1651719f82d3SEliot Blennerhassett 	char c = 0;
1652719f82d3SEliot Blennerhassett 	unsigned int n = 0;
1653719f82d3SEliot Blennerhassett 	u16 hE = 0;
1654719f82d3SEliot Blennerhassett 
1655719f82d3SEliot Blennerhassett 	if ((string_length < 1) || (string_length > 256))
1656719f82d3SEliot Blennerhassett 		return HPI_ERROR_INVALID_CONTROL_VALUE;
1657719f82d3SEliot Blennerhassett 	for (sub_string_index = 0; sub_string_index < string_length;
1658719f82d3SEliot Blennerhassett 		sub_string_index += 8) {
1659719f82d3SEliot Blennerhassett 		struct hpi_message hm;
1660719f82d3SEliot Blennerhassett 		struct hpi_response hr;
1661719f82d3SEliot Blennerhassett 
1662719f82d3SEliot Blennerhassett 		hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
1663719f82d3SEliot Blennerhassett 			HPI_CONTROL_GET_STATE);
1664719f82d3SEliot Blennerhassett 		u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
1665719f82d3SEliot Blennerhassett 		hm.u.c.attribute = attribute;
1666719f82d3SEliot Blennerhassett 		hm.u.c.param1 = sub_string_index;
1667719f82d3SEliot Blennerhassett 		hm.u.c.param2 = 0;
1668719f82d3SEliot Blennerhassett 		hpi_send_recv(&hm, &hr);
1669719f82d3SEliot Blennerhassett 
1670719f82d3SEliot Blennerhassett 		if (sub_string_index == 0
1671719f82d3SEliot Blennerhassett 			&& (hr.u.cu.chars8.remaining_chars + 8) >
1672719f82d3SEliot Blennerhassett 			string_length)
1673719f82d3SEliot Blennerhassett 			return HPI_ERROR_INVALID_CONTROL_VALUE;
1674719f82d3SEliot Blennerhassett 
1675719f82d3SEliot Blennerhassett 		if (hr.error) {
1676719f82d3SEliot Blennerhassett 			hE = hr.error;
1677719f82d3SEliot Blennerhassett 			break;
1678719f82d3SEliot Blennerhassett 		}
1679719f82d3SEliot Blennerhassett 		for (j = 0; j < 8; j++) {
1680719f82d3SEliot Blennerhassett 			c = hr.u.cu.chars8.sz_data[j];
1681719f82d3SEliot Blennerhassett 			psz_string[sub_string_index + j] = c;
1682719f82d3SEliot Blennerhassett 			n++;
1683719f82d3SEliot Blennerhassett 			if (n >= string_length) {
1684719f82d3SEliot Blennerhassett 				psz_string[string_length - 1] = 0;
1685719f82d3SEliot Blennerhassett 				hE = HPI_ERROR_INVALID_CONTROL_VALUE;
1686719f82d3SEliot Blennerhassett 				break;
1687719f82d3SEliot Blennerhassett 			}
1688719f82d3SEliot Blennerhassett 			if (c == 0)
1689719f82d3SEliot Blennerhassett 				break;
1690719f82d3SEliot Blennerhassett 		}
1691719f82d3SEliot Blennerhassett 
1692719f82d3SEliot Blennerhassett 		if ((hr.u.cu.chars8.remaining_chars == 0)
1693719f82d3SEliot Blennerhassett 			&& ((sub_string_index + j) < string_length)
1694719f82d3SEliot Blennerhassett 			&& (c != 0)) {
1695719f82d3SEliot Blennerhassett 			c = 0;
1696719f82d3SEliot Blennerhassett 			psz_string[sub_string_index + j] = c;
1697719f82d3SEliot Blennerhassett 		}
1698719f82d3SEliot Blennerhassett 		if (c == 0)
1699719f82d3SEliot Blennerhassett 			break;
1700719f82d3SEliot Blennerhassett 	}
1701719f82d3SEliot Blennerhassett 	return hE;
1702719f82d3SEliot Blennerhassett }
1703719f82d3SEliot Blennerhassett 
1704719f82d3SEliot Blennerhassett u16 HPI_AESEBU__receiver_query_format(const struct hpi_hsubsys *ph_subsys,
1705719f82d3SEliot Blennerhassett 	const u32 h_aes_rx, const u32 index, u16 *pw_format)
1706719f82d3SEliot Blennerhassett {
1707719f82d3SEliot Blennerhassett 	u32 qr;
1708719f82d3SEliot Blennerhassett 	u16 err;
1709719f82d3SEliot Blennerhassett 
1710719f82d3SEliot Blennerhassett 	err = hpi_control_query(ph_subsys, h_aes_rx, HPI_AESEBURX_FORMAT,
1711719f82d3SEliot Blennerhassett 		index, 0, &qr);
1712719f82d3SEliot Blennerhassett 	*pw_format = (u16)qr;
1713719f82d3SEliot Blennerhassett 	return err;
1714719f82d3SEliot Blennerhassett }
1715719f82d3SEliot Blennerhassett 
1716719f82d3SEliot Blennerhassett u16 HPI_AESEBU__receiver_set_format(const struct hpi_hsubsys *ph_subsys,
1717719f82d3SEliot Blennerhassett 	u32 h_control, u16 format)
1718719f82d3SEliot Blennerhassett {
1719719f82d3SEliot Blennerhassett 	return hpi_control_param_set(ph_subsys, h_control,
1720719f82d3SEliot Blennerhassett 		HPI_AESEBURX_FORMAT, format, 0);
1721719f82d3SEliot Blennerhassett }
1722719f82d3SEliot Blennerhassett 
1723719f82d3SEliot Blennerhassett u16 HPI_AESEBU__receiver_get_format(const struct hpi_hsubsys *ph_subsys,
1724719f82d3SEliot Blennerhassett 	u32 h_control, u16 *pw_format)
1725719f82d3SEliot Blennerhassett {
1726719f82d3SEliot Blennerhassett 	u16 err;
1727719f82d3SEliot Blennerhassett 	u32 param;
1728719f82d3SEliot Blennerhassett 
1729719f82d3SEliot Blennerhassett 	err = hpi_control_param1_get(ph_subsys, h_control,
1730719f82d3SEliot Blennerhassett 		HPI_AESEBURX_FORMAT, &param);
1731719f82d3SEliot Blennerhassett 	if (!err && pw_format)
1732719f82d3SEliot Blennerhassett 		*pw_format = (u16)param;
1733719f82d3SEliot Blennerhassett 
1734719f82d3SEliot Blennerhassett 	return err;
1735719f82d3SEliot Blennerhassett }
1736719f82d3SEliot Blennerhassett 
1737719f82d3SEliot Blennerhassett u16 HPI_AESEBU__receiver_get_sample_rate(const struct hpi_hsubsys *ph_subsys,
1738719f82d3SEliot Blennerhassett 	u32 h_control, u32 *psample_rate)
1739719f82d3SEliot Blennerhassett {
1740719f82d3SEliot Blennerhassett 	return hpi_control_param1_get(ph_subsys, h_control,
1741719f82d3SEliot Blennerhassett 		HPI_AESEBURX_SAMPLERATE, psample_rate);
1742719f82d3SEliot Blennerhassett }
1743719f82d3SEliot Blennerhassett 
1744719f82d3SEliot Blennerhassett u16 HPI_AESEBU__receiver_get_user_data(const struct hpi_hsubsys *ph_subsys,
1745719f82d3SEliot Blennerhassett 	u32 h_control, u16 index, u16 *pw_data)
1746719f82d3SEliot Blennerhassett {
1747719f82d3SEliot Blennerhassett 	struct hpi_message hm;
1748719f82d3SEliot Blennerhassett 	struct hpi_response hr;
1749719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
1750719f82d3SEliot Blennerhassett 		HPI_CONTROL_GET_STATE);
1751719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
1752719f82d3SEliot Blennerhassett 	hm.u.c.attribute = HPI_AESEBURX_USERDATA;
1753719f82d3SEliot Blennerhassett 	hm.u.c.param1 = index;
1754719f82d3SEliot Blennerhassett 
1755719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
1756719f82d3SEliot Blennerhassett 
1757719f82d3SEliot Blennerhassett 	if (pw_data)
1758719f82d3SEliot Blennerhassett 		*pw_data = (u16)hr.u.c.param2;
1759719f82d3SEliot Blennerhassett 	return hr.error;
1760719f82d3SEliot Blennerhassett }
1761719f82d3SEliot Blennerhassett 
1762719f82d3SEliot Blennerhassett u16 HPI_AESEBU__receiver_get_channel_status(const struct hpi_hsubsys
1763719f82d3SEliot Blennerhassett 	*ph_subsys, u32 h_control, u16 index, u16 *pw_data)
1764719f82d3SEliot Blennerhassett {
1765719f82d3SEliot Blennerhassett 	struct hpi_message hm;
1766719f82d3SEliot Blennerhassett 	struct hpi_response hr;
1767719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
1768719f82d3SEliot Blennerhassett 		HPI_CONTROL_GET_STATE);
1769719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
1770719f82d3SEliot Blennerhassett 	hm.u.c.attribute = HPI_AESEBURX_CHANNELSTATUS;
1771719f82d3SEliot Blennerhassett 	hm.u.c.param1 = index;
1772719f82d3SEliot Blennerhassett 
1773719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
1774719f82d3SEliot Blennerhassett 
1775719f82d3SEliot Blennerhassett 	if (pw_data)
1776719f82d3SEliot Blennerhassett 		*pw_data = (u16)hr.u.c.param2;
1777719f82d3SEliot Blennerhassett 	return hr.error;
1778719f82d3SEliot Blennerhassett }
1779719f82d3SEliot Blennerhassett 
1780719f82d3SEliot Blennerhassett u16 HPI_AESEBU__receiver_get_error_status(const struct hpi_hsubsys *ph_subsys,
1781719f82d3SEliot Blennerhassett 	u32 h_control, u16 *pw_error_data)
1782719f82d3SEliot Blennerhassett {
1783719f82d3SEliot Blennerhassett 	u32 error_data = 0;
1784719f82d3SEliot Blennerhassett 	u16 error = 0;
1785719f82d3SEliot Blennerhassett 
1786719f82d3SEliot Blennerhassett 	error = hpi_control_param1_get(ph_subsys, h_control,
1787719f82d3SEliot Blennerhassett 		HPI_AESEBURX_ERRORSTATUS, &error_data);
1788719f82d3SEliot Blennerhassett 	if (pw_error_data)
1789719f82d3SEliot Blennerhassett 		*pw_error_data = (u16)error_data;
1790719f82d3SEliot Blennerhassett 	return error;
1791719f82d3SEliot Blennerhassett }
1792719f82d3SEliot Blennerhassett 
1793719f82d3SEliot Blennerhassett u16 HPI_AESEBU__transmitter_set_sample_rate(const struct hpi_hsubsys
1794719f82d3SEliot Blennerhassett 	*ph_subsys, u32 h_control, u32 sample_rate)
1795719f82d3SEliot Blennerhassett {
1796719f82d3SEliot Blennerhassett 	return hpi_control_param_set(ph_subsys, h_control,
1797719f82d3SEliot Blennerhassett 		HPI_AESEBUTX_SAMPLERATE, sample_rate, 0);
1798719f82d3SEliot Blennerhassett }
1799719f82d3SEliot Blennerhassett 
1800719f82d3SEliot Blennerhassett u16 HPI_AESEBU__transmitter_set_user_data(const struct hpi_hsubsys *ph_subsys,
1801719f82d3SEliot Blennerhassett 	u32 h_control, u16 index, u16 data)
1802719f82d3SEliot Blennerhassett {
1803719f82d3SEliot Blennerhassett 	return hpi_control_param_set(ph_subsys, h_control,
1804719f82d3SEliot Blennerhassett 		HPI_AESEBUTX_USERDATA, index, data);
1805719f82d3SEliot Blennerhassett }
1806719f82d3SEliot Blennerhassett 
1807719f82d3SEliot Blennerhassett u16 HPI_AESEBU__transmitter_set_channel_status(const struct hpi_hsubsys
1808719f82d3SEliot Blennerhassett 	*ph_subsys, u32 h_control, u16 index, u16 data)
1809719f82d3SEliot Blennerhassett {
1810719f82d3SEliot Blennerhassett 	return hpi_control_param_set(ph_subsys, h_control,
1811719f82d3SEliot Blennerhassett 		HPI_AESEBUTX_CHANNELSTATUS, index, data);
1812719f82d3SEliot Blennerhassett }
1813719f82d3SEliot Blennerhassett 
1814719f82d3SEliot Blennerhassett u16 HPI_AESEBU__transmitter_get_channel_status(const struct hpi_hsubsys
1815719f82d3SEliot Blennerhassett 	*ph_subsys, u32 h_control, u16 index, u16 *pw_data)
1816719f82d3SEliot Blennerhassett {
1817719f82d3SEliot Blennerhassett 	return HPI_ERROR_INVALID_OPERATION;
1818719f82d3SEliot Blennerhassett }
1819719f82d3SEliot Blennerhassett 
1820719f82d3SEliot Blennerhassett u16 HPI_AESEBU__transmitter_query_format(const struct hpi_hsubsys *ph_subsys,
1821719f82d3SEliot Blennerhassett 	const u32 h_aes_tx, const u32 index, u16 *pw_format)
1822719f82d3SEliot Blennerhassett {
1823719f82d3SEliot Blennerhassett 	u32 qr;
1824719f82d3SEliot Blennerhassett 	u16 err;
1825719f82d3SEliot Blennerhassett 
1826719f82d3SEliot Blennerhassett 	err = hpi_control_query(ph_subsys, h_aes_tx, HPI_AESEBUTX_FORMAT,
1827719f82d3SEliot Blennerhassett 		index, 0, &qr);
1828719f82d3SEliot Blennerhassett 	*pw_format = (u16)qr;
1829719f82d3SEliot Blennerhassett 	return err;
1830719f82d3SEliot Blennerhassett }
1831719f82d3SEliot Blennerhassett 
1832719f82d3SEliot Blennerhassett u16 HPI_AESEBU__transmitter_set_format(const struct hpi_hsubsys *ph_subsys,
1833719f82d3SEliot Blennerhassett 	u32 h_control, u16 output_format)
1834719f82d3SEliot Blennerhassett {
1835719f82d3SEliot Blennerhassett 	return hpi_control_param_set(ph_subsys, h_control,
1836719f82d3SEliot Blennerhassett 		HPI_AESEBUTX_FORMAT, output_format, 0);
1837719f82d3SEliot Blennerhassett }
1838719f82d3SEliot Blennerhassett 
1839719f82d3SEliot Blennerhassett u16 HPI_AESEBU__transmitter_get_format(const struct hpi_hsubsys *ph_subsys,
1840719f82d3SEliot Blennerhassett 	u32 h_control, u16 *pw_output_format)
1841719f82d3SEliot Blennerhassett {
1842719f82d3SEliot Blennerhassett 	u16 err;
1843719f82d3SEliot Blennerhassett 	u32 param;
1844719f82d3SEliot Blennerhassett 
1845719f82d3SEliot Blennerhassett 	err = hpi_control_param1_get(ph_subsys, h_control,
1846719f82d3SEliot Blennerhassett 		HPI_AESEBUTX_FORMAT, &param);
1847719f82d3SEliot Blennerhassett 	if (!err && pw_output_format)
1848719f82d3SEliot Blennerhassett 		*pw_output_format = (u16)param;
1849719f82d3SEliot Blennerhassett 
1850719f82d3SEliot Blennerhassett 	return err;
1851719f82d3SEliot Blennerhassett }
1852719f82d3SEliot Blennerhassett 
1853719f82d3SEliot Blennerhassett u16 hpi_bitstream_set_clock_edge(const struct hpi_hsubsys *ph_subsys,
1854719f82d3SEliot Blennerhassett 	u32 h_control, u16 edge_type)
1855719f82d3SEliot Blennerhassett {
1856719f82d3SEliot Blennerhassett 	return hpi_control_param_set(ph_subsys, h_control,
1857719f82d3SEliot Blennerhassett 		HPI_BITSTREAM_CLOCK_EDGE, edge_type, 0);
1858719f82d3SEliot Blennerhassett }
1859719f82d3SEliot Blennerhassett 
1860719f82d3SEliot Blennerhassett u16 hpi_bitstream_set_data_polarity(const struct hpi_hsubsys *ph_subsys,
1861719f82d3SEliot Blennerhassett 	u32 h_control, u16 polarity)
1862719f82d3SEliot Blennerhassett {
1863719f82d3SEliot Blennerhassett 	return hpi_control_param_set(ph_subsys, h_control,
1864719f82d3SEliot Blennerhassett 		HPI_BITSTREAM_DATA_POLARITY, polarity, 0);
1865719f82d3SEliot Blennerhassett }
1866719f82d3SEliot Blennerhassett 
1867719f82d3SEliot Blennerhassett u16 hpi_bitstream_get_activity(const struct hpi_hsubsys *ph_subsys,
1868719f82d3SEliot Blennerhassett 	u32 h_control, u16 *pw_clk_activity, u16 *pw_data_activity)
1869719f82d3SEliot Blennerhassett {
1870719f82d3SEliot Blennerhassett 	struct hpi_message hm;
1871719f82d3SEliot Blennerhassett 	struct hpi_response hr;
1872719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
1873719f82d3SEliot Blennerhassett 		HPI_CONTROL_GET_STATE);
1874719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
1875719f82d3SEliot Blennerhassett 	hm.u.c.attribute = HPI_BITSTREAM_ACTIVITY;
1876719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
1877719f82d3SEliot Blennerhassett 	if (pw_clk_activity)
1878719f82d3SEliot Blennerhassett 		*pw_clk_activity = (u16)hr.u.c.param1;
1879719f82d3SEliot Blennerhassett 	if (pw_data_activity)
1880719f82d3SEliot Blennerhassett 		*pw_data_activity = (u16)hr.u.c.param2;
1881719f82d3SEliot Blennerhassett 	return hr.error;
1882719f82d3SEliot Blennerhassett }
1883719f82d3SEliot Blennerhassett 
1884719f82d3SEliot Blennerhassett u16 hpi_channel_mode_query_mode(const struct hpi_hsubsys *ph_subsys,
1885719f82d3SEliot Blennerhassett 	const u32 h_mode, const u32 index, u16 *pw_mode)
1886719f82d3SEliot Blennerhassett {
1887719f82d3SEliot Blennerhassett 	u32 qr;
1888719f82d3SEliot Blennerhassett 	u16 err;
1889719f82d3SEliot Blennerhassett 
1890719f82d3SEliot Blennerhassett 	err = hpi_control_query(ph_subsys, h_mode, HPI_CHANNEL_MODE_MODE,
1891719f82d3SEliot Blennerhassett 		index, 0, &qr);
1892719f82d3SEliot Blennerhassett 	*pw_mode = (u16)qr;
1893719f82d3SEliot Blennerhassett 	return err;
1894719f82d3SEliot Blennerhassett }
1895719f82d3SEliot Blennerhassett 
1896719f82d3SEliot Blennerhassett u16 hpi_channel_mode_set(const struct hpi_hsubsys *ph_subsys, u32 h_control,
1897719f82d3SEliot Blennerhassett 	u16 mode)
1898719f82d3SEliot Blennerhassett {
1899719f82d3SEliot Blennerhassett 	return hpi_control_param_set(ph_subsys, h_control,
1900719f82d3SEliot Blennerhassett 		HPI_CHANNEL_MODE_MODE, mode, 0);
1901719f82d3SEliot Blennerhassett }
1902719f82d3SEliot Blennerhassett 
1903719f82d3SEliot Blennerhassett u16 hpi_channel_mode_get(const struct hpi_hsubsys *ph_subsys, u32 h_control,
1904719f82d3SEliot Blennerhassett 	u16 *mode)
1905719f82d3SEliot Blennerhassett {
1906719f82d3SEliot Blennerhassett 	u32 mode32 = 0;
1907719f82d3SEliot Blennerhassett 	u16 error = hpi_control_param1_get(ph_subsys, h_control,
1908719f82d3SEliot Blennerhassett 		HPI_CHANNEL_MODE_MODE, &mode32);
1909719f82d3SEliot Blennerhassett 	if (mode)
1910719f82d3SEliot Blennerhassett 		*mode = (u16)mode32;
1911719f82d3SEliot Blennerhassett 	return error;
1912719f82d3SEliot Blennerhassett }
1913719f82d3SEliot Blennerhassett 
1914719f82d3SEliot Blennerhassett u16 hpi_cobranet_hmi_write(const struct hpi_hsubsys *ph_subsys, u32 h_control,
1915719f82d3SEliot Blennerhassett 	u32 hmi_address, u32 byte_count, u8 *pb_data)
1916719f82d3SEliot Blennerhassett {
1917719f82d3SEliot Blennerhassett 	struct hpi_message hm;
1918719f82d3SEliot Blennerhassett 	struct hpi_response hr;
1919719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROLEX,
1920719f82d3SEliot Blennerhassett 		HPI_CONTROL_SET_STATE);
1921719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
1922719f82d3SEliot Blennerhassett 
1923719f82d3SEliot Blennerhassett 	hm.u.cx.u.cobranet_data.byte_count = byte_count;
1924719f82d3SEliot Blennerhassett 	hm.u.cx.u.cobranet_data.hmi_address = hmi_address;
1925719f82d3SEliot Blennerhassett 
1926719f82d3SEliot Blennerhassett 	if (byte_count <= 8) {
1927719f82d3SEliot Blennerhassett 		memcpy(hm.u.cx.u.cobranet_data.data, pb_data, byte_count);
1928719f82d3SEliot Blennerhassett 		hm.u.cx.attribute = HPI_COBRANET_SET;
1929719f82d3SEliot Blennerhassett 	} else {
1930719f82d3SEliot Blennerhassett 		hm.u.cx.u.cobranet_bigdata.pb_data = pb_data;
1931719f82d3SEliot Blennerhassett 		hm.u.cx.attribute = HPI_COBRANET_SET_DATA;
1932719f82d3SEliot Blennerhassett 	}
1933719f82d3SEliot Blennerhassett 
1934719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
1935719f82d3SEliot Blennerhassett 
1936719f82d3SEliot Blennerhassett 	return hr.error;
1937719f82d3SEliot Blennerhassett }
1938719f82d3SEliot Blennerhassett 
1939719f82d3SEliot Blennerhassett u16 hpi_cobranet_hmi_read(const struct hpi_hsubsys *ph_subsys, u32 h_control,
1940719f82d3SEliot Blennerhassett 	u32 hmi_address, u32 max_byte_count, u32 *pbyte_count, u8 *pb_data)
1941719f82d3SEliot Blennerhassett {
1942719f82d3SEliot Blennerhassett 	struct hpi_message hm;
1943719f82d3SEliot Blennerhassett 	struct hpi_response hr;
1944719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROLEX,
1945719f82d3SEliot Blennerhassett 		HPI_CONTROL_GET_STATE);
1946719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
1947719f82d3SEliot Blennerhassett 
1948719f82d3SEliot Blennerhassett 	hm.u.cx.u.cobranet_data.byte_count = max_byte_count;
1949719f82d3SEliot Blennerhassett 	hm.u.cx.u.cobranet_data.hmi_address = hmi_address;
1950719f82d3SEliot Blennerhassett 
1951719f82d3SEliot Blennerhassett 	if (max_byte_count <= 8) {
1952719f82d3SEliot Blennerhassett 		hm.u.cx.attribute = HPI_COBRANET_GET;
1953719f82d3SEliot Blennerhassett 	} else {
1954719f82d3SEliot Blennerhassett 		hm.u.cx.u.cobranet_bigdata.pb_data = pb_data;
1955719f82d3SEliot Blennerhassett 		hm.u.cx.attribute = HPI_COBRANET_GET_DATA;
1956719f82d3SEliot Blennerhassett 	}
1957719f82d3SEliot Blennerhassett 
1958719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
1959719f82d3SEliot Blennerhassett 	if (!hr.error && pb_data) {
1960719f82d3SEliot Blennerhassett 
1961719f82d3SEliot Blennerhassett 		*pbyte_count = hr.u.cx.u.cobranet_data.byte_count;
1962719f82d3SEliot Blennerhassett 
1963719f82d3SEliot Blennerhassett 		if (*pbyte_count < max_byte_count)
1964719f82d3SEliot Blennerhassett 			max_byte_count = *pbyte_count;
1965719f82d3SEliot Blennerhassett 
1966719f82d3SEliot Blennerhassett 		if (hm.u.cx.attribute == HPI_COBRANET_GET) {
1967719f82d3SEliot Blennerhassett 			memcpy(pb_data, hr.u.cx.u.cobranet_data.data,
1968719f82d3SEliot Blennerhassett 				max_byte_count);
1969719f82d3SEliot Blennerhassett 		} else {
1970719f82d3SEliot Blennerhassett 
1971719f82d3SEliot Blennerhassett 		}
1972719f82d3SEliot Blennerhassett 
1973719f82d3SEliot Blennerhassett 	}
1974719f82d3SEliot Blennerhassett 	return hr.error;
1975719f82d3SEliot Blennerhassett }
1976719f82d3SEliot Blennerhassett 
1977719f82d3SEliot Blennerhassett u16 hpi_cobranet_hmi_get_status(const struct hpi_hsubsys *ph_subsys,
1978719f82d3SEliot Blennerhassett 	u32 h_control, u32 *pstatus, u32 *preadable_size,
1979719f82d3SEliot Blennerhassett 	u32 *pwriteable_size)
1980719f82d3SEliot Blennerhassett {
1981719f82d3SEliot Blennerhassett 	struct hpi_message hm;
1982719f82d3SEliot Blennerhassett 	struct hpi_response hr;
1983719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROLEX,
1984719f82d3SEliot Blennerhassett 		HPI_CONTROL_GET_STATE);
1985719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
1986719f82d3SEliot Blennerhassett 
1987719f82d3SEliot Blennerhassett 	hm.u.cx.attribute = HPI_COBRANET_GET_STATUS;
1988719f82d3SEliot Blennerhassett 
1989719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
1990719f82d3SEliot Blennerhassett 	if (!hr.error) {
1991719f82d3SEliot Blennerhassett 		if (pstatus)
1992719f82d3SEliot Blennerhassett 			*pstatus = hr.u.cx.u.cobranet_status.status;
1993719f82d3SEliot Blennerhassett 		if (preadable_size)
1994719f82d3SEliot Blennerhassett 			*preadable_size =
1995719f82d3SEliot Blennerhassett 				hr.u.cx.u.cobranet_status.readable_size;
1996719f82d3SEliot Blennerhassett 		if (pwriteable_size)
1997719f82d3SEliot Blennerhassett 			*pwriteable_size =
1998719f82d3SEliot Blennerhassett 				hr.u.cx.u.cobranet_status.writeable_size;
1999719f82d3SEliot Blennerhassett 	}
2000719f82d3SEliot Blennerhassett 	return hr.error;
2001719f82d3SEliot Blennerhassett }
2002719f82d3SEliot Blennerhassett 
2003719f82d3SEliot Blennerhassett u16 hpi_cobranet_getI_paddress(const struct hpi_hsubsys *ph_subsys,
2004719f82d3SEliot Blennerhassett 	u32 h_control, u32 *pi_paddress)
2005719f82d3SEliot Blennerhassett {
2006719f82d3SEliot Blennerhassett 	u32 byte_count;
2007719f82d3SEliot Blennerhassett 	u32 iP;
2008719f82d3SEliot Blennerhassett 	u16 error;
2009719f82d3SEliot Blennerhassett 	error = hpi_cobranet_hmi_read(ph_subsys, h_control,
2010719f82d3SEliot Blennerhassett 		HPI_COBRANET_HMI_cobra_ip_mon_currentIP, 4, &byte_count,
2011719f82d3SEliot Blennerhassett 		(u8 *)&iP);
2012719f82d3SEliot Blennerhassett 
2013719f82d3SEliot Blennerhassett 	*pi_paddress =
2014719f82d3SEliot Blennerhassett 		((iP & 0xff000000) >> 8) | ((iP & 0x00ff0000) << 8) | ((iP &
2015719f82d3SEliot Blennerhassett 			0x0000ff00) >> 8) | ((iP & 0x000000ff) << 8);
2016719f82d3SEliot Blennerhassett 
2017719f82d3SEliot Blennerhassett 	if (error)
2018719f82d3SEliot Blennerhassett 		*pi_paddress = 0;
2019719f82d3SEliot Blennerhassett 
2020719f82d3SEliot Blennerhassett 	return error;
2021719f82d3SEliot Blennerhassett 
2022719f82d3SEliot Blennerhassett }
2023719f82d3SEliot Blennerhassett 
2024719f82d3SEliot Blennerhassett u16 hpi_cobranet_setI_paddress(const struct hpi_hsubsys *ph_subsys,
2025719f82d3SEliot Blennerhassett 	u32 h_control, u32 i_paddress)
2026719f82d3SEliot Blennerhassett {
2027719f82d3SEliot Blennerhassett 	u32 iP;
2028719f82d3SEliot Blennerhassett 	u16 error;
2029719f82d3SEliot Blennerhassett 
2030719f82d3SEliot Blennerhassett 	iP = ((i_paddress & 0xff000000) >> 8) | ((i_paddress & 0x00ff0000) <<
2031719f82d3SEliot Blennerhassett 		8) | ((i_paddress & 0x0000ff00) >> 8) | ((i_paddress &
2032719f82d3SEliot Blennerhassett 			0x000000ff) << 8);
2033719f82d3SEliot Blennerhassett 
2034719f82d3SEliot Blennerhassett 	error = hpi_cobranet_hmi_write(ph_subsys, h_control,
2035719f82d3SEliot Blennerhassett 		HPI_COBRANET_HMI_cobra_ip_mon_currentIP, 4, (u8 *)&iP);
2036719f82d3SEliot Blennerhassett 
2037719f82d3SEliot Blennerhassett 	return error;
2038719f82d3SEliot Blennerhassett 
2039719f82d3SEliot Blennerhassett }
2040719f82d3SEliot Blennerhassett 
2041719f82d3SEliot Blennerhassett u16 hpi_cobranet_get_staticI_paddress(const struct hpi_hsubsys *ph_subsys,
2042719f82d3SEliot Blennerhassett 	u32 h_control, u32 *pi_paddress)
2043719f82d3SEliot Blennerhassett {
2044719f82d3SEliot Blennerhassett 	u32 byte_count;
2045719f82d3SEliot Blennerhassett 	u32 iP;
2046719f82d3SEliot Blennerhassett 	u16 error;
2047719f82d3SEliot Blennerhassett 	error = hpi_cobranet_hmi_read(ph_subsys, h_control,
2048719f82d3SEliot Blennerhassett 		HPI_COBRANET_HMI_cobra_ip_mon_staticIP, 4, &byte_count,
2049719f82d3SEliot Blennerhassett 		(u8 *)&iP);
2050719f82d3SEliot Blennerhassett 
2051719f82d3SEliot Blennerhassett 	*pi_paddress =
2052719f82d3SEliot Blennerhassett 		((iP & 0xff000000) >> 8) | ((iP & 0x00ff0000) << 8) | ((iP &
2053719f82d3SEliot Blennerhassett 			0x0000ff00) >> 8) | ((iP & 0x000000ff) << 8);
2054719f82d3SEliot Blennerhassett 
2055719f82d3SEliot Blennerhassett 	if (error)
2056719f82d3SEliot Blennerhassett 		*pi_paddress = 0;
2057719f82d3SEliot Blennerhassett 
2058719f82d3SEliot Blennerhassett 	return error;
2059719f82d3SEliot Blennerhassett 
2060719f82d3SEliot Blennerhassett }
2061719f82d3SEliot Blennerhassett 
2062719f82d3SEliot Blennerhassett u16 hpi_cobranet_set_staticI_paddress(const struct hpi_hsubsys *ph_subsys,
2063719f82d3SEliot Blennerhassett 	u32 h_control, u32 i_paddress)
2064719f82d3SEliot Blennerhassett {
2065719f82d3SEliot Blennerhassett 	u32 iP;
2066719f82d3SEliot Blennerhassett 	u16 error;
2067719f82d3SEliot Blennerhassett 
2068719f82d3SEliot Blennerhassett 	iP = ((i_paddress & 0xff000000) >> 8) | ((i_paddress & 0x00ff0000) <<
2069719f82d3SEliot Blennerhassett 		8) | ((i_paddress & 0x0000ff00) >> 8) | ((i_paddress &
2070719f82d3SEliot Blennerhassett 			0x000000ff) << 8);
2071719f82d3SEliot Blennerhassett 
2072719f82d3SEliot Blennerhassett 	error = hpi_cobranet_hmi_write(ph_subsys, h_control,
2073719f82d3SEliot Blennerhassett 		HPI_COBRANET_HMI_cobra_ip_mon_staticIP, 4, (u8 *)&iP);
2074719f82d3SEliot Blennerhassett 
2075719f82d3SEliot Blennerhassett 	return error;
2076719f82d3SEliot Blennerhassett 
2077719f82d3SEliot Blennerhassett }
2078719f82d3SEliot Blennerhassett 
2079719f82d3SEliot Blennerhassett u16 hpi_cobranet_getMA_caddress(const struct hpi_hsubsys *ph_subsys,
2080719f82d3SEliot Blennerhassett 	u32 h_control, u32 *pmAC_MS_bs, u32 *pmAC_LS_bs)
2081719f82d3SEliot Blennerhassett {
2082719f82d3SEliot Blennerhassett 	u32 byte_count;
2083719f82d3SEliot Blennerhassett 	u16 error;
2084719f82d3SEliot Blennerhassett 	u32 mAC;
2085719f82d3SEliot Blennerhassett 	error = hpi_cobranet_hmi_read(ph_subsys, h_control,
2086719f82d3SEliot Blennerhassett 		HPI_COBRANET_HMI_cobra_if_phy_address, 4, &byte_count,
2087719f82d3SEliot Blennerhassett 		(u8 *)&mAC);
2088719f82d3SEliot Blennerhassett 	*pmAC_MS_bs =
2089719f82d3SEliot Blennerhassett 		((mAC & 0xff000000) >> 8) | ((mAC & 0x00ff0000) << 8) | ((mAC
2090719f82d3SEliot Blennerhassett 			& 0x0000ff00) >> 8) | ((mAC & 0x000000ff) << 8);
2091719f82d3SEliot Blennerhassett 	error += hpi_cobranet_hmi_read(ph_subsys, h_control,
2092719f82d3SEliot Blennerhassett 		HPI_COBRANET_HMI_cobra_if_phy_address + 1, 4, &byte_count,
2093719f82d3SEliot Blennerhassett 		(u8 *)&mAC);
2094719f82d3SEliot Blennerhassett 	*pmAC_LS_bs =
2095719f82d3SEliot Blennerhassett 		((mAC & 0xff000000) >> 8) | ((mAC & 0x00ff0000) << 8) | ((mAC
2096719f82d3SEliot Blennerhassett 			& 0x0000ff00) >> 8) | ((mAC & 0x000000ff) << 8);
2097719f82d3SEliot Blennerhassett 
2098719f82d3SEliot Blennerhassett 	if (error) {
2099719f82d3SEliot Blennerhassett 		*pmAC_MS_bs = 0;
2100719f82d3SEliot Blennerhassett 		*pmAC_LS_bs = 0;
2101719f82d3SEliot Blennerhassett 	}
2102719f82d3SEliot Blennerhassett 
2103719f82d3SEliot Blennerhassett 	return error;
2104719f82d3SEliot Blennerhassett }
2105719f82d3SEliot Blennerhassett 
2106719f82d3SEliot Blennerhassett u16 hpi_compander_set(const struct hpi_hsubsys *ph_subsys, u32 h_control,
2107719f82d3SEliot Blennerhassett 	u16 attack, u16 decay, short ratio100, short threshold0_01dB,
2108719f82d3SEliot Blennerhassett 	short makeup_gain0_01dB)
2109719f82d3SEliot Blennerhassett {
2110719f82d3SEliot Blennerhassett 	struct hpi_message hm;
2111719f82d3SEliot Blennerhassett 	struct hpi_response hr;
2112719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2113719f82d3SEliot Blennerhassett 		HPI_CONTROL_SET_STATE);
2114719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
2115719f82d3SEliot Blennerhassett 
2116719f82d3SEliot Blennerhassett 	hm.u.c.param1 = attack + ((u32)ratio100 << 16);
2117719f82d3SEliot Blennerhassett 	hm.u.c.param2 = (decay & 0xFFFFL);
2118719f82d3SEliot Blennerhassett 	hm.u.c.an_log_value[0] = threshold0_01dB;
2119719f82d3SEliot Blennerhassett 	hm.u.c.an_log_value[1] = makeup_gain0_01dB;
2120719f82d3SEliot Blennerhassett 	hm.u.c.attribute = HPI_COMPANDER_PARAMS;
2121719f82d3SEliot Blennerhassett 
2122719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
2123719f82d3SEliot Blennerhassett 
2124719f82d3SEliot Blennerhassett 	return hr.error;
2125719f82d3SEliot Blennerhassett }
2126719f82d3SEliot Blennerhassett 
2127719f82d3SEliot Blennerhassett u16 hpi_compander_get(const struct hpi_hsubsys *ph_subsys, u32 h_control,
2128719f82d3SEliot Blennerhassett 	u16 *pw_attack, u16 *pw_decay, short *pw_ratio100,
2129719f82d3SEliot Blennerhassett 	short *pn_threshold0_01dB, short *pn_makeup_gain0_01dB)
2130719f82d3SEliot Blennerhassett {
2131719f82d3SEliot Blennerhassett 	struct hpi_message hm;
2132719f82d3SEliot Blennerhassett 	struct hpi_response hr;
2133719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2134719f82d3SEliot Blennerhassett 		HPI_CONTROL_GET_STATE);
2135719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
2136719f82d3SEliot Blennerhassett 	hm.u.c.attribute = HPI_COMPANDER_PARAMS;
2137719f82d3SEliot Blennerhassett 
2138719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
2139719f82d3SEliot Blennerhassett 
2140719f82d3SEliot Blennerhassett 	if (pw_attack)
2141719f82d3SEliot Blennerhassett 		*pw_attack = (short)(hr.u.c.param1 & 0xFFFF);
2142719f82d3SEliot Blennerhassett 	if (pw_decay)
2143719f82d3SEliot Blennerhassett 		*pw_decay = (short)(hr.u.c.param2 & 0xFFFF);
2144719f82d3SEliot Blennerhassett 	if (pw_ratio100)
2145719f82d3SEliot Blennerhassett 		*pw_ratio100 = (short)(hr.u.c.param1 >> 16);
2146719f82d3SEliot Blennerhassett 
2147719f82d3SEliot Blennerhassett 	if (pn_threshold0_01dB)
2148719f82d3SEliot Blennerhassett 		*pn_threshold0_01dB = hr.u.c.an_log_value[0];
2149719f82d3SEliot Blennerhassett 	if (pn_makeup_gain0_01dB)
2150719f82d3SEliot Blennerhassett 		*pn_makeup_gain0_01dB = hr.u.c.an_log_value[1];
2151719f82d3SEliot Blennerhassett 
2152719f82d3SEliot Blennerhassett 	return hr.error;
2153719f82d3SEliot Blennerhassett }
2154719f82d3SEliot Blennerhassett 
2155719f82d3SEliot Blennerhassett u16 hpi_level_query_range(const struct hpi_hsubsys *ph_subsys, u32 h_control,
2156719f82d3SEliot Blennerhassett 	short *min_gain_01dB, short *max_gain_01dB, short *step_gain_01dB)
2157719f82d3SEliot Blennerhassett {
2158719f82d3SEliot Blennerhassett 	struct hpi_message hm;
2159719f82d3SEliot Blennerhassett 	struct hpi_response hr;
2160719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2161719f82d3SEliot Blennerhassett 		HPI_CONTROL_GET_STATE);
2162719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
2163719f82d3SEliot Blennerhassett 	hm.u.c.attribute = HPI_LEVEL_RANGE;
2164719f82d3SEliot Blennerhassett 
2165719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
2166719f82d3SEliot Blennerhassett 	if (hr.error) {
2167719f82d3SEliot Blennerhassett 		hr.u.c.an_log_value[0] = 0;
2168719f82d3SEliot Blennerhassett 		hr.u.c.an_log_value[1] = 0;
2169719f82d3SEliot Blennerhassett 		hr.u.c.param1 = 0;
2170719f82d3SEliot Blennerhassett 	}
2171719f82d3SEliot Blennerhassett 	if (min_gain_01dB)
2172719f82d3SEliot Blennerhassett 		*min_gain_01dB = hr.u.c.an_log_value[0];
2173719f82d3SEliot Blennerhassett 	if (max_gain_01dB)
2174719f82d3SEliot Blennerhassett 		*max_gain_01dB = hr.u.c.an_log_value[1];
2175719f82d3SEliot Blennerhassett 	if (step_gain_01dB)
2176719f82d3SEliot Blennerhassett 		*step_gain_01dB = (short)hr.u.c.param1;
2177719f82d3SEliot Blennerhassett 	return hr.error;
2178719f82d3SEliot Blennerhassett }
2179719f82d3SEliot Blennerhassett 
2180719f82d3SEliot Blennerhassett u16 hpi_level_set_gain(const struct hpi_hsubsys *ph_subsys, u32 h_control,
2181719f82d3SEliot Blennerhassett 	short an_gain0_01dB[HPI_MAX_CHANNELS]
2182719f82d3SEliot Blennerhassett 	)
2183719f82d3SEliot Blennerhassett {
2184719f82d3SEliot Blennerhassett 	struct hpi_message hm;
2185719f82d3SEliot Blennerhassett 	struct hpi_response hr;
2186719f82d3SEliot Blennerhassett 
2187719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2188719f82d3SEliot Blennerhassett 		HPI_CONTROL_SET_STATE);
2189719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
2190719f82d3SEliot Blennerhassett 	memcpy(hm.u.c.an_log_value, an_gain0_01dB,
2191719f82d3SEliot Blennerhassett 		sizeof(short) * HPI_MAX_CHANNELS);
2192719f82d3SEliot Blennerhassett 	hm.u.c.attribute = HPI_LEVEL_GAIN;
2193719f82d3SEliot Blennerhassett 
2194719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
2195719f82d3SEliot Blennerhassett 
2196719f82d3SEliot Blennerhassett 	return hr.error;
2197719f82d3SEliot Blennerhassett }
2198719f82d3SEliot Blennerhassett 
2199719f82d3SEliot Blennerhassett u16 hpi_level_get_gain(const struct hpi_hsubsys *ph_subsys, u32 h_control,
2200719f82d3SEliot Blennerhassett 	short an_gain0_01dB[HPI_MAX_CHANNELS]
2201719f82d3SEliot Blennerhassett 	)
2202719f82d3SEliot Blennerhassett {
2203719f82d3SEliot Blennerhassett 	struct hpi_message hm;
2204719f82d3SEliot Blennerhassett 	struct hpi_response hr;
2205719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2206719f82d3SEliot Blennerhassett 		HPI_CONTROL_GET_STATE);
2207719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
2208719f82d3SEliot Blennerhassett 	hm.u.c.attribute = HPI_LEVEL_GAIN;
2209719f82d3SEliot Blennerhassett 
2210719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
2211719f82d3SEliot Blennerhassett 
2212719f82d3SEliot Blennerhassett 	memcpy(an_gain0_01dB, hr.u.c.an_log_value,
2213719f82d3SEliot Blennerhassett 		sizeof(short) * HPI_MAX_CHANNELS);
2214719f82d3SEliot Blennerhassett 	return hr.error;
2215719f82d3SEliot Blennerhassett }
2216719f82d3SEliot Blennerhassett 
2217719f82d3SEliot Blennerhassett u16 hpi_meter_query_channels(const struct hpi_hsubsys *ph_subsys,
2218719f82d3SEliot Blennerhassett 	const u32 h_meter, u32 *p_channels)
2219719f82d3SEliot Blennerhassett {
2220719f82d3SEliot Blennerhassett 	return hpi_control_query(ph_subsys, h_meter, HPI_METER_NUM_CHANNELS,
2221719f82d3SEliot Blennerhassett 		0, 0, p_channels);
2222719f82d3SEliot Blennerhassett }
2223719f82d3SEliot Blennerhassett 
2224719f82d3SEliot Blennerhassett u16 hpi_meter_get_peak(const struct hpi_hsubsys *ph_subsys, u32 h_control,
2225719f82d3SEliot Blennerhassett 	short an_peakdB[HPI_MAX_CHANNELS]
2226719f82d3SEliot Blennerhassett 	)
2227719f82d3SEliot Blennerhassett {
2228719f82d3SEliot Blennerhassett 	short i = 0;
2229719f82d3SEliot Blennerhassett 
2230719f82d3SEliot Blennerhassett 	struct hpi_message hm;
2231719f82d3SEliot Blennerhassett 	struct hpi_response hr;
2232719f82d3SEliot Blennerhassett 
2233719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2234719f82d3SEliot Blennerhassett 		HPI_CONTROL_GET_STATE);
2235719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
2236719f82d3SEliot Blennerhassett 	hm.obj_index = hm.obj_index;
2237719f82d3SEliot Blennerhassett 	hm.u.c.attribute = HPI_METER_PEAK;
2238719f82d3SEliot Blennerhassett 
2239719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
2240719f82d3SEliot Blennerhassett 
2241719f82d3SEliot Blennerhassett 	if (!hr.error)
2242719f82d3SEliot Blennerhassett 		memcpy(an_peakdB, hr.u.c.an_log_value,
2243719f82d3SEliot Blennerhassett 			sizeof(short) * HPI_MAX_CHANNELS);
2244719f82d3SEliot Blennerhassett 	else
2245719f82d3SEliot Blennerhassett 		for (i = 0; i < HPI_MAX_CHANNELS; i++)
2246719f82d3SEliot Blennerhassett 			an_peakdB[i] = HPI_METER_MINIMUM;
2247719f82d3SEliot Blennerhassett 	return hr.error;
2248719f82d3SEliot Blennerhassett }
2249719f82d3SEliot Blennerhassett 
2250719f82d3SEliot Blennerhassett u16 hpi_meter_get_rms(const struct hpi_hsubsys *ph_subsys, u32 h_control,
2251719f82d3SEliot Blennerhassett 	short an_rmsdB[HPI_MAX_CHANNELS]
2252719f82d3SEliot Blennerhassett 	)
2253719f82d3SEliot Blennerhassett {
2254719f82d3SEliot Blennerhassett 	short i = 0;
2255719f82d3SEliot Blennerhassett 
2256719f82d3SEliot Blennerhassett 	struct hpi_message hm;
2257719f82d3SEliot Blennerhassett 	struct hpi_response hr;
2258719f82d3SEliot Blennerhassett 
2259719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2260719f82d3SEliot Blennerhassett 		HPI_CONTROL_GET_STATE);
2261719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
2262719f82d3SEliot Blennerhassett 	hm.u.c.attribute = HPI_METER_RMS;
2263719f82d3SEliot Blennerhassett 
2264719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
2265719f82d3SEliot Blennerhassett 
2266719f82d3SEliot Blennerhassett 	if (!hr.error)
2267719f82d3SEliot Blennerhassett 		memcpy(an_rmsdB, hr.u.c.an_log_value,
2268719f82d3SEliot Blennerhassett 			sizeof(short) * HPI_MAX_CHANNELS);
2269719f82d3SEliot Blennerhassett 	else
2270719f82d3SEliot Blennerhassett 		for (i = 0; i < HPI_MAX_CHANNELS; i++)
2271719f82d3SEliot Blennerhassett 			an_rmsdB[i] = HPI_METER_MINIMUM;
2272719f82d3SEliot Blennerhassett 
2273719f82d3SEliot Blennerhassett 	return hr.error;
2274719f82d3SEliot Blennerhassett }
2275719f82d3SEliot Blennerhassett 
2276719f82d3SEliot Blennerhassett u16 hpi_meter_set_rms_ballistics(const struct hpi_hsubsys *ph_subsys,
2277719f82d3SEliot Blennerhassett 	u32 h_control, u16 attack, u16 decay)
2278719f82d3SEliot Blennerhassett {
2279719f82d3SEliot Blennerhassett 	return hpi_control_param_set(ph_subsys, h_control,
2280719f82d3SEliot Blennerhassett 		HPI_METER_RMS_BALLISTICS, attack, decay);
2281719f82d3SEliot Blennerhassett }
2282719f82d3SEliot Blennerhassett 
2283719f82d3SEliot Blennerhassett u16 hpi_meter_get_rms_ballistics(const struct hpi_hsubsys *ph_subsys,
2284719f82d3SEliot Blennerhassett 	u32 h_control, u16 *pn_attack, u16 *pn_decay)
2285719f82d3SEliot Blennerhassett {
2286719f82d3SEliot Blennerhassett 	u32 attack;
2287719f82d3SEliot Blennerhassett 	u32 decay;
2288719f82d3SEliot Blennerhassett 	u16 error;
2289719f82d3SEliot Blennerhassett 
2290719f82d3SEliot Blennerhassett 	error = hpi_control_param2_get(ph_subsys, h_control,
2291719f82d3SEliot Blennerhassett 		HPI_METER_RMS_BALLISTICS, &attack, &decay);
2292719f82d3SEliot Blennerhassett 
2293719f82d3SEliot Blennerhassett 	if (pn_attack)
2294719f82d3SEliot Blennerhassett 		*pn_attack = (unsigned short)attack;
2295719f82d3SEliot Blennerhassett 	if (pn_decay)
2296719f82d3SEliot Blennerhassett 		*pn_decay = (unsigned short)decay;
2297719f82d3SEliot Blennerhassett 
2298719f82d3SEliot Blennerhassett 	return error;
2299719f82d3SEliot Blennerhassett }
2300719f82d3SEliot Blennerhassett 
2301719f82d3SEliot Blennerhassett u16 hpi_meter_set_peak_ballistics(const struct hpi_hsubsys *ph_subsys,
2302719f82d3SEliot Blennerhassett 	u32 h_control, u16 attack, u16 decay)
2303719f82d3SEliot Blennerhassett {
2304719f82d3SEliot Blennerhassett 	return hpi_control_param_set(ph_subsys, h_control,
2305719f82d3SEliot Blennerhassett 		HPI_METER_PEAK_BALLISTICS, attack, decay);
2306719f82d3SEliot Blennerhassett }
2307719f82d3SEliot Blennerhassett 
2308719f82d3SEliot Blennerhassett u16 hpi_meter_get_peak_ballistics(const struct hpi_hsubsys *ph_subsys,
2309719f82d3SEliot Blennerhassett 	u32 h_control, u16 *pn_attack, u16 *pn_decay)
2310719f82d3SEliot Blennerhassett {
2311719f82d3SEliot Blennerhassett 	u32 attack;
2312719f82d3SEliot Blennerhassett 	u32 decay;
2313719f82d3SEliot Blennerhassett 	u16 error;
2314719f82d3SEliot Blennerhassett 
2315719f82d3SEliot Blennerhassett 	error = hpi_control_param2_get(ph_subsys, h_control,
2316719f82d3SEliot Blennerhassett 		HPI_METER_PEAK_BALLISTICS, &attack, &decay);
2317719f82d3SEliot Blennerhassett 
2318719f82d3SEliot Blennerhassett 	if (pn_attack)
2319719f82d3SEliot Blennerhassett 		*pn_attack = (short)attack;
2320719f82d3SEliot Blennerhassett 	if (pn_decay)
2321719f82d3SEliot Blennerhassett 		*pn_decay = (short)decay;
2322719f82d3SEliot Blennerhassett 
2323719f82d3SEliot Blennerhassett 	return error;
2324719f82d3SEliot Blennerhassett }
2325719f82d3SEliot Blennerhassett 
2326719f82d3SEliot Blennerhassett u16 hpi_microphone_set_phantom_power(const struct hpi_hsubsys *ph_subsys,
2327719f82d3SEliot Blennerhassett 	u32 h_control, u16 on_off)
2328719f82d3SEliot Blennerhassett {
2329719f82d3SEliot Blennerhassett 	return hpi_control_param_set(ph_subsys, h_control,
2330719f82d3SEliot Blennerhassett 		HPI_MICROPHONE_PHANTOM_POWER, (u32)on_off, 0);
2331719f82d3SEliot Blennerhassett }
2332719f82d3SEliot Blennerhassett 
2333719f82d3SEliot Blennerhassett u16 hpi_microphone_get_phantom_power(const struct hpi_hsubsys *ph_subsys,
2334719f82d3SEliot Blennerhassett 	u32 h_control, u16 *pw_on_off)
2335719f82d3SEliot Blennerhassett {
2336719f82d3SEliot Blennerhassett 	u16 error = 0;
2337719f82d3SEliot Blennerhassett 	u32 on_off = 0;
2338719f82d3SEliot Blennerhassett 	error = hpi_control_param1_get(ph_subsys, h_control,
2339719f82d3SEliot Blennerhassett 		HPI_MICROPHONE_PHANTOM_POWER, &on_off);
2340719f82d3SEliot Blennerhassett 	if (pw_on_off)
2341719f82d3SEliot Blennerhassett 		*pw_on_off = (u16)on_off;
2342719f82d3SEliot Blennerhassett 	return error;
2343719f82d3SEliot Blennerhassett }
2344719f82d3SEliot Blennerhassett 
2345719f82d3SEliot Blennerhassett u16 hpi_multiplexer_set_source(const struct hpi_hsubsys *ph_subsys,
2346719f82d3SEliot Blennerhassett 	u32 h_control, u16 source_node_type, u16 source_node_index)
2347719f82d3SEliot Blennerhassett {
2348719f82d3SEliot Blennerhassett 	return hpi_control_param_set(ph_subsys, h_control,
2349719f82d3SEliot Blennerhassett 		HPI_MULTIPLEXER_SOURCE, source_node_type, source_node_index);
2350719f82d3SEliot Blennerhassett }
2351719f82d3SEliot Blennerhassett 
2352719f82d3SEliot Blennerhassett u16 hpi_multiplexer_get_source(const struct hpi_hsubsys *ph_subsys,
2353719f82d3SEliot Blennerhassett 	u32 h_control, u16 *source_node_type, u16 *source_node_index)
2354719f82d3SEliot Blennerhassett {
2355719f82d3SEliot Blennerhassett 	u32 node, index;
2356719f82d3SEliot Blennerhassett 	u16 error = hpi_control_param2_get(ph_subsys, h_control,
2357719f82d3SEliot Blennerhassett 		HPI_MULTIPLEXER_SOURCE, &node,
2358719f82d3SEliot Blennerhassett 		&index);
2359719f82d3SEliot Blennerhassett 	if (source_node_type)
2360719f82d3SEliot Blennerhassett 		*source_node_type = (u16)node;
2361719f82d3SEliot Blennerhassett 	if (source_node_index)
2362719f82d3SEliot Blennerhassett 		*source_node_index = (u16)index;
2363719f82d3SEliot Blennerhassett 	return error;
2364719f82d3SEliot Blennerhassett }
2365719f82d3SEliot Blennerhassett 
2366719f82d3SEliot Blennerhassett u16 hpi_multiplexer_query_source(const struct hpi_hsubsys *ph_subsys,
2367719f82d3SEliot Blennerhassett 	u32 h_control, u16 index, u16 *source_node_type,
2368719f82d3SEliot Blennerhassett 	u16 *source_node_index)
2369719f82d3SEliot Blennerhassett {
2370719f82d3SEliot Blennerhassett 	struct hpi_message hm;
2371719f82d3SEliot Blennerhassett 	struct hpi_response hr;
2372719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2373719f82d3SEliot Blennerhassett 		HPI_CONTROL_GET_STATE);
2374719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
2375719f82d3SEliot Blennerhassett 	hm.u.c.attribute = HPI_MULTIPLEXER_QUERYSOURCE;
2376719f82d3SEliot Blennerhassett 	hm.u.c.param1 = index;
2377719f82d3SEliot Blennerhassett 
2378719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
2379719f82d3SEliot Blennerhassett 
2380719f82d3SEliot Blennerhassett 	if (source_node_type)
2381719f82d3SEliot Blennerhassett 		*source_node_type = (u16)hr.u.c.param1;
2382719f82d3SEliot Blennerhassett 	if (source_node_index)
2383719f82d3SEliot Blennerhassett 		*source_node_index = (u16)hr.u.c.param2;
2384719f82d3SEliot Blennerhassett 	return hr.error;
2385719f82d3SEliot Blennerhassett }
2386719f82d3SEliot Blennerhassett 
2387719f82d3SEliot Blennerhassett u16 hpi_parametricEQ__get_info(const struct hpi_hsubsys *ph_subsys,
2388719f82d3SEliot Blennerhassett 	u32 h_control, u16 *pw_number_of_bands, u16 *pw_on_off)
2389719f82d3SEliot Blennerhassett {
2390719f82d3SEliot Blennerhassett 	u32 oB = 0;
2391719f82d3SEliot Blennerhassett 	u32 oO = 0;
2392719f82d3SEliot Blennerhassett 	u16 error = 0;
2393719f82d3SEliot Blennerhassett 
2394719f82d3SEliot Blennerhassett 	error = hpi_control_param2_get(ph_subsys, h_control,
2395719f82d3SEliot Blennerhassett 		HPI_EQUALIZER_NUM_FILTERS, &oO, &oB);
2396719f82d3SEliot Blennerhassett 	if (pw_number_of_bands)
2397719f82d3SEliot Blennerhassett 		*pw_number_of_bands = (u16)oB;
2398719f82d3SEliot Blennerhassett 	if (pw_on_off)
2399719f82d3SEliot Blennerhassett 		*pw_on_off = (u16)oO;
2400719f82d3SEliot Blennerhassett 	return error;
2401719f82d3SEliot Blennerhassett }
2402719f82d3SEliot Blennerhassett 
2403719f82d3SEliot Blennerhassett u16 hpi_parametricEQ__set_state(const struct hpi_hsubsys *ph_subsys,
2404719f82d3SEliot Blennerhassett 	u32 h_control, u16 on_off)
2405719f82d3SEliot Blennerhassett {
2406719f82d3SEliot Blennerhassett 	return hpi_control_param_set(ph_subsys, h_control,
2407719f82d3SEliot Blennerhassett 		HPI_EQUALIZER_NUM_FILTERS, on_off, 0);
2408719f82d3SEliot Blennerhassett }
2409719f82d3SEliot Blennerhassett 
2410719f82d3SEliot Blennerhassett u16 hpi_parametricEQ__get_band(const struct hpi_hsubsys *ph_subsys,
2411719f82d3SEliot Blennerhassett 	u32 h_control, u16 index, u16 *pn_type, u32 *pfrequency_hz,
2412719f82d3SEliot Blennerhassett 	short *pnQ100, short *pn_gain0_01dB)
2413719f82d3SEliot Blennerhassett {
2414719f82d3SEliot Blennerhassett 	struct hpi_message hm;
2415719f82d3SEliot Blennerhassett 	struct hpi_response hr;
2416719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2417719f82d3SEliot Blennerhassett 		HPI_CONTROL_GET_STATE);
2418719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
2419719f82d3SEliot Blennerhassett 	hm.u.c.attribute = HPI_EQUALIZER_FILTER;
2420719f82d3SEliot Blennerhassett 	hm.u.c.param2 = index;
2421719f82d3SEliot Blennerhassett 
2422719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
2423719f82d3SEliot Blennerhassett 
2424719f82d3SEliot Blennerhassett 	if (pfrequency_hz)
2425719f82d3SEliot Blennerhassett 		*pfrequency_hz = hr.u.c.param1;
2426719f82d3SEliot Blennerhassett 	if (pn_type)
2427719f82d3SEliot Blennerhassett 		*pn_type = (u16)(hr.u.c.param2 >> 16);
2428719f82d3SEliot Blennerhassett 	if (pnQ100)
2429719f82d3SEliot Blennerhassett 		*pnQ100 = hr.u.c.an_log_value[1];
2430719f82d3SEliot Blennerhassett 	if (pn_gain0_01dB)
2431719f82d3SEliot Blennerhassett 		*pn_gain0_01dB = hr.u.c.an_log_value[0];
2432719f82d3SEliot Blennerhassett 
2433719f82d3SEliot Blennerhassett 	return hr.error;
2434719f82d3SEliot Blennerhassett }
2435719f82d3SEliot Blennerhassett 
2436719f82d3SEliot Blennerhassett u16 hpi_parametricEQ__set_band(const struct hpi_hsubsys *ph_subsys,
2437719f82d3SEliot Blennerhassett 	u32 h_control, u16 index, u16 type, u32 frequency_hz, short q100,
2438719f82d3SEliot Blennerhassett 	short gain0_01dB)
2439719f82d3SEliot Blennerhassett {
2440719f82d3SEliot Blennerhassett 	struct hpi_message hm;
2441719f82d3SEliot Blennerhassett 	struct hpi_response hr;
2442719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2443719f82d3SEliot Blennerhassett 		HPI_CONTROL_SET_STATE);
2444719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
2445719f82d3SEliot Blennerhassett 
2446719f82d3SEliot Blennerhassett 	hm.u.c.param1 = frequency_hz;
2447719f82d3SEliot Blennerhassett 	hm.u.c.param2 = (index & 0xFFFFL) + ((u32)type << 16);
2448719f82d3SEliot Blennerhassett 	hm.u.c.an_log_value[0] = gain0_01dB;
2449719f82d3SEliot Blennerhassett 	hm.u.c.an_log_value[1] = q100;
2450719f82d3SEliot Blennerhassett 	hm.u.c.attribute = HPI_EQUALIZER_FILTER;
2451719f82d3SEliot Blennerhassett 
2452719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
2453719f82d3SEliot Blennerhassett 
2454719f82d3SEliot Blennerhassett 	return hr.error;
2455719f82d3SEliot Blennerhassett }
2456719f82d3SEliot Blennerhassett 
2457719f82d3SEliot Blennerhassett u16 hpi_parametricEQ__get_coeffs(const struct hpi_hsubsys *ph_subsys,
2458719f82d3SEliot Blennerhassett 	u32 h_control, u16 index, short coeffs[5]
2459719f82d3SEliot Blennerhassett 	)
2460719f82d3SEliot Blennerhassett {
2461719f82d3SEliot Blennerhassett 	struct hpi_message hm;
2462719f82d3SEliot Blennerhassett 	struct hpi_response hr;
2463719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2464719f82d3SEliot Blennerhassett 		HPI_CONTROL_GET_STATE);
2465719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
2466719f82d3SEliot Blennerhassett 	hm.u.c.attribute = HPI_EQUALIZER_COEFFICIENTS;
2467719f82d3SEliot Blennerhassett 	hm.u.c.param2 = index;
2468719f82d3SEliot Blennerhassett 
2469719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
2470719f82d3SEliot Blennerhassett 
2471719f82d3SEliot Blennerhassett 	coeffs[0] = (short)hr.u.c.an_log_value[0];
2472719f82d3SEliot Blennerhassett 	coeffs[1] = (short)hr.u.c.an_log_value[1];
2473719f82d3SEliot Blennerhassett 	coeffs[2] = (short)hr.u.c.param1;
2474719f82d3SEliot Blennerhassett 	coeffs[3] = (short)(hr.u.c.param1 >> 16);
2475719f82d3SEliot Blennerhassett 	coeffs[4] = (short)hr.u.c.param2;
2476719f82d3SEliot Blennerhassett 
2477719f82d3SEliot Blennerhassett 	return hr.error;
2478719f82d3SEliot Blennerhassett }
2479719f82d3SEliot Blennerhassett 
2480719f82d3SEliot Blennerhassett u16 hpi_sample_clock_query_source(const struct hpi_hsubsys *ph_subsys,
2481719f82d3SEliot Blennerhassett 	const u32 h_clock, const u32 index, u16 *pw_source)
2482719f82d3SEliot Blennerhassett {
2483719f82d3SEliot Blennerhassett 	u32 qr;
2484719f82d3SEliot Blennerhassett 	u16 err;
2485719f82d3SEliot Blennerhassett 
2486719f82d3SEliot Blennerhassett 	err = hpi_control_query(ph_subsys, h_clock, HPI_SAMPLECLOCK_SOURCE,
2487719f82d3SEliot Blennerhassett 		index, 0, &qr);
2488719f82d3SEliot Blennerhassett 	*pw_source = (u16)qr;
2489719f82d3SEliot Blennerhassett 	return err;
2490719f82d3SEliot Blennerhassett }
2491719f82d3SEliot Blennerhassett 
2492719f82d3SEliot Blennerhassett u16 hpi_sample_clock_set_source(const struct hpi_hsubsys *ph_subsys,
2493719f82d3SEliot Blennerhassett 	u32 h_control, u16 source)
2494719f82d3SEliot Blennerhassett {
2495719f82d3SEliot Blennerhassett 	return hpi_control_param_set(ph_subsys, h_control,
2496719f82d3SEliot Blennerhassett 		HPI_SAMPLECLOCK_SOURCE, source, 0);
2497719f82d3SEliot Blennerhassett }
2498719f82d3SEliot Blennerhassett 
2499719f82d3SEliot Blennerhassett u16 hpi_sample_clock_get_source(const struct hpi_hsubsys *ph_subsys,
2500719f82d3SEliot Blennerhassett 	u32 h_control, u16 *pw_source)
2501719f82d3SEliot Blennerhassett {
2502719f82d3SEliot Blennerhassett 	u16 error = 0;
2503719f82d3SEliot Blennerhassett 	u32 source = 0;
2504719f82d3SEliot Blennerhassett 	error = hpi_control_param1_get(ph_subsys, h_control,
2505719f82d3SEliot Blennerhassett 		HPI_SAMPLECLOCK_SOURCE, &source);
2506719f82d3SEliot Blennerhassett 	if (!error)
2507719f82d3SEliot Blennerhassett 		if (pw_source)
2508719f82d3SEliot Blennerhassett 			*pw_source = (u16)source;
2509719f82d3SEliot Blennerhassett 	return error;
2510719f82d3SEliot Blennerhassett }
2511719f82d3SEliot Blennerhassett 
2512719f82d3SEliot Blennerhassett u16 hpi_sample_clock_query_source_index(const struct hpi_hsubsys *ph_subsys,
2513719f82d3SEliot Blennerhassett 	const u32 h_clock, const u32 index, const u32 source,
2514719f82d3SEliot Blennerhassett 	u16 *pw_source_index)
2515719f82d3SEliot Blennerhassett {
2516719f82d3SEliot Blennerhassett 	u32 qr;
2517719f82d3SEliot Blennerhassett 	u16 err;
2518719f82d3SEliot Blennerhassett 
2519719f82d3SEliot Blennerhassett 	err = hpi_control_query(ph_subsys, h_clock,
2520719f82d3SEliot Blennerhassett 		HPI_SAMPLECLOCK_SOURCE_INDEX, index, source, &qr);
2521719f82d3SEliot Blennerhassett 	*pw_source_index = (u16)qr;
2522719f82d3SEliot Blennerhassett 	return err;
2523719f82d3SEliot Blennerhassett }
2524719f82d3SEliot Blennerhassett 
2525719f82d3SEliot Blennerhassett u16 hpi_sample_clock_set_source_index(const struct hpi_hsubsys *ph_subsys,
2526719f82d3SEliot Blennerhassett 	u32 h_control, u16 source_index)
2527719f82d3SEliot Blennerhassett {
2528719f82d3SEliot Blennerhassett 	return hpi_control_param_set(ph_subsys, h_control,
2529719f82d3SEliot Blennerhassett 		HPI_SAMPLECLOCK_SOURCE_INDEX, source_index, 0);
2530719f82d3SEliot Blennerhassett }
2531719f82d3SEliot Blennerhassett 
2532719f82d3SEliot Blennerhassett u16 hpi_sample_clock_get_source_index(const struct hpi_hsubsys *ph_subsys,
2533719f82d3SEliot Blennerhassett 	u32 h_control, u16 *pw_source_index)
2534719f82d3SEliot Blennerhassett {
2535719f82d3SEliot Blennerhassett 	u16 error = 0;
2536719f82d3SEliot Blennerhassett 	u32 source_index = 0;
2537719f82d3SEliot Blennerhassett 	error = hpi_control_param1_get(ph_subsys, h_control,
2538719f82d3SEliot Blennerhassett 		HPI_SAMPLECLOCK_SOURCE_INDEX, &source_index);
2539719f82d3SEliot Blennerhassett 	if (!error)
2540719f82d3SEliot Blennerhassett 		if (pw_source_index)
2541719f82d3SEliot Blennerhassett 			*pw_source_index = (u16)source_index;
2542719f82d3SEliot Blennerhassett 	return error;
2543719f82d3SEliot Blennerhassett }
2544719f82d3SEliot Blennerhassett 
2545719f82d3SEliot Blennerhassett u16 hpi_sample_clock_query_local_rate(const struct hpi_hsubsys *ph_subsys,
2546719f82d3SEliot Blennerhassett 	const u32 h_clock, const u32 index, u32 *prate)
2547719f82d3SEliot Blennerhassett {
2548719f82d3SEliot Blennerhassett 	u16 err;
2549719f82d3SEliot Blennerhassett 	err = hpi_control_query(ph_subsys, h_clock,
2550719f82d3SEliot Blennerhassett 		HPI_SAMPLECLOCK_LOCAL_SAMPLERATE, index, 0, prate);
2551719f82d3SEliot Blennerhassett 
2552719f82d3SEliot Blennerhassett 	return err;
2553719f82d3SEliot Blennerhassett }
2554719f82d3SEliot Blennerhassett 
2555719f82d3SEliot Blennerhassett u16 hpi_sample_clock_set_local_rate(const struct hpi_hsubsys *ph_subsys,
2556719f82d3SEliot Blennerhassett 	u32 h_control, u32 sample_rate)
2557719f82d3SEliot Blennerhassett {
2558719f82d3SEliot Blennerhassett 	return hpi_control_param_set(ph_subsys, h_control,
2559719f82d3SEliot Blennerhassett 		HPI_SAMPLECLOCK_LOCAL_SAMPLERATE, sample_rate, 0);
2560719f82d3SEliot Blennerhassett }
2561719f82d3SEliot Blennerhassett 
2562719f82d3SEliot Blennerhassett u16 hpi_sample_clock_get_local_rate(const struct hpi_hsubsys *ph_subsys,
2563719f82d3SEliot Blennerhassett 	u32 h_control, u32 *psample_rate)
2564719f82d3SEliot Blennerhassett {
2565719f82d3SEliot Blennerhassett 	u16 error = 0;
2566719f82d3SEliot Blennerhassett 	u32 sample_rate = 0;
2567719f82d3SEliot Blennerhassett 	error = hpi_control_param1_get(ph_subsys, h_control,
2568719f82d3SEliot Blennerhassett 		HPI_SAMPLECLOCK_LOCAL_SAMPLERATE, &sample_rate);
2569719f82d3SEliot Blennerhassett 	if (!error)
2570719f82d3SEliot Blennerhassett 		if (psample_rate)
2571719f82d3SEliot Blennerhassett 			*psample_rate = sample_rate;
2572719f82d3SEliot Blennerhassett 	return error;
2573719f82d3SEliot Blennerhassett }
2574719f82d3SEliot Blennerhassett 
2575719f82d3SEliot Blennerhassett u16 hpi_sample_clock_get_sample_rate(const struct hpi_hsubsys *ph_subsys,
2576719f82d3SEliot Blennerhassett 	u32 h_control, u32 *psample_rate)
2577719f82d3SEliot Blennerhassett {
2578719f82d3SEliot Blennerhassett 	u16 error = 0;
2579719f82d3SEliot Blennerhassett 	u32 sample_rate = 0;
2580719f82d3SEliot Blennerhassett 	error = hpi_control_param1_get(ph_subsys, h_control,
2581719f82d3SEliot Blennerhassett 		HPI_SAMPLECLOCK_SAMPLERATE, &sample_rate);
2582719f82d3SEliot Blennerhassett 	if (!error)
2583719f82d3SEliot Blennerhassett 		if (psample_rate)
2584719f82d3SEliot Blennerhassett 			*psample_rate = sample_rate;
2585719f82d3SEliot Blennerhassett 	return error;
2586719f82d3SEliot Blennerhassett }
2587719f82d3SEliot Blennerhassett 
2588719f82d3SEliot Blennerhassett u16 hpi_sample_clock_set_auto(const struct hpi_hsubsys *ph_subsys,
2589719f82d3SEliot Blennerhassett 	u32 h_control, u32 enable)
2590719f82d3SEliot Blennerhassett {
2591719f82d3SEliot Blennerhassett 	return hpi_control_param_set(ph_subsys, h_control,
2592719f82d3SEliot Blennerhassett 		HPI_SAMPLECLOCK_AUTO, enable, 0);
2593719f82d3SEliot Blennerhassett }
2594719f82d3SEliot Blennerhassett 
2595719f82d3SEliot Blennerhassett u16 hpi_sample_clock_get_auto(const struct hpi_hsubsys *ph_subsys,
2596719f82d3SEliot Blennerhassett 	u32 h_control, u32 *penable)
2597719f82d3SEliot Blennerhassett {
2598719f82d3SEliot Blennerhassett 	return hpi_control_param1_get(ph_subsys, h_control,
2599719f82d3SEliot Blennerhassett 		HPI_SAMPLECLOCK_AUTO, penable);
2600719f82d3SEliot Blennerhassett }
2601719f82d3SEliot Blennerhassett 
2602719f82d3SEliot Blennerhassett u16 hpi_sample_clock_set_local_rate_lock(const struct hpi_hsubsys *ph_subsys,
2603719f82d3SEliot Blennerhassett 	u32 h_control, u32 lock)
2604719f82d3SEliot Blennerhassett {
2605719f82d3SEliot Blennerhassett 	return hpi_control_param_set(ph_subsys, h_control,
2606719f82d3SEliot Blennerhassett 		HPI_SAMPLECLOCK_LOCAL_LOCK, lock, 0);
2607719f82d3SEliot Blennerhassett }
2608719f82d3SEliot Blennerhassett 
2609719f82d3SEliot Blennerhassett u16 hpi_sample_clock_get_local_rate_lock(const struct hpi_hsubsys *ph_subsys,
2610719f82d3SEliot Blennerhassett 	u32 h_control, u32 *plock)
2611719f82d3SEliot Blennerhassett {
2612719f82d3SEliot Blennerhassett 	return hpi_control_param1_get(ph_subsys, h_control,
2613719f82d3SEliot Blennerhassett 		HPI_SAMPLECLOCK_LOCAL_LOCK, plock);
2614719f82d3SEliot Blennerhassett }
2615719f82d3SEliot Blennerhassett 
2616719f82d3SEliot Blennerhassett u16 hpi_tone_detector_get_frequency(const struct hpi_hsubsys *ph_subsys,
2617719f82d3SEliot Blennerhassett 	u32 h_control, u32 index, u32 *frequency)
2618719f82d3SEliot Blennerhassett {
2619719f82d3SEliot Blennerhassett 	return hpi_control_param_get(ph_subsys, h_control,
2620719f82d3SEliot Blennerhassett 		HPI_TONEDETECTOR_FREQUENCY, index, 0, frequency, NULL);
2621719f82d3SEliot Blennerhassett }
2622719f82d3SEliot Blennerhassett 
2623719f82d3SEliot Blennerhassett u16 hpi_tone_detector_get_state(const struct hpi_hsubsys *ph_subsys,
2624719f82d3SEliot Blennerhassett 	u32 h_control, u32 *state)
2625719f82d3SEliot Blennerhassett {
2626719f82d3SEliot Blennerhassett 	return hpi_control_param_get(ph_subsys, h_control,
2627719f82d3SEliot Blennerhassett 		HPI_TONEDETECTOR_STATE, 0, 0, (u32 *)state, NULL);
2628719f82d3SEliot Blennerhassett }
2629719f82d3SEliot Blennerhassett 
2630719f82d3SEliot Blennerhassett u16 hpi_tone_detector_set_enable(const struct hpi_hsubsys *ph_subsys,
2631719f82d3SEliot Blennerhassett 	u32 h_control, u32 enable)
2632719f82d3SEliot Blennerhassett {
2633719f82d3SEliot Blennerhassett 	return hpi_control_param_set(ph_subsys, h_control, HPI_GENERIC_ENABLE,
2634719f82d3SEliot Blennerhassett 		(u32)enable, 0);
2635719f82d3SEliot Blennerhassett }
2636719f82d3SEliot Blennerhassett 
2637719f82d3SEliot Blennerhassett u16 hpi_tone_detector_get_enable(const struct hpi_hsubsys *ph_subsys,
2638719f82d3SEliot Blennerhassett 	u32 h_control, u32 *enable)
2639719f82d3SEliot Blennerhassett {
2640719f82d3SEliot Blennerhassett 	return hpi_control_param_get(ph_subsys, h_control, HPI_GENERIC_ENABLE,
2641719f82d3SEliot Blennerhassett 		0, 0, (u32 *)enable, NULL);
2642719f82d3SEliot Blennerhassett }
2643719f82d3SEliot Blennerhassett 
2644719f82d3SEliot Blennerhassett u16 hpi_tone_detector_set_event_enable(const struct hpi_hsubsys *ph_subsys,
2645719f82d3SEliot Blennerhassett 	u32 h_control, u32 event_enable)
2646719f82d3SEliot Blennerhassett {
2647719f82d3SEliot Blennerhassett 	return hpi_control_param_set(ph_subsys, h_control,
2648719f82d3SEliot Blennerhassett 		HPI_GENERIC_EVENT_ENABLE, (u32)event_enable, 0);
2649719f82d3SEliot Blennerhassett }
2650719f82d3SEliot Blennerhassett 
2651719f82d3SEliot Blennerhassett u16 hpi_tone_detector_get_event_enable(const struct hpi_hsubsys *ph_subsys,
2652719f82d3SEliot Blennerhassett 	u32 h_control, u32 *event_enable)
2653719f82d3SEliot Blennerhassett {
2654719f82d3SEliot Blennerhassett 	return hpi_control_param_get(ph_subsys, h_control,
2655719f82d3SEliot Blennerhassett 		HPI_GENERIC_EVENT_ENABLE, 0, 0, (u32 *)event_enable, NULL);
2656719f82d3SEliot Blennerhassett }
2657719f82d3SEliot Blennerhassett 
2658719f82d3SEliot Blennerhassett u16 hpi_tone_detector_set_threshold(const struct hpi_hsubsys *ph_subsys,
2659719f82d3SEliot Blennerhassett 	u32 h_control, int threshold)
2660719f82d3SEliot Blennerhassett {
2661719f82d3SEliot Blennerhassett 	return hpi_control_param_set(ph_subsys, h_control,
2662719f82d3SEliot Blennerhassett 		HPI_TONEDETECTOR_THRESHOLD, (u32)threshold, 0);
2663719f82d3SEliot Blennerhassett }
2664719f82d3SEliot Blennerhassett 
2665719f82d3SEliot Blennerhassett u16 hpi_tone_detector_get_threshold(const struct hpi_hsubsys *ph_subsys,
2666719f82d3SEliot Blennerhassett 	u32 h_control, int *threshold)
2667719f82d3SEliot Blennerhassett {
2668719f82d3SEliot Blennerhassett 	return hpi_control_param_get(ph_subsys, h_control,
2669719f82d3SEliot Blennerhassett 		HPI_TONEDETECTOR_THRESHOLD, 0, 0, (u32 *)threshold, NULL);
2670719f82d3SEliot Blennerhassett }
2671719f82d3SEliot Blennerhassett 
2672719f82d3SEliot Blennerhassett u16 hpi_silence_detector_get_state(const struct hpi_hsubsys *ph_subsys,
2673719f82d3SEliot Blennerhassett 	u32 h_control, u32 *state)
2674719f82d3SEliot Blennerhassett {
2675719f82d3SEliot Blennerhassett 	return hpi_control_param_get(ph_subsys, h_control,
2676719f82d3SEliot Blennerhassett 		HPI_SILENCEDETECTOR_STATE, 0, 0, (u32 *)state, NULL);
2677719f82d3SEliot Blennerhassett }
2678719f82d3SEliot Blennerhassett 
2679719f82d3SEliot Blennerhassett u16 hpi_silence_detector_set_enable(const struct hpi_hsubsys *ph_subsys,
2680719f82d3SEliot Blennerhassett 	u32 h_control, u32 enable)
2681719f82d3SEliot Blennerhassett {
2682719f82d3SEliot Blennerhassett 	return hpi_control_param_set(ph_subsys, h_control, HPI_GENERIC_ENABLE,
2683719f82d3SEliot Blennerhassett 		(u32)enable, 0);
2684719f82d3SEliot Blennerhassett }
2685719f82d3SEliot Blennerhassett 
2686719f82d3SEliot Blennerhassett u16 hpi_silence_detector_get_enable(const struct hpi_hsubsys *ph_subsys,
2687719f82d3SEliot Blennerhassett 	u32 h_control, u32 *enable)
2688719f82d3SEliot Blennerhassett {
2689719f82d3SEliot Blennerhassett 	return hpi_control_param_get(ph_subsys, h_control, HPI_GENERIC_ENABLE,
2690719f82d3SEliot Blennerhassett 		0, 0, (u32 *)enable, NULL);
2691719f82d3SEliot Blennerhassett }
2692719f82d3SEliot Blennerhassett 
2693719f82d3SEliot Blennerhassett u16 hpi_silence_detector_set_event_enable(const struct hpi_hsubsys *ph_subsys,
2694719f82d3SEliot Blennerhassett 	u32 h_control, u32 event_enable)
2695719f82d3SEliot Blennerhassett {
2696719f82d3SEliot Blennerhassett 	return hpi_control_param_set(ph_subsys, h_control,
2697719f82d3SEliot Blennerhassett 		HPI_GENERIC_EVENT_ENABLE, (u32)event_enable, 0);
2698719f82d3SEliot Blennerhassett }
2699719f82d3SEliot Blennerhassett 
2700719f82d3SEliot Blennerhassett u16 hpi_silence_detector_get_event_enable(const struct hpi_hsubsys *ph_subsys,
2701719f82d3SEliot Blennerhassett 	u32 h_control, u32 *event_enable)
2702719f82d3SEliot Blennerhassett {
2703719f82d3SEliot Blennerhassett 	return hpi_control_param_get(ph_subsys, h_control,
2704719f82d3SEliot Blennerhassett 		HPI_GENERIC_EVENT_ENABLE, 0, 0, (u32 *)event_enable, NULL);
2705719f82d3SEliot Blennerhassett }
2706719f82d3SEliot Blennerhassett 
2707719f82d3SEliot Blennerhassett u16 hpi_silence_detector_set_delay(const struct hpi_hsubsys *ph_subsys,
2708719f82d3SEliot Blennerhassett 	u32 h_control, u32 delay)
2709719f82d3SEliot Blennerhassett {
2710719f82d3SEliot Blennerhassett 	return hpi_control_param_set(ph_subsys, h_control,
2711719f82d3SEliot Blennerhassett 		HPI_SILENCEDETECTOR_DELAY, (u32)delay, 0);
2712719f82d3SEliot Blennerhassett }
2713719f82d3SEliot Blennerhassett 
2714719f82d3SEliot Blennerhassett u16 hpi_silence_detector_get_delay(const struct hpi_hsubsys *ph_subsys,
2715719f82d3SEliot Blennerhassett 	u32 h_control, u32 *delay)
2716719f82d3SEliot Blennerhassett {
2717719f82d3SEliot Blennerhassett 	return hpi_control_param_get(ph_subsys, h_control,
2718719f82d3SEliot Blennerhassett 		HPI_SILENCEDETECTOR_DELAY, 0, 0, (u32 *)delay, NULL);
2719719f82d3SEliot Blennerhassett }
2720719f82d3SEliot Blennerhassett 
2721719f82d3SEliot Blennerhassett u16 hpi_silence_detector_set_threshold(const struct hpi_hsubsys *ph_subsys,
2722719f82d3SEliot Blennerhassett 	u32 h_control, int threshold)
2723719f82d3SEliot Blennerhassett {
2724719f82d3SEliot Blennerhassett 	return hpi_control_param_set(ph_subsys, h_control,
2725719f82d3SEliot Blennerhassett 		HPI_SILENCEDETECTOR_THRESHOLD, (u32)threshold, 0);
2726719f82d3SEliot Blennerhassett }
2727719f82d3SEliot Blennerhassett 
2728719f82d3SEliot Blennerhassett u16 hpi_silence_detector_get_threshold(const struct hpi_hsubsys *ph_subsys,
2729719f82d3SEliot Blennerhassett 	u32 h_control, int *threshold)
2730719f82d3SEliot Blennerhassett {
2731719f82d3SEliot Blennerhassett 	return hpi_control_param_get(ph_subsys, h_control,
2732719f82d3SEliot Blennerhassett 		HPI_SILENCEDETECTOR_THRESHOLD, 0, 0, (u32 *)threshold, NULL);
2733719f82d3SEliot Blennerhassett }
2734719f82d3SEliot Blennerhassett 
2735719f82d3SEliot Blennerhassett u16 hpi_tuner_query_band(const struct hpi_hsubsys *ph_subsys,
2736719f82d3SEliot Blennerhassett 	const u32 h_tuner, const u32 index, u16 *pw_band)
2737719f82d3SEliot Blennerhassett {
2738719f82d3SEliot Blennerhassett 	u32 qr;
2739719f82d3SEliot Blennerhassett 	u16 err;
2740719f82d3SEliot Blennerhassett 
2741719f82d3SEliot Blennerhassett 	err = hpi_control_query(ph_subsys, h_tuner, HPI_TUNER_BAND, index, 0,
2742719f82d3SEliot Blennerhassett 		&qr);
2743719f82d3SEliot Blennerhassett 	*pw_band = (u16)qr;
2744719f82d3SEliot Blennerhassett 	return err;
2745719f82d3SEliot Blennerhassett }
2746719f82d3SEliot Blennerhassett 
2747719f82d3SEliot Blennerhassett u16 hpi_tuner_set_band(const struct hpi_hsubsys *ph_subsys, u32 h_control,
2748719f82d3SEliot Blennerhassett 	u16 band)
2749719f82d3SEliot Blennerhassett {
2750719f82d3SEliot Blennerhassett 	return hpi_control_param_set(ph_subsys, h_control, HPI_TUNER_BAND,
2751719f82d3SEliot Blennerhassett 		band, 0);
2752719f82d3SEliot Blennerhassett }
2753719f82d3SEliot Blennerhassett 
2754719f82d3SEliot Blennerhassett u16 hpi_tuner_get_band(const struct hpi_hsubsys *ph_subsys, u32 h_control,
2755719f82d3SEliot Blennerhassett 	u16 *pw_band)
2756719f82d3SEliot Blennerhassett {
2757719f82d3SEliot Blennerhassett 	u32 band = 0;
2758719f82d3SEliot Blennerhassett 	u16 error = 0;
2759719f82d3SEliot Blennerhassett 
2760719f82d3SEliot Blennerhassett 	error = hpi_control_param1_get(ph_subsys, h_control, HPI_TUNER_BAND,
2761719f82d3SEliot Blennerhassett 		&band);
2762719f82d3SEliot Blennerhassett 	if (pw_band)
2763719f82d3SEliot Blennerhassett 		*pw_band = (u16)band;
2764719f82d3SEliot Blennerhassett 	return error;
2765719f82d3SEliot Blennerhassett }
2766719f82d3SEliot Blennerhassett 
2767719f82d3SEliot Blennerhassett u16 hpi_tuner_query_frequency(const struct hpi_hsubsys *ph_subsys,
2768719f82d3SEliot Blennerhassett 	const u32 h_tuner, const u32 index, const u16 band, u32 *pfreq)
2769719f82d3SEliot Blennerhassett {
2770719f82d3SEliot Blennerhassett 	return hpi_control_query(ph_subsys, h_tuner, HPI_TUNER_FREQ, index,
2771719f82d3SEliot Blennerhassett 		band, pfreq);
2772719f82d3SEliot Blennerhassett }
2773719f82d3SEliot Blennerhassett 
2774719f82d3SEliot Blennerhassett u16 hpi_tuner_set_frequency(const struct hpi_hsubsys *ph_subsys,
2775719f82d3SEliot Blennerhassett 	u32 h_control, u32 freq_ink_hz)
2776719f82d3SEliot Blennerhassett {
2777719f82d3SEliot Blennerhassett 	return hpi_control_param_set(ph_subsys, h_control, HPI_TUNER_FREQ,
2778719f82d3SEliot Blennerhassett 		freq_ink_hz, 0);
2779719f82d3SEliot Blennerhassett }
2780719f82d3SEliot Blennerhassett 
2781719f82d3SEliot Blennerhassett u16 hpi_tuner_get_frequency(const struct hpi_hsubsys *ph_subsys,
2782719f82d3SEliot Blennerhassett 	u32 h_control, u32 *pw_freq_ink_hz)
2783719f82d3SEliot Blennerhassett {
2784719f82d3SEliot Blennerhassett 	return hpi_control_param1_get(ph_subsys, h_control, HPI_TUNER_FREQ,
2785719f82d3SEliot Blennerhassett 		pw_freq_ink_hz);
2786719f82d3SEliot Blennerhassett }
2787719f82d3SEliot Blennerhassett 
2788719f82d3SEliot Blennerhassett u16 hpi_tuner_query_gain(const struct hpi_hsubsys *ph_subsys,
2789719f82d3SEliot Blennerhassett 	const u32 h_tuner, const u32 index, u16 *pw_gain)
2790719f82d3SEliot Blennerhassett {
2791719f82d3SEliot Blennerhassett 	u32 qr;
2792719f82d3SEliot Blennerhassett 	u16 err;
2793719f82d3SEliot Blennerhassett 
2794719f82d3SEliot Blennerhassett 	err = hpi_control_query(ph_subsys, h_tuner, HPI_TUNER_BAND, index, 0,
2795719f82d3SEliot Blennerhassett 		&qr);
2796719f82d3SEliot Blennerhassett 	*pw_gain = (u16)qr;
2797719f82d3SEliot Blennerhassett 	return err;
2798719f82d3SEliot Blennerhassett }
2799719f82d3SEliot Blennerhassett 
2800719f82d3SEliot Blennerhassett u16 hpi_tuner_set_gain(const struct hpi_hsubsys *ph_subsys, u32 h_control,
2801719f82d3SEliot Blennerhassett 	short gain)
2802719f82d3SEliot Blennerhassett {
2803719f82d3SEliot Blennerhassett 	return hpi_control_param_set(ph_subsys, h_control, HPI_TUNER_GAIN,
2804719f82d3SEliot Blennerhassett 		gain, 0);
2805719f82d3SEliot Blennerhassett }
2806719f82d3SEliot Blennerhassett 
2807719f82d3SEliot Blennerhassett u16 hpi_tuner_get_gain(const struct hpi_hsubsys *ph_subsys, u32 h_control,
2808719f82d3SEliot Blennerhassett 	short *pn_gain)
2809719f82d3SEliot Blennerhassett {
2810719f82d3SEliot Blennerhassett 	u32 gain = 0;
2811719f82d3SEliot Blennerhassett 	u16 error = 0;
2812719f82d3SEliot Blennerhassett 
2813719f82d3SEliot Blennerhassett 	error = hpi_control_param1_get(ph_subsys, h_control, HPI_TUNER_GAIN,
2814719f82d3SEliot Blennerhassett 		&gain);
2815719f82d3SEliot Blennerhassett 	if (pn_gain)
2816719f82d3SEliot Blennerhassett 		*pn_gain = (u16)gain;
2817719f82d3SEliot Blennerhassett 	return error;
2818719f82d3SEliot Blennerhassett }
2819719f82d3SEliot Blennerhassett 
2820719f82d3SEliot Blennerhassett u16 hpi_tuner_getRF_level(const struct hpi_hsubsys *ph_subsys, u32 h_control,
2821719f82d3SEliot Blennerhassett 	short *pw_level)
2822719f82d3SEliot Blennerhassett {
2823719f82d3SEliot Blennerhassett 	struct hpi_message hm;
2824719f82d3SEliot Blennerhassett 	struct hpi_response hr;
2825719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2826719f82d3SEliot Blennerhassett 		HPI_CONTROL_GET_STATE);
2827719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
2828719f82d3SEliot Blennerhassett 	hm.u.c.attribute = HPI_TUNER_LEVEL;
2829719f82d3SEliot Blennerhassett 	hm.u.c.param1 = HPI_TUNER_LEVEL_AVERAGE;
2830719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
2831719f82d3SEliot Blennerhassett 	if (pw_level)
2832719f82d3SEliot Blennerhassett 		*pw_level = (short)hr.u.c.param1;
2833719f82d3SEliot Blennerhassett 	return hr.error;
2834719f82d3SEliot Blennerhassett }
2835719f82d3SEliot Blennerhassett 
2836719f82d3SEliot Blennerhassett u16 hpi_tuner_get_rawRF_level(const struct hpi_hsubsys *ph_subsys,
2837719f82d3SEliot Blennerhassett 	u32 h_control, short *pw_level)
2838719f82d3SEliot Blennerhassett {
2839719f82d3SEliot Blennerhassett 	struct hpi_message hm;
2840719f82d3SEliot Blennerhassett 	struct hpi_response hr;
2841719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2842719f82d3SEliot Blennerhassett 		HPI_CONTROL_GET_STATE);
2843719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
2844719f82d3SEliot Blennerhassett 	hm.u.c.attribute = HPI_TUNER_LEVEL;
2845719f82d3SEliot Blennerhassett 	hm.u.c.param1 = HPI_TUNER_LEVEL_RAW;
2846719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
2847719f82d3SEliot Blennerhassett 	if (pw_level)
2848719f82d3SEliot Blennerhassett 		*pw_level = (short)hr.u.c.param1;
2849719f82d3SEliot Blennerhassett 	return hr.error;
2850719f82d3SEliot Blennerhassett }
2851719f82d3SEliot Blennerhassett 
2852719f82d3SEliot Blennerhassett u16 hpi_tuner_query_deemphasis(const struct hpi_hsubsys *ph_subsys,
2853719f82d3SEliot Blennerhassett 	const u32 h_tuner, const u32 index, const u16 band, u32 *pdeemphasis)
2854719f82d3SEliot Blennerhassett {
2855719f82d3SEliot Blennerhassett 	return hpi_control_query(ph_subsys, h_tuner, HPI_TUNER_DEEMPHASIS,
2856719f82d3SEliot Blennerhassett 		index, band, pdeemphasis);
2857719f82d3SEliot Blennerhassett }
2858719f82d3SEliot Blennerhassett 
2859719f82d3SEliot Blennerhassett u16 hpi_tuner_set_deemphasis(const struct hpi_hsubsys *ph_subsys,
2860719f82d3SEliot Blennerhassett 	u32 h_control, u32 deemphasis)
2861719f82d3SEliot Blennerhassett {
2862719f82d3SEliot Blennerhassett 	return hpi_control_param_set(ph_subsys, h_control,
2863719f82d3SEliot Blennerhassett 		HPI_TUNER_DEEMPHASIS, deemphasis, 0);
2864719f82d3SEliot Blennerhassett }
2865719f82d3SEliot Blennerhassett 
2866719f82d3SEliot Blennerhassett u16 hpi_tuner_get_deemphasis(const struct hpi_hsubsys *ph_subsys,
2867719f82d3SEliot Blennerhassett 	u32 h_control, u32 *pdeemphasis)
2868719f82d3SEliot Blennerhassett {
2869719f82d3SEliot Blennerhassett 	return hpi_control_param1_get(ph_subsys, h_control,
2870719f82d3SEliot Blennerhassett 		HPI_TUNER_DEEMPHASIS, pdeemphasis);
2871719f82d3SEliot Blennerhassett }
2872719f82d3SEliot Blennerhassett 
2873719f82d3SEliot Blennerhassett u16 hpi_tuner_query_program(const struct hpi_hsubsys *ph_subsys,
2874719f82d3SEliot Blennerhassett 	const u32 h_tuner, u32 *pbitmap_program)
2875719f82d3SEliot Blennerhassett {
2876719f82d3SEliot Blennerhassett 	return hpi_control_query(ph_subsys, h_tuner, HPI_TUNER_PROGRAM, 0, 0,
2877719f82d3SEliot Blennerhassett 		pbitmap_program);
2878719f82d3SEliot Blennerhassett }
2879719f82d3SEliot Blennerhassett 
2880719f82d3SEliot Blennerhassett u16 hpi_tuner_set_program(const struct hpi_hsubsys *ph_subsys, u32 h_control,
2881719f82d3SEliot Blennerhassett 	u32 program)
2882719f82d3SEliot Blennerhassett {
2883719f82d3SEliot Blennerhassett 	return hpi_control_param_set(ph_subsys, h_control, HPI_TUNER_PROGRAM,
2884719f82d3SEliot Blennerhassett 		program, 0);
2885719f82d3SEliot Blennerhassett }
2886719f82d3SEliot Blennerhassett 
2887719f82d3SEliot Blennerhassett u16 hpi_tuner_get_program(const struct hpi_hsubsys *ph_subsys, u32 h_control,
2888719f82d3SEliot Blennerhassett 	u32 *pprogram)
2889719f82d3SEliot Blennerhassett {
2890719f82d3SEliot Blennerhassett 	return hpi_control_param1_get(ph_subsys, h_control, HPI_TUNER_PROGRAM,
2891719f82d3SEliot Blennerhassett 		pprogram);
2892719f82d3SEliot Blennerhassett }
2893719f82d3SEliot Blennerhassett 
2894719f82d3SEliot Blennerhassett u16 hpi_tuner_get_hd_radio_dsp_version(const struct hpi_hsubsys *ph_subsys,
2895719f82d3SEliot Blennerhassett 	u32 h_control, char *psz_dsp_version, const u32 string_size)
2896719f82d3SEliot Blennerhassett {
2897719f82d3SEliot Blennerhassett 	return hpi_control_get_string(ph_subsys, h_control,
2898719f82d3SEliot Blennerhassett 		HPI_TUNER_HDRADIO_DSP_VERSION, psz_dsp_version, string_size);
2899719f82d3SEliot Blennerhassett }
2900719f82d3SEliot Blennerhassett 
2901719f82d3SEliot Blennerhassett u16 hpi_tuner_get_hd_radio_sdk_version(const struct hpi_hsubsys *ph_subsys,
2902719f82d3SEliot Blennerhassett 	u32 h_control, char *psz_sdk_version, const u32 string_size)
2903719f82d3SEliot Blennerhassett {
2904719f82d3SEliot Blennerhassett 	return hpi_control_get_string(ph_subsys, h_control,
2905719f82d3SEliot Blennerhassett 		HPI_TUNER_HDRADIO_SDK_VERSION, psz_sdk_version, string_size);
2906719f82d3SEliot Blennerhassett }
2907719f82d3SEliot Blennerhassett 
2908719f82d3SEliot Blennerhassett u16 hpi_tuner_get_status(const struct hpi_hsubsys *ph_subsys, u32 h_control,
2909719f82d3SEliot Blennerhassett 	u16 *pw_status_mask, u16 *pw_status)
2910719f82d3SEliot Blennerhassett {
2911719f82d3SEliot Blennerhassett 	u32 status = 0;
2912719f82d3SEliot Blennerhassett 	u16 error = 0;
2913719f82d3SEliot Blennerhassett 
2914719f82d3SEliot Blennerhassett 	error = hpi_control_param1_get(ph_subsys, h_control, HPI_TUNER_STATUS,
2915719f82d3SEliot Blennerhassett 		&status);
2916719f82d3SEliot Blennerhassett 	if (pw_status) {
2917719f82d3SEliot Blennerhassett 		if (!error) {
2918719f82d3SEliot Blennerhassett 			*pw_status_mask = (u16)(status >> 16);
2919719f82d3SEliot Blennerhassett 			*pw_status = (u16)(status & 0xFFFF);
2920719f82d3SEliot Blennerhassett 		} else {
2921719f82d3SEliot Blennerhassett 			*pw_status_mask = 0;
2922719f82d3SEliot Blennerhassett 			*pw_status = 0;
2923719f82d3SEliot Blennerhassett 		}
2924719f82d3SEliot Blennerhassett 	}
2925719f82d3SEliot Blennerhassett 	return error;
2926719f82d3SEliot Blennerhassett }
2927719f82d3SEliot Blennerhassett 
2928719f82d3SEliot Blennerhassett u16 hpi_tuner_set_mode(const struct hpi_hsubsys *ph_subsys, u32 h_control,
2929719f82d3SEliot Blennerhassett 	u32 mode, u32 value)
2930719f82d3SEliot Blennerhassett {
2931719f82d3SEliot Blennerhassett 	return hpi_control_param_set(ph_subsys, h_control, HPI_TUNER_MODE,
2932719f82d3SEliot Blennerhassett 		mode, value);
2933719f82d3SEliot Blennerhassett }
2934719f82d3SEliot Blennerhassett 
2935719f82d3SEliot Blennerhassett u16 hpi_tuner_get_mode(const struct hpi_hsubsys *ph_subsys, u32 h_control,
2936719f82d3SEliot Blennerhassett 	u32 mode, u32 *pn_value)
2937719f82d3SEliot Blennerhassett {
2938719f82d3SEliot Blennerhassett 	return hpi_control_param_get(ph_subsys, h_control, HPI_TUNER_MODE,
2939719f82d3SEliot Blennerhassett 		mode, 0, pn_value, NULL);
2940719f82d3SEliot Blennerhassett }
2941719f82d3SEliot Blennerhassett 
2942719f82d3SEliot Blennerhassett u16 hpi_tuner_get_hd_radio_signal_quality(const struct hpi_hsubsys *ph_subsys,
2943719f82d3SEliot Blennerhassett 	u32 h_control, u32 *pquality)
2944719f82d3SEliot Blennerhassett {
2945719f82d3SEliot Blennerhassett 	return hpi_control_param_get(ph_subsys, h_control,
2946719f82d3SEliot Blennerhassett 		HPI_TUNER_HDRADIO_SIGNAL_QUALITY, 0, 0, pquality, NULL);
2947719f82d3SEliot Blennerhassett }
2948719f82d3SEliot Blennerhassett 
2949*5a498ef1SEliot Blennerhassett u16 hpi_tuner_get_hd_radio_signal_blend(const struct hpi_hsubsys *ph_subsys,
2950*5a498ef1SEliot Blennerhassett 	u32 h_control, u32 *pblend)
2951*5a498ef1SEliot Blennerhassett {
2952*5a498ef1SEliot Blennerhassett 	return hpi_control_param_get(ph_subsys, h_control,
2953*5a498ef1SEliot Blennerhassett 		HPI_TUNER_HDRADIO_BLEND, 0, 0, pblend, NULL);
2954*5a498ef1SEliot Blennerhassett }
2955*5a498ef1SEliot Blennerhassett 
2956*5a498ef1SEliot Blennerhassett u16 hpi_tuner_set_hd_radio_signal_blend(const struct hpi_hsubsys *ph_subsys,
2957*5a498ef1SEliot Blennerhassett 	u32 h_control, const u32 blend)
2958*5a498ef1SEliot Blennerhassett {
2959*5a498ef1SEliot Blennerhassett 	return hpi_control_param_set(ph_subsys, h_control,
2960*5a498ef1SEliot Blennerhassett 		HPI_TUNER_HDRADIO_BLEND, blend, 0);
2961*5a498ef1SEliot Blennerhassett }
2962*5a498ef1SEliot Blennerhassett 
2963719f82d3SEliot Blennerhassett u16 hpi_tuner_getRDS(const struct hpi_hsubsys *ph_subsys, u32 h_control,
2964719f82d3SEliot Blennerhassett 	char *p_data)
2965719f82d3SEliot Blennerhassett {
2966719f82d3SEliot Blennerhassett 	struct hpi_message hm;
2967719f82d3SEliot Blennerhassett 	struct hpi_response hr;
2968719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2969719f82d3SEliot Blennerhassett 		HPI_CONTROL_GET_STATE);
2970719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
2971719f82d3SEliot Blennerhassett 	hm.u.c.attribute = HPI_TUNER_RDS;
2972719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
2973719f82d3SEliot Blennerhassett 	if (p_data) {
2974719f82d3SEliot Blennerhassett 		*(u32 *)&p_data[0] = hr.u.cu.tuner.rds.data[0];
2975719f82d3SEliot Blennerhassett 		*(u32 *)&p_data[4] = hr.u.cu.tuner.rds.data[1];
2976719f82d3SEliot Blennerhassett 		*(u32 *)&p_data[8] = hr.u.cu.tuner.rds.bLER;
2977719f82d3SEliot Blennerhassett 	}
2978719f82d3SEliot Blennerhassett 	return hr.error;
2979719f82d3SEliot Blennerhassett }
2980719f82d3SEliot Blennerhassett 
2981719f82d3SEliot Blennerhassett u16 HPI_PAD__get_channel_name(const struct hpi_hsubsys *ph_subsys,
2982719f82d3SEliot Blennerhassett 	u32 h_control, char *psz_string, const u32 data_length)
2983719f82d3SEliot Blennerhassett {
2984719f82d3SEliot Blennerhassett 	return hpi_control_get_string(ph_subsys, h_control,
2985719f82d3SEliot Blennerhassett 		HPI_PAD_CHANNEL_NAME, psz_string, data_length);
2986719f82d3SEliot Blennerhassett }
2987719f82d3SEliot Blennerhassett 
2988719f82d3SEliot Blennerhassett u16 HPI_PAD__get_artist(const struct hpi_hsubsys *ph_subsys, u32 h_control,
2989719f82d3SEliot Blennerhassett 	char *psz_string, const u32 data_length)
2990719f82d3SEliot Blennerhassett {
2991719f82d3SEliot Blennerhassett 	return hpi_control_get_string(ph_subsys, h_control, HPI_PAD_ARTIST,
2992719f82d3SEliot Blennerhassett 		psz_string, data_length);
2993719f82d3SEliot Blennerhassett }
2994719f82d3SEliot Blennerhassett 
2995719f82d3SEliot Blennerhassett u16 HPI_PAD__get_title(const struct hpi_hsubsys *ph_subsys, u32 h_control,
2996719f82d3SEliot Blennerhassett 	char *psz_string, const u32 data_length)
2997719f82d3SEliot Blennerhassett {
2998719f82d3SEliot Blennerhassett 	return hpi_control_get_string(ph_subsys, h_control, HPI_PAD_TITLE,
2999719f82d3SEliot Blennerhassett 		psz_string, data_length);
3000719f82d3SEliot Blennerhassett }
3001719f82d3SEliot Blennerhassett 
3002719f82d3SEliot Blennerhassett u16 HPI_PAD__get_comment(const struct hpi_hsubsys *ph_subsys, u32 h_control,
3003719f82d3SEliot Blennerhassett 	char *psz_string, const u32 data_length)
3004719f82d3SEliot Blennerhassett {
3005719f82d3SEliot Blennerhassett 	return hpi_control_get_string(ph_subsys, h_control, HPI_PAD_COMMENT,
3006719f82d3SEliot Blennerhassett 		psz_string, data_length);
3007719f82d3SEliot Blennerhassett }
3008719f82d3SEliot Blennerhassett 
3009719f82d3SEliot Blennerhassett u16 HPI_PAD__get_program_type(const struct hpi_hsubsys *ph_subsys,
3010719f82d3SEliot Blennerhassett 	u32 h_control, u32 *ppTY)
3011719f82d3SEliot Blennerhassett {
3012719f82d3SEliot Blennerhassett 	return hpi_control_param_get(ph_subsys, h_control,
3013719f82d3SEliot Blennerhassett 		HPI_PAD_PROGRAM_TYPE, 0, 0, ppTY, NULL);
3014719f82d3SEliot Blennerhassett }
3015719f82d3SEliot Blennerhassett 
3016719f82d3SEliot Blennerhassett u16 HPI_PAD__get_rdsPI(const struct hpi_hsubsys *ph_subsys, u32 h_control,
3017719f82d3SEliot Blennerhassett 	u32 *ppI)
3018719f82d3SEliot Blennerhassett {
3019719f82d3SEliot Blennerhassett 	return hpi_control_param_get(ph_subsys, h_control, HPI_PAD_PROGRAM_ID,
3020719f82d3SEliot Blennerhassett 		0, 0, ppI, NULL);
3021719f82d3SEliot Blennerhassett }
3022719f82d3SEliot Blennerhassett 
3023719f82d3SEliot Blennerhassett u16 hpi_volume_query_channels(const struct hpi_hsubsys *ph_subsys,
3024719f82d3SEliot Blennerhassett 	const u32 h_volume, u32 *p_channels)
3025719f82d3SEliot Blennerhassett {
3026719f82d3SEliot Blennerhassett 	return hpi_control_query(ph_subsys, h_volume, HPI_VOLUME_NUM_CHANNELS,
3027719f82d3SEliot Blennerhassett 		0, 0, p_channels);
3028719f82d3SEliot Blennerhassett }
3029719f82d3SEliot Blennerhassett 
3030719f82d3SEliot Blennerhassett u16 hpi_volume_set_gain(const struct hpi_hsubsys *ph_subsys, u32 h_control,
3031719f82d3SEliot Blennerhassett 	short an_log_gain[HPI_MAX_CHANNELS]
3032719f82d3SEliot Blennerhassett 	)
3033719f82d3SEliot Blennerhassett {
3034719f82d3SEliot Blennerhassett 	struct hpi_message hm;
3035719f82d3SEliot Blennerhassett 	struct hpi_response hr;
3036719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
3037719f82d3SEliot Blennerhassett 		HPI_CONTROL_SET_STATE);
3038719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
3039719f82d3SEliot Blennerhassett 	memcpy(hm.u.c.an_log_value, an_log_gain,
3040719f82d3SEliot Blennerhassett 		sizeof(short) * HPI_MAX_CHANNELS);
3041719f82d3SEliot Blennerhassett 	hm.u.c.attribute = HPI_VOLUME_GAIN;
3042719f82d3SEliot Blennerhassett 
3043719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
3044719f82d3SEliot Blennerhassett 
3045719f82d3SEliot Blennerhassett 	return hr.error;
3046719f82d3SEliot Blennerhassett }
3047719f82d3SEliot Blennerhassett 
3048719f82d3SEliot Blennerhassett u16 hpi_volume_get_gain(const struct hpi_hsubsys *ph_subsys, u32 h_control,
3049719f82d3SEliot Blennerhassett 	short an_log_gain[HPI_MAX_CHANNELS]
3050719f82d3SEliot Blennerhassett 	)
3051719f82d3SEliot Blennerhassett {
3052719f82d3SEliot Blennerhassett 	struct hpi_message hm;
3053719f82d3SEliot Blennerhassett 	struct hpi_response hr;
3054719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
3055719f82d3SEliot Blennerhassett 		HPI_CONTROL_GET_STATE);
3056719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
3057719f82d3SEliot Blennerhassett 	hm.u.c.attribute = HPI_VOLUME_GAIN;
3058719f82d3SEliot Blennerhassett 
3059719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
3060719f82d3SEliot Blennerhassett 
3061719f82d3SEliot Blennerhassett 	memcpy(an_log_gain, hr.u.c.an_log_value,
3062719f82d3SEliot Blennerhassett 		sizeof(short) * HPI_MAX_CHANNELS);
3063719f82d3SEliot Blennerhassett 	return hr.error;
3064719f82d3SEliot Blennerhassett }
3065719f82d3SEliot Blennerhassett 
3066719f82d3SEliot Blennerhassett u16 hpi_volume_query_range(const struct hpi_hsubsys *ph_subsys, u32 h_control,
3067719f82d3SEliot Blennerhassett 	short *min_gain_01dB, short *max_gain_01dB, short *step_gain_01dB)
3068719f82d3SEliot Blennerhassett {
3069719f82d3SEliot Blennerhassett 	struct hpi_message hm;
3070719f82d3SEliot Blennerhassett 	struct hpi_response hr;
3071719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
3072719f82d3SEliot Blennerhassett 		HPI_CONTROL_GET_STATE);
3073719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
3074719f82d3SEliot Blennerhassett 	hm.u.c.attribute = HPI_VOLUME_RANGE;
3075719f82d3SEliot Blennerhassett 
3076719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
3077719f82d3SEliot Blennerhassett 	if (hr.error) {
3078719f82d3SEliot Blennerhassett 		hr.u.c.an_log_value[0] = 0;
3079719f82d3SEliot Blennerhassett 		hr.u.c.an_log_value[1] = 0;
3080719f82d3SEliot Blennerhassett 		hr.u.c.param1 = 0;
3081719f82d3SEliot Blennerhassett 	}
3082719f82d3SEliot Blennerhassett 	if (min_gain_01dB)
3083719f82d3SEliot Blennerhassett 		*min_gain_01dB = hr.u.c.an_log_value[0];
3084719f82d3SEliot Blennerhassett 	if (max_gain_01dB)
3085719f82d3SEliot Blennerhassett 		*max_gain_01dB = hr.u.c.an_log_value[1];
3086719f82d3SEliot Blennerhassett 	if (step_gain_01dB)
3087719f82d3SEliot Blennerhassett 		*step_gain_01dB = (short)hr.u.c.param1;
3088719f82d3SEliot Blennerhassett 	return hr.error;
3089719f82d3SEliot Blennerhassett }
3090719f82d3SEliot Blennerhassett 
3091719f82d3SEliot Blennerhassett u16 hpi_volume_auto_fade_profile(const struct hpi_hsubsys *ph_subsys,
3092719f82d3SEliot Blennerhassett 	u32 h_control, short an_stop_gain0_01dB[HPI_MAX_CHANNELS],
3093719f82d3SEliot Blennerhassett 	u32 duration_ms, u16 profile)
3094719f82d3SEliot Blennerhassett {
3095719f82d3SEliot Blennerhassett 	struct hpi_message hm;
3096719f82d3SEliot Blennerhassett 	struct hpi_response hr;
3097719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
3098719f82d3SEliot Blennerhassett 		HPI_CONTROL_SET_STATE);
3099719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
3100719f82d3SEliot Blennerhassett 
3101719f82d3SEliot Blennerhassett 	memcpy(hm.u.c.an_log_value, an_stop_gain0_01dB,
3102719f82d3SEliot Blennerhassett 		sizeof(short) * HPI_MAX_CHANNELS);
3103719f82d3SEliot Blennerhassett 
3104719f82d3SEliot Blennerhassett 	hm.u.c.attribute = HPI_VOLUME_AUTOFADE;
3105719f82d3SEliot Blennerhassett 	hm.u.c.param1 = duration_ms;
3106719f82d3SEliot Blennerhassett 	hm.u.c.param2 = profile;
3107719f82d3SEliot Blennerhassett 
3108719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
3109719f82d3SEliot Blennerhassett 
3110719f82d3SEliot Blennerhassett 	return hr.error;
3111719f82d3SEliot Blennerhassett }
3112719f82d3SEliot Blennerhassett 
3113719f82d3SEliot Blennerhassett u16 hpi_volume_auto_fade(const struct hpi_hsubsys *ph_subsys, u32 h_control,
3114719f82d3SEliot Blennerhassett 	short an_stop_gain0_01dB[HPI_MAX_CHANNELS], u32 duration_ms)
3115719f82d3SEliot Blennerhassett {
3116719f82d3SEliot Blennerhassett 	return hpi_volume_auto_fade_profile(ph_subsys, h_control,
3117719f82d3SEliot Blennerhassett 		an_stop_gain0_01dB, duration_ms, HPI_VOLUME_AUTOFADE_LOG);
3118719f82d3SEliot Blennerhassett }
3119719f82d3SEliot Blennerhassett 
3120719f82d3SEliot Blennerhassett u16 hpi_vox_set_threshold(const struct hpi_hsubsys *ph_subsys, u32 h_control,
3121719f82d3SEliot Blennerhassett 	short an_gain0_01dB)
3122719f82d3SEliot Blennerhassett {
3123719f82d3SEliot Blennerhassett 	struct hpi_message hm;
3124719f82d3SEliot Blennerhassett 	struct hpi_response hr;
3125719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
3126719f82d3SEliot Blennerhassett 		HPI_CONTROL_SET_STATE);
3127719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
3128719f82d3SEliot Blennerhassett 	hm.u.c.attribute = HPI_VOX_THRESHOLD;
3129719f82d3SEliot Blennerhassett 
3130719f82d3SEliot Blennerhassett 	hm.u.c.an_log_value[0] = an_gain0_01dB;
3131719f82d3SEliot Blennerhassett 
3132719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
3133719f82d3SEliot Blennerhassett 
3134719f82d3SEliot Blennerhassett 	return hr.error;
3135719f82d3SEliot Blennerhassett }
3136719f82d3SEliot Blennerhassett 
3137719f82d3SEliot Blennerhassett u16 hpi_vox_get_threshold(const struct hpi_hsubsys *ph_subsys, u32 h_control,
3138719f82d3SEliot Blennerhassett 	short *an_gain0_01dB)
3139719f82d3SEliot Blennerhassett {
3140719f82d3SEliot Blennerhassett 	struct hpi_message hm;
3141719f82d3SEliot Blennerhassett 	struct hpi_response hr;
3142719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
3143719f82d3SEliot Blennerhassett 		HPI_CONTROL_GET_STATE);
3144719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
3145719f82d3SEliot Blennerhassett 	hm.u.c.attribute = HPI_VOX_THRESHOLD;
3146719f82d3SEliot Blennerhassett 
3147719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
3148719f82d3SEliot Blennerhassett 
3149719f82d3SEliot Blennerhassett 	*an_gain0_01dB = hr.u.c.an_log_value[0];
3150719f82d3SEliot Blennerhassett 
3151719f82d3SEliot Blennerhassett 	return hr.error;
3152719f82d3SEliot Blennerhassett }
3153719f82d3SEliot Blennerhassett 
3154719f82d3SEliot Blennerhassett static size_t strv_packet_size = MIN_STRV_PACKET_SIZE;
3155719f82d3SEliot Blennerhassett 
3156719f82d3SEliot Blennerhassett static size_t entity_type_to_size[LAST_ENTITY_TYPE] = {
3157719f82d3SEliot Blennerhassett 	0,
3158719f82d3SEliot Blennerhassett 	sizeof(struct hpi_entity),
3159719f82d3SEliot Blennerhassett 	sizeof(void *),
3160719f82d3SEliot Blennerhassett 
3161719f82d3SEliot Blennerhassett 	sizeof(int),
3162719f82d3SEliot Blennerhassett 	sizeof(float),
3163719f82d3SEliot Blennerhassett 	sizeof(double),
3164719f82d3SEliot Blennerhassett 
3165719f82d3SEliot Blennerhassett 	sizeof(char),
3166719f82d3SEliot Blennerhassett 	sizeof(char),
3167719f82d3SEliot Blennerhassett 
3168719f82d3SEliot Blennerhassett 	4 * sizeof(char),
3169719f82d3SEliot Blennerhassett 	16 * sizeof(char),
3170719f82d3SEliot Blennerhassett 	6 * sizeof(char),
3171719f82d3SEliot Blennerhassett };
3172719f82d3SEliot Blennerhassett 
3173719f82d3SEliot Blennerhassett inline size_t hpi_entity_size(struct hpi_entity *entity_ptr)
3174719f82d3SEliot Blennerhassett {
3175719f82d3SEliot Blennerhassett 	return entity_ptr->header.size;
3176719f82d3SEliot Blennerhassett }
3177719f82d3SEliot Blennerhassett 
3178719f82d3SEliot Blennerhassett inline size_t hpi_entity_header_size(struct hpi_entity *entity_ptr)
3179719f82d3SEliot Blennerhassett {
3180719f82d3SEliot Blennerhassett 	return sizeof(entity_ptr->header);
3181719f82d3SEliot Blennerhassett }
3182719f82d3SEliot Blennerhassett 
3183719f82d3SEliot Blennerhassett inline size_t hpi_entity_value_size(struct hpi_entity *entity_ptr)
3184719f82d3SEliot Blennerhassett {
3185719f82d3SEliot Blennerhassett 	return hpi_entity_size(entity_ptr) -
3186719f82d3SEliot Blennerhassett 		hpi_entity_header_size(entity_ptr);
3187719f82d3SEliot Blennerhassett }
3188719f82d3SEliot Blennerhassett 
3189719f82d3SEliot Blennerhassett inline size_t hpi_entity_item_count(struct hpi_entity *entity_ptr)
3190719f82d3SEliot Blennerhassett {
3191719f82d3SEliot Blennerhassett 	return hpi_entity_value_size(entity_ptr) /
3192719f82d3SEliot Blennerhassett 		entity_type_to_size[entity_ptr->header.type];
3193719f82d3SEliot Blennerhassett }
3194719f82d3SEliot Blennerhassett 
3195719f82d3SEliot Blennerhassett inline struct hpi_entity *hpi_entity_ptr_to_next(struct hpi_entity
3196719f82d3SEliot Blennerhassett 	*entity_ptr)
3197719f82d3SEliot Blennerhassett {
3198719f82d3SEliot Blennerhassett 	return (void *)(((uint8_t *) entity_ptr) +
3199719f82d3SEliot Blennerhassett 		hpi_entity_size(entity_ptr));
3200719f82d3SEliot Blennerhassett }
3201719f82d3SEliot Blennerhassett 
3202719f82d3SEliot Blennerhassett inline u16 hpi_entity_check_type(const enum e_entity_type t)
3203719f82d3SEliot Blennerhassett {
3204719f82d3SEliot Blennerhassett 	if (t >= 0 && t < STR_TYPE_FIELD_MAX)
3205719f82d3SEliot Blennerhassett 		return 0;
3206719f82d3SEliot Blennerhassett 	return HPI_ERROR_ENTITY_TYPE_INVALID;
3207719f82d3SEliot Blennerhassett }
3208719f82d3SEliot Blennerhassett 
3209719f82d3SEliot Blennerhassett inline u16 hpi_entity_check_role(const enum e_entity_role r)
3210719f82d3SEliot Blennerhassett {
3211719f82d3SEliot Blennerhassett 	if (r >= 0 && r < STR_ROLE_FIELD_MAX)
3212719f82d3SEliot Blennerhassett 		return 0;
3213719f82d3SEliot Blennerhassett 	return HPI_ERROR_ENTITY_ROLE_INVALID;
3214719f82d3SEliot Blennerhassett }
3215719f82d3SEliot Blennerhassett 
3216719f82d3SEliot Blennerhassett static u16 hpi_entity_get_next(struct hpi_entity *entity, int recursive_flag,
3217719f82d3SEliot Blennerhassett 	void *guard_p, struct hpi_entity **next)
3218719f82d3SEliot Blennerhassett {
3219719f82d3SEliot Blennerhassett 	HPI_DEBUG_ASSERT(entity != NULL);
3220719f82d3SEliot Blennerhassett 	HPI_DEBUG_ASSERT(next != NULL);
3221719f82d3SEliot Blennerhassett 	HPI_DEBUG_ASSERT(hpi_entity_size(entity) != 0);
3222719f82d3SEliot Blennerhassett 
3223719f82d3SEliot Blennerhassett 	if (guard_p <= (void *)entity) {
3224719f82d3SEliot Blennerhassett 		*next = NULL;
3225719f82d3SEliot Blennerhassett 		return 0;
3226719f82d3SEliot Blennerhassett 	}
3227719f82d3SEliot Blennerhassett 
3228719f82d3SEliot Blennerhassett 	if (recursive_flag && entity->header.type == entity_type_sequence)
3229719f82d3SEliot Blennerhassett 		*next = (struct hpi_entity *)entity->value;
3230719f82d3SEliot Blennerhassett 	else
3231719f82d3SEliot Blennerhassett 		*next = (struct hpi_entity *)hpi_entity_ptr_to_next(entity);
3232719f82d3SEliot Blennerhassett 
3233719f82d3SEliot Blennerhassett 	if (guard_p <= (void *)*next) {
3234719f82d3SEliot Blennerhassett 		*next = NULL;
3235719f82d3SEliot Blennerhassett 		return 0;
3236719f82d3SEliot Blennerhassett 	}
3237719f82d3SEliot Blennerhassett 
3238719f82d3SEliot Blennerhassett 	HPI_DEBUG_ASSERT(guard_p >= (void *)hpi_entity_ptr_to_next(*next));
3239719f82d3SEliot Blennerhassett 	return 0;
3240719f82d3SEliot Blennerhassett }
3241719f82d3SEliot Blennerhassett 
3242719f82d3SEliot Blennerhassett u16 hpi_entity_find_next(struct hpi_entity *container_entity,
3243719f82d3SEliot Blennerhassett 	enum e_entity_type type, enum e_entity_role role, int recursive_flag,
3244719f82d3SEliot Blennerhassett 	struct hpi_entity **current_match)
3245719f82d3SEliot Blennerhassett {
3246719f82d3SEliot Blennerhassett 	struct hpi_entity *tmp = NULL;
3247719f82d3SEliot Blennerhassett 	void *guard_p = NULL;
3248719f82d3SEliot Blennerhassett 
3249719f82d3SEliot Blennerhassett 	HPI_DEBUG_ASSERT(container_entity != NULL);
3250719f82d3SEliot Blennerhassett 	guard_p = hpi_entity_ptr_to_next(container_entity);
3251719f82d3SEliot Blennerhassett 
3252719f82d3SEliot Blennerhassett 	if (*current_match != NULL)
3253719f82d3SEliot Blennerhassett 		hpi_entity_get_next(*current_match, recursive_flag, guard_p,
3254719f82d3SEliot Blennerhassett 			&tmp);
3255719f82d3SEliot Blennerhassett 	else
3256719f82d3SEliot Blennerhassett 		hpi_entity_get_next(container_entity, 1, guard_p, &tmp);
3257719f82d3SEliot Blennerhassett 
3258719f82d3SEliot Blennerhassett 	while (tmp) {
3259719f82d3SEliot Blennerhassett 		u16 err;
3260719f82d3SEliot Blennerhassett 
3261719f82d3SEliot Blennerhassett 		HPI_DEBUG_ASSERT((void *)tmp >= (void *)container_entity);
3262719f82d3SEliot Blennerhassett 
3263719f82d3SEliot Blennerhassett 		if ((!type || tmp->header.type == type) && (!role
3264719f82d3SEliot Blennerhassett 				|| tmp->header.role == role)) {
3265719f82d3SEliot Blennerhassett 			*current_match = tmp;
3266719f82d3SEliot Blennerhassett 			return 0;
3267719f82d3SEliot Blennerhassett 		}
3268719f82d3SEliot Blennerhassett 
3269719f82d3SEliot Blennerhassett 		err = hpi_entity_get_next(tmp, recursive_flag, guard_p,
3270719f82d3SEliot Blennerhassett 			current_match);
3271719f82d3SEliot Blennerhassett 		if (err)
3272719f82d3SEliot Blennerhassett 			return err;
3273719f82d3SEliot Blennerhassett 
3274719f82d3SEliot Blennerhassett 		tmp = *current_match;
3275719f82d3SEliot Blennerhassett 	}
3276719f82d3SEliot Blennerhassett 
3277719f82d3SEliot Blennerhassett 	*current_match = NULL;
3278719f82d3SEliot Blennerhassett 	return 0;
3279719f82d3SEliot Blennerhassett }
3280719f82d3SEliot Blennerhassett 
3281719f82d3SEliot Blennerhassett void hpi_entity_free(struct hpi_entity *entity)
3282719f82d3SEliot Blennerhassett {
3283719f82d3SEliot Blennerhassett 	kfree(entity);
3284719f82d3SEliot Blennerhassett }
3285719f82d3SEliot Blennerhassett 
3286719f82d3SEliot Blennerhassett static u16 hpi_entity_alloc_and_copy(struct hpi_entity *src,
3287719f82d3SEliot Blennerhassett 	struct hpi_entity **dst)
3288719f82d3SEliot Blennerhassett {
3289719f82d3SEliot Blennerhassett 	size_t buf_size;
3290719f82d3SEliot Blennerhassett 	HPI_DEBUG_ASSERT(dst != NULL);
3291719f82d3SEliot Blennerhassett 	HPI_DEBUG_ASSERT(src != NULL);
3292719f82d3SEliot Blennerhassett 
3293719f82d3SEliot Blennerhassett 	buf_size = hpi_entity_size(src);
3294719f82d3SEliot Blennerhassett 	*dst = kmalloc(buf_size, GFP_KERNEL);
32952448b147SDan Carpenter 	if (*dst == NULL)
3296719f82d3SEliot Blennerhassett 		return HPI_ERROR_MEMORY_ALLOC;
3297719f82d3SEliot Blennerhassett 	memcpy(*dst, src, buf_size);
3298719f82d3SEliot Blennerhassett 	return 0;
3299719f82d3SEliot Blennerhassett }
3300719f82d3SEliot Blennerhassett 
3301719f82d3SEliot Blennerhassett u16 hpi_universal_info(const struct hpi_hsubsys *ph_subsys, u32 hC,
3302719f82d3SEliot Blennerhassett 	struct hpi_entity **info)
3303719f82d3SEliot Blennerhassett {
3304719f82d3SEliot Blennerhassett 	struct hpi_msg_strv hm;
3305719f82d3SEliot Blennerhassett 	struct hpi_res_strv *phr;
3306719f82d3SEliot Blennerhassett 	u16 hpi_err;
3307719f82d3SEliot Blennerhassett 	int remaining_attempts = 2;
3308719f82d3SEliot Blennerhassett 	size_t resp_packet_size = 1024;
3309719f82d3SEliot Blennerhassett 
3310719f82d3SEliot Blennerhassett 	*info = NULL;
3311719f82d3SEliot Blennerhassett 
3312719f82d3SEliot Blennerhassett 	while (remaining_attempts--) {
3313719f82d3SEliot Blennerhassett 		phr = kmalloc(resp_packet_size, GFP_KERNEL);
3314719f82d3SEliot Blennerhassett 		HPI_DEBUG_ASSERT(phr != NULL);
3315719f82d3SEliot Blennerhassett 
3316719f82d3SEliot Blennerhassett 		hpi_init_message_responseV1(&hm.h, (u16)sizeof(hm), &phr->h,
3317719f82d3SEliot Blennerhassett 			(u16)resp_packet_size, HPI_OBJ_CONTROL,
3318719f82d3SEliot Blennerhassett 			HPI_CONTROL_GET_INFO);
3319719f82d3SEliot Blennerhassett 		u32TOINDEXES(hC, &hm.h.adapter_index, &hm.h.obj_index);
3320719f82d3SEliot Blennerhassett 
3321719f82d3SEliot Blennerhassett 		hm.strv.header.size = sizeof(hm.strv);
3322719f82d3SEliot Blennerhassett 		phr->strv.header.size = resp_packet_size - sizeof(phr->h);
3323719f82d3SEliot Blennerhassett 
3324719f82d3SEliot Blennerhassett 		hpi_send_recv((struct hpi_message *)&hm.h,
3325719f82d3SEliot Blennerhassett 			(struct hpi_response *)&phr->h);
3326719f82d3SEliot Blennerhassett 		if (phr->h.error == HPI_ERROR_RESPONSE_BUFFER_TOO_SMALL) {
3327719f82d3SEliot Blennerhassett 
3328719f82d3SEliot Blennerhassett 			HPI_DEBUG_ASSERT(phr->h.specific_error >
3329719f82d3SEliot Blennerhassett 				MIN_STRV_PACKET_SIZE
3330719f82d3SEliot Blennerhassett 				&& phr->h.specific_error < 1500);
3331719f82d3SEliot Blennerhassett 			resp_packet_size = phr->h.specific_error;
3332719f82d3SEliot Blennerhassett 		} else {
3333719f82d3SEliot Blennerhassett 			remaining_attempts = 0;
3334719f82d3SEliot Blennerhassett 			if (!phr->h.error)
3335719f82d3SEliot Blennerhassett 				hpi_entity_alloc_and_copy(&phr->strv, info);
3336719f82d3SEliot Blennerhassett 		}
3337719f82d3SEliot Blennerhassett 
3338719f82d3SEliot Blennerhassett 		hpi_err = phr->h.error;
3339719f82d3SEliot Blennerhassett 		kfree(phr);
3340719f82d3SEliot Blennerhassett 	}
3341719f82d3SEliot Blennerhassett 
3342719f82d3SEliot Blennerhassett 	return hpi_err;
3343719f82d3SEliot Blennerhassett }
3344719f82d3SEliot Blennerhassett 
3345719f82d3SEliot Blennerhassett u16 hpi_universal_get(const struct hpi_hsubsys *ph_subsys, u32 hC,
3346719f82d3SEliot Blennerhassett 	struct hpi_entity **value)
3347719f82d3SEliot Blennerhassett {
3348719f82d3SEliot Blennerhassett 	struct hpi_msg_strv hm;
3349719f82d3SEliot Blennerhassett 	struct hpi_res_strv *phr;
3350719f82d3SEliot Blennerhassett 	u16 hpi_err;
3351719f82d3SEliot Blennerhassett 	int remaining_attempts = 2;
3352719f82d3SEliot Blennerhassett 
3353719f82d3SEliot Blennerhassett 	*value = NULL;
3354719f82d3SEliot Blennerhassett 
3355719f82d3SEliot Blennerhassett 	while (remaining_attempts--) {
3356719f82d3SEliot Blennerhassett 		phr = kmalloc(strv_packet_size, GFP_KERNEL);
3357719f82d3SEliot Blennerhassett 		if (!phr)
3358719f82d3SEliot Blennerhassett 			return HPI_ERROR_MEMORY_ALLOC;
3359719f82d3SEliot Blennerhassett 
3360719f82d3SEliot Blennerhassett 		hpi_init_message_responseV1(&hm.h, (u16)sizeof(hm), &phr->h,
3361719f82d3SEliot Blennerhassett 			(u16)strv_packet_size, HPI_OBJ_CONTROL,
3362719f82d3SEliot Blennerhassett 			HPI_CONTROL_GET_STATE);
3363719f82d3SEliot Blennerhassett 		u32TOINDEXES(hC, &hm.h.adapter_index, &hm.h.obj_index);
3364719f82d3SEliot Blennerhassett 
3365719f82d3SEliot Blennerhassett 		hm.strv.header.size = sizeof(hm.strv);
3366719f82d3SEliot Blennerhassett 		phr->strv.header.size = strv_packet_size - sizeof(phr->h);
3367719f82d3SEliot Blennerhassett 
3368719f82d3SEliot Blennerhassett 		hpi_send_recv((struct hpi_message *)&hm.h,
3369719f82d3SEliot Blennerhassett 			(struct hpi_response *)&phr->h);
3370719f82d3SEliot Blennerhassett 		if (phr->h.error == HPI_ERROR_RESPONSE_BUFFER_TOO_SMALL) {
3371719f82d3SEliot Blennerhassett 
3372719f82d3SEliot Blennerhassett 			HPI_DEBUG_ASSERT(phr->h.specific_error >
3373719f82d3SEliot Blennerhassett 				MIN_STRV_PACKET_SIZE
3374719f82d3SEliot Blennerhassett 				&& phr->h.specific_error < 1000);
3375719f82d3SEliot Blennerhassett 			strv_packet_size = phr->h.specific_error;
3376719f82d3SEliot Blennerhassett 		} else {
3377719f82d3SEliot Blennerhassett 			remaining_attempts = 0;
3378719f82d3SEliot Blennerhassett 			if (!phr->h.error)
3379719f82d3SEliot Blennerhassett 				hpi_entity_alloc_and_copy(&phr->strv, value);
3380719f82d3SEliot Blennerhassett 		}
3381719f82d3SEliot Blennerhassett 
3382719f82d3SEliot Blennerhassett 		hpi_err = phr->h.error;
3383719f82d3SEliot Blennerhassett 		kfree(phr);
3384719f82d3SEliot Blennerhassett 	}
3385719f82d3SEliot Blennerhassett 
3386719f82d3SEliot Blennerhassett 	return hpi_err;
3387719f82d3SEliot Blennerhassett }
3388719f82d3SEliot Blennerhassett 
3389719f82d3SEliot Blennerhassett u16 hpi_universal_set(const struct hpi_hsubsys *ph_subsys, u32 hC,
3390719f82d3SEliot Blennerhassett 	struct hpi_entity *value)
3391719f82d3SEliot Blennerhassett {
3392719f82d3SEliot Blennerhassett 	struct hpi_msg_strv *phm;
3393719f82d3SEliot Blennerhassett 	struct hpi_res_strv hr;
3394719f82d3SEliot Blennerhassett 
3395719f82d3SEliot Blennerhassett 	phm = kmalloc(sizeof(phm->h) + value->header.size, GFP_KERNEL);
3396719f82d3SEliot Blennerhassett 	HPI_DEBUG_ASSERT(phm != NULL);
3397719f82d3SEliot Blennerhassett 
3398719f82d3SEliot Blennerhassett 	hpi_init_message_responseV1(&phm->h,
3399719f82d3SEliot Blennerhassett 		sizeof(phm->h) + value->header.size, &hr.h, sizeof(hr),
3400719f82d3SEliot Blennerhassett 		HPI_OBJ_CONTROL, HPI_CONTROL_SET_STATE);
3401719f82d3SEliot Blennerhassett 	u32TOINDEXES(hC, &phm->h.adapter_index, &phm->h.obj_index);
3402719f82d3SEliot Blennerhassett 	hr.strv.header.size = sizeof(hr.strv);
3403719f82d3SEliot Blennerhassett 
3404719f82d3SEliot Blennerhassett 	memcpy(&phm->strv, value, value->header.size);
3405719f82d3SEliot Blennerhassett 	hpi_send_recv((struct hpi_message *)&phm->h,
3406719f82d3SEliot Blennerhassett 		(struct hpi_response *)&hr.h);
3407719f82d3SEliot Blennerhassett 
3408719f82d3SEliot Blennerhassett 	return hr.h.error;
3409719f82d3SEliot Blennerhassett }
3410719f82d3SEliot Blennerhassett 
3411719f82d3SEliot Blennerhassett u16 hpi_entity_alloc_and_pack(const enum e_entity_type type,
3412719f82d3SEliot Blennerhassett 	const size_t item_count, const enum e_entity_role role, void *value,
3413719f82d3SEliot Blennerhassett 	struct hpi_entity **entity)
3414719f82d3SEliot Blennerhassett {
3415719f82d3SEliot Blennerhassett 	size_t bytes_to_copy, total_size;
3416719f82d3SEliot Blennerhassett 	u16 hE = 0;
3417719f82d3SEliot Blennerhassett 	*entity = NULL;
3418719f82d3SEliot Blennerhassett 
3419719f82d3SEliot Blennerhassett 	hE = hpi_entity_check_type(type);
3420719f82d3SEliot Blennerhassett 	if (hE)
3421719f82d3SEliot Blennerhassett 		return hE;
3422719f82d3SEliot Blennerhassett 
34231be1d76bSDan Carpenter 	HPI_DEBUG_ASSERT(role > entity_role_null && type < LAST_ENTITY_TYPE);
3424719f82d3SEliot Blennerhassett 
3425719f82d3SEliot Blennerhassett 	bytes_to_copy = entity_type_to_size[type] * item_count;
3426719f82d3SEliot Blennerhassett 	total_size = hpi_entity_header_size(*entity) + bytes_to_copy;
3427719f82d3SEliot Blennerhassett 
3428719f82d3SEliot Blennerhassett 	HPI_DEBUG_ASSERT(total_size >= hpi_entity_header_size(*entity)
3429719f82d3SEliot Blennerhassett 		&& total_size < STR_SIZE_FIELD_MAX);
3430719f82d3SEliot Blennerhassett 
3431719f82d3SEliot Blennerhassett 	*entity = kmalloc(total_size, GFP_KERNEL);
3432719f82d3SEliot Blennerhassett 	if (*entity == NULL)
3433719f82d3SEliot Blennerhassett 		return HPI_ERROR_MEMORY_ALLOC;
3434719f82d3SEliot Blennerhassett 	memcpy((*entity)->value, value, bytes_to_copy);
3435719f82d3SEliot Blennerhassett 	(*entity)->header.size =
3436719f82d3SEliot Blennerhassett 		hpi_entity_header_size(*entity) + bytes_to_copy;
3437719f82d3SEliot Blennerhassett 	(*entity)->header.type = type;
3438719f82d3SEliot Blennerhassett 	(*entity)->header.role = role;
3439719f82d3SEliot Blennerhassett 	return 0;
3440719f82d3SEliot Blennerhassett }
3441719f82d3SEliot Blennerhassett 
3442719f82d3SEliot Blennerhassett u16 hpi_entity_copy_value_from(struct hpi_entity *entity,
3443719f82d3SEliot Blennerhassett 	enum e_entity_type type, size_t item_count, void *value_dst_p)
3444719f82d3SEliot Blennerhassett {
3445719f82d3SEliot Blennerhassett 	size_t bytes_to_copy;
3446719f82d3SEliot Blennerhassett 
3447719f82d3SEliot Blennerhassett 	if (entity->header.type != type)
3448719f82d3SEliot Blennerhassett 		return HPI_ERROR_ENTITY_TYPE_MISMATCH;
3449719f82d3SEliot Blennerhassett 
3450719f82d3SEliot Blennerhassett 	if (hpi_entity_item_count(entity) != item_count)
3451719f82d3SEliot Blennerhassett 		return HPI_ERROR_ENTITY_ITEM_COUNT;
3452719f82d3SEliot Blennerhassett 
3453719f82d3SEliot Blennerhassett 	bytes_to_copy = entity_type_to_size[type] * item_count;
3454719f82d3SEliot Blennerhassett 	memcpy(value_dst_p, entity->value, bytes_to_copy);
3455719f82d3SEliot Blennerhassett 	return 0;
3456719f82d3SEliot Blennerhassett }
3457719f82d3SEliot Blennerhassett 
3458719f82d3SEliot Blennerhassett u16 hpi_entity_unpack(struct hpi_entity *entity, enum e_entity_type *type,
3459719f82d3SEliot Blennerhassett 	size_t *item_count, enum e_entity_role *role, void **value)
3460719f82d3SEliot Blennerhassett {
3461719f82d3SEliot Blennerhassett 	u16 err = 0;
3462719f82d3SEliot Blennerhassett 	HPI_DEBUG_ASSERT(entity != NULL);
3463719f82d3SEliot Blennerhassett 
3464719f82d3SEliot Blennerhassett 	if (type)
3465719f82d3SEliot Blennerhassett 		*type = entity->header.type;
3466719f82d3SEliot Blennerhassett 
3467719f82d3SEliot Blennerhassett 	if (role)
3468719f82d3SEliot Blennerhassett 		*role = entity->header.role;
3469719f82d3SEliot Blennerhassett 
3470719f82d3SEliot Blennerhassett 	if (value)
3471719f82d3SEliot Blennerhassett 		*value = entity->value;
3472719f82d3SEliot Blennerhassett 
3473719f82d3SEliot Blennerhassett 	if (item_count != NULL) {
3474719f82d3SEliot Blennerhassett 		if (entity->header.type == entity_type_sequence) {
3475719f82d3SEliot Blennerhassett 			void *guard_p = hpi_entity_ptr_to_next(entity);
3476719f82d3SEliot Blennerhassett 			struct hpi_entity *next = NULL;
3477719f82d3SEliot Blennerhassett 			void *contents = entity->value;
3478719f82d3SEliot Blennerhassett 
3479719f82d3SEliot Blennerhassett 			*item_count = 0;
3480719f82d3SEliot Blennerhassett 			while (contents < guard_p) {
3481719f82d3SEliot Blennerhassett 				(*item_count)++;
3482719f82d3SEliot Blennerhassett 				err = hpi_entity_get_next(contents, 0,
3483719f82d3SEliot Blennerhassett 					guard_p, &next);
3484719f82d3SEliot Blennerhassett 				if (next == NULL || err)
3485719f82d3SEliot Blennerhassett 					break;
3486719f82d3SEliot Blennerhassett 				contents = next;
3487719f82d3SEliot Blennerhassett 			}
3488719f82d3SEliot Blennerhassett 		} else {
3489719f82d3SEliot Blennerhassett 			*item_count = hpi_entity_item_count(entity);
3490719f82d3SEliot Blennerhassett 		}
3491719f82d3SEliot Blennerhassett 	}
3492719f82d3SEliot Blennerhassett 	return err;
3493719f82d3SEliot Blennerhassett }
3494719f82d3SEliot Blennerhassett 
3495719f82d3SEliot Blennerhassett u16 hpi_gpio_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index,
3496719f82d3SEliot Blennerhassett 	u32 *ph_gpio, u16 *pw_number_input_bits, u16 *pw_number_output_bits)
3497719f82d3SEliot Blennerhassett {
3498719f82d3SEliot Blennerhassett 	struct hpi_message hm;
3499719f82d3SEliot Blennerhassett 	struct hpi_response hr;
3500719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_GPIO, HPI_GPIO_OPEN);
3501719f82d3SEliot Blennerhassett 	hm.adapter_index = adapter_index;
3502719f82d3SEliot Blennerhassett 
3503719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
3504719f82d3SEliot Blennerhassett 
3505719f82d3SEliot Blennerhassett 	if (hr.error == 0) {
3506719f82d3SEliot Blennerhassett 		*ph_gpio =
3507719f82d3SEliot Blennerhassett 			hpi_indexes_to_handle(HPI_OBJ_GPIO, adapter_index, 0);
3508719f82d3SEliot Blennerhassett 		if (pw_number_input_bits)
3509719f82d3SEliot Blennerhassett 			*pw_number_input_bits = hr.u.l.number_input_bits;
3510719f82d3SEliot Blennerhassett 		if (pw_number_output_bits)
3511719f82d3SEliot Blennerhassett 			*pw_number_output_bits = hr.u.l.number_output_bits;
3512719f82d3SEliot Blennerhassett 	} else
3513719f82d3SEliot Blennerhassett 		*ph_gpio = 0;
3514719f82d3SEliot Blennerhassett 	return hr.error;
3515719f82d3SEliot Blennerhassett }
3516719f82d3SEliot Blennerhassett 
3517719f82d3SEliot Blennerhassett u16 hpi_gpio_read_bit(const struct hpi_hsubsys *ph_subsys, u32 h_gpio,
3518719f82d3SEliot Blennerhassett 	u16 bit_index, u16 *pw_bit_data)
3519719f82d3SEliot Blennerhassett {
3520719f82d3SEliot Blennerhassett 	struct hpi_message hm;
3521719f82d3SEliot Blennerhassett 	struct hpi_response hr;
3522719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_GPIO, HPI_GPIO_READ_BIT);
3523719f82d3SEliot Blennerhassett 	u32TOINDEX(h_gpio, &hm.adapter_index);
3524719f82d3SEliot Blennerhassett 	hm.u.l.bit_index = bit_index;
3525719f82d3SEliot Blennerhassett 
3526719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
3527719f82d3SEliot Blennerhassett 
3528719f82d3SEliot Blennerhassett 	*pw_bit_data = hr.u.l.bit_data[0];
3529719f82d3SEliot Blennerhassett 	return hr.error;
3530719f82d3SEliot Blennerhassett }
3531719f82d3SEliot Blennerhassett 
3532719f82d3SEliot Blennerhassett u16 hpi_gpio_read_all_bits(const struct hpi_hsubsys *ph_subsys, u32 h_gpio,
3533719f82d3SEliot Blennerhassett 	u16 aw_all_bit_data[4]
3534719f82d3SEliot Blennerhassett 	)
3535719f82d3SEliot Blennerhassett {
3536719f82d3SEliot Blennerhassett 	struct hpi_message hm;
3537719f82d3SEliot Blennerhassett 	struct hpi_response hr;
3538719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_GPIO, HPI_GPIO_READ_ALL);
3539719f82d3SEliot Blennerhassett 	u32TOINDEX(h_gpio, &hm.adapter_index);
3540719f82d3SEliot Blennerhassett 
3541719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
3542719f82d3SEliot Blennerhassett 
3543719f82d3SEliot Blennerhassett 	if (aw_all_bit_data) {
3544719f82d3SEliot Blennerhassett 		aw_all_bit_data[0] = hr.u.l.bit_data[0];
3545719f82d3SEliot Blennerhassett 		aw_all_bit_data[1] = hr.u.l.bit_data[1];
3546719f82d3SEliot Blennerhassett 		aw_all_bit_data[2] = hr.u.l.bit_data[2];
3547719f82d3SEliot Blennerhassett 		aw_all_bit_data[3] = hr.u.l.bit_data[3];
3548719f82d3SEliot Blennerhassett 	}
3549719f82d3SEliot Blennerhassett 	return hr.error;
3550719f82d3SEliot Blennerhassett }
3551719f82d3SEliot Blennerhassett 
3552719f82d3SEliot Blennerhassett u16 hpi_gpio_write_bit(const struct hpi_hsubsys *ph_subsys, u32 h_gpio,
3553719f82d3SEliot Blennerhassett 	u16 bit_index, u16 bit_data)
3554719f82d3SEliot Blennerhassett {
3555719f82d3SEliot Blennerhassett 	struct hpi_message hm;
3556719f82d3SEliot Blennerhassett 	struct hpi_response hr;
3557719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_GPIO, HPI_GPIO_WRITE_BIT);
3558719f82d3SEliot Blennerhassett 	u32TOINDEX(h_gpio, &hm.adapter_index);
3559719f82d3SEliot Blennerhassett 	hm.u.l.bit_index = bit_index;
3560719f82d3SEliot Blennerhassett 	hm.u.l.bit_data = bit_data;
3561719f82d3SEliot Blennerhassett 
3562719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
3563719f82d3SEliot Blennerhassett 
3564719f82d3SEliot Blennerhassett 	return hr.error;
3565719f82d3SEliot Blennerhassett }
3566719f82d3SEliot Blennerhassett 
3567719f82d3SEliot Blennerhassett u16 hpi_gpio_write_status(const struct hpi_hsubsys *ph_subsys, u32 h_gpio,
3568719f82d3SEliot Blennerhassett 	u16 aw_all_bit_data[4]
3569719f82d3SEliot Blennerhassett 	)
3570719f82d3SEliot Blennerhassett {
3571719f82d3SEliot Blennerhassett 	struct hpi_message hm;
3572719f82d3SEliot Blennerhassett 	struct hpi_response hr;
3573719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_GPIO,
3574719f82d3SEliot Blennerhassett 		HPI_GPIO_WRITE_STATUS);
3575719f82d3SEliot Blennerhassett 	u32TOINDEX(h_gpio, &hm.adapter_index);
3576719f82d3SEliot Blennerhassett 
3577719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
3578719f82d3SEliot Blennerhassett 
3579719f82d3SEliot Blennerhassett 	if (aw_all_bit_data) {
3580719f82d3SEliot Blennerhassett 		aw_all_bit_data[0] = hr.u.l.bit_data[0];
3581719f82d3SEliot Blennerhassett 		aw_all_bit_data[1] = hr.u.l.bit_data[1];
3582719f82d3SEliot Blennerhassett 		aw_all_bit_data[2] = hr.u.l.bit_data[2];
3583719f82d3SEliot Blennerhassett 		aw_all_bit_data[3] = hr.u.l.bit_data[3];
3584719f82d3SEliot Blennerhassett 	}
3585719f82d3SEliot Blennerhassett 	return hr.error;
3586719f82d3SEliot Blennerhassett }
3587719f82d3SEliot Blennerhassett 
3588719f82d3SEliot Blennerhassett u16 hpi_async_event_open(const struct hpi_hsubsys *ph_subsys,
3589719f82d3SEliot Blennerhassett 	u16 adapter_index, u32 *ph_async)
3590719f82d3SEliot Blennerhassett {
3591719f82d3SEliot Blennerhassett 	struct hpi_message hm;
3592719f82d3SEliot Blennerhassett 	struct hpi_response hr;
3593719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_ASYNCEVENT,
3594719f82d3SEliot Blennerhassett 		HPI_ASYNCEVENT_OPEN);
3595719f82d3SEliot Blennerhassett 	hm.adapter_index = adapter_index;
3596719f82d3SEliot Blennerhassett 
3597719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
3598719f82d3SEliot Blennerhassett 
3599719f82d3SEliot Blennerhassett 	if (hr.error == 0)
3600719f82d3SEliot Blennerhassett 
3601719f82d3SEliot Blennerhassett 		*ph_async =
3602719f82d3SEliot Blennerhassett 			hpi_indexes_to_handle(HPI_OBJ_ASYNCEVENT,
3603719f82d3SEliot Blennerhassett 			adapter_index, 0);
3604719f82d3SEliot Blennerhassett 	else
3605719f82d3SEliot Blennerhassett 		*ph_async = 0;
3606719f82d3SEliot Blennerhassett 	return hr.error;
3607719f82d3SEliot Blennerhassett 
3608719f82d3SEliot Blennerhassett }
3609719f82d3SEliot Blennerhassett 
3610719f82d3SEliot Blennerhassett u16 hpi_async_event_close(const struct hpi_hsubsys *ph_subsys, u32 h_async)
3611719f82d3SEliot Blennerhassett {
3612719f82d3SEliot Blennerhassett 	struct hpi_message hm;
3613719f82d3SEliot Blennerhassett 	struct hpi_response hr;
3614719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_ASYNCEVENT,
3615719f82d3SEliot Blennerhassett 		HPI_ASYNCEVENT_OPEN);
3616719f82d3SEliot Blennerhassett 	u32TOINDEX(h_async, &hm.adapter_index);
3617719f82d3SEliot Blennerhassett 
3618719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
3619719f82d3SEliot Blennerhassett 
3620719f82d3SEliot Blennerhassett 	return hr.error;
3621719f82d3SEliot Blennerhassett }
3622719f82d3SEliot Blennerhassett 
3623719f82d3SEliot Blennerhassett u16 hpi_async_event_wait(const struct hpi_hsubsys *ph_subsys, u32 h_async,
3624719f82d3SEliot Blennerhassett 	u16 maximum_events, struct hpi_async_event *p_events,
3625719f82d3SEliot Blennerhassett 	u16 *pw_number_returned)
3626719f82d3SEliot Blennerhassett {
3627719f82d3SEliot Blennerhassett 	return 0;
3628719f82d3SEliot Blennerhassett }
3629719f82d3SEliot Blennerhassett 
3630719f82d3SEliot Blennerhassett u16 hpi_async_event_get_count(const struct hpi_hsubsys *ph_subsys,
3631719f82d3SEliot Blennerhassett 	u32 h_async, u16 *pw_count)
3632719f82d3SEliot Blennerhassett {
3633719f82d3SEliot Blennerhassett 	struct hpi_message hm;
3634719f82d3SEliot Blennerhassett 	struct hpi_response hr;
3635719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_ASYNCEVENT,
3636719f82d3SEliot Blennerhassett 		HPI_ASYNCEVENT_GETCOUNT);
3637719f82d3SEliot Blennerhassett 	u32TOINDEX(h_async, &hm.adapter_index);
3638719f82d3SEliot Blennerhassett 
3639719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
3640719f82d3SEliot Blennerhassett 
3641719f82d3SEliot Blennerhassett 	if (hr.error == 0)
3642719f82d3SEliot Blennerhassett 		if (pw_count)
3643719f82d3SEliot Blennerhassett 			*pw_count = hr.u.as.u.count.count;
3644719f82d3SEliot Blennerhassett 
3645719f82d3SEliot Blennerhassett 	return hr.error;
3646719f82d3SEliot Blennerhassett }
3647719f82d3SEliot Blennerhassett 
3648719f82d3SEliot Blennerhassett u16 hpi_async_event_get(const struct hpi_hsubsys *ph_subsys, u32 h_async,
3649719f82d3SEliot Blennerhassett 	u16 maximum_events, struct hpi_async_event *p_events,
3650719f82d3SEliot Blennerhassett 	u16 *pw_number_returned)
3651719f82d3SEliot Blennerhassett {
3652719f82d3SEliot Blennerhassett 	struct hpi_message hm;
3653719f82d3SEliot Blennerhassett 	struct hpi_response hr;
3654719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_ASYNCEVENT,
3655719f82d3SEliot Blennerhassett 		HPI_ASYNCEVENT_GET);
3656719f82d3SEliot Blennerhassett 	u32TOINDEX(h_async, &hm.adapter_index);
3657719f82d3SEliot Blennerhassett 
3658719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
3659719f82d3SEliot Blennerhassett 	if (!hr.error) {
3660719f82d3SEliot Blennerhassett 		memcpy(p_events, &hr.u.as.u.event,
3661719f82d3SEliot Blennerhassett 			sizeof(struct hpi_async_event));
3662719f82d3SEliot Blennerhassett 		*pw_number_returned = 1;
3663719f82d3SEliot Blennerhassett 	}
3664719f82d3SEliot Blennerhassett 
3665719f82d3SEliot Blennerhassett 	return hr.error;
3666719f82d3SEliot Blennerhassett }
3667719f82d3SEliot Blennerhassett 
3668719f82d3SEliot Blennerhassett u16 hpi_nv_memory_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index,
3669719f82d3SEliot Blennerhassett 	u32 *ph_nv_memory, u16 *pw_size_in_bytes)
3670719f82d3SEliot Blennerhassett {
3671719f82d3SEliot Blennerhassett 	struct hpi_message hm;
3672719f82d3SEliot Blennerhassett 	struct hpi_response hr;
3673719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_NVMEMORY,
3674719f82d3SEliot Blennerhassett 		HPI_NVMEMORY_OPEN);
3675719f82d3SEliot Blennerhassett 	hm.adapter_index = adapter_index;
3676719f82d3SEliot Blennerhassett 
3677719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
3678719f82d3SEliot Blennerhassett 
3679719f82d3SEliot Blennerhassett 	if (hr.error == 0) {
3680719f82d3SEliot Blennerhassett 		*ph_nv_memory =
3681719f82d3SEliot Blennerhassett 			hpi_indexes_to_handle(HPI_OBJ_NVMEMORY, adapter_index,
3682719f82d3SEliot Blennerhassett 			0);
3683719f82d3SEliot Blennerhassett 		if (pw_size_in_bytes)
3684719f82d3SEliot Blennerhassett 			*pw_size_in_bytes = hr.u.n.size_in_bytes;
3685719f82d3SEliot Blennerhassett 	} else
3686719f82d3SEliot Blennerhassett 		*ph_nv_memory = 0;
3687719f82d3SEliot Blennerhassett 	return hr.error;
3688719f82d3SEliot Blennerhassett }
3689719f82d3SEliot Blennerhassett 
3690719f82d3SEliot Blennerhassett u16 hpi_nv_memory_read_byte(const struct hpi_hsubsys *ph_subsys,
3691719f82d3SEliot Blennerhassett 	u32 h_nv_memory, u16 index, u16 *pw_data)
3692719f82d3SEliot Blennerhassett {
3693719f82d3SEliot Blennerhassett 	struct hpi_message hm;
3694719f82d3SEliot Blennerhassett 	struct hpi_response hr;
3695719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_NVMEMORY,
3696719f82d3SEliot Blennerhassett 		HPI_NVMEMORY_READ_BYTE);
3697719f82d3SEliot Blennerhassett 	u32TOINDEX(h_nv_memory, &hm.adapter_index);
3698719f82d3SEliot Blennerhassett 	hm.u.n.address = index;
3699719f82d3SEliot Blennerhassett 
3700719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
3701719f82d3SEliot Blennerhassett 
3702719f82d3SEliot Blennerhassett 	*pw_data = hr.u.n.data;
3703719f82d3SEliot Blennerhassett 	return hr.error;
3704719f82d3SEliot Blennerhassett }
3705719f82d3SEliot Blennerhassett 
3706719f82d3SEliot Blennerhassett u16 hpi_nv_memory_write_byte(const struct hpi_hsubsys *ph_subsys,
3707719f82d3SEliot Blennerhassett 	u32 h_nv_memory, u16 index, u16 data)
3708719f82d3SEliot Blennerhassett {
3709719f82d3SEliot Blennerhassett 	struct hpi_message hm;
3710719f82d3SEliot Blennerhassett 	struct hpi_response hr;
3711719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_NVMEMORY,
3712719f82d3SEliot Blennerhassett 		HPI_NVMEMORY_WRITE_BYTE);
3713719f82d3SEliot Blennerhassett 	u32TOINDEX(h_nv_memory, &hm.adapter_index);
3714719f82d3SEliot Blennerhassett 	hm.u.n.address = index;
3715719f82d3SEliot Blennerhassett 	hm.u.n.data = data;
3716719f82d3SEliot Blennerhassett 
3717719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
3718719f82d3SEliot Blennerhassett 
3719719f82d3SEliot Blennerhassett 	return hr.error;
3720719f82d3SEliot Blennerhassett }
3721719f82d3SEliot Blennerhassett 
3722719f82d3SEliot Blennerhassett u16 hpi_profile_open_all(const struct hpi_hsubsys *ph_subsys,
3723719f82d3SEliot Blennerhassett 	u16 adapter_index, u16 profile_index, u32 *ph_profile,
3724719f82d3SEliot Blennerhassett 	u16 *pw_max_profiles)
3725719f82d3SEliot Blennerhassett {
3726719f82d3SEliot Blennerhassett 	struct hpi_message hm;
3727719f82d3SEliot Blennerhassett 	struct hpi_response hr;
3728719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE,
3729719f82d3SEliot Blennerhassett 		HPI_PROFILE_OPEN_ALL);
3730719f82d3SEliot Blennerhassett 	hm.adapter_index = adapter_index;
3731719f82d3SEliot Blennerhassett 	hm.obj_index = profile_index;
3732719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
3733719f82d3SEliot Blennerhassett 
3734719f82d3SEliot Blennerhassett 	*pw_max_profiles = hr.u.p.u.o.max_profiles;
3735719f82d3SEliot Blennerhassett 	if (hr.error == 0)
3736719f82d3SEliot Blennerhassett 		*ph_profile =
3737719f82d3SEliot Blennerhassett 			hpi_indexes_to_handle(HPI_OBJ_PROFILE, adapter_index,
3738719f82d3SEliot Blennerhassett 			profile_index);
3739719f82d3SEliot Blennerhassett 	else
3740719f82d3SEliot Blennerhassett 		*ph_profile = 0;
3741719f82d3SEliot Blennerhassett 	return hr.error;
3742719f82d3SEliot Blennerhassett }
3743719f82d3SEliot Blennerhassett 
3744719f82d3SEliot Blennerhassett u16 hpi_profile_get(const struct hpi_hsubsys *ph_subsys, u32 h_profile,
3745719f82d3SEliot Blennerhassett 	u16 bin_index, u16 *pw_seconds, u32 *pmicro_seconds, u32 *pcall_count,
3746719f82d3SEliot Blennerhassett 	u32 *pmax_micro_seconds, u32 *pmin_micro_seconds)
3747719f82d3SEliot Blennerhassett {
3748719f82d3SEliot Blennerhassett 	struct hpi_message hm;
3749719f82d3SEliot Blennerhassett 	struct hpi_response hr;
3750719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE, HPI_PROFILE_GET);
3751719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_profile, &hm.adapter_index, &hm.obj_index);
3752719f82d3SEliot Blennerhassett 	hm.u.p.bin_index = bin_index;
3753719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
3754719f82d3SEliot Blennerhassett 	if (pw_seconds)
3755719f82d3SEliot Blennerhassett 		*pw_seconds = hr.u.p.u.t.seconds;
3756719f82d3SEliot Blennerhassett 	if (pmicro_seconds)
3757719f82d3SEliot Blennerhassett 		*pmicro_seconds = hr.u.p.u.t.micro_seconds;
3758719f82d3SEliot Blennerhassett 	if (pcall_count)
3759719f82d3SEliot Blennerhassett 		*pcall_count = hr.u.p.u.t.call_count;
3760719f82d3SEliot Blennerhassett 	if (pmax_micro_seconds)
3761719f82d3SEliot Blennerhassett 		*pmax_micro_seconds = hr.u.p.u.t.max_micro_seconds;
3762719f82d3SEliot Blennerhassett 	if (pmin_micro_seconds)
3763719f82d3SEliot Blennerhassett 		*pmin_micro_seconds = hr.u.p.u.t.min_micro_seconds;
3764719f82d3SEliot Blennerhassett 	return hr.error;
3765719f82d3SEliot Blennerhassett }
3766719f82d3SEliot Blennerhassett 
3767719f82d3SEliot Blennerhassett u16 hpi_profile_get_utilization(const struct hpi_hsubsys *ph_subsys,
3768719f82d3SEliot Blennerhassett 	u32 h_profile, u32 *putilization)
3769719f82d3SEliot Blennerhassett {
3770719f82d3SEliot Blennerhassett 	struct hpi_message hm;
3771719f82d3SEliot Blennerhassett 	struct hpi_response hr;
3772719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE,
3773719f82d3SEliot Blennerhassett 		HPI_PROFILE_GET_UTILIZATION);
3774719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_profile, &hm.adapter_index, &hm.obj_index);
3775719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
3776719f82d3SEliot Blennerhassett 	if (hr.error) {
3777719f82d3SEliot Blennerhassett 		if (putilization)
3778719f82d3SEliot Blennerhassett 			*putilization = 0;
3779719f82d3SEliot Blennerhassett 	} else {
3780719f82d3SEliot Blennerhassett 		if (putilization)
3781719f82d3SEliot Blennerhassett 			*putilization = hr.u.p.u.t.call_count;
3782719f82d3SEliot Blennerhassett 	}
3783719f82d3SEliot Blennerhassett 	return hr.error;
3784719f82d3SEliot Blennerhassett }
3785719f82d3SEliot Blennerhassett 
3786719f82d3SEliot Blennerhassett u16 hpi_profile_get_name(const struct hpi_hsubsys *ph_subsys, u32 h_profile,
3787719f82d3SEliot Blennerhassett 	u16 bin_index, char *sz_name, u16 name_length)
3788719f82d3SEliot Blennerhassett {
3789719f82d3SEliot Blennerhassett 	struct hpi_message hm;
3790719f82d3SEliot Blennerhassett 	struct hpi_response hr;
3791719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE,
3792719f82d3SEliot Blennerhassett 		HPI_PROFILE_GET_NAME);
3793719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_profile, &hm.adapter_index, &hm.obj_index);
3794719f82d3SEliot Blennerhassett 	hm.u.p.bin_index = bin_index;
3795719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
3796719f82d3SEliot Blennerhassett 	if (hr.error) {
3797719f82d3SEliot Blennerhassett 		if (sz_name)
3798719f82d3SEliot Blennerhassett 			strcpy(sz_name, "??");
3799719f82d3SEliot Blennerhassett 	} else {
3800719f82d3SEliot Blennerhassett 		if (sz_name)
3801719f82d3SEliot Blennerhassett 			memcpy(sz_name, (char *)hr.u.p.u.n.sz_name,
3802719f82d3SEliot Blennerhassett 				name_length);
3803719f82d3SEliot Blennerhassett 	}
3804719f82d3SEliot Blennerhassett 	return hr.error;
3805719f82d3SEliot Blennerhassett }
3806719f82d3SEliot Blennerhassett 
3807719f82d3SEliot Blennerhassett u16 hpi_profile_start_all(const struct hpi_hsubsys *ph_subsys, u32 h_profile)
3808719f82d3SEliot Blennerhassett {
3809719f82d3SEliot Blennerhassett 	struct hpi_message hm;
3810719f82d3SEliot Blennerhassett 	struct hpi_response hr;
3811719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE,
3812719f82d3SEliot Blennerhassett 		HPI_PROFILE_START_ALL);
3813719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_profile, &hm.adapter_index, &hm.obj_index);
3814719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
3815719f82d3SEliot Blennerhassett 
3816719f82d3SEliot Blennerhassett 	return hr.error;
3817719f82d3SEliot Blennerhassett }
3818719f82d3SEliot Blennerhassett 
3819719f82d3SEliot Blennerhassett u16 hpi_profile_stop_all(const struct hpi_hsubsys *ph_subsys, u32 h_profile)
3820719f82d3SEliot Blennerhassett {
3821719f82d3SEliot Blennerhassett 	struct hpi_message hm;
3822719f82d3SEliot Blennerhassett 	struct hpi_response hr;
3823719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE,
3824719f82d3SEliot Blennerhassett 		HPI_PROFILE_STOP_ALL);
3825719f82d3SEliot Blennerhassett 	u32TOINDEXES(h_profile, &hm.adapter_index, &hm.obj_index);
3826719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
3827719f82d3SEliot Blennerhassett 
3828719f82d3SEliot Blennerhassett 	return hr.error;
3829719f82d3SEliot Blennerhassett }
3830719f82d3SEliot Blennerhassett 
3831719f82d3SEliot Blennerhassett u16 hpi_watchdog_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index,
3832719f82d3SEliot Blennerhassett 	u32 *ph_watchdog)
3833719f82d3SEliot Blennerhassett {
3834719f82d3SEliot Blennerhassett 	struct hpi_message hm;
3835719f82d3SEliot Blennerhassett 	struct hpi_response hr;
3836719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_WATCHDOG,
3837719f82d3SEliot Blennerhassett 		HPI_WATCHDOG_OPEN);
3838719f82d3SEliot Blennerhassett 	hm.adapter_index = adapter_index;
3839719f82d3SEliot Blennerhassett 
3840719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
3841719f82d3SEliot Blennerhassett 
3842719f82d3SEliot Blennerhassett 	if (hr.error == 0)
3843719f82d3SEliot Blennerhassett 		*ph_watchdog =
3844719f82d3SEliot Blennerhassett 			hpi_indexes_to_handle(HPI_OBJ_WATCHDOG, adapter_index,
3845719f82d3SEliot Blennerhassett 			0);
3846719f82d3SEliot Blennerhassett 	else
3847719f82d3SEliot Blennerhassett 		*ph_watchdog = 0;
3848719f82d3SEliot Blennerhassett 	return hr.error;
3849719f82d3SEliot Blennerhassett }
3850719f82d3SEliot Blennerhassett 
3851719f82d3SEliot Blennerhassett u16 hpi_watchdog_set_time(const struct hpi_hsubsys *ph_subsys, u32 h_watchdog,
3852719f82d3SEliot Blennerhassett 	u32 time_millisec)
3853719f82d3SEliot Blennerhassett {
3854719f82d3SEliot Blennerhassett 	struct hpi_message hm;
3855719f82d3SEliot Blennerhassett 	struct hpi_response hr;
3856719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_WATCHDOG,
3857719f82d3SEliot Blennerhassett 		HPI_WATCHDOG_SET_TIME);
3858719f82d3SEliot Blennerhassett 	u32TOINDEX(h_watchdog, &hm.adapter_index);
3859719f82d3SEliot Blennerhassett 	hm.u.w.time_ms = time_millisec;
3860719f82d3SEliot Blennerhassett 
3861719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
3862719f82d3SEliot Blennerhassett 
3863719f82d3SEliot Blennerhassett 	return hr.error;
3864719f82d3SEliot Blennerhassett }
3865719f82d3SEliot Blennerhassett 
3866719f82d3SEliot Blennerhassett u16 hpi_watchdog_ping(const struct hpi_hsubsys *ph_subsys, u32 h_watchdog)
3867719f82d3SEliot Blennerhassett {
3868719f82d3SEliot Blennerhassett 	struct hpi_message hm;
3869719f82d3SEliot Blennerhassett 	struct hpi_response hr;
3870719f82d3SEliot Blennerhassett 	hpi_init_message_response(&hm, &hr, HPI_OBJ_WATCHDOG,
3871719f82d3SEliot Blennerhassett 		HPI_WATCHDOG_PING);
3872719f82d3SEliot Blennerhassett 	u32TOINDEX(h_watchdog, &hm.adapter_index);
3873719f82d3SEliot Blennerhassett 
3874719f82d3SEliot Blennerhassett 	hpi_send_recv(&hm, &hr);
3875719f82d3SEliot Blennerhassett 
3876719f82d3SEliot Blennerhassett 	return hr.error;
3877719f82d3SEliot Blennerhassett }
3878