blob: 7335951522b37f309c7b7325d1a36ea4c00d67cd [file] [log] [blame]
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301/* Copyright (c) 2014, 2016-2017 The Linux Foundation. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#include <linux/kernel.h>
14#include <linux/platform_device.h>
15#include <linux/err.h>
16#include <linux/module.h>
17#include <sound/hwdep.h>
18#include <sound/devdep_params.h>
19#include "msm-pcm-routing-devdep.h"
20#include "msm-ds2-dap-config.h"
21
22#ifdef CONFIG_SND_HWDEP
23static int msm_pcm_routing_hwdep_open(struct snd_hwdep *hw, struct file *file)
24{
25 pr_debug("%s\n", __func__);
26 msm_ds2_dap_update_port_parameters(hw, file, true);
27 return 0;
28}
29
30static int msm_pcm_routing_hwdep_release(struct snd_hwdep *hw,
31 struct file *file)
32{
33 pr_debug("%s\n", __func__);
34 msm_ds2_dap_update_port_parameters(hw, file, false);
35 return 0;
36}
37
38static int msm_pcm_routing_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
39 unsigned int cmd, unsigned long arg)
40{
41 int ret = 0;
42 void __user *argp = (void __user *)arg;
43
44 pr_debug("%s:cmd %x\n", __func__, cmd);
45 switch (cmd) {
46 case SNDRV_DEVDEP_DAP_IOCTL_SET_PARAM:
47 case SNDRV_DEVDEP_DAP_IOCTL_GET_PARAM:
48 case SNDRV_DEVDEP_DAP_IOCTL_DAP_COMMAND:
49 case SNDRV_DEVDEP_DAP_IOCTL_DAP_LICENSE:
50 msm_pcm_routing_acquire_lock();
51 ret = msm_ds2_dap_ioctl(hw, file, cmd, argp);
52 msm_pcm_routing_release_lock();
53 break;
54 case SNDRV_DEVDEP_DAP_IOCTL_GET_VISUALIZER:
55 ret = msm_ds2_dap_ioctl(hw, file, cmd, argp);
56 break;
57 default:
58 pr_err("%s called with invalid control 0x%X\n", __func__, cmd);
59 ret = -EINVAL;
60 break;
61 }
62 return ret;
63}
64
65void msm_pcm_routing_hwdep_free(struct snd_pcm *pcm)
66{
67 pr_debug("%s\n", __func__);
68}
69
70#ifdef CONFIG_COMPAT
71static int msm_pcm_routing_hwdep_compat_ioctl(struct snd_hwdep *hw,
72 struct file *file,
73 unsigned int cmd,
74 unsigned long arg)
75{
76 int ret = 0;
77 void __user *argp = (void __user *)arg;
78
79 pr_debug("%s:cmd %x\n", __func__, cmd);
80 switch (cmd) {
81 case SNDRV_DEVDEP_DAP_IOCTL_SET_PARAM32:
82 case SNDRV_DEVDEP_DAP_IOCTL_GET_PARAM32:
83 case SNDRV_DEVDEP_DAP_IOCTL_DAP_COMMAND32:
84 case SNDRV_DEVDEP_DAP_IOCTL_DAP_LICENSE32:
85 msm_pcm_routing_acquire_lock();
86 ret = msm_ds2_dap_compat_ioctl(hw, file, cmd, argp);
87 msm_pcm_routing_release_lock();
88 break;
89 case SNDRV_DEVDEP_DAP_IOCTL_GET_VISUALIZER32:
90 ret = msm_ds2_dap_compat_ioctl(hw, file, cmd, argp);
91 break;
92 default:
93 pr_err("%s called with invalid control 0x%X\n", __func__, cmd);
94 ret = -EINVAL;
95 break;
96 }
97 return ret;
98}
99#endif
100
101int msm_pcm_routing_hwdep_new(struct snd_soc_pcm_runtime *runtime,
102 struct msm_pcm_routing_bdai_data *msm_bedais)
103{
104 struct snd_hwdep *hwdep;
105 struct snd_soc_dai_link *dai_link = runtime->dai_link;
106 int rc;
107
108 if (dai_link->id < 0 ||
109 dai_link->id >= MSM_BACKEND_DAI_MAX) {
110 pr_err("%s:BE id %d invalid index\n",
111 __func__, dai_link->id);
112 return -EINVAL;
113 }
114 pr_debug("%s BE id %d\n", __func__, dai_link->id);
115 rc = snd_hwdep_new(runtime->card->snd_card,
116 msm_bedais[dai_link->id].name,
117 dai_link->id, &hwdep);
118 if (hwdep == NULL) {
119 pr_err("%s: hwdep intf failed to create %s- hwdep NULL\n",
120 __func__, msm_bedais[dai_link->id].name);
121 return rc;
122 }
123 if (rc < 0) {
124 pr_err("%s: hwdep intf failed to create %s rc %d\n", __func__,
125 msm_bedais[dai_link->id].name, rc);
126 return rc;
127 }
128
129 hwdep->iface = SNDRV_HWDEP_IFACE_AUDIO_BE;
130 hwdep->private_data = &msm_bedais[dai_link->id];
131 hwdep->ops.open = msm_pcm_routing_hwdep_open;
132 hwdep->ops.ioctl = msm_pcm_routing_hwdep_ioctl;
133 hwdep->ops.release = msm_pcm_routing_hwdep_release;
134#ifdef CONFIG_COMPAT
135 hwdep->ops.ioctl_compat = msm_pcm_routing_hwdep_compat_ioctl;
136#endif
137 return rc;
138}
139#endif