Meng Wang | 688a867 | 2019-01-29 13:43:33 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Meng Wang | 61af684 | 2018-09-10 17:47:55 +0800 | [diff] [blame] | 2 | /* |
Saurav Kumar | 9beffd7 | 2020-09-10 16:06:16 +0530 | [diff] [blame] | 3 | * Copyright (c) 2014, 2016-2017, 2020, The Linux Foundation. All rights reserved. |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 4 | */ |
| 5 | #include <linux/slab.h> |
| 6 | #include <linux/fs.h> |
| 7 | #include <linux/module.h> |
| 8 | #include <linux/miscdevice.h> |
| 9 | #include <linux/uaccess.h> |
| 10 | #include <linux/mutex.h> |
| 11 | #include <linux/msm_ion.h> |
Laxminath Kasam | 605b42f | 2017-08-01 22:02:15 +0530 | [diff] [blame] | 12 | #include <dsp/msm_audio_ion.h> |
| 13 | #include <dsp/audio_calibration.h> |
| 14 | #include <dsp/audio_cal_utils.h> |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 15 | |
| 16 | struct audio_cal_client_info { |
| 17 | struct list_head list; |
| 18 | struct audio_cal_callbacks *callbacks; |
| 19 | }; |
| 20 | |
| 21 | struct audio_cal_info { |
| 22 | struct mutex common_lock; |
| 23 | struct mutex cal_mutex[MAX_CAL_TYPES]; |
| 24 | struct list_head client_info[MAX_CAL_TYPES]; |
| 25 | int ref_count; |
| 26 | }; |
| 27 | |
| 28 | static struct audio_cal_info audio_cal; |
| 29 | |
| 30 | |
| 31 | static bool callbacks_are_equal(struct audio_cal_callbacks *callback1, |
| 32 | struct audio_cal_callbacks *callback2) |
| 33 | { |
| 34 | bool ret = true; |
| 35 | struct audio_cal_callbacks *call1 = callback1; |
| 36 | struct audio_cal_callbacks *call2 = callback2; |
| 37 | |
| 38 | pr_debug("%s\n", __func__); |
| 39 | |
| 40 | if ((call1 == NULL) && (call2 == NULL)) |
| 41 | ret = true; |
| 42 | else if ((call1 == NULL) || (call2 == NULL)) |
| 43 | ret = false; |
| 44 | else if ((call1->alloc != call2->alloc) || |
| 45 | (call1->dealloc != call2->dealloc) || |
| 46 | (call1->pre_cal != call2->pre_cal) || |
| 47 | (call1->set_cal != call2->set_cal) || |
| 48 | (call1->get_cal != call2->get_cal) || |
| 49 | (call1->post_cal != call2->post_cal)) |
| 50 | ret = false; |
| 51 | return ret; |
| 52 | } |
| 53 | |
| 54 | int audio_cal_deregister(int num_cal_types, |
| 55 | struct audio_cal_reg *reg_data) |
| 56 | { |
| 57 | int ret = 0; |
| 58 | int i = 0; |
| 59 | struct list_head *ptr, *next; |
| 60 | struct audio_cal_client_info *client_info_node = NULL; |
| 61 | |
| 62 | pr_debug("%s\n", __func__); |
| 63 | |
| 64 | if (reg_data == NULL) { |
| 65 | pr_err("%s: reg_data is NULL!\n", __func__); |
| 66 | ret = -EINVAL; |
| 67 | goto done; |
| 68 | } else if ((num_cal_types <= 0) || |
| 69 | (num_cal_types > MAX_CAL_TYPES)) { |
| 70 | pr_err("%s: num_cal_types of %d is Invalid!\n", |
| 71 | __func__, num_cal_types); |
| 72 | ret = -EINVAL; |
| 73 | goto done; |
| 74 | } |
| 75 | |
| 76 | for (; i < num_cal_types; i++) { |
| 77 | if ((reg_data[i].cal_type < 0) || |
| 78 | (reg_data[i].cal_type >= MAX_CAL_TYPES)) { |
| 79 | pr_err("%s: cal type %d at index %d is Invalid!\n", |
| 80 | __func__, reg_data[i].cal_type, i); |
| 81 | ret = -EINVAL; |
| 82 | continue; |
| 83 | } |
| 84 | |
| 85 | mutex_lock(&audio_cal.cal_mutex[reg_data[i].cal_type]); |
| 86 | list_for_each_safe(ptr, next, |
| 87 | &audio_cal.client_info[reg_data[i].cal_type]) { |
| 88 | |
| 89 | client_info_node = list_entry(ptr, |
| 90 | struct audio_cal_client_info, list); |
| 91 | if (callbacks_are_equal(client_info_node->callbacks, |
| 92 | ®_data[i].callbacks)) { |
| 93 | list_del(&client_info_node->list); |
| 94 | kfree(client_info_node->callbacks); |
| 95 | client_info_node->callbacks = NULL; |
| 96 | kfree(client_info_node); |
| 97 | client_info_node = NULL; |
| 98 | break; |
| 99 | } |
| 100 | } |
| 101 | mutex_unlock(&audio_cal.cal_mutex[reg_data[i].cal_type]); |
| 102 | } |
| 103 | done: |
| 104 | return ret; |
| 105 | } |
| 106 | |
| 107 | |
| 108 | int audio_cal_register(int num_cal_types, |
| 109 | struct audio_cal_reg *reg_data) |
| 110 | { |
| 111 | int ret = 0; |
| 112 | int i = 0; |
| 113 | struct audio_cal_client_info *client_info_node = NULL; |
| 114 | struct audio_cal_callbacks *callback_node = NULL; |
| 115 | |
| 116 | pr_debug("%s\n", __func__); |
| 117 | |
| 118 | if (reg_data == NULL) { |
| 119 | pr_err("%s: callbacks are NULL!\n", __func__); |
| 120 | ret = -EINVAL; |
| 121 | goto done; |
| 122 | } else if ((num_cal_types <= 0) || |
| 123 | (num_cal_types > MAX_CAL_TYPES)) { |
| 124 | pr_err("%s: num_cal_types of %d is Invalid!\n", |
| 125 | __func__, num_cal_types); |
| 126 | ret = -EINVAL; |
| 127 | goto done; |
| 128 | } |
| 129 | |
| 130 | for (; i < num_cal_types; i++) { |
| 131 | if ((reg_data[i].cal_type < 0) || |
| 132 | (reg_data[i].cal_type >= MAX_CAL_TYPES)) { |
| 133 | pr_err("%s: cal type %d at index %d is Invalid!\n", |
| 134 | __func__, reg_data[i].cal_type, i); |
| 135 | ret = -EINVAL; |
| 136 | goto err; |
| 137 | } |
| 138 | |
| 139 | client_info_node = kmalloc(sizeof(*client_info_node), |
| 140 | GFP_KERNEL); |
| 141 | if (client_info_node == NULL) { |
| 142 | ret = -ENOMEM; |
| 143 | goto err; |
| 144 | } |
| 145 | INIT_LIST_HEAD(&client_info_node->list); |
| 146 | |
| 147 | callback_node = kmalloc(sizeof(*callback_node), |
| 148 | GFP_KERNEL); |
| 149 | if (callback_node == NULL) { |
| 150 | ret = -ENOMEM; |
| 151 | goto err; |
| 152 | } |
| 153 | |
| 154 | memcpy(callback_node, ®_data[i].callbacks, |
| 155 | sizeof(*callback_node)); |
| 156 | client_info_node->callbacks = callback_node; |
| 157 | |
| 158 | mutex_lock(&audio_cal.cal_mutex[reg_data[i].cal_type]); |
| 159 | list_add_tail(&client_info_node->list, |
| 160 | &audio_cal.client_info[reg_data[i].cal_type]); |
| 161 | mutex_unlock(&audio_cal.cal_mutex[reg_data[i].cal_type]); |
| 162 | } |
| 163 | done: |
| 164 | return ret; |
| 165 | err: |
| 166 | audio_cal_deregister(num_cal_types, reg_data); |
| 167 | return ret; |
| 168 | } |
| 169 | |
| 170 | static int call_allocs(int32_t cal_type, |
| 171 | size_t cal_type_size, void *data) |
| 172 | { |
| 173 | int ret = 0; |
| 174 | int ret2 = 0; |
| 175 | struct list_head *ptr, *next; |
| 176 | struct audio_cal_client_info *client_info_node = NULL; |
| 177 | |
| 178 | pr_debug("%s\n", __func__); |
| 179 | |
| 180 | list_for_each_safe(ptr, next, |
| 181 | &audio_cal.client_info[cal_type]) { |
| 182 | |
| 183 | client_info_node = list_entry(ptr, |
| 184 | struct audio_cal_client_info, list); |
| 185 | |
| 186 | if (client_info_node->callbacks->alloc == NULL) |
| 187 | continue; |
| 188 | |
| 189 | ret2 = client_info_node->callbacks-> |
| 190 | alloc(cal_type, cal_type_size, data); |
| 191 | if (ret2 < 0) { |
| 192 | pr_err("%s: alloc failed!\n", __func__); |
| 193 | ret = ret2; |
| 194 | } |
| 195 | } |
| 196 | return ret; |
| 197 | } |
| 198 | |
| 199 | static int call_deallocs(int32_t cal_type, |
| 200 | size_t cal_type_size, void *data) |
| 201 | { |
| 202 | int ret = 0; |
| 203 | int ret2 = 0; |
| 204 | struct list_head *ptr, *next; |
| 205 | struct audio_cal_client_info *client_info_node = NULL; |
| 206 | |
| 207 | pr_debug("%s cal type %d\n", __func__, cal_type); |
| 208 | |
| 209 | list_for_each_safe(ptr, next, |
| 210 | &audio_cal.client_info[cal_type]) { |
| 211 | |
| 212 | client_info_node = list_entry(ptr, |
| 213 | struct audio_cal_client_info, list); |
| 214 | |
| 215 | if (client_info_node->callbacks->dealloc == NULL) |
| 216 | continue; |
| 217 | |
| 218 | ret2 = client_info_node->callbacks-> |
| 219 | dealloc(cal_type, cal_type_size, data); |
| 220 | if (ret2 < 0) { |
| 221 | pr_err("%s: dealloc failed!\n", __func__); |
| 222 | ret = ret2; |
| 223 | } |
| 224 | } |
| 225 | return ret; |
| 226 | } |
| 227 | |
| 228 | static int call_pre_cals(int32_t cal_type, |
| 229 | size_t cal_type_size, void *data) |
| 230 | { |
| 231 | int ret = 0; |
| 232 | int ret2 = 0; |
| 233 | struct list_head *ptr, *next; |
| 234 | struct audio_cal_client_info *client_info_node = NULL; |
| 235 | |
| 236 | pr_debug("%s cal type %d\n", __func__, cal_type); |
| 237 | |
| 238 | list_for_each_safe(ptr, next, |
| 239 | &audio_cal.client_info[cal_type]) { |
| 240 | |
| 241 | client_info_node = list_entry(ptr, |
| 242 | struct audio_cal_client_info, list); |
| 243 | |
| 244 | if (client_info_node->callbacks->pre_cal == NULL) |
| 245 | continue; |
| 246 | |
| 247 | ret2 = client_info_node->callbacks-> |
| 248 | pre_cal(cal_type, cal_type_size, data); |
| 249 | if (ret2 < 0) { |
| 250 | pr_err("%s: pre_cal failed!\n", __func__); |
| 251 | ret = ret2; |
| 252 | } |
| 253 | } |
| 254 | return ret; |
| 255 | } |
| 256 | |
| 257 | static int call_post_cals(int32_t cal_type, |
| 258 | size_t cal_type_size, void *data) |
| 259 | { |
| 260 | int ret = 0; |
| 261 | int ret2 = 0; |
| 262 | struct list_head *ptr, *next; |
| 263 | struct audio_cal_client_info *client_info_node = NULL; |
| 264 | |
| 265 | pr_debug("%s cal type %d\n", __func__, cal_type); |
| 266 | |
| 267 | list_for_each_safe(ptr, next, |
| 268 | &audio_cal.client_info[cal_type]) { |
| 269 | |
| 270 | client_info_node = list_entry(ptr, |
| 271 | struct audio_cal_client_info, list); |
| 272 | |
| 273 | if (client_info_node->callbacks->post_cal == NULL) |
| 274 | continue; |
| 275 | |
| 276 | ret2 = client_info_node->callbacks-> |
| 277 | post_cal(cal_type, cal_type_size, data); |
| 278 | if (ret2 < 0) { |
| 279 | pr_err("%s: post_cal failed!\n", __func__); |
| 280 | ret = ret2; |
| 281 | } |
| 282 | } |
| 283 | return ret; |
| 284 | } |
| 285 | |
| 286 | static int call_set_cals(int32_t cal_type, |
| 287 | size_t cal_type_size, void *data) |
| 288 | { |
| 289 | int ret = 0; |
| 290 | int ret2 = 0; |
| 291 | struct list_head *ptr, *next; |
| 292 | struct audio_cal_client_info *client_info_node = NULL; |
| 293 | |
| 294 | pr_debug("%s cal type %d\n", __func__, cal_type); |
| 295 | |
| 296 | list_for_each_safe(ptr, next, |
| 297 | &audio_cal.client_info[cal_type]) { |
| 298 | |
| 299 | client_info_node = list_entry(ptr, |
| 300 | struct audio_cal_client_info, list); |
| 301 | |
| 302 | if (client_info_node->callbacks->set_cal == NULL) |
| 303 | continue; |
| 304 | |
| 305 | ret2 = client_info_node->callbacks-> |
| 306 | set_cal(cal_type, cal_type_size, data); |
| 307 | if (ret2 < 0) { |
| 308 | pr_err("%s: set_cal failed!\n", __func__); |
| 309 | ret = ret2; |
| 310 | } |
| 311 | } |
| 312 | return ret; |
| 313 | } |
| 314 | |
| 315 | static int call_get_cals(int32_t cal_type, |
| 316 | size_t cal_type_size, void *data) |
| 317 | { |
| 318 | int ret = 0; |
| 319 | int ret2 = 0; |
| 320 | struct list_head *ptr, *next; |
| 321 | struct audio_cal_client_info *client_info_node = NULL; |
| 322 | |
| 323 | pr_debug("%s cal type %d\n", __func__, cal_type); |
| 324 | |
| 325 | list_for_each_safe(ptr, next, |
| 326 | &audio_cal.client_info[cal_type]) { |
| 327 | |
| 328 | client_info_node = list_entry(ptr, |
| 329 | struct audio_cal_client_info, list); |
| 330 | |
| 331 | if (client_info_node->callbacks->get_cal == NULL) |
| 332 | continue; |
| 333 | |
| 334 | ret2 = client_info_node->callbacks-> |
| 335 | get_cal(cal_type, cal_type_size, data); |
| 336 | if (ret2 < 0) { |
| 337 | pr_err("%s: get_cal failed!\n", __func__); |
| 338 | ret = ret2; |
| 339 | } |
| 340 | } |
| 341 | return ret; |
| 342 | } |
| 343 | |
| 344 | static int audio_cal_open(struct inode *inode, struct file *f) |
| 345 | { |
| 346 | int ret = 0; |
| 347 | |
| 348 | pr_debug("%s\n", __func__); |
| 349 | |
| 350 | mutex_lock(&audio_cal.common_lock); |
| 351 | audio_cal.ref_count++; |
| 352 | mutex_unlock(&audio_cal.common_lock); |
| 353 | |
| 354 | return ret; |
| 355 | } |
| 356 | |
| 357 | static void dealloc_all_clients(void) |
| 358 | { |
| 359 | int i = 0; |
| 360 | struct audio_cal_type_dealloc dealloc_data; |
| 361 | |
| 362 | pr_debug("%s\n", __func__); |
| 363 | |
| 364 | dealloc_data.cal_hdr.version = VERSION_0_0; |
| 365 | dealloc_data.cal_hdr.buffer_number = ALL_CAL_BLOCKS; |
| 366 | dealloc_data.cal_data.mem_handle = -1; |
| 367 | |
| 368 | for (; i < MAX_CAL_TYPES; i++) |
| 369 | call_deallocs(i, sizeof(dealloc_data), &dealloc_data); |
| 370 | } |
| 371 | |
| 372 | static int audio_cal_release(struct inode *inode, struct file *f) |
| 373 | { |
| 374 | int ret = 0; |
| 375 | |
| 376 | pr_debug("%s\n", __func__); |
| 377 | |
| 378 | mutex_lock(&audio_cal.common_lock); |
| 379 | audio_cal.ref_count--; |
| 380 | if (audio_cal.ref_count <= 0) { |
| 381 | audio_cal.ref_count = 0; |
| 382 | dealloc_all_clients(); |
| 383 | } |
| 384 | mutex_unlock(&audio_cal.common_lock); |
| 385 | |
| 386 | return ret; |
| 387 | } |
| 388 | |
| 389 | static long audio_cal_shared_ioctl(struct file *file, unsigned int cmd, |
| 390 | void __user *arg) |
| 391 | { |
| 392 | int ret = 0; |
| 393 | int32_t size; |
| 394 | struct audio_cal_basic *data = NULL; |
| 395 | |
| 396 | pr_debug("%s\n", __func__); |
| 397 | |
| 398 | switch (cmd) { |
| 399 | case AUDIO_ALLOCATE_CALIBRATION: |
| 400 | case AUDIO_DEALLOCATE_CALIBRATION: |
| 401 | case AUDIO_PREPARE_CALIBRATION: |
| 402 | case AUDIO_SET_CALIBRATION: |
| 403 | case AUDIO_GET_CALIBRATION: |
| 404 | case AUDIO_POST_CALIBRATION: |
| 405 | break; |
| 406 | default: |
| 407 | pr_err("%s: ioctl not found!\n", __func__); |
| 408 | ret = -EFAULT; |
| 409 | goto done; |
| 410 | } |
| 411 | |
| 412 | if (copy_from_user(&size, (void *)arg, sizeof(size))) { |
| 413 | pr_err("%s: Could not copy size value from user\n", __func__); |
| 414 | ret = -EFAULT; |
| 415 | goto done; |
| 416 | } else if ((size < sizeof(struct audio_cal_basic)) |
| 417 | || (size > MAX_IOCTL_CMD_SIZE)) { |
| 418 | pr_err("%s: Invalid size sent to driver: %d, max size is %d, min size is %zd\n", |
| 419 | __func__, size, MAX_IOCTL_CMD_SIZE, |
| 420 | sizeof(struct audio_cal_basic)); |
| 421 | ret = -EINVAL; |
| 422 | goto done; |
| 423 | } |
| 424 | |
| 425 | data = kmalloc(size, GFP_KERNEL); |
| 426 | if (data == NULL) { |
| 427 | ret = -ENOMEM; |
| 428 | goto done; |
| 429 | } else if (copy_from_user(data, (void *)arg, size)) { |
| 430 | pr_err("%s: Could not copy data from user\n", |
| 431 | __func__); |
| 432 | ret = -EFAULT; |
| 433 | goto done; |
| 434 | } else if ((data->hdr.cal_type < 0) || |
| 435 | (data->hdr.cal_type >= MAX_CAL_TYPES)) { |
| 436 | pr_err("%s: cal type %d is Invalid!\n", |
| 437 | __func__, data->hdr.cal_type); |
| 438 | ret = -EINVAL; |
| 439 | goto done; |
| 440 | } else if ((data->hdr.cal_type_size < |
| 441 | sizeof(struct audio_cal_type_basic)) || |
| 442 | (data->hdr.cal_type_size > |
| 443 | get_user_cal_type_size(data->hdr.cal_type))) { |
| 444 | pr_err("%s: cal type size %d is Invalid! Max is %zd!\n", |
| 445 | __func__, data->hdr.cal_type_size, |
| 446 | get_user_cal_type_size(data->hdr.cal_type)); |
| 447 | ret = -EINVAL; |
| 448 | goto done; |
| 449 | } else if (data->cal_type.cal_hdr.buffer_number < 0) { |
| 450 | pr_err("%s: cal type %d Invalid buffer number %d!\n", |
| 451 | __func__, data->hdr.cal_type, |
| 452 | data->cal_type.cal_hdr.buffer_number); |
| 453 | ret = -EINVAL; |
| 454 | goto done; |
Asish Bhattacharya | 84f7f73 | 2017-07-25 16:29:27 +0530 | [diff] [blame] | 455 | } else if ((data->hdr.cal_type_size + sizeof(data->hdr)) > size) { |
| 456 | pr_err("%s: cal type hdr size %zd + cal type size %d is greater than user buffer size %d\n", |
| 457 | __func__, sizeof(data->hdr), data->hdr.cal_type_size, |
| 458 | size); |
| 459 | ret = -EFAULT; |
| 460 | goto done; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | |
| 464 | mutex_lock(&audio_cal.cal_mutex[data->hdr.cal_type]); |
| 465 | |
| 466 | switch (cmd) { |
| 467 | case AUDIO_ALLOCATE_CALIBRATION: |
| 468 | ret = call_allocs(data->hdr.cal_type, |
| 469 | data->hdr.cal_type_size, &data->cal_type); |
| 470 | break; |
| 471 | case AUDIO_DEALLOCATE_CALIBRATION: |
| 472 | ret = call_deallocs(data->hdr.cal_type, |
| 473 | data->hdr.cal_type_size, &data->cal_type); |
| 474 | break; |
| 475 | case AUDIO_PREPARE_CALIBRATION: |
| 476 | ret = call_pre_cals(data->hdr.cal_type, |
| 477 | data->hdr.cal_type_size, &data->cal_type); |
| 478 | break; |
| 479 | case AUDIO_SET_CALIBRATION: |
| 480 | ret = call_set_cals(data->hdr.cal_type, |
| 481 | data->hdr.cal_type_size, &data->cal_type); |
| 482 | break; |
| 483 | case AUDIO_GET_CALIBRATION: |
| 484 | ret = call_get_cals(data->hdr.cal_type, |
| 485 | data->hdr.cal_type_size, &data->cal_type); |
| 486 | break; |
| 487 | case AUDIO_POST_CALIBRATION: |
| 488 | ret = call_post_cals(data->hdr.cal_type, |
| 489 | data->hdr.cal_type_size, &data->cal_type); |
| 490 | break; |
| 491 | } |
| 492 | |
| 493 | if (cmd == AUDIO_GET_CALIBRATION) { |
| 494 | if (data->hdr.cal_type_size == 0) |
| 495 | goto unlock; |
| 496 | if (data == NULL) |
| 497 | goto unlock; |
Asish Bhattacharya | 84f7f73 | 2017-07-25 16:29:27 +0530 | [diff] [blame] | 498 | if (copy_to_user(arg, data, |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 499 | sizeof(data->hdr) + data->hdr.cal_type_size)) { |
| 500 | pr_err("%s: Could not copy cal type to user\n", |
| 501 | __func__); |
| 502 | ret = -EFAULT; |
| 503 | goto unlock; |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | unlock: |
| 508 | mutex_unlock(&audio_cal.cal_mutex[data->hdr.cal_type]); |
| 509 | done: |
| 510 | kfree(data); |
| 511 | return ret; |
| 512 | } |
| 513 | |
| 514 | static long audio_cal_ioctl(struct file *f, |
| 515 | unsigned int cmd, unsigned long arg) |
| 516 | { |
| 517 | return audio_cal_shared_ioctl(f, cmd, (void __user *)arg); |
| 518 | } |
| 519 | |
| 520 | #ifdef CONFIG_COMPAT |
| 521 | |
| 522 | #define AUDIO_ALLOCATE_CALIBRATION32 _IOWR(CAL_IOCTL_MAGIC, \ |
| 523 | 200, compat_uptr_t) |
| 524 | #define AUDIO_DEALLOCATE_CALIBRATION32 _IOWR(CAL_IOCTL_MAGIC, \ |
| 525 | 201, compat_uptr_t) |
| 526 | #define AUDIO_PREPARE_CALIBRATION32 _IOWR(CAL_IOCTL_MAGIC, \ |
| 527 | 202, compat_uptr_t) |
| 528 | #define AUDIO_SET_CALIBRATION32 _IOWR(CAL_IOCTL_MAGIC, \ |
| 529 | 203, compat_uptr_t) |
| 530 | #define AUDIO_GET_CALIBRATION32 _IOWR(CAL_IOCTL_MAGIC, \ |
| 531 | 204, compat_uptr_t) |
| 532 | #define AUDIO_POST_CALIBRATION32 _IOWR(CAL_IOCTL_MAGIC, \ |
| 533 | 205, compat_uptr_t) |
| 534 | |
| 535 | static long audio_cal_compat_ioctl(struct file *f, |
| 536 | unsigned int cmd, unsigned long arg) |
| 537 | { |
| 538 | unsigned int cmd64; |
| 539 | int ret = 0; |
| 540 | |
| 541 | switch (cmd) { |
| 542 | case AUDIO_ALLOCATE_CALIBRATION32: |
| 543 | cmd64 = AUDIO_ALLOCATE_CALIBRATION; |
| 544 | break; |
| 545 | case AUDIO_DEALLOCATE_CALIBRATION32: |
| 546 | cmd64 = AUDIO_DEALLOCATE_CALIBRATION; |
| 547 | break; |
| 548 | case AUDIO_PREPARE_CALIBRATION32: |
| 549 | cmd64 = AUDIO_PREPARE_CALIBRATION; |
| 550 | break; |
| 551 | case AUDIO_SET_CALIBRATION32: |
| 552 | cmd64 = AUDIO_SET_CALIBRATION; |
| 553 | break; |
| 554 | case AUDIO_GET_CALIBRATION32: |
| 555 | cmd64 = AUDIO_GET_CALIBRATION; |
| 556 | break; |
| 557 | case AUDIO_POST_CALIBRATION32: |
| 558 | cmd64 = AUDIO_POST_CALIBRATION; |
| 559 | break; |
| 560 | default: |
| 561 | pr_err("%s: ioctl not found!\n", __func__); |
| 562 | ret = -EFAULT; |
| 563 | goto done; |
| 564 | } |
| 565 | |
| 566 | ret = audio_cal_shared_ioctl(f, cmd64, compat_ptr(arg)); |
| 567 | done: |
| 568 | return ret; |
| 569 | } |
| 570 | #endif |
| 571 | |
| 572 | static const struct file_operations audio_cal_fops = { |
| 573 | .owner = THIS_MODULE, |
| 574 | .open = audio_cal_open, |
| 575 | .release = audio_cal_release, |
| 576 | .unlocked_ioctl = audio_cal_ioctl, |
| 577 | #ifdef CONFIG_COMPAT |
| 578 | .compat_ioctl = audio_cal_compat_ioctl, |
| 579 | #endif |
| 580 | }; |
| 581 | |
| 582 | struct miscdevice audio_cal_misc = { |
| 583 | .minor = MISC_DYNAMIC_MINOR, |
| 584 | .name = "msm_audio_cal", |
| 585 | .fops = &audio_cal_fops, |
| 586 | }; |
| 587 | |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 588 | int __init audio_cal_init(void) |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 589 | { |
| 590 | int i = 0; |
| 591 | |
| 592 | pr_debug("%s\n", __func__); |
| 593 | |
Saurav Kumar | 9beffd7 | 2020-09-10 16:06:16 +0530 | [diff] [blame] | 594 | cal_utils_init(); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 595 | memset(&audio_cal, 0, sizeof(audio_cal)); |
| 596 | mutex_init(&audio_cal.common_lock); |
| 597 | for (; i < MAX_CAL_TYPES; i++) { |
| 598 | INIT_LIST_HEAD(&audio_cal.client_info[i]); |
| 599 | mutex_init(&audio_cal.cal_mutex[i]); |
| 600 | } |
| 601 | |
| 602 | return misc_register(&audio_cal_misc); |
| 603 | } |
| 604 | |
Asish Bhattacharya | 5faacb3 | 2017-12-04 17:23:15 +0530 | [diff] [blame] | 605 | void audio_cal_exit(void) |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 606 | { |
| 607 | int i = 0; |
| 608 | struct list_head *ptr, *next; |
| 609 | struct audio_cal_client_info *client_info_node; |
| 610 | |
| 611 | for (; i < MAX_CAL_TYPES; i++) { |
| 612 | list_for_each_safe(ptr, next, |
| 613 | &audio_cal.client_info[i]) { |
| 614 | client_info_node = list_entry(ptr, |
| 615 | struct audio_cal_client_info, list); |
| 616 | list_del(&client_info_node->list); |
| 617 | kfree(client_info_node->callbacks); |
| 618 | client_info_node->callbacks = NULL; |
| 619 | kfree(client_info_node); |
| 620 | client_info_node = NULL; |
| 621 | } |
| 622 | } |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 623 | misc_deregister(&audio_cal_misc); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 624 | } |
| 625 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 626 | |
| 627 | MODULE_DESCRIPTION("SoC QDSP6v2 Audio Calibration driver"); |
| 628 | MODULE_LICENSE("GPL v2"); |