Lior Barenboim | 69539fb | 2013-12-25 18:38:31 +0200 | [diff] [blame] | 1 | /* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved. |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 2 | * |
| 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 Eruchimovitch | 1221b85 | 2012-04-02 11:21:30 +0300 | [diff] [blame] | 27 | #include "usfcdev.h" |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 28 | |
| 29 | /* The driver version*/ |
Lior Barenboim | 69539fb | 2013-12-25 18:38:31 +0200 | [diff] [blame] | 30 | #define DRV_VERSION "1.6.1" |
| 31 | #define USF_VERSION_ID 0x0161 |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 32 | |
| 33 | /* Standard timeout in the asynchronous ops */ |
Baruch Eruchimovitch | d0c077f | 2012-05-03 18:38:34 +0300 | [diff] [blame] | 34 | #define USF_TIMEOUT_JIFFIES (1*HZ) /* 1 sec */ |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 35 | |
| 36 | /* Undefined USF device */ |
| 37 | #define USF_UNDEF_DEV_ID 0xffff |
| 38 | |
| 39 | /* RX memory mapping flag */ |
Baruch Eruchimovitch | dac2474 | 2012-02-01 15:29:29 +0200 | [diff] [blame] | 40 | #define USF_VM_WRITE 2 |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 41 | |
Baruch Eruchimovitch | 24dda6a | 2012-01-02 20:28:19 +0200 | [diff] [blame] | 42 | /* Number of events, copied from the user space to kernel one */ |
| 43 | #define USF_EVENTS_PORTION_SIZE 20 |
| 44 | |
Baruch Eruchimovitch | dac2474 | 2012-02-01 15:29:29 +0200 | [diff] [blame] | 45 | /* 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 Eruchimovitch | b4c3272 | 2013-10-14 15:49:41 +0300 | [diff] [blame] | 54 | /* 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 Eruchimovitch | dac2474 | 2012-02-01 15:29:29 +0200 | [diff] [blame] | 59 | /* 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 Dennis | 029c41b | 2013-10-29 17:44:09 +0200 | [diff] [blame] | 65 | #define BITS_IN_BYTE 8 |
| 66 | |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 67 | /* The driver states */ |
| 68 | enum usf_state_type { |
| 69 | USF_IDLE_STATE, |
| 70 | USF_OPENED_STATE, |
| 71 | USF_CONFIGURED_STATE, |
| 72 | USF_WORK_STATE, |
Lior Barenboim | bfbed9c | 2014-03-20 14:56:01 +0200 | [diff] [blame^] | 73 | USF_ADSP_RESTART_STATE, |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 74 | USF_ERROR_STATE |
| 75 | }; |
| 76 | |
Baruch Eruchimovitch | 24dda6a | 2012-01-02 20:28:19 +0200 | [diff] [blame] | 77 | /* The US detection status upon FW/HW based US detection results */ |
| 78 | enum usf_us_detect_type { |
| 79 | USF_US_DETECT_UNDEF, |
| 80 | USF_US_DETECT_YES, |
| 81 | USF_US_DETECT_NO |
| 82 | }; |
| 83 | |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 84 | struct 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 Eruchimovitch | 24dda6a | 2012-01-02 20:28:19 +0200 | [diff] [blame] | 104 | /* US detection result */ |
| 105 | enum usf_us_detect_type us_detect_type; |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 106 | /* User's update info isn't acceptable */ |
| 107 | u8 user_upd_info_na; |
| 108 | }; |
| 109 | |
| 110 | struct 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 Eruchimovitch | cf5a4d1 | 2012-05-31 21:48:18 +0300 | [diff] [blame] | 120 | /* The input devices are "input" module registered clients */ |
| 121 | struct input_dev *input_ifs[USF_MAX_EVENT_IND]; |
Baruch Eruchimovitch | 1221b85 | 2012-04-02 11:21:30 +0300 | [diff] [blame] | 122 | /* 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 Barenboim | 69539fb | 2013-12-25 18:38:31 +0200 | [diff] [blame] | 126 | /* The requested buttons bitmap */ |
| 127 | uint16_t req_buttons_bitmap; |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 128 | }; |
| 129 | |
Baruch Eruchimovitch | cf5a4d1 | 2012-05-31 21:48:18 +0300 | [diff] [blame] | 130 | struct 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 Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 147 | /* The MAX number of the supported devices */ |
| 148 | #define MAX_DEVS_NUMBER 1 |
| 149 | |
Lior Barenboim | 69539fb | 2013-12-25 18:38:31 +0200 | [diff] [blame] | 150 | /* |
| 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 Eruchimovitch | dac2474 | 2012-02-01 15:29:29 +0200 | [diff] [blame] | 157 | |
Ravit Dennis | 029c41b | 2013-10-29 17:44:09 +0200 | [diff] [blame] | 158 | /* Supported buttons container */ |
| 159 | static const int s_button_map[] = { |
| 160 | BTN_STYLUS, |
Lior Barenboim | 69539fb | 2013-12-25 18:38:31 +0200 | [diff] [blame] | 161 | BTN_STYLUS2, |
| 162 | BTN_TOOL_PEN, |
| 163 | BTN_TOOL_RUBBER, |
| 164 | BTN_TOOL_FINGER, |
| 165 | BTN_USF_HOVERING_CURSOR |
Ravit Dennis | 029c41b | 2013-10-29 17:44:09 +0200 | [diff] [blame] | 166 | }; |
| 167 | |
Baruch Eruchimovitch | dac2474 | 2012-02-01 15:29:29 +0200 | [diff] [blame] | 168 | /* The opened devices container */ |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 169 | static int s_opened_devs[MAX_DEVS_NUMBER]; |
| 170 | |
Baruch Eruchimovitch | cf5a4d1 | 2012-05-31 21:48:18 +0300 | [diff] [blame] | 171 | #define USF_NAME_PREFIX "usf_" |
Baruch Eruchimovitch | 1221b85 | 2012-04-02 11:21:30 +0300 | [diff] [blame] | 172 | #define USF_NAME_PREFIX_SIZE 4 |
| 173 | |
Baruch Eruchimovitch | cf5a4d1 | 2012-05-31 21:48:18 +0300 | [diff] [blame] | 174 | |
| 175 | static 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 | |
| 193 | static 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 Dennis | 029c41b | 2013-10-29 17:44:09 +0200 | [diff] [blame] | 198 | int i = 0; |
Lior Barenboim | 69539fb | 2013-12-25 18:38:31 +0200 | [diff] [blame] | 199 | |
| 200 | int num_buttons = min(ARRAY_SIZE(s_button_map), |
| 201 | sizeof(input_info->req_buttons_bitmap) * |
Ravit Dennis | 029c41b | 2013-10-29 17:44:09 +0200 | [diff] [blame] | 202 | BITS_IN_BYTE); |
Lior Barenboim | 69539fb | 2013-12-25 18:38:31 +0200 | [diff] [blame] | 203 | uint16_t max_buttons_bitmap = ((1 << ARRAY_SIZE(s_button_map)) - 1); |
| 204 | |
Baruch Eruchimovitch | cf5a4d1 | 2012-05-31 21:48:18 +0300 | [diff] [blame] | 205 | struct input_dev *in_dev = allocate_dev(ind, name); |
Baruch Eruchimovitch | cf5a4d1 | 2012-05-31 21:48:18 +0300 | [diff] [blame] | 206 | if (in_dev == NULL) |
| 207 | return -ENOMEM; |
| 208 | |
Lior Barenboim | 69539fb | 2013-12-25 18:38:31 +0200 | [diff] [blame] | 209 | if (input_info->req_buttons_bitmap > max_buttons_bitmap) { |
| 210 | pr_err("%s: Requested buttons[%d] exceeds max buttons available[%d]\n", |
Ravit Dennis | 029c41b | 2013-10-29 17:44:09 +0200 | [diff] [blame] | 211 | __func__, |
Lior Barenboim | 69539fb | 2013-12-25 18:38:31 +0200 | [diff] [blame] | 212 | input_info->req_buttons_bitmap, |
| 213 | max_buttons_bitmap); |
Ravit Dennis | 029c41b | 2013-10-29 17:44:09 +0200 | [diff] [blame] | 214 | return -EINVAL; |
| 215 | } |
| 216 | |
Baruch Eruchimovitch | cf5a4d1 | 2012-05-31 21:48:18 +0300 | [diff] [blame] | 217 | usf_info->input_ifs[ind] = in_dev; |
Lior Barenboim | 69539fb | 2013-12-25 18:38:31 +0200 | [diff] [blame] | 218 | usf_info->req_buttons_bitmap = |
| 219 | input_info->req_buttons_bitmap; |
Baruch Eruchimovitch | cf5a4d1 | 2012-05-31 21:48:18 +0300 | [diff] [blame] | 220 | 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 Dennis | 029c41b | 2013-10-29 17:44:09 +0200 | [diff] [blame] | 222 | |
Lior Barenboim | 69539fb | 2013-12-25 18:38:31 +0200 | [diff] [blame] | 223 | for (i = 0; i < num_buttons; i++) |
| 224 | if (input_info->req_buttons_bitmap & (1 << i)) |
Ravit Dennis | 029c41b | 2013-10-29 17:44:09 +0200 | [diff] [blame] | 225 | in_dev->keybit[BIT_WORD(s_button_map[i])] |= |
| 226 | BIT_MASK(s_button_map[i]); |
| 227 | |
Baruch Eruchimovitch | cf5a4d1 | 2012-05-31 21:48:18 +0300 | [diff] [blame] | 228 | 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 | |
| 258 | static 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 | |
| 280 | static 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 | |
| 299 | static void notify_tsc_event(struct usf_type *usf_info, |
| 300 | uint16_t if_ind, |
| 301 | struct usf_event_type *event) |
| 302 | |
| 303 | { |
Ravit Dennis | 029c41b | 2013-10-29 17:44:09 +0200 | [diff] [blame] | 304 | int i = 0; |
Lior Barenboim | 69539fb | 2013-12-25 18:38:31 +0200 | [diff] [blame] | 305 | int num_buttons = min(ARRAY_SIZE(s_button_map), |
| 306 | sizeof(usf_info->req_buttons_bitmap) * |
Ravit Dennis | 029c41b | 2013-10-29 17:44:09 +0200 | [diff] [blame] | 307 | BITS_IN_BYTE); |
| 308 | |
Baruch Eruchimovitch | cf5a4d1 | 2012-05-31 21:48:18 +0300 | [diff] [blame] | 309 | 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 Barenboim | 69539fb | 2013-12-25 18:38:31 +0200 | [diff] [blame] | 322 | for (i = 0; i < num_buttons; i++) { |
Ravit Dennis | 029c41b | 2013-10-29 17:44:09 +0200 | [diff] [blame] | 323 | uint16_t mask = (1 << i), |
Lior Barenboim | 69539fb | 2013-12-25 18:38:31 +0200 | [diff] [blame] | 324 | btn_state = !!(pe->buttons_state_bitmap & mask); |
| 325 | if (usf_info->req_buttons_bitmap & mask) |
Ravit Dennis | 029c41b | 2013-10-29 17:44:09 +0200 | [diff] [blame] | 326 | input_report_key(input_if, s_button_map[i], btn_state); |
| 327 | } |
| 328 | |
Baruch Eruchimovitch | cf5a4d1 | 2012-05-31 21:48:18 +0300 | [diff] [blame] | 329 | input_sync(input_if); |
| 330 | |
Lior Barenboim | 69539fb | 2013-12-25 18:38:31 +0200 | [diff] [blame] | 331 | pr_debug("%s: TSC event: xyz[%d;%d;%d], incl[%d;%d], pressure[%d], buttons[%d]\n", |
Baruch Eruchimovitch | cf5a4d1 | 2012-05-31 21:48:18 +0300 | [diff] [blame] | 332 | __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 Dennis | 029c41b | 2013-10-29 17:44:09 +0200 | [diff] [blame] | 338 | pe->pressure, |
Lior Barenboim | 69539fb | 2013-12-25 18:38:31 +0200 | [diff] [blame] | 339 | pe->buttons_state_bitmap); |
Baruch Eruchimovitch | cf5a4d1 | 2012-05-31 21:48:18 +0300 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | static 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 | |
| 367 | static 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 | |
| 383 | static 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 Dennis | 0c7e603 | 2013-10-01 17:26:48 +0300 | [diff] [blame] | 392 | {USF_TSC_EXT_EVENT, "usf_tsc_ext", |
| 393 | prepare_tsc_input_device, notify_tsc_event}, |
Baruch Eruchimovitch | cf5a4d1 | 2012-05-31 21:48:18 +0300 | [diff] [blame] | 394 | }; |
| 395 | |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 396 | static 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 Eruchimovitch | 258b347 | 2012-10-14 21:46:35 +0200 | [diff] [blame] | 407 | case Q6USM_EVENT_WRITE_DONE: |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 408 | wake_up(&usf_xx->wait); |
| 409 | break; |
Lior Barenboim | bfbed9c | 2014-03-20 14:56:01 +0200 | [diff] [blame^] | 410 | |
| 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 Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 417 | default: |
| 418 | break; |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | static 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 Eruchimovitch | 258b347 | 2012-10-14 21:46:35 +0200 | [diff] [blame] | 433 | case Q6USM_EVENT_READ_DONE: |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 434 | 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 Eruchimovitch | 258b347 | 2012-10-14 21:46:35 +0200 | [diff] [blame] | 440 | case Q6USM_EVENT_SIGNAL_DETECT_RESULT: |
Baruch Eruchimovitch | dac2474 | 2012-02-01 15:29:29 +0200 | [diff] [blame] | 441 | usf_xx->us_detect_type = (payload[APR_US_DETECT_RESULT_IND]) ? |
Baruch Eruchimovitch | 24dda6a | 2012-01-02 20:28:19 +0200 | [diff] [blame] | 442 | USF_US_DETECT_YES : |
| 443 | USF_US_DETECT_NO; |
| 444 | |
| 445 | wake_up(&usf_xx->wait); |
| 446 | break; |
| 447 | |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 448 | case APR_BASIC_RSP_RESULT: |
Baruch Eruchimovitch | dac2474 | 2012-02-01 15:29:29 +0200 | [diff] [blame] | 449 | if (payload[APR_RESULT_IND]) { |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 450 | 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 Barenboim | bfbed9c | 2014-03-20 14:56:01 +0200 | [diff] [blame^] | 456 | 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 Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 462 | default: |
| 463 | break; |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | static 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 | |
| 482 | static 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 | |
| 495 | static 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 Eruchimovitch | 64eb8da | 2013-04-08 14:33:17 +0300 | [diff] [blame] | 499 | uint16_t min_map_size = 0; |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 500 | |
| 501 | if ((usf_xx == NULL) || |
| 502 | (config == NULL)) |
| 503 | return -EINVAL; |
| 504 | |
Baruch Eruchimovitch | b4c3272 | 2013-10-14 15:49:41 +0300 | [diff] [blame] | 505 | 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 Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 514 | data_map_size = sizeof(usf_xx->encdec_cfg.cfg_common.data_map); |
Baruch Eruchimovitch | 64eb8da | 2013-04-08 14:33:17 +0300 | [diff] [blame] | 515 | min_map_size = min(data_map_size, config->port_cnt); |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 516 | |
| 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 Eruchimovitch | dac2474 | 2012-02-01 15:29:29 +0200 | [diff] [blame] | 526 | pr_debug("%s: name=%s; buf_size:%d; dev_id:0x%x; sample_rate:%d\n", |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 527 | __func__, usf_xx->client_name, config->buf_size, |
| 528 | config->dev_id, config->sample_rate); |
| 529 | |
Baruch Eruchimovitch | dac2474 | 2012-02-01 15:29:29 +0200 | [diff] [blame] | 530 | pr_debug("%s: buf_num:%d; format:%d; port_cnt:%d; data_size=%d\n", |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 531 | __func__, config->buf_num, config->stream_format, |
| 532 | config->port_cnt, config->params_data_size); |
| 533 | |
Ravit Dennis | 895a557 | 2013-06-05 16:34:42 +0300 | [diff] [blame] | 534 | pr_debug("%s: id[0]=%d, id[1]=%d, id[2]=%d, id[3]=%d, id[4]=%d,\n", |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 535 | __func__, |
| 536 | config->port_id[0], |
| 537 | config->port_id[1], |
| 538 | config->port_id[2], |
Baruch Eruchimovitch | 64eb8da | 2013-04-08 14:33:17 +0300 | [diff] [blame] | 539 | config->port_id[3], |
| 540 | config->port_id[4]); |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 541 | |
Ravit Dennis | 895a557 | 2013-06-05 16:34:42 +0300 | [diff] [blame] | 542 | 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 Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 547 | /* 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 Eruchimovitch | 64eb8da | 2013-04-08 14:33:17 +0300 | [diff] [blame] | 559 | min_map_size); |
| 560 | |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 561 | 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 Eruchimovitch | 24dda6a | 2012-01-02 20:28:19 +0200 | [diff] [blame] | 587 | return -EFAULT; |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 588 | } |
| 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 Eruchimovitch | 1221b85 | 2012-04-02 11:21:30 +0300 | [diff] [blame] | 609 | static 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 | |
| 622 | static 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 | |
| 640 | static 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 | |
| 652 | static 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 Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 667 | static int register_input_device(struct usf_type *usf_info, |
| 668 | struct us_input_info_type *input_info) |
| 669 | { |
| 670 | int rc = 0; |
Baruch Eruchimovitch | 1221b85 | 2012-04-02 11:21:30 +0300 | [diff] [blame] | 671 | bool ret = true; |
Baruch Eruchimovitch | cf5a4d1 | 2012-05-31 21:48:18 +0300 | [diff] [blame] | 672 | uint16_t ind = 0; |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 673 | |
| 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 Eruchimovitch | cf5a4d1 | 2012-05-31 21:48:18 +0300 | [diff] [blame] | 681 | 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 Eruchimovitch | dac2474 | 2012-02-01 15:29:29 +0200 | [diff] [blame] | 697 | |
Baruch Eruchimovitch | cf5a4d1 | 2012-05-31 21:48:18 +0300 | [diff] [blame] | 698 | 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 Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 721 | } |
| 722 | |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 723 | |
| 724 | static void handle_input_event(struct usf_type *usf_info, |
| 725 | uint16_t event_counter, |
| 726 | struct usf_event_type *event) |
| 727 | { |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 728 | uint16_t ind = 0; |
Baruch Eruchimovitch | 24dda6a | 2012-01-02 20:28:19 +0200 | [diff] [blame] | 729 | uint16_t events_num = 0; |
| 730 | struct usf_event_type usf_events[USF_EVENTS_PORTION_SIZE]; |
| 731 | int rc = 0; |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 732 | |
Baruch Eruchimovitch | cf5a4d1 | 2012-05-31 21:48:18 +0300 | [diff] [blame] | 733 | if ((usf_info == NULL) || |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 734 | (event == NULL) || (!event_counter)) { |
| 735 | return; |
| 736 | } |
| 737 | |
Baruch Eruchimovitch | 24dda6a | 2012-01-02 20:28:19 +0200 | [diff] [blame] | 738 | 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 Eruchimovitch | cf5a4d1 | 2012-05-31 21:48:18 +0300 | [diff] [blame] | 756 | 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 Eruchimovitch | 24dda6a | 2012-01-02 20:28:19 +0200 | [diff] [blame] | 767 | } /* loop in the portion */ |
| 768 | } /* all events loop */ |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | static 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 Eruchimovitch | 24dda6a | 2012-01-02 20:28:19 +0200 | [diff] [blame] | 777 | 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 Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 783 | |
Baruch Eruchimovitch | 24dda6a | 2012-01-02 20:28:19 +0200 | [diff] [blame] | 784 | 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 Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 791 | usf_xx->usf_state = |
| 792 | USF_WORK_STATE; |
| 793 | } |
| 794 | |
| 795 | return rc; |
| 796 | } /* usf_start_tx */ |
| 797 | |
| 798 | static 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 Eruchimovitch | 24dda6a | 2012-01-02 20:28:19 +0200 | [diff] [blame] | 810 | static 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 Eruchimovitch | b4c3272 | 2013-10-14 15:49:41 +0300 | [diff] [blame] | 814 | struct usm_session_cmd_detect_info *p_allocated_memory = NULL; |
Baruch Eruchimovitch | 24dda6a | 2012-01-02 20:28:19 +0200 | [diff] [blame] | 815 | 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 Eruchimovitch | b4c3272 | 2013-10-14 15:49:41 +0300 | [diff] [blame] | 841 | p_allocated_memory = kzalloc(detect_info_size, GFP_KERNEL); |
| 842 | if (p_allocated_memory == NULL) { |
Baruch Eruchimovitch | 24dda6a | 2012-01-02 20:28:19 +0200 | [diff] [blame] | 843 | pr_err("%s: detect_info[%d] allocation failed\n", |
| 844 | __func__, detect_info_size); |
| 845 | return -ENOMEM; |
| 846 | } |
Baruch Eruchimovitch | b4c3272 | 2013-10-14 15:49:41 +0300 | [diff] [blame] | 847 | p_usm_detect_info = p_allocated_memory; |
Baruch Eruchimovitch | 24dda6a | 2012-01-02 20:28:19 +0200 | [diff] [blame] | 848 | 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 Eruchimovitch | b4c3272 | 2013-10-14 15:49:41 +0300 | [diff] [blame] | 857 | kfree(p_allocated_memory); |
Baruch Eruchimovitch | 24dda6a | 2012-01-02 20:28:19 +0200 | [diff] [blame] | 858 | return -EFAULT; |
| 859 | } |
Baruch Eruchimovitch | dac2474 | 2012-02-01 15:29:29 +0200 | [diff] [blame] | 860 | p_usm_detect_info->algorithm_cfg_size = |
| 861 | detect_info.params_data_size; |
Baruch Eruchimovitch | 24dda6a | 2012-01-02 20:28:19 +0200 | [diff] [blame] | 862 | } 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 Eruchimovitch | b4c3272 | 2013-10-14 15:49:41 +0300 | [diff] [blame] | 874 | kfree(p_allocated_memory); |
Baruch Eruchimovitch | 24dda6a | 2012-01-02 20:28:19 +0200 | [diff] [blame] | 875 | return rc; |
| 876 | } |
| 877 | |
| 878 | /* Get US detection result */ |
| 879 | if (detect_info.detect_timeout == USF_INFINITIVE_TIMEOUT) { |
Baruch Eruchimovitch | d0c077f | 2012-05-03 18:38:34 +0300 | [diff] [blame] | 880 | rc = wait_event_interruptible(usf_xx->wait, |
| 881 | (usf_xx->us_detect_type != |
Lior Barenboim | bfbed9c | 2014-03-20 14:56:01 +0200 | [diff] [blame^] | 882 | USF_US_DETECT_UNDEF) || |
| 883 | (usf_xx->usf_state == |
| 884 | USF_ADSP_RESTART_STATE)); |
Baruch Eruchimovitch | 24dda6a | 2012-01-02 20:28:19 +0200 | [diff] [blame] | 885 | } 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 Eruchimovitch | d0c077f | 2012-05-03 18:38:34 +0300 | [diff] [blame] | 890 | } |
| 891 | rc = wait_event_interruptible_timeout(usf_xx->wait, |
Baruch Eruchimovitch | 24dda6a | 2012-01-02 20:28:19 +0200 | [diff] [blame] | 892 | (usf_xx->us_detect_type != |
Lior Barenboim | bfbed9c | 2014-03-20 14:56:01 +0200 | [diff] [blame^] | 893 | 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 Eruchimovitch | d0c077f | 2012-05-03 18:38:34 +0300 | [diff] [blame] | 901 | /* In the case of timeout, "no US" is assumed */ |
Baruch Eruchimovitch | b4c3272 | 2013-10-14 15:49:41 +0300 | [diff] [blame] | 902 | if (rc < 0) |
Baruch Eruchimovitch | d0c077f | 2012-05-03 18:38:34 +0300 | [diff] [blame] | 903 | pr_err("%s: Getting US detection failed rc[%d]\n", |
| 904 | __func__, rc); |
Baruch Eruchimovitch | b4c3272 | 2013-10-14 15:49:41 +0300 | [diff] [blame] | 905 | 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 Eruchimovitch | 24dda6a | 2012-01-02 20:28:19 +0200 | [diff] [blame] | 917 | } |
| 918 | |
Baruch Eruchimovitch | b4c3272 | 2013-10-14 15:49:41 +0300 | [diff] [blame] | 919 | kfree(p_allocated_memory); |
Baruch Eruchimovitch | 24dda6a | 2012-01-02 20:28:19 +0200 | [diff] [blame] | 920 | |
| 921 | return rc; |
| 922 | } /* usf_set_us_detection */ |
| 923 | |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 924 | static 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 Eruchimovitch | 24dda6a | 2012-01-02 20:28:19 +0200 | [diff] [blame] | 934 | pr_err("%s: copy config_tx from user; rc=%d\n", |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 935 | __func__, rc); |
Baruch Eruchimovitch | 24dda6a | 2012-01-02 20:28:19 +0200 | [diff] [blame] | 936 | return -EFAULT; |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 937 | } |
| 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 Eruchimovitch | 64eb8da | 2013-04-08 14:33:17 +0300 | [diff] [blame] | 971 | if (rc) { |
| 972 | (void)q6usm_cmd(usf_xx->usc, CMD_CLOSE); |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 973 | return rc; |
Baruch Eruchimovitch | 64eb8da | 2013-04-08 14:33:17 +0300 | [diff] [blame] | 974 | } |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 975 | |
| 976 | rc = q6usm_enc_cfg_blk(usf_xx->usc, |
| 977 | &usf_xx->encdec_cfg); |
Baruch Eruchimovitch | 24dda6a | 2012-01-02 20:28:19 +0200 | [diff] [blame] | 978 | if (!rc && |
| 979 | (config_tx.input_info.event_types != USF_NO_EVENT)) { |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 980 | rc = register_input_device(usf, |
| 981 | &config_tx.input_info); |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 982 | } |
| 983 | |
Baruch Eruchimovitch | 64eb8da | 2013-04-08 14:33:17 +0300 | [diff] [blame] | 984 | if (rc) |
| 985 | (void)q6usm_cmd(usf_xx->usc, CMD_CLOSE); |
| 986 | else |
Baruch Eruchimovitch | 24dda6a | 2012-01-02 20:28:19 +0200 | [diff] [blame] | 987 | usf_xx->usf_state = USF_CONFIGURED_STATE; |
| 988 | |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 989 | return rc; |
| 990 | } /* usf_set_tx_info */ |
| 991 | |
| 992 | static 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 Eruchimovitch | 24dda6a | 2012-01-02 20:28:19 +0200 | [diff] [blame] | 1001 | pr_err("%s: copy config_rx from user; rc=%d\n", |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 1002 | __func__, rc); |
Baruch Eruchimovitch | 24dda6a | 2012-01-02 20:28:19 +0200 | [diff] [blame] | 1003 | return -EFAULT; |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 1004 | } |
| 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 Eruchimovitch | b4c3272 | 2013-10-14 15:49:41 +0300 | [diff] [blame] | 1020 | 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 Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 1028 | } |
| 1029 | |
| 1030 | rc = q6usm_dec_cfg_blk(usf_xx->usc, |
| 1031 | &usf_xx->encdec_cfg); |
Baruch Eruchimovitch | 64eb8da | 2013-04-08 14:33:17 +0300 | [diff] [blame] | 1032 | if (rc) |
| 1033 | (void)q6usm_cmd(usf_xx->usc, CMD_CLOSE); |
| 1034 | else { |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 1035 | 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 | |
| 1043 | static 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 Eruchimovitch | 24dda6a | 2012-01-02 20:28:19 +0200 | [diff] [blame] | 1047 | uint32_t timeout = 0; |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 1048 | 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 Eruchimovitch | 24dda6a | 2012-01-02 20:28:19 +0200 | [diff] [blame] | 1053 | pr_err("%s: copy upd_tx_info from user; rc=%d\n", |
| 1054 | __func__, rc); |
| 1055 | return -EFAULT; |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | if (!usf_xx->user_upd_info_na) { |
Baruch Eruchimovitch | 1221b85 | 2012-04-02 11:21:30 +0300 | [diff] [blame] | 1059 | usf_set_event_filters(usf, upd_tx_info.event_filters); |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 1060 | 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 Eruchimovitch | 24dda6a | 2012-01-02 20:28:19 +0200 | [diff] [blame] | 1073 | if (upd_tx_info.timeout == USF_INFINITIVE_TIMEOUT) { |
Baruch Eruchimovitch | d0c077f | 2012-05-03 18:38:34 +0300 | [diff] [blame] | 1074 | rc = wait_event_interruptible(usf_xx->wait, |
Baruch Eruchimovitch | 24dda6a | 2012-01-02 20:28:19 +0200 | [diff] [blame] | 1075 | (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 Eruchimovitch | 24dda6a | 2012-01-02 20:28:19 +0200 | [diff] [blame] | 1083 | prev_jiffies = jiffies; |
Baruch Eruchimovitch | d0c077f | 2012-05-03 18:38:34 +0300 | [diff] [blame] | 1084 | if (upd_tx_info.timeout == USF_DEFAULT_TIMEOUT) { |
| 1085 | timeout = USF_TIMEOUT_JIFFIES; |
| 1086 | rc = wait_event_timeout( |
| 1087 | usf_xx->wait, |
Baruch Eruchimovitch | 24dda6a | 2012-01-02 20:28:19 +0200 | [diff] [blame] | 1088 | (usf_xx->prev_region != |
| 1089 | usf_xx->new_region) || |
| 1090 | (usf_xx->usf_state != |
| 1091 | USF_WORK_STATE), |
| 1092 | timeout); |
Baruch Eruchimovitch | d0c077f | 2012-05-03 18:38:34 +0300 | [diff] [blame] | 1093 | } 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 Eruchimovitch | 24dda6a | 2012-01-02 20:28:19 +0200 | [diff] [blame] | 1103 | } |
| 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 Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 1118 | } |
| 1119 | } |
| 1120 | |
Baruch Eruchimovitch | d0c077f | 2012-05-03 18:38:34 +0300 | [diff] [blame] | 1121 | if ((usf_xx->usf_state != USF_WORK_STATE) || |
| 1122 | (rc == -ERESTARTSYS)) { |
Baruch Eruchimovitch | 258b347 | 2012-10-14 21:46:35 +0200 | [diff] [blame] | 1123 | pr_err("%s: Get ready region failure; state[%d]; rc[%d]\n", |
Baruch Eruchimovitch | d0c077f | 2012-05-03 18:38:34 +0300 | [diff] [blame] | 1124 | __func__, usf_xx->usf_state, rc); |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 1125 | return -EINTR; |
| 1126 | } |
| 1127 | |
| 1128 | upd_tx_info.ready_region = usf_xx->new_region; |
Baruch Eruchimovitch | 24dda6a | 2012-01-02 20:28:19 +0200 | [diff] [blame] | 1129 | usf_xx->prev_region = upd_tx_info.ready_region; |
| 1130 | |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 1131 | 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 Eruchimovitch | 24dda6a | 2012-01-02 20:28:19 +0200 | [diff] [blame] | 1134 | return -EIO; |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 1135 | } |
Baruch Eruchimovitch | 24dda6a | 2012-01-02 20:28:19 +0200 | [diff] [blame] | 1136 | |
| 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 Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 1144 | |
| 1145 | return rc; |
| 1146 | } /* usf_get_tx_update */ |
| 1147 | |
| 1148 | static 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 Eruchimovitch | 24dda6a | 2012-01-02 20:28:19 +0200 | [diff] [blame] | 1155 | pr_err("%s: copy upd_rx_info from user; rc=%d\n", |
| 1156 | __func__, rc); |
| 1157 | return -EFAULT; |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 1158 | } |
| 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 Eruchimovitch | 24dda6a | 2012-01-02 20:28:19 +0200 | [diff] [blame] | 1190 | } else { |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 1191 | rc = copy_to_user( |
| 1192 | (void __user *)arg, |
| 1193 | &upd_rx_info, |
| 1194 | sizeof(upd_rx_info)); |
Baruch Eruchimovitch | 24dda6a | 2012-01-02 20:28:19 +0200 | [diff] [blame] | 1195 | if (rc) { |
| 1196 | pr_err("%s: copy rx_info to user; rc=%d\n", |
| 1197 | __func__, rc); |
| 1198 | rc = -EFAULT; |
| 1199 | } |
| 1200 | } |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 1201 | } |
| 1202 | |
| 1203 | return rc; |
| 1204 | } /* usf_set_rx_update */ |
| 1205 | |
Baruch Eruchimovitch | 1221b85 | 2012-04-02 11:21:30 +0300 | [diff] [blame] | 1206 | static void usf_release_input(struct usf_type *usf) |
| 1207 | { |
Baruch Eruchimovitch | cf5a4d1 | 2012-05-31 21:48:18 +0300 | [diff] [blame] | 1208 | uint16_t ind = 0; |
| 1209 | |
Baruch Eruchimovitch | 32b44a2 | 2012-07-24 15:42:59 +0300 | [diff] [blame] | 1210 | usf_unregister_conflicting_events( |
| 1211 | usf->conflicting_event_types); |
| 1212 | usf->conflicting_event_types = 0; |
Baruch Eruchimovitch | cf5a4d1 | 2012-05-31 21:48:18 +0300 | [diff] [blame] | 1213 | for (ind = 0; ind < USF_MAX_EVENT_IND; ++ind) { |
| 1214 | if (usf->input_ifs[ind] == NULL) |
| 1215 | continue; |
Baruch Eruchimovitch | cf5a4d1 | 2012-05-31 21:48:18 +0300 | [diff] [blame] | 1216 | 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 Eruchimovitch | 1221b85 | 2012-04-02 11:21:30 +0300 | [diff] [blame] | 1221 | } |
| 1222 | } /* usf_release_input */ |
| 1223 | |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 1224 | static int usf_stop_tx(struct usf_type *usf) |
| 1225 | { |
| 1226 | struct usf_xx_type *usf_xx = &usf->usf_tx; |
| 1227 | |
Baruch Eruchimovitch | 1221b85 | 2012-04-02 11:21:30 +0300 | [diff] [blame] | 1228 | usf_release_input(usf); |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 1229 | usf_disable(usf_xx); |
| 1230 | |
| 1231 | return 0; |
| 1232 | } /* usf_stop_tx */ |
| 1233 | |
Baruch Eruchimovitch | dac2474 | 2012-02-01 15:29:29 +0200 | [diff] [blame] | 1234 | static 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 Eruchimovitch | b4c3272 | 2013-10-14 15:49:41 +0300 | [diff] [blame] | 1246 | 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 Eruchimovitch | dac2474 | 2012-02-01 15:29:29 +0200 | [diff] [blame] | 1252 | rc = copy_to_user(version_info.pbuf, |
| 1253 | DRV_VERSION, |
Baruch Eruchimovitch | b4c3272 | 2013-10-14 15:49:41 +0300 | [diff] [blame] | 1254 | sizeof(DRV_VERSION)); |
Baruch Eruchimovitch | dac2474 | 2012-02-01 15:29:29 +0200 | [diff] [blame] | 1255 | 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 Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 1273 | static 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 Barenboim | bfbed9c | 2014-03-20 14:56:01 +0200 | [diff] [blame^] | 1361 | if ((usf_xx->usf_state == USF_WORK_STATE) |
| 1362 | || (usf_xx->usf_state == USF_ADSP_RESTART_STATE)) |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 1363 | 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 Barenboim | bfbed9c | 2014-03-20 14:56:01 +0200 | [diff] [blame^] | 1375 | if ((usf_xx->usf_state == USF_WORK_STATE) |
| 1376 | || (usf_xx->usf_state == USF_ADSP_RESTART_STATE)) |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 1377 | 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 Eruchimovitch | 24dda6a | 2012-01-02 20:28:19 +0200 | [diff] [blame] | 1387 | 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 Eruchimovitch | dac2474 | 2012-02-01 15:29:29 +0200 | [diff] [blame] | 1398 | } /* US_SET_DETECTION */ |
| 1399 | |
| 1400 | case US_GET_VERSION: { |
| 1401 | rc = usf_get_version(arg); |
| 1402 | break; |
| 1403 | } /* US_GET_VERSION */ |
Baruch Eruchimovitch | 24dda6a | 2012-01-02 20:28:19 +0200 | [diff] [blame] | 1404 | |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 1405 | default: |
Baruch Eruchimovitch | dac2474 | 2012-02-01 15:29:29 +0200 | [diff] [blame] | 1406 | pr_err("%s: unsupported IOCTL command [%d]\n", |
| 1407 | __func__, |
| 1408 | cmd); |
| 1409 | rc = -ENOTTY; |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 1410 | 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 | |
| 1421 | static 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 | |
| 1435 | static 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 Eruchimovitch | dac2474 | 2012-02-01 15:29:29 +0200 | [diff] [blame] | 1448 | pr_debug("%s: device %d is added; ind=%d\n", |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 1449 | __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 | |
| 1459 | static 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 Eruchimovitch | 24dda6a | 2012-01-02 20:28:19 +0200 | [diff] [blame] | 1481 | usf->usf_tx.us_detect_type = USF_US_DETECT_UNDEF; |
| 1482 | usf->usf_rx.us_detect_type = USF_US_DETECT_UNDEF; |
| 1483 | |
Baruch Eruchimovitch | dac2474 | 2012-02-01 15:29:29 +0200 | [diff] [blame] | 1484 | pr_debug("%s:usf in open\n", __func__); |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 1485 | return 0; |
| 1486 | } |
| 1487 | |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 1488 | static int usf_release(struct inode *inode, struct file *file) |
| 1489 | { |
| 1490 | struct usf_type *usf = file->private_data; |
| 1491 | |
Baruch Eruchimovitch | dac2474 | 2012-02-01 15:29:29 +0200 | [diff] [blame] | 1492 | pr_debug("%s: release entry\n", __func__); |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 1493 | |
Baruch Eruchimovitch | 1221b85 | 2012-04-02 11:21:30 +0300 | [diff] [blame] | 1494 | usf_release_input(usf); |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 1495 | |
| 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 Eruchimovitch | dac2474 | 2012-02-01 15:29:29 +0200 | [diff] [blame] | 1502 | pr_debug("%s: release exit\n", __func__); |
Baruch Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 1503 | return 0; |
| 1504 | } |
| 1505 | |
| 1506 | static 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 | |
| 1514 | struct miscdevice usf_misc[MAX_DEVS_NUMBER] = { |
| 1515 | { |
| 1516 | .minor = MISC_DYNAMIC_MINOR, |
| 1517 | .name = "usf1", |
| 1518 | .fops = &usf_fops, |
| 1519 | }, |
| 1520 | }; |
| 1521 | |
| 1522 | static int __init usf_init(void) |
| 1523 | { |
| 1524 | int rc = 0; |
| 1525 | uint16_t ind = 0; |
| 1526 | |
Baruch Eruchimovitch | dac2474 | 2012-02-01 15:29:29 +0200 | [diff] [blame] | 1527 | 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 Eruchimovitch | e9cbfc1 | 2011-10-09 19:47:08 +0200 | [diff] [blame] | 1529 | |
| 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 | |
| 1542 | device_initcall(usf_init); |
| 1543 | |
| 1544 | MODULE_DESCRIPTION("Ultrasound framework driver"); |