blob: 192aaf950257cf80a13ae1f4193ee885e187eb33 [file] [log] [blame]
Lior Barenboim69539fb2013-12-25 18:38:31 +02001/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +02002 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 */
13
14#include <linux/fs.h>
15#include <linux/module.h>
16#include <linux/miscdevice.h>
17#include <linux/sched.h>
18#include <linux/slab.h>
19#include <linux/wait.h>
20#include <linux/input.h>
21#include <linux/uaccess.h>
22#include <linux/time.h>
23#include <asm/mach-types.h>
24#include <sound/apr_audio.h>
25#include <mach/qdsp6v2/usf.h>
26#include "q6usm.h"
Baruch Eruchimovitch1221b852012-04-02 11:21:30 +030027#include "usfcdev.h"
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +020028
29/* The driver version*/
Lior Barenboim69539fb2013-12-25 18:38:31 +020030#define DRV_VERSION "1.6.1"
31#define USF_VERSION_ID 0x0161
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +020032
33/* Standard timeout in the asynchronous ops */
Baruch Eruchimovitchd0c077f2012-05-03 18:38:34 +030034#define USF_TIMEOUT_JIFFIES (1*HZ) /* 1 sec */
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +020035
36/* Undefined USF device */
37#define USF_UNDEF_DEV_ID 0xffff
38
39/* RX memory mapping flag */
Baruch Eruchimovitchdac24742012-02-01 15:29:29 +020040#define USF_VM_WRITE 2
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +020041
Baruch Eruchimovitch24dda6a2012-01-02 20:28:19 +020042/* Number of events, copied from the user space to kernel one */
43#define USF_EVENTS_PORTION_SIZE 20
44
Baruch Eruchimovitchdac24742012-02-01 15:29:29 +020045/* Indexes in range definitions */
46#define MIN_IND 0
47#define MAX_IND 1
48
49/* The coordinates indexes */
50#define X_IND 0
51#define Y_IND 1
52#define Z_IND 2
53
Baruch Eruchimovitchb4c32722013-10-14 15:49:41 +030054/* Shared memory limits */
55/* max_buf_size = (port_size(65535*2) * port_num(8) * group_size(3) */
56#define USF_MAX_BUF_SIZE 3145680
57#define USF_MAX_BUF_NUM 32
58
Baruch Eruchimovitchdac24742012-02-01 15:29:29 +020059/* Place for opreation result, received from QDSP6 */
60#define APR_RESULT_IND 1
61
62/* Place for US detection result, received from QDSP6 */
63#define APR_US_DETECT_RESULT_IND 0
64
Ravit Dennis029c41b2013-10-29 17:44:09 +020065#define BITS_IN_BYTE 8
66
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +020067/* The driver states */
68enum usf_state_type {
69 USF_IDLE_STATE,
70 USF_OPENED_STATE,
71 USF_CONFIGURED_STATE,
72 USF_WORK_STATE,
Lior Barenboimbfbed9c2014-03-20 14:56:01 +020073 USF_ADSP_RESTART_STATE,
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +020074 USF_ERROR_STATE
75};
76
Baruch Eruchimovitch24dda6a2012-01-02 20:28:19 +020077/* The US detection status upon FW/HW based US detection results */
78enum usf_us_detect_type {
79 USF_US_DETECT_UNDEF,
80 USF_US_DETECT_YES,
81 USF_US_DETECT_NO
82};
83
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +020084struct usf_xx_type {
85 /* Name of the client - event calculator */
86 char client_name[USF_MAX_CLIENT_NAME_SIZE];
87 /* The driver state in TX or RX direction */
88 enum usf_state_type usf_state;
89 /* wait for q6 events mechanism */
90 wait_queue_head_t wait;
91 /* IF with q6usm info */
92 struct us_client *usc;
93 /* Q6:USM' Encoder/decoder configuration */
94 struct us_encdec_cfg encdec_cfg;
95 /* Shared buffer (with Q6:USM) size */
96 uint32_t buffer_size;
97 /* Number of the shared buffers (with Q6:USM) */
98 uint32_t buffer_count;
99 /* Shared memory (Cyclic buffer with 1 gap) control */
100 uint32_t new_region;
101 uint32_t prev_region;
102 /* Q6:USM's events handler */
103 void (*cb)(uint32_t, uint32_t, uint32_t *, void *);
Baruch Eruchimovitch24dda6a2012-01-02 20:28:19 +0200104 /* US detection result */
105 enum usf_us_detect_type us_detect_type;
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +0200106 /* User's update info isn't acceptable */
107 u8 user_upd_info_na;
108};
109
110struct usf_type {
111 /* TX device component configuration & control */
112 struct usf_xx_type usf_tx;
113 /* RX device component configuration & control */
114 struct usf_xx_type usf_rx;
115 /* Index into the opened device container */
116 /* To prevent mutual usage of the same device */
117 uint16_t dev_ind;
118 /* Event types, supported by device */
119 uint16_t event_types;
Baruch Eruchimovitchcf5a4d12012-05-31 21:48:18 +0300120 /* The input devices are "input" module registered clients */
121 struct input_dev *input_ifs[USF_MAX_EVENT_IND];
Baruch Eruchimovitch1221b852012-04-02 11:21:30 +0300122 /* Bitmap of types of events, conflicting to USF's ones */
123 uint16_t conflicting_event_types;
124 /* Bitmap of types of events from devs, conflicting with USF */
125 uint16_t conflicting_event_filters;
Lior Barenboim69539fb2013-12-25 18:38:31 +0200126 /* The requested buttons bitmap */
127 uint16_t req_buttons_bitmap;
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +0200128};
129
Baruch Eruchimovitchcf5a4d12012-05-31 21:48:18 +0300130struct usf_input_dev_type {
131 /* Input event type, supported by the input device */
132 uint16_t event_type;
133 /* Input device name */
134 const char *input_dev_name;
135 /* Input device registration function */
136 int (*prepare_dev)(uint16_t, struct usf_type *,
137 struct us_input_info_type *,
138 const char *);
139 /* Input event notification function */
140 void (*notify_event)(struct usf_type *,
141 uint16_t,
142 struct usf_event_type *
143 );
144};
145
146
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +0200147/* The MAX number of the supported devices */
148#define MAX_DEVS_NUMBER 1
149
Lior Barenboim69539fb2013-12-25 18:38:31 +0200150/*
151 * code for a special button that is used to show/hide a
152 * hovering cursor in the input framework. Must be in
153 * sync with the button code definition in the framework
154 * (EventHub.h)
155 */
156#define BTN_USF_HOVERING_CURSOR 0x230
Baruch Eruchimovitchdac24742012-02-01 15:29:29 +0200157
Ravit Dennis029c41b2013-10-29 17:44:09 +0200158/* Supported buttons container */
159static const int s_button_map[] = {
160 BTN_STYLUS,
Lior Barenboim69539fb2013-12-25 18:38:31 +0200161 BTN_STYLUS2,
162 BTN_TOOL_PEN,
163 BTN_TOOL_RUBBER,
164 BTN_TOOL_FINGER,
165 BTN_USF_HOVERING_CURSOR
Ravit Dennis029c41b2013-10-29 17:44:09 +0200166};
167
Baruch Eruchimovitchdac24742012-02-01 15:29:29 +0200168/* The opened devices container */
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +0200169static int s_opened_devs[MAX_DEVS_NUMBER];
170
Baruch Eruchimovitchcf5a4d12012-05-31 21:48:18 +0300171#define USF_NAME_PREFIX "usf_"
Baruch Eruchimovitch1221b852012-04-02 11:21:30 +0300172#define USF_NAME_PREFIX_SIZE 4
173
Baruch Eruchimovitchcf5a4d12012-05-31 21:48:18 +0300174
175static struct input_dev *allocate_dev(uint16_t ind, const char *name)
176{
177 struct input_dev *in_dev = input_allocate_device();
178
179 if (in_dev == NULL) {
180 pr_err("%s: input_allocate_device() failed\n", __func__);
181 } else {
182 /* Common part configuration */
183 in_dev->name = name;
184 in_dev->phys = NULL;
185 in_dev->id.bustype = BUS_HOST;
186 in_dev->id.vendor = 0x0001;
187 in_dev->id.product = 0x0001;
188 in_dev->id.version = USF_VERSION_ID;
189 }
190 return in_dev;
191}
192
193static int prepare_tsc_input_device(uint16_t ind,
194 struct usf_type *usf_info,
195 struct us_input_info_type *input_info,
196 const char *name)
197{
Ravit Dennis029c41b2013-10-29 17:44:09 +0200198 int i = 0;
Lior Barenboim69539fb2013-12-25 18:38:31 +0200199
200 int num_buttons = min(ARRAY_SIZE(s_button_map),
201 sizeof(input_info->req_buttons_bitmap) *
Ravit Dennis029c41b2013-10-29 17:44:09 +0200202 BITS_IN_BYTE);
Lior Barenboim69539fb2013-12-25 18:38:31 +0200203 uint16_t max_buttons_bitmap = ((1 << ARRAY_SIZE(s_button_map)) - 1);
204
Baruch Eruchimovitchcf5a4d12012-05-31 21:48:18 +0300205 struct input_dev *in_dev = allocate_dev(ind, name);
Baruch Eruchimovitchcf5a4d12012-05-31 21:48:18 +0300206 if (in_dev == NULL)
207 return -ENOMEM;
208
Lior Barenboim69539fb2013-12-25 18:38:31 +0200209 if (input_info->req_buttons_bitmap > max_buttons_bitmap) {
210 pr_err("%s: Requested buttons[%d] exceeds max buttons available[%d]\n",
Ravit Dennis029c41b2013-10-29 17:44:09 +0200211 __func__,
Lior Barenboim69539fb2013-12-25 18:38:31 +0200212 input_info->req_buttons_bitmap,
213 max_buttons_bitmap);
Ravit Dennis029c41b2013-10-29 17:44:09 +0200214 return -EINVAL;
215 }
216
Baruch Eruchimovitchcf5a4d12012-05-31 21:48:18 +0300217 usf_info->input_ifs[ind] = in_dev;
Lior Barenboim69539fb2013-12-25 18:38:31 +0200218 usf_info->req_buttons_bitmap =
219 input_info->req_buttons_bitmap;
Baruch Eruchimovitchcf5a4d12012-05-31 21:48:18 +0300220 in_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
221 in_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
Ravit Dennis029c41b2013-10-29 17:44:09 +0200222
Lior Barenboim69539fb2013-12-25 18:38:31 +0200223 for (i = 0; i < num_buttons; i++)
224 if (input_info->req_buttons_bitmap & (1 << i))
Ravit Dennis029c41b2013-10-29 17:44:09 +0200225 in_dev->keybit[BIT_WORD(s_button_map[i])] |=
226 BIT_MASK(s_button_map[i]);
227
Baruch Eruchimovitchcf5a4d12012-05-31 21:48:18 +0300228 input_set_abs_params(in_dev, ABS_X,
229 input_info->tsc_x_dim[MIN_IND],
230 input_info->tsc_x_dim[MAX_IND],
231 0, 0);
232 input_set_abs_params(in_dev, ABS_Y,
233 input_info->tsc_y_dim[MIN_IND],
234 input_info->tsc_y_dim[MAX_IND],
235 0, 0);
236 input_set_abs_params(in_dev, ABS_DISTANCE,
237 input_info->tsc_z_dim[MIN_IND],
238 input_info->tsc_z_dim[MAX_IND],
239 0, 0);
240
241 input_set_abs_params(in_dev, ABS_PRESSURE,
242 input_info->tsc_pressure[MIN_IND],
243 input_info->tsc_pressure[MAX_IND],
244 0, 0);
245
246 input_set_abs_params(in_dev, ABS_TILT_X,
247 input_info->tsc_x_tilt[MIN_IND],
248 input_info->tsc_x_tilt[MAX_IND],
249 0, 0);
250 input_set_abs_params(in_dev, ABS_TILT_Y,
251 input_info->tsc_y_tilt[MIN_IND],
252 input_info->tsc_y_tilt[MAX_IND],
253 0, 0);
254
255 return 0;
256}
257
258static int prepare_mouse_input_device(uint16_t ind, struct usf_type *usf_info,
259 struct us_input_info_type *input_info,
260 const char *name)
261{
262 struct input_dev *in_dev = allocate_dev(ind, name);
263
264 if (in_dev == NULL)
265 return -ENOMEM;
266
267 usf_info->input_ifs[ind] = in_dev;
268 in_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
269
270 in_dev->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_LEFT) |
271 BIT_MASK(BTN_RIGHT) |
272 BIT_MASK(BTN_MIDDLE);
273 in_dev->relbit[0] = BIT_MASK(REL_X) |
274 BIT_MASK(REL_Y) |
275 BIT_MASK(REL_Z);
276
277 return 0;
278}
279
280static int prepare_keyboard_input_device(
281 uint16_t ind,
282 struct usf_type *usf_info,
283 struct us_input_info_type *input_info,
284 const char *name)
285{
286 struct input_dev *in_dev = allocate_dev(ind, name);
287
288 if (in_dev == NULL)
289 return -ENOMEM;
290
291 usf_info->input_ifs[ind] = in_dev;
292 in_dev->evbit[0] |= BIT_MASK(EV_KEY);
293 /* All keys are permitted */
294 memset(in_dev->keybit, 0xff, sizeof(in_dev->keybit));
295
296 return 0;
297}
298
299static void notify_tsc_event(struct usf_type *usf_info,
300 uint16_t if_ind,
301 struct usf_event_type *event)
302
303{
Ravit Dennis029c41b2013-10-29 17:44:09 +0200304 int i = 0;
Lior Barenboim69539fb2013-12-25 18:38:31 +0200305 int num_buttons = min(ARRAY_SIZE(s_button_map),
306 sizeof(usf_info->req_buttons_bitmap) *
Ravit Dennis029c41b2013-10-29 17:44:09 +0200307 BITS_IN_BYTE);
308
Baruch Eruchimovitchcf5a4d12012-05-31 21:48:18 +0300309 struct input_dev *input_if = usf_info->input_ifs[if_ind];
310 struct point_event_type *pe = &(event->event_data.point_event);
311
312 input_report_abs(input_if, ABS_X, pe->coordinates[X_IND]);
313 input_report_abs(input_if, ABS_Y, pe->coordinates[Y_IND]);
314 input_report_abs(input_if, ABS_DISTANCE, pe->coordinates[Z_IND]);
315
316 input_report_abs(input_if, ABS_TILT_X, pe->inclinations[X_IND]);
317 input_report_abs(input_if, ABS_TILT_Y, pe->inclinations[Y_IND]);
318
319 input_report_abs(input_if, ABS_PRESSURE, pe->pressure);
320 input_report_key(input_if, BTN_TOUCH, !!(pe->pressure));
321
Lior Barenboim69539fb2013-12-25 18:38:31 +0200322 for (i = 0; i < num_buttons; i++) {
Ravit Dennis029c41b2013-10-29 17:44:09 +0200323 uint16_t mask = (1 << i),
Lior Barenboim69539fb2013-12-25 18:38:31 +0200324 btn_state = !!(pe->buttons_state_bitmap & mask);
325 if (usf_info->req_buttons_bitmap & mask)
Ravit Dennis029c41b2013-10-29 17:44:09 +0200326 input_report_key(input_if, s_button_map[i], btn_state);
327 }
328
Baruch Eruchimovitchcf5a4d12012-05-31 21:48:18 +0300329 input_sync(input_if);
330
Lior Barenboim69539fb2013-12-25 18:38:31 +0200331 pr_debug("%s: TSC event: xyz[%d;%d;%d], incl[%d;%d], pressure[%d], buttons[%d]\n",
Baruch Eruchimovitchcf5a4d12012-05-31 21:48:18 +0300332 __func__,
333 pe->coordinates[X_IND],
334 pe->coordinates[Y_IND],
335 pe->coordinates[Z_IND],
336 pe->inclinations[X_IND],
337 pe->inclinations[Y_IND],
Ravit Dennis029c41b2013-10-29 17:44:09 +0200338 pe->pressure,
Lior Barenboim69539fb2013-12-25 18:38:31 +0200339 pe->buttons_state_bitmap);
Baruch Eruchimovitchcf5a4d12012-05-31 21:48:18 +0300340}
341
342static void notify_mouse_event(struct usf_type *usf_info,
343 uint16_t if_ind,
344 struct usf_event_type *event)
345{
346 struct input_dev *input_if = usf_info->input_ifs[if_ind];
347 struct mouse_event_type *me = &(event->event_data.mouse_event);
348
349 input_report_rel(input_if, REL_X, me->rels[X_IND]);
350 input_report_rel(input_if, REL_Y, me->rels[Y_IND]);
351 input_report_rel(input_if, REL_Z, me->rels[Z_IND]);
352
353 input_report_key(input_if, BTN_LEFT,
354 me->buttons_states & USF_BUTTON_LEFT_MASK);
355 input_report_key(input_if, BTN_MIDDLE,
356 me->buttons_states & USF_BUTTON_MIDDLE_MASK);
357 input_report_key(input_if, BTN_RIGHT,
358 me->buttons_states & USF_BUTTON_RIGHT_MASK);
359
360 input_sync(input_if);
361
362 pr_debug("%s: mouse event: dx[%d], dy[%d], buttons_states[%d]\n",
363 __func__, me->rels[X_IND],
364 me->rels[Y_IND], me->buttons_states);
365}
366
367static void notify_key_event(struct usf_type *usf_info,
368 uint16_t if_ind,
369 struct usf_event_type *event)
370{
371 struct input_dev *input_if = usf_info->input_ifs[if_ind];
372 struct key_event_type *ke = &(event->event_data.key_event);
373
374 input_report_key(input_if, ke->key, ke->key_state);
375 input_sync(input_if);
376 pr_debug("%s: key event: key[%d], state[%d]\n",
377 __func__,
378 ke->key,
379 ke->key_state);
380
381}
382
383static struct usf_input_dev_type s_usf_input_devs[] = {
384 {USF_TSC_EVENT, "usf_tsc",
385 prepare_tsc_input_device, notify_tsc_event},
386 {USF_TSC_PTR_EVENT, "usf_tsc_ptr",
387 prepare_tsc_input_device, notify_tsc_event},
388 {USF_MOUSE_EVENT, "usf_mouse",
389 prepare_mouse_input_device, notify_mouse_event},
390 {USF_KEYBOARD_EVENT, "usf_kb",
391 prepare_keyboard_input_device, notify_key_event},
Ravit Dennis0c7e6032013-10-01 17:26:48 +0300392 {USF_TSC_EXT_EVENT, "usf_tsc_ext",
393 prepare_tsc_input_device, notify_tsc_event},
Baruch Eruchimovitchcf5a4d12012-05-31 21:48:18 +0300394};
395
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +0200396static void usf_rx_cb(uint32_t opcode, uint32_t token,
397 uint32_t *payload, void *priv)
398{
399 struct usf_xx_type *usf_xx = (struct usf_xx_type *) priv;
400
401 if (usf_xx == NULL) {
402 pr_err("%s: the private data is NULL\n", __func__);
403 return;
404 }
405
406 switch (opcode) {
Baruch Eruchimovitch258b3472012-10-14 21:46:35 +0200407 case Q6USM_EVENT_WRITE_DONE:
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +0200408 wake_up(&usf_xx->wait);
409 break;
Lior Barenboimbfbed9c2014-03-20 14:56:01 +0200410
411 case RESET_EVENTS:
412 pr_err("%s: received RESET_EVENTS\n", __func__);
413 usf_xx->usf_state = USF_ADSP_RESTART_STATE;
414 wake_up(&usf_xx->wait);
415 break;
416
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +0200417 default:
418 break;
419 }
420}
421
422static void usf_tx_cb(uint32_t opcode, uint32_t token,
423 uint32_t *payload, void *priv)
424{
425 struct usf_xx_type *usf_xx = (struct usf_xx_type *) priv;
426
427 if (usf_xx == NULL) {
428 pr_err("%s: the private data is NULL\n", __func__);
429 return;
430 }
431
432 switch (opcode) {
Baruch Eruchimovitch258b3472012-10-14 21:46:35 +0200433 case Q6USM_EVENT_READ_DONE:
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +0200434 if (token == USM_WRONG_TOKEN)
435 usf_xx->usf_state = USF_ERROR_STATE;
436 usf_xx->new_region = token;
437 wake_up(&usf_xx->wait);
438 break;
439
Baruch Eruchimovitch258b3472012-10-14 21:46:35 +0200440 case Q6USM_EVENT_SIGNAL_DETECT_RESULT:
Baruch Eruchimovitchdac24742012-02-01 15:29:29 +0200441 usf_xx->us_detect_type = (payload[APR_US_DETECT_RESULT_IND]) ?
Baruch Eruchimovitch24dda6a2012-01-02 20:28:19 +0200442 USF_US_DETECT_YES :
443 USF_US_DETECT_NO;
444
445 wake_up(&usf_xx->wait);
446 break;
447
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +0200448 case APR_BASIC_RSP_RESULT:
Baruch Eruchimovitchdac24742012-02-01 15:29:29 +0200449 if (payload[APR_RESULT_IND]) {
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +0200450 usf_xx->usf_state = USF_ERROR_STATE;
451 usf_xx->new_region = USM_WRONG_TOKEN;
452 wake_up(&usf_xx->wait);
453 }
454 break;
455
Lior Barenboimbfbed9c2014-03-20 14:56:01 +0200456 case RESET_EVENTS:
457 pr_err("%s: received RESET_EVENTS\n", __func__);
458 usf_xx->usf_state = USF_ADSP_RESTART_STATE;
459 wake_up(&usf_xx->wait);
460 break;
461
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +0200462 default:
463 break;
464 }
465}
466
467static void release_xx(struct usf_xx_type *usf_xx)
468{
469 if (usf_xx != NULL) {
470 if (usf_xx->usc) {
471 q6usm_us_client_free(usf_xx->usc);
472 usf_xx->usc = NULL;
473 }
474
475 if (usf_xx->encdec_cfg.params != NULL) {
476 kfree(usf_xx->encdec_cfg.params);
477 usf_xx->encdec_cfg.params = NULL;
478 }
479 }
480}
481
482static void usf_disable(struct usf_xx_type *usf_xx)
483{
484 if (usf_xx != NULL) {
485 if ((usf_xx->usf_state != USF_IDLE_STATE) &&
486 (usf_xx->usf_state != USF_OPENED_STATE)) {
487 (void)q6usm_cmd(usf_xx->usc, CMD_CLOSE);
488 usf_xx->usf_state = USF_OPENED_STATE;
489 wake_up(&usf_xx->wait);
490 }
491 release_xx(usf_xx);
492 }
493}
494
495static int config_xx(struct usf_xx_type *usf_xx, struct us_xx_info_type *config)
496{
497 int rc = 0;
498 uint16_t data_map_size = 0;
Baruch Eruchimovitch64eb8da2013-04-08 14:33:17 +0300499 uint16_t min_map_size = 0;
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +0200500
501 if ((usf_xx == NULL) ||
502 (config == NULL))
503 return -EINVAL;
504
Baruch Eruchimovitchb4c32722013-10-14 15:49:41 +0300505 if ((config->buf_size == 0) ||
506 (config->buf_size > USF_MAX_BUF_SIZE) ||
507 (config->buf_num == 0) ||
508 (config->buf_num > USF_MAX_BUF_NUM)) {
509 pr_err("%s: wrong params: buf_size=%d; buf_num=%d\n",
510 __func__, config->buf_size, config->buf_num);
511 return -EINVAL;
512 }
513
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +0200514 data_map_size = sizeof(usf_xx->encdec_cfg.cfg_common.data_map);
Baruch Eruchimovitch64eb8da2013-04-08 14:33:17 +0300515 min_map_size = min(data_map_size, config->port_cnt);
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +0200516
517 if (config->client_name != NULL) {
518 if (strncpy_from_user(usf_xx->client_name,
519 config->client_name,
520 sizeof(usf_xx->client_name) - 1) < 0) {
521 pr_err("%s: get client name failed\n", __func__);
522 return -EINVAL;
523 }
524 }
525
Baruch Eruchimovitchdac24742012-02-01 15:29:29 +0200526 pr_debug("%s: name=%s; buf_size:%d; dev_id:0x%x; sample_rate:%d\n",
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +0200527 __func__, usf_xx->client_name, config->buf_size,
528 config->dev_id, config->sample_rate);
529
Baruch Eruchimovitchdac24742012-02-01 15:29:29 +0200530 pr_debug("%s: buf_num:%d; format:%d; port_cnt:%d; data_size=%d\n",
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +0200531 __func__, config->buf_num, config->stream_format,
532 config->port_cnt, config->params_data_size);
533
Ravit Dennis895a5572013-06-05 16:34:42 +0300534 pr_debug("%s: id[0]=%d, id[1]=%d, id[2]=%d, id[3]=%d, id[4]=%d,\n",
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +0200535 __func__,
536 config->port_id[0],
537 config->port_id[1],
538 config->port_id[2],
Baruch Eruchimovitch64eb8da2013-04-08 14:33:17 +0300539 config->port_id[3],
540 config->port_id[4]);
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +0200541
Ravit Dennis895a5572013-06-05 16:34:42 +0300542 pr_debug("id[5]=%d, id[6]=%d, id[7]=%d\n",
543 config->port_id[5],
544 config->port_id[6],
545 config->port_id[7]);
546
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +0200547 /* q6usm allocation & configuration */
548 usf_xx->buffer_size = config->buf_size;
549 usf_xx->buffer_count = config->buf_num;
550 usf_xx->encdec_cfg.cfg_common.bits_per_sample =
551 config->bits_per_sample;
552 usf_xx->encdec_cfg.cfg_common.sample_rate = config->sample_rate;
553 /* AFE port e.g. AFE_PORT_ID_SLIMBUS_MULTI_CHAN_1_RX */
554 usf_xx->encdec_cfg.cfg_common.dev_id = config->dev_id;
555
556 usf_xx->encdec_cfg.cfg_common.ch_cfg = config->port_cnt;
557 memcpy((void *)&usf_xx->encdec_cfg.cfg_common.data_map,
558 (void *)config->port_id,
Baruch Eruchimovitch64eb8da2013-04-08 14:33:17 +0300559 min_map_size);
560
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +0200561 if (rc) {
562 pr_err("%s: ports offsets copy failure\n", __func__);
563 return -EINVAL;
564 }
565
566 usf_xx->encdec_cfg.format_id = config->stream_format;
567 usf_xx->encdec_cfg.params_size = config->params_data_size;
568 usf_xx->user_upd_info_na = 1; /* it's used in US_GET_TX_UPDATE */
569
570 if (config->params_data_size > 0) { /* transparent data copy */
571 usf_xx->encdec_cfg.params = kzalloc(config->params_data_size,
572 GFP_KERNEL);
573 if (usf_xx->encdec_cfg.params == NULL) {
574 pr_err("%s: params memory alloc[%d] failure\n",
575 __func__,
576 config->params_data_size);
577 return -ENOMEM;
578 }
579 rc = copy_from_user(usf_xx->encdec_cfg.params,
580 config->params_data,
581 config->params_data_size);
582 if (rc) {
583 pr_err("%s: transparent data copy failure\n",
584 __func__);
585 kfree(usf_xx->encdec_cfg.params);
586 usf_xx->encdec_cfg.params = NULL;
Baruch Eruchimovitch24dda6a2012-01-02 20:28:19 +0200587 return -EFAULT;
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +0200588 }
589 pr_debug("%s: params_size[%d]; params[%d,%d,%d,%d, %d]\n",
590 __func__,
591 config->params_data_size,
592 usf_xx->encdec_cfg.params[0],
593 usf_xx->encdec_cfg.params[1],
594 usf_xx->encdec_cfg.params[2],
595 usf_xx->encdec_cfg.params[3],
596 usf_xx->encdec_cfg.params[4]
597 );
598 }
599
600 usf_xx->usc = q6usm_us_client_alloc(usf_xx->cb, (void *)usf_xx);
601 if (!usf_xx->usc) {
602 pr_err("%s: Could not allocate q6usm client\n", __func__);
603 rc = -EFAULT;
604 }
605
606 return rc;
607}
608
Baruch Eruchimovitch1221b852012-04-02 11:21:30 +0300609static bool usf_match(uint16_t event_type_ind, struct input_dev *dev)
610{
611 bool rc = false;
612
613 rc = (event_type_ind < MAX_EVENT_TYPE_NUM) &&
614 ((dev->name == NULL) ||
615 strncmp(dev->name, USF_NAME_PREFIX, USF_NAME_PREFIX_SIZE));
616 pr_debug("%s: name=[%s]; rc=%d\n",
617 __func__, dev->name, rc);
618
619 return rc;
620}
621
622static bool usf_register_conflicting_events(uint16_t event_types)
623{
624 bool rc = true;
625 uint16_t ind = 0;
626 uint16_t mask = 1;
627
628 for (ind = 0; ind < MAX_EVENT_TYPE_NUM; ++ind) {
629 if (event_types & mask) {
630 rc = usfcdev_register(ind, usf_match);
631 if (!rc)
632 break;
633 }
634 mask = mask << 1;
635 }
636
637 return rc;
638}
639
640static void usf_unregister_conflicting_events(uint16_t event_types)
641{
642 uint16_t ind = 0;
643 uint16_t mask = 1;
644
645 for (ind = 0; ind < MAX_EVENT_TYPE_NUM; ++ind) {
646 if (event_types & mask)
647 usfcdev_unregister(ind);
648 mask = mask << 1;
649 }
650}
651
652static void usf_set_event_filters(struct usf_type *usf, uint16_t event_filters)
653{
654 uint16_t ind = 0;
655 uint16_t mask = 1;
656
657 if (usf->conflicting_event_filters != event_filters) {
658 for (ind = 0; ind < MAX_EVENT_TYPE_NUM; ++ind) {
659 if (usf->conflicting_event_types & mask)
660 usfcdev_set_filter(ind, event_filters&mask);
661 mask = mask << 1;
662 }
663 usf->conflicting_event_filters = event_filters;
664 }
665}
666
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +0200667static int register_input_device(struct usf_type *usf_info,
668 struct us_input_info_type *input_info)
669{
670 int rc = 0;
Baruch Eruchimovitch1221b852012-04-02 11:21:30 +0300671 bool ret = true;
Baruch Eruchimovitchcf5a4d12012-05-31 21:48:18 +0300672 uint16_t ind = 0;
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +0200673
674 if ((usf_info == NULL) ||
675 (input_info == NULL) ||
676 !(input_info->event_types & USF_ALL_EVENTS)) {
677 pr_err("%s: wrong input parameter(s)\n", __func__);
678 return -EINVAL;
679 }
680
Baruch Eruchimovitchcf5a4d12012-05-31 21:48:18 +0300681 for (ind = 0; ind < USF_MAX_EVENT_IND; ++ind) {
682 if (usf_info->input_ifs[ind] != NULL) {
683 pr_err("%s: input_if[%d] is already allocated\n",
684 __func__, ind);
685 return -EFAULT;
686 }
687 if ((input_info->event_types &
688 s_usf_input_devs[ind].event_type) &&
689 s_usf_input_devs[ind].prepare_dev) {
690 rc = (*s_usf_input_devs[ind].prepare_dev)(
691 ind,
692 usf_info,
693 input_info,
694 s_usf_input_devs[ind].input_dev_name);
695 if (rc)
696 return rc;
Baruch Eruchimovitchdac24742012-02-01 15:29:29 +0200697
Baruch Eruchimovitchcf5a4d12012-05-31 21:48:18 +0300698 rc = input_register_device(usf_info->input_ifs[ind]);
699 if (rc) {
700 pr_err("%s: input_reg_dev() failed; rc=%d\n",
701 __func__, rc);
702 input_free_device(usf_info->input_ifs[ind]);
703 usf_info->input_ifs[ind] = NULL;
704 } else {
705 usf_info->event_types |=
706 s_usf_input_devs[ind].event_type;
707 pr_debug("%s: input device[%s] was registered\n",
708 __func__,
709 s_usf_input_devs[ind].input_dev_name);
710 }
711 } /* supported event */
712 } /* event types loop */
713
714 ret = usf_register_conflicting_events(
715 input_info->conflicting_event_types);
716 if (ret)
717 usf_info->conflicting_event_types =
718 input_info->conflicting_event_types;
719
720 return 0;
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +0200721}
722
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +0200723
724static void handle_input_event(struct usf_type *usf_info,
725 uint16_t event_counter,
726 struct usf_event_type *event)
727{
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +0200728 uint16_t ind = 0;
Baruch Eruchimovitch24dda6a2012-01-02 20:28:19 +0200729 uint16_t events_num = 0;
730 struct usf_event_type usf_events[USF_EVENTS_PORTION_SIZE];
731 int rc = 0;
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +0200732
Baruch Eruchimovitchcf5a4d12012-05-31 21:48:18 +0300733 if ((usf_info == NULL) ||
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +0200734 (event == NULL) || (!event_counter)) {
735 return;
736 }
737
Baruch Eruchimovitch24dda6a2012-01-02 20:28:19 +0200738 while (event_counter > 0) {
739 if (event_counter > USF_EVENTS_PORTION_SIZE) {
740 events_num = USF_EVENTS_PORTION_SIZE;
741 event_counter -= USF_EVENTS_PORTION_SIZE;
742 } else {
743 events_num = event_counter;
744 event_counter = 0;
745 }
746 rc = copy_from_user(usf_events,
747 event,
748 events_num * sizeof(struct usf_event_type));
749 if (rc) {
750 pr_err("%s: copy upd_rx_info from user; rc=%d\n",
751 __func__, rc);
752 return;
753 }
754 for (ind = 0; ind < events_num; ++ind) {
755 struct usf_event_type *p_event = &usf_events[ind];
Baruch Eruchimovitchcf5a4d12012-05-31 21:48:18 +0300756 uint16_t if_ind = p_event->event_type_ind;
757
758 if ((if_ind >= USF_MAX_EVENT_IND) ||
759 (usf_info->input_ifs[if_ind] == NULL))
760 continue; /* event isn't supported */
761
762 if (s_usf_input_devs[if_ind].notify_event)
763 (*s_usf_input_devs[if_ind].notify_event)(
764 usf_info,
765 if_ind,
766 p_event);
Baruch Eruchimovitch24dda6a2012-01-02 20:28:19 +0200767 } /* loop in the portion */
768 } /* all events loop */
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +0200769}
770
771static int usf_start_tx(struct usf_xx_type *usf_xx)
772{
773 int rc = q6usm_run(usf_xx->usc, 0, 0, 0);
774
775 pr_debug("%s: tx: q6usm_run; rc=%d\n", __func__, rc);
776 if (!rc) {
Baruch Eruchimovitch24dda6a2012-01-02 20:28:19 +0200777 if (usf_xx->buffer_count >= USM_MIN_BUF_CNT) {
778 /* supply all buffers */
779 rc = q6usm_read(usf_xx->usc,
780 usf_xx->buffer_count);
781 pr_debug("%s: q6usm_read[%d]\n",
782 __func__, rc);
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +0200783
Baruch Eruchimovitch24dda6a2012-01-02 20:28:19 +0200784 if (rc)
785 pr_err("%s: buf read failed",
786 __func__);
787 else
788 usf_xx->usf_state =
789 USF_WORK_STATE;
790 } else
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +0200791 usf_xx->usf_state =
792 USF_WORK_STATE;
793 }
794
795 return rc;
796} /* usf_start_tx */
797
798static int usf_start_rx(struct usf_xx_type *usf_xx)
799{
800 int rc = q6usm_run(usf_xx->usc, 0, 0, 0);
801
802 pr_debug("%s: rx: q6usm_run; rc=%d\n",
803 __func__, rc);
804 if (!rc)
805 usf_xx->usf_state = USF_WORK_STATE;
806
807 return rc;
808} /* usf_start_rx */
809
Baruch Eruchimovitch24dda6a2012-01-02 20:28:19 +0200810static int usf_set_us_detection(struct usf_type *usf, unsigned long arg)
811{
812 uint32_t timeout = 0;
813 struct us_detect_info_type detect_info;
Baruch Eruchimovitchb4c32722013-10-14 15:49:41 +0300814 struct usm_session_cmd_detect_info *p_allocated_memory = NULL;
Baruch Eruchimovitch24dda6a2012-01-02 20:28:19 +0200815 struct usm_session_cmd_detect_info usm_detect_info;
816 struct usm_session_cmd_detect_info *p_usm_detect_info =
817 &usm_detect_info;
818 uint32_t detect_info_size = sizeof(struct usm_session_cmd_detect_info);
819 struct usf_xx_type *usf_xx = &usf->usf_tx;
820 int rc = copy_from_user(&detect_info,
821 (void *) arg,
822 sizeof(detect_info));
823
824 if (rc) {
825 pr_err("%s: copy detect_info from user; rc=%d\n",
826 __func__, rc);
827 return -EFAULT;
828 }
829
830 if (detect_info.us_detector != US_DETECT_FW) {
831 pr_err("%s: unsupported detector: %d\n",
832 __func__, detect_info.us_detector);
833 return -EINVAL;
834 }
835
836 if ((detect_info.params_data_size != 0) &&
837 (detect_info.params_data != NULL)) {
838 uint8_t *p_data = NULL;
839
840 detect_info_size += detect_info.params_data_size;
Baruch Eruchimovitchb4c32722013-10-14 15:49:41 +0300841 p_allocated_memory = kzalloc(detect_info_size, GFP_KERNEL);
842 if (p_allocated_memory == NULL) {
Baruch Eruchimovitch24dda6a2012-01-02 20:28:19 +0200843 pr_err("%s: detect_info[%d] allocation failed\n",
844 __func__, detect_info_size);
845 return -ENOMEM;
846 }
Baruch Eruchimovitchb4c32722013-10-14 15:49:41 +0300847 p_usm_detect_info = p_allocated_memory;
Baruch Eruchimovitch24dda6a2012-01-02 20:28:19 +0200848 p_data = (uint8_t *)p_usm_detect_info +
849 sizeof(struct usm_session_cmd_detect_info);
850
851 rc = copy_from_user(p_data,
852 (void *)detect_info.params_data,
853 detect_info.params_data_size);
854 if (rc) {
855 pr_err("%s: copy params from user; rc=%d\n",
856 __func__, rc);
Baruch Eruchimovitchb4c32722013-10-14 15:49:41 +0300857 kfree(p_allocated_memory);
Baruch Eruchimovitch24dda6a2012-01-02 20:28:19 +0200858 return -EFAULT;
859 }
Baruch Eruchimovitchdac24742012-02-01 15:29:29 +0200860 p_usm_detect_info->algorithm_cfg_size =
861 detect_info.params_data_size;
Baruch Eruchimovitch24dda6a2012-01-02 20:28:19 +0200862 } else
863 usm_detect_info.algorithm_cfg_size = 0;
864
865 p_usm_detect_info->detect_mode = detect_info.us_detect_mode;
866 p_usm_detect_info->skip_interval = detect_info.skip_time;
867
868 usf_xx->us_detect_type = USF_US_DETECT_UNDEF;
869
870 rc = q6usm_set_us_detection(usf_xx->usc,
871 p_usm_detect_info,
872 detect_info_size);
873 if (rc || (detect_info.detect_timeout == USF_NO_WAIT_TIMEOUT)) {
Baruch Eruchimovitchb4c32722013-10-14 15:49:41 +0300874 kfree(p_allocated_memory);
Baruch Eruchimovitch24dda6a2012-01-02 20:28:19 +0200875 return rc;
876 }
877
878 /* Get US detection result */
879 if (detect_info.detect_timeout == USF_INFINITIVE_TIMEOUT) {
Baruch Eruchimovitchd0c077f2012-05-03 18:38:34 +0300880 rc = wait_event_interruptible(usf_xx->wait,
881 (usf_xx->us_detect_type !=
Lior Barenboimbfbed9c2014-03-20 14:56:01 +0200882 USF_US_DETECT_UNDEF) ||
883 (usf_xx->usf_state ==
884 USF_ADSP_RESTART_STATE));
Baruch Eruchimovitch24dda6a2012-01-02 20:28:19 +0200885 } else {
886 if (detect_info.detect_timeout == USF_DEFAULT_TIMEOUT)
887 timeout = USF_TIMEOUT_JIFFIES;
888 else
889 timeout = detect_info.detect_timeout * HZ;
Baruch Eruchimovitchd0c077f2012-05-03 18:38:34 +0300890 }
891 rc = wait_event_interruptible_timeout(usf_xx->wait,
Baruch Eruchimovitch24dda6a2012-01-02 20:28:19 +0200892 (usf_xx->us_detect_type !=
Lior Barenboimbfbed9c2014-03-20 14:56:01 +0200893 USF_US_DETECT_UNDEF) ||
894 (usf_xx->usf_state ==
895 USF_ADSP_RESTART_STATE), timeout);
896
897 /* In the case of aDSP restart, "no US" is assumed */
898 if (usf_xx->usf_state == USF_ADSP_RESTART_STATE) {
899 rc = -EFAULT;
900 }
Baruch Eruchimovitchd0c077f2012-05-03 18:38:34 +0300901 /* In the case of timeout, "no US" is assumed */
Baruch Eruchimovitchb4c32722013-10-14 15:49:41 +0300902 if (rc < 0)
Baruch Eruchimovitchd0c077f2012-05-03 18:38:34 +0300903 pr_err("%s: Getting US detection failed rc[%d]\n",
904 __func__, rc);
Baruch Eruchimovitchb4c32722013-10-14 15:49:41 +0300905 else {
906 usf->usf_rx.us_detect_type = usf->usf_tx.us_detect_type;
907 detect_info.is_us =
908 (usf_xx->us_detect_type == USF_US_DETECT_YES);
909 rc = copy_to_user((void __user *)arg,
910 &detect_info,
911 sizeof(detect_info));
912 if (rc) {
913 pr_err("%s: copy detect_info to user; rc=%d\n",
914 __func__, rc);
915 rc = -EFAULT;
916 }
Baruch Eruchimovitch24dda6a2012-01-02 20:28:19 +0200917 }
918
Baruch Eruchimovitchb4c32722013-10-14 15:49:41 +0300919 kfree(p_allocated_memory);
Baruch Eruchimovitch24dda6a2012-01-02 20:28:19 +0200920
921 return rc;
922} /* usf_set_us_detection */
923
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +0200924static int usf_set_tx_info(struct usf_type *usf, unsigned long arg)
925{
926 struct us_tx_info_type config_tx;
927 const char *name = NULL;
928 struct usf_xx_type *usf_xx = &usf->usf_tx;
929 int rc = copy_from_user(&config_tx,
930 (void *) arg,
931 sizeof(config_tx));
932
933 if (rc) {
Baruch Eruchimovitch24dda6a2012-01-02 20:28:19 +0200934 pr_err("%s: copy config_tx from user; rc=%d\n",
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +0200935 __func__, rc);
Baruch Eruchimovitch24dda6a2012-01-02 20:28:19 +0200936 return -EFAULT;
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +0200937 }
938
939 name = config_tx.us_xx_info.client_name;
940
941 usf_xx->new_region = USM_UNDEF_TOKEN;
942 usf_xx->prev_region = USM_UNDEF_TOKEN;
943 usf_xx->cb = usf_tx_cb;
944
945 init_waitqueue_head(&usf_xx->wait);
946
947 if (name != NULL) {
948 int res = strncpy_from_user(
949 usf_xx->client_name,
950 name,
951 sizeof(usf_xx->client_name)-1);
952 if (res < 0) {
953 pr_err("%s: get client name failed\n",
954 __func__);
955 return -EINVAL;
956 }
957 }
958
959 rc = config_xx(usf_xx, &config_tx.us_xx_info);
960 if (rc)
961 return rc;
962
963 rc = q6usm_open_read(usf_xx->usc,
964 usf_xx->encdec_cfg.format_id);
965 if (rc)
966 return rc;
967
968 rc = q6usm_us_client_buf_alloc(OUT, usf_xx->usc,
969 usf_xx->buffer_size,
970 usf_xx->buffer_count);
Baruch Eruchimovitch64eb8da2013-04-08 14:33:17 +0300971 if (rc) {
972 (void)q6usm_cmd(usf_xx->usc, CMD_CLOSE);
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +0200973 return rc;
Baruch Eruchimovitch64eb8da2013-04-08 14:33:17 +0300974 }
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +0200975
976 rc = q6usm_enc_cfg_blk(usf_xx->usc,
977 &usf_xx->encdec_cfg);
Baruch Eruchimovitch24dda6a2012-01-02 20:28:19 +0200978 if (!rc &&
979 (config_tx.input_info.event_types != USF_NO_EVENT)) {
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +0200980 rc = register_input_device(usf,
981 &config_tx.input_info);
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +0200982 }
983
Baruch Eruchimovitch64eb8da2013-04-08 14:33:17 +0300984 if (rc)
985 (void)q6usm_cmd(usf_xx->usc, CMD_CLOSE);
986 else
Baruch Eruchimovitch24dda6a2012-01-02 20:28:19 +0200987 usf_xx->usf_state = USF_CONFIGURED_STATE;
988
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +0200989 return rc;
990} /* usf_set_tx_info */
991
992static int usf_set_rx_info(struct usf_type *usf, unsigned long arg)
993{
994 struct us_rx_info_type config_rx;
995 struct usf_xx_type *usf_xx = &usf->usf_rx;
996 int rc = copy_from_user(&config_rx,
997 (void *) arg,
998 sizeof(config_rx));
999
1000 if (rc) {
Baruch Eruchimovitch24dda6a2012-01-02 20:28:19 +02001001 pr_err("%s: copy config_rx from user; rc=%d\n",
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +02001002 __func__, rc);
Baruch Eruchimovitch24dda6a2012-01-02 20:28:19 +02001003 return -EFAULT;
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +02001004 }
1005
1006 usf_xx->new_region = USM_UNDEF_TOKEN;
1007 usf_xx->prev_region = USM_UNDEF_TOKEN;
1008
1009 usf_xx->cb = usf_rx_cb;
1010
1011 rc = config_xx(usf_xx, &config_rx.us_xx_info);
1012 if (rc)
1013 return rc;
1014
1015 rc = q6usm_open_write(usf_xx->usc,
1016 usf_xx->encdec_cfg.format_id);
1017 if (rc)
1018 return rc;
1019
Baruch Eruchimovitchb4c32722013-10-14 15:49:41 +03001020 rc = q6usm_us_client_buf_alloc(
1021 IN,
1022 usf_xx->usc,
1023 usf_xx->buffer_size,
1024 usf_xx->buffer_count);
1025 if (rc) {
1026 (void)q6usm_cmd(usf_xx->usc, CMD_CLOSE);
1027 return rc;
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +02001028 }
1029
1030 rc = q6usm_dec_cfg_blk(usf_xx->usc,
1031 &usf_xx->encdec_cfg);
Baruch Eruchimovitch64eb8da2013-04-08 14:33:17 +03001032 if (rc)
1033 (void)q6usm_cmd(usf_xx->usc, CMD_CLOSE);
1034 else {
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +02001035 init_waitqueue_head(&usf_xx->wait);
1036 usf_xx->usf_state = USF_CONFIGURED_STATE;
1037 }
1038
1039 return rc;
1040} /* usf_set_rx_info */
1041
1042
1043static int usf_get_tx_update(struct usf_type *usf, unsigned long arg)
1044{
1045 struct us_tx_update_info_type upd_tx_info;
1046 unsigned long prev_jiffies = 0;
Baruch Eruchimovitch24dda6a2012-01-02 20:28:19 +02001047 uint32_t timeout = 0;
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +02001048 struct usf_xx_type *usf_xx = &usf->usf_tx;
1049 int rc = copy_from_user(&upd_tx_info, (void *) arg,
1050 sizeof(upd_tx_info));
1051
1052 if (rc) {
Baruch Eruchimovitch24dda6a2012-01-02 20:28:19 +02001053 pr_err("%s: copy upd_tx_info from user; rc=%d\n",
1054 __func__, rc);
1055 return -EFAULT;
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +02001056 }
1057
1058 if (!usf_xx->user_upd_info_na) {
Baruch Eruchimovitch1221b852012-04-02 11:21:30 +03001059 usf_set_event_filters(usf, upd_tx_info.event_filters);
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +02001060 handle_input_event(usf,
1061 upd_tx_info.event_counter,
1062 upd_tx_info.event);
1063
1064 /* Release available regions */
1065 rc = q6usm_read(usf_xx->usc,
1066 upd_tx_info.free_region);
1067 if (rc)
1068 return rc;
1069 } else
1070 usf_xx->user_upd_info_na = 0;
1071
1072 /* Get data ready regions */
Baruch Eruchimovitch24dda6a2012-01-02 20:28:19 +02001073 if (upd_tx_info.timeout == USF_INFINITIVE_TIMEOUT) {
Baruch Eruchimovitchd0c077f2012-05-03 18:38:34 +03001074 rc = wait_event_interruptible(usf_xx->wait,
Baruch Eruchimovitch24dda6a2012-01-02 20:28:19 +02001075 (usf_xx->prev_region !=
1076 usf_xx->new_region) ||
1077 (usf_xx->usf_state !=
1078 USF_WORK_STATE));
1079 } else {
1080 if (upd_tx_info.timeout == USF_NO_WAIT_TIMEOUT)
1081 rc = (usf_xx->prev_region != usf_xx->new_region);
1082 else {
Baruch Eruchimovitch24dda6a2012-01-02 20:28:19 +02001083 prev_jiffies = jiffies;
Baruch Eruchimovitchd0c077f2012-05-03 18:38:34 +03001084 if (upd_tx_info.timeout == USF_DEFAULT_TIMEOUT) {
1085 timeout = USF_TIMEOUT_JIFFIES;
1086 rc = wait_event_timeout(
1087 usf_xx->wait,
Baruch Eruchimovitch24dda6a2012-01-02 20:28:19 +02001088 (usf_xx->prev_region !=
1089 usf_xx->new_region) ||
1090 (usf_xx->usf_state !=
1091 USF_WORK_STATE),
1092 timeout);
Baruch Eruchimovitchd0c077f2012-05-03 18:38:34 +03001093 } else {
1094 timeout = upd_tx_info.timeout * HZ;
1095 rc = wait_event_interruptible_timeout(
1096 usf_xx->wait,
1097 (usf_xx->prev_region !=
1098 usf_xx->new_region) ||
1099 (usf_xx->usf_state !=
1100 USF_WORK_STATE),
1101 timeout);
1102 }
Baruch Eruchimovitch24dda6a2012-01-02 20:28:19 +02001103 }
1104 if (!rc) {
1105 pr_debug("%s: timeout. prev_j=%lu; j=%lu\n",
1106 __func__, prev_jiffies, jiffies);
1107 pr_debug("%s: timeout. prev=%d; new=%d\n",
1108 __func__, usf_xx->prev_region,
1109 usf_xx->new_region);
1110 pr_debug("%s: timeout. free_region=%d;\n",
1111 __func__, upd_tx_info.free_region);
1112 if (usf_xx->prev_region ==
1113 usf_xx->new_region) {
1114 pr_err("%s:read data: timeout\n",
1115 __func__);
1116 return -ETIME;
1117 }
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +02001118 }
1119 }
1120
Baruch Eruchimovitchd0c077f2012-05-03 18:38:34 +03001121 if ((usf_xx->usf_state != USF_WORK_STATE) ||
1122 (rc == -ERESTARTSYS)) {
Baruch Eruchimovitch258b3472012-10-14 21:46:35 +02001123 pr_err("%s: Get ready region failure; state[%d]; rc[%d]\n",
Baruch Eruchimovitchd0c077f2012-05-03 18:38:34 +03001124 __func__, usf_xx->usf_state, rc);
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +02001125 return -EINTR;
1126 }
1127
1128 upd_tx_info.ready_region = usf_xx->new_region;
Baruch Eruchimovitch24dda6a2012-01-02 20:28:19 +02001129 usf_xx->prev_region = upd_tx_info.ready_region;
1130
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +02001131 if (upd_tx_info.ready_region == USM_WRONG_TOKEN) {
1132 pr_err("%s: TX path corrupted; prev=%d\n",
1133 __func__, usf_xx->prev_region);
Baruch Eruchimovitch24dda6a2012-01-02 20:28:19 +02001134 return -EIO;
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +02001135 }
Baruch Eruchimovitch24dda6a2012-01-02 20:28:19 +02001136
1137 rc = copy_to_user((void __user *)arg, &upd_tx_info,
1138 sizeof(upd_tx_info));
1139 if (rc) {
1140 pr_err("%s: copy upd_tx_info to user; rc=%d\n",
1141 __func__, rc);
1142 rc = -EFAULT;
1143 }
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +02001144
1145 return rc;
1146} /* usf_get_tx_update */
1147
1148static int usf_set_rx_update(struct usf_xx_type *usf_xx, unsigned long arg)
1149{
1150 struct us_rx_update_info_type upd_rx_info;
1151 int rc = copy_from_user(&upd_rx_info, (void *) arg,
1152 sizeof(upd_rx_info));
1153
1154 if (rc) {
Baruch Eruchimovitch24dda6a2012-01-02 20:28:19 +02001155 pr_err("%s: copy upd_rx_info from user; rc=%d\n",
1156 __func__, rc);
1157 return -EFAULT;
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +02001158 }
1159
1160 /* Send available data regions */
1161 if (upd_rx_info.ready_region !=
1162 usf_xx->buffer_count) {
1163 rc = q6usm_write(
1164 usf_xx->usc,
1165 upd_rx_info.ready_region);
1166 if (rc)
1167 return rc;
1168 }
1169
1170 /* Get free regions */
1171 rc = wait_event_timeout(
1172 usf_xx->wait,
1173 !q6usm_is_write_buf_full(
1174 usf_xx->usc,
1175 &upd_rx_info.free_region) ||
1176 (usf_xx->usf_state == USF_IDLE_STATE),
1177 USF_TIMEOUT_JIFFIES);
1178
1179 if (!rc) {
1180 rc = -ETIME;
1181 pr_err("%s:timeout. wait for write buf not full\n",
1182 __func__);
1183 } else {
1184 if (usf_xx->usf_state !=
1185 USF_WORK_STATE) {
1186 pr_err("%s: RX: state[%d]\n",
1187 __func__,
1188 usf_xx->usf_state);
1189 rc = -EINTR;
Baruch Eruchimovitch24dda6a2012-01-02 20:28:19 +02001190 } else {
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +02001191 rc = copy_to_user(
1192 (void __user *)arg,
1193 &upd_rx_info,
1194 sizeof(upd_rx_info));
Baruch Eruchimovitch24dda6a2012-01-02 20:28:19 +02001195 if (rc) {
1196 pr_err("%s: copy rx_info to user; rc=%d\n",
1197 __func__, rc);
1198 rc = -EFAULT;
1199 }
1200 }
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +02001201 }
1202
1203 return rc;
1204} /* usf_set_rx_update */
1205
Baruch Eruchimovitch1221b852012-04-02 11:21:30 +03001206static void usf_release_input(struct usf_type *usf)
1207{
Baruch Eruchimovitchcf5a4d12012-05-31 21:48:18 +03001208 uint16_t ind = 0;
1209
Baruch Eruchimovitch32b44a22012-07-24 15:42:59 +03001210 usf_unregister_conflicting_events(
1211 usf->conflicting_event_types);
1212 usf->conflicting_event_types = 0;
Baruch Eruchimovitchcf5a4d12012-05-31 21:48:18 +03001213 for (ind = 0; ind < USF_MAX_EVENT_IND; ++ind) {
1214 if (usf->input_ifs[ind] == NULL)
1215 continue;
Baruch Eruchimovitchcf5a4d12012-05-31 21:48:18 +03001216 input_unregister_device(usf->input_ifs[ind]);
1217 usf->input_ifs[ind] = NULL;
1218 pr_debug("%s input_unregister_device[%s]\n",
1219 __func__,
1220 s_usf_input_devs[ind].input_dev_name);
Baruch Eruchimovitch1221b852012-04-02 11:21:30 +03001221 }
1222} /* usf_release_input */
1223
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +02001224static int usf_stop_tx(struct usf_type *usf)
1225{
1226 struct usf_xx_type *usf_xx = &usf->usf_tx;
1227
Baruch Eruchimovitch1221b852012-04-02 11:21:30 +03001228 usf_release_input(usf);
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +02001229 usf_disable(usf_xx);
1230
1231 return 0;
1232} /* usf_stop_tx */
1233
Baruch Eruchimovitchdac24742012-02-01 15:29:29 +02001234static int usf_get_version(unsigned long arg)
1235{
1236 struct us_version_info_type version_info;
1237 int rc = copy_from_user(&version_info, (void *) arg,
1238 sizeof(version_info));
1239
1240 if (rc) {
1241 pr_err("%s: copy version_info from user; rc=%d\n",
1242 __func__, rc);
1243 return -EFAULT;
1244 }
1245
Baruch Eruchimovitchb4c32722013-10-14 15:49:41 +03001246 if (version_info.buf_size < sizeof(DRV_VERSION)) {
1247 pr_err("%s: buf_size (%d) < version string size (%d)\n",
1248 __func__, version_info.buf_size, sizeof(DRV_VERSION));
1249 return -EINVAL;
1250 }
1251
Baruch Eruchimovitchdac24742012-02-01 15:29:29 +02001252 rc = copy_to_user(version_info.pbuf,
1253 DRV_VERSION,
Baruch Eruchimovitchb4c32722013-10-14 15:49:41 +03001254 sizeof(DRV_VERSION));
Baruch Eruchimovitchdac24742012-02-01 15:29:29 +02001255 if (rc) {
1256 pr_err("%s: copy to version_info.pbuf; rc=%d\n",
1257 __func__, rc);
1258 rc = -EFAULT;
1259 }
1260
1261 rc = copy_to_user((void __user *)arg,
1262 &version_info,
1263 sizeof(version_info));
1264 if (rc) {
1265 pr_err("%s: copy version_info to user; rc=%d\n",
1266 __func__, rc);
1267 rc = -EFAULT;
1268 }
1269
1270 return rc;
1271} /* usf_get_version */
1272
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +02001273static long usf_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1274{
1275 int rc = 0;
1276 struct usf_type *usf = file->private_data;
1277 struct usf_xx_type *usf_xx = NULL;
1278
1279 switch (cmd) {
1280 case US_START_TX: {
1281 usf_xx = &usf->usf_tx;
1282 if (usf_xx->usf_state == USF_CONFIGURED_STATE)
1283 rc = usf_start_tx(usf_xx);
1284 else {
1285 pr_err("%s: start_tx: wrong state[%d]\n",
1286 __func__,
1287 usf_xx->usf_state);
1288 return -EBADFD;
1289 }
1290 break;
1291 }
1292
1293 case US_START_RX: {
1294 usf_xx = &usf->usf_rx;
1295 if (usf_xx->usf_state == USF_CONFIGURED_STATE)
1296 rc = usf_start_rx(usf_xx);
1297 else {
1298 pr_err("%s: start_rx: wrong state[%d]\n",
1299 __func__,
1300 usf_xx->usf_state);
1301 return -EBADFD;
1302 }
1303 break;
1304 }
1305
1306 case US_SET_TX_INFO: {
1307 usf_xx = &usf->usf_tx;
1308 if (usf_xx->usf_state == USF_OPENED_STATE)
1309 rc = usf_set_tx_info(usf, arg);
1310 else {
1311 pr_err("%s: set_tx_info: wrong state[%d]\n",
1312 __func__,
1313 usf_xx->usf_state);
1314 return -EBADFD;
1315 }
1316
1317 break;
1318 } /* US_SET_TX_INFO */
1319
1320 case US_SET_RX_INFO: {
1321 usf_xx = &usf->usf_rx;
1322 if (usf_xx->usf_state == USF_OPENED_STATE)
1323 rc = usf_set_rx_info(usf, arg);
1324 else {
1325 pr_err("%s: set_rx_info: wrong state[%d]\n",
1326 __func__,
1327 usf_xx->usf_state);
1328 return -EBADFD;
1329 }
1330
1331 break;
1332 } /* US_SET_RX_INFO */
1333
1334 case US_GET_TX_UPDATE: {
1335 struct usf_xx_type *usf_xx = &usf->usf_tx;
1336 if (usf_xx->usf_state == USF_WORK_STATE)
1337 rc = usf_get_tx_update(usf, arg);
1338 else {
1339 pr_err("%s: get_tx_update: wrong state[%d]\n", __func__,
1340 usf_xx->usf_state);
1341 rc = -EBADFD;
1342 }
1343 break;
1344 } /* US_GET_TX_UPDATE */
1345
1346 case US_SET_RX_UPDATE: {
1347 struct usf_xx_type *usf_xx = &usf->usf_rx;
1348 if (usf_xx->usf_state == USF_WORK_STATE)
1349 rc = usf_set_rx_update(usf_xx, arg);
1350 else {
1351 pr_err("%s: set_rx_update: wrong state[%d]\n",
1352 __func__,
1353 usf_xx->usf_state);
1354 rc = -EBADFD;
1355 }
1356 break;
1357 } /* US_SET_RX_UPDATE */
1358
1359 case US_STOP_TX: {
1360 usf_xx = &usf->usf_tx;
Lior Barenboimbfbed9c2014-03-20 14:56:01 +02001361 if ((usf_xx->usf_state == USF_WORK_STATE)
1362 || (usf_xx->usf_state == USF_ADSP_RESTART_STATE))
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +02001363 rc = usf_stop_tx(usf);
1364 else {
1365 pr_err("%s: stop_tx: wrong state[%d]\n",
1366 __func__,
1367 usf_xx->usf_state);
1368 return -EBADFD;
1369 }
1370 break;
1371 } /* US_STOP_TX */
1372
1373 case US_STOP_RX: {
1374 usf_xx = &usf->usf_rx;
Lior Barenboimbfbed9c2014-03-20 14:56:01 +02001375 if ((usf_xx->usf_state == USF_WORK_STATE)
1376 || (usf_xx->usf_state == USF_ADSP_RESTART_STATE))
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +02001377 usf_disable(usf_xx);
1378 else {
1379 pr_err("%s: stop_rx: wrong state[%d]\n",
1380 __func__,
1381 usf_xx->usf_state);
1382 return -EBADFD;
1383 }
1384 break;
1385 } /* US_STOP_RX */
1386
Baruch Eruchimovitch24dda6a2012-01-02 20:28:19 +02001387 case US_SET_DETECTION: {
1388 struct usf_xx_type *usf_xx = &usf->usf_tx;
1389 if (usf_xx->usf_state == USF_WORK_STATE)
1390 rc = usf_set_us_detection(usf, arg);
1391 else {
1392 pr_err("%s: set us detection: wrong state[%d]\n",
1393 __func__,
1394 usf_xx->usf_state);
1395 rc = -EBADFD;
1396 }
1397 break;
Baruch Eruchimovitchdac24742012-02-01 15:29:29 +02001398 } /* US_SET_DETECTION */
1399
1400 case US_GET_VERSION: {
1401 rc = usf_get_version(arg);
1402 break;
1403 } /* US_GET_VERSION */
Baruch Eruchimovitch24dda6a2012-01-02 20:28:19 +02001404
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +02001405 default:
Baruch Eruchimovitchdac24742012-02-01 15:29:29 +02001406 pr_err("%s: unsupported IOCTL command [%d]\n",
1407 __func__,
1408 cmd);
1409 rc = -ENOTTY;
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +02001410 break;
1411 }
1412
1413 if (rc &&
1414 ((cmd == US_SET_TX_INFO) ||
1415 (cmd == US_SET_RX_INFO)))
1416 release_xx(usf_xx);
1417
1418 return rc;
1419} /* usf_ioctl */
1420
1421static int usf_mmap(struct file *file, struct vm_area_struct *vms)
1422{
1423 struct usf_type *usf = file->private_data;
1424 int dir = OUT;
1425 struct usf_xx_type *usf_xx = &usf->usf_tx;
1426
1427 if (vms->vm_flags & USF_VM_WRITE) { /* RX buf mapping */
1428 dir = IN;
1429 usf_xx = &usf->usf_rx;
1430 }
1431
1432 return q6usm_get_virtual_address(dir, usf_xx->usc, vms);
1433}
1434
1435static uint16_t add_opened_dev(int minor)
1436{
1437 uint16_t ind = 0;
1438
1439 for (ind = 0; ind < MAX_DEVS_NUMBER; ++ind) {
1440 if (minor == s_opened_devs[ind]) {
1441 pr_err("%s: device %d is already opened\n",
1442 __func__, minor);
1443 return USF_UNDEF_DEV_ID;
1444 }
1445
1446 if (s_opened_devs[ind] == 0) {
1447 s_opened_devs[ind] = minor;
Baruch Eruchimovitchdac24742012-02-01 15:29:29 +02001448 pr_debug("%s: device %d is added; ind=%d\n",
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +02001449 __func__, minor, ind);
1450 return ind;
1451 }
1452 }
1453
1454 pr_err("%s: there is no place for device %d\n",
1455 __func__, minor);
1456 return USF_UNDEF_DEV_ID;
1457}
1458
1459static int usf_open(struct inode *inode, struct file *file)
1460{
1461 struct usf_type *usf = NULL;
1462 uint16_t dev_ind = 0;
1463 int minor = MINOR(inode->i_rdev);
1464
1465 dev_ind = add_opened_dev(minor);
1466 if (dev_ind == USF_UNDEF_DEV_ID)
1467 return -EBUSY;
1468
1469 usf = kzalloc(sizeof(struct usf_type), GFP_KERNEL);
1470 if (usf == NULL) {
1471 pr_err("%s:usf allocation failed\n", __func__);
1472 return -ENOMEM;
1473 }
1474
1475 file->private_data = usf;
1476 usf->dev_ind = dev_ind;
1477
1478 usf->usf_tx.usf_state = USF_OPENED_STATE;
1479 usf->usf_rx.usf_state = USF_OPENED_STATE;
1480
Baruch Eruchimovitch24dda6a2012-01-02 20:28:19 +02001481 usf->usf_tx.us_detect_type = USF_US_DETECT_UNDEF;
1482 usf->usf_rx.us_detect_type = USF_US_DETECT_UNDEF;
1483
Baruch Eruchimovitchdac24742012-02-01 15:29:29 +02001484 pr_debug("%s:usf in open\n", __func__);
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +02001485 return 0;
1486}
1487
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +02001488static int usf_release(struct inode *inode, struct file *file)
1489{
1490 struct usf_type *usf = file->private_data;
1491
Baruch Eruchimovitchdac24742012-02-01 15:29:29 +02001492 pr_debug("%s: release entry\n", __func__);
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +02001493
Baruch Eruchimovitch1221b852012-04-02 11:21:30 +03001494 usf_release_input(usf);
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +02001495
1496 usf_disable(&usf->usf_tx);
1497 usf_disable(&usf->usf_rx);
1498
1499 s_opened_devs[usf->dev_ind] = 0;
1500
1501 kfree(usf);
Baruch Eruchimovitchdac24742012-02-01 15:29:29 +02001502 pr_debug("%s: release exit\n", __func__);
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +02001503 return 0;
1504}
1505
1506static const struct file_operations usf_fops = {
1507 .owner = THIS_MODULE,
1508 .open = usf_open,
1509 .release = usf_release,
1510 .unlocked_ioctl = usf_ioctl,
1511 .mmap = usf_mmap,
1512};
1513
1514struct miscdevice usf_misc[MAX_DEVS_NUMBER] = {
1515 {
1516 .minor = MISC_DYNAMIC_MINOR,
1517 .name = "usf1",
1518 .fops = &usf_fops,
1519 },
1520};
1521
1522static int __init usf_init(void)
1523{
1524 int rc = 0;
1525 uint16_t ind = 0;
1526
Baruch Eruchimovitchdac24742012-02-01 15:29:29 +02001527 pr_debug("%s: USF SW version %s.\n", __func__, DRV_VERSION);
1528 pr_debug("%s: Max %d devs registration\n", __func__, MAX_DEVS_NUMBER);
Baruch Eruchimovitche9cbfc12011-10-09 19:47:08 +02001529
1530 for (ind = 0; ind < MAX_DEVS_NUMBER; ++ind) {
1531 rc = misc_register(&usf_misc[ind]);
1532 if (rc) {
1533 pr_err("%s: misc_register() failed ind=%d; rc = %d\n",
1534 __func__, ind, rc);
1535 break;
1536 }
1537 }
1538
1539 return rc;
1540}
1541
1542device_initcall(usf_init);
1543
1544MODULE_DESCRIPTION("Ultrasound framework driver");