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