Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | /* arch/arm/mach-msm/qdsp6/audiov2/audio_ctrl.c |
| 2 | * |
| 3 | * Copyright (C) 2009 Google, Inc. |
| 4 | * Copyright (C) 2009 HTC Corporation |
Duy Truong | 790f06d | 2013-02-13 16:38:12 -0800 | [diff] [blame^] | 5 | * Copyright (c) 2009, The Linux Foundation. All rights reserved. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6 | * |
| 7 | * This software is licensed under the terms of the GNU General Public |
| 8 | * License version 2, as published by the Free Software Foundation, and |
| 9 | * may be copied, distributed, and modified under those terms. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | */ |
| 17 | |
| 18 | #include <linux/fs.h> |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/miscdevice.h> |
| 21 | #include <linux/uaccess.h> |
| 22 | #include <linux/msm_audio.h> |
| 23 | |
| 24 | #include <mach/msm_qdsp6_audiov2.h> |
| 25 | |
| 26 | #define BUFSZ (0) |
| 27 | |
| 28 | static DEFINE_MUTEX(voice_lock); |
| 29 | static int voice_started; |
| 30 | |
| 31 | static struct audio_client *voc_clnt; |
| 32 | |
| 33 | static int q6_voice_start(void) |
| 34 | { |
| 35 | int rc = 0; |
| 36 | |
| 37 | mutex_lock(&voice_lock); |
| 38 | |
| 39 | if (voice_started) { |
| 40 | pr_err("voice: busy\n"); |
| 41 | rc = -EBUSY; |
| 42 | goto done; |
| 43 | } |
| 44 | |
| 45 | voc_clnt = q6voice_open(); |
| 46 | if (!voc_clnt) { |
| 47 | pr_err("voice: open voice failed.\n"); |
| 48 | rc = -ENOMEM; |
| 49 | goto done; |
| 50 | } |
| 51 | |
| 52 | voice_started = 1; |
| 53 | done: |
| 54 | mutex_unlock(&voice_lock); |
| 55 | return rc; |
| 56 | } |
| 57 | |
| 58 | static int q6_voice_stop(void) |
| 59 | { |
| 60 | mutex_lock(&voice_lock); |
| 61 | if (voice_started) { |
| 62 | q6voice_close(voc_clnt); |
| 63 | voice_started = 0; |
| 64 | } |
| 65 | mutex_unlock(&voice_lock); |
| 66 | return 0; |
| 67 | } |
| 68 | |
| 69 | static int q6_open(struct inode *inode, struct file *file) |
| 70 | { |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | static int q6_ioctl(struct inode *inode, struct file *file, |
| 75 | unsigned int cmd, unsigned long arg) |
| 76 | { |
| 77 | int rc; |
| 78 | uint32_t n; |
| 79 | uint32_t id[2]; |
| 80 | |
| 81 | switch (cmd) { |
| 82 | case AUDIO_SWITCH_DEVICE: |
| 83 | rc = copy_from_user(&n, (void *)arg, sizeof(n)); |
| 84 | if (!rc) |
| 85 | rc = q6audio_do_routing(n); |
| 86 | break; |
| 87 | case AUDIO_SET_VOLUME: |
| 88 | rc = copy_from_user(&n, (void *)arg, sizeof(n)); |
| 89 | if (!rc) |
| 90 | rc = q6audio_set_rx_volume(n); |
| 91 | break; |
| 92 | case AUDIO_SET_MUTE: |
| 93 | rc = copy_from_user(&n, (void *)arg, sizeof(n)); |
| 94 | if (!rc) |
| 95 | rc = q6audio_set_tx_mute(n); |
| 96 | break; |
| 97 | case AUDIO_UPDATE_ACDB: |
| 98 | rc = copy_from_user(&id, (void *)arg, sizeof(id)); |
| 99 | if (!rc) |
| 100 | rc = q6audio_update_acdb(id[0], id[1]); |
| 101 | break; |
| 102 | case AUDIO_START_VOICE: |
| 103 | rc = q6_voice_start(); |
| 104 | break; |
| 105 | case AUDIO_STOP_VOICE: |
| 106 | rc = q6_voice_stop(); |
| 107 | break; |
| 108 | default: |
| 109 | rc = -EINVAL; |
| 110 | } |
| 111 | |
| 112 | return rc; |
| 113 | } |
| 114 | |
| 115 | |
| 116 | static int q6_release(struct inode *inode, struct file *file) |
| 117 | { |
| 118 | return 0; |
| 119 | } |
| 120 | |
| 121 | static const struct file_operations q6_dev_fops = { |
| 122 | .owner = THIS_MODULE, |
| 123 | .open = q6_open, |
| 124 | .ioctl = q6_ioctl, |
| 125 | .release = q6_release, |
| 126 | }; |
| 127 | |
| 128 | struct miscdevice q6_control_device = { |
| 129 | .minor = MISC_DYNAMIC_MINOR, |
| 130 | .name = "msm_audio_ctl", |
| 131 | .fops = &q6_dev_fops, |
| 132 | }; |
| 133 | |
| 134 | |
| 135 | static int __init q6_audio_ctl_init(void) |
| 136 | { |
| 137 | return misc_register(&q6_control_device); |
| 138 | } |
| 139 | |
| 140 | device_initcall(q6_audio_ctl_init); |