Skip to content

Commit 233d2c4

Browse files
committed
Clean ups and preparation for IPC abstraction in the SOF driver
Merge series from Ranjani Sridharan <ranjani.sridharan@linux.intel.com>: In preparation for adding support for the new IPC version that has been introduced in the SOF firmware, this patch set includes some clean ups and necessary modifications to commonly used functions that will be re-used across different IPC-specific code.
2 parents efb1a2d + f535880 commit 233d2c4

10 files changed

Lines changed: 267 additions & 179 deletions

File tree

include/sound/sof/dai.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,9 @@ struct sof_ipc_dai_config {
116116
};
117117
} __packed;
118118

119+
struct sof_dai_private_data {
120+
struct sof_ipc_comp_dai *comp_dai;
121+
struct sof_ipc_dai_config *dai_config;
122+
};
123+
119124
#endif

include/sound/sof/topology.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,6 @@ struct sof_ipc_comp {
8787
*/
8888
#define SOF_BUF_UNDERRUN_PERMITTED BIT(1)
8989

90-
/* the UUID size in bytes, shared between FW and host */
91-
#define SOF_UUID_SIZE 16
92-
9390
/* create new component buffer - SOF_IPC_TPLG_BUFFER_NEW */
9491
struct sof_ipc_buffer {
9592
struct sof_ipc_comp comp;
@@ -303,9 +300,4 @@ enum sof_event_types {
303300
SOF_KEYWORD_DETECT_DAPM_EVENT,
304301
};
305302

306-
/* extended data struct for UUID components */
307-
struct sof_ipc_comp_ext {
308-
uint8_t uuid[SOF_UUID_SIZE];
309-
} __packed;
310-
311303
#endif

sound/soc/sof/intel/hda-dai.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ static struct sof_ipc_dai_config *hda_dai_update_config(struct snd_soc_dapm_widg
167167
int channel)
168168
{
169169
struct snd_sof_widget *swidget = w->dobj.private;
170+
struct sof_dai_private_data *private;
170171
struct sof_ipc_dai_config *config;
171172
struct snd_sof_dai *sof_dai;
172173

@@ -175,12 +176,19 @@ static struct sof_ipc_dai_config *hda_dai_update_config(struct snd_soc_dapm_widg
175176

176177
sof_dai = swidget->private;
177178

178-
if (!sof_dai || !sof_dai->dai_config) {
179-
dev_err(swidget->scomp->dev, "error: No config for DAI %s\n", w->name);
179+
if (!sof_dai || !sof_dai->private) {
180+
dev_err(swidget->scomp->dev, "%s: No private data for DAI %s\n", __func__,
181+
w->name);
180182
return NULL;
181183
}
182184

183-
config = &sof_dai->dai_config[sof_dai->current_config];
185+
private = sof_dai->private;
186+
if (!private->dai_config) {
187+
dev_err(swidget->scomp->dev, "%s: No config for DAI %s\n", __func__, w->name);
188+
return NULL;
189+
}
190+
191+
config = &private->dai_config[sof_dai->current_config];
184192

185193
/* update config with stream tag */
186194
config->hda.link_dma_ch = channel;
@@ -294,19 +302,26 @@ static int hda_link_dai_config_pause_push_ipc(struct snd_soc_dapm_widget *w)
294302
struct snd_sof_widget *swidget = w->dobj.private;
295303
struct snd_soc_component *component = swidget->scomp;
296304
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
305+
struct sof_dai_private_data *private;
297306
struct sof_ipc_dai_config *config;
298307
struct snd_sof_dai *sof_dai;
299308
struct sof_ipc_reply reply;
300309
int ret;
301310

302311
sof_dai = swidget->private;
303312

304-
if (!sof_dai || !sof_dai->dai_config) {
305-
dev_err(sdev->dev, "No config for DAI %s\n", w->name);
313+
if (!sof_dai || !sof_dai->private) {
314+
dev_err(sdev->dev, "%s: No private data for DAI %s\n", __func__, w->name);
315+
return -EINVAL;
316+
}
317+
318+
private = sof_dai->private;
319+
if (!private->dai_config) {
320+
dev_err(sdev->dev, "%s: No config for DAI %s\n", __func__, w->name);
306321
return -EINVAL;
307322
}
308323

309-
config = &sof_dai->dai_config[sof_dai->current_config];
324+
config = &private->dai_config[sof_dai->current_config];
310325

311326
/* set PAUSE command flag */
312327
config->flags = FIELD_PREP(SOF_DAI_CONFIG_FLAGS_CMD_MASK, SOF_DAI_CONFIG_FLAGS_PAUSE);

sound/soc/sof/intel/hda.c

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,21 @@ int hda_ctrl_dai_widget_setup(struct snd_soc_dapm_widget *w, unsigned int quirk_
4747
struct snd_soc_component *component = swidget->scomp;
4848
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
4949
struct sof_ipc_dai_config *config;
50+
struct sof_dai_private_data *private;
5051
struct snd_sof_dai *sof_dai;
5152
struct sof_ipc_reply reply;
5253
int ret;
5354

5455
sof_dai = swidget->private;
5556

56-
if (!sof_dai || !sof_dai->dai_config) {
57-
dev_err(sdev->dev, "No config for DAI %s\n", w->name);
57+
if (!sof_dai || !sof_dai->private) {
58+
dev_err(sdev->dev, "%s: No private data for DAI %s\n", __func__, w->name);
59+
return -EINVAL;
60+
}
61+
62+
private = sof_dai->private;
63+
if (!private->dai_config) {
64+
dev_err(sdev->dev, "%s: No config for DAI %s\n", __func__, w->name);
5865
return -EINVAL;
5966
}
6067

@@ -65,7 +72,7 @@ int hda_ctrl_dai_widget_setup(struct snd_soc_dapm_widget *w, unsigned int quirk_
6572
return ret;
6673
}
6774

68-
config = &sof_dai->dai_config[sof_dai->current_config];
75+
config = &private->dai_config[sof_dai->current_config];
6976

7077
/*
7178
* For static pipelines, the DAI widget would already be set up and calling
@@ -101,23 +108,30 @@ int hda_ctrl_dai_widget_free(struct snd_soc_dapm_widget *w, unsigned int quirk_f
101108
struct snd_sof_widget *swidget = w->dobj.private;
102109
struct snd_soc_component *component = swidget->scomp;
103110
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
111+
struct sof_dai_private_data *private;
104112
struct sof_ipc_dai_config *config;
105113
struct snd_sof_dai *sof_dai;
106114
struct sof_ipc_reply reply;
107115
int ret;
108116

109117
sof_dai = swidget->private;
110118

111-
if (!sof_dai || !sof_dai->dai_config) {
112-
dev_err(sdev->dev, "error: No config to free DAI %s\n", w->name);
119+
if (!sof_dai || !sof_dai->private) {
120+
dev_err(sdev->dev, "%s: No private data for DAI %s\n", __func__, w->name);
121+
return -EINVAL;
122+
}
123+
124+
private = sof_dai->private;
125+
if (!private->dai_config) {
126+
dev_err(sdev->dev, "%s: No config for DAI %s\n", __func__, w->name);
113127
return -EINVAL;
114128
}
115129

116130
/* nothing to do if hw_free() is called without restarting the stream after resume. */
117131
if (!sof_dai->configured)
118132
return 0;
119133

120-
config = &sof_dai->dai_config[sof_dai->current_config];
134+
config = &private->dai_config[sof_dai->current_config];
121135

122136
/* set HW_FREE flag along with any quirks */
123137
config->flags = SOF_DAI_CONFIG_FLAGS_HW_FREE |
@@ -154,6 +168,7 @@ static int sdw_dai_config_ipc(struct snd_sof_dev *sdev,
154168
int link_id, int alh_stream_id, int dai_id, bool setup)
155169
{
156170
struct snd_sof_widget *swidget = w->dobj.private;
171+
struct sof_dai_private_data *private;
157172
struct sof_ipc_dai_config *config;
158173
struct snd_sof_dai *sof_dai;
159174

@@ -164,12 +179,18 @@ static int sdw_dai_config_ipc(struct snd_sof_dev *sdev,
164179

165180
sof_dai = swidget->private;
166181

167-
if (!sof_dai || !sof_dai->dai_config) {
168-
dev_err(sdev->dev, "error: No config for DAI %s\n", w->name);
182+
if (!sof_dai || !sof_dai->private) {
183+
dev_err(sdev->dev, "%s: No private data for DAI %s\n", __func__, w->name);
184+
return -EINVAL;
185+
}
186+
187+
private = sof_dai->private;
188+
if (!private->dai_config) {
189+
dev_err(sdev->dev, "%s: No config for DAI %s\n", __func__, w->name);
169190
return -EINVAL;
170191
}
171192

172-
config = &sof_dai->dai_config[sof_dai->current_config];
193+
config = &private->dai_config[sof_dai->current_config];
173194

174195
/* update config with link and stream ID */
175196
config->dai_index = (link_id << 8) | dai_id;

sound/soc/sof/ipc.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,6 @@ static void ipc_stream_message(struct snd_sof_dev *sdev, void *msg_buf);
2727
* IPC message Tx/Rx message handling.
2828
*/
2929

30-
/* SOF generic IPC data */
31-
struct snd_sof_ipc {
32-
struct snd_sof_dev *sdev;
33-
34-
/* protects messages and the disable flag */
35-
struct mutex tx_mutex;
36-
/* disables further sending of ipc's */
37-
bool disable_ipc_tx;
38-
39-
struct snd_sof_ipc_msg msg;
40-
};
41-
4230
struct sof_ipc_ctrl_data_params {
4331
size_t msg_bytes;
4432
size_t hdr_bytes;

sound/soc/sof/pcm.c

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,9 @@ static void ssp_dai_config_pcm_params_match(struct snd_sof_dev *sdev, const char
670670
if (!dai->name || strcmp(link_name, dai->name))
671671
continue;
672672
for (i = 0; i < dai->number_configs; i++) {
673-
config = &dai->dai_config[i];
673+
struct sof_dai_private_data *private = dai->private;
674+
675+
config = &private->dai_config[i];
674676
if (config->ssp.fsync_rate == params_rate(params)) {
675677
dev_dbg(sdev->dev, "DAI config %d matches pcm hw params\n", i);
676678
dai->current_config = i;
@@ -693,6 +695,7 @@ int sof_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_pa
693695
struct snd_sof_dai *dai =
694696
snd_sof_find_dai(component, (char *)rtd->dai_link->name);
695697
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
698+
struct sof_dai_private_data *private = dai->private;
696699
struct snd_soc_dpcm *dpcm;
697700

698701
/* no topology exists for this BE, try a common configuration */
@@ -717,7 +720,7 @@ int sof_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_pa
717720
/* read format from topology */
718721
snd_mask_none(fmt);
719722

720-
switch (dai->comp_dai->config.frame_fmt) {
723+
switch (private->comp_dai->config.frame_fmt) {
721724
case SOF_IPC_FRAME_S16_LE:
722725
snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S16_LE);
723726
break;
@@ -733,15 +736,15 @@ int sof_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_pa
733736
}
734737

735738
/* read rate and channels from topology */
736-
switch (dai->dai_config->type) {
739+
switch (private->dai_config->type) {
737740
case SOF_DAI_INTEL_SSP:
738741
/* search for config to pcm params match, if not found use default */
739742
ssp_dai_config_pcm_params_match(sdev, (char *)rtd->dai_link->name, params);
740743

741-
rate->min = dai->dai_config[dai->current_config].ssp.fsync_rate;
742-
rate->max = dai->dai_config[dai->current_config].ssp.fsync_rate;
743-
channels->min = dai->dai_config[dai->current_config].ssp.tdm_slots;
744-
channels->max = dai->dai_config[dai->current_config].ssp.tdm_slots;
744+
rate->min = private->dai_config[dai->current_config].ssp.fsync_rate;
745+
rate->max = private->dai_config[dai->current_config].ssp.fsync_rate;
746+
channels->min = private->dai_config[dai->current_config].ssp.tdm_slots;
747+
channels->max = private->dai_config[dai->current_config].ssp.tdm_slots;
745748

746749
dev_dbg(component->dev,
747750
"rate_min: %d rate_max: %d\n", rate->min, rate->max);
@@ -752,11 +755,11 @@ int sof_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_pa
752755
break;
753756
case SOF_DAI_INTEL_DMIC:
754757
/* DMIC only supports 16 or 32 bit formats */
755-
if (dai->comp_dai->config.frame_fmt == SOF_IPC_FRAME_S24_4LE) {
758+
if (private->comp_dai->config.frame_fmt == SOF_IPC_FRAME_S24_4LE) {
756759
dev_err(component->dev,
757760
"error: invalid fmt %d for DAI type %d\n",
758-
dai->comp_dai->config.frame_fmt,
759-
dai->dai_config->type);
761+
private->comp_dai->config.frame_fmt,
762+
private->dai_config->type);
760763
}
761764
break;
762765
case SOF_DAI_INTEL_HDA:
@@ -776,14 +779,14 @@ int sof_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_pa
776779
* Dai could run with different channel count compared with
777780
* front end, so get dai channel count from topology
778781
*/
779-
channels->min = dai->dai_config->alh.channels;
780-
channels->max = dai->dai_config->alh.channels;
782+
channels->min = private->dai_config->alh.channels;
783+
channels->max = private->dai_config->alh.channels;
781784
break;
782785
case SOF_DAI_IMX_ESAI:
783-
rate->min = dai->dai_config->esai.fsync_rate;
784-
rate->max = dai->dai_config->esai.fsync_rate;
785-
channels->min = dai->dai_config->esai.tdm_slots;
786-
channels->max = dai->dai_config->esai.tdm_slots;
786+
rate->min = private->dai_config->esai.fsync_rate;
787+
rate->max = private->dai_config->esai.fsync_rate;
788+
channels->min = private->dai_config->esai.tdm_slots;
789+
channels->max = private->dai_config->esai.tdm_slots;
787790

788791
dev_dbg(component->dev,
789792
"rate_min: %d rate_max: %d\n", rate->min, rate->max);
@@ -792,10 +795,10 @@ int sof_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_pa
792795
channels->min, channels->max);
793796
break;
794797
case SOF_DAI_MEDIATEK_AFE:
795-
rate->min = dai->dai_config->afe.rate;
796-
rate->max = dai->dai_config->afe.rate;
797-
channels->min = dai->dai_config->afe.channels;
798-
channels->max = dai->dai_config->afe.channels;
798+
rate->min = private->dai_config->afe.rate;
799+
rate->max = private->dai_config->afe.rate;
800+
channels->min = private->dai_config->afe.channels;
801+
channels->max = private->dai_config->afe.channels;
799802

800803
dev_dbg(component->dev,
801804
"rate_min: %d rate_max: %d\n", rate->min, rate->max);
@@ -804,10 +807,10 @@ int sof_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_pa
804807
channels->min, channels->max);
805808
break;
806809
case SOF_DAI_IMX_SAI:
807-
rate->min = dai->dai_config->sai.fsync_rate;
808-
rate->max = dai->dai_config->sai.fsync_rate;
809-
channels->min = dai->dai_config->sai.tdm_slots;
810-
channels->max = dai->dai_config->sai.tdm_slots;
810+
rate->min = private->dai_config->sai.fsync_rate;
811+
rate->max = private->dai_config->sai.fsync_rate;
812+
channels->min = private->dai_config->sai.tdm_slots;
813+
channels->max = private->dai_config->sai.tdm_slots;
811814

812815
dev_dbg(component->dev,
813816
"rate_min: %d rate_max: %d\n", rate->min, rate->max);
@@ -816,10 +819,10 @@ int sof_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_pa
816819
channels->min, channels->max);
817820
break;
818821
case SOF_DAI_AMD_BT:
819-
rate->min = dai->dai_config->acpbt.fsync_rate;
820-
rate->max = dai->dai_config->acpbt.fsync_rate;
821-
channels->min = dai->dai_config->acpbt.tdm_slots;
822-
channels->max = dai->dai_config->acpbt.tdm_slots;
822+
rate->min = private->dai_config->acpbt.fsync_rate;
823+
rate->max = private->dai_config->acpbt.fsync_rate;
824+
channels->min = private->dai_config->acpbt.tdm_slots;
825+
channels->max = private->dai_config->acpbt.tdm_slots;
823826

824827
dev_dbg(component->dev,
825828
"AMD_BT rate_min: %d rate_max: %d\n", rate->min, rate->max);
@@ -828,10 +831,10 @@ int sof_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_pa
828831
channels->min, channels->max);
829832
break;
830833
case SOF_DAI_AMD_SP:
831-
rate->min = dai->dai_config->acpsp.fsync_rate;
832-
rate->max = dai->dai_config->acpsp.fsync_rate;
833-
channels->min = dai->dai_config->acpsp.tdm_slots;
834-
channels->max = dai->dai_config->acpsp.tdm_slots;
834+
rate->min = private->dai_config->acpsp.fsync_rate;
835+
rate->max = private->dai_config->acpsp.fsync_rate;
836+
channels->min = private->dai_config->acpsp.tdm_slots;
837+
channels->max = private->dai_config->acpsp.tdm_slots;
835838

836839
dev_dbg(component->dev,
837840
"AMD_SP rate_min: %d rate_max: %d\n", rate->min, rate->max);
@@ -840,10 +843,10 @@ int sof_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_pa
840843
channels->min, channels->max);
841844
break;
842845
case SOF_DAI_AMD_DMIC:
843-
rate->min = dai->dai_config->acpdmic.fsync_rate;
844-
rate->max = dai->dai_config->acpdmic.fsync_rate;
845-
channels->min = dai->dai_config->acpdmic.tdm_slots;
846-
channels->max = dai->dai_config->acpdmic.tdm_slots;
846+
rate->min = private->dai_config->acpdmic.fsync_rate;
847+
rate->max = private->dai_config->acpdmic.fsync_rate;
848+
channels->min = private->dai_config->acpdmic.tdm_slots;
849+
channels->max = private->dai_config->acpdmic.tdm_slots;
847850

848851
dev_dbg(component->dev,
849852
"AMD_DMIC rate_min: %d rate_max: %d\n", rate->min, rate->max);
@@ -853,7 +856,7 @@ int sof_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_pa
853856
break;
854857
default:
855858
dev_err(component->dev, "error: invalid DAI type %d\n",
856-
dai->dai_config->type);
859+
private->dai_config->type);
857860
break;
858861
}
859862

0 commit comments

Comments
 (0)