[alsa-devel] [PATCH v2 00/11] ASoC: topology: Remaining kernel patches
From: Mengdong Lin mengdong.lin@linux.intel.com
This series contains all remaining kernel patches of topology, including some ABI update to PCM (FrontEnds) and link (BackEnds) objects. We don't user more series.
User will be able to create BE DAIs and DAI links, configure more for FE links. Code are verified and can cover reqeust of Intel pre-release platforms for next year, so ABI should be stable.
Current kernel topology code does not really touch Codec-Codec links since there is no user requst atm. We can add support for CC links later by reusing code and data structures for BE links, and no need to revise ABI.
History: v2: Add the reason for creating BE DAI & DAI links by topology to commit message. Drop support for configuring DPCM trigger ordering in topology.
Guneshwor Singh (1): ASoC: topology: Add FE DAIs only if not already added
Mengdong Lin (10): ASoC: topology: Able to create BE DAIs ASoC: topology: ABI - Add flags to PCM ASoC: topology: ABI - Add private data to PCM ASoC: topology: ABI - Add name & component info to BE/CC links ASoC: topology: ABI - Define DAI physical PCM data formats ASoC: topology: ABI - Add HW configurations to BE/CC links ASoC: topology: ABI - Add flags and private data to BE/CC links ASoC: Define API to find a dai link by id ASoC: Probe link components after finding new links ASoC: topology: Able to create BE DAI links
include/sound/soc-dai.h | 15 +- include/sound/soc-topology.h | 1 + include/sound/soc.h | 2 + include/uapi/sound/asoc.h | 90 ++++++++++- sound/soc/soc-core.c | 36 ++++- sound/soc/soc-topology.c | 355 ++++++++++++++++++++++++++++++++++++++----- 6 files changed, 446 insertions(+), 53 deletions(-)
From: Mengdong Lin mengdong.lin@linux.intel.com
Topology will check with ASoC if a BE DAI already exists by checking its name. If the BE DAI doesn't exist, topology will create a new one and the dai_load ops will be called for device specific init.
Here is why we need topology to create BE DAIs (and BE DAI links in later patches): Intel platform supports too many different types of DAIs based on the platform variant e.g. I2S, HDA, DMIC and Soundwire in the future. Due to the SoC pin count limitation, not all the interface pins are taken out of the SoC to connect various peripherals. So even though technically hardware supports many physical interfaces but the platform may have limited what can be connected on the platform. Our attempt is to create BE DAIs based on what is actually supported on a platform, e.g. if the platform does not support HDA then we will not create the HDA DAIs. Ideally, the driver should query BIOS to get the physical pin output types and connections to peripherals for a specific platform, but unfortunately BIOS sometimes does not have accurate info, so there is still hard code of BE DAI & DAI links in driver. To share a common driver across Intel platforms and remove the hard code, we choose topology to give us such info e.g. SKL Chrome topology does not use HDA Codec and so there are only I2S and DMIC DAIs.
Signed-off-by: Guneshwor Singh guneshwor.o.singh@intel.com Signed-off-by: Mengdong Lin mengdong.lin@linux.intel.com
diff --git a/include/sound/soc-topology.h b/include/sound/soc-topology.h index d318fe4..9ebb9f2 100644 --- a/include/sound/soc-topology.h +++ b/include/sound/soc-topology.h @@ -39,6 +39,7 @@ enum snd_soc_dobj_type { SND_SOC_DOBJ_ENUM, SND_SOC_DOBJ_BYTES, SND_SOC_DOBJ_PCM, + SND_SOC_DOBJ_BE_DAI, SND_SOC_DOBJ_DAI_LINK, SND_SOC_DOBJ_CODEC_LINK, SND_SOC_DOBJ_WIDGET, diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index c0bbcd9..810b1d7 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -2871,7 +2871,8 @@ int snd_soc_register_dai(struct snd_soc_component *component, struct snd_soc_dai *dai; int ret;
- if (dai_drv->dobj.type != SND_SOC_DOBJ_PCM) { + if (!(dai_drv->dobj.type == SND_SOC_DOBJ_PCM || + dai_drv->dobj.type == SND_SOC_DOBJ_BE_DAI)) { dev_err(component->dev, "Invalid dai type %d\n", dai_drv->dobj.type); return -EINVAL; diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c index 6b05047..b271248 100644 --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -1711,42 +1711,14 @@ static int soc_tplg_pcm_elems_load(struct soc_tplg *tplg, return 0; }
-/* * - * soc_tplg_be_dai_config - Find and configure an existing BE DAI. - * @tplg: topology context - * @be: topology BE DAI configs. - * - * The BE dai should already be registered by the platform driver. The - * platform driver should specify the BE DAI name and ID for matching. - */ -static int soc_tplg_be_dai_config(struct soc_tplg *tplg, +static int config_be_dai(struct soc_tplg *tplg, + struct snd_soc_dai_driver *dai_drv, struct snd_soc_tplg_be_dai *be) { - struct snd_soc_dai_link_component dai_component = {0}; - struct snd_soc_dai *dai; - struct snd_soc_dai_driver *dai_drv; struct snd_soc_pcm_stream *stream; struct snd_soc_tplg_stream_caps *caps; int ret;
- dai_component.dai_name = be->dai_name; - dai = snd_soc_find_dai(&dai_component); - if (!dai) { - dev_err(tplg->dev, "ASoC: BE DAI %s not registered\n", - be->dai_name); - return -EINVAL; - } - - if (be->dai_id != dai->id) { - dev_err(tplg->dev, "ASoC: BE DAI %s id mismatch\n", - be->dai_name); - return -EINVAL; - } - - dai_drv = dai->driver; - if (!dai_drv) - return -EINVAL; - if (be->playback) { stream = &dai_drv->playback; caps = &be->caps[SND_SOC_TPLG_STREAM_PLAYBACK]; @@ -1765,13 +1737,80 @@ static int soc_tplg_be_dai_config(struct soc_tplg *tplg, /* pass control to component driver for optional further init */ ret = soc_tplg_dai_load(tplg, dai_drv); if (ret < 0) { - dev_err(tplg->comp->dev, "ASoC: DAI loading failed\n"); + dev_err(tplg->comp->dev, "ASoC: BE DAI loading failed\n"); return ret; }
return 0; }
+static int soc_tplg_be_dai_create(struct soc_tplg *tplg, + struct snd_soc_tplg_be_dai *be) +{ + struct snd_soc_dai_driver *dai_drv; + int ret; + + dai_drv = kzalloc(sizeof(struct snd_soc_dai_driver), GFP_KERNEL); + if (dai_drv == NULL) + return -ENOMEM; + + dai_drv->name = be->dai_name; + dai_drv->id = be->dai_id; + + ret = config_be_dai(tplg, dai_drv, be); + if (ret < 0) { + kfree(dai_drv); + return ret; + } + + dai_drv->dobj.index = tplg->index; + dai_drv->dobj.ops = tplg->ops; + dai_drv->dobj.type = SND_SOC_DOBJ_BE_DAI; + list_add(&dai_drv->dobj.list, &tplg->comp->dobj_list); + + /* register the DAI to the component */ + return snd_soc_register_dai(tplg->comp, dai_drv); +} + +/* * + * soc_tplg_be_dai_config - Create a new BE DAI or configure an existing one. + * @tplg: topology context + * @be: topology BE DAI configs. + * + * The BE dai should already be registered by the platform driver. The + * platform driver should specify the BE DAI name and ID for matching. + */ +static int soc_tplg_be_dai_config(struct soc_tplg *tplg, + struct snd_soc_tplg_be_dai *be) +{ + struct snd_soc_dai_link_component dai_component = {0}; + struct snd_soc_dai *dai; + struct snd_soc_dai_driver *dai_drv; + + if (!strlen(be->dai_name)) { + dev_err(tplg->dev, "ASoC: Invalid BE DAI name\n"); + return -EINVAL; + } + + dai_component.dai_name = be->dai_name; + dai = snd_soc_find_dai(&dai_component); + if (!dai) /* BE DAI doesn't exist, create it */ + return soc_tplg_be_dai_create(tplg, be); + + /* configure an existing BE DAI */ + if (be->dai_id != dai->id) { + dev_err(tplg->dev, "ASoC: BE DAI %s id mismatch\n", + be->dai_name); + return -EINVAL; + } + + dai_drv = dai->driver; + if (!dai_drv) + return -EINVAL; + + return config_be_dai(tplg, dai_drv, be); +} + static int soc_tplg_be_dai_elems_load(struct soc_tplg *tplg, struct snd_soc_tplg_hdr *hdr) { @@ -2063,6 +2102,9 @@ int snd_soc_tplg_component_remove(struct snd_soc_component *comp, u32 index) case SND_SOC_DOBJ_PCM: remove_dai(comp, dobj, pass); break; + case SND_SOC_DOBJ_BE_DAI: + remove_dai(comp, dobj, pass); + break; case SND_SOC_DOBJ_DAI_LINK: remove_link(comp, dobj, pass); break;
On Fri, Sep 09, 2016 at 07:43:11PM +0800, mengdong.lin@linux.intel.com wrote:
From: Mengdong Lin mengdong.lin@linux.intel.com
Topology will check with ASoC if a BE DAI already exists by checking its name. If the BE DAI doesn't exist, topology will create a new one and the dai_load ops will be called for device specific init.
I still remain fundamentally unconvinced that this is a good or scalable idea and that it makes sense to have it be part of the standard topology ABI. We are not going to download a DSP firmware that creates a new physical link in the system so having the topology be the thing creating those physical links seems wrong.
create the HDA DAIs. Ideally, the driver should query BIOS to get the physical pin output types and connections to peripherals for a specific platform, but unfortunately BIOS sometimes does not have accurate info, so there is still hard code of BE DAI & DAI links in driver. To share a
Having the connections to the DSP specified in the toplogy is of course sensible but fundamentally this is always going to be choosing from a list of physical DAIs that we already know about and potential connections for those that are also already known. If the driver wants to do something in response to a DAI being hooked up into the topology (which seems to be the actual goal here) that would be sensible but attempting to create physical hardware in a topology does not seem like a good idea as a generic feature.
Regards, Hardik Shah
-----Original Message----- From: Mark Brown [mailto:broonie@kernel.org]
On Fri, Sep 09, 2016 at 07:43:11PM +0800, mengdong.lin@linux.intel.com wrote:
From: Mengdong Lin mengdong.lin@linux.intel.com
Topology will check with ASoC if a BE DAI already exists by checking its name. If the BE DAI doesn't exist, topology will create a new one and the dai_load ops will be called for device specific init.
I still remain fundamentally unconvinced that this is a good or scalable idea and that it makes sense to have it be part of the standard topology ABI. We are not going to download a DSP firmware that creates a new physical link in the system so having the topology be the thing creating those physical links seems wrong.
Hi Mark, You are right, physical links will always remain same.
create the HDA DAIs. Ideally, the driver should query BIOS to get the physical pin output types and connections to peripherals for a specific platform, but unfortunately BIOS sometimes does not have accurate info, so there is still hard code of BE DAI & DAI links in driver. To share a
Having the connections to the DSP specified in the toplogy is of course sensible but fundamentally this is always going to be choosing from a list of physical DAIs that we already know about and potential connections for those that are also already known. If the driver wants to do something in response to a DAI being hooked up into the topology (which seems to be the actual goal here) that would be sensible but attempting to create physical hardware in a topology does not seem like a good idea as a generic feature.
We were trying to optimize here by creating DAIs for only those physical links which are getting used on the platform. Intel hardware supports multiple physical links like I2S, HDA, HDMI and DMICs and with that BE DAIs can increase up to 15-20, and very few of them may be really used in most of the platforms. But if you think we should create BE DAIs for all physical links, we will go ahead with that approach.
Thanks for your comments, Hardik! So we'll no longer let topology to create BE DAIs.
And how about the BE DAI links? They are also physical hardware things. Could we also let topology configure those that can be changed by SW on the BE link, instead of letting topology create the BE links?
Thanks Mengdong
On 09/20/2016 01:09 AM, Shah, Hardik T wrote:
Regards, Hardik Shah
-----Original Message----- From: Mark Brown [mailto:broonie@kernel.org]
On Fri, Sep 09, 2016 at 07:43:11PM +0800, mengdong.lin@linux.intel.com wrote:
From: Mengdong Lin mengdong.lin@linux.intel.com
Topology will check with ASoC if a BE DAI already exists by checking its name. If the BE DAI doesn't exist, topology will create a new one and the dai_load ops will be called for device specific init.
I still remain fundamentally unconvinced that this is a good or scalable idea and that it makes sense to have it be part of the standard topology ABI. We are not going to download a DSP firmware that creates a new physical link in the system so having the topology be the thing creating those physical links seems wrong.
Hi Mark, You are right, physical links will always remain same.
create the HDA DAIs. Ideally, the driver should query BIOS to get the physical pin output types and connections to peripherals for a specific platform, but unfortunately BIOS sometimes does not have accurate info, so there is still hard code of BE DAI & DAI links in driver. To share a
Having the connections to the DSP specified in the toplogy is of course sensible but fundamentally this is always going to be choosing from a list of physical DAIs that we already know about and potential connections for those that are also already known. If the driver wants to do something in response to a DAI being hooked up into the topology (which seems to be the actual goal here) that would be sensible but attempting to create physical hardware in a topology does not seem like a good idea as a generic feature.
We were trying to optimize here by creating DAIs for only those physical links which are getting used on the platform. Intel hardware supports multiple physical links like I2S, HDA, HDMI and DMICs and with that BE DAIs can increase up to 15-20, and very few of them may be really used in most of the platforms. But if you think we should create BE DAIs for all physical links, we will go ahead with that approach. _______________________________________________ Alsa-devel mailing list Alsa-devel@alsa-project.org http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
On Wed, 2016-09-21 at 13:44 +0800, Mengdong Lin wrote:
Thanks for your comments, Hardik! So we'll no longer let topology to create BE DAIs.
And how about the BE DAI links? They are also physical hardware things. Could we also let topology configure those that can be changed by SW on the BE link, instead of letting topology create the BE links?
Yes, the topology should be able to configure the physical link SW params as the link may be used for multiple use cases on multiple different devices with the same FW binary. Each use case or device will possibly require a different BE DAi link configuration.
Liam
On Wed, Sep 21, 2016 at 08:09:55AM +0100, Liam Girdwood wrote:
On Wed, 2016-09-21 at 13:44 +0800, Mengdong Lin wrote:
And how about the BE DAI links? They are also physical hardware things. Could we also let topology configure those that can be changed by SW on the BE link, instead of letting topology create the BE links?
Yes, the topology should be able to configure the physical link SW params as the link may be used for multiple use cases on multiple different devices with the same FW binary. Each use case or device will possibly require a different BE DAi link configuration.
Configuration is fine, it's just attempting to say that physical links are instantiated by the DSP firmware that's the problem. That's just so obviously an invitation to fragility and abuse.
From: Mengdong Lin mengdong.lin@linux.intel.com
Add flags to PCM. These flags will be applied to FE (Front End) links.
Signed-off-by: Mengdong Lin mengdong.lin@linux.intel.com
diff --git a/include/uapi/sound/asoc.h b/include/uapi/sound/asoc.h index 33d00a4..a8d25be 100644 --- a/include/uapi/sound/asoc.h +++ b/include/uapi/sound/asoc.h @@ -130,6 +130,10 @@ #define SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_CHANNELS (1 << 1) #define SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_SAMPLEBITS (1 << 2)
+/* DAI link flags */ +#define SND_SOC_TPLG_LNK_FLGBIT_IGNORE_SUSPEND (1 << 0) +#define SND_SOC_TPLG_LNK_FLGBIT_IGNORE_POWERDOWN_TIME (1 << 1) + /* * Block Header. * This header precedes all object and object arrays below. @@ -440,6 +444,8 @@ struct snd_soc_tplg_pcm { struct snd_soc_tplg_stream stream[SND_SOC_TPLG_STREAM_CONFIG_MAX]; /* for DAI link */ __le32 num_streams; /* number of streams */ struct snd_soc_tplg_stream_caps caps[2]; /* playback and capture for DAI */ + __le32 flag_mask; /* bitmask of flags to configure */ + __le32 flags; /* SND_SOC_TPLG_LNK_FLGBIT_* flag value */ } __attribute__((packed));
diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c index b271248..ede60df 100644 --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -1621,6 +1621,18 @@ static int soc_tplg_dai_create(struct soc_tplg *tplg, return snd_soc_register_dai(tplg->comp, dai_drv); }
+static void set_link_flags(struct snd_soc_dai_link *link, + unsigned int flag_mask, unsigned int flags) +{ + if (flag_mask & SND_SOC_TPLG_LNK_FLGBIT_IGNORE_SUSPEND) + link->ignore_suspend = + flags & SND_SOC_TPLG_LNK_FLGBIT_IGNORE_SUSPEND ? 1 : 0; + + if (flag_mask & SND_SOC_TPLG_LNK_FLGBIT_IGNORE_POWERDOWN_TIME) + link->ignore_pmdown_time = + flags & SND_SOC_TPLG_LNK_FLGBIT_IGNORE_POWERDOWN_TIME ? 1 : 0; +} + /* create the FE DAI link */ static int soc_tplg_link_create(struct soc_tplg *tplg, struct snd_soc_tplg_pcm *pcm) @@ -1644,6 +1656,8 @@ static int soc_tplg_link_create(struct soc_tplg *tplg, link->dynamic = 1; link->dpcm_playback = pcm->playback; link->dpcm_capture = pcm->capture; + if (pcm->flag_mask) + set_link_flags(link, pcm->flag_mask, pcm->flags);
/* pass control to component driver for optional further init */ ret = soc_tplg_dai_link_load(tplg, link);
From: Mengdong Lin mengdong.lin@linux.intel.com
Add private data to PCM (Frontend DAI & DAI link) for future extension. Revise offset update for PCM with private data.
Signed-off-by: Mengdong Lin mengdong.lin@linux.intel.com
diff --git a/include/uapi/sound/asoc.h b/include/uapi/sound/asoc.h index a8d25be..309c9a7 100644 --- a/include/uapi/sound/asoc.h +++ b/include/uapi/sound/asoc.h @@ -446,6 +446,7 @@ struct snd_soc_tplg_pcm { struct snd_soc_tplg_stream_caps caps[2]; /* playback and capture for DAI */ __le32 flag_mask; /* bitmask of flags to configure */ __le32 flags; /* SND_SOC_TPLG_LNK_FLGBIT_* flag value */ + struct snd_soc_tplg_private priv; } __attribute__((packed));
diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c index ede60df..8ccd7f9 100644 --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -1708,19 +1708,18 @@ static int soc_tplg_pcm_elems_load(struct soc_tplg *tplg, }
/* create the FE DAIs and DAI links */ - pcm = (struct snd_soc_tplg_pcm *)tplg->pos; for (i = 0; i < count; i++) { + pcm = (struct snd_soc_tplg_pcm *)tplg->pos; if (pcm->size != sizeof(*pcm)) { dev_err(tplg->dev, "ASoC: invalid pcm size\n"); return -EINVAL; }
soc_tplg_pcm_create(tplg, pcm); - pcm++; + tplg->pos += (sizeof(*pcm) + pcm->priv.size); }
dev_dbg(tplg->dev, "ASoC: adding %d PCM DAIs\n", count); - tplg->pos += sizeof(struct snd_soc_tplg_pcm) * count;
return 0; }
From: Guneshwor Singh guneshwor.o.singh@intel.com
Topology will check with ASoC if the FE DAI already exists by checking its name. If not, topology will create a new one.
Signed-off-by: Guneshwor Singh guneshwor.o.singh@intel.com Signed-off-by: Mengdong Lin mengdong.lin@linux.intel.com
diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c index 8ccd7f9..17e0b74 100644 --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -1680,13 +1680,25 @@ static int soc_tplg_link_create(struct soc_tplg *tplg, static int soc_tplg_pcm_create(struct soc_tplg *tplg, struct snd_soc_tplg_pcm *pcm) { + struct snd_soc_dai_link_component dai_component = {0}; + struct snd_soc_dai *dai; int ret;
- ret = soc_tplg_dai_create(tplg, pcm); - if (ret < 0) - return ret; + if (!strlen(pcm->dai_name)) { + dev_err(tplg->dev, "ASoC: Invalid FE DAI name %s\n", + pcm->dai_name); + return -EINVAL; + } + + dai_component.dai_name = pcm->dai_name; + dai = snd_soc_find_dai(&dai_component); + if (!dai) { /* FE DAI doesn't exist, create it */ + ret = soc_tplg_dai_create(tplg, pcm); + if (ret < 0) + return ret; + }
- return soc_tplg_link_create(tplg, pcm); + return soc_tplg_link_create(tplg, pcm); }
static int soc_tplg_pcm_elems_load(struct soc_tplg *tplg,
From: Mengdong Lin mengdong.lin@linux.intel.com
Add link name, stream name, CPU and codec components info, for topology to create new backend or codec-codec links in the future.
Signed-off-by: Mengdong Lin mengdong.lin@linux.intel.com
diff --git a/include/uapi/sound/asoc.h b/include/uapi/sound/asoc.h index 309c9a7..1d4c3b9 100644 --- a/include/uapi/sound/asoc.h +++ b/include/uapi/sound/asoc.h @@ -39,6 +39,9 @@ */ #define SND_SOC_TPLG_STREAM_CONFIG_MAX 8
+/* maximum number of codecs for a BE/CC link */ +#define SND_SOC_TPLG_LINK_CODECS_MAX 4 + /* individual kcontrol info types - can be mixed with other types */ #define SND_SOC_TPLG_CTL_VOLSW 1 #define SND_SOC_TPLG_CTL_VOLSW_SX 2 @@ -451,6 +454,15 @@ struct snd_soc_tplg_pcm {
/* + * Component for backend links. + */ +struct snd_soc_tplg_link_cmpnt { + __le32 size; /* in bytes of this structure */ + char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; /* component name, optional */ + char dai_name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; +} __attribute__((packed)); + +/* * Describes the BE or CC link runtime supported configs or params * * File block representation for BE/CC link config :- @@ -462,9 +474,16 @@ struct snd_soc_tplg_pcm { */ struct snd_soc_tplg_link_config { __le32 size; /* in bytes of this structure */ - __le32 id; /* unique ID - used to match */ + __le32 id; /* unique ID - used to match with DAI link */ struct snd_soc_tplg_stream stream[SND_SOC_TPLG_STREAM_CONFIG_MAX]; /* supported configs playback and captrure */ __le32 num_streams; /* number of streams */ + + char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; /* link name */ + char stream_name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; /* stream name */ + + struct snd_soc_tplg_link_cmpnt cpu; /* cpu component */ + struct snd_soc_tplg_link_cmpnt codecs[SND_SOC_TPLG_LINK_CODECS_MAX]; /* codec components */ + __le32 num_codecs; /* number of codecs */ } __attribute__((packed));
/*
From: Mengdong Lin mengdong.lin@linux.intel.com
Define DAI physical PCM data formats for user space, so users can specify the formats of backends by topology (e.g. the DAI format to set on backend link init).
The kernel will also refer to these formats.
Signed-off-by: Mengdong Lin mengdong.lin@linux.intel.com
diff --git a/include/sound/soc-dai.h b/include/sound/soc-dai.h index 964b7de..534aae2 100644 --- a/include/sound/soc-dai.h +++ b/include/sound/soc-dai.h @@ -15,6 +15,7 @@
#include <linux/list.h> +#include <sound/asoc.h>
struct snd_pcm_substream; struct snd_soc_dapm_widget; @@ -26,13 +27,13 @@ struct snd_compr_stream; * Describes the physical PCM data formating and clocking. Add new formats * to the end. */ -#define SND_SOC_DAIFMT_I2S 1 /* I2S mode */ -#define SND_SOC_DAIFMT_RIGHT_J 2 /* Right Justified mode */ -#define SND_SOC_DAIFMT_LEFT_J 3 /* Left Justified mode */ -#define SND_SOC_DAIFMT_DSP_A 4 /* L data MSB after FRM LRC */ -#define SND_SOC_DAIFMT_DSP_B 5 /* L data MSB during FRM LRC */ -#define SND_SOC_DAIFMT_AC97 6 /* AC97 */ -#define SND_SOC_DAIFMT_PDM 7 /* Pulse density modulation */ +#define SND_SOC_DAIFMT_I2S SND_SOC_DAI_FORMAT_I2S +#define SND_SOC_DAIFMT_RIGHT_J SND_SOC_DAI_FORMAT_RIGHT_J +#define SND_SOC_DAIFMT_LEFT_J SND_SOC_DAI_FORMAT_LEFT_J +#define SND_SOC_DAIFMT_DSP_A SND_SOC_DAI_FORMAT_DSP_A +#define SND_SOC_DAIFMT_DSP_B SND_SOC_DAI_FORMAT_DSP_B +#define SND_SOC_DAIFMT_AC97 SND_SOC_DAI_FORMAT_AC97 +#define SND_SOC_DAIFMT_PDM SND_SOC_DAI_FORMAT_PDM
/* left and right justified also known as MSB and LSB respectively */ #define SND_SOC_DAIFMT_MSB SND_SOC_DAIFMT_LEFT_J diff --git a/include/uapi/sound/asoc.h b/include/uapi/sound/asoc.h index 1d4c3b9..3256dd4 100644 --- a/include/uapi/sound/asoc.h +++ b/include/uapi/sound/asoc.h @@ -137,6 +137,21 @@ #define SND_SOC_TPLG_LNK_FLGBIT_IGNORE_SUSPEND (1 << 0) #define SND_SOC_TPLG_LNK_FLGBIT_IGNORE_POWERDOWN_TIME (1 << 1)
+/* DAI physical PCM data formats. + * Add new formats to the end of the list. + */ +#define SND_SOC_DAI_FORMAT_I2S 1 /* I2S mode */ +#define SND_SOC_DAI_FORMAT_RIGHT_J 2 /* Right Justified mode */ +#define SND_SOC_DAI_FORMAT_LEFT_J 3 /* Left Justified mode */ +#define SND_SOC_DAI_FORMAT_DSP_A 4 /* L data MSB after FRM LRC */ +#define SND_SOC_DAI_FORMAT_DSP_B 5 /* L data MSB during FRM LRC */ +#define SND_SOC_DAI_FORMAT_AC97 6 /* AC97 */ +#define SND_SOC_DAI_FORMAT_PDM 7 /* Pulse density modulation */ + +/* left and right justified also known as MSB and LSB respectively */ +#define SND_SOC_DAI_FORMAT_MSB SND_SOC_DAI_FORMAT_LEFT_J +#define SND_SOC_DAI_FORMAT_LSB SND_SOC_DAI_FORMAT_RIGHT_J + /* * Block Header. * This header precedes all object and object arrays below.
From: Mengdong Lin mengdong.lin@linux.intel.com
Define the types and ABI struct for a single Backend or Codec<->Codec link runtime supported hardware config, e.g. audio hardware formats.
The default HW config ID will help topology to find the DAI format to set on init.
Topology provides this as a fallback if such HW settings are not available in ACPI or device tree, to avoid hard code in drivers.
It's only for config items that can be programmed by SW or FW, not for physical things like link connections or GPIO used for HP etc.
Signed-off-by: Mengdong Lin mengdong.lin@linux.intel.com
diff --git a/include/uapi/sound/asoc.h b/include/uapi/sound/asoc.h index 3256dd4..31f2181 100644 --- a/include/uapi/sound/asoc.h +++ b/include/uapi/sound/asoc.h @@ -42,6 +42,11 @@ /* maximum number of codecs for a BE/CC link */ #define SND_SOC_TPLG_LINK_CODECS_MAX 4
+/* + * Maximum number of BE/CC link HW configs + */ +#define SND_SOC_TPLG_HW_CONFIG_MAX 8 + /* individual kcontrol info types - can be mixed with other types */ #define SND_SOC_TPLG_CTL_VOLSW 1 #define SND_SOC_TPLG_CTL_VOLSW_SX 2 @@ -295,6 +300,35 @@ struct snd_soc_tplg_stream { __le32 channels; /* channels */ } __attribute__((packed));
+ +/* + * Describes a single BE or CC link runtime supported hardware config, + * i.e. hardware audio formats. + */ +struct snd_soc_tplg_hw_config { + __le32 size; /* in bytes of this structure */ + __le32 id; /* unique ID - - used to match */ + __le32 fmt; /* SND_SOC_DAI_FORMAT_ format value */ + __u8 clock_gated; /* 1 if clock can be gated to save power */ + __u8 invert_bclk; /* 1 for inverted BCLK, 0 for normal */ + __u8 invert_fsync; /* 1 for inverted frame clock, 0 for normal */ + __u8 bclk_master; /* 1 for master of BCLK, 0 for slave */ + __u8 fsync_master; /* 1 for master of FSYNC, 0 for slave */ + __u8 mclk_direction; /* 0 for input, 1 for output */ + __le16 reserved; /* for 32bit alignment */ + __le32 mclk_rate; /* MCLK or SYSCLK freqency in Hz */ + __le32 bclk_rate; /* BCLK freqency in Hz */ + __le32 fsync_rate; /* frame clock in Hz */ + __le32 tdm_slots; /* number of TDM slots in use */ + __le32 tdm_slot_width; /* width in bits for each slot */ + __le32 tx_slots; /* bit mask for active Tx slots */ + __le32 rx_slots; /* bit mask for active Rx slots */ + __le32 tx_channels; /* number of Tx channels */ + __le32 tx_chanmap[SND_SOC_TPLG_MAX_CHAN]; /* array of slot number */ + __le32 rx_channels; /* number of Rx channels */ + __le32 rx_chanmap[SND_SOC_TPLG_MAX_CHAN]; /* array of slot number */ +} __attribute__((packed)); + /* * Manifest. List totals for each payload type. Not used in parsing, but will * be passed to the component driver before any other objects in order for any @@ -499,6 +533,10 @@ struct snd_soc_tplg_link_config { struct snd_soc_tplg_link_cmpnt cpu; /* cpu component */ struct snd_soc_tplg_link_cmpnt codecs[SND_SOC_TPLG_LINK_CODECS_MAX]; /* codec components */ __le32 num_codecs; /* number of codecs */ + + struct snd_soc_tplg_hw_config hw_config[SND_SOC_TPLG_HW_CONFIG_MAX]; /* hw configs */ + __le32 num_hw_configs; /* number of hw configs */ + __le32 default_hw_config_id; /* default hw config ID for init */ } __attribute__((packed));
/*
From: Mengdong Lin mengdong.lin@linux.intel.com
The flags will be used to configure an existing Backend and Codec<->Codec link or create a new links.
The private data is reserved for future extension.
Signed-off-by: Mengdong Lin mengdong.lin@linux.intel.com
diff --git a/include/uapi/sound/asoc.h b/include/uapi/sound/asoc.h index 31f2181..abae889 100644 --- a/include/uapi/sound/asoc.h +++ b/include/uapi/sound/asoc.h @@ -141,6 +141,11 @@ /* DAI link flags */ #define SND_SOC_TPLG_LNK_FLGBIT_IGNORE_SUSPEND (1 << 0) #define SND_SOC_TPLG_LNK_FLGBIT_IGNORE_POWERDOWN_TIME (1 << 1) +#define SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_RATES (1 << 2) +#define SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_CHANNELS (1 << 3) +#define SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_SAMPLEBITS (1 << 4) +#define SND_SOC_TPLG_LNK_FLGBIT_DPCM_PLAYBACK (1 << 5) +#define SND_SOC_TPLG_LNK_FLGBIT_DPCM_CAPTURE (1 << 6)
/* DAI physical PCM data formats. * Add new formats to the end of the list. @@ -537,6 +542,10 @@ struct snd_soc_tplg_link_config { struct snd_soc_tplg_hw_config hw_config[SND_SOC_TPLG_HW_CONFIG_MAX]; /* hw configs */ __le32 num_hw_configs; /* number of hw configs */ __le32 default_hw_config_id; /* default hw config ID for init */ + + __le32 flag_mask; /* bitmask of flags to configure */ + __le32 flags; /* SND_SOC_TPLG_LNK_FLGBIT_* flag value */ + struct snd_soc_tplg_private priv; } __attribute__((packed));
/*
From: Mengdong Lin mengdong.lin@linux.intel.com
Topology can use this to check if a BE link already exists, and create a new link if not found.
Signed-off-by: Mengdong Lin mengdong.lin@linux.intel.com
diff --git a/include/sound/soc.h b/include/sound/soc.h index 4f1c784..d52601a 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -1671,6 +1671,8 @@ int snd_soc_add_dai_link(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link); void snd_soc_remove_dai_link(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link); +struct snd_soc_dai_link *snd_soc_find_dai_link(struct snd_soc_card *card, + int id);
int snd_soc_register_dai(struct snd_soc_component *component, struct snd_soc_dai_driver *dai_drv); diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 810b1d7..e8113df 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -972,6 +972,22 @@ struct snd_soc_dai *snd_soc_find_dai( } EXPORT_SYMBOL_GPL(snd_soc_find_dai);
+struct snd_soc_dai_link *snd_soc_find_dai_link( + struct snd_soc_card *card, int id) +{ + struct snd_soc_dai_link *link, *_link; + + lockdep_assert_held(&client_mutex); + + list_for_each_entry_safe(link, _link, &card->dai_link_list, list) { + if (link->id == id) + return link; + } + + return NULL; +} +EXPORT_SYMBOL_GPL(snd_soc_find_dai_link); + static bool soc_is_dai_link_bound(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link) {
From: Mengdong Lin mengdong.lin@linux.intel.com
Probing link components may bring new links from topolgy and these new links may need new components. So there will be multiple rounds of components probing until there is no new links found during the process.
Probing of aux_dev is moved earlier to simply the code. There is no need to probe aux_devices multiple times.
Signed-off-by: Mengdong Lin mengdong.lin@linux.intel.com
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index e8113df..6870917 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1862,6 +1862,7 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card) struct snd_soc_pcm_runtime *rtd; struct snd_soc_dai_link *dai_link; int ret, i, order; + bool find_new_link; /* topolgy may create new links */
mutex_lock(&client_mutex); mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_INIT); @@ -1934,7 +1935,13 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card) goto card_probe_error; }
+ /* probe auxiliary components */ + ret = soc_probe_aux_devices(card); + if (ret < 0) + goto probe_dai_err; + /* probe all components used by DAI links on this card */ +probe_link_cmpnt: for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST; order++) { list_for_each_entry(rtd, &card->rtd_list, list) { @@ -1948,18 +1955,15 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card) } }
- /* probe auxiliary components */ - ret = soc_probe_aux_devices(card); - if (ret < 0) - goto probe_dai_err; - /* Find new DAI links added during probing components and bind them. * Components with topology may bring new DAIs and DAI links. */ + find_new_link = false; list_for_each_entry(dai_link, &card->dai_link_list, list) { if (soc_is_dai_link_bound(card, dai_link)) continue;
+ find_new_link = true; ret = soc_init_dai_link(card, dai_link); if (ret) goto probe_dai_err; @@ -1968,6 +1972,9 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card) goto probe_dai_err; }
+ if (find_new_link) /* new link may have unprobed components */ + goto probe_link_cmpnt; + /* probe all DAI links on this card */ for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST; order++) {
From: Mengdong Lin mengdong.lin@linux.intel.com
Topology will check with ASoC if a BE (Backend) link already exists by checking its ID. If the BE link doesn't exist, topology will create it and the link_load ops and card's add_dai_link will be called for machine specific init.
The reason we need topology to create BE DAI links is same as that for BE DAIs: Due to the SoC pin count limitation, not all the interface pins are taken out of the SoC to connect various peripherals. Sometimes BIOS does have enough info about the physical pin output types and their connections to peripherals while we want to create BE DAI links based on what is actually used on a platform. So we choose topology to give us such info and help driver to create BE links dynamically.
Signed-off-by: Mengdong Lin mengdong.lin@linux.intel.com
diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c index 17e0b74..3f71f1d 100644 --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -49,9 +49,10 @@ #define SOC_TPLG_PASS_GRAPH 5 #define SOC_TPLG_PASS_PINS 6 #define SOC_TPLG_PASS_BE_DAI 7 +#define SOC_TPLG_PASS_LINK 8
#define SOC_TPLG_PASS_START SOC_TPLG_PASS_MANIFEST -#define SOC_TPLG_PASS_END SOC_TPLG_PASS_BE_DAI +#define SOC_TPLG_PASS_END SOC_TPLG_PASS_LINK
struct soc_tplg { const struct firmware *fw; @@ -493,6 +494,7 @@ static void remove_link(struct snd_soc_component *comp,
list_del(&dobj->list); snd_soc_remove_dai_link(comp->card, link); + kfree(link->codecs); kfree(link); }
@@ -1631,6 +1633,29 @@ static void set_link_flags(struct snd_soc_dai_link *link, if (flag_mask & SND_SOC_TPLG_LNK_FLGBIT_IGNORE_POWERDOWN_TIME) link->ignore_pmdown_time = flags & SND_SOC_TPLG_LNK_FLGBIT_IGNORE_POWERDOWN_TIME ? 1 : 0; + + if (flag_mask & SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_RATES) + link->symmetric_rates = + flags & SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_RATES ? 1 : 0; + + if (flag_mask & SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_CHANNELS) + link->symmetric_channels = + flags & SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_CHANNELS ? + 1 : 0; + + if (flag_mask & SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_SAMPLEBITS) + link->symmetric_samplebits = + flags & SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_SAMPLEBITS ? + 1 : 0; + + if (flag_mask & SND_SOC_TPLG_LNK_FLGBIT_DPCM_PLAYBACK) + link->dpcm_playback = + flags & SND_SOC_TPLG_LNK_FLGBIT_DPCM_PLAYBACK ? 1 : 0; + + if (flag_mask & SND_SOC_TPLG_LNK_FLGBIT_DPCM_CAPTURE) + link->dpcm_capture = + flags & SND_SOC_TPLG_LNK_FLGBIT_DPCM_CAPTURE ? 1 : 0; + }
/* create the FE DAI link */ @@ -1862,6 +1887,189 @@ static int soc_tplg_be_dai_elems_load(struct soc_tplg *tplg, return 0; }
+/* * + * set_be_link_hw_format - Set the HW audio format of the BE DAI link. + * @tplg: topology context + * @cfg: topology BE DAI link configs. + * + * Topology context contains a list of supported HW formats (configs) and + * a default format ID for the BE link. This function will use this default ID + * to choose the HW format to set the link's DAI format for init. + */ +static void set_be_link_hw_format(struct snd_soc_dai_link *link, + struct snd_soc_tplg_link_config *cfg) +{ + struct snd_soc_tplg_hw_config *hw_config; + unsigned char bclk_master, fsync_master; + unsigned char invert_bclk, invert_fsync; + int i; + + for (i = 0; i < cfg->num_hw_configs; i++) { + hw_config = &cfg->hw_config[i]; + if (hw_config->id != cfg->default_hw_config_id) + continue; + + link->dai_fmt = hw_config->fmt & SND_SOC_DAIFMT_FORMAT_MASK; + + /* clock signal polarity */ + invert_bclk = hw_config->invert_bclk; + invert_fsync = hw_config->invert_fsync; + if (!invert_bclk && !invert_fsync) + link->dai_fmt |= SND_SOC_DAIFMT_NB_NF; + else if (!invert_bclk && invert_fsync) + link->dai_fmt |= SND_SOC_DAIFMT_NB_IF; + else if (invert_bclk && !invert_fsync) + link->dai_fmt |= SND_SOC_DAIFMT_IB_NF; + else + link->dai_fmt |= SND_SOC_DAIFMT_IB_IF; + + /* clock masters */ + bclk_master = hw_config->bclk_master; + fsync_master = hw_config->fsync_master; + if (!bclk_master && !fsync_master) + link->dai_fmt |= SND_SOC_DAIFMT_CBM_CFM; + else if (bclk_master && !fsync_master) + link->dai_fmt |= SND_SOC_DAIFMT_CBS_CFM; + else if (!bclk_master && fsync_master) + link->dai_fmt |= SND_SOC_DAIFMT_CBM_CFS; + else + link->dai_fmt |= SND_SOC_DAIFMT_CBS_CFS; + + return; + } +} + +/* create a BE DAI link */ +static int soc_tplg_be_link_create(struct soc_tplg *tplg, + struct snd_soc_tplg_link_config *cfg) +{ + struct snd_soc_dai_link *link; + int i, ret = 0; + + dev_dbg(tplg->dev, + "Adding BE link %s, stream name %s\n", + cfg->name, cfg->stream_name); + + link = kzalloc(sizeof(struct snd_soc_dai_link), GFP_KERNEL); + if (link == NULL) + return -ENOMEM; + + /* id and names */ + if (strlen(cfg->name)) + link->name = cfg->name; + if (strlen(cfg->stream_name)) + link->stream_name = cfg->stream_name; + link->id = cfg->id; + + /* components */ + if (strlen(cfg->cpu.name)) + link->cpu_name = cfg->cpu.name; + link->cpu_dai_name = cfg->cpu.dai_name; + + if (!cfg->num_codecs || !cfg->codecs) { + ret = -EINVAL; + goto err; + } + + link->num_codecs = cfg->num_codecs; + link->codecs = kcalloc(link->num_codecs, + sizeof(struct snd_soc_dai_link_component), + GFP_KERNEL); + if (!link->codecs) { + ret = -ENOMEM; + goto err; + } + + for (i = 0; i < link->num_codecs ; i++) { + if (strlen(cfg->codecs[i].name)) + link->codecs[i].name = cfg->codecs[i].name; + link->codecs[i].dai_name = cfg->codecs[i].dai_name; + } + + /* hw format */ + if (cfg->num_hw_configs) + set_be_link_hw_format(link, cfg); + + /* flags */ + link->no_pcm = 1; + if (cfg->flag_mask) + set_link_flags(link, cfg->flag_mask, cfg->flags); + + /* pass control to component driver for optional further init */ + ret = soc_tplg_dai_link_load(tplg, link); + if (ret < 0) { + dev_err(tplg->dev, "ASoC: BE link loading failed\n"); + goto err; + } + + link->dobj.index = tplg->index; + link->dobj.ops = tplg->ops; + link->dobj.type = SND_SOC_DOBJ_DAI_LINK; + list_add(&link->dobj.list, &tplg->comp->dobj_list); + + snd_soc_add_dai_link(tplg->comp->card, link); + return 0; + +err: + if (link) { + kfree(link->codecs); + kfree(link->params); + kfree(link); + } + + return ret; +} + +/* Config an existing or create a new BE DAI link */ +static int soc_tplg_be_link_config(struct soc_tplg *tplg, + struct snd_soc_tplg_link_config *cfg) +{ + struct snd_soc_dai_link *link; + + link = snd_soc_find_dai_link(tplg->comp->card, cfg->id); + if (!link) + return soc_tplg_be_link_create(tplg, cfg); + + /* TODO: configure existing BE links. No user request atm. */ + return 0; +} + + +/* Load BE link elements from the topology context */ +static int soc_tplg_be_link_elems_load(struct soc_tplg *tplg, + struct snd_soc_tplg_hdr *hdr) +{ + struct snd_soc_tplg_link_config *link; + int count = hdr->count; + int i; + + if (tplg->pass != SOC_TPLG_PASS_LINK) { + tplg->pos += hdr->size + hdr->payload_size; + return 0; + }; + + if (soc_tplg_check_elem_count(tplg, + sizeof(struct snd_soc_tplg_link_config), count, + hdr->payload_size, "BE DAI link")) { + dev_err(tplg->dev, "ASoC: invalid count %d for BE DAI link elems\n", + count); + return -EINVAL; + } + + /* config or create the BE DAI links */ + for (i = 0; i < count; i++) { + link = (struct snd_soc_tplg_link_config *)tplg->pos; + if (link->size != sizeof(*link)) { + dev_err(tplg->dev, "ASoC: invalid link config size\n"); + return -EINVAL; + } + + soc_tplg_be_link_config(tplg, link); + tplg->pos += (sizeof(*link) + link->priv.size); + } + + return 0; +}
static int soc_tplg_manifest_load(struct soc_tplg *tplg, struct snd_soc_tplg_hdr *hdr) @@ -1968,6 +2176,8 @@ static int soc_tplg_load_header(struct soc_tplg *tplg, return soc_tplg_pcm_elems_load(tplg, hdr); case SND_SOC_TPLG_TYPE_BE_DAI: return soc_tplg_be_dai_elems_load(tplg, hdr); + case SND_SOC_TPLG_TYPE_BACKEND_LINK: + return soc_tplg_be_link_elems_load(tplg, hdr); case SND_SOC_TPLG_TYPE_MANIFEST: return soc_tplg_manifest_load(tplg, hdr); default:
participants (5)
-
Liam Girdwood
-
Mark Brown
-
Mengdong Lin
-
mengdong.lin@linux.intel.com
-
Shah, Hardik T