1 #define LOG_TAG "oslo_packages_test"
2
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <ctype.h>
6 #include <errno.h>
7 #include <sys/ioctl.h>
8 #include <string.h>
9 #include <math.h>
10
11 #include <cutils/log.h>
12
13 #include <linux/mfd/adnc/iaxxx-odsp.h>
14 #include <linux/mfd/adnc/iaxxx-system-identifiers.h>
15 #include <tinyalsa/asoundlib.h>
16
17 #define ODSP_NODE "/dev/iaxxx-odsp-celldrv"
18
19 #define BUFFER_PACKAGE "BufferPackage.bin"
20 #define BUFFER_CONFIG_OSLO_VAL "BufferConfigValOslo.bin"
21 #define SENSOR_PACKAGE "OsloSensorPackage.bin"
22
23 #define PLUGIN3_SRC_ID 0x30FF
24
open_mixer_ctl()25 static struct mixer* open_mixer_ctl()
26 {
27 return mixer_open(0);
28 }
29
close_mixer_ctl(struct mixer * mixer)30 static void close_mixer_ctl(struct mixer *mixer)
31 {
32 if (mixer) {
33 mixer_close(mixer);
34 }
35 }
36
set_mixer_ctl_val(struct mixer * mixer,char * id,int value)37 static int set_mixer_ctl_val(struct mixer *mixer, char *id, int value)
38 {
39 struct mixer_ctl *ctl = NULL;
40 int err = 0;
41
42 if ((NULL == mixer) || (NULL == id)) {
43 ALOGE("%s: ERROR Null argument passed", __func__);
44 err = -EINVAL;
45 goto exit;
46 }
47
48 ctl = mixer_get_ctl_by_name(mixer, id);
49 if (NULL == ctl) {
50 ALOGE("%s: ERROR Invalid control name: %s", __func__, id);
51 err = -1;
52 goto exit;
53 }
54
55 if (mixer_ctl_set_value(ctl, 0, value)) {
56 ALOGE("%s: ERROR Invalid value for %s", __func__, id);
57 err = -1;
58 goto exit;
59 }
60
61 exit:
62 return err;
63 }
64
set_mixer_ctl_string(struct mixer * mixer,char * id,const char * string)65 static int set_mixer_ctl_string(struct mixer *mixer, char *id, const char *string)
66 {
67 struct mixer_ctl *ctl = NULL;
68 int err = 0;
69
70 if ((NULL == mixer) || (NULL == id)) {
71 ALOGE("%s: ERROR Null argument passed", __func__);
72 err = -EINVAL;
73 goto exit;
74 }
75
76 ctl = mixer_get_ctl_by_name(mixer, id);
77 if (NULL == ctl) {
78 ALOGE("%s: ERROR Invalid control name: %s", __func__, id);
79 err = -1;
80 goto exit;
81 }
82
83 if (mixer_ctl_set_enum_by_string(ctl, string)) {
84 ALOGE("%s: ERROR Invalid string for %s", __func__, id);
85 err = -1;
86 goto exit;
87 }
88
89 exit:
90 return err;
91 }
92
usage()93 void usage()
94 {
95 fputs("\
96 USAGE -\n\
97 -------\n\
98 1) Oslo_packages_test 1\n\
99 2) Oslo_packages_test 0\n\
100 \n\
101 1 means load all packages\n\
102 0 means unload.\n\
103 ", stdout);
104
105 exit(EXIT_FAILURE);
106 }
107
main(int argc,char * argv[])108 int main(int argc, char *argv[])
109 {
110 FILE *odsp_node = NULL;
111 struct iaxxx_pkg_mgmt_info pkg_info;
112 struct iaxxx_plugin_info pi;
113 struct iaxxx_plugin_create_cfg pcc;
114 struct iaxxx_set_event se;
115 struct iaxxx_evt_info ei;
116
117 uint32_t buffer_id;
118 uint32_t sensor_pkg_id;
119 int param;
120 int err = 0;
121
122 struct mixer *mixer = NULL;
123
124 if (argc <= 1 || argc > 2) {
125 usage();
126 }
127
128 param = strtol(argv[1], NULL, 0);
129 if (param > 1 || param < 0) {
130 usage();
131 }
132
133 /* Open Host Driver File node */
134 if((odsp_node = fopen(ODSP_NODE, "rw")) == NULL) {
135 printf("file %s open for write error: %s\n", ODSP_NODE,
136 strerror(errno));
137 ALOGE("file %s open for write error: %s\n", ODSP_NODE,
138 strerror(errno));
139 err = -EIO;
140 goto exit;
141 }
142
143 mixer = open_mixer_ctl();
144 if (NULL == mixer) {
145 ALOGE("%s: ERROR: Failed to open the mixer control", __func__);
146 err = -EINVAL;
147 goto exit;
148 }
149
150 if (param == 1) {
151 /* Load all pacakge */
152
153 /* Sensor Plugin */
154 strcpy(pkg_info.pkg_name, SENSOR_PACKAGE);
155 pkg_info.pkg_id = 0;
156 pkg_info.proc_id = 0;
157 err = ioctl(fileno(odsp_node), ODSP_LOAD_PACKAGE, (unsigned long)&pkg_info);
158 if (err) {
159 printf("%s: ERROR: SENSOR ODSP_LOAD_PACKAGE failed %d(%s)\n", __func__, errno, strerror(errno));
160 ALOGE("%s: ERROR: SENSOR ODSP_LOAD_PACKAGE failed %d(%s)\n", __func__, errno, strerror(errno));
161 goto exit;
162 }
163 printf("%s: SENSOR ODSP_LOAD_PACKAGE %x\n", __func__, pkg_info.proc_id);
164 ALOGD("%s: SENSOR ODSP_LOAD_PACKAGE %x\n", __func__, pkg_info.proc_id);
165 sensor_pkg_id = pkg_info.proc_id;
166
167 /* Buffer Plugin */
168 strcpy(pkg_info.pkg_name, BUFFER_PACKAGE);
169 pkg_info.pkg_id = 4;
170 pkg_info.proc_id = 0;
171 err = ioctl(fileno(odsp_node), ODSP_LOAD_PACKAGE, (unsigned long)&pkg_info);
172 if (err) {
173 printf("%s: ERROR: Buffer ODSP_LOAD_PACKAGE failed %d(%s)\n", __func__, errno, strerror(errno));
174 ALOGE("%s: ERROR: Buffer ODSP_LOAD_PACKAGE failed %d(%s)\n", __func__, errno, strerror(errno));
175 goto exit;
176 }
177 printf("%s: Buffer ODSP_LOAD_PACKAGE %x\n", __func__, pkg_info.proc_id);
178 ALOGD("%s: Buffer ODSP_LOAD_PACKAGE %x\n", __func__, pkg_info.proc_id);
179 buffer_id = pkg_info.proc_id;
180
181 /* if buffer plugin Loaded */
182 strcpy(pcc.file_name, BUFFER_CONFIG_OSLO_VAL);
183 pcc.inst_id = 2;
184 pcc.block_id = 1;
185 pcc.cfg_size = 12;
186 pcc.cfg_val = 0;
187
188 err = ioctl(fileno(odsp_node), ODSP_PLG_SET_CREATE_CFG, (unsigned long)&pcc);
189 if (err) {
190 printf("%s: ERROR: ODSP_PLG_SET_CREATE_CFG IOCTL failed to set create config %d(%s)\n", __func__, errno, strerror(errno));
191 ALOGE("%s: ERROR: ODSP_PLG_SET_CREATE_CFG IOCTL failed to set create config %d(%s)\n", __func__, errno, strerror(errno));
192 goto exit;
193 }
194
195 /* Create Buffer plugin */
196 pi.plg_idx = 0;
197 pi.pkg_id = buffer_id;
198 pi.block_id = 1;
199 pi.inst_id = 2;
200 pi.priority = 1;
201 err = ioctl(fileno(odsp_node), ODSP_PLG_CREATE, (unsigned long)&pi);
202 if (err) {
203 printf("%s: ERROR: ODSP_PLG_CREATE IOCTL failed to create Buffer Plugin with error %d(%s)\n", __func__, errno, strerror(errno));
204 ALOGE("%s: ERROR: ODSP_PLG_CREATE IOCTL failed to create Buffer Plugin with error %d(%s)\n", __func__, errno, strerror(errno));
205 goto exit;
206 }
207
208 /* Create placeholder sensor plugin */
209 pi.plg_idx = 0;
210 pi.pkg_id = sensor_pkg_id;
211 pi.block_id = 1;
212 pi.inst_id = 3;
213 pi.priority = 1;
214 err = ioctl(fileno(odsp_node), ODSP_PLG_CREATE, (unsigned long)&pi);
215 if (err) {
216 printf("%s: ERROR: ODSP_PLG_CREATE IOCTL failed to create sensor Plugin with error %d(%s)\n", __func__, errno, strerror(errno));
217 ALOGE("%s: ERROR: ODSP_PLG_CREATE IOCTL failed to create sensor Plugin with error %d(%s)\n", __func__, errno, strerror(errno));
218 goto exit;
219 }
220
221 /* Set the events and params */
222 se.inst_id = 3;
223 se.event_enable_mask = 0x7;
224 se.block_id = 1;
225 err = ioctl(fileno(odsp_node), ODSP_PLG_SET_EVENT, (unsigned long)&se);
226 if (err) {
227 printf("%s: ERROR: ODSP_PLG_SET_EVENT IOCTL failed with error %d(%s)\n", __func__, errno, strerror(errno));
228 ALOGE("%s: ERROR: ODSP_PLG_SET_EVENT IOCTL failed with error %d(%s)\n", __func__, errno, strerror(errno));
229 goto exit;
230 }
231
232 printf("Registering for 3 sensor mode switch events\n");
233 ALOGD("Registering for 3 sensor mode switch events\n");
234
235 /* Subscribe for events */
236 ei.src_id = PLUGIN3_SRC_ID;
237 ei.event_id = 0; // 0 - Mode switch to presence mode
238 ei.dst_id = IAXXX_SYSID_SCRIPT_MGR;
239 ei.dst_opaque = 0x1201;
240 err = ioctl(fileno(odsp_node), ODSP_EVENT_SUBSCRIBE, (unsigned long)&ei);
241 if (err) {
242 printf("%s: ERROR: ODSP_EVENT_SUBSCRIBE (for event_id %d, src_id %d) IOCTL failed with error %d(%s)\n",
243 __func__, ei.event_id, ei.src_id, errno, strerror(errno));
244 ALOGE("%s: ERROR: ODSP_EVENT_SUBSCRIBE (for event_id %d, src_id %d) IOCTL failed with error %d(%s)\n",
245 __func__, ei.event_id, ei.src_id, errno, strerror(errno));
246 goto exit;
247 }
248
249 /* Subscribe for events */
250 ei.src_id = PLUGIN3_SRC_ID;
251 ei.event_id = 1; // 1 - Mode switch to detected mode.
252 ei.dst_id = IAXXX_SYSID_SCRIPT_MGR;
253 ei.dst_opaque = 0x1202;
254 err = ioctl(fileno(odsp_node), ODSP_EVENT_SUBSCRIBE, (unsigned long)&ei);
255 if (err) {
256 printf("%s: ERROR: ODSP_EVENT_SUBSCRIBE (for event_id %d, src_id %d) IOCTL failed with error %d(%s)\n",
257 __func__, ei.event_id, ei.src_id, errno, strerror(errno));
258 ALOGE("%s: ERROR: ODSP_EVENT_SUBSCRIBE (for event_id %d, src_id %d) IOCTL failed with error %d(%s)\n",
259 __func__, ei.event_id, ei.src_id, errno, strerror(errno));
260 goto exit;
261 }
262
263 /* Subscribe for events */
264 ei.src_id = PLUGIN3_SRC_ID;
265 ei.event_id = 2; // 2 - Mode switch to max mode
266 ei.dst_id = IAXXX_SYSID_HOST; // update this to HOST_1 for Customer
267 ei.dst_opaque = 0;
268 err = ioctl(fileno(odsp_node), ODSP_EVENT_SUBSCRIBE, (unsigned long)&ei);
269 if (err) {
270 printf("%s: ERROR: ODSP_EVENT_SUBSCRIBE (for event_id %d, src_id %d) IOCTL failed with error %d(%s)\n",
271 __func__, ei.event_id, ei.src_id, errno, strerror(errno));
272 ALOGE("%s: ERROR: ODSP_EVENT_SUBSCRIBE (for event_id %d, src_id %d) IOCTL failed with error %d(%s)\n",
273 __func__, ei.event_id, ei.src_id, errno, strerror(errno));
274 goto exit;
275 }
276
277 /* setup routing */
278 set_mixer_ctl_val(mixer, "sensor0 En", 1);
279
280 set_mixer_ctl_string(mixer, "Plgin2Ip Ep0 Conf", "SensorOut0");
281 set_mixer_ctl_string(mixer, "Plgin3Ip Ep0 Conf", "plugin2Out0");
282
283 set_mixer_ctl_val(mixer, "Plgin2Blk1En", 1);
284 set_mixer_ctl_val(mixer, "Plgin3Blk1En", 1);
285 } else {
286 /* disconnect the route */
287 set_mixer_ctl_val(mixer, "Plgin3Blk1En", 0);
288 set_mixer_ctl_val(mixer, "Plgin2Blk1En", 0);
289 set_mixer_ctl_val(mixer, "sensor0 En", 0);
290
291 /* Unload all pacakge */
292 printf("UnSubscribe 3 sensor mode switch events\n");
293 ALOGD("UnSubscribe 3 sensor mode switch events\n");
294
295 /* UnSubscribe for events */
296 ei.src_id = PLUGIN3_SRC_ID;
297 ei.event_id = 2; // 2 - Mode switch to max mode
298 ei.dst_id = IAXXX_SYSID_HOST; // update this to HOST_1 for Customer
299 ei.dst_opaque = 0;
300 err = ioctl(fileno(odsp_node), ODSP_EVENT_UNSUBSCRIBE, (unsigned long)&ei);
301 if (err) {
302 printf("%s: ERROR: ODSP_EVENT_UNSUBSCRIBE (for event_id %d, src_id %d) IOCTL failed with error %d(%s)\n",
303 __func__, ei.event_id, ei.src_id, errno, strerror(errno));
304 ALOGE("%s: ERROR: ODSP_EVENT_UNSUBSCRIBE (for event_id %d, src_id %d) IOCTL failed with error %d(%s)\n",
305 __func__, ei.event_id, ei.src_id, errno, strerror(errno));
306 goto exit;
307 }
308
309 /* UnSubscribe for events */
310 ei.src_id = PLUGIN3_SRC_ID;
311 ei.event_id = 1; // 1 - Mode switch to detected mode.
312 ei.dst_id = IAXXX_SYSID_SCRIPT_MGR;
313 ei.dst_opaque = 0x1202;
314 err = ioctl(fileno(odsp_node), ODSP_EVENT_UNSUBSCRIBE, (unsigned long)&ei);
315 if (err) {
316 printf("%s: ERROR: ODSP_EVENT_UNSUBSCRIBE (for event_id %d, src_id %d) IOCTL failed with error %d(%s)\n",
317 __func__, ei.event_id, ei.src_id, errno, strerror(errno));
318 ALOGE("%s: ERROR: ODSP_EVENT_UNSUBSCRIBE (for event_id %d, src_id %d) IOCTL failed with error %d(%s)\n",
319 __func__, ei.event_id, ei.src_id, errno, strerror(errno));
320 goto exit;
321 }
322
323 /* UnSubscribe for events */
324 ei.src_id = PLUGIN3_SRC_ID;
325 ei.event_id = 0; // 0 - Mode switch to presence mode
326 ei.dst_id = IAXXX_SYSID_SCRIPT_MGR;
327 ei.dst_opaque = 0x1201;
328 err = ioctl(fileno(odsp_node), ODSP_EVENT_UNSUBSCRIBE, (unsigned long)&ei);
329 if (-1 == err) {
330 printf("%s: ERROR: ODSP_EVENT_UNSUBSCRIBE (for event_id %d, src_id %d) IOCTL failed with error %d(%s)\n",
331 __func__, ei.event_id, ei.src_id, errno, strerror(errno));
332 ALOGE("%s: ERROR: ODSP_EVENT_UNSUBSCRIBE (for event_id %d, src_id %d) IOCTL failed with error %d(%s)\n",
333 __func__, ei.event_id, ei.src_id, errno, strerror(errno));
334 goto exit;
335 }
336
337 /* Set the events and params */
338 se.inst_id = 3;
339 se.event_enable_mask = 0x0;
340 se.block_id = 1;
341 err = ioctl(fileno(odsp_node), ODSP_PLG_SET_EVENT, (unsigned long)&se);
342 if (err) {
343 printf("%s: ERROR: ODSP_PLG_SET_EVENT IOCTL failed with error %d(%s)\n", __func__, errno, strerror(errno));
344 ALOGE("%s: ERROR: ODSP_PLG_SET_EVENT IOCTL failed with error %d(%s)\n", __func__, errno, strerror(errno));
345 goto exit;
346 }
347
348 /* destroy placeholder sensor plugin */
349 pi.block_id = 1;
350 pi.inst_id = 3;
351 err = ioctl(fileno(odsp_node), ODSP_PLG_DESTROY, (unsigned long)&pi);
352 if (err) {
353 printf("%s: ERROR: ODSP_PLG_DESTROY IOCTL failed to create sensor Plugin with error %d(%s)\n", __func__, errno, strerror(errno));
354 ALOGE("%s: ERROR: ODSP_PLG_DESTROY IOCTL failed to create sensor Plugin with error %d(%s)\n", __func__, errno, strerror(errno));
355 goto exit;
356 }
357
358 /* destroy Buffer plugin */
359 pi.block_id = 1;
360 pi.inst_id = 2;
361 err = ioctl(fileno(odsp_node), ODSP_PLG_DESTROY, (unsigned long)&pi);
362 if (err) {
363 printf("%s: ERROR: ODSP_PLG_DESTROY IOCTL failed to create Buffer Plugin with error %d(%s)\n", __func__, errno, strerror(errno));
364 ALOGE("%s: ERROR: ODSP_PLG_DESTROY IOCTL failed to create Buffer Plugin with error %d(%s)\n", __func__, errno, strerror(errno));
365 goto exit;
366 }
367
368 /*Unload Buffer Plugin */
369
370 pkg_info.pkg_id = 4;
371 pkg_info.proc_id = 4;
372 err = ioctl(fileno(odsp_node), ODSP_UNLOAD_PACKAGE, (unsigned long)&pkg_info);
373 if (err) {
374 printf("%s: ERROR: SENSOR ODSP_UNLOAD_PACKAGE failed %d(%s)\n", __func__, errno, strerror(errno));
375 ALOGE("%s: ERROR: SENSOR ODSP_UNLOAD_PACKAGE failed %d(%s)\n", __func__, errno, strerror(errno));
376 goto exit;
377 }
378
379 printf("%s: SENSOR ODSP_UNLOAD_PACKAGE %x\n", __func__, pkg_info.proc_id);
380 ALOGD("%s: SENSOR ODSP_UNLOAD_PACKAGE %x\n", __func__, pkg_info.proc_id);
381
382 /*Unload Sensor Plugin */
383 pkg_info.pkg_id = 0;
384 pkg_info.proc_id = 4;
385 err = ioctl(fileno(odsp_node), ODSP_UNLOAD_PACKAGE, (unsigned long)&pkg_info);
386 if (err) {
387 printf("%s: ERROR: Buffer ODSP_UNLOAD_PACKAGE failed %d(%s)\n", __func__, errno, strerror(errno));
388 ALOGE("%s: ERROR: Buffer ODSP_UNLOAD_PACKAGE failed %d(%s)\n", __func__, errno, strerror(errno));
389 goto exit;
390 }
391
392 printf("%s: Buffer ODSP_UNLOAD_PACKAGE %x\n", __func__, pkg_info.proc_id);
393 ALOGD("%s: Buffer ODSP_UNLOAD_PACKAGE %x\n", __func__, pkg_info.proc_id);
394 }
395 exit:
396 if (odsp_node)
397 fclose(odsp_node);
398 if (mixer)
399 close_mixer_ctl(mixer);
400 return err;
401 }
402