aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVinod Koul <vinod.koul@intel.com>2014-09-09 05:41:25 -0400
committerMark Brown <broonie@kernel.org>2014-09-16 14:53:53 -0400
commit10615a5c49721803ed258316280858142a24e72a (patch)
tree6a90ae137609be77bf3492b1d7a06aeae26e8f62
parentd2b16b8fa1b6352757cd0a58234591e1496a82ad (diff)
ASoC: Intel: mrfld: add bytes control for modules
This patch add support for various modules like eq etc for mrfld DSP. All these modules will be exposed to usermode as bytes controls. Signed-off-by: Vinod Koul <vinod.koul@intel.com> Signed-off-by: Subhransu S. Prusty <subhransu.s.prusty@intel.com> Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r--sound/soc/intel/sst-atom-controls.c179
-rw-r--r--sound/soc/intel/sst-atom-controls.h130
-rw-r--r--sound/soc/intel/sst-mfld-platform.h2
3 files changed, 310 insertions, 1 deletions
diff --git a/sound/soc/intel/sst-atom-controls.c b/sound/soc/intel/sst-atom-controls.c
index ace3c4a59b14..7104a34181a9 100644
--- a/sound/soc/intel/sst-atom-controls.c
+++ b/sound/soc/intel/sst-atom-controls.c
@@ -25,6 +25,179 @@
25#include "sst-mfld-platform.h" 25#include "sst-mfld-platform.h"
26#include "sst-atom-controls.h" 26#include "sst-atom-controls.h"
27 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
28int sst_dsp_init_v2_dpcm(struct snd_soc_platform *platform) 201int sst_dsp_init_v2_dpcm(struct snd_soc_platform *platform)
29{ 202{
30 int ret = 0; 203 int ret = 0;
@@ -35,5 +208,11 @@ int sst_dsp_init_v2_dpcm(struct snd_soc_platform *platform)
35 if (!drv->byte_stream) 208 if (!drv->byte_stream)
36 return -ENOMEM; 209 return -ENOMEM;
37 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));
38 return ret; 217 return ret;
39} 218}
diff --git a/sound/soc/intel/sst-atom-controls.h b/sound/soc/intel/sst-atom-controls.h
index 8554889c0694..a73e894b175c 100644
--- a/sound/soc/intel/sst-atom-controls.h
+++ b/sound/soc/intel/sst-atom-controls.h
@@ -309,4 +309,134 @@ enum sst_swm_state {
309 SST_SWM_ON = 3, 309 SST_SWM_ON = 3,
310}; 310};
311 311
312#define SST_FILL_LOCATION_IDS(dst, cell_idx, pipe_id) do { \
313 dst.location_id.p.cell_nbr_idx = (cell_idx); \
314 dst.location_id.p.path_id = (pipe_id); \
315 } while (0)
316#define SST_FILL_LOCATION_ID(dst, loc_id) (\
317 dst.location_id.f = (loc_id))
318#define SST_FILL_MODULE_ID(dst, mod_id) (\
319 dst.module_id = (mod_id))
320
321#define SST_FILL_DESTINATION1(dst, id) do { \
322 SST_FILL_LOCATION_ID(dst, (id) & 0xFFFF); \
323 SST_FILL_MODULE_ID(dst, ((id) & 0xFFFF0000) >> 16); \
324 } while (0)
325#define SST_FILL_DESTINATION2(dst, loc_id, mod_id) do { \
326 SST_FILL_LOCATION_ID(dst, loc_id); \
327 SST_FILL_MODULE_ID(dst, mod_id); \
328 } while (0)
329#define SST_FILL_DESTINATION3(dst, cell_idx, path_id, mod_id) do { \
330 SST_FILL_LOCATION_IDS(dst, cell_idx, path_id); \
331 SST_FILL_MODULE_ID(dst, mod_id); \
332 } while (0)
333
334#define SST_FILL_DESTINATION(level, dst, ...) \
335 SST_FILL_DESTINATION##level(dst, __VA_ARGS__)
336#define SST_FILL_DEFAULT_DESTINATION(dst) \
337 SST_FILL_DESTINATION(2, dst, SST_DEFAULT_LOCATION_ID, SST_DEFAULT_MODULE_ID)
338
339struct sst_destination_id {
340 union sst_location_id {
341 struct {
342 u8 cell_nbr_idx; /* module index */
343 u8 path_id; /* pipe_id */
344 } __packed p; /* part */
345 u16 f; /* full */
346 } __packed location_id;
347 u16 module_id;
348} __packed;
349struct sst_dsp_header {
350 struct sst_destination_id dst;
351 u16 command_id;
352 u16 length;
353} __packed;
354
355/*
356 *
357 * Common Commands
358 *
359 */
360struct sst_cmd_generic {
361 struct sst_dsp_header header;
362} __packed;
363struct sst_cmd_set_params {
364 struct sst_destination_id dst;
365 u16 command_id;
366 char params[0];
367} __packed;
368#define SST_CONTROL_NAME(xpname, xmname, xinstance, xtype) \
369 xpname " " xmname " " #xinstance " " xtype
370
371#define SST_COMBO_CONTROL_NAME(xpname, xmname, xinstance, xtype, xsubmodule) \
372 xpname " " xmname " " #xinstance " " xtype " " xsubmodule
373enum sst_algo_kcontrol_type {
374 SST_ALGO_PARAMS,
375 SST_ALGO_BYPASS,
376};
377
378struct sst_algo_control {
379 enum sst_algo_kcontrol_type type;
380 int max;
381 u16 module_id;
382 u16 pipe_id;
383 u16 task_id;
384 u16 cmd_id;
385 bool bypass;
386 unsigned char *params;
387 struct snd_soc_dapm_widget *w;
388};
389
390/* size of the control = size of params + size of length field */
391#define SST_ALGO_CTL_VALUE(xcount, xtype, xpipe, xmod, xtask, xcmd) \
392 (struct sst_algo_control){ \
393 .max = xcount + sizeof(u16), .type = xtype, .module_id = xmod, \
394 .pipe_id = xpipe, .task_id = xtask, .cmd_id = xcmd, \
395 }
396
397#define SST_ALGO_KCONTROL(xname, xcount, xmod, xpipe, \
398 xtask, xcmd, xtype, xinfo, xget, xput) \
399{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
400 .name = xname, \
401 .info = xinfo, .get = xget, .put = xput, \
402 .private_value = (unsigned long)& \
403 SST_ALGO_CTL_VALUE(xcount, xtype, xpipe, \
404 xmod, xtask, xcmd), \
405}
406
407#define SST_ALGO_KCONTROL_BYTES(xpname, xmname, xcount, xmod, \
408 xpipe, xinstance, xtask, xcmd) \
409 SST_ALGO_KCONTROL(SST_CONTROL_NAME(xpname, xmname, xinstance, "params"), \
410 xcount, xmod, xpipe, xtask, xcmd, SST_ALGO_PARAMS, \
411 sst_algo_bytes_ctl_info, \
412 sst_algo_control_get, sst_algo_control_set)
413
414#define SST_ALGO_KCONTROL_BOOL(xpname, xmname, xmod, xpipe, xinstance, xtask) \
415 SST_ALGO_KCONTROL(SST_CONTROL_NAME(xpname, xmname, xinstance, "bypass"), \
416 0, xmod, xpipe, xtask, 0, SST_ALGO_BYPASS, \
417 snd_soc_info_bool_ext, \
418 sst_algo_control_get, sst_algo_control_set)
419
420#define SST_ALGO_BYPASS_PARAMS(xpname, xmname, xcount, xmod, xpipe, \
421 xinstance, xtask, xcmd) \
422 SST_ALGO_KCONTROL_BOOL(xpname, xmname, xmod, xpipe, xinstance, xtask), \
423 SST_ALGO_KCONTROL_BYTES(xpname, xmname, xcount, xmod, xpipe, xinstance, xtask, xcmd)
424
425#define SST_COMBO_ALGO_KCONTROL_BYTES(xpname, xmname, xsubmod, xcount, xmod, \
426 xpipe, xinstance, xtask, xcmd) \
427 SST_ALGO_KCONTROL(SST_COMBO_CONTROL_NAME(xpname, xmname, xinstance, "params", \
428 xsubmod), \
429 xcount, xmod, xpipe, xtask, xcmd, SST_ALGO_PARAMS, \
430 sst_algo_bytes_ctl_info, \
431 sst_algo_control_get, sst_algo_control_set)
432
433
434struct sst_enum {
435 bool tx;
436 unsigned short reg;
437 unsigned int max;
438 const char * const *texts;
439 struct snd_soc_dapm_widget *w;
440};
441
312#endif 442#endif
diff --git a/sound/soc/intel/sst-mfld-platform.h b/sound/soc/intel/sst-mfld-platform.h
index 0c5b943daff3..7092ee3e96a3 100644
--- a/sound/soc/intel/sst-mfld-platform.h
+++ b/sound/soc/intel/sst-mfld-platform.h
@@ -166,7 +166,7 @@ struct sst_algo_int_control_v2 {
166struct sst_data { 166struct sst_data {
167 struct platform_device *pdev; 167 struct platform_device *pdev;
168 struct sst_platform_data *pdata; 168 struct sst_platform_data *pdata;
169 char *byte_stream; 169 struct snd_sst_bytes_v2 *byte_stream;
170 struct mutex lock; 170 struct mutex lock;
171}; 171};
172int sst_register_dsp(struct sst_device *sst); 172int sst_register_dsp(struct sst_device *sst);