[alsa-devel] [PATCH v3 0/8] 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.
User will be able to config existing BE 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.
v3: Topology no longer creates BE DAI or BE DAI links, but only configure existing ones. The API to find a DAI link can also check the name and stream name in case a soc card doesn't use unique ID for DAI links. The user space code is also ready.
Mengdong Lin (8): ASoC: topology: ABI - Add flags to PCM ASoC: topology: ABI - Add private data to PCM ASoC: topology: ABI - Define DAI physical PCM data formats ASoC: topology: ABI - Add HW configurations to BE DAI links ASoC: topology: ABI - Add flags and private data to BE DAI links ASoC: topology: ABI - Add name and stream name to BE DAI links ASoC: Define API to find a dai link ASoC: topology: Add support to configure existing BE DAI links
include/sound/soc-dai.h | 15 +++-- include/sound/soc.h | 3 + include/uapi/sound/asoc.h | 67 +++++++++++++++++++ sound/soc/soc-core.c | 42 ++++++++++++ sound/soc/soc-topology.c | 166 ++++++++++++++++++++++++++++++++++++++++++++-- 5 files changed, 282 insertions(+), 11 deletions(-)
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 6b05047..b6e7063 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);
On Thu, Sep 29, 2016 at 02:08:51PM +0800, mengdong.lin@linux.intel.com wrote:
- __le32 flag_mask; /* bitmask of flags to configure */
- __le32 flags; /* SND_SOC_TPLG_LNK_FLGBIT_* flag value */
} __attribute__((packed));
I just followed up on the userspace patches but to repeat what I was saying there I think given that users are actively complaining about topology ABI files breaking we need to handle any extensions in a backwards compatible fashion.
On 10/06/2016 10:44 PM, Mark Brown wrote:
On Thu, Sep 29, 2016 at 02:08:51PM +0800, mengdong.lin@linux.intel.com wrote:
- __le32 flag_mask; /* bitmask of flags to configure */
- __le32 flags; /* SND_SOC_TPLG_LNK_FLGBIT_* flag value */ } __attribute__((packed));
I just followed up on the userspace patches but to repeat what I was saying there I think given that users are actively complaining about topology ABI files breaking we need to handle any extensions in a backwards compatible fashion.
Thanks for your comments!
We'll try to solve this backward compatible issue in kernel. And we'll support from topology ABI version 4.
Version 4 is now used by alsa-lib. Before version 4, only Intel use it internally and later we moved to version 4.
Thanks Mengdong
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 b6e7063..e76fb15 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: Mengdong Lin mengdong.lin@linux.intel.com
Define DAI physical PCM data formats for user space, so users can configure 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 309c9a7..de563d6 100644 --- a/include/uapi/sound/asoc.h +++ b/include/uapi/sound/asoc.h @@ -134,6 +134,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 runtime supported hardware configs of backend DAI links, 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 de563d6..5d06d65 100644 --- a/include/uapi/sound/asoc.h +++ b/include/uapi/sound/asoc.h @@ -39,6 +39,11 @@ */ #define SND_SOC_TPLG_STREAM_CONFIG_MAX 8
+/* + * 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 @@ -292,6 +297,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 @@ -480,6 +514,9 @@ struct snd_soc_tplg_link_config { __le32 id; /* unique ID - used to match */ struct snd_soc_tplg_stream stream[SND_SOC_TPLG_STREAM_CONFIG_MAX]; /* supported configs playback and captrure */ __le32 num_streams; /* number of streams */ + 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 DAI link.
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 5d06d65..d440bb1 100644 --- a/include/uapi/sound/asoc.h +++ b/include/uapi/sound/asoc.h @@ -138,6 +138,9 @@ /* 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)
/* DAI physical PCM data formats. * Add new formats to the end of the list. @@ -517,6 +520,9 @@ 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 also use name or stream name to find an existing backend link and configure it.
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 d440bb1..019c8af 100644 --- a/include/uapi/sound/asoc.h +++ b/include/uapi/sound/asoc.h @@ -515,6 +515,8 @@ 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 */ + char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; /* name - used to match */ + char stream_name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; /* stream name - used to match */ struct snd_soc_tplg_stream stream[SND_SOC_TPLG_STREAM_CONFIG_MAX]; /* supported configs playback and captrure */ __le32 num_streams; /* number of streams */ struct snd_soc_tplg_hw_config hw_config[SND_SOC_TPLG_HW_CONFIG_MAX]; /* hw configs */
From: Mengdong Lin mengdong.lin@linux.intel.com
Define the API to find an existing DAI link of the soc card by matching the ID, name and stream name.
Some cards may use unique ID for each DAI link, so matching ID is enough, and name or stream name are not necessary. But user need to specify name or stream name as well if not sure whether link ID is unique since most cards use 0 as the default link ID.
Topology can use this API to find an existing BE link and configure it.
Signed-off-by: Mengdong Lin mengdong.lin@linux.intel.com
diff --git a/include/sound/soc.h b/include/sound/soc.h index 4f1c784..c3a38ee 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -1671,6 +1671,9 @@ 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, const char *name, + const char *stream_name);
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 c0bbcd9..a7a1ca4 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -972,6 +972,48 @@ struct snd_soc_dai *snd_soc_find_dai( } EXPORT_SYMBOL_GPL(snd_soc_find_dai);
+ +/** + * snd_soc_find_dai_link - Find a DAI link + * + * @card: soc card + * @id: DAI link ID to match + * @name: DAI link name to match, optional + * @stream name: DAI link stream name to match, optional + * + * This function will search all existing DAI links of the soc card to + * find the link of the same ID. Since DAI links may not have their + * unique ID, so name and stream name should also match if being + * specified. + * + * Return: pointer of DAI link, or NULL if not found. + */ +struct snd_soc_dai_link *snd_soc_find_dai_link(struct snd_soc_card *card, + int id, const char *name, + const char *stream_name) +{ + 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) + continue; + + if (name && (!link->name || strcmp(name, link->name))) + continue; + + if (stream_name && (!link->stream_name + || strcmp(stream_name, link->stream_name))) + continue; + + 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) {
The patch
ASoC: Define API to find a dai link
has been applied to the asoc tree at
git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks, Mark
From 17fb175520e5497d71351aa66a125324fcb625a7 Mon Sep 17 00:00:00 2001
From: Mengdong Lin mengdong.lin@linux.intel.com Date: Thu, 3 Nov 2016 01:04:12 +0800 Subject: [PATCH] ASoC: Define API to find a dai link
Define the API to find an existing DAI link of the soc card by matching the ID, name and stream name.
Some cards may use unique ID for each DAI link, so matching ID is enough, and name or stream name are not necessary. But user need to specify name or stream name as well if not sure whether link ID is unique since most cards use 0 as the default link ID.
Topology can use this API to find an existing BE link and configure it.
Signed-off-by: Mengdong Lin mengdong.lin@linux.intel.com Signed-off-by: Mark Brown broonie@kernel.org --- include/sound/soc.h | 3 +++ sound/soc/soc-core.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+)
diff --git a/include/sound/soc.h b/include/sound/soc.h index 4f1c784e44f6..c3a38ee2b006 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -1671,6 +1671,9 @@ 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, const char *name, + const char *stream_name);
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 c0bbcd903261..a7a1ca40bcf5 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -972,6 +972,48 @@ struct snd_soc_dai *snd_soc_find_dai( } EXPORT_SYMBOL_GPL(snd_soc_find_dai);
+ +/** + * snd_soc_find_dai_link - Find a DAI link + * + * @card: soc card + * @id: DAI link ID to match + * @name: DAI link name to match, optional + * @stream name: DAI link stream name to match, optional + * + * This function will search all existing DAI links of the soc card to + * find the link of the same ID. Since DAI links may not have their + * unique ID, so name and stream name should also match if being + * specified. + * + * Return: pointer of DAI link, or NULL if not found. + */ +struct snd_soc_dai_link *snd_soc_find_dai_link(struct snd_soc_card *card, + int id, const char *name, + const char *stream_name) +{ + 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) + continue; + + if (name && (!link->name || strcmp(name, link->name))) + continue; + + if (stream_name && (!link->stream_name + || strcmp(stream_name, link->stream_name))) + continue; + + 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
Topology will find an existing BE (Backend) link by checking its ID, name and stream name, and configure its physical audio format and flags.
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 e76fb15..7526fe3 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; @@ -1631,6 +1632,20 @@ 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; }
/* create the FE DAI link */ @@ -1811,6 +1826,134 @@ 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; + } +} + + +/* Find and configure an existing 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; + const char *name, *stream_name; + int ret; + + name = strlen(cfg->name) ? cfg->name : NULL; + stream_name = strlen(cfg->stream_name) ? cfg->stream_name : NULL; + + link = snd_soc_find_dai_link(tplg->comp->card, cfg->id, + name, stream_name); + if (!link) { + dev_err(tplg->dev, "ASoC: BE DAI link %s (id %d) not exist\n", + name, cfg->id); + return -EINVAL; + } + + /* hw format */ + if (cfg->num_hw_configs) + set_be_link_hw_format(link, cfg); + + /* flags */ + 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"); + return ret; + } + + 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, ret; + + 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 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; + } + + ret = soc_tplg_be_link_config(tplg, link); + if (ret < 0) + return ret; + 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) @@ -1917,6 +2060,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 (3)
-
Mark Brown
-
Mengdong Lin
-
mengdong.lin@linux.intel.com