Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 Google, Inc. |
Duy Truong | 790f06d | 2013-02-13 16:38:12 -0800 | [diff] [blame] | 3 | * Copyright (c) 2010-2011, The Linux Foundation. All rights reserved. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4 | * Author: Brian Swetland <swetland@google.com> |
| 5 | * |
| 6 | * This software is licensed under the terms of the GNU General Public |
| 7 | * License version 2, as published by the Free Software Foundation, and |
| 8 | * may be copied, distributed, and modified under those terms. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | */ |
| 16 | |
| 17 | #include <linux/slab.h> |
| 18 | #include <linux/mutex.h> |
| 19 | #include <linux/sched.h> |
| 20 | #include <linux/wait.h> |
| 21 | #include <linux/dma-mapping.h> |
| 22 | #include <linux/clk.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 23 | #include <linux/delay.h> |
| 24 | #include <linux/wakelock.h> |
| 25 | #include <linux/android_pmem.h> |
| 26 | #include <linux/firmware.h> |
| 27 | #include <linux/miscdevice.h> |
Stephen Boyd | 2fcabf9 | 2012-05-30 10:41:11 -0700 | [diff] [blame] | 28 | #include <linux/pm_qos.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 29 | |
| 30 | #include "dal.h" |
| 31 | #include "dal_audio.h" |
| 32 | #include "dal_audio_format.h" |
| 33 | #include "dal_acdb.h" |
| 34 | #include "dal_adie.h" |
| 35 | #include <mach/msm_qdsp6_audio.h> |
Stephen Boyd | 2fcabf9 | 2012-05-30 10:41:11 -0700 | [diff] [blame] | 36 | #include <mach/cpuidle.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 37 | |
| 38 | #include <linux/msm_audio_aac.h> |
| 39 | |
| 40 | #include <linux/gpio.h> |
| 41 | |
| 42 | #include "q6audio_devices.h" |
| 43 | #include <mach/debug_mm.h> |
| 44 | |
| 45 | |
| 46 | struct q6_hw_info { |
| 47 | int min_gain; |
| 48 | int max_gain; |
| 49 | }; |
| 50 | |
| 51 | /* TODO: provide mechanism to configure from board file */ |
| 52 | |
| 53 | static struct q6_hw_info q6_audio_hw[Q6_HW_COUNT] = { |
| 54 | [Q6_HW_HANDSET] = { |
| 55 | .min_gain = -400, |
| 56 | .max_gain = 1100, |
| 57 | }, |
| 58 | [Q6_HW_HEADSET] = { |
| 59 | .min_gain = -1100, |
| 60 | .max_gain = 400, |
| 61 | }, |
| 62 | [Q6_HW_SPEAKER] = { |
| 63 | .min_gain = -1000, |
| 64 | .max_gain = 500, |
| 65 | }, |
| 66 | [Q6_HW_TTY] = { |
| 67 | .min_gain = 0, |
| 68 | .max_gain = 0, |
| 69 | }, |
| 70 | [Q6_HW_BT_SCO] = { |
| 71 | .min_gain = -1100, |
| 72 | .max_gain = 400, |
| 73 | }, |
| 74 | [Q6_HW_BT_A2DP] = { |
| 75 | .min_gain = -1100, |
| 76 | .max_gain = 400, |
| 77 | }, |
| 78 | }; |
| 79 | |
| 80 | static struct wake_lock wakelock; |
Stephen Boyd | 2fcabf9 | 2012-05-30 10:41:11 -0700 | [diff] [blame] | 81 | static struct pm_qos_request pm_qos_req; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 82 | static int idlecount; |
| 83 | static DEFINE_MUTEX(idlecount_lock); |
| 84 | |
| 85 | void audio_prevent_sleep(void) |
| 86 | { |
| 87 | mutex_lock(&idlecount_lock); |
| 88 | if (++idlecount == 1) { |
| 89 | wake_lock(&wakelock); |
Stephen Boyd | 2fcabf9 | 2012-05-30 10:41:11 -0700 | [diff] [blame] | 90 | pm_qos_update_request(&pm_qos_req, |
| 91 | msm_cpuidle_get_deep_idle_latency()); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 92 | } |
| 93 | mutex_unlock(&idlecount_lock); |
| 94 | } |
| 95 | |
| 96 | void audio_allow_sleep(void) |
| 97 | { |
| 98 | mutex_lock(&idlecount_lock); |
| 99 | if (--idlecount == 0) { |
Stephen Boyd | 2fcabf9 | 2012-05-30 10:41:11 -0700 | [diff] [blame] | 100 | pm_qos_update_request(&pm_qos_req, PM_QOS_DEFAULT_VALUE); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 101 | wake_unlock(&wakelock); |
| 102 | } |
| 103 | mutex_unlock(&idlecount_lock); |
| 104 | } |
| 105 | |
| 106 | static struct clk *icodec_rx_clk; |
| 107 | static struct clk *icodec_tx_clk; |
| 108 | static struct clk *ecodec_clk; |
| 109 | static struct clk *sdac_clk; |
| 110 | |
| 111 | static struct q6audio_analog_ops default_analog_ops; |
| 112 | static struct q6audio_analog_ops *analog_ops = &default_analog_ops; |
| 113 | static uint32_t tx_clk_freq = 8000; |
| 114 | static int tx_mute_status = 0; |
| 115 | static int rx_vol_level = 100; |
| 116 | static uint32_t tx_acdb = 0; |
| 117 | static uint32_t rx_acdb = 0; |
| 118 | |
| 119 | void q6audio_register_analog_ops(struct q6audio_analog_ops *ops) |
| 120 | { |
| 121 | analog_ops = ops; |
| 122 | } |
| 123 | |
| 124 | static struct q6_device_info *q6_lookup_device(uint32_t device_id, |
| 125 | uint32_t acdb_id) |
| 126 | { |
| 127 | struct q6_device_info *di = q6_audio_devices; |
| 128 | |
| 129 | pr_debug("[%s:%s] device_id = 0x%x, acdb_id = %d\n", __MM_FILE__, |
| 130 | __func__, device_id, acdb_id); |
| 131 | if (acdb_id) { |
| 132 | for (;;) { |
| 133 | if (di->cad_id == acdb_id && di->id == device_id) |
| 134 | return di; |
| 135 | if (di->id == 0) { |
| 136 | pr_err("[%s:%s] bogus id 0x%08x\n", |
| 137 | __MM_FILE__, __func__, device_id); |
| 138 | return di; |
| 139 | } |
| 140 | di++; |
| 141 | } |
| 142 | } else { |
| 143 | for (;;) { |
| 144 | if (di->id == device_id) |
| 145 | return di; |
| 146 | if (di->id == 0) { |
| 147 | pr_err("[%s:%s] bogus id 0x%08x\n", |
| 148 | __MM_FILE__, __func__, device_id); |
| 149 | return di; |
| 150 | } |
| 151 | di++; |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | static uint32_t q6_device_to_codec(uint32_t device_id) |
| 157 | { |
| 158 | struct q6_device_info *di = q6_lookup_device(device_id, 0); |
| 159 | return di->codec; |
| 160 | } |
| 161 | |
| 162 | static uint32_t q6_device_to_dir(uint32_t device_id) |
| 163 | { |
| 164 | struct q6_device_info *di = q6_lookup_device(device_id, 0); |
| 165 | return di->dir; |
| 166 | } |
| 167 | |
| 168 | static uint32_t q6_device_to_cad_id(uint32_t device_id) |
| 169 | { |
| 170 | struct q6_device_info *di = q6_lookup_device(device_id, 0); |
| 171 | return di->cad_id; |
| 172 | } |
| 173 | |
| 174 | static uint32_t q6_device_to_path(uint32_t device_id, uint32_t acdb_id) |
| 175 | { |
| 176 | struct q6_device_info *di = q6_lookup_device(device_id, acdb_id); |
| 177 | return di->path; |
| 178 | } |
| 179 | |
| 180 | static uint32_t q6_device_to_rate(uint32_t device_id) |
| 181 | { |
| 182 | struct q6_device_info *di = q6_lookup_device(device_id, 0); |
| 183 | return di->rate; |
| 184 | } |
| 185 | |
| 186 | int q6_device_volume(uint32_t device_id, int level) |
| 187 | { |
| 188 | struct q6_device_info *di = q6_lookup_device(device_id, 0); |
| 189 | struct q6_hw_info *hw; |
| 190 | |
| 191 | hw = &q6_audio_hw[di->hw]; |
| 192 | |
| 193 | return hw->min_gain + ((hw->max_gain - hw->min_gain) * level) / 100; |
| 194 | } |
| 195 | |
| 196 | static inline int adie_open(struct dal_client *client) |
| 197 | { |
| 198 | pr_debug("[%s:%s]\n", __MM_FILE__, __func__); |
| 199 | return dal_call_f0(client, DAL_OP_OPEN, 0); |
| 200 | } |
| 201 | |
| 202 | static inline int adie_close(struct dal_client *client) |
| 203 | { |
| 204 | pr_debug("[%s:%s]\n", __MM_FILE__, __func__); |
| 205 | return dal_call_f0(client, DAL_OP_CLOSE, 0); |
| 206 | } |
| 207 | |
| 208 | static inline int adie_set_path(struct dal_client *client, |
| 209 | uint32_t id, uint32_t path_type) |
| 210 | { |
| 211 | pr_debug("[%s:%s] id = 0x%x, path_type = %d\n", __MM_FILE__, |
| 212 | __func__, id, path_type); |
| 213 | return dal_call_f1(client, ADIE_OP_SET_PATH, id, path_type); |
| 214 | } |
| 215 | |
| 216 | static inline int adie_set_path_freq_plan(struct dal_client *client, |
| 217 | uint32_t path_type, uint32_t plan) |
| 218 | { |
| 219 | pr_debug("[%s:%s] path_type = %d, plan = %d\n", __MM_FILE__, |
| 220 | __func__, path_type, plan); |
| 221 | return dal_call_f1(client, ADIE_OP_SET_PATH_FREQUENCY_PLAN, |
| 222 | path_type, plan); |
| 223 | } |
| 224 | |
| 225 | static inline int adie_proceed_to_stage(struct dal_client *client, |
| 226 | uint32_t path_type, uint32_t stage) |
| 227 | { |
| 228 | pr_debug("[%s:%s] path_type = %d, stage = 0x%x\n", __MM_FILE__, |
| 229 | __func__, path_type, stage); |
| 230 | return dal_call_f1(client, ADIE_OP_PROCEED_TO_STAGE, |
| 231 | path_type, stage); |
| 232 | } |
| 233 | |
| 234 | static inline int adie_mute_path(struct dal_client *client, |
| 235 | uint32_t path_type, uint32_t mute_state) |
| 236 | { |
| 237 | pr_debug("[%s:%s] path_type = %d, mute = %d\n", __MM_FILE__, __func__, |
| 238 | path_type, mute_state); |
| 239 | return dal_call_f1(client, ADIE_OP_MUTE_PATH, path_type, mute_state); |
| 240 | } |
| 241 | |
| 242 | static int adie_refcount; |
| 243 | |
| 244 | static struct dal_client *adie; |
| 245 | static struct dal_client *adsp; |
| 246 | static struct dal_client *acdb; |
| 247 | |
| 248 | static int adie_enable(void) |
| 249 | { |
| 250 | adie_refcount++; |
| 251 | if (adie_refcount == 1) |
| 252 | adie_open(adie); |
| 253 | return 0; |
| 254 | } |
| 255 | |
| 256 | static int adie_disable(void) |
| 257 | { |
| 258 | adie_refcount--; |
| 259 | if (adie_refcount == 0) |
| 260 | adie_close(adie); |
| 261 | return 0; |
| 262 | } |
| 263 | |
| 264 | /* 4k PMEM used for exchanging acdb device config tables |
| 265 | * and stream format descriptions with the DSP. |
| 266 | */ |
| 267 | static char *audio_data; |
| 268 | static int32_t audio_phys; |
| 269 | |
| 270 | #define SESSION_MIN 0 |
| 271 | #define SESSION_MAX 64 |
| 272 | |
| 273 | static DEFINE_MUTEX(session_lock); |
| 274 | static DEFINE_MUTEX(audio_lock); |
| 275 | |
| 276 | static struct audio_client *session[SESSION_MAX]; |
| 277 | |
| 278 | static int session_alloc(struct audio_client *ac) |
| 279 | { |
| 280 | int n; |
| 281 | |
| 282 | mutex_lock(&session_lock); |
| 283 | for (n = SESSION_MIN; n < SESSION_MAX; n++) { |
| 284 | if (!session[n]) { |
| 285 | session[n] = ac; |
| 286 | mutex_unlock(&session_lock); |
| 287 | pr_debug("[%s:%s] session = %d\n", __MM_FILE__, |
| 288 | __func__, n); |
| 289 | return n; |
| 290 | } |
| 291 | } |
| 292 | mutex_unlock(&session_lock); |
| 293 | return -ENOMEM; |
| 294 | } |
| 295 | |
| 296 | static void session_free(int n, struct audio_client *ac) |
| 297 | { |
| 298 | mutex_lock(&session_lock); |
| 299 | if (session[n] == ac) { |
| 300 | session[n] = 0; |
| 301 | pr_debug("[%s:%s] session = %d\n", __MM_FILE__, __func__, n); |
| 302 | } |
| 303 | mutex_unlock(&session_lock); |
| 304 | } |
| 305 | |
| 306 | static void audio_client_free(struct audio_client *ac) |
| 307 | { |
| 308 | pr_debug("[%s:%s] ac = %p\n", __MM_FILE__, __func__, ac); |
| 309 | session_free(ac->session, ac); |
| 310 | |
| 311 | if (ac->buf[0].data) { |
| 312 | iounmap(ac->buf[0].data); |
| 313 | pmem_kfree(ac->buf[0].phys); |
| 314 | } |
| 315 | if (ac->buf[1].data) { |
| 316 | iounmap(ac->buf[1].data); |
| 317 | pmem_kfree(ac->buf[1].phys); |
| 318 | } |
| 319 | kfree(ac); |
| 320 | } |
| 321 | |
| 322 | static struct audio_client *audio_client_alloc(unsigned bufsz) |
| 323 | { |
| 324 | struct audio_client *ac; |
| 325 | int n; |
| 326 | |
| 327 | pr_debug("[%s:%s] bufsz = %d\n", __MM_FILE__, __func__, bufsz); |
| 328 | ac = kzalloc(sizeof(*ac), GFP_KERNEL); |
| 329 | if (!ac) |
| 330 | return 0; |
| 331 | |
| 332 | n = session_alloc(ac); |
| 333 | if (n < 0) |
| 334 | goto fail_session; |
| 335 | ac->session = n; |
| 336 | |
| 337 | if (bufsz > 0) { |
| 338 | ac->buf[0].phys = pmem_kalloc(bufsz, |
| 339 | PMEM_MEMTYPE_EBI1|PMEM_ALIGNMENT_4K); |
| 340 | ac->buf[0].data = ioremap(ac->buf[0].phys, bufsz); |
| 341 | if (!ac->buf[0].data) |
| 342 | goto fail; |
| 343 | ac->buf[1].phys = pmem_kalloc(bufsz, |
| 344 | PMEM_MEMTYPE_EBI1|PMEM_ALIGNMENT_4K); |
| 345 | ac->buf[1].data = ioremap(ac->buf[1].phys, bufsz); |
| 346 | if (!ac->buf[1].data) |
| 347 | goto fail; |
| 348 | |
| 349 | ac->buf[0].size = bufsz; |
| 350 | ac->buf[1].size = bufsz; |
| 351 | } |
| 352 | |
| 353 | init_waitqueue_head(&ac->wait); |
| 354 | ac->client = adsp; |
| 355 | |
| 356 | return ac; |
| 357 | |
| 358 | fail: |
| 359 | session_free(n, ac); |
| 360 | fail_session: |
| 361 | audio_client_free(ac); |
| 362 | return 0; |
| 363 | } |
| 364 | |
| 365 | void audio_client_dump(struct audio_client *ac) |
| 366 | { |
| 367 | dal_trace_dump(ac->client); |
| 368 | } |
| 369 | |
| 370 | static int audio_ioctl(struct audio_client *ac, void *ptr, uint32_t len) |
| 371 | { |
| 372 | struct adsp_command_hdr *hdr = ptr; |
| 373 | uint32_t tmp; |
| 374 | int r; |
| 375 | |
| 376 | hdr->size = len - sizeof(u32); |
| 377 | hdr->dst = AUDIO_ADDR(ac->session, 0, AUDIO_DOMAIN_DSP); |
| 378 | hdr->src = AUDIO_ADDR(ac->session, 0, AUDIO_DOMAIN_APP); |
| 379 | hdr->context = ac->session; |
| 380 | ac->cb_status = -EBUSY; |
| 381 | r = dal_call(ac->client, AUDIO_OP_CONTROL, 5, ptr, len, &tmp, sizeof(tmp)); |
| 382 | if (r != 4) |
| 383 | return -EIO; |
| 384 | if (!wait_event_timeout(ac->wait, (ac->cb_status != -EBUSY), 5*HZ)) { |
| 385 | dal_trace_dump(ac->client); |
| 386 | pr_err("[%s:%s] timeout. dsp dead?\n", __MM_FILE__, __func__); |
| 387 | q6audio_dsp_not_responding(); |
| 388 | } |
| 389 | return ac->cb_status; |
| 390 | } |
| 391 | |
| 392 | static int audio_command(struct audio_client *ac, uint32_t cmd) |
| 393 | { |
| 394 | struct adsp_command_hdr rpc; |
| 395 | memset(&rpc, 0, sizeof(rpc)); |
| 396 | rpc.opcode = cmd; |
| 397 | return audio_ioctl(ac, &rpc, sizeof(rpc)); |
| 398 | } |
| 399 | |
| 400 | static int audio_open_control(struct audio_client *ac) |
| 401 | { |
| 402 | struct adsp_open_command rpc; |
| 403 | |
| 404 | pr_debug("[%s:%s] ac = %p\n", __MM_FILE__, __func__, ac); |
| 405 | memset(&rpc, 0, sizeof(rpc)); |
| 406 | rpc.hdr.opcode = ADSP_AUDIO_IOCTL_CMD_OPEN_DEVICE; |
| 407 | return audio_ioctl(ac, &rpc, sizeof(rpc)); |
| 408 | } |
| 409 | |
| 410 | static int audio_out_open(struct audio_client *ac, uint32_t bufsz, |
| 411 | uint32_t rate, uint32_t channels) |
| 412 | { |
| 413 | struct adsp_open_command rpc; |
| 414 | |
| 415 | memset(&rpc, 0, sizeof(rpc)); |
| 416 | |
| 417 | rpc.format.standard.format = ADSP_AUDIO_FORMAT_PCM; |
| 418 | rpc.format.standard.channels = channels; |
| 419 | rpc.format.standard.bits_per_sample = 16; |
| 420 | rpc.format.standard.sampling_rate = rate; |
| 421 | rpc.format.standard.is_signed = 1; |
| 422 | rpc.format.standard.is_interleaved = 1; |
| 423 | |
| 424 | rpc.hdr.opcode = ADSP_AUDIO_IOCTL_CMD_OPEN_WRITE; |
| 425 | rpc.device = ADSP_AUDIO_DEVICE_ID_DEFAULT; |
| 426 | rpc.stream_context = ADSP_AUDIO_DEVICE_CONTEXT_PLAYBACK; |
| 427 | rpc.buf_max_size = bufsz; |
| 428 | |
| 429 | pr_debug("[%s:%s]ac = %p\n", __MM_FILE__, __func__, ac); |
| 430 | return audio_ioctl(ac, &rpc, sizeof(rpc)); |
| 431 | } |
| 432 | |
| 433 | static int audio_in_open(struct audio_client *ac, uint32_t bufsz, |
| 434 | uint32_t flags, uint32_t rate, uint32_t channels) |
| 435 | { |
| 436 | struct adsp_open_command rpc; |
| 437 | |
| 438 | memset(&rpc, 0, sizeof(rpc)); |
| 439 | |
| 440 | rpc.format.standard.format = ADSP_AUDIO_FORMAT_PCM; |
| 441 | rpc.format.standard.channels = channels; |
| 442 | rpc.format.standard.bits_per_sample = 16; |
| 443 | rpc.format.standard.sampling_rate = rate; |
| 444 | rpc.format.standard.is_signed = 1; |
| 445 | rpc.format.standard.is_interleaved = 1; |
| 446 | |
| 447 | rpc.hdr.opcode = ADSP_AUDIO_IOCTL_CMD_OPEN_READ; |
| 448 | rpc.device = ADSP_AUDIO_DEVICE_ID_DEFAULT; |
| 449 | if (flags == AUDIO_FLAG_READ) |
| 450 | rpc.stream_context = ADSP_AUDIO_DEVICE_CONTEXT_RECORD; |
| 451 | else |
| 452 | rpc.stream_context = ADSP_AUDIO_DEVICE_CONTEXT_MIXED_RECORD; |
| 453 | |
| 454 | rpc.buf_max_size = bufsz; |
| 455 | |
| 456 | pr_debug("[%s:%s] ac = %p\n", __MM_FILE__, __func__, ac); |
| 457 | return audio_ioctl(ac, &rpc, sizeof(rpc)); |
| 458 | } |
| 459 | |
| 460 | static int audio_auxpcm_out_open(struct audio_client *ac, |
| 461 | uint32_t rate, uint32_t channels) |
| 462 | { |
| 463 | struct adsp_open_command rpc; |
| 464 | |
| 465 | memset(&rpc, 0, sizeof(rpc)); |
| 466 | |
| 467 | rpc.format.standard.format = ADSP_AUDIO_FORMAT_PCM; |
| 468 | rpc.format.standard.channels = channels; |
| 469 | rpc.format.standard.bits_per_sample = 16; |
| 470 | rpc.format.standard.sampling_rate = rate; |
| 471 | rpc.format.standard.is_signed = 1; |
| 472 | rpc.format.standard.is_interleaved = 1; |
| 473 | |
| 474 | rpc.hdr.opcode = ADSP_AUDIO_IOCTL_CMD_OPEN_READ; |
| 475 | rpc.device = ADSP_AUDIO_DEVICE_ID_DEFAULT; |
| 476 | rpc.mode = ADSP_AUDIO_OPEN_STREAM_MODE_AUX_PCM; |
| 477 | rpc.stream_context = ADSP_AUDIO_DEVICE_CONTEXT_RECORD; |
| 478 | |
| 479 | pr_debug("[%s:%s] ac = %p\n", __MM_FILE__, __func__, ac); |
| 480 | return audio_ioctl(ac, &rpc, sizeof(rpc)); |
| 481 | } |
| 482 | |
| 483 | static int audio_auxpcm_in_open(struct audio_client *ac, uint32_t rate, |
| 484 | uint32_t channels) |
| 485 | { |
| 486 | struct adsp_open_command rpc; |
| 487 | |
| 488 | memset(&rpc, 0, sizeof(rpc)); |
| 489 | |
| 490 | rpc.format.standard.format = ADSP_AUDIO_FORMAT_PCM; |
| 491 | rpc.format.standard.channels = channels; |
| 492 | rpc.format.standard.bits_per_sample = 16; |
| 493 | rpc.format.standard.sampling_rate = rate; |
| 494 | rpc.format.standard.is_signed = 1; |
| 495 | rpc.format.standard.is_interleaved = 1; |
| 496 | |
| 497 | rpc.hdr.opcode = ADSP_AUDIO_IOCTL_CMD_OPEN_WRITE; |
| 498 | rpc.device = ADSP_AUDIO_DEVICE_ID_DEFAULT; |
| 499 | rpc.mode = ADSP_AUDIO_OPEN_STREAM_MODE_AUX_PCM; |
| 500 | rpc.stream_context = ADSP_AUDIO_DEVICE_CONTEXT_PLAYBACK; |
| 501 | |
| 502 | pr_debug("[%s:%s] ac = %p\n", __MM_FILE__, __func__, ac); |
| 503 | return audio_ioctl(ac, &rpc, sizeof(rpc)); |
| 504 | } |
| 505 | |
| 506 | static int audio_mp3_open(struct audio_client *ac, uint32_t bufsz, |
| 507 | uint32_t rate, uint32_t channels) |
| 508 | { |
| 509 | struct adsp_open_command rpc; |
| 510 | |
| 511 | memset(&rpc, 0, sizeof(rpc)); |
| 512 | |
| 513 | rpc.format.standard.format = ADSP_AUDIO_FORMAT_MP3; |
| 514 | rpc.format.standard.channels = channels; |
| 515 | rpc.format.standard.bits_per_sample = 16; |
| 516 | rpc.format.standard.sampling_rate = rate; |
| 517 | rpc.format.standard.is_signed = 1; |
| 518 | rpc.format.standard.is_interleaved = 0; |
| 519 | |
| 520 | rpc.hdr.opcode = ADSP_AUDIO_IOCTL_CMD_OPEN_WRITE; |
| 521 | rpc.device = ADSP_AUDIO_DEVICE_ID_DEFAULT; |
| 522 | rpc.stream_context = ADSP_AUDIO_DEVICE_CONTEXT_PLAYBACK; |
| 523 | rpc.buf_max_size = bufsz; |
| 524 | |
| 525 | pr_debug("[%s:%s] ac = %p\n", __MM_FILE__, __func__, ac); |
| 526 | return audio_ioctl(ac, &rpc, sizeof(rpc)); |
| 527 | } |
| 528 | |
| 529 | static int audio_dtmf_open(struct audio_client *ac, |
| 530 | uint32_t rate, uint32_t channels) |
| 531 | { |
| 532 | struct adsp_open_command rpc; |
| 533 | |
| 534 | memset(&rpc, 0, sizeof(rpc)); |
| 535 | |
| 536 | rpc.format.standard.format = ADSP_AUDIO_FORMAT_DTMF; |
| 537 | rpc.format.standard.channels = channels; |
| 538 | rpc.format.standard.bits_per_sample = 16; |
| 539 | rpc.format.standard.sampling_rate = rate; |
| 540 | rpc.format.standard.is_signed = 1; |
| 541 | rpc.format.standard.is_interleaved = 0; |
| 542 | |
| 543 | rpc.hdr.opcode = ADSP_AUDIO_IOCTL_CMD_OPEN_WRITE; |
| 544 | rpc.device = ADSP_AUDIO_DEVICE_ID_DEFAULT; |
| 545 | rpc.stream_context = ADSP_AUDIO_DEVICE_CONTEXT_PLAYBACK; |
| 546 | |
| 547 | pr_debug("[%s:%s] ac = %p\n", __MM_FILE__, __func__, ac); |
| 548 | return audio_ioctl(ac, &rpc, sizeof(rpc)); |
| 549 | } |
| 550 | |
| 551 | static int audio_aac_open(struct audio_client *ac, uint32_t bufsz, |
| 552 | uint32_t sample_rate, uint32_t channels, |
| 553 | uint32_t bit_rate, uint32_t flags, |
| 554 | uint32_t stream_format) |
| 555 | { |
| 556 | struct adsp_open_command rpc; |
| 557 | int audio_object_type; |
| 558 | int index = sizeof(u32); |
| 559 | u32 *aac_type = NULL; |
| 560 | |
| 561 | memset(&rpc, 0, sizeof(rpc)); |
| 562 | |
| 563 | rpc.format.binary.format = ADSP_AUDIO_FORMAT_MPEG4_AAC; |
| 564 | /* only 48k sample rate is supported */ |
| 565 | sample_rate = 3; |
| 566 | /* AAC OBJECT LC */ |
| 567 | audio_object_type = 2; |
| 568 | |
| 569 | aac_type = (u32 *)rpc.format.binary.data; |
| 570 | switch (stream_format) { |
| 571 | case AUDIO_AAC_FORMAT_ADTS: |
| 572 | /* AAC Encoder expect MPEG4_ADTS media type */ |
| 573 | *aac_type = ADSP_AUDIO_AAC_MPEG4_ADTS; |
| 574 | break; |
| 575 | case AUDIO_AAC_FORMAT_RAW: |
| 576 | /* for ADIF recording */ |
| 577 | *aac_type = ADSP_AUDIO_AAC_RAW; |
| 578 | break; |
| 579 | } |
| 580 | |
| 581 | rpc.format.binary.data[index++] = (u8)( |
| 582 | ((audio_object_type & 0x1F) << 3) | |
| 583 | ((sample_rate >> 1) & 0x7)); |
| 584 | rpc.format.binary.data[index] = (u8)( |
| 585 | ((sample_rate & 0x1) << 7) | |
| 586 | ((channels & 0x7) << 3)); |
| 587 | rpc.format.binary.num_bytes = index + 1; |
| 588 | rpc.hdr.opcode = ADSP_AUDIO_IOCTL_CMD_OPEN_READ; |
| 589 | rpc.device = ADSP_AUDIO_DEVICE_ID_DEFAULT; |
| 590 | |
| 591 | if (flags == AUDIO_FLAG_READ) |
| 592 | rpc.stream_context = ADSP_AUDIO_DEVICE_CONTEXT_RECORD; |
| 593 | else |
| 594 | rpc.stream_context = ADSP_AUDIO_DEVICE_CONTEXT_MIXED_RECORD; |
| 595 | |
| 596 | rpc.buf_max_size = bufsz; |
| 597 | rpc.config.aac.bit_rate = bit_rate; |
| 598 | rpc.config.aac.encoder_mode = ADSP_AUDIO_ENC_AAC_LC_ONLY_MODE; |
| 599 | pr_debug("[%s:%s] ac = %p\n", __MM_FILE__, __func__, ac); |
| 600 | return audio_ioctl(ac, &rpc, sizeof(rpc)); |
| 601 | } |
| 602 | |
| 603 | static int audio_qcp_open(struct audio_client *ac, uint32_t bufsz, |
| 604 | uint32_t min_rate, uint32_t max_rate, |
| 605 | uint32_t flags, uint32_t format) |
| 606 | { |
| 607 | struct adsp_open_command rpc; |
| 608 | |
| 609 | memset(&rpc, 0, sizeof(rpc)); |
| 610 | |
| 611 | rpc.format.standard.format = format; |
| 612 | rpc.format.standard.channels = 1; |
| 613 | rpc.format.standard.bits_per_sample = 16; |
| 614 | rpc.format.standard.sampling_rate = 8000; |
| 615 | rpc.format.standard.is_signed = 1; |
| 616 | rpc.format.standard.is_interleaved = 0; |
| 617 | |
| 618 | rpc.hdr.opcode = ADSP_AUDIO_IOCTL_CMD_OPEN_READ; |
| 619 | rpc.device = ADSP_AUDIO_DEVICE_ID_DEFAULT; |
| 620 | |
| 621 | if (flags == AUDIO_FLAG_READ) |
| 622 | rpc.stream_context = ADSP_AUDIO_DEVICE_CONTEXT_RECORD; |
| 623 | else |
| 624 | rpc.stream_context = ADSP_AUDIO_DEVICE_CONTEXT_MIXED_RECORD; |
| 625 | rpc.buf_max_size = bufsz; |
| 626 | rpc.config.evrc.min_rate = min_rate; |
| 627 | rpc.config.evrc.max_rate = max_rate; |
| 628 | |
| 629 | pr_debug("[%s:%s] ac = %p\n", __MM_FILE__, __func__, ac); |
| 630 | return audio_ioctl(ac, &rpc, sizeof(rpc)); |
| 631 | } |
| 632 | |
| 633 | static int audio_amrnb_open(struct audio_client *ac, uint32_t bufsz, |
| 634 | uint32_t enc_mode, uint32_t flags, |
| 635 | uint32_t dtx_enable) |
| 636 | { |
| 637 | struct adsp_open_command rpc; |
| 638 | |
| 639 | memset(&rpc, 0, sizeof(rpc)); |
| 640 | |
| 641 | rpc.format.standard.format = ADSP_AUDIO_FORMAT_AMRNB_FS; |
| 642 | rpc.format.standard.channels = 1; |
| 643 | rpc.format.standard.bits_per_sample = 16; |
| 644 | rpc.format.standard.sampling_rate = 8000; |
| 645 | rpc.format.standard.is_signed = 1; |
| 646 | rpc.format.standard.is_interleaved = 0; |
| 647 | |
| 648 | rpc.hdr.opcode = ADSP_AUDIO_IOCTL_CMD_OPEN_READ; |
| 649 | rpc.device = ADSP_AUDIO_DEVICE_ID_DEFAULT; |
| 650 | |
| 651 | if (flags == AUDIO_FLAG_READ) |
| 652 | rpc.stream_context = ADSP_AUDIO_DEVICE_CONTEXT_RECORD; |
| 653 | else |
| 654 | rpc.stream_context = ADSP_AUDIO_DEVICE_CONTEXT_MIXED_RECORD; |
| 655 | |
| 656 | rpc.buf_max_size = bufsz; |
| 657 | rpc.config.amr.mode = enc_mode; |
| 658 | rpc.config.amr.dtx_mode = dtx_enable; |
| 659 | rpc.config.amr.enable = 1; |
| 660 | |
| 661 | pr_debug("[%s:%s] ac = %p\n", __MM_FILE__, __func__, ac); |
| 662 | return audio_ioctl(ac, &rpc, sizeof(rpc)); |
| 663 | } |
| 664 | |
| 665 | |
| 666 | |
| 667 | static int audio_close(struct audio_client *ac) |
| 668 | { |
| 669 | pr_debug("[%s:%s] ac = %p\n", __MM_FILE__, __func__, ac); |
| 670 | audio_command(ac, ADSP_AUDIO_IOCTL_CMD_STREAM_STOP); |
| 671 | audio_command(ac, ADSP_AUDIO_IOCTL_CMD_CLOSE); |
| 672 | return 0; |
| 673 | } |
| 674 | |
| 675 | static int audio_set_table(struct audio_client *ac, |
| 676 | uint32_t device_id, int size) |
| 677 | { |
| 678 | struct adsp_set_dev_cfg_table_command rpc; |
| 679 | |
| 680 | memset(&rpc, 0, sizeof(rpc)); |
| 681 | rpc.hdr.opcode = ADSP_AUDIO_IOCTL_SET_DEVICE_CONFIG_TABLE; |
| 682 | if (q6_device_to_dir(device_id) == Q6_TX) { |
| 683 | if (tx_clk_freq > 16000) |
| 684 | rpc.hdr.data = 48000; |
| 685 | else if (tx_clk_freq > 8000) |
| 686 | rpc.hdr.data = 16000; |
| 687 | else |
| 688 | rpc.hdr.data = 8000; |
| 689 | } |
| 690 | rpc.device_id = device_id; |
| 691 | rpc.phys_addr = audio_phys; |
| 692 | rpc.phys_size = size; |
| 693 | rpc.phys_used = size; |
| 694 | |
| 695 | pr_debug("[%s:%s] ac = %p, device_id = 0x%x, size = %d\n", __MM_FILE__, |
| 696 | __func__, ac, device_id, size); |
| 697 | return audio_ioctl(ac, &rpc, sizeof(rpc)); |
| 698 | } |
| 699 | |
| 700 | int q6audio_read(struct audio_client *ac, struct audio_buffer *ab) |
| 701 | { |
| 702 | struct adsp_buffer_command rpc; |
| 703 | uint32_t res; |
| 704 | int r; |
| 705 | |
| 706 | memset(&rpc, 0, sizeof(rpc)); |
| 707 | rpc.hdr.size = sizeof(rpc) - sizeof(u32); |
| 708 | rpc.hdr.dst = AUDIO_ADDR(ac->session, 0, AUDIO_DOMAIN_DSP); |
| 709 | rpc.hdr.src = AUDIO_ADDR(ac->session, 0, AUDIO_DOMAIN_APP); |
| 710 | rpc.hdr.context = ac->session; |
| 711 | rpc.hdr.opcode = ADSP_AUDIO_IOCTL_CMD_DATA_TX; |
| 712 | rpc.buffer.addr = ab->phys; |
| 713 | rpc.buffer.max_size = ab->size; |
| 714 | rpc.buffer.actual_size = ab->actual_size; |
| 715 | |
| 716 | pr_debug("[%s:%s] ac = %p\n", __MM_FILE__, __func__, ac); |
| 717 | r = dal_call(ac->client, AUDIO_OP_DATA, 5, &rpc, sizeof(rpc), |
| 718 | &res, sizeof(res)); |
| 719 | return 0; |
| 720 | } |
| 721 | |
| 722 | int q6audio_write(struct audio_client *ac, struct audio_buffer *ab) |
| 723 | { |
| 724 | struct adsp_buffer_command rpc; |
| 725 | uint32_t res; |
| 726 | int r; |
| 727 | |
| 728 | memset(&rpc, 0, sizeof(rpc)); |
| 729 | rpc.hdr.size = sizeof(rpc) - sizeof(u32); |
| 730 | rpc.hdr.dst = AUDIO_ADDR(ac->session, 0, AUDIO_DOMAIN_DSP); |
| 731 | rpc.hdr.src = AUDIO_ADDR(ac->session, 0, AUDIO_DOMAIN_APP); |
| 732 | rpc.hdr.context = ac->session; |
| 733 | rpc.hdr.opcode = ADSP_AUDIO_IOCTL_CMD_DATA_RX; |
| 734 | rpc.buffer.addr = ab->phys; |
| 735 | rpc.buffer.max_size = ab->size; |
| 736 | rpc.buffer.actual_size = ab->actual_size; |
| 737 | |
| 738 | pr_debug("[%s:%s] ac = %p\n", __MM_FILE__, __func__, ac); |
| 739 | r = dal_call(ac->client, AUDIO_OP_DATA, 5, &rpc, sizeof(rpc), |
| 740 | &res, sizeof(res)); |
| 741 | return 0; |
| 742 | } |
| 743 | |
| 744 | static int audio_rx_volume(struct audio_client *ac, uint32_t dev_id, int32_t volume) |
| 745 | { |
| 746 | struct adsp_set_dev_volume_command rpc; |
| 747 | |
| 748 | pr_debug("[%s:%s] volume = %d\n", __MM_FILE__, __func__, volume); |
| 749 | memset(&rpc, 0, sizeof(rpc)); |
| 750 | rpc.hdr.opcode = ADSP_AUDIO_IOCTL_CMD_SET_DEVICE_VOL; |
| 751 | rpc.device_id = dev_id; |
| 752 | rpc.path = ADSP_PATH_RX; |
| 753 | rpc.volume = volume; |
| 754 | return audio_ioctl(ac, &rpc, sizeof(rpc)); |
| 755 | } |
| 756 | |
| 757 | static int audio_rx_mute(struct audio_client *ac, uint32_t dev_id, int mute) |
| 758 | { |
| 759 | struct adsp_set_dev_mute_command rpc; |
| 760 | |
| 761 | pr_debug("[%s:%s] mute = %d, dev_id = 0x%x\n", __MM_FILE__, |
| 762 | __func__, mute, dev_id); |
| 763 | memset(&rpc, 0, sizeof(rpc)); |
| 764 | rpc.hdr.opcode = ADSP_AUDIO_IOCTL_CMD_SET_DEVICE_MUTE; |
| 765 | rpc.device_id = dev_id; |
| 766 | rpc.path = ADSP_PATH_RX; |
| 767 | rpc.mute = !!mute; |
| 768 | return audio_ioctl(ac, &rpc, sizeof(rpc)); |
| 769 | } |
| 770 | |
| 771 | static int audio_tx_mute(struct audio_client *ac, uint32_t dev_id, int mute) |
| 772 | { |
| 773 | struct adsp_set_dev_mute_command rpc; |
| 774 | |
| 775 | pr_debug("[%s:%s] mute = %d\n", __MM_FILE__, __func__, mute); |
| 776 | if (mute < 0 || mute > 3) { |
| 777 | pr_err("[%s:%s] invalid mute status %d\n", __MM_FILE__, |
| 778 | __func__, mute); |
| 779 | return -EINVAL; |
| 780 | } |
| 781 | |
| 782 | memset(&rpc, 0, sizeof(rpc)); |
| 783 | rpc.hdr.opcode = ADSP_AUDIO_IOCTL_CMD_SET_DEVICE_MUTE; |
| 784 | if ((mute == STREAM_UNMUTE) || (mute == STREAM_MUTE)) { |
| 785 | rpc.device_id = ADSP_AUDIO_DEVICE_ID_VOICE; |
| 786 | rpc.path = ADSP_PATH_TX_CNG_DIS; |
| 787 | } else { |
| 788 | rpc.device_id = dev_id; |
| 789 | rpc.path = ADSP_PATH_TX; |
| 790 | } |
| 791 | mute &= 0x01; |
| 792 | rpc.mute = !!mute; |
| 793 | return audio_ioctl(ac, &rpc, sizeof(rpc)); |
| 794 | } |
| 795 | |
| 796 | static int audio_stream_volume(struct audio_client *ac, int volume) |
| 797 | { |
| 798 | struct adsp_set_volume_command rpc; |
| 799 | int rc; |
| 800 | |
| 801 | pr_debug("[%s:%s] volume = %d\n", __MM_FILE__, __func__, volume); |
| 802 | memset(&rpc, 0, sizeof(rpc)); |
| 803 | rpc.hdr.opcode = ADSP_AUDIO_IOCTL_CMD_SET_STREAM_VOL; |
| 804 | rpc.volume = volume; |
| 805 | rc = audio_ioctl(ac, &rpc, sizeof(rpc)); |
| 806 | return rc; |
| 807 | } |
| 808 | |
| 809 | static int audio_stream_mute(struct audio_client *ac, int mute) |
| 810 | { |
| 811 | struct adsp_set_mute_command rpc; |
| 812 | int rc; |
| 813 | |
| 814 | pr_debug("[%s:%s] mute = %d\n", __MM_FILE__, __func__, mute); |
| 815 | memset(&rpc, 0, sizeof(rpc)); |
| 816 | rpc.hdr.opcode = ADSP_AUDIO_IOCTL_CMD_SET_STREAM_MUTE; |
| 817 | rpc.mute = mute; |
| 818 | rc = audio_ioctl(ac, &rpc, sizeof(rpc)); |
| 819 | return rc; |
| 820 | } |
| 821 | |
| 822 | static void callback(void *data, int len, void *cookie) |
| 823 | { |
| 824 | struct adsp_event_hdr *e = data; |
| 825 | struct audio_client *ac; |
| 826 | struct adsp_buffer_event *abe = data; |
| 827 | |
| 828 | if (e->context >= SESSION_MAX) { |
| 829 | pr_err("[%s:%s] bogus session %d\n", __MM_FILE__, __func__, |
| 830 | e->context); |
| 831 | return; |
| 832 | } |
| 833 | ac = session[e->context]; |
| 834 | if (!ac) { |
| 835 | pr_err("[%s:%s] unknown session %d\n", __MM_FILE__, __func__, |
| 836 | e->context); |
| 837 | return; |
| 838 | } |
| 839 | |
| 840 | if (e->event_id == ADSP_AUDIO_IOCTL_CMD_STREAM_EOS) { |
| 841 | pr_debug("[%s:%s] CB Stream eos, ac = %p\n", |
| 842 | __MM_FILE__, __func__, ac); |
| 843 | if (e->status) |
| 844 | pr_err("[%s:%s] playback status %d\n", __MM_FILE__, |
| 845 | __func__, e->status); |
| 846 | if (ac->cb_status == -EBUSY) { |
| 847 | ac->cb_status = e->status; |
| 848 | wake_up(&ac->wait); |
| 849 | } |
| 850 | return; |
| 851 | } |
| 852 | |
| 853 | if (e->event_id == ADSP_AUDIO_EVT_STATUS_BUF_DONE) { |
| 854 | pr_debug("[%s:%s] CB done, ac = %p, status = %d\n", |
| 855 | __MM_FILE__, __func__, ac, e->status); |
| 856 | if (e->status) |
| 857 | pr_err("[%s:%s] buffer status %d\n", __MM_FILE__, |
| 858 | __func__, e->status); |
| 859 | |
| 860 | ac->buf[ac->dsp_buf].actual_size = abe->buffer.actual_size; |
| 861 | ac->buf[ac->dsp_buf].used = 0; |
| 862 | ac->dsp_buf ^= 1; |
| 863 | wake_up(&ac->wait); |
| 864 | return; |
| 865 | } |
| 866 | |
| 867 | pr_debug("[%s:%s] ac = %p, event_id = 0x%x, status = %d\n", |
| 868 | __MM_FILE__, __func__, ac, e->event_id, e->status); |
| 869 | if (e->status) |
| 870 | pr_warning("audio_cb: s=%d e=%08x status=%d\n", |
| 871 | e->context, e->event_id, e->status); |
| 872 | if (ac->cb_status == -EBUSY) { |
| 873 | ac->cb_status = e->status; |
| 874 | wake_up(&ac->wait); |
| 875 | } |
| 876 | } |
| 877 | |
| 878 | static void audio_init(struct dal_client *client) |
| 879 | { |
| 880 | u32 tmp[3]; |
| 881 | |
| 882 | pr_debug("[%s:%s]\n", __MM_FILE__, __func__); |
| 883 | tmp[0] = 2 * sizeof(u32); |
| 884 | tmp[1] = 0; |
| 885 | tmp[2] = 0; |
| 886 | dal_call(client, AUDIO_OP_INIT, 5, tmp, sizeof(tmp), |
| 887 | tmp, sizeof(u32)); |
| 888 | } |
| 889 | |
| 890 | static struct audio_client *ac_control; |
| 891 | |
| 892 | static int q6audio_init(void) |
| 893 | { |
| 894 | struct audio_client *ac = 0; |
| 895 | int res; |
| 896 | |
| 897 | pr_debug("[%s:%s]\n", __MM_FILE__, __func__); |
| 898 | mutex_lock(&audio_lock); |
| 899 | if (ac_control) { |
| 900 | res = 0; |
| 901 | goto done; |
| 902 | } |
| 903 | |
| 904 | pr_info("[%s:%s] codecs\n", __MM_FILE__, __func__); |
| 905 | icodec_rx_clk = clk_get(0, "icodec_rx_clk"); |
| 906 | icodec_tx_clk = clk_get(0, "icodec_tx_clk"); |
| 907 | ecodec_clk = clk_get(0, "ecodec_clk"); |
| 908 | sdac_clk = clk_get(0, "sdac_clk"); |
| 909 | audio_phys = pmem_kalloc(4096, PMEM_MEMTYPE_EBI1|PMEM_ALIGNMENT_4K); |
| 910 | audio_data = ioremap(audio_phys, 4096); |
| 911 | |
| 912 | pr_info("[%s:%s] attach ADSP\n", __MM_FILE__, __func__); |
| 913 | adsp = dal_attach(AUDIO_DAL_DEVICE, AUDIO_DAL_PORT, 1, |
| 914 | callback, 0); |
| 915 | if (!adsp) { |
| 916 | pr_err("[%s:%s] cannot attach to adsp\n", __MM_FILE__, |
| 917 | __func__); |
| 918 | res = -ENODEV; |
| 919 | goto done; |
| 920 | } |
| 921 | pr_info("[%s:%s] INIT\n", __MM_FILE__, __func__); |
| 922 | audio_init(adsp); |
| 923 | dal_trace(adsp); |
| 924 | |
| 925 | ac = audio_client_alloc(0); |
| 926 | if (!ac) { |
| 927 | pr_err("[%s:%s] cannot allocate client\n", |
| 928 | __MM_FILE__, __func__); |
| 929 | res = -ENOMEM; |
| 930 | goto done; |
| 931 | } |
| 932 | |
| 933 | pr_info("[%s:%s] OPEN control\n", __MM_FILE__, __func__); |
| 934 | if (audio_open_control(ac)) { |
| 935 | pr_err("[%s:%s] cannot open control channel\n", |
| 936 | __MM_FILE__, __func__); |
| 937 | res = -ENODEV; |
| 938 | goto done; |
| 939 | } |
| 940 | |
| 941 | pr_info("[%s:%s] attach ACDB\n", __MM_FILE__, __func__); |
| 942 | acdb = dal_attach(ACDB_DAL_DEVICE, ACDB_DAL_PORT, 0, 0, 0); |
| 943 | if (!acdb) { |
| 944 | pr_err("[%s:%s] cannot attach to acdb channel\n", |
| 945 | __MM_FILE__, __func__); |
| 946 | res = -ENODEV; |
| 947 | goto done; |
| 948 | } |
| 949 | |
| 950 | pr_info("[%s:%s] attach ADIE\n", __MM_FILE__, __func__); |
| 951 | adie = dal_attach(ADIE_DAL_DEVICE, ADIE_DAL_PORT, 0, 0, 0); |
| 952 | if (!adie) { |
| 953 | pr_err("[%s:%s] cannot attach to adie\n", |
| 954 | __MM_FILE__, __func__); |
| 955 | res = -ENODEV; |
| 956 | goto done; |
| 957 | } |
| 958 | if (analog_ops->init) |
| 959 | analog_ops->init(); |
| 960 | |
| 961 | res = 0; |
| 962 | ac_control = ac; |
| 963 | |
Stephen Boyd | 2fcabf9 | 2012-05-30 10:41:11 -0700 | [diff] [blame] | 964 | pm_qos_add_request(&pm_qos_req, PM_QOS_CPU_DMA_LATENCY, |
| 965 | PM_QOS_DEFAULT_VALUE); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 966 | wake_lock_init(&wakelock, WAKE_LOCK_SUSPEND, "audio_pcm_suspend"); |
| 967 | done: |
| 968 | if ((res < 0) && ac) |
| 969 | audio_client_free(ac); |
| 970 | mutex_unlock(&audio_lock); |
| 971 | |
| 972 | pr_debug("[%s:%s] res = %d\n", __MM_FILE__, __func__, res); |
| 973 | return res; |
| 974 | } |
| 975 | |
| 976 | struct audio_config_data { |
| 977 | uint32_t device_id; |
| 978 | uint32_t sample_rate; |
| 979 | uint32_t offset; |
| 980 | uint32_t length; |
| 981 | }; |
| 982 | |
| 983 | struct audio_config_database { |
| 984 | uint8_t magic[8]; |
| 985 | uint32_t entry_count; |
| 986 | uint32_t unused; |
| 987 | struct audio_config_data entry[0]; |
| 988 | }; |
| 989 | |
| 990 | void *acdb_data; |
| 991 | const struct firmware *acdb_fw; |
| 992 | extern struct miscdevice q6_control_device; |
| 993 | |
| 994 | static int acdb_get_config_table(uint32_t device_id, uint32_t sample_rate) |
| 995 | { |
| 996 | struct acdb_cmd_device_table rpc; |
| 997 | struct acdb_result res; |
| 998 | int r; |
| 999 | |
| 1000 | pr_debug("[%s:%s] device_id = 0x%x, samplerate = %d\n", __MM_FILE__, |
| 1001 | __func__, device_id, sample_rate); |
| 1002 | if (q6audio_init()) |
| 1003 | return 0; |
| 1004 | |
| 1005 | memset(audio_data, 0, 4096); |
| 1006 | memset(&rpc, 0, sizeof(rpc)); |
| 1007 | |
| 1008 | rpc.size = sizeof(rpc) - (2 * sizeof(uint32_t)); |
| 1009 | rpc.command_id = ACDB_GET_DEVICE_TABLE; |
| 1010 | rpc.device_id = device_id; |
| 1011 | rpc.sample_rate_id = sample_rate; |
| 1012 | rpc.total_bytes = 4096; |
| 1013 | rpc.unmapped_buf = audio_phys; |
| 1014 | rpc.res_size = sizeof(res) - (2 * sizeof(uint32_t)); |
| 1015 | |
| 1016 | r = dal_call(acdb, ACDB_OP_IOCTL, 8, &rpc, sizeof(rpc), |
| 1017 | &res, sizeof(res)); |
| 1018 | |
| 1019 | if ((r == sizeof(res)) && (res.dal_status == 0)) |
| 1020 | return res.used_bytes; |
| 1021 | |
| 1022 | return -EIO; |
| 1023 | } |
| 1024 | |
| 1025 | static uint32_t audio_rx_path_id = ADIE_PATH_HANDSET_RX; |
| 1026 | static uint32_t audio_rx_device_id = ADSP_AUDIO_DEVICE_ID_HANDSET_SPKR; |
| 1027 | static uint32_t audio_rx_device_group = -1; |
| 1028 | static uint32_t audio_tx_path_id = ADIE_PATH_HANDSET_TX; |
| 1029 | static uint32_t audio_tx_device_id = ADSP_AUDIO_DEVICE_ID_HANDSET_MIC; |
| 1030 | static uint32_t audio_tx_device_group = -1; |
| 1031 | |
| 1032 | static int qdsp6_devchg_notify(struct audio_client *ac, |
| 1033 | uint32_t dev_type, uint32_t dev_id) |
| 1034 | { |
| 1035 | struct adsp_device_switch_command rpc; |
| 1036 | |
| 1037 | if (dev_type != ADSP_AUDIO_RX_DEVICE && |
| 1038 | dev_type != ADSP_AUDIO_TX_DEVICE) |
| 1039 | return -EINVAL; |
| 1040 | |
| 1041 | memset(&rpc, 0, sizeof(rpc)); |
| 1042 | rpc.hdr.opcode = ADSP_AUDIO_IOCTL_CMD_DEVICE_SWITCH_PREPARE; |
| 1043 | if (dev_type == ADSP_AUDIO_RX_DEVICE) { |
| 1044 | rpc.old_device = audio_rx_device_id; |
| 1045 | rpc.new_device = dev_id; |
| 1046 | } else { |
| 1047 | rpc.old_device = audio_tx_device_id; |
| 1048 | rpc.new_device = dev_id; |
| 1049 | } |
| 1050 | rpc.device_class = 0; |
| 1051 | rpc.device_type = dev_type; |
| 1052 | pr_debug("[%s:%s] dev_id = 0x%x\n", __MM_FILE__, __func__, dev_id); |
| 1053 | return audio_ioctl(ac, &rpc, sizeof(rpc)); |
| 1054 | } |
| 1055 | |
| 1056 | static int qdsp6_standby(struct audio_client *ac) |
| 1057 | { |
| 1058 | pr_debug("[%s:%s]\n", __MM_FILE__, __func__); |
| 1059 | return audio_command(ac, ADSP_AUDIO_IOCTL_CMD_DEVICE_SWITCH_STANDBY); |
| 1060 | } |
| 1061 | |
| 1062 | static int qdsp6_start(struct audio_client *ac) |
| 1063 | { |
| 1064 | pr_debug("[%s:%s]\n", __MM_FILE__, __func__); |
| 1065 | return audio_command(ac, ADSP_AUDIO_IOCTL_CMD_DEVICE_SWITCH_COMMIT); |
| 1066 | } |
| 1067 | |
| 1068 | static void audio_rx_analog_enable(int en) |
| 1069 | { |
| 1070 | pr_debug("[%s:%s] audio_rx_device_id = 0x%x, en = %d\n", __MM_FILE__, |
| 1071 | __func__, audio_rx_device_id, en); |
| 1072 | switch (audio_rx_device_id) { |
| 1073 | case ADSP_AUDIO_DEVICE_ID_HEADSET_SPKR_MONO: |
| 1074 | case ADSP_AUDIO_DEVICE_ID_HEADSET_SPKR_STEREO: |
| 1075 | case ADSP_AUDIO_DEVICE_ID_TTY_HEADSET_SPKR: |
| 1076 | if (analog_ops->headset_enable) |
| 1077 | analog_ops->headset_enable(en); |
| 1078 | break; |
| 1079 | case ADSP_AUDIO_DEVICE_ID_SPKR_PHONE_MONO_W_MONO_HEADSET: |
| 1080 | case ADSP_AUDIO_DEVICE_ID_SPKR_PHONE_MONO_W_STEREO_HEADSET: |
| 1081 | case ADSP_AUDIO_DEVICE_ID_SPKR_PHONE_STEREO_W_MONO_HEADSET: |
| 1082 | case ADSP_AUDIO_DEVICE_ID_SPKR_PHONE_STEREO_W_STEREO_HEADSET: |
| 1083 | if (analog_ops->headset_enable) |
| 1084 | analog_ops->headset_enable(en); |
| 1085 | if (analog_ops->speaker_enable) |
| 1086 | analog_ops->speaker_enable(en); |
| 1087 | break; |
| 1088 | case ADSP_AUDIO_DEVICE_ID_SPKR_PHONE_MONO: |
| 1089 | case ADSP_AUDIO_DEVICE_ID_SPKR_PHONE_STEREO: |
| 1090 | if (analog_ops->speaker_enable) |
| 1091 | analog_ops->speaker_enable(en); |
| 1092 | break; |
| 1093 | case ADSP_AUDIO_DEVICE_ID_BT_SCO_SPKR: |
| 1094 | if (analog_ops->bt_sco_enable) |
| 1095 | analog_ops->bt_sco_enable(en); |
| 1096 | break; |
| 1097 | case ADSP_AUDIO_DEVICE_ID_HANDSET_SPKR: |
| 1098 | if (analog_ops->receiver_enable) |
| 1099 | analog_ops->receiver_enable(en); |
| 1100 | break; |
| 1101 | } |
| 1102 | } |
| 1103 | |
| 1104 | static void audio_tx_analog_enable(int en) |
| 1105 | { |
| 1106 | pr_debug("[%s:%s] audio_tx_device_id = 0x%x, en = %d\n", __MM_FILE__, |
| 1107 | __func__, audio_tx_device_id, en); |
| 1108 | switch (audio_tx_device_id) { |
| 1109 | case ADSP_AUDIO_DEVICE_ID_HANDSET_MIC: |
| 1110 | case ADSP_AUDIO_DEVICE_ID_SPKR_PHONE_MIC: |
| 1111 | if (analog_ops->int_mic_enable) |
| 1112 | analog_ops->int_mic_enable(en); |
| 1113 | break; |
| 1114 | case ADSP_AUDIO_DEVICE_ID_HEADSET_MIC: |
| 1115 | case ADSP_AUDIO_DEVICE_ID_TTY_HEADSET_MIC: |
| 1116 | case ADSP_AUDIO_DEVICE_ID_HANDSET_DUAL_MIC: |
| 1117 | case ADSP_AUDIO_DEVICE_ID_SPKR_PHONE_DUAL_MIC: |
| 1118 | if (analog_ops->ext_mic_enable) |
| 1119 | analog_ops->ext_mic_enable(en); |
| 1120 | break; |
| 1121 | case ADSP_AUDIO_DEVICE_ID_BT_SCO_MIC: |
| 1122 | if (analog_ops->bt_sco_enable) |
| 1123 | analog_ops->bt_sco_enable(en); |
| 1124 | break; |
| 1125 | } |
| 1126 | } |
| 1127 | |
| 1128 | static int audio_update_acdb(uint32_t adev, uint32_t acdb_id) |
| 1129 | { |
| 1130 | uint32_t sample_rate; |
| 1131 | int sz; |
| 1132 | |
| 1133 | pr_debug("[%s:%s] adev = 0x%x, acdb_id = 0x%x\n", __MM_FILE__, |
| 1134 | __func__, adev, acdb_id); |
| 1135 | if (q6_device_to_dir(adev) == Q6_RX) { |
| 1136 | rx_acdb = acdb_id; |
| 1137 | sample_rate = q6_device_to_rate(adev); |
| 1138 | } else { |
| 1139 | |
| 1140 | tx_acdb = acdb_id; |
| 1141 | if (tx_clk_freq > 16000) |
| 1142 | sample_rate = 48000; |
| 1143 | else if (tx_clk_freq > 8000) |
| 1144 | sample_rate = 16000; |
| 1145 | else |
| 1146 | sample_rate = 8000; |
| 1147 | } |
| 1148 | |
| 1149 | if (acdb_id == 0) |
| 1150 | acdb_id = q6_device_to_cad_id(adev); |
| 1151 | |
| 1152 | sz = acdb_get_config_table(acdb_id, sample_rate); |
| 1153 | audio_set_table(ac_control, adev, sz); |
| 1154 | |
| 1155 | return 0; |
| 1156 | } |
| 1157 | |
| 1158 | static void adie_rx_path_enable(uint32_t acdb_id) |
| 1159 | { |
| 1160 | pr_debug("[%s:%s]\n", __MM_FILE__, __func__); |
| 1161 | if (audio_rx_path_id) { |
| 1162 | adie_enable(); |
| 1163 | adie_set_path(adie, audio_rx_path_id, ADIE_PATH_RX); |
| 1164 | adie_set_path_freq_plan(adie, ADIE_PATH_RX, 48000); |
| 1165 | |
| 1166 | adie_proceed_to_stage(adie, ADIE_PATH_RX, |
| 1167 | ADIE_STAGE_DIGITAL_READY); |
| 1168 | adie_proceed_to_stage(adie, ADIE_PATH_RX, |
| 1169 | ADIE_STAGE_DIGITAL_ANALOG_READY); |
| 1170 | } |
| 1171 | } |
| 1172 | |
| 1173 | static void q6_rx_path_enable(int reconf, uint32_t acdb_id) |
| 1174 | { |
| 1175 | pr_debug("[%s:%s]\n", __MM_FILE__, __func__); |
| 1176 | if (!reconf) |
| 1177 | qdsp6_devchg_notify(ac_control, ADSP_AUDIO_RX_DEVICE, audio_rx_device_id); |
| 1178 | audio_update_acdb(audio_rx_device_id, acdb_id); |
| 1179 | qdsp6_standby(ac_control); |
| 1180 | qdsp6_start(ac_control); |
| 1181 | } |
| 1182 | |
| 1183 | static void _audio_rx_path_enable(int reconf, uint32_t acdb_id) |
| 1184 | { |
| 1185 | pr_debug("[%s:%s] reconf = %d\n", __MM_FILE__, __func__, reconf); |
| 1186 | q6_rx_path_enable(reconf, acdb_id); |
| 1187 | if (audio_rx_path_id) |
| 1188 | adie_rx_path_enable(acdb_id); |
| 1189 | audio_rx_analog_enable(1); |
| 1190 | } |
| 1191 | |
| 1192 | static void _audio_tx_path_enable(int reconf, uint32_t acdb_id) |
| 1193 | { |
| 1194 | pr_debug("[%s:%s] reconf = %d, tx_clk_freq = %d\n", __MM_FILE__, |
| 1195 | __func__, reconf, tx_clk_freq); |
| 1196 | audio_tx_analog_enable(1); |
| 1197 | |
| 1198 | if (audio_tx_path_id) { |
| 1199 | adie_enable(); |
| 1200 | adie_set_path(adie, audio_tx_path_id, ADIE_PATH_TX); |
| 1201 | |
| 1202 | if (tx_clk_freq > 16000) |
| 1203 | adie_set_path_freq_plan(adie, ADIE_PATH_TX, 48000); |
| 1204 | else if (tx_clk_freq > 8000) |
| 1205 | adie_set_path_freq_plan(adie, ADIE_PATH_TX, 16000); |
| 1206 | else |
| 1207 | adie_set_path_freq_plan(adie, ADIE_PATH_TX, 8000); |
| 1208 | |
| 1209 | adie_proceed_to_stage(adie, ADIE_PATH_TX, |
| 1210 | ADIE_STAGE_DIGITAL_READY); |
| 1211 | adie_proceed_to_stage(adie, ADIE_PATH_TX, |
| 1212 | ADIE_STAGE_DIGITAL_ANALOG_READY); |
| 1213 | } |
| 1214 | |
| 1215 | |
| 1216 | if (!reconf) |
| 1217 | qdsp6_devchg_notify(ac_control, ADSP_AUDIO_TX_DEVICE, |
| 1218 | audio_tx_device_id); |
| 1219 | audio_update_acdb(audio_tx_device_id, acdb_id); |
| 1220 | qdsp6_standby(ac_control); |
| 1221 | qdsp6_start(ac_control); |
| 1222 | |
| 1223 | audio_tx_mute(ac_control, audio_tx_device_id, tx_mute_status); |
| 1224 | } |
| 1225 | |
| 1226 | static void _audio_rx_path_disable(void) |
| 1227 | { |
| 1228 | pr_debug("[%s:%s]\n", __MM_FILE__, __func__); |
| 1229 | audio_rx_analog_enable(0); |
| 1230 | |
| 1231 | if (audio_rx_path_id) { |
| 1232 | adie_proceed_to_stage(adie, ADIE_PATH_RX, |
| 1233 | ADIE_STAGE_ANALOG_OFF); |
| 1234 | adie_proceed_to_stage(adie, ADIE_PATH_RX, |
| 1235 | ADIE_STAGE_DIGITAL_OFF); |
| 1236 | adie_disable(); |
| 1237 | } |
| 1238 | } |
| 1239 | |
| 1240 | static void _audio_tx_path_disable(void) |
| 1241 | { |
| 1242 | pr_debug("[%s:%s]\n", __MM_FILE__, __func__); |
| 1243 | audio_tx_analog_enable(0); |
| 1244 | |
| 1245 | if (audio_tx_path_id) { |
| 1246 | adie_proceed_to_stage(adie, ADIE_PATH_TX, |
| 1247 | ADIE_STAGE_ANALOG_OFF); |
| 1248 | adie_proceed_to_stage(adie, ADIE_PATH_TX, |
| 1249 | ADIE_STAGE_DIGITAL_OFF); |
| 1250 | adie_disable(); |
| 1251 | } |
| 1252 | } |
| 1253 | |
| 1254 | static int icodec_rx_clk_refcount; |
| 1255 | static int icodec_tx_clk_refcount; |
| 1256 | static int ecodec_clk_refcount; |
| 1257 | static int sdac_clk_refcount; |
| 1258 | |
| 1259 | static void ecodec_clk_enable(void) |
| 1260 | { |
| 1261 | ecodec_clk_refcount++; |
| 1262 | if (ecodec_clk_refcount == 1) { |
| 1263 | clk_set_rate(ecodec_clk, 2048000); |
| 1264 | clk_enable(ecodec_clk); |
| 1265 | } |
| 1266 | } |
| 1267 | static void ecodec_clk_disable(int group_reset, int path) |
| 1268 | { |
| 1269 | ecodec_clk_refcount--; |
| 1270 | if (ecodec_clk_refcount == 0) { |
| 1271 | clk_disable(ecodec_clk); |
| 1272 | if (group_reset) { |
| 1273 | if (path == ADSP_PATH_TX) |
| 1274 | audio_tx_device_group = -1; |
| 1275 | else |
| 1276 | audio_rx_device_group = -1; |
| 1277 | } |
| 1278 | } |
| 1279 | } |
| 1280 | static void _audio_rx_clk_enable(void) |
| 1281 | { |
| 1282 | uint32_t device_group = q6_device_to_codec(audio_rx_device_id); |
| 1283 | |
| 1284 | pr_debug("[%s:%s] rx_clk_refcount = %d\n", __MM_FILE__, __func__, |
| 1285 | icodec_rx_clk_refcount); |
| 1286 | switch(device_group) { |
| 1287 | case Q6_ICODEC_RX: |
| 1288 | icodec_rx_clk_refcount++; |
| 1289 | if (icodec_rx_clk_refcount == 1) { |
| 1290 | clk_set_rate(icodec_rx_clk, 12288000); |
| 1291 | clk_enable(icodec_rx_clk); |
| 1292 | } |
| 1293 | break; |
| 1294 | case Q6_ECODEC_RX: |
| 1295 | ecodec_clk_enable(); |
| 1296 | break; |
| 1297 | case Q6_SDAC_RX: |
| 1298 | sdac_clk_refcount++; |
| 1299 | if (sdac_clk_refcount == 1) { |
| 1300 | clk_set_rate(sdac_clk, 12288000); |
| 1301 | clk_enable(sdac_clk); |
| 1302 | } |
| 1303 | break; |
| 1304 | default: |
| 1305 | return; |
| 1306 | } |
| 1307 | audio_rx_device_group = device_group; |
| 1308 | } |
| 1309 | |
| 1310 | static void _audio_tx_clk_enable(void) |
| 1311 | { |
| 1312 | uint32_t device_group = q6_device_to_codec(audio_tx_device_id); |
| 1313 | uint32_t icodec_tx_clk_rate; |
| 1314 | |
| 1315 | pr_debug("[%s:%s] tx_clk_refcount = %d\n", __MM_FILE__, __func__, |
| 1316 | icodec_tx_clk_refcount); |
| 1317 | switch (device_group) { |
| 1318 | case Q6_ICODEC_TX: |
| 1319 | icodec_tx_clk_refcount++; |
| 1320 | if (icodec_tx_clk_refcount == 1) { |
| 1321 | if (tx_clk_freq > 16000) |
| 1322 | icodec_tx_clk_rate = 48000; |
| 1323 | else if (tx_clk_freq > 8000) |
| 1324 | icodec_tx_clk_rate = 16000; |
| 1325 | else |
| 1326 | icodec_tx_clk_rate = 8000; |
| 1327 | |
| 1328 | clk_set_rate(icodec_tx_clk, icodec_tx_clk_rate * 256); |
| 1329 | clk_enable(icodec_tx_clk); |
| 1330 | } |
| 1331 | break; |
| 1332 | case Q6_ECODEC_TX: |
| 1333 | ecodec_clk_enable(); |
| 1334 | break; |
| 1335 | case Q6_SDAC_TX: |
| 1336 | /* TODO: In QCT BSP, clk rate was set to 20480000 */ |
| 1337 | sdac_clk_refcount++; |
| 1338 | if (sdac_clk_refcount == 1) { |
| 1339 | clk_set_rate(sdac_clk, 12288000); |
| 1340 | clk_enable(sdac_clk); |
| 1341 | } |
| 1342 | break; |
| 1343 | default: |
| 1344 | return; |
| 1345 | } |
| 1346 | audio_tx_device_group = device_group; |
| 1347 | } |
| 1348 | |
| 1349 | static void _audio_rx_clk_disable(void) |
| 1350 | { |
| 1351 | pr_debug("[%s:%s] rx_clk_refcount = %d\n", __MM_FILE__, __func__, |
| 1352 | icodec_rx_clk_refcount); |
| 1353 | switch (audio_rx_device_group) { |
| 1354 | case Q6_ICODEC_RX: |
| 1355 | icodec_rx_clk_refcount--; |
| 1356 | if (icodec_rx_clk_refcount == 0) { |
| 1357 | clk_disable(icodec_rx_clk); |
| 1358 | audio_rx_device_group = -1; |
| 1359 | } |
| 1360 | break; |
| 1361 | case Q6_ECODEC_RX: |
| 1362 | ecodec_clk_disable(1, ADSP_PATH_RX); |
| 1363 | break; |
| 1364 | case Q6_SDAC_RX: |
| 1365 | sdac_clk_refcount--; |
| 1366 | if (sdac_clk_refcount == 0) { |
| 1367 | clk_disable(sdac_clk); |
| 1368 | audio_rx_device_group = -1; |
| 1369 | } |
| 1370 | break; |
| 1371 | default: |
| 1372 | pr_err("[%s:%s] invalid rx device group %d\n", __MM_FILE__, |
| 1373 | __func__, audio_rx_device_group); |
| 1374 | break; |
| 1375 | } |
| 1376 | } |
| 1377 | |
| 1378 | static void _audio_tx_clk_disable(void) |
| 1379 | { |
| 1380 | pr_debug("[%s:%s] tx_clk_refcount = %d\n", __MM_FILE__, __func__, |
| 1381 | icodec_tx_clk_refcount); |
| 1382 | switch (audio_tx_device_group) { |
| 1383 | case Q6_ICODEC_TX: |
| 1384 | icodec_tx_clk_refcount--; |
| 1385 | if (icodec_tx_clk_refcount == 0) { |
| 1386 | clk_disable(icodec_tx_clk); |
| 1387 | audio_tx_device_group = -1; |
| 1388 | } |
| 1389 | break; |
| 1390 | case Q6_ECODEC_TX: |
| 1391 | ecodec_clk_disable(1, ADSP_PATH_TX); |
| 1392 | break; |
| 1393 | case Q6_SDAC_TX: |
| 1394 | sdac_clk_refcount--; |
| 1395 | if (sdac_clk_refcount == 0) { |
| 1396 | clk_disable(sdac_clk); |
| 1397 | audio_tx_device_group = -1; |
| 1398 | } |
| 1399 | break; |
| 1400 | default: |
| 1401 | pr_err("[%s:%s] invalid tx device group %d\n", |
| 1402 | __MM_FILE__, __func__, audio_tx_device_group); |
| 1403 | break; |
| 1404 | } |
| 1405 | } |
| 1406 | |
| 1407 | static void _audio_rx_clk_reinit(uint32_t rx_device, uint32_t acdb_id) |
| 1408 | { |
| 1409 | uint32_t device_group = q6_device_to_codec(rx_device); |
| 1410 | |
| 1411 | pr_debug("[%s:%s] rx_device = 0x%x\n", __MM_FILE__, __func__, |
| 1412 | rx_device); |
| 1413 | if (device_group != audio_rx_device_group) |
| 1414 | _audio_rx_clk_disable(); |
| 1415 | |
| 1416 | audio_rx_device_id = rx_device; |
| 1417 | audio_rx_path_id = q6_device_to_path(rx_device, acdb_id); |
| 1418 | |
| 1419 | if (device_group != audio_rx_device_group) |
| 1420 | _audio_rx_clk_enable(); |
| 1421 | |
| 1422 | } |
| 1423 | |
| 1424 | static void _audio_tx_clk_reinit(uint32_t tx_device, uint32_t acdb_id) |
| 1425 | { |
| 1426 | uint32_t device_group = q6_device_to_codec(tx_device); |
| 1427 | |
| 1428 | pr_debug("[%s:%s] tx_device = 0x%x\n", __MM_FILE__, __func__, |
| 1429 | tx_device); |
| 1430 | if (device_group != audio_tx_device_group) |
| 1431 | _audio_tx_clk_disable(); |
| 1432 | |
| 1433 | audio_tx_device_id = tx_device; |
| 1434 | audio_tx_path_id = q6_device_to_path(tx_device, acdb_id); |
| 1435 | |
| 1436 | if (device_group != audio_tx_device_group) |
| 1437 | _audio_tx_clk_enable(); |
| 1438 | } |
| 1439 | |
| 1440 | static DEFINE_MUTEX(audio_path_lock); |
| 1441 | static int audio_rx_path_refcount; |
| 1442 | static int audio_tx_path_refcount; |
| 1443 | |
| 1444 | static int audio_rx_path_enable(int en, uint32_t acdb_id) |
| 1445 | { |
| 1446 | pr_debug("[%s:%s] en = %d\n", __MM_FILE__, __func__, en); |
| 1447 | mutex_lock(&audio_path_lock); |
| 1448 | if (en) { |
| 1449 | audio_rx_path_refcount++; |
| 1450 | if (audio_rx_path_refcount == 1) { |
| 1451 | _audio_rx_clk_enable(); |
| 1452 | _audio_rx_path_enable(0, acdb_id); |
| 1453 | } |
| 1454 | } else { |
| 1455 | audio_rx_path_refcount--; |
| 1456 | if (audio_rx_path_refcount == 0) { |
| 1457 | _audio_rx_path_disable(); |
| 1458 | _audio_rx_clk_disable(); |
| 1459 | } |
| 1460 | } |
| 1461 | mutex_unlock(&audio_path_lock); |
| 1462 | return 0; |
| 1463 | } |
| 1464 | |
| 1465 | static int audio_tx_path_enable(int en, uint32_t acdb_id) |
| 1466 | { |
| 1467 | pr_debug("[%s:%s] en = %d\n", __MM_FILE__, __func__, en); |
| 1468 | mutex_lock(&audio_path_lock); |
| 1469 | if (en) { |
| 1470 | audio_tx_path_refcount++; |
| 1471 | if (audio_tx_path_refcount == 1) { |
| 1472 | _audio_tx_clk_enable(); |
| 1473 | _audio_tx_path_enable(0, acdb_id); |
| 1474 | } |
| 1475 | } else { |
| 1476 | audio_tx_path_refcount--; |
| 1477 | if (audio_tx_path_refcount == 0) { |
| 1478 | _audio_tx_path_disable(); |
| 1479 | _audio_tx_clk_disable(); |
| 1480 | } |
| 1481 | } |
| 1482 | mutex_unlock(&audio_path_lock); |
| 1483 | return 0; |
| 1484 | } |
| 1485 | |
| 1486 | int q6audio_update_acdb(uint32_t id_src, uint32_t id_dst) |
| 1487 | { |
| 1488 | int res; |
| 1489 | |
| 1490 | pr_debug("[%s:%s] id_src = 0x%x\n, id_dst = 0x%x\n", __MM_FILE__, |
| 1491 | __func__, id_src, id_dst); |
| 1492 | if (q6audio_init()) |
| 1493 | return 0; |
| 1494 | |
| 1495 | mutex_lock(&audio_path_lock); |
| 1496 | |
| 1497 | if (q6_device_to_dir(id_dst) == Q6_RX) |
| 1498 | qdsp6_devchg_notify(ac_control, ADSP_AUDIO_RX_DEVICE, id_dst); |
| 1499 | else |
| 1500 | qdsp6_devchg_notify(ac_control, ADSP_AUDIO_TX_DEVICE, id_dst); |
| 1501 | res = audio_update_acdb(id_dst, id_src); |
| 1502 | if (res) |
| 1503 | goto done; |
| 1504 | |
| 1505 | qdsp6_standby(ac_control); |
| 1506 | qdsp6_start(ac_control); |
| 1507 | done: |
| 1508 | mutex_unlock(&audio_path_lock); |
| 1509 | return res; |
| 1510 | } |
| 1511 | |
| 1512 | int q6audio_set_tx_mute(int mute) |
| 1513 | { |
| 1514 | uint32_t adev; |
| 1515 | int rc; |
| 1516 | |
| 1517 | if (q6audio_init()) |
| 1518 | return 0; |
| 1519 | |
| 1520 | mutex_lock(&audio_path_lock); |
| 1521 | |
| 1522 | if (mute == tx_mute_status) { |
| 1523 | mutex_unlock(&audio_path_lock); |
| 1524 | return 0; |
| 1525 | } |
| 1526 | |
| 1527 | adev = audio_tx_device_id; |
| 1528 | rc = audio_tx_mute(ac_control, adev, mute); |
| 1529 | |
| 1530 | /* DSP caches the requested MUTE state when it cannot apply the state |
| 1531 | immediately. In that case, it returns EUNSUPPORTED and applies the |
| 1532 | cached state later */ |
| 1533 | if ((rc == ADSP_AUDIO_STATUS_SUCCESS) || |
| 1534 | (rc == ADSP_AUDIO_STATUS_EUNSUPPORTED)) { |
| 1535 | pr_debug("[%s:%s] return status = %d\n", |
| 1536 | __MM_FILE__, __func__, rc); |
| 1537 | tx_mute_status = mute; |
| 1538 | } |
| 1539 | mutex_unlock(&audio_path_lock); |
| 1540 | return 0; |
| 1541 | } |
| 1542 | |
| 1543 | int q6audio_set_stream_volume(struct audio_client *ac, int vol) |
| 1544 | { |
| 1545 | if (vol > 1200 || vol < -4000) { |
| 1546 | pr_err("[%s:%s] unsupported volume level %d\n", __MM_FILE__, |
| 1547 | __func__, vol); |
| 1548 | return -EINVAL; |
| 1549 | } |
| 1550 | mutex_lock(&audio_path_lock); |
| 1551 | audio_stream_mute(ac, 0); |
| 1552 | audio_stream_volume(ac, vol); |
| 1553 | mutex_unlock(&audio_path_lock); |
| 1554 | return 0; |
| 1555 | } |
| 1556 | |
| 1557 | int q6audio_set_rx_volume(int level) |
| 1558 | { |
| 1559 | uint32_t adev; |
| 1560 | int vol; |
| 1561 | |
| 1562 | pr_debug("[%s:%s] level = %d\n", __MM_FILE__, __func__, level); |
| 1563 | if (q6audio_init()) |
| 1564 | return 0; |
| 1565 | |
| 1566 | if (level < 0 || level > 100) |
| 1567 | return -EINVAL; |
| 1568 | |
| 1569 | mutex_lock(&audio_path_lock); |
| 1570 | adev = ADSP_AUDIO_DEVICE_ID_VOICE; |
| 1571 | |
| 1572 | if (level) { |
| 1573 | vol = q6_device_volume(audio_rx_device_id, level); |
| 1574 | audio_rx_mute(ac_control, adev, 0); |
| 1575 | audio_rx_volume(ac_control, adev, vol); |
| 1576 | } else |
| 1577 | audio_rx_mute(ac_control, adev, 1); |
| 1578 | |
| 1579 | rx_vol_level = level; |
| 1580 | mutex_unlock(&audio_path_lock); |
| 1581 | return 0; |
| 1582 | } |
| 1583 | |
| 1584 | static void do_rx_routing(uint32_t device_id, uint32_t acdb_id) |
| 1585 | { |
| 1586 | pr_debug("[%s:%s] device_id = 0x%x, acdb_id = 0x%x\n", __MM_FILE__, |
| 1587 | __func__, device_id, acdb_id); |
| 1588 | if (device_id == audio_rx_device_id && |
| 1589 | audio_rx_path_id == q6_device_to_path(device_id, acdb_id)) { |
| 1590 | if (acdb_id != rx_acdb) { |
| 1591 | qdsp6_devchg_notify(ac_control, ADSP_AUDIO_RX_DEVICE, device_id); |
| 1592 | audio_update_acdb(device_id, acdb_id); |
| 1593 | qdsp6_standby(ac_control); |
| 1594 | qdsp6_start(ac_control); |
| 1595 | } |
| 1596 | return; |
| 1597 | } |
| 1598 | |
| 1599 | if (audio_rx_path_refcount > 0) { |
| 1600 | qdsp6_devchg_notify(ac_control, ADSP_AUDIO_RX_DEVICE, device_id); |
| 1601 | _audio_rx_path_disable(); |
| 1602 | _audio_rx_clk_reinit(device_id, acdb_id); |
| 1603 | _audio_rx_path_enable(1, acdb_id); |
| 1604 | } else { |
| 1605 | qdsp6_devchg_notify(ac_control, ADSP_AUDIO_RX_DEVICE, |
| 1606 | device_id); |
| 1607 | audio_update_acdb(device_id, acdb_id); |
| 1608 | qdsp6_standby(ac_control); |
| 1609 | qdsp6_start(ac_control); |
| 1610 | audio_rx_device_id = device_id; |
| 1611 | audio_rx_path_id = q6_device_to_path(device_id, acdb_id); |
| 1612 | } |
| 1613 | } |
| 1614 | |
| 1615 | static void do_tx_routing(uint32_t device_id, uint32_t acdb_id) |
| 1616 | { |
| 1617 | pr_debug("[%s:%s] device_id = 0x%x, acdb_id = 0x%x\n", __MM_FILE__, |
| 1618 | __func__, device_id, acdb_id); |
| 1619 | if (device_id == audio_tx_device_id && |
| 1620 | audio_tx_path_id == q6_device_to_path(device_id, acdb_id)) { |
| 1621 | if (acdb_id != tx_acdb) { |
| 1622 | qdsp6_devchg_notify(ac_control, ADSP_AUDIO_TX_DEVICE, |
| 1623 | device_id); |
| 1624 | audio_update_acdb(device_id, acdb_id); |
| 1625 | qdsp6_standby(ac_control); |
| 1626 | qdsp6_start(ac_control); |
| 1627 | } |
| 1628 | return; |
| 1629 | } |
| 1630 | |
| 1631 | if (audio_tx_path_refcount > 0) { |
| 1632 | qdsp6_devchg_notify(ac_control, ADSP_AUDIO_TX_DEVICE, device_id); |
| 1633 | _audio_tx_path_disable(); |
| 1634 | _audio_tx_clk_reinit(device_id, acdb_id); |
| 1635 | _audio_tx_path_enable(1, acdb_id); |
| 1636 | } else { |
| 1637 | qdsp6_devchg_notify(ac_control, ADSP_AUDIO_TX_DEVICE, |
| 1638 | device_id); |
| 1639 | audio_update_acdb(device_id, acdb_id); |
| 1640 | qdsp6_standby(ac_control); |
| 1641 | qdsp6_start(ac_control); |
| 1642 | audio_tx_device_id = device_id; |
| 1643 | audio_tx_path_id = q6_device_to_path(device_id, acdb_id); |
| 1644 | tx_acdb = acdb_id; |
| 1645 | } |
| 1646 | } |
| 1647 | |
| 1648 | int q6audio_do_routing(uint32_t device_id, uint32_t acdb_id) |
| 1649 | { |
| 1650 | if (q6audio_init()) |
| 1651 | return 0; |
| 1652 | |
| 1653 | mutex_lock(&audio_path_lock); |
| 1654 | |
| 1655 | switch(q6_device_to_dir(device_id)) { |
| 1656 | case Q6_RX: |
| 1657 | do_rx_routing(device_id, acdb_id); |
| 1658 | break; |
| 1659 | case Q6_TX: |
| 1660 | do_tx_routing(device_id, acdb_id); |
| 1661 | break; |
| 1662 | } |
| 1663 | |
| 1664 | mutex_unlock(&audio_path_lock); |
| 1665 | return 0; |
| 1666 | } |
| 1667 | |
| 1668 | int q6audio_set_route(const char *name) |
| 1669 | { |
| 1670 | uint32_t route; |
| 1671 | if (!strcmp(name, "speaker")) { |
| 1672 | route = ADIE_PATH_SPEAKER_STEREO_RX; |
| 1673 | } else if (!strcmp(name, "headphones")) { |
| 1674 | route = ADIE_PATH_HEADSET_STEREO_RX; |
| 1675 | } else if (!strcmp(name, "handset")) { |
| 1676 | route = ADIE_PATH_HANDSET_RX; |
| 1677 | } else { |
| 1678 | return -EINVAL; |
| 1679 | } |
| 1680 | |
| 1681 | mutex_lock(&audio_path_lock); |
| 1682 | if (route == audio_rx_path_id) |
| 1683 | goto done; |
| 1684 | |
| 1685 | audio_rx_path_id = route; |
| 1686 | |
| 1687 | if (audio_rx_path_refcount > 0) { |
| 1688 | _audio_rx_path_disable(); |
| 1689 | _audio_rx_path_enable(1, 0); |
| 1690 | } |
| 1691 | if (audio_tx_path_refcount > 0) { |
| 1692 | _audio_tx_path_disable(); |
| 1693 | _audio_tx_path_enable(1, 0); |
| 1694 | } |
| 1695 | done: |
| 1696 | mutex_unlock(&audio_path_lock); |
| 1697 | return 0; |
| 1698 | } |
| 1699 | |
| 1700 | static int audio_stream_equalizer(struct audio_client *ac, void *eq_config) |
| 1701 | { |
| 1702 | int i; |
| 1703 | struct adsp_set_equalizer_command rpc; |
| 1704 | struct adsp_audio_eq_stream_config *eq_cfg; |
| 1705 | eq_cfg = (struct adsp_audio_eq_stream_config *) eq_config; |
| 1706 | |
| 1707 | memset(&rpc, 0, sizeof(rpc)); |
| 1708 | |
| 1709 | rpc.hdr.opcode = ADSP_AUDIO_IOCTL_SET_SESSION_EQ_CONFIG; |
| 1710 | rpc.enable = eq_cfg->enable; |
| 1711 | rpc.num_bands = eq_cfg->num_bands; |
| 1712 | for (i = 0; i < eq_cfg->num_bands; i++) { |
| 1713 | rpc.eq_bands[i].band_idx = eq_cfg->eq_bands[i].band_idx; |
| 1714 | rpc.eq_bands[i].filter_type = eq_cfg->eq_bands[i].filter_type; |
| 1715 | rpc.eq_bands[i].center_freq_hz = |
| 1716 | eq_cfg->eq_bands[i].center_freq_hz; |
| 1717 | rpc.eq_bands[i].filter_gain = eq_cfg->eq_bands[i].filter_gain; |
| 1718 | rpc.eq_bands[i].q_factor = eq_cfg->eq_bands[i].q_factor; |
| 1719 | } |
| 1720 | return audio_ioctl(ac, &rpc, sizeof(rpc)); |
| 1721 | } |
| 1722 | |
| 1723 | int q6audio_set_stream_eq_pcm(struct audio_client *ac, void *eq_config) |
| 1724 | { |
| 1725 | int rc = 0; |
| 1726 | mutex_lock(&audio_path_lock); |
| 1727 | rc = audio_stream_equalizer(ac, eq_config); |
| 1728 | mutex_unlock(&audio_path_lock); |
| 1729 | return rc; |
| 1730 | } |
| 1731 | |
| 1732 | struct audio_client *q6audio_open_auxpcm(uint32_t rate, |
| 1733 | uint32_t channels, uint32_t flags, uint32_t acdb_id) |
| 1734 | { |
| 1735 | int rc, retry = 5; |
| 1736 | struct audio_client *ac; |
| 1737 | |
| 1738 | pr_debug("[%s:%s] rate = %d, channels = %d\n", __MM_FILE__, __func__, |
| 1739 | rate, channels); |
| 1740 | if (q6audio_init()) |
| 1741 | return NULL; |
| 1742 | ac = audio_client_alloc(0); |
| 1743 | if (!ac) |
| 1744 | return NULL; |
| 1745 | |
| 1746 | ac->flags = flags; |
| 1747 | |
| 1748 | mutex_lock(&audio_path_lock); |
| 1749 | |
| 1750 | if (ac->flags & AUDIO_FLAG_WRITE) { |
| 1751 | audio_tx_path_refcount++; |
| 1752 | if (audio_tx_path_refcount == 1) { |
| 1753 | tx_clk_freq = rate; |
| 1754 | _audio_tx_clk_enable(); |
| 1755 | _audio_tx_path_enable(0, acdb_id); |
| 1756 | } |
| 1757 | } else { |
| 1758 | audio_rx_path_refcount++; |
| 1759 | if (audio_rx_path_refcount == 1) { |
| 1760 | _audio_rx_clk_enable(); |
| 1761 | _audio_rx_path_enable(0, acdb_id); |
| 1762 | } |
| 1763 | } |
| 1764 | |
| 1765 | ecodec_clk_enable(); |
| 1766 | |
| 1767 | for (retry = 5;; retry--) { |
| 1768 | if (ac->flags & AUDIO_FLAG_WRITE) |
| 1769 | rc = audio_auxpcm_out_open(ac, rate, channels); |
| 1770 | else |
| 1771 | rc = audio_auxpcm_in_open(ac, rate, channels); |
| 1772 | if (rc == 0) |
| 1773 | break; |
| 1774 | if (retry == 0) |
| 1775 | q6audio_dsp_not_responding(); |
| 1776 | |
| 1777 | pr_err("[%s:%s] open pcm error %d, retrying\n", |
| 1778 | __MM_FILE__, __func__, rc); |
| 1779 | msleep(1); |
| 1780 | } |
| 1781 | |
| 1782 | mutex_unlock(&audio_path_lock); |
| 1783 | |
| 1784 | for (retry = 5;; retry--) { |
| 1785 | rc = audio_command(ac, ADSP_AUDIO_IOCTL_CMD_SESSION_START); |
| 1786 | if (rc == 0) |
| 1787 | break; |
| 1788 | if (retry == 0) |
| 1789 | q6audio_dsp_not_responding(); |
| 1790 | |
| 1791 | pr_err("[%s:%s] stream start error %d, retrying\n", |
| 1792 | __MM_FILE__, __func__, rc); |
| 1793 | } |
| 1794 | audio_prevent_sleep(); |
| 1795 | return ac; |
| 1796 | |
| 1797 | } |
| 1798 | |
| 1799 | struct audio_client *q6audio_open_pcm(uint32_t bufsz, uint32_t rate, |
| 1800 | uint32_t channels, uint32_t flags, uint32_t acdb_id) |
| 1801 | { |
| 1802 | int rc, retry = 5; |
| 1803 | struct audio_client *ac; |
| 1804 | |
| 1805 | pr_debug("[%s:%s] bufsz = %d, rate = %d, channels = %d\n", __MM_FILE__, |
| 1806 | __func__, bufsz, rate, channels); |
| 1807 | if (q6audio_init()) |
| 1808 | return 0; |
| 1809 | |
| 1810 | ac = audio_client_alloc(bufsz); |
| 1811 | if (!ac) |
| 1812 | return 0; |
| 1813 | |
| 1814 | ac->flags = flags; |
| 1815 | |
| 1816 | mutex_lock(&audio_path_lock); |
| 1817 | |
| 1818 | if (ac->flags & AUDIO_FLAG_WRITE) { |
| 1819 | audio_rx_path_refcount++; |
| 1820 | if (audio_rx_path_refcount == 1) { |
| 1821 | _audio_rx_clk_enable(); |
| 1822 | q6_rx_path_enable(0, acdb_id); |
| 1823 | adie_rx_path_enable(acdb_id); |
| 1824 | } |
| 1825 | } else { |
| 1826 | /* TODO: consider concurrency with voice call */ |
| 1827 | audio_tx_path_refcount++; |
| 1828 | if (audio_tx_path_refcount == 1) { |
| 1829 | tx_clk_freq = rate; |
| 1830 | _audio_tx_clk_enable(); |
| 1831 | _audio_tx_path_enable(0, acdb_id); |
| 1832 | } |
| 1833 | } |
| 1834 | |
| 1835 | for (retry = 5;;retry--) { |
| 1836 | if (ac->flags & AUDIO_FLAG_WRITE) |
| 1837 | rc = audio_out_open(ac, bufsz, rate, channels); |
| 1838 | else |
| 1839 | rc = audio_in_open(ac, bufsz, flags, rate, channels); |
| 1840 | if (rc == 0) |
| 1841 | break; |
| 1842 | if (retry == 0) |
| 1843 | q6audio_dsp_not_responding(); |
| 1844 | |
| 1845 | pr_err("[%s:%s] open pcm error %d, retrying\n", |
| 1846 | __MM_FILE__, __func__, rc); |
| 1847 | msleep(1); |
| 1848 | } |
| 1849 | |
| 1850 | if (ac->flags & AUDIO_FLAG_WRITE) { |
| 1851 | if (audio_rx_path_refcount == 1) |
| 1852 | audio_rx_analog_enable(1); |
| 1853 | } |
| 1854 | mutex_unlock(&audio_path_lock); |
| 1855 | |
| 1856 | for (retry = 5;;retry--) { |
| 1857 | rc = audio_command(ac, ADSP_AUDIO_IOCTL_CMD_SESSION_START); |
| 1858 | if (rc == 0) |
| 1859 | break; |
| 1860 | if (retry == 0) |
| 1861 | q6audio_dsp_not_responding(); |
| 1862 | |
| 1863 | pr_err("[%s:%s] stream start error %d, retrying\n", |
| 1864 | __MM_FILE__, __func__, rc); |
| 1865 | } |
| 1866 | |
| 1867 | if (!(ac->flags & AUDIO_FLAG_WRITE)) { |
| 1868 | ac->buf[0].used = 1; |
| 1869 | ac->buf[1].used = 1; |
| 1870 | q6audio_read(ac, &ac->buf[0]); |
| 1871 | q6audio_read(ac, &ac->buf[1]); |
| 1872 | } |
| 1873 | |
| 1874 | audio_prevent_sleep(); |
| 1875 | return ac; |
| 1876 | } |
| 1877 | |
| 1878 | int q6audio_close(struct audio_client *ac) |
| 1879 | { |
| 1880 | audio_close(ac); |
| 1881 | if (ac->flags & AUDIO_FLAG_WRITE) |
| 1882 | audio_rx_path_enable(0, 0); |
| 1883 | else |
| 1884 | audio_tx_path_enable(0, 0); |
| 1885 | audio_client_free(ac); |
| 1886 | audio_allow_sleep(); |
| 1887 | pr_debug("[%s:%s] ac = %p\n", __MM_FILE__, __func__, ac); |
| 1888 | return 0; |
| 1889 | } |
| 1890 | |
| 1891 | int q6audio_auxpcm_close(struct audio_client *ac) |
| 1892 | { |
| 1893 | audio_close(ac); |
| 1894 | if (ac->flags & AUDIO_FLAG_WRITE) { |
| 1895 | audio_tx_path_enable(0, 0); |
| 1896 | ecodec_clk_disable(0, ADSP_PATH_RX); |
| 1897 | } else { |
| 1898 | audio_rx_path_enable(0, 0); |
| 1899 | ecodec_clk_disable(0, ADSP_PATH_TX); |
| 1900 | } |
| 1901 | |
| 1902 | audio_client_free(ac); |
| 1903 | audio_allow_sleep(); |
| 1904 | pr_debug("[%s:%s] ac = %p\n", __MM_FILE__, __func__, ac); |
| 1905 | return 0; |
| 1906 | } |
| 1907 | struct audio_client *q6voice_open(uint32_t flags) |
| 1908 | { |
| 1909 | struct audio_client *ac; |
| 1910 | |
| 1911 | pr_debug("[%s:%s] flags = %d\n", __MM_FILE__, __func__, flags); |
| 1912 | if (q6audio_init()) |
| 1913 | return 0; |
| 1914 | |
| 1915 | ac = audio_client_alloc(0); |
| 1916 | if (!ac) |
| 1917 | return 0; |
| 1918 | |
| 1919 | ac->flags = flags; |
| 1920 | if (ac->flags & AUDIO_FLAG_WRITE) |
| 1921 | audio_rx_path_enable(1, rx_acdb); |
| 1922 | else { |
| 1923 | if (!audio_tx_path_refcount) |
| 1924 | tx_clk_freq = 8000; |
| 1925 | audio_tx_path_enable(1, tx_acdb); |
| 1926 | } |
| 1927 | |
| 1928 | return ac; |
| 1929 | } |
| 1930 | |
| 1931 | int q6voice_close(struct audio_client *ac) |
| 1932 | { |
| 1933 | if (ac->flags & AUDIO_FLAG_WRITE) |
| 1934 | audio_rx_path_enable(0, 0); |
| 1935 | else |
| 1936 | audio_tx_path_enable(0, 0); |
| 1937 | |
| 1938 | tx_mute_status = 0; |
| 1939 | audio_client_free(ac); |
| 1940 | pr_debug("[%s:%s]\n", __MM_FILE__, __func__); |
| 1941 | return 0; |
| 1942 | } |
| 1943 | |
| 1944 | struct audio_client *q6audio_open_mp3(uint32_t bufsz, uint32_t rate, |
| 1945 | uint32_t channels, uint32_t acdb_id) |
| 1946 | { |
| 1947 | struct audio_client *ac; |
| 1948 | |
| 1949 | pr_debug("[%s:%s] bufsz = %d, rate = %d\n, channels = %d", |
| 1950 | __MM_FILE__, __func__, bufsz, rate, channels); |
| 1951 | |
| 1952 | if (q6audio_init()) |
| 1953 | return 0; |
| 1954 | |
| 1955 | ac = audio_client_alloc(bufsz); |
| 1956 | if (!ac) |
| 1957 | return 0; |
| 1958 | |
| 1959 | ac->flags = AUDIO_FLAG_WRITE; |
| 1960 | audio_rx_path_enable(1, acdb_id); |
| 1961 | |
| 1962 | audio_mp3_open(ac, bufsz, rate, channels); |
| 1963 | audio_command(ac, ADSP_AUDIO_IOCTL_CMD_SESSION_START); |
| 1964 | |
| 1965 | mutex_lock(&audio_path_lock); |
| 1966 | audio_rx_mute(ac_control, audio_rx_device_id, 0); |
| 1967 | audio_rx_volume(ac_control, audio_rx_device_id, |
| 1968 | q6_device_volume(audio_rx_device_id, rx_vol_level)); |
| 1969 | mutex_unlock(&audio_path_lock); |
| 1970 | return ac; |
| 1971 | } |
| 1972 | |
| 1973 | struct audio_client *q6audio_open_dtmf(uint32_t rate, |
| 1974 | uint32_t channels, uint32_t acdb_id) |
| 1975 | { |
| 1976 | struct audio_client *ac; |
| 1977 | |
| 1978 | pr_debug("[%s:%s] rate = %d\n, channels = %d", __MM_FILE__, __func__, |
| 1979 | rate, channels); |
| 1980 | if (q6audio_init()) |
| 1981 | return 0; |
| 1982 | |
| 1983 | ac = audio_client_alloc(0); |
| 1984 | if (!ac) |
| 1985 | return 0; |
| 1986 | |
| 1987 | ac->flags = AUDIO_FLAG_WRITE; |
| 1988 | audio_rx_path_enable(1, acdb_id); |
| 1989 | |
| 1990 | audio_dtmf_open(ac, rate, channels); |
| 1991 | audio_command(ac, ADSP_AUDIO_IOCTL_CMD_SESSION_START); |
| 1992 | |
| 1993 | mutex_lock(&audio_path_lock); |
| 1994 | audio_rx_mute(ac_control, audio_rx_device_id, 0); |
| 1995 | audio_rx_volume(ac_control, audio_rx_device_id, |
| 1996 | q6_device_volume(audio_rx_device_id, rx_vol_level)); |
| 1997 | mutex_unlock(&audio_path_lock); |
| 1998 | |
| 1999 | return ac; |
| 2000 | } |
| 2001 | |
| 2002 | int q6audio_play_dtmf(struct audio_client *ac, uint16_t dtmf_hi, |
| 2003 | uint16_t dtmf_low, uint16_t duration, uint16_t rx_gain) |
| 2004 | { |
| 2005 | struct adsp_audio_dtmf_start_command dtmf_cmd; |
| 2006 | |
| 2007 | pr_debug("[%s:%s] high = %d, low = %d\n", __MM_FILE__, __func__, |
| 2008 | dtmf_hi, dtmf_low); |
| 2009 | |
| 2010 | dtmf_cmd.hdr.opcode = ADSP_AUDIO_IOCTL_CMD_SESSION_DTMF_START; |
| 2011 | dtmf_cmd.hdr.response_type = ADSP_AUDIO_RESPONSE_COMMAND; |
| 2012 | dtmf_cmd.tone1_hz = dtmf_hi; |
| 2013 | dtmf_cmd.tone2_hz = dtmf_low; |
| 2014 | dtmf_cmd.duration_usec = duration * 1000; |
| 2015 | dtmf_cmd.gain_mb = rx_gain; |
| 2016 | |
| 2017 | return audio_ioctl(ac, &dtmf_cmd, |
| 2018 | sizeof(struct adsp_audio_dtmf_start_command)); |
| 2019 | |
| 2020 | } |
| 2021 | |
| 2022 | int q6audio_mp3_close(struct audio_client *ac) |
| 2023 | { |
| 2024 | pr_debug("[%s:%s]\n", __MM_FILE__, __func__); |
| 2025 | audio_close(ac); |
| 2026 | audio_rx_path_enable(0, 0); |
| 2027 | audio_client_free(ac); |
| 2028 | return 0; |
| 2029 | } |
| 2030 | |
| 2031 | |
| 2032 | struct audio_client *q6audio_open_aac(uint32_t bufsz, uint32_t samplerate, |
| 2033 | uint32_t channels, uint32_t bitrate, |
| 2034 | uint32_t stream_format, uint32_t flags, |
| 2035 | uint32_t acdb_id) |
| 2036 | { |
| 2037 | struct audio_client *ac; |
| 2038 | |
| 2039 | pr_debug("[%s:%s] bufsz = %d, samplerate = %d, channels = %d\n", |
| 2040 | __MM_FILE__, __func__, bufsz, samplerate, channels); |
| 2041 | |
| 2042 | if (q6audio_init()) |
| 2043 | return 0; |
| 2044 | |
| 2045 | ac = audio_client_alloc(bufsz); |
| 2046 | if (!ac) |
| 2047 | return 0; |
| 2048 | |
| 2049 | ac->flags = flags; |
| 2050 | |
| 2051 | if (ac->flags & AUDIO_FLAG_WRITE) |
| 2052 | audio_rx_path_enable(1, acdb_id); |
| 2053 | else{ |
| 2054 | if (!audio_tx_path_refcount) |
| 2055 | tx_clk_freq = 48000; |
| 2056 | audio_tx_path_enable(1, acdb_id); |
| 2057 | } |
| 2058 | |
| 2059 | audio_aac_open(ac, bufsz, samplerate, channels, bitrate, flags, |
| 2060 | stream_format); |
| 2061 | audio_command(ac, ADSP_AUDIO_IOCTL_CMD_SESSION_START); |
| 2062 | |
| 2063 | if (!(ac->flags & AUDIO_FLAG_WRITE)) { |
| 2064 | ac->buf[0].used = 1; |
| 2065 | ac->buf[1].used = 1; |
| 2066 | q6audio_read(ac, &ac->buf[0]); |
| 2067 | q6audio_read(ac, &ac->buf[1]); |
| 2068 | } |
| 2069 | audio_prevent_sleep(); |
| 2070 | return ac; |
| 2071 | } |
| 2072 | |
| 2073 | |
| 2074 | struct audio_client *q6audio_open_qcp(uint32_t bufsz, uint32_t min_rate, |
| 2075 | uint32_t max_rate, uint32_t flags, |
| 2076 | uint32_t format, uint32_t acdb_id) |
| 2077 | { |
| 2078 | struct audio_client *ac; |
| 2079 | |
| 2080 | pr_debug("[%s:%s] bufsz = %d\n", __MM_FILE__, __func__, bufsz); |
| 2081 | |
| 2082 | if (q6audio_init()) |
| 2083 | return 0; |
| 2084 | |
| 2085 | ac = audio_client_alloc(bufsz); |
| 2086 | if (!ac) |
| 2087 | return 0; |
| 2088 | |
| 2089 | ac->flags = flags; |
| 2090 | |
| 2091 | if (ac->flags & AUDIO_FLAG_WRITE) |
| 2092 | audio_rx_path_enable(1, acdb_id); |
| 2093 | else{ |
| 2094 | if (!audio_tx_path_refcount) |
| 2095 | tx_clk_freq = 8000; |
| 2096 | audio_tx_path_enable(1, acdb_id); |
| 2097 | } |
| 2098 | |
| 2099 | audio_qcp_open(ac, bufsz, min_rate, max_rate, flags, format); |
| 2100 | audio_command(ac, ADSP_AUDIO_IOCTL_CMD_SESSION_START); |
| 2101 | |
| 2102 | if (!(ac->flags & AUDIO_FLAG_WRITE)) { |
| 2103 | ac->buf[0].used = 1; |
| 2104 | ac->buf[1].used = 1; |
| 2105 | q6audio_read(ac, &ac->buf[0]); |
| 2106 | q6audio_read(ac, &ac->buf[1]); |
| 2107 | } |
| 2108 | audio_prevent_sleep(); |
| 2109 | return ac; |
| 2110 | } |
| 2111 | |
| 2112 | struct audio_client *q6audio_open_amrnb(uint32_t bufsz, uint32_t enc_mode, |
| 2113 | uint32_t dtx_mode_enable, |
| 2114 | uint32_t flags, uint32_t acdb_id) |
| 2115 | { |
| 2116 | struct audio_client *ac; |
| 2117 | |
| 2118 | pr_debug("[%s:%s] bufsz = %d, dtx_mode = %d\n", __MM_FILE__, |
| 2119 | __func__, bufsz, dtx_mode_enable); |
| 2120 | |
| 2121 | if (q6audio_init()) |
| 2122 | return 0; |
| 2123 | |
| 2124 | ac = audio_client_alloc(bufsz); |
| 2125 | if (!ac) |
| 2126 | return 0; |
| 2127 | |
| 2128 | ac->flags = flags; |
| 2129 | if (ac->flags & AUDIO_FLAG_WRITE) |
| 2130 | audio_rx_path_enable(1, acdb_id); |
| 2131 | else{ |
| 2132 | if (!audio_tx_path_refcount) |
| 2133 | tx_clk_freq = 8000; |
| 2134 | audio_tx_path_enable(1, acdb_id); |
| 2135 | } |
| 2136 | |
| 2137 | audio_amrnb_open(ac, bufsz, enc_mode, flags, dtx_mode_enable); |
| 2138 | audio_command(ac, ADSP_AUDIO_IOCTL_CMD_SESSION_START); |
| 2139 | |
| 2140 | if (!(ac->flags & AUDIO_FLAG_WRITE)) { |
| 2141 | ac->buf[0].used = 1; |
| 2142 | ac->buf[1].used = 1; |
| 2143 | q6audio_read(ac, &ac->buf[0]); |
| 2144 | q6audio_read(ac, &ac->buf[1]); |
| 2145 | } |
| 2146 | audio_prevent_sleep(); |
| 2147 | return ac; |
| 2148 | } |
| 2149 | |
| 2150 | int q6audio_async(struct audio_client *ac) |
| 2151 | { |
| 2152 | struct adsp_command_hdr rpc; |
| 2153 | pr_debug("[%s:%s] ac = %p\n", __MM_FILE__, __func__, ac); |
| 2154 | memset(&rpc, 0, sizeof(rpc)); |
| 2155 | rpc.opcode = ADSP_AUDIO_IOCTL_CMD_STREAM_EOS; |
| 2156 | rpc.response_type = ADSP_AUDIO_RESPONSE_ASYNC; |
| 2157 | return audio_ioctl(ac, &rpc, sizeof(rpc)); |
| 2158 | } |