aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/intel/sst-atom-controls.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/soc/intel/sst-atom-controls.c')
-rw-r--r--sound/soc/intel/sst-atom-controls.c218
1 files changed, 218 insertions, 0 deletions
diff --git a/sound/soc/intel/sst-atom-controls.c b/sound/soc/intel/sst-atom-controls.c
new file mode 100644
index 000000000000..7104a34181a9
--- /dev/null
+++ b/sound/soc/intel/sst-atom-controls.c
@@ -0,0 +1,218 @@
1/*
2 * sst-atom-controls.c - Intel MID Platform driver DPCM ALSA controls for Mrfld
3 *
4 * Copyright (C) 2013-14 Intel Corp
5 * Author: Omair Mohammed Abdullah <omair.m.abdullah@intel.com>
6 * Vinod Koul <vinod.koul@intel.com>
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2 of the License.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19 */
20#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
21
22#include <linux/slab.h>
23#include <sound/soc.h>
24#include <sound/tlv.h>
25#include "sst-mfld-platform.h"
26#include "sst-atom-controls.h"
27
28static int sst_fill_byte_control(struct sst_data *drv,
29 u8 ipc_msg, u8 block,
30 u8 task_id, u8 pipe_id,
31 u16 len, void *cmd_data)
32{
33 struct snd_sst_bytes_v2 *byte_data = drv->byte_stream;
34
35 byte_data->type = SST_CMD_BYTES_SET;
36 byte_data->ipc_msg = ipc_msg;
37 byte_data->block = block;
38 byte_data->task_id = task_id;
39 byte_data->pipe_id = pipe_id;
40
41 if (len > SST_MAX_BIN_BYTES - sizeof(*byte_data)) {
42 dev_err(&drv->pdev->dev, "command length too big (%u)", len);
43 return -EINVAL;
44 }
45 byte_data->len = len;
46 memcpy(byte_data->bytes, cmd_data, len);
47 print_hex_dump_bytes("writing to lpe: ", DUMP_PREFIX_OFFSET,
48 byte_data, len + sizeof(*byte_data));
49 return 0;
50}
51
52static int sst_fill_and_send_cmd_unlocked(struct sst_data *drv,
53 u8 ipc_msg, u8 block, u8 task_id, u8 pipe_id,
54 void *cmd_data, u16 len)
55{
56 int ret = 0;
57
58 ret = sst_fill_byte_control(drv, ipc_msg,
59 block, task_id, pipe_id, len, cmd_data);
60 if (ret < 0)
61 return ret;
62 return sst->ops->send_byte_stream(sst->dev, drv->byte_stream);
63}
64
65/**
66 * sst_fill_and_send_cmd - generate the IPC message and send it to the FW
67 * @ipc_msg: type of IPC (CMD, SET_PARAMS, GET_PARAMS)
68 * @cmd_data: the IPC payload
69 */
70static int sst_fill_and_send_cmd(struct sst_data *drv,
71 u8 ipc_msg, u8 block, u8 task_id, u8 pipe_id,
72 void *cmd_data, u16 len)
73{
74 int ret;
75
76 mutex_lock(&drv->lock);
77 ret = sst_fill_and_send_cmd_unlocked(drv, ipc_msg, block,
78 task_id, pipe_id, cmd_data, len);
79 mutex_unlock(&drv->lock);
80
81 return ret;
82}
83
84static int sst_send_algo_cmd(struct sst_data *drv,
85 struct sst_algo_control *bc)
86{
87 int len, ret = 0;
88 struct sst_cmd_set_params *cmd;
89
90 /*bc->max includes sizeof algos + length field*/
91 len = sizeof(cmd->dst) + sizeof(cmd->command_id) + bc->max;
92
93 cmd = kzalloc(len, GFP_KERNEL);
94 if (cmd == NULL)
95 return -ENOMEM;
96
97 SST_FILL_DESTINATION(2, cmd->dst, bc->pipe_id, bc->module_id);
98 cmd->command_id = bc->cmd_id;
99 memcpy(cmd->params, bc->params, bc->max);
100
101 ret = sst_fill_and_send_cmd_unlocked(drv, SST_IPC_IA_SET_PARAMS,
102 SST_FLAG_BLOCKED, bc->task_id, 0, cmd, len);
103 kfree(cmd);
104 return ret;
105}
106
107static int sst_algo_bytes_ctl_info(struct snd_kcontrol *kcontrol,
108 struct snd_ctl_elem_info *uinfo)
109{
110 struct sst_algo_control *bc = (void *)kcontrol->private_value;
111
112 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
113 uinfo->count = bc->max;
114
115 return 0;
116}
117
118static int sst_algo_control_get(struct snd_kcontrol *kcontrol,
119 struct snd_ctl_elem_value *ucontrol)
120{
121 struct sst_algo_control *bc = (void *)kcontrol->private_value;
122 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
123
124 switch (bc->type) {
125 case SST_ALGO_PARAMS:
126 memcpy(ucontrol->value.bytes.data, bc->params, bc->max);
127 break;
128 default:
129 dev_err(component->dev, "Invalid Input- algo type:%d\n",
130 bc->type);
131 return -EINVAL;
132
133 }
134 return 0;
135}
136
137static int sst_algo_control_set(struct snd_kcontrol *kcontrol,
138 struct snd_ctl_elem_value *ucontrol)
139{
140 int ret = 0;
141 struct snd_soc_component *cmpnt = snd_soc_kcontrol_component(kcontrol);
142 struct sst_data *drv = snd_soc_component_get_drvdata(cmpnt);
143 struct sst_algo_control *bc = (void *)kcontrol->private_value;
144
145 dev_dbg(cmpnt->dev, "control_name=%s\n", kcontrol->id.name);
146 mutex_lock(&drv->lock);
147 switch (bc->type) {
148 case SST_ALGO_PARAMS:
149 memcpy(bc->params, ucontrol->value.bytes.data, bc->max);
150 break;
151 default:
152 mutex_unlock(&drv->lock);
153 dev_err(cmpnt->dev, "Invalid Input- algo type:%d\n",
154 bc->type);
155 return -EINVAL;
156 }
157 /*if pipe is enabled, need to send the algo params from here*/
158 if (bc->w && bc->w->power)
159 ret = sst_send_algo_cmd(drv, bc);
160 mutex_unlock(&drv->lock);
161
162 return ret;
163}
164
165static const struct snd_kcontrol_new sst_algo_controls[] = {
166 SST_ALGO_KCONTROL_BYTES("media_loop1_out", "fir", 272, SST_MODULE_ID_FIR_24,
167 SST_PATH_INDEX_MEDIA_LOOP1_OUT, 0, SST_TASK_SBA, SBA_VB_SET_FIR),
168 SST_ALGO_KCONTROL_BYTES("media_loop1_out", "iir", 300, SST_MODULE_ID_IIR_24,
169 SST_PATH_INDEX_MEDIA_LOOP1_OUT, 0, SST_TASK_SBA, SBA_VB_SET_IIR),
170 SST_ALGO_KCONTROL_BYTES("media_loop1_out", "mdrp", 286, SST_MODULE_ID_MDRP,
171 SST_PATH_INDEX_MEDIA_LOOP1_OUT, 0, SST_TASK_SBA, SBA_SET_MDRP),
172 SST_ALGO_KCONTROL_BYTES("media_loop2_out", "fir", 272, SST_MODULE_ID_FIR_24,
173 SST_PATH_INDEX_MEDIA_LOOP2_OUT, 0, SST_TASK_SBA, SBA_VB_SET_FIR),
174 SST_ALGO_KCONTROL_BYTES("media_loop2_out", "iir", 300, SST_MODULE_ID_IIR_24,
175 SST_PATH_INDEX_MEDIA_LOOP2_OUT, 0, SST_TASK_SBA, SBA_VB_SET_IIR),
176 SST_ALGO_KCONTROL_BYTES("media_loop2_out", "mdrp", 286, SST_MODULE_ID_MDRP,
177 SST_PATH_INDEX_MEDIA_LOOP2_OUT, 0, SST_TASK_SBA, SBA_SET_MDRP),
178 SST_ALGO_KCONTROL_BYTES("sprot_loop_out", "lpro", 192, SST_MODULE_ID_SPROT,
179 SST_PATH_INDEX_SPROT_LOOP_OUT, 0, SST_TASK_SBA, SBA_VB_LPRO),
180 SST_ALGO_KCONTROL_BYTES("codec_in0", "dcr", 52, SST_MODULE_ID_FILT_DCR,
181 SST_PATH_INDEX_CODEC_IN0, 0, SST_TASK_SBA, SBA_VB_SET_IIR),
182 SST_ALGO_KCONTROL_BYTES("codec_in1", "dcr", 52, SST_MODULE_ID_FILT_DCR,
183 SST_PATH_INDEX_CODEC_IN1, 0, SST_TASK_SBA, SBA_VB_SET_IIR),
184
185};
186
187static int sst_algo_control_init(struct device *dev)
188{
189 int i = 0;
190 struct sst_algo_control *bc;
191 /*allocate space to cache the algo parameters in the driver*/
192 for (i = 0; i < ARRAY_SIZE(sst_algo_controls); i++) {
193 bc = (struct sst_algo_control *)sst_algo_controls[i].private_value;
194 bc->params = devm_kzalloc(dev, bc->max, GFP_KERNEL);
195 if (bc->params == NULL)
196 return -ENOMEM;
197 }
198 return 0;
199}
200
201int sst_dsp_init_v2_dpcm(struct snd_soc_platform *platform)
202{
203 int ret = 0;
204 struct sst_data *drv = snd_soc_platform_get_drvdata(platform);
205
206 drv->byte_stream = devm_kzalloc(platform->dev,
207 SST_MAX_BIN_BYTES, GFP_KERNEL);
208 if (!drv->byte_stream)
209 return -ENOMEM;
210
211 /*Initialize algo control params*/
212 ret = sst_algo_control_init(platform->dev);
213 if (ret)
214 return ret;
215 ret = snd_soc_add_platform_controls(platform, sst_algo_controls,
216 ARRAY_SIZE(sst_algo_controls));
217 return ret;
218}