[PATCH v3 4/4] ASoC: pcm512x: Add support for more data formats
Currently, pcm512x driver supports only I2S data format. This commit adds RJ, LJ, DSP_A and DSP_B as well. I don't expect regression WRT existing sound cards, because: * default value in corresponding register of pcm512x codec is 0 == I2S * existing in-tree sound cards with pcm512x codec are configured for I2S * i don't see how existing off-tree sound cards with pcm512x codec could be configured differently - it would not work * tested explicitly, that there is no regression with Raspberry Pi + sound card `sound/soc/bcm/hifiberry_dacplus.c` Signed-off-by: Kirill Marinushkin Cc: Mark Brown Cc: Takashi Iwai Cc: Liam Girdwood Cc: Matthias Reichl Cc: Kuninori Morimoto Cc: Peter Ujfalusi Cc: alsa-de...@alsa-project.org Cc: linux-kernel@vger.kernel.org --- sound/soc/codecs/pcm512x.c | 38 ++ 1 file changed, 38 insertions(+) diff --git a/sound/soc/codecs/pcm512x.c b/sound/soc/codecs/pcm512x.c index 22ef77955a28..4dc844f3c1fc 100644 --- a/sound/soc/codecs/pcm512x.c +++ b/sound/soc/codecs/pcm512x.c @@ -1335,6 +1335,8 @@ static int pcm512x_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) { struct snd_soc_component *component = dai->component; struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component); + int afmt; + int offset = 0; int clock_output; int master_mode; int ret; @@ -1372,6 +1374,42 @@ static int pcm512x_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) return ret; } + switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { + case SND_SOC_DAIFMT_I2S: + afmt = PCM512x_AFMT_I2S; + break; + case SND_SOC_DAIFMT_RIGHT_J: + afmt = PCM512x_AFMT_RTJ; + break; + case SND_SOC_DAIFMT_LEFT_J: + afmt = PCM512x_AFMT_LTJ; + break; + case SND_SOC_DAIFMT_DSP_A: + offset = 1; + fallthrough; + case SND_SOC_DAIFMT_DSP_B: + afmt = PCM512x_AFMT_DSP; + break; + default: + dev_err(component->dev, "unsupported DAI format: 0x%x\n", + pcm512x->fmt); + return -EINVAL; + } + + ret = regmap_update_bits(pcm512x->regmap, PCM512x_I2S_1, +PCM512x_AFMT, afmt); + if (ret != 0) { + dev_err(component->dev, "Failed to set data format: %d\n", ret); + return ret; + } + + ret = regmap_update_bits(pcm512x->regmap, PCM512x_I2S_2, +0xFF, offset); + if (ret != 0) { + dev_err(component->dev, "Failed to set data offset: %d\n", ret); + return ret; + } + pcm512x->fmt = fmt; return 0; -- 2.13.6
[PATCH v3 0/4] ASoC: pcm512x: Patch series to set fmt from `set_fmt()`
Set format from `set_fmt()` func instead of `hw_params()`, plus supportive commits Kirill Marinushkin (4): ASoC: pcm512x: Fix not setting word length if DAIFMT_CBS_CFS ASoC: pcm512x: Rearrange operations in `hw_params()` ASoC: pcm512x: Move format check into `set_fmt()` ASoC: pcm512x: Add support for more data formats sound/soc/codecs/pcm512x.c | 134 - 1 file changed, 84 insertions(+), 50 deletions(-) -- 2.13.6
[PATCH v3 1/4] ASoC: pcm512x: Fix not setting word length if DAIFMT_CBS_CFS
In `pcm512x_hw_params()`, the following switch-case: switch (pcm512x->fmt & SND_SOC_DAIFMT_MASTER_MASK) { case SND_SOC_DAIFMT_CBS_CFS: returns 0, which was preventing word length from being written into codecs register. Fixed by writing it into register before checking `SND_SOC_DAIFMT_MASTER_MASK`. Tested with Raspberry Pi + sound card `hifiberry_dacplus` in CBS_CFS format Signed-off-by: Kirill Marinushkin Cc: Mark Brown Cc: Takashi Iwai Cc: Liam Girdwood Cc: Matthias Reichl Cc: Kuninori Morimoto Cc: Peter Ujfalusi Cc: alsa-de...@alsa-project.org Cc: linux-kernel@vger.kernel.org --- sound/soc/codecs/pcm512x.c | 14 +++--- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/sound/soc/codecs/pcm512x.c b/sound/soc/codecs/pcm512x.c index 8153d3d01654..db3dc6a40feb 100644 --- a/sound/soc/codecs/pcm512x.c +++ b/sound/soc/codecs/pcm512x.c @@ -1195,6 +1195,13 @@ static int pcm512x_hw_params(struct snd_pcm_substream *substream, return -EINVAL; } + ret = regmap_update_bits(pcm512x->regmap, PCM512x_I2S_1, +PCM512x_ALEN, alen); + if (ret != 0) { + dev_err(component->dev, "Failed to set frame size: %d\n", ret); + return ret; + } + switch (pcm512x->fmt & SND_SOC_DAIFMT_MASTER_MASK) { case SND_SOC_DAIFMT_CBS_CFS: ret = regmap_update_bits(pcm512x->regmap, @@ -1229,13 +1236,6 @@ static int pcm512x_hw_params(struct snd_pcm_substream *substream, return -EINVAL; } - ret = regmap_update_bits(pcm512x->regmap, PCM512x_I2S_1, -PCM512x_ALEN, alen); - if (ret != 0) { - dev_err(component->dev, "Failed to set frame size: %d\n", ret); - return ret; - } - if (pcm512x->pll_out) { ret = regmap_write(pcm512x->regmap, PCM512x_FLEX_A, 0x11); if (ret != 0) { -- 2.13.6
[PATCH v3 3/4] ASoC: pcm512x: Move format check into `set_fmt()`
I would like to describe the reasoning by quoting Peter Ujfalusi from his review of this patch series v1 [1]: > When you bind a link you will use set_fmt for the two sides to see if > they can agree, that both can support what has been asked. > > The pcm512x driver just saves the fmt and say back to that card: > whatever, I'm fine with it. But runtime during hw_params it can fail due > to unsupported bus format, which it actually acked to be ok. > > This is the difference. > > Sure, some device have constraint based on the fmt towards the hw_params > and it is perfectly OK to do such a checks and rejections or build > rules/constraints based on fmt, but failing hw_params just because > set_fmt did not checked that the bus format is not even supported is not > a nice thing to do. [1] https://patchwork.kernel.org/project/alsa-devel/patch/ 20201109212133.25869-1-kmarinush...@birdec.com/ Signed-off-by: Kirill Marinushkin Cc: Mark Brown Cc: Takashi Iwai Cc: Liam Girdwood Cc: Matthias Reichl Cc: Kuninori Morimoto Cc: Peter Ujfalusi Cc: alsa-de...@alsa-project.org Cc: linux-kernel@vger.kernel.org --- sound/soc/codecs/pcm512x.c | 55 +- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/sound/soc/codecs/pcm512x.c b/sound/soc/codecs/pcm512x.c index aa55a477a28f..22ef77955a28 100644 --- a/sound/soc/codecs/pcm512x.c +++ b/sound/soc/codecs/pcm512x.c @@ -1168,8 +1168,6 @@ static int pcm512x_hw_params(struct snd_pcm_substream *substream, struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component); int alen; int gpio; - int clock_output; - int master_mode; int ret; dev_dbg(component->dev, "hw_params %u Hz, %u channels\n", @@ -1202,11 +1200,8 @@ static int pcm512x_hw_params(struct snd_pcm_substream *substream, return ret; } - switch (pcm512x->fmt & SND_SOC_DAIFMT_MASTER_MASK) { - case SND_SOC_DAIFMT_CBS_CFS: - clock_output = 0; - master_mode = 0; - + if ((pcm512x->fmt & SND_SOC_DAIFMT_MASTER_MASK) == + SND_SOC_DAIFMT_CBS_CFS) { ret = regmap_update_bits(pcm512x->regmap, PCM512x_ERROR_DETECT, PCM512x_DCAS, 0); if (ret != 0) { @@ -1216,16 +1211,6 @@ static int pcm512x_hw_params(struct snd_pcm_substream *substream, return ret; } goto skip_pll; - case SND_SOC_DAIFMT_CBM_CFM: - clock_output = PCM512x_BCKO | PCM512x_LRKO; - master_mode = PCM512x_RLRK | PCM512x_RBCK; - break; - case SND_SOC_DAIFMT_CBM_CFS: - clock_output = PCM512x_BCKO; - master_mode = PCM512x_RBCK; - break; - default: - return -EINVAL; } if (pcm512x->pll_out) { @@ -1343,6 +1328,34 @@ static int pcm512x_hw_params(struct snd_pcm_substream *substream, } skip_pll: + return 0; +} + +static int pcm512x_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) +{ + struct snd_soc_component *component = dai->component; + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component); + int clock_output; + int master_mode; + int ret; + + switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { + case SND_SOC_DAIFMT_CBS_CFS: + clock_output = 0; + master_mode = 0; + break; + case SND_SOC_DAIFMT_CBM_CFM: + clock_output = PCM512x_BCKO | PCM512x_LRKO; + master_mode = PCM512x_RLRK | PCM512x_RBCK; + break; + case SND_SOC_DAIFMT_CBM_CFS: + clock_output = PCM512x_BCKO; + master_mode = PCM512x_RBCK; + break; + default: + return -EINVAL; + } + ret = regmap_update_bits(pcm512x->regmap, PCM512x_BCLK_LRCLK_CFG, PCM512x_BCKP | PCM512x_BCKO | PCM512x_LRKO, clock_output); @@ -1359,14 +1372,6 @@ static int pcm512x_hw_params(struct snd_pcm_substream *substream, return ret; } - return 0; -} - -static int pcm512x_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) -{ - struct snd_soc_component *component = dai->component; - struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component); - pcm512x->fmt = fmt; return 0; -- 2.13.6
[PATCH v3 2/4] ASoC: pcm512x: Rearrange operations in `hw_params()`
This commit is a preparation for the next patch in the series. It's goal is to make format check easy-to-move-out. Theoretically, more butifications are possile in `hw_params()` func, but my intention in this commit is to keep behaviour unchanged. Signed-off-by: Kirill Marinushkin Cc: Mark Brown Cc: Takashi Iwai Cc: Liam Girdwood Cc: Matthias Reichl Cc: Kuninori Morimoto Cc: Peter Ujfalusi Cc: alsa-de...@alsa-project.org Cc: linux-kernel@vger.kernel.org --- sound/soc/codecs/pcm512x.c | 49 +++--- 1 file changed, 20 insertions(+), 29 deletions(-) diff --git a/sound/soc/codecs/pcm512x.c b/sound/soc/codecs/pcm512x.c index db3dc6a40feb..aa55a477a28f 100644 --- a/sound/soc/codecs/pcm512x.c +++ b/sound/soc/codecs/pcm512x.c @@ -1204,16 +1204,8 @@ static int pcm512x_hw_params(struct snd_pcm_substream *substream, switch (pcm512x->fmt & SND_SOC_DAIFMT_MASTER_MASK) { case SND_SOC_DAIFMT_CBS_CFS: - ret = regmap_update_bits(pcm512x->regmap, -PCM512x_BCLK_LRCLK_CFG, -PCM512x_BCKP -| PCM512x_BCKO | PCM512x_LRKO, -0); - if (ret != 0) { - dev_err(component->dev, - "Failed to enable slave mode: %d\n", ret); - return ret; - } + clock_output = 0; + master_mode = 0; ret = regmap_update_bits(pcm512x->regmap, PCM512x_ERROR_DETECT, PCM512x_DCAS, 0); @@ -1223,7 +1215,7 @@ static int pcm512x_hw_params(struct snd_pcm_substream *substream, ret); return ret; } - return 0; + goto skip_pll; case SND_SOC_DAIFMT_CBM_CFM: clock_output = PCM512x_BCKO | PCM512x_LRKO; master_mode = PCM512x_RLRK | PCM512x_RBCK; @@ -1316,25 +1308,7 @@ static int pcm512x_hw_params(struct snd_pcm_substream *substream, dev_err(component->dev, "Failed to enable pll: %d\n", ret); return ret; } - } - - ret = regmap_update_bits(pcm512x->regmap, PCM512x_BCLK_LRCLK_CFG, -PCM512x_BCKP | PCM512x_BCKO | PCM512x_LRKO, -clock_output); - if (ret != 0) { - dev_err(component->dev, "Failed to enable clock output: %d\n", ret); - return ret; - } - ret = regmap_update_bits(pcm512x->regmap, PCM512x_MASTER_MODE, -PCM512x_RLRK | PCM512x_RBCK, -master_mode); - if (ret != 0) { - dev_err(component->dev, "Failed to enable master mode: %d\n", ret); - return ret; - } - - if (pcm512x->pll_out) { gpio = PCM512x_G1OE << (pcm512x->pll_out - 1); ret = regmap_update_bits(pcm512x->regmap, PCM512x_GPIO_EN, gpio, gpio); @@ -1368,6 +1342,23 @@ static int pcm512x_hw_params(struct snd_pcm_substream *substream, return ret; } +skip_pll: + ret = regmap_update_bits(pcm512x->regmap, PCM512x_BCLK_LRCLK_CFG, +PCM512x_BCKP | PCM512x_BCKO | PCM512x_LRKO, +clock_output); + if (ret != 0) { + dev_err(component->dev, "Failed to enable clock output: %d\n", ret); + return ret; + } + + ret = regmap_update_bits(pcm512x->regmap, PCM512x_MASTER_MODE, +PCM512x_RLRK | PCM512x_RBCK, +master_mode); + if (ret != 0) { + dev_err(component->dev, "Failed to enable master mode: %d\n", ret); + return ret; + } + return 0; } -- 2.13.6
Re: [PATCH] ASoC: pcm512x: Add support for data formats RJ and LJ
Hello Peter, On 11/12/2020 08:41 AM, Peter Ujfalusi wrote: > Hi Kirill, > > On 11/11/2020 9.54, Kirill Marinushkin wrote: >> Hello Peter, >> >> than you for your review! >> >>> The bus format and >>> >>>>switch (pcm512x->fmt & SND_SOC_DAIFMT_MASTER_MASK) { >>> >>>>case SND_SOC_DAIFMT_CBS_CFS: >>>>ret = regmap_update_bits(pcm512x->regmap, >>> >>> the clock generation role should be set in pcm512x_set_fmt(), in that >>> way you can deny specific setups earlier. >> >> I think we could move both checks for`SND_SOC_DAIFMT_FORMAT_MASK` and >> `SND_SOC_DAIFMT_MASTER_MASK` into `pcm512x_set_fmt()`. But it would be a >> different scope, and I didn't intend to do that level of refactoring. > > Right, I was just saying what would make sense. > >> Looking at other codecs in kernel, I would say, that doing those checks in >> `pcm512x_hw_params()`, as they are done currently, is an equally valid >> approach. > > The exception proves the rule > >> As technically keeping checs where they are now doesn't break anything > > They are just in a wrong place. > >> and is >> aligned with ASoC codecs design, I suggest to keep the checks where they are. > > The set_fmt callback is there to set the bus format, it has nothing to > do (in most cases) with the sample format (hw_params). Bus coding, clock > source has nothing to do with hw_params. > > When you bind a link you will use set_fmt for the two sides to see if > they can agree, that both can support what has been asked. > > The pcm512x driver just saves the fmt and say back to that card: > whatever, I'm fine with it. But runtime during hw_params it can fail due > to unsupported bus format, which it actually acked to be ok. > > This is the difference. > > Sure, some device have constraint based on the fmt towards the hw_params > and it is perfectly OK to do such a checks and rejections or build > rules/constraints based on fmt, but failing hw_params just because > set_fmt did not checked that the bus format is not even supported is not > a nice thing to do. Those are good arguments >> Would you agree? > > I don't have a device to test, I'm just trying to point out what is the > right thing to do. I have a device to test. I will move format checks into `pcm512x_set_fmt()`, ensure that it works properly, and submit as patch v3. > I don't buy the argument that the sequencing is important here for the > register writes. The fmt is set only once and those registers will be > only written once. > >>> I would also add DSP_A and DSP_B modes at the same time, DSP_A would >>> need a write of 1 to register 41 (PCM512x_I2S_2, offset = 1), other >>> formats should set the offset to 0. >> >> That's a good idea, than you for technical details! I just didn't know how to >> use DSP_A and DSP_B. I will add them, and submit as patch v2 > > Great! > Thanks > - Péter > >> Best regards, >> Kirill >> >> On 11/10/2020 07:59 AM, Peter Ujfalusi wrote: >>> >>> >>> On 09/11/2020 23.21, Kirill Marinushkin wrote: >>>> Currently, pcm512x driver supports only I2S data format. >>>> This commit adds RJ and LJ as well. >>>> >>>> I don't expect regression WRT existing sound cards, because: >>>> >>>> * default value in corresponding register of pcm512x codec is 0 == I2S >>>> * existing in-tree sound cards with pcm512x codec are configured for I2S >>>> * i don't see how existing off-tree sound cards with pcm512x codec could be >>>> configured differently - it would not work >>>> * tested explicitly, that there is no regression with Raspberry Pi + >>>> sound card `sound/soc/bcm/hifiberry_dacplus.c` >>>> >>>> Signed-off-by: Kirill Marinushkin >>>> Cc: Mark Brown >>>> Cc: Takashi Iwai >>>> Cc: Liam Girdwood >>>> Cc: Matthias Reichl >>>> Cc: Kuninori Morimoto >>>> Cc: Peter Ujfalusi >>>> Cc: alsa-de...@alsa-project.org >>>> Cc: linux-kernel@vger.kernel.org >>>> --- >>>> sound/soc/codecs/pcm512x.c | 24 >>>> 1 file changed, 24 insertions(+) >>>> >>>> diff --git a/sound/soc/codecs/pcm512x.c b/sound/soc/codecs/pcm512x.c >>>> index 8153d3d01654..c6e975fb4a43 100644 >>>> --- a/sound/soc/codecs/pcm512x.c >>>> +++ b/sound/soc/codecs/pcm512x.c >>>> @@ -1167,6 +1167,7 @@ static in
[PATCH v2] ASoC: pcm512x: Add support for more data formats
Currently, pcm512x driver supports only I2S data format. This commit adds RJ, LJ, DSP_A and DSP_B as well. I don't expect regression WRT existing sound cards, because: * default value in corresponding register of pcm512x codec is 0 == I2S * existing in-tree sound cards with pcm512x codec are configured for I2S * i don't see how existing off-tree sound cards with pcm512x codec could be configured differently - it would not work * tested explicitly, that there is no regression with Raspberry Pi + sound card `sound/soc/bcm/hifiberry_dacplus.c` Signed-off-by: Kirill Marinushkin Cc: Mark Brown Cc: Takashi Iwai Cc: Liam Girdwood Cc: Matthias Reichl Cc: Kuninori Morimoto Cc: Peter Ujfalusi Cc: alsa-de...@alsa-project.org Cc: linux-kernel@vger.kernel.org --- sound/soc/codecs/pcm512x.c | 38 ++ 1 file changed, 38 insertions(+) diff --git a/sound/soc/codecs/pcm512x.c b/sound/soc/codecs/pcm512x.c index 8153d3d01654..e309227649e7 100644 --- a/sound/soc/codecs/pcm512x.c +++ b/sound/soc/codecs/pcm512x.c @@ -1167,6 +1167,8 @@ static int pcm512x_hw_params(struct snd_pcm_substream *substream, struct snd_soc_component *component = dai->component; struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component); int alen; + int afmt; + int offset = 0; int gpio; int clock_output; int master_mode; @@ -1195,6 +1197,28 @@ static int pcm512x_hw_params(struct snd_pcm_substream *substream, return -EINVAL; } + switch (pcm512x->fmt & SND_SOC_DAIFMT_FORMAT_MASK) { + case SND_SOC_DAIFMT_I2S: + afmt = PCM512x_AFMT_I2S; + break; + case SND_SOC_DAIFMT_RIGHT_J: + afmt = PCM512x_AFMT_RTJ; + break; + case SND_SOC_DAIFMT_LEFT_J: + afmt = PCM512x_AFMT_LTJ; + break; + case SND_SOC_DAIFMT_DSP_A: + offset = 1; + fallthrough; + case SND_SOC_DAIFMT_DSP_B: + afmt = PCM512x_AFMT_DSP; + break; + default: + dev_err(component->dev, "unsupported DAI format: 0x%x\n", + pcm512x->fmt); + return -EINVAL; + } + switch (pcm512x->fmt & SND_SOC_DAIFMT_MASTER_MASK) { case SND_SOC_DAIFMT_CBS_CFS: ret = regmap_update_bits(pcm512x->regmap, @@ -1236,6 +1260,20 @@ static int pcm512x_hw_params(struct snd_pcm_substream *substream, return ret; } + ret = regmap_update_bits(pcm512x->regmap, PCM512x_I2S_1, +PCM512x_AFMT, afmt); + if (ret != 0) { + dev_err(component->dev, "Failed to set data format: %d\n", ret); + return ret; + } + + ret = regmap_update_bits(pcm512x->regmap, PCM512x_I2S_2, +0xFF, offset); + if (ret != 0) { + dev_err(component->dev, "Failed to set data offset: %d\n", ret); + return ret; + } + if (pcm512x->pll_out) { ret = regmap_write(pcm512x->regmap, PCM512x_FLEX_A, 0x11); if (ret != 0) { -- 2.13.6
Re: [PATCH] ASoC: pcm512x: Add support for data formats RJ and LJ
Hello Peter, than you for your review! > The bus format and > >> switch (pcm512x->fmt & SND_SOC_DAIFMT_MASTER_MASK) { > >> case SND_SOC_DAIFMT_CBS_CFS: >> ret = regmap_update_bits(pcm512x->regmap, > > the clock generation role should be set in pcm512x_set_fmt(), in that > way you can deny specific setups earlier. I think we could move both checks for`SND_SOC_DAIFMT_FORMAT_MASK` and `SND_SOC_DAIFMT_MASTER_MASK` into `pcm512x_set_fmt()`. But it would be a different scope, and I didn't intend to do that level of refactoring. Looking at other codecs in kernel, I would say, that doing those checks in `pcm512x_hw_params()`, as they are done currently, is an equally valid approach. As technically keeping checs where they are now doesn't break anything, and is aligned with ASoC codecs design, I suggest to keep the checks where they are. Would you agree? > I would also add DSP_A and DSP_B modes at the same time, DSP_A would > need a write of 1 to register 41 (PCM512x_I2S_2, offset = 1), other > formats should set the offset to 0. That's a good idea, than you for technical details! I just didn't know how to use DSP_A and DSP_B. I will add them, and submit as patch v2 Best regards, Kirill On 11/10/2020 07:59 AM, Peter Ujfalusi wrote: > > > On 09/11/2020 23.21, Kirill Marinushkin wrote: >> Currently, pcm512x driver supports only I2S data format. >> This commit adds RJ and LJ as well. >> >> I don't expect regression WRT existing sound cards, because: >> >> * default value in corresponding register of pcm512x codec is 0 == I2S >> * existing in-tree sound cards with pcm512x codec are configured for I2S >> * i don't see how existing off-tree sound cards with pcm512x codec could be >> configured differently - it would not work >> * tested explicitly, that there is no regression with Raspberry Pi + >> sound card `sound/soc/bcm/hifiberry_dacplus.c` >> >> Signed-off-by: Kirill Marinushkin >> Cc: Mark Brown >> Cc: Takashi Iwai >> Cc: Liam Girdwood >> Cc: Matthias Reichl >> Cc: Kuninori Morimoto >> Cc: Peter Ujfalusi >> Cc: alsa-de...@alsa-project.org >> Cc: linux-kernel@vger.kernel.org >> --- >> sound/soc/codecs/pcm512x.c | 24 >> 1 file changed, 24 insertions(+) >> >> diff --git a/sound/soc/codecs/pcm512x.c b/sound/soc/codecs/pcm512x.c >> index 8153d3d01654..c6e975fb4a43 100644 >> --- a/sound/soc/codecs/pcm512x.c >> +++ b/sound/soc/codecs/pcm512x.c >> @@ -1167,6 +1167,7 @@ static int pcm512x_hw_params(struct snd_pcm_substream >> *substream, >> struct snd_soc_component *component = dai->component; >> struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component); >> int alen; >> +int afmt; >> int gpio; >> int clock_output; >> int master_mode; >> @@ -1195,6 +1196,22 @@ static int pcm512x_hw_params(struct snd_pcm_substream >> *substream, >> return -EINVAL; >> } >> >> +switch (pcm512x->fmt & SND_SOC_DAIFMT_FORMAT_MASK) { >> +case SND_SOC_DAIFMT_I2S: >> +afmt = PCM512x_AFMT_I2S; >> +break; >> +case SND_SOC_DAIFMT_RIGHT_J: >> +afmt = PCM512x_AFMT_RTJ; >> +break; >> +case SND_SOC_DAIFMT_LEFT_J: >> +afmt = PCM512x_AFMT_LTJ; >> +break; >> +default: >> +dev_err(component->dev, "unsupported DAI format: 0x%x\n", >> +pcm512x->fmt); >> +return -EINVAL; >> +} >> + > > The bus format and > >> switch (pcm512x->fmt & SND_SOC_DAIFMT_MASTER_MASK) { > >> case SND_SOC_DAIFMT_CBS_CFS: >> ret = regmap_update_bits(pcm512x->regmap, > > the clock generation role should be set in pcm512x_set_fmt(), in that > way you can deny specific setups earlier. > > I would also add DSP_A and DSP_B modes at the same time, DSP_A would > need a write of 1 to register 41 (PCM512x_I2S_2, offset = 1), other > formats should set the offset to 0. > >> @@ -1236,6 +1253,13 @@ static int pcm512x_hw_params(struct snd_pcm_substream >> *substream, >> return ret; >> } >> >> +ret = regmap_update_bits(pcm512x->regmap, PCM512x_I2S_1, >> + PCM512x_AFMT, afmt); >> +if (ret != 0) { >> +dev_err(component->dev, "Failed to set data format: %d\n", ret); >> +return ret; >> +} >> + >> if (pcm512x->pll_out) { >> ret = regmap_write(pcm512x->regmap, PCM512x_FLEX_A, 0x11); >> if (ret != 0) { >> > > - Péter > > Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. > Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki >
[PATCH] ASoC: pcm512x: Add support for data formats RJ and LJ
Currently, pcm512x driver supports only I2S data format. This commit adds RJ and LJ as well. I don't expect regression WRT existing sound cards, because: * default value in corresponding register of pcm512x codec is 0 == I2S * existing in-tree sound cards with pcm512x codec are configured for I2S * i don't see how existing off-tree sound cards with pcm512x codec could be configured differently - it would not work * tested explicitly, that there is no regression with Raspberry Pi + sound card `sound/soc/bcm/hifiberry_dacplus.c` Signed-off-by: Kirill Marinushkin Cc: Mark Brown Cc: Takashi Iwai Cc: Liam Girdwood Cc: Matthias Reichl Cc: Kuninori Morimoto Cc: Peter Ujfalusi Cc: alsa-de...@alsa-project.org Cc: linux-kernel@vger.kernel.org --- sound/soc/codecs/pcm512x.c | 24 1 file changed, 24 insertions(+) diff --git a/sound/soc/codecs/pcm512x.c b/sound/soc/codecs/pcm512x.c index 8153d3d01654..c6e975fb4a43 100644 --- a/sound/soc/codecs/pcm512x.c +++ b/sound/soc/codecs/pcm512x.c @@ -1167,6 +1167,7 @@ static int pcm512x_hw_params(struct snd_pcm_substream *substream, struct snd_soc_component *component = dai->component; struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component); int alen; + int afmt; int gpio; int clock_output; int master_mode; @@ -1195,6 +1196,22 @@ static int pcm512x_hw_params(struct snd_pcm_substream *substream, return -EINVAL; } + switch (pcm512x->fmt & SND_SOC_DAIFMT_FORMAT_MASK) { + case SND_SOC_DAIFMT_I2S: + afmt = PCM512x_AFMT_I2S; + break; + case SND_SOC_DAIFMT_RIGHT_J: + afmt = PCM512x_AFMT_RTJ; + break; + case SND_SOC_DAIFMT_LEFT_J: + afmt = PCM512x_AFMT_LTJ; + break; + default: + dev_err(component->dev, "unsupported DAI format: 0x%x\n", + pcm512x->fmt); + return -EINVAL; + } + switch (pcm512x->fmt & SND_SOC_DAIFMT_MASTER_MASK) { case SND_SOC_DAIFMT_CBS_CFS: ret = regmap_update_bits(pcm512x->regmap, @@ -1236,6 +1253,13 @@ static int pcm512x_hw_params(struct snd_pcm_substream *substream, return ret; } + ret = regmap_update_bits(pcm512x->regmap, PCM512x_I2S_1, +PCM512x_AFMT, afmt); + if (ret != 0) { + dev_err(component->dev, "Failed to set data format: %d\n", ret); + return ret; + } + if (pcm512x->pll_out) { ret = regmap_write(pcm512x->regmap, PCM512x_FLEX_A, 0x11); if (ret != 0) { -- 2.13.6
[PATCH] ASoC: Relocate my e-mail to .com domain zone
Signed-off-by: Kirill Marinushkin --- MAINTAINERS| 2 +- sound/soc/codecs/pcm3060-i2c.c | 4 ++-- sound/soc/codecs/pcm3060-spi.c | 4 ++-- sound/soc/codecs/pcm3060.c | 4 ++-- sound/soc/codecs/pcm3060.h | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/MAINTAINERS b/MAINTAINERS index 558acf24ea1e..9cdc10e80d78 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -15829,7 +15829,7 @@ S: Maintained F: drivers/net/ethernet/ti/netcp* TI PCM3060 ASoC CODEC DRIVER -M: Kirill Marinushkin +M: Kirill Marinushkin L: alsa-de...@alsa-project.org (moderated for non-subscribers) S: Maintained F: Documentation/devicetree/bindings/sound/pcm3060.txt diff --git a/sound/soc/codecs/pcm3060-i2c.c b/sound/soc/codecs/pcm3060-i2c.c index cdc8314882bc..abcdeb922201 100644 --- a/sound/soc/codecs/pcm3060-i2c.c +++ b/sound/soc/codecs/pcm3060-i2c.c @@ -2,7 +2,7 @@ // // PCM3060 I2C driver // -// Copyright (C) 2018 Kirill Marinushkin +// Copyright (C) 2018 Kirill Marinushkin #include #include @@ -56,5 +56,5 @@ static struct i2c_driver pcm3060_i2c_driver = { module_i2c_driver(pcm3060_i2c_driver); MODULE_DESCRIPTION("PCM3060 I2C driver"); -MODULE_AUTHOR("Kirill Marinushkin "); +MODULE_AUTHOR("Kirill Marinushkin "); MODULE_LICENSE("GPL v2"); diff --git a/sound/soc/codecs/pcm3060-spi.c b/sound/soc/codecs/pcm3060-spi.c index f6f19fa80932..3b79734b832b 100644 --- a/sound/soc/codecs/pcm3060-spi.c +++ b/sound/soc/codecs/pcm3060-spi.c @@ -2,7 +2,7 @@ // // PCM3060 SPI driver // -// Copyright (C) 2018 Kirill Marinushkin +// Copyright (C) 2018 Kirill Marinushkin #include #include @@ -55,5 +55,5 @@ static struct spi_driver pcm3060_spi_driver = { module_spi_driver(pcm3060_spi_driver); MODULE_DESCRIPTION("PCM3060 SPI driver"); -MODULE_AUTHOR("Kirill Marinushkin "); +MODULE_AUTHOR("Kirill Marinushkin "); MODULE_LICENSE("GPL v2"); diff --git a/sound/soc/codecs/pcm3060.c b/sound/soc/codecs/pcm3060.c index 32b26f1c2282..b2358069cf9b 100644 --- a/sound/soc/codecs/pcm3060.c +++ b/sound/soc/codecs/pcm3060.c @@ -2,7 +2,7 @@ // // PCM3060 codec driver // -// Copyright (C) 2018 Kirill Marinushkin +// Copyright (C) 2018 Kirill Marinushkin #include #include @@ -342,5 +342,5 @@ int pcm3060_probe(struct device *dev) EXPORT_SYMBOL(pcm3060_probe); MODULE_DESCRIPTION("PCM3060 codec driver"); -MODULE_AUTHOR("Kirill Marinushkin "); +MODULE_AUTHOR("Kirill Marinushkin "); MODULE_LICENSE("GPL v2"); diff --git a/sound/soc/codecs/pcm3060.h b/sound/soc/codecs/pcm3060.h index 75931c9a9d85..18d51e5dac2c 100644 --- a/sound/soc/codecs/pcm3060.h +++ b/sound/soc/codecs/pcm3060.h @@ -2,7 +2,7 @@ /* * PCM3060 codec driver * - * Copyright (C) 2018 Kirill Marinushkin + * Copyright (C) 2018 Kirill Marinushkin */ #ifndef _SND_SOC_PCM3060_H -- 2.13.6
Re: [PATCH v1 2/4] ASoC: Add codec driver for ST TDA7802
On 06/11/19 19:49, Thomas Preston wrote: > Add an I2C based codec driver for ST TDA7802 amplifier. By default, the > amplifier supports 4 audio channels but can support up to 16 with > multiple devices. Input is configurable for I2S or TDM. > > The unified device properties API is used to get board-specific config from > device tree / ACPI. > > Signed-off-by: Thomas Preston > Cc: Patrick Glaser > Cc: Rob Duncan > Cc: Nate Case > --- > sound/soc/codecs/Kconfig | 6 + > sound/soc/codecs/Makefile | 2 + > sound/soc/codecs/tda7802.c | 580 > + > 3 files changed, 588 insertions(+) > create mode 100644 sound/soc/codecs/tda7802.c > > diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig > index e730d47ac85b..1d30c2333cb1 100644 > --- a/sound/soc/codecs/Kconfig > +++ b/sound/soc/codecs/Kconfig > @@ -176,6 +176,7 @@ config SND_SOC_ALL_CODECS > select SND_SOC_TAS5720 if I2C > select SND_SOC_TAS6424 if I2C > select SND_SOC_TDA7419 if I2C > + select SND_SOC_TDA7802 if I2C > select SND_SOC_TFA9879 if I2C > select SND_SOC_TLV320AIC23_I2C if I2C > select SND_SOC_TLV320AIC23_SPI if SPI_MASTER > @@ -1078,6 +1079,11 @@ config SND_SOC_TDA7419 > depends on I2C > select REGMAP_I2C > > +config SND_SOC_TDA7802 > + tristate "ST TDA7802 audio processor" > + depends on I2C > + select REGMAP_I2C > + > config SND_SOC_TFA9879 > tristate "NXP Semiconductors TFA9879 amplifier" > depends on I2C > diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile > index aa7720a7a0aa..fc3fc672bc4b 100644 > --- a/sound/soc/codecs/Makefile > +++ b/sound/soc/codecs/Makefile > @@ -187,6 +187,7 @@ snd-soc-tas571x-objs := tas571x.o > snd-soc-tas5720-objs := tas5720.o > snd-soc-tas6424-objs := tas6424.o > snd-soc-tda7419-objs := tda7419.o > +snd-soc-tda7802-objs := tda7802.o > snd-soc-tfa9879-objs := tfa9879.o > snd-soc-tlv320aic23-objs := tlv320aic23.o > snd-soc-tlv320aic23-i2c-objs := tlv320aic23-i2c.o > @@ -460,6 +461,7 @@ obj-$(CONFIG_SND_SOC_TAS571X) += snd-soc-tas571x.o > obj-$(CONFIG_SND_SOC_TAS5720)+= snd-soc-tas5720.o > obj-$(CONFIG_SND_SOC_TAS6424)+= snd-soc-tas6424.o > obj-$(CONFIG_SND_SOC_TDA7419)+= snd-soc-tda7419.o > +obj-$(CONFIG_SND_SOC_TDA7802)+= snd-soc-tda7802.o > obj-$(CONFIG_SND_SOC_TFA9879)+= snd-soc-tfa9879.o > obj-$(CONFIG_SND_SOC_TLV320AIC23)+= snd-soc-tlv320aic23.o > obj-$(CONFIG_SND_SOC_TLV320AIC23_I2C)+= snd-soc-tlv320aic23-i2c.o > diff --git a/sound/soc/codecs/tda7802.c b/sound/soc/codecs/tda7802.c > new file mode 100644 > index ..38ca52de85f0 > --- /dev/null > +++ b/sound/soc/codecs/tda7802.c > @@ -0,0 +1,580 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * tda7802.c -- codec driver for ST TDA7802 > + * > + * Copyright (C) 2016-2019 Tesla Motors, Inc. > + * > + * This program is free software; you can redistribute it and/or > + * modify it under the terms of the GNU General Public License as > + * published by the Free Software Foundation; either version 2 of the > + * License, or (at your option) any later version. > + * > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +enum tda7802_type { > + tda7802_base, > +}; > + > +#define I2C_BUS 4 > + > +#define CHANNELS_PER_AMP4 > +#define MAX_NUM_AMPS4 > + > +#define ENABLE_DELAY_MS 10 > + > +#define TDA7802_IB0 0x00 > +#define TDA7802_IB1 0x01 > +#define TDA7802_IB2 0x02 > +#define TDA7802_IB3 0x03 > +#define TDA7802_IB4 0x04 > +#define TDA7802_IB5 0x05 > + > +#define TDA7802_DB0 0x10 > +#define TDA7802_DB1 0x11 > +#define TDA7802_DB2 0x12 > +#define TDA7802_DB3 0x13 > +#define TDA7802_DB4 0x14 > +#define TDA7802_DB5 0x15 > + > +#define IB0_CH4_TRISTATE_ON (1 << 7) > +#define IB0_CH3_TRISTATE_ON (1 << 6) > +#define IB0_CH2_TRISTATE_ON (1 << 5) > +#define IB0_CH1_TRISTATE_ON (1 << 4) > +#define IB0_CH4_HIGH_EFF(0 << 3) > +#define IB0_CH4_CLASS_AB(1 << 3) > +#define IB0_CH3_HIGH_EFF(0 << 2) > +#define IB0_CH3_CLASS_AB(1 << 2) > +#define IB0_CH2_HIGH_EFF(0 << 0) > +#define IB0_CH2_CLASS_AB(1 << 1) > +#define IB0_CH1_HIGH_EFF(0 << 0) > +#define IB0_CH1_CLASS_AB(1 << 0) > + > +#define IB1_REAR_IMPEDANCE_2_OHM(0 << 7) > +#define IB1_REAR_IMPEDANCE_4_OHM(1 << 7) > +#define IB1_LONG_DIAG_TIMING_x1 (0 << 5) > +#define IB1_LONG_DIAG_TIMING_x2
[PATCH 1/2] ASoC: pcm3060: Add soft reset on probe
Softly reset registers values on module probe Signed-off-by: Kirill Marinushkin --- sound/soc/codecs/pcm3060.c | 8 1 file changed, 8 insertions(+) diff --git a/sound/soc/codecs/pcm3060.c b/sound/soc/codecs/pcm3060.c index 6714aa8d9026..543cb86fd764 100644 --- a/sound/soc/codecs/pcm3060.c +++ b/sound/soc/codecs/pcm3060.c @@ -287,6 +287,14 @@ int pcm3060_probe(struct device *dev) int rc; struct pcm3060_priv *priv = dev_get_drvdata(dev); + /* soft reset */ + rc = regmap_update_bits(priv->regmap, PCM3060_REG64, + PCM3060_REG_MRST, 0); + if (rc) { + dev_err(dev, "failed to reset component, rc=%d\n", rc); + return rc; + } + if (dev->of_node) pcm3060_parse_dt(dev->of_node, priv); -- 2.13.6
[PATCH 2/2] ASoC: pcm3060: Add clock select
ADC and DAC can be clocked from separate or same sources CLK1 and CLK2. By default, ADC is clocked from CLK1, and DAC - from CLK2. This commits allows sound cards to selest a proper clock source during `hw_params()` via `snd_soc_dai_set_sysclk()`. It makes possible to have a single clock source for both ADC and DAC. Signed-off-by: Kirill Marinushkin --- sound/soc/codecs/pcm3060.c | 27 +++ sound/soc/codecs/pcm3060.h | 5 + 2 files changed, 32 insertions(+) diff --git a/sound/soc/codecs/pcm3060.c b/sound/soc/codecs/pcm3060.c index 543cb86fd764..32b26f1c2282 100644 --- a/sound/soc/codecs/pcm3060.c +++ b/sound/soc/codecs/pcm3060.c @@ -18,12 +18,39 @@ static int pcm3060_set_sysclk(struct snd_soc_dai *dai, int clk_id, { struct snd_soc_component *comp = dai->component; struct pcm3060_priv *priv = snd_soc_component_get_drvdata(comp); + unsigned int reg; + unsigned int val; if (dir != SND_SOC_CLOCK_IN) { dev_err(comp->dev, "unsupported sysclock dir: %d\n", dir); return -EINVAL; } + switch (clk_id) { + case PCM3060_CLK_DEF: + val = 0; + break; + + case PCM3060_CLK1: + val = (dai->id == PCM3060_DAI_ID_DAC ? PCM3060_REG_CSEL : 0); + break; + + case PCM3060_CLK2: + val = (dai->id == PCM3060_DAI_ID_DAC ? 0 : PCM3060_REG_CSEL); + break; + + default: + dev_err(comp->dev, "unsupported sysclock id: %d\n", clk_id); + return -EINVAL; + } + + if (dai->id == PCM3060_DAI_ID_DAC) + reg = PCM3060_REG67; + else + reg = PCM3060_REG72; + + regmap_update_bits(priv->regmap, reg, PCM3060_REG_CSEL, val); + priv->dai[dai->id].sclk_freq = freq; return 0; diff --git a/sound/soc/codecs/pcm3060.h b/sound/soc/codecs/pcm3060.h index 6a027b4a845d..75931c9a9d85 100644 --- a/sound/soc/codecs/pcm3060.h +++ b/sound/soc/codecs/pcm3060.h @@ -17,6 +17,11 @@ extern const struct regmap_config pcm3060_regmap; #define PCM3060_DAI_ID_ADC 1 #define PCM3060_DAI_IDS_NUM2 +/* ADC and DAC can be clocked from separate or same sources CLK1 and CLK2 */ +#define PCM3060_CLK_DEF0 /* default: CLK1->ADC, CLK2->DAC */ +#define PCM3060_CLK1 1 +#define PCM3060_CLK2 2 + struct pcm3060_priv_dai { bool is_master; unsigned int sclk_freq; -- 2.13.6
Re: [PATCH] x86/retpoline: Fix forcing me to update my compiler
>> First problem: I cannot compile the kernel with my version of compiler >> Second problem: when I disable the feature - it cannot take effect, >> because the parse-time error happens before `syncconfig` On 12/08/18 13:42, Borislav Petkov wrote: > Does this help? > > https://git.kernel.org/tip/25896d073d8a0403b07e6dec56f58e6c33678207 > The patch which you mentioned fixes the second problem: now I can disable CONFIG_RETPOLINE. But, the first problem is still here: with defconfig and gcc v6.4.0, kernel doesn't build, with this message: $ make scripts/kconfig/conf --syncconfig Kconfig You are building kernel with non-retpoline compiler. Please update your compiler. make: *** [arch/x86/Makefile:311: checkbin] Error 1 I don't think that this is a proper behavior. I suggest to allow compilation Best Regards, Kirill
Re: [PATCH] x86/retpoline: Fix forcing me to update my compiler
>> First problem: I cannot compile the kernel with my version of compiler >> Second problem: when I disable the feature - it cannot take effect, >> because the parse-time error happens before `syncconfig` On 12/08/18 13:42, Borislav Petkov wrote: > Does this help? > > https://git.kernel.org/tip/25896d073d8a0403b07e6dec56f58e6c33678207 > The patch which you mentioned fixes the second problem: now I can disable CONFIG_RETPOLINE. But, the first problem is still here: with defconfig and gcc v6.4.0, kernel doesn't build, with this message: $ make scripts/kconfig/conf --syncconfig Kconfig You are building kernel with non-retpoline compiler. Please update your compiler. make: *** [arch/x86/Makefile:311: checkbin] Error 1 I don't think that this is a proper behavior. I suggest to allow compilation Best Regards, Kirill
[PATCH] x86/retpoline: Fix forcing me to update my compiler
First problem: I cannot compile the kernel with my version of compiler $ make defconfig *** Default configuration is based on 'i386_defconfig' \# \# configuration written to .config \# $ grep CONFIG_RETPOLINE .config CONFIG_RETPOLINE=y $ make arch/x86/Makefile:224: *** You are building kernel with non-retpoline compiler, please update your compiler.. Stop. Second problem: when I disable the feature - it cannot take effect, because the parse-time error happens before `syncconfig` $ scripts/config -d RETPOLINE $ grep CONFIG_RETPOLINE .config \# CONFIG_RETPOLINE is not set $ make arch/x86/Makefile:224: *** You are building kernel with non-retpoline compiler, please update your compiler.. Stop. Fixes: 4cd24de3a098 ("x86/retpoline: Make CONFIG_RETPOLINE depend on compiler support") Signed-off-by: Kirill Marinushkin Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Zhenzhong Duan Cc: H. Peter Anvin Cc: x...@kernel.org Cc: linux-kernel@vger.kernel.org Cc: sta...@vger.kernel.org --- arch/x86/Makefile | 3 --- 1 file changed, 3 deletions(-) diff --git a/arch/x86/Makefile b/arch/x86/Makefile index f5d7f4134524..26a2198c59b3 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -220,9 +220,6 @@ KBUILD_CFLAGS += -fno-asynchronous-unwind-tables # Avoid indirect branches in kernel to deal with Spectre ifdef CONFIG_RETPOLINE -ifeq ($(RETPOLINE_CFLAGS),) - $(error You are building kernel with non-retpoline compiler, please update your compiler.) -endif KBUILD_CFLAGS += $(RETPOLINE_CFLAGS) endif -- 2.13.6
[PATCH] x86/retpoline: Fix forcing me to update my compiler
First problem: I cannot compile the kernel with my version of compiler $ make defconfig *** Default configuration is based on 'i386_defconfig' \# \# configuration written to .config \# $ grep CONFIG_RETPOLINE .config CONFIG_RETPOLINE=y $ make arch/x86/Makefile:224: *** You are building kernel with non-retpoline compiler, please update your compiler.. Stop. Second problem: when I disable the feature - it cannot take effect, because the parse-time error happens before `syncconfig` $ scripts/config -d RETPOLINE $ grep CONFIG_RETPOLINE .config \# CONFIG_RETPOLINE is not set $ make arch/x86/Makefile:224: *** You are building kernel with non-retpoline compiler, please update your compiler.. Stop. Fixes: 4cd24de3a098 ("x86/retpoline: Make CONFIG_RETPOLINE depend on compiler support") Signed-off-by: Kirill Marinushkin Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Zhenzhong Duan Cc: H. Peter Anvin Cc: x...@kernel.org Cc: linux-kernel@vger.kernel.org Cc: sta...@vger.kernel.org --- arch/x86/Makefile | 3 --- 1 file changed, 3 deletions(-) diff --git a/arch/x86/Makefile b/arch/x86/Makefile index f5d7f4134524..26a2198c59b3 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -220,9 +220,6 @@ KBUILD_CFLAGS += -fno-asynchronous-unwind-tables # Avoid indirect branches in kernel to deal with Spectre ifdef CONFIG_RETPOLINE -ifeq ($(RETPOLINE_CFLAGS),) - $(error You are building kernel with non-retpoline compiler, please update your compiler.) -endif KBUILD_CFLAGS += $(RETPOLINE_CFLAGS) endif -- 2.13.6
[PATCH] ASoC: pcm3060: Add powersaving widgets for DAC and ADC
Enable DAC/ADC only when playing/capturing Signed-off-by: Kirill Marinushkin --- sound/soc/codecs/pcm3060.c | 14 ++ sound/soc/codecs/pcm3060.h | 2 ++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/sound/soc/codecs/pcm3060.c b/sound/soc/codecs/pcm3060.c index 1dd851a7b43b..6714aa8d9026 100644 --- a/sound/soc/codecs/pcm3060.c +++ b/sound/soc/codecs/pcm3060.c @@ -198,19 +198,25 @@ static const struct snd_kcontrol_new pcm3060_dapm_controls[] = { }; static const struct snd_soc_dapm_widget pcm3060_dapm_widgets[] = { + SND_SOC_DAPM_DAC("DAC", "Playback", PCM3060_REG64, +PCM3060_REG_SHIFT_DAPSV, 1), + SND_SOC_DAPM_OUTPUT("OUTL"), SND_SOC_DAPM_OUTPUT("OUTR"), SND_SOC_DAPM_INPUT("INL"), SND_SOC_DAPM_INPUT("INR"), + + SND_SOC_DAPM_ADC("ADC", "Capture", PCM3060_REG64, +PCM3060_REG_SHIFT_ADPSV, 1), }; static const struct snd_soc_dapm_route pcm3060_dapm_map[] = { - { "OUTL", NULL, "Playback" }, - { "OUTR", NULL, "Playback" }, + { "OUTL", NULL, "DAC" }, + { "OUTR", NULL, "DAC" }, - { "Capture", NULL, "INL" }, - { "Capture", NULL, "INR" }, + { "ADC", NULL, "INL" }, + { "ADC", NULL, "INR" }, }; /* soc component */ diff --git a/sound/soc/codecs/pcm3060.h b/sound/soc/codecs/pcm3060.h index c895cf40ee10..6a027b4a845d 100644 --- a/sound/soc/codecs/pcm3060.h +++ b/sound/soc/codecs/pcm3060.h @@ -37,7 +37,9 @@ int pcm3060_remove(struct device *dev); #define PCM3060_REG_MRST 0x80 #define PCM3060_REG_SRST 0x40 #define PCM3060_REG_ADPSV 0x20 +#define PCM3060_REG_SHIFT_ADPSV0x05 #define PCM3060_REG_DAPSV 0x10 +#define PCM3060_REG_SHIFT_DAPSV0x04 #define PCM3060_REG_SE 0x01 #define PCM3060_REG65 0x41 -- 2.13.6
[PATCH] ASoC: pcm3060: Add powersaving widgets for DAC and ADC
Enable DAC/ADC only when playing/capturing Signed-off-by: Kirill Marinushkin --- sound/soc/codecs/pcm3060.c | 14 ++ sound/soc/codecs/pcm3060.h | 2 ++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/sound/soc/codecs/pcm3060.c b/sound/soc/codecs/pcm3060.c index 1dd851a7b43b..6714aa8d9026 100644 --- a/sound/soc/codecs/pcm3060.c +++ b/sound/soc/codecs/pcm3060.c @@ -198,19 +198,25 @@ static const struct snd_kcontrol_new pcm3060_dapm_controls[] = { }; static const struct snd_soc_dapm_widget pcm3060_dapm_widgets[] = { + SND_SOC_DAPM_DAC("DAC", "Playback", PCM3060_REG64, +PCM3060_REG_SHIFT_DAPSV, 1), + SND_SOC_DAPM_OUTPUT("OUTL"), SND_SOC_DAPM_OUTPUT("OUTR"), SND_SOC_DAPM_INPUT("INL"), SND_SOC_DAPM_INPUT("INR"), + + SND_SOC_DAPM_ADC("ADC", "Capture", PCM3060_REG64, +PCM3060_REG_SHIFT_ADPSV, 1), }; static const struct snd_soc_dapm_route pcm3060_dapm_map[] = { - { "OUTL", NULL, "Playback" }, - { "OUTR", NULL, "Playback" }, + { "OUTL", NULL, "DAC" }, + { "OUTR", NULL, "DAC" }, - { "Capture", NULL, "INL" }, - { "Capture", NULL, "INR" }, + { "ADC", NULL, "INL" }, + { "ADC", NULL, "INR" }, }; /* soc component */ diff --git a/sound/soc/codecs/pcm3060.h b/sound/soc/codecs/pcm3060.h index c895cf40ee10..6a027b4a845d 100644 --- a/sound/soc/codecs/pcm3060.h +++ b/sound/soc/codecs/pcm3060.h @@ -37,7 +37,9 @@ int pcm3060_remove(struct device *dev); #define PCM3060_REG_MRST 0x80 #define PCM3060_REG_SRST 0x40 #define PCM3060_REG_ADPSV 0x20 +#define PCM3060_REG_SHIFT_ADPSV0x05 #define PCM3060_REG_DAPSV 0x10 +#define PCM3060_REG_SHIFT_DAPSV0x04 #define PCM3060_REG_SE 0x01 #define PCM3060_REG65 0x41 -- 2.13.6
Re: [resend PATCH] dt-bindings: sound: Add documentation for pcm3060 property out-single-ended
Thank you Rob, Mark already applied this patch, with a slightly modified subject: https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git/commit/?h=for-next=fd7de6370cb62b147185834d60069568a21acacd Best Regards, Kirill On 12/04/18 22:43, Rob Herring wrote: > On Thu, 15 Nov 2018 08:12:53 +0100, Kirill Marinushkin wrote: >> Output of pcm3060 codec may be configured as single-ended or differential >> >> Signed-off-by: Kirill Marinushkin >> Cc: devicet...@vger.kernel.org >> --- >> Hello Mark, >> >> yesterday there was a misunderstanding: when I wrote you >> >>> I think you forgot one patch in the series >> >> you accidently applied the already-applied patch instead of the forgotten >> one. To avoid the confusion, in this e-mail I resend you the proper >> forgotten patch in a separate mailing thread. >> >> Please apply this patch for-next. >> >> Best Regards, >> Kirill >> --- >> Documentation/devicetree/bindings/sound/pcm3060.txt | 6 ++ >> 1 file changed, 6 insertions(+) >> > > Reviewed-by: Rob Herring >
Re: [resend PATCH] dt-bindings: sound: Add documentation for pcm3060 property out-single-ended
Thank you Rob, Mark already applied this patch, with a slightly modified subject: https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git/commit/?h=for-next=fd7de6370cb62b147185834d60069568a21acacd Best Regards, Kirill On 12/04/18 22:43, Rob Herring wrote: > On Thu, 15 Nov 2018 08:12:53 +0100, Kirill Marinushkin wrote: >> Output of pcm3060 codec may be configured as single-ended or differential >> >> Signed-off-by: Kirill Marinushkin >> Cc: devicet...@vger.kernel.org >> --- >> Hello Mark, >> >> yesterday there was a misunderstanding: when I wrote you >> >>> I think you forgot one patch in the series >> >> you accidently applied the already-applied patch instead of the forgotten >> one. To avoid the confusion, in this e-mail I resend you the proper >> forgotten patch in a separate mailing thread. >> >> Please apply this patch for-next. >> >> Best Regards, >> Kirill >> --- >> Documentation/devicetree/bindings/sound/pcm3060.txt | 6 ++ >> 1 file changed, 6 insertions(+) >> > > Reviewed-by: Rob Herring >
[resend PATCH] dt-bindings: sound: Add documentation for pcm3060 property out-single-ended
Output of pcm3060 codec may be configured as single-ended or differential Signed-off-by: Kirill Marinushkin Cc: devicet...@vger.kernel.org --- Hello Mark, yesterday there was a misunderstanding: when I wrote you > I think you forgot one patch in the series you accidently applied the already-applied patch instead of the forgotten one. To avoid the confusion, in this e-mail I resend you the proper forgotten patch in a separate mailing thread. Please apply this patch for-next. Best Regards, Kirill --- Documentation/devicetree/bindings/sound/pcm3060.txt | 6 ++ 1 file changed, 6 insertions(+) diff --git a/Documentation/devicetree/bindings/sound/pcm3060.txt b/Documentation/devicetree/bindings/sound/pcm3060.txt index 90fcb8523099..97de66932d44 100644 --- a/Documentation/devicetree/bindings/sound/pcm3060.txt +++ b/Documentation/devicetree/bindings/sound/pcm3060.txt @@ -9,9 +9,15 @@ Required properties: - reg : the I2C address of the device for I2C, the chip select number for SPI. +Optional properties: + +- ti,out-single-ended: "true" if output is single-ended; + "false" or not specified if output is differential. + Examples: pcm3060: pcm3060@46 { compatible = "ti,pcm3060"; reg = <0x46>; +ti,out-single-ended = "true"; }; -- 2.13.6
[resend PATCH] dt-bindings: sound: Add documentation for pcm3060 property out-single-ended
Output of pcm3060 codec may be configured as single-ended or differential Signed-off-by: Kirill Marinushkin Cc: devicet...@vger.kernel.org --- Hello Mark, yesterday there was a misunderstanding: when I wrote you > I think you forgot one patch in the series you accidently applied the already-applied patch instead of the forgotten one. To avoid the confusion, in this e-mail I resend you the proper forgotten patch in a separate mailing thread. Please apply this patch for-next. Best Regards, Kirill --- Documentation/devicetree/bindings/sound/pcm3060.txt | 6 ++ 1 file changed, 6 insertions(+) diff --git a/Documentation/devicetree/bindings/sound/pcm3060.txt b/Documentation/devicetree/bindings/sound/pcm3060.txt index 90fcb8523099..97de66932d44 100644 --- a/Documentation/devicetree/bindings/sound/pcm3060.txt +++ b/Documentation/devicetree/bindings/sound/pcm3060.txt @@ -9,9 +9,15 @@ Required properties: - reg : the I2C address of the device for I2C, the chip select number for SPI. +Optional properties: + +- ti,out-single-ended: "true" if output is single-ended; + "false" or not specified if output is differential. + Examples: pcm3060: pcm3060@46 { compatible = "ti,pcm3060"; reg = <0x46>; +ti,out-single-ended = "true"; }; -- 2.13.6
Re: Applied "ASoC: pcm3060: Add DT property for single-ended output" to the asoc tree
Hello Mark, Thank you for applying this patch series. I think you forgot one patch in the series: patch [1] is a documentation for patch [2]. It has a different naming scheme, because that's how the document [3] recommends. That's why it was not obvious that they relate to each other. Document [3] also says: > The Documentation/ portion of the patch should come in the series before > the code implementing the binding. Therefore, could you to apply patch [1] to the same branch as [2]? Best Regards, Kirill [1] [PATCH v2 1/3] dt-bindings: sound: Add documentation for pcm3060 property out-single-ended [2] [PATCH v2 2/3] ASoC: pcm3060: Add DT property for single-ended output [3] Documentation/devicetree/bindings/submitting-patches.txt On 11/14/18 01:37, Mark Brown wrote: > The patch > >ASoC: pcm3060: Add DT property for single-ended output > > has been applied to the asoc tree at > >https://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 b1cbde8fb287f4fd3493ca4167efee344c3e Mon Sep 17 00:00:00 2001 > From: Kirill Marinushkin > Date: Mon, 12 Nov 2018 08:08:33 +0100 > Subject: [PATCH] ASoC: pcm3060: Add DT property for single-ended output > > DAC output may be differential (default) or single-ended. > > Signed-off-by: Kirill Marinushkin > Signed-off-by: Mark Brown > --- > sound/soc/codecs/pcm3060.c | 14 ++ > sound/soc/codecs/pcm3060.h | 1 + > 2 files changed, 15 insertions(+) > > diff --git a/sound/soc/codecs/pcm3060.c b/sound/soc/codecs/pcm3060.c > index 771b46e1974b..1dd851a7b43b 100644 > --- a/sound/soc/codecs/pcm3060.c > +++ b/sound/soc/codecs/pcm3060.c > @@ -270,9 +270,23 @@ EXPORT_SYMBOL(pcm3060_regmap); > > /* device */ > > +static void pcm3060_parse_dt(const struct device_node *np, > + struct pcm3060_priv *priv) > +{ > + priv->out_se = of_property_read_bool(np, "ti,out-single-ended"); > +} > + > int pcm3060_probe(struct device *dev) > { > int rc; > + struct pcm3060_priv *priv = dev_get_drvdata(dev); > + > + if (dev->of_node) > + pcm3060_parse_dt(dev->of_node, priv); > + > + if (priv->out_se) > + regmap_update_bits(priv->regmap, PCM3060_REG64, > +PCM3060_REG_SE, PCM3060_REG_SE); > > rc = devm_snd_soc_register_component(dev, _soc_comp_driver, >pcm3060_dai, > diff --git a/sound/soc/codecs/pcm3060.h b/sound/soc/codecs/pcm3060.h > index fd89a68aa8a7..c895cf40ee10 100644 > --- a/sound/soc/codecs/pcm3060.h > +++ b/sound/soc/codecs/pcm3060.h > @@ -25,6 +25,7 @@ struct pcm3060_priv_dai { > struct pcm3060_priv { > struct regmap *regmap; > struct pcm3060_priv_dai dai[PCM3060_DAI_IDS_NUM]; > + u8 out_se: 1; > }; > > int pcm3060_probe(struct device *dev); >
Re: Applied "ASoC: pcm3060: Add DT property for single-ended output" to the asoc tree
Hello Mark, Thank you for applying this patch series. I think you forgot one patch in the series: patch [1] is a documentation for patch [2]. It has a different naming scheme, because that's how the document [3] recommends. That's why it was not obvious that they relate to each other. Document [3] also says: > The Documentation/ portion of the patch should come in the series before > the code implementing the binding. Therefore, could you to apply patch [1] to the same branch as [2]? Best Regards, Kirill [1] [PATCH v2 1/3] dt-bindings: sound: Add documentation for pcm3060 property out-single-ended [2] [PATCH v2 2/3] ASoC: pcm3060: Add DT property for single-ended output [3] Documentation/devicetree/bindings/submitting-patches.txt On 11/14/18 01:37, Mark Brown wrote: > The patch > >ASoC: pcm3060: Add DT property for single-ended output > > has been applied to the asoc tree at > >https://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 b1cbde8fb287f4fd3493ca4167efee344c3e Mon Sep 17 00:00:00 2001 > From: Kirill Marinushkin > Date: Mon, 12 Nov 2018 08:08:33 +0100 > Subject: [PATCH] ASoC: pcm3060: Add DT property for single-ended output > > DAC output may be differential (default) or single-ended. > > Signed-off-by: Kirill Marinushkin > Signed-off-by: Mark Brown > --- > sound/soc/codecs/pcm3060.c | 14 ++ > sound/soc/codecs/pcm3060.h | 1 + > 2 files changed, 15 insertions(+) > > diff --git a/sound/soc/codecs/pcm3060.c b/sound/soc/codecs/pcm3060.c > index 771b46e1974b..1dd851a7b43b 100644 > --- a/sound/soc/codecs/pcm3060.c > +++ b/sound/soc/codecs/pcm3060.c > @@ -270,9 +270,23 @@ EXPORT_SYMBOL(pcm3060_regmap); > > /* device */ > > +static void pcm3060_parse_dt(const struct device_node *np, > + struct pcm3060_priv *priv) > +{ > + priv->out_se = of_property_read_bool(np, "ti,out-single-ended"); > +} > + > int pcm3060_probe(struct device *dev) > { > int rc; > + struct pcm3060_priv *priv = dev_get_drvdata(dev); > + > + if (dev->of_node) > + pcm3060_parse_dt(dev->of_node, priv); > + > + if (priv->out_se) > + regmap_update_bits(priv->regmap, PCM3060_REG64, > +PCM3060_REG_SE, PCM3060_REG_SE); > > rc = devm_snd_soc_register_component(dev, _soc_comp_driver, >pcm3060_dai, > diff --git a/sound/soc/codecs/pcm3060.h b/sound/soc/codecs/pcm3060.h > index fd89a68aa8a7..c895cf40ee10 100644 > --- a/sound/soc/codecs/pcm3060.h > +++ b/sound/soc/codecs/pcm3060.h > @@ -25,6 +25,7 @@ struct pcm3060_priv_dai { > struct pcm3060_priv { > struct regmap *regmap; > struct pcm3060_priv_dai dai[PCM3060_DAI_IDS_NUM]; > + u8 out_se: 1; > }; > > int pcm3060_probe(struct device *dev); >
[PATCH v2 3/3] ASoC: pcm3060: Rename output widgets
In the initial commit [1], I added differential output of the codec as separate `+` and `-` widgets: OUTL+ OUTR+ OUTL- OUTR- Later, in the commit [2], I added a device tree property to configure the output as single-ended or differential. Having this property, the `+` and `-` separation in widgets seems for me confusing. There are no functional benefits in such separation, so I find reasonable to get rid of it: OUTL OUTR The new naming is more friendly for sound cards, and is better aligned with other codec drivers in kernel. Renaming the output widgets now should not be a problem from the backwards- compatibility perspective, as the driver for PCM3060 is added into the mainline very recently, and did not yet appear in any releases. [1] commit 6ee47d4a8dac ("ASoC: pcm3060: Add codec driver") [2] commit a78c62de00d5 ("ASoC: pcm3060: Add DT property for single-ended output") Signed-off-by: Kirill Marinushkin --- sound/soc/codecs/pcm3060.c | 12 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/sound/soc/codecs/pcm3060.c b/sound/soc/codecs/pcm3060.c index 5f479aa61097..1dd851a7b43b 100644 --- a/sound/soc/codecs/pcm3060.c +++ b/sound/soc/codecs/pcm3060.c @@ -198,20 +198,16 @@ static const struct snd_kcontrol_new pcm3060_dapm_controls[] = { }; static const struct snd_soc_dapm_widget pcm3060_dapm_widgets[] = { - SND_SOC_DAPM_OUTPUT("OUTL+"), - SND_SOC_DAPM_OUTPUT("OUTR+"), - SND_SOC_DAPM_OUTPUT("OUTL-"), - SND_SOC_DAPM_OUTPUT("OUTR-"), + SND_SOC_DAPM_OUTPUT("OUTL"), + SND_SOC_DAPM_OUTPUT("OUTR"), SND_SOC_DAPM_INPUT("INL"), SND_SOC_DAPM_INPUT("INR"), }; static const struct snd_soc_dapm_route pcm3060_dapm_map[] = { - { "OUTL+", NULL, "Playback" }, - { "OUTR+", NULL, "Playback" }, - { "OUTL-", NULL, "Playback" }, - { "OUTR-", NULL, "Playback" }, + { "OUTL", NULL, "Playback" }, + { "OUTR", NULL, "Playback" }, { "Capture", NULL, "INL" }, { "Capture", NULL, "INR" }, -- 2.13.6
[PATCH v2 3/3] ASoC: pcm3060: Rename output widgets
In the initial commit [1], I added differential output of the codec as separate `+` and `-` widgets: OUTL+ OUTR+ OUTL- OUTR- Later, in the commit [2], I added a device tree property to configure the output as single-ended or differential. Having this property, the `+` and `-` separation in widgets seems for me confusing. There are no functional benefits in such separation, so I find reasonable to get rid of it: OUTL OUTR The new naming is more friendly for sound cards, and is better aligned with other codec drivers in kernel. Renaming the output widgets now should not be a problem from the backwards- compatibility perspective, as the driver for PCM3060 is added into the mainline very recently, and did not yet appear in any releases. [1] commit 6ee47d4a8dac ("ASoC: pcm3060: Add codec driver") [2] commit a78c62de00d5 ("ASoC: pcm3060: Add DT property for single-ended output") Signed-off-by: Kirill Marinushkin --- sound/soc/codecs/pcm3060.c | 12 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/sound/soc/codecs/pcm3060.c b/sound/soc/codecs/pcm3060.c index 5f479aa61097..1dd851a7b43b 100644 --- a/sound/soc/codecs/pcm3060.c +++ b/sound/soc/codecs/pcm3060.c @@ -198,20 +198,16 @@ static const struct snd_kcontrol_new pcm3060_dapm_controls[] = { }; static const struct snd_soc_dapm_widget pcm3060_dapm_widgets[] = { - SND_SOC_DAPM_OUTPUT("OUTL+"), - SND_SOC_DAPM_OUTPUT("OUTR+"), - SND_SOC_DAPM_OUTPUT("OUTL-"), - SND_SOC_DAPM_OUTPUT("OUTR-"), + SND_SOC_DAPM_OUTPUT("OUTL"), + SND_SOC_DAPM_OUTPUT("OUTR"), SND_SOC_DAPM_INPUT("INL"), SND_SOC_DAPM_INPUT("INR"), }; static const struct snd_soc_dapm_route pcm3060_dapm_map[] = { - { "OUTL+", NULL, "Playback" }, - { "OUTR+", NULL, "Playback" }, - { "OUTL-", NULL, "Playback" }, - { "OUTR-", NULL, "Playback" }, + { "OUTL", NULL, "Playback" }, + { "OUTR", NULL, "Playback" }, { "Capture", NULL, "INL" }, { "Capture", NULL, "INR" }, -- 2.13.6
[PATCH v2 1/3] dt-bindings: sound: Add documentation for pcm3060 property out-single-ended
Output of pcm3060 codec may be configured as single-ended or differential Signed-off-by: Kirill Marinushkin Cc: devicet...@vger.kernel.org --- Documentation/devicetree/bindings/sound/pcm3060.txt | 6 ++ 1 file changed, 6 insertions(+) diff --git a/Documentation/devicetree/bindings/sound/pcm3060.txt b/Documentation/devicetree/bindings/sound/pcm3060.txt index 90fcb8523099..97de66932d44 100644 --- a/Documentation/devicetree/bindings/sound/pcm3060.txt +++ b/Documentation/devicetree/bindings/sound/pcm3060.txt @@ -9,9 +9,15 @@ Required properties: - reg : the I2C address of the device for I2C, the chip select number for SPI. +Optional properties: + +- ti,out-single-ended: "true" if output is single-ended; + "false" or not specified if output is differential. + Examples: pcm3060: pcm3060@46 { compatible = "ti,pcm3060"; reg = <0x46>; +ti,out-single-ended = "true"; }; -- 2.13.6
[PATCH v2 2/3] ASoC: pcm3060: Add DT property for single-ended output
DAC output may be differential (default) or single-ended. Signed-off-by: Kirill Marinushkin --- sound/soc/codecs/pcm3060.c | 14 ++ sound/soc/codecs/pcm3060.h | 1 + 2 files changed, 15 insertions(+) diff --git a/sound/soc/codecs/pcm3060.c b/sound/soc/codecs/pcm3060.c index 494d9d662be8..5f479aa61097 100644 --- a/sound/soc/codecs/pcm3060.c +++ b/sound/soc/codecs/pcm3060.c @@ -274,9 +274,23 @@ EXPORT_SYMBOL(pcm3060_regmap); /* device */ +static void pcm3060_parse_dt(const struct device_node *np, +struct pcm3060_priv *priv) +{ + priv->out_se = of_property_read_bool(np, "ti,out-single-ended"); +} + int pcm3060_probe(struct device *dev) { int rc; + struct pcm3060_priv *priv = dev_get_drvdata(dev); + + if (dev->of_node) + pcm3060_parse_dt(dev->of_node, priv); + + if (priv->out_se) + regmap_update_bits(priv->regmap, PCM3060_REG64, + PCM3060_REG_SE, PCM3060_REG_SE); rc = devm_snd_soc_register_component(dev, _soc_comp_driver, pcm3060_dai, diff --git a/sound/soc/codecs/pcm3060.h b/sound/soc/codecs/pcm3060.h index fd89a68aa8a7..c895cf40ee10 100644 --- a/sound/soc/codecs/pcm3060.h +++ b/sound/soc/codecs/pcm3060.h @@ -25,6 +25,7 @@ struct pcm3060_priv_dai { struct pcm3060_priv { struct regmap *regmap; struct pcm3060_priv_dai dai[PCM3060_DAI_IDS_NUM]; + u8 out_se: 1; }; int pcm3060_probe(struct device *dev); -- 2.13.6
[PATCH v2 1/3] dt-bindings: sound: Add documentation for pcm3060 property out-single-ended
Output of pcm3060 codec may be configured as single-ended or differential Signed-off-by: Kirill Marinushkin Cc: devicet...@vger.kernel.org --- Documentation/devicetree/bindings/sound/pcm3060.txt | 6 ++ 1 file changed, 6 insertions(+) diff --git a/Documentation/devicetree/bindings/sound/pcm3060.txt b/Documentation/devicetree/bindings/sound/pcm3060.txt index 90fcb8523099..97de66932d44 100644 --- a/Documentation/devicetree/bindings/sound/pcm3060.txt +++ b/Documentation/devicetree/bindings/sound/pcm3060.txt @@ -9,9 +9,15 @@ Required properties: - reg : the I2C address of the device for I2C, the chip select number for SPI. +Optional properties: + +- ti,out-single-ended: "true" if output is single-ended; + "false" or not specified if output is differential. + Examples: pcm3060: pcm3060@46 { compatible = "ti,pcm3060"; reg = <0x46>; +ti,out-single-ended = "true"; }; -- 2.13.6
[PATCH v2 2/3] ASoC: pcm3060: Add DT property for single-ended output
DAC output may be differential (default) or single-ended. Signed-off-by: Kirill Marinushkin --- sound/soc/codecs/pcm3060.c | 14 ++ sound/soc/codecs/pcm3060.h | 1 + 2 files changed, 15 insertions(+) diff --git a/sound/soc/codecs/pcm3060.c b/sound/soc/codecs/pcm3060.c index 494d9d662be8..5f479aa61097 100644 --- a/sound/soc/codecs/pcm3060.c +++ b/sound/soc/codecs/pcm3060.c @@ -274,9 +274,23 @@ EXPORT_SYMBOL(pcm3060_regmap); /* device */ +static void pcm3060_parse_dt(const struct device_node *np, +struct pcm3060_priv *priv) +{ + priv->out_se = of_property_read_bool(np, "ti,out-single-ended"); +} + int pcm3060_probe(struct device *dev) { int rc; + struct pcm3060_priv *priv = dev_get_drvdata(dev); + + if (dev->of_node) + pcm3060_parse_dt(dev->of_node, priv); + + if (priv->out_se) + regmap_update_bits(priv->regmap, PCM3060_REG64, + PCM3060_REG_SE, PCM3060_REG_SE); rc = devm_snd_soc_register_component(dev, _soc_comp_driver, pcm3060_dai, diff --git a/sound/soc/codecs/pcm3060.h b/sound/soc/codecs/pcm3060.h index fd89a68aa8a7..c895cf40ee10 100644 --- a/sound/soc/codecs/pcm3060.h +++ b/sound/soc/codecs/pcm3060.h @@ -25,6 +25,7 @@ struct pcm3060_priv_dai { struct pcm3060_priv { struct regmap *regmap; struct pcm3060_priv_dai dai[PCM3060_DAI_IDS_NUM]; + u8 out_se: 1; }; int pcm3060_probe(struct device *dev); -- 2.13.6
Re: [PATCH 1/2] ASoC: pcm3060: Add control for differential output
Hello Mark, On 11/05/18 12:20, Mark Brown wrote: > On Mon, Oct 29, 2018 at 09:59:12AM +0100, Kirill Marinushkin wrote: >> DAC may be switched between differential and single-ended output. > > Isn't this something that'd be better controlled by DT - it's usually > going to be part of the board design? > I agree with that. I implemented it as a switch, just because that's how other codec drivers do. In such situations, I prefer to be aligned with already existing code. Indeed, it's more logical to implement such setup via DT. I will rewrite and send it as patch v2. Best Regards, Kirill
Re: [PATCH 1/2] ASoC: pcm3060: Add control for differential output
Hello Mark, On 11/05/18 12:20, Mark Brown wrote: > On Mon, Oct 29, 2018 at 09:59:12AM +0100, Kirill Marinushkin wrote: >> DAC may be switched between differential and single-ended output. > > Isn't this something that'd be better controlled by DT - it's usually > going to be part of the board design? > I agree with that. I implemented it as a switch, just because that's how other codec drivers do. In such situations, I prefer to be aligned with already existing code. Indeed, it's more logical to implement such setup via DT. I will rewrite and send it as patch v2. Best Regards, Kirill
[PATCH 2/2] ASoC: pcm3060: Rename output widgets
In the initial commit [1], I added differential outputs of the codec as separate `+` and `-` widgets: OUTL+ OUTR+ OUTL- OUTR- Later, in the commit [2], I added a control to switch the outputs between differential and single-ended modes. Having this control, the `+` and `-` separation in widgets seems for me confusing. There are no functional benefits in such separation, so I find reasonable to get rid of it: OUTL OUTR The new naming is more friendly for sound cards, and is better aligned with other codec drivers in kernel. Renaming outputs now should not be a problem from the backwards- compatibility perspective, as the driver for PCM3060 is added into the mainline very recently, and did not yet appear in any releases. [1] commit 6ee47d4a8dac ("ASoC: pcm3060: Add codec driver") [2] commit c33260d09337 ("ASoC: pcm3060: Add control for differential output") Signed-off-by: Kirill Marinushkin --- sound/soc/codecs/pcm3060.c | 12 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/sound/soc/codecs/pcm3060.c b/sound/soc/codecs/pcm3060.c index f792ad637ae4..078a3b1fc064 100644 --- a/sound/soc/codecs/pcm3060.c +++ b/sound/soc/codecs/pcm3060.c @@ -207,20 +207,16 @@ static const struct snd_kcontrol_new pcm3060_dapm_controls[] = { }; static const struct snd_soc_dapm_widget pcm3060_dapm_widgets[] = { - SND_SOC_DAPM_OUTPUT("OUTL+"), - SND_SOC_DAPM_OUTPUT("OUTR+"), - SND_SOC_DAPM_OUTPUT("OUTL-"), - SND_SOC_DAPM_OUTPUT("OUTR-"), + SND_SOC_DAPM_OUTPUT("OUTL"), + SND_SOC_DAPM_OUTPUT("OUTR"), SND_SOC_DAPM_INPUT("INL"), SND_SOC_DAPM_INPUT("INR"), }; static const struct snd_soc_dapm_route pcm3060_dapm_map[] = { - { "OUTL+", NULL, "Playback" }, - { "OUTR+", NULL, "Playback" }, - { "OUTL-", NULL, "Playback" }, - { "OUTR-", NULL, "Playback" }, + { "OUTL", NULL, "Playback" }, + { "OUTR", NULL, "Playback" }, { "Capture", NULL, "INL" }, { "Capture", NULL, "INR" }, -- 2.13.6
[PATCH 2/2] ASoC: pcm3060: Rename output widgets
In the initial commit [1], I added differential outputs of the codec as separate `+` and `-` widgets: OUTL+ OUTR+ OUTL- OUTR- Later, in the commit [2], I added a control to switch the outputs between differential and single-ended modes. Having this control, the `+` and `-` separation in widgets seems for me confusing. There are no functional benefits in such separation, so I find reasonable to get rid of it: OUTL OUTR The new naming is more friendly for sound cards, and is better aligned with other codec drivers in kernel. Renaming outputs now should not be a problem from the backwards- compatibility perspective, as the driver for PCM3060 is added into the mainline very recently, and did not yet appear in any releases. [1] commit 6ee47d4a8dac ("ASoC: pcm3060: Add codec driver") [2] commit c33260d09337 ("ASoC: pcm3060: Add control for differential output") Signed-off-by: Kirill Marinushkin --- sound/soc/codecs/pcm3060.c | 12 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/sound/soc/codecs/pcm3060.c b/sound/soc/codecs/pcm3060.c index f792ad637ae4..078a3b1fc064 100644 --- a/sound/soc/codecs/pcm3060.c +++ b/sound/soc/codecs/pcm3060.c @@ -207,20 +207,16 @@ static const struct snd_kcontrol_new pcm3060_dapm_controls[] = { }; static const struct snd_soc_dapm_widget pcm3060_dapm_widgets[] = { - SND_SOC_DAPM_OUTPUT("OUTL+"), - SND_SOC_DAPM_OUTPUT("OUTR+"), - SND_SOC_DAPM_OUTPUT("OUTL-"), - SND_SOC_DAPM_OUTPUT("OUTR-"), + SND_SOC_DAPM_OUTPUT("OUTL"), + SND_SOC_DAPM_OUTPUT("OUTR"), SND_SOC_DAPM_INPUT("INL"), SND_SOC_DAPM_INPUT("INR"), }; static const struct snd_soc_dapm_route pcm3060_dapm_map[] = { - { "OUTL+", NULL, "Playback" }, - { "OUTR+", NULL, "Playback" }, - { "OUTL-", NULL, "Playback" }, - { "OUTR-", NULL, "Playback" }, + { "OUTL", NULL, "Playback" }, + { "OUTR", NULL, "Playback" }, { "Capture", NULL, "INL" }, { "Capture", NULL, "INR" }, -- 2.13.6
[PATCH 1/2] ASoC: pcm3060: Add control for differential output
DAC may be switched between differential and single-ended output. Signed-off-by: Kirill Marinushkin --- sound/soc/codecs/pcm3060.c | 9 + sound/soc/codecs/pcm3060.h | 1 + 2 files changed, 10 insertions(+) diff --git a/sound/soc/codecs/pcm3060.c b/sound/soc/codecs/pcm3060.c index 494d9d662be8..f792ad637ae4 100644 --- a/sound/soc/codecs/pcm3060.c +++ b/sound/soc/codecs/pcm3060.c @@ -179,6 +179,13 @@ static struct snd_soc_dai_driver pcm3060_dai[] = { /* dapm */ +static const char * const pcm3060_dapm_out_dif_txt[] = { + "Differential", "Single-Ended" +}; + +static SOC_ENUM_SINGLE_DECL(pcm3060_dapm_out_dif_enum, PCM3060_REG64, + PCM3060_REG_SHIFT_SE, pcm3060_dapm_out_dif_txt); + static DECLARE_TLV_DB_SCALE(pcm3060_dapm_tlv, -10050, 50, 1); static const struct snd_kcontrol_new pcm3060_dapm_controls[] = { @@ -195,6 +202,8 @@ static const struct snd_kcontrol_new pcm3060_dapm_controls[] = { 0, pcm3060_dapm_tlv), SOC_DOUBLE("Master Capture Switch", PCM3060_REG73, PCM3060_REG_SHIFT_MUT11, PCM3060_REG_SHIFT_MUT12, 1, 1), + + SOC_ENUM("DAC Out Differential", pcm3060_dapm_out_dif_enum), }; static const struct snd_soc_dapm_widget pcm3060_dapm_widgets[] = { diff --git a/sound/soc/codecs/pcm3060.h b/sound/soc/codecs/pcm3060.h index fd89a68aa8a7..32080ff00166 100644 --- a/sound/soc/codecs/pcm3060.h +++ b/sound/soc/codecs/pcm3060.h @@ -38,6 +38,7 @@ int pcm3060_remove(struct device *dev); #define PCM3060_REG_ADPSV 0x20 #define PCM3060_REG_DAPSV 0x10 #define PCM3060_REG_SE 0x01 +#define PCM3060_REG_SHIFT_SE 0x00 #define PCM3060_REG65 0x41 #define PCM3060_REG66 0x42 -- 2.13.6
[PATCH 1/2] ASoC: pcm3060: Add control for differential output
DAC may be switched between differential and single-ended output. Signed-off-by: Kirill Marinushkin --- sound/soc/codecs/pcm3060.c | 9 + sound/soc/codecs/pcm3060.h | 1 + 2 files changed, 10 insertions(+) diff --git a/sound/soc/codecs/pcm3060.c b/sound/soc/codecs/pcm3060.c index 494d9d662be8..f792ad637ae4 100644 --- a/sound/soc/codecs/pcm3060.c +++ b/sound/soc/codecs/pcm3060.c @@ -179,6 +179,13 @@ static struct snd_soc_dai_driver pcm3060_dai[] = { /* dapm */ +static const char * const pcm3060_dapm_out_dif_txt[] = { + "Differential", "Single-Ended" +}; + +static SOC_ENUM_SINGLE_DECL(pcm3060_dapm_out_dif_enum, PCM3060_REG64, + PCM3060_REG_SHIFT_SE, pcm3060_dapm_out_dif_txt); + static DECLARE_TLV_DB_SCALE(pcm3060_dapm_tlv, -10050, 50, 1); static const struct snd_kcontrol_new pcm3060_dapm_controls[] = { @@ -195,6 +202,8 @@ static const struct snd_kcontrol_new pcm3060_dapm_controls[] = { 0, pcm3060_dapm_tlv), SOC_DOUBLE("Master Capture Switch", PCM3060_REG73, PCM3060_REG_SHIFT_MUT11, PCM3060_REG_SHIFT_MUT12, 1, 1), + + SOC_ENUM("DAC Out Differential", pcm3060_dapm_out_dif_enum), }; static const struct snd_soc_dapm_widget pcm3060_dapm_widgets[] = { diff --git a/sound/soc/codecs/pcm3060.h b/sound/soc/codecs/pcm3060.h index fd89a68aa8a7..32080ff00166 100644 --- a/sound/soc/codecs/pcm3060.h +++ b/sound/soc/codecs/pcm3060.h @@ -38,6 +38,7 @@ int pcm3060_remove(struct device *dev); #define PCM3060_REG_ADPSV 0x20 #define PCM3060_REG_DAPSV 0x10 #define PCM3060_REG_SE 0x01 +#define PCM3060_REG_SHIFT_SE 0x00 #define PCM3060_REG65 0x41 #define PCM3060_REG66 0x42 -- 2.13.6
Re: [alsa-devel] [PATCH v2] staging: bcm2835-audio: interpolate audio delay
Hello Takashi, Mike, @Takashi On 10/25/18 09:37, Takashi Iwai wrote: > Well, in the API POV, it's nothing wrong to keep hwptr sticking while > updating only delay value. It implies that the hardware chip doesn't > provide the hwptr update. Thank you for the clarification. Modifying `runtime->delay` from the `pointer` function looked wrong for me. Now I understand the motivation and the use-case. I will be more careful when analyzing the code which doesn't fit my expectations. @Mike I was wrong. You can ignore my comments. Please don't take them personal: it's all about having high-quality code in kernel. Best Regards, Kirill
Re: [alsa-devel] [PATCH v2] staging: bcm2835-audio: interpolate audio delay
Hello Takashi, Mike, @Takashi On 10/25/18 09:37, Takashi Iwai wrote: > Well, in the API POV, it's nothing wrong to keep hwptr sticking while > updating only delay value. It implies that the hardware chip doesn't > provide the hwptr update. Thank you for the clarification. Modifying `runtime->delay` from the `pointer` function looked wrong for me. Now I understand the motivation and the use-case. I will be more careful when analyzing the code which doesn't fit my expectations. @Mike I was wrong. You can ignore my comments. Please don't take them personal: it's all about having high-quality code in kernel. Best Regards, Kirill
Re: [alsa-devel] [PATCH v2] staging: bcm2835-audio: interpolate audio delay
Hello Mike, We are not on the same page. What you hear is not what I tell you. Either you don't understand what happens in your commit, or I don't understand what happens in the driver. Hopefully somebody in the community can comment here. On 10/24/18 21:54, Mike Brady wrote: You modify the function, which is called `snd_bcm2835_pcm_pointer`. Here you are supposed to increase `alsa_stream->pos` with the proper offset. Instead, you imitate a delay, but in fact the delay is not increased. So, the proper solution should be to fix the reported pointer. >>> >>> I think there is a difficulty with this. The “pos” pointer looks to have to >>> be modulo the buffer size. This causes a problem, as I see it, in that if >>> the calculated (pos + interpolated delay in bytes) is longer than the >>> buffer size >> >> >> There is no "interpolated delay". The concept of "interpolated delay" is >> incorrect. > > Yes, my language here is wrong. What I mean is the estimated number of frames > output since the pointer was last updated — let’s call it the `interpolated > frame count`. > That's not what I mean. From my perspective, the problem is not in language, but in the concept which you introduce here. >> When you play sound - the pointer increments. > > Unfortunately, when you play sound, the pointer does not actually increment, > for up to about 10 milliseconds. I know of no way to actually access the true > “live” position of the frame that is being played at any instant; hence the > desire to estimate it. > Your vision of situation in the opposite from my vision. What you see as a symptom - I see as a root cause. As I see, you should fix the pointer-not-incrementing. Why do you think that it's okay that the pointer is not updating during sound play? Why do you insist that there is a delay? I don't understand why we are so stuck here. > What actually seems to be happening is that when `bcm2835_playback_fifo` is > called, the pointer is updated, but as frames are individually output to the > DAC, this pointer does not increment. It is not updated until the next time > `bcm2835_playback_fifo` is called. > >> But in this commit you increment the delay, as if sound doesn't play. > > It is true that the patch does make use of the snd_pcm_runtime structure’s > “delay" field (aka "runtime->delay” here). That field is defined for: “/* > extra delay; typically FIFO size */”. Clearly it is not being used for that > here — it is being used simply because it is part of the calculation done in > snd_pcm_calc_delay(), as you point out. At present, it looks like that field > isn’t being used –– it’s set to zero –– and not modified anywhere else in the > driver, AFAICS. If it was necessary, it would be a simple matter to preserve > whatever value it was given. > That's not what I am talking about. Somehow we don't understand each other. As a result, userspace will recieve the correct delay, instead of these crazy 10 ms. >>> >>> Just to point out that with the proposed patch, it appears that the correct >>> delay is being reported, (apart, possibly, from any delay originally set in >>> the snd_pcm_delay field, as mentioned above). >> >> >> Then I would like to point out the alsa-lib function `snd_pcm_avail()` - it >> will return the wrong value. > > It is already the case that snd_pcm_avail() does not return the true delay. > The ALSA documentation states: "The value returned by that call [i.e. the > snd_pcm_avail*() functions] is not directly related to the delay…” > Do you mean, that you are submitting the patch into the upstream kernel without reading the code? snd_pcm_avail() is calculated based on: * hw_ptr * buffer_size * appl_ptr * boundary If you fix hw_ptr - it will fix both snd_pcm_delay() and snd_pcm_avail(). Instead, you invent the "interpolated delay", which in fact only compensates the wrong hw_ptr instead of fixing it. Best Regards, Kirill
Re: [alsa-devel] [PATCH v2] staging: bcm2835-audio: interpolate audio delay
Hello Mike, We are not on the same page. What you hear is not what I tell you. Either you don't understand what happens in your commit, or I don't understand what happens in the driver. Hopefully somebody in the community can comment here. On 10/24/18 21:54, Mike Brady wrote: You modify the function, which is called `snd_bcm2835_pcm_pointer`. Here you are supposed to increase `alsa_stream->pos` with the proper offset. Instead, you imitate a delay, but in fact the delay is not increased. So, the proper solution should be to fix the reported pointer. >>> >>> I think there is a difficulty with this. The “pos” pointer looks to have to >>> be modulo the buffer size. This causes a problem, as I see it, in that if >>> the calculated (pos + interpolated delay in bytes) is longer than the >>> buffer size >> >> >> There is no "interpolated delay". The concept of "interpolated delay" is >> incorrect. > > Yes, my language here is wrong. What I mean is the estimated number of frames > output since the pointer was last updated — let’s call it the `interpolated > frame count`. > That's not what I mean. From my perspective, the problem is not in language, but in the concept which you introduce here. >> When you play sound - the pointer increments. > > Unfortunately, when you play sound, the pointer does not actually increment, > for up to about 10 milliseconds. I know of no way to actually access the true > “live” position of the frame that is being played at any instant; hence the > desire to estimate it. > Your vision of situation in the opposite from my vision. What you see as a symptom - I see as a root cause. As I see, you should fix the pointer-not-incrementing. Why do you think that it's okay that the pointer is not updating during sound play? Why do you insist that there is a delay? I don't understand why we are so stuck here. > What actually seems to be happening is that when `bcm2835_playback_fifo` is > called, the pointer is updated, but as frames are individually output to the > DAC, this pointer does not increment. It is not updated until the next time > `bcm2835_playback_fifo` is called. > >> But in this commit you increment the delay, as if sound doesn't play. > > It is true that the patch does make use of the snd_pcm_runtime structure’s > “delay" field (aka "runtime->delay” here). That field is defined for: “/* > extra delay; typically FIFO size */”. Clearly it is not being used for that > here — it is being used simply because it is part of the calculation done in > snd_pcm_calc_delay(), as you point out. At present, it looks like that field > isn’t being used –– it’s set to zero –– and not modified anywhere else in the > driver, AFAICS. If it was necessary, it would be a simple matter to preserve > whatever value it was given. > That's not what I am talking about. Somehow we don't understand each other. As a result, userspace will recieve the correct delay, instead of these crazy 10 ms. >>> >>> Just to point out that with the proposed patch, it appears that the correct >>> delay is being reported, (apart, possibly, from any delay originally set in >>> the snd_pcm_delay field, as mentioned above). >> >> >> Then I would like to point out the alsa-lib function `snd_pcm_avail()` - it >> will return the wrong value. > > It is already the case that snd_pcm_avail() does not return the true delay. > The ALSA documentation states: "The value returned by that call [i.e. the > snd_pcm_avail*() functions] is not directly related to the delay…” > Do you mean, that you are submitting the patch into the upstream kernel without reading the code? snd_pcm_avail() is calculated based on: * hw_ptr * buffer_size * appl_ptr * boundary If you fix hw_ptr - it will fix both snd_pcm_delay() and snd_pcm_avail(). Instead, you invent the "interpolated delay", which in fact only compensates the wrong hw_ptr instead of fixing it. Best Regards, Kirill
Re: [alsa-devel] [PATCH v2] staging: bcm2835-audio: interpolate audio delay
Hello Mike, On 10/24/18 10:20, Mike Brady wrote: > Hi Kirill. Thanks for your comments. > >> On 22 Oct 2018, at 23:25, Kirill Marinushkin wrote: >> >> AFAIU, this patch is wrong. Please correct me, maybe I misunderstand >> something. >> >>> The problem that this patch seeks to resolve is that when userland asks for >>> the delay >> >> The userspace asks not for delay, but for the pointer. > > The call in question is snd_pcm_delay. I presume this delay is calculated > from knowledge of the stream position “pos", the period (buffer?) number (and > period/buffer size) and the snd_pcm_runtime structure’s “delay" field > (“runtime->delay”). > In kernel, this delay is calculated in `snd_pcm_calc_delay()`, defined at `sound/core/pcm_native.c:889`. If you analyze how this calculation is done, you will see that the returned value is a summary of the following fields: * runtime->status->hw_ptr * runtime->buffer_size * runtime->control->appl_ptr * runtime->boundary * runtime->delay >> You modify the function, which is called `snd_bcm2835_pcm_pointer`. Here you >> are >> supposed to increase `alsa_stream->pos` with the proper offset. Instead, you >> imitate a delay, but in fact the delay is not increased. >> >> So, the proper solution should be to fix the reported pointer. > > I think there is a difficulty with this. The “pos” pointer looks to have to > be modulo the buffer size. This causes a problem, as I see it, in that if the > calculated (pos + interpolated delay in bytes) is longer than the buffer size There is no "interpolated delay". The concept of "interpolated delay" is incorrect. When you play sound - the pointer increments. But in this commit you increment the delay, as if sound doesn't play. >> As a result, >> userspace will recieve the correct delay, instead of these crazy 10 ms. > > Just to point out that with the proposed patch, it appears that the correct > delay is being reported, (apart, possibly, from any delay originally set in > the snd_pcm_delay field, as mentioned above). Then I would like to point out the alsa-lib function `snd_pcm_avail()` - it will return the wrong value. > > All the best, > Mike > >> FYI, there is >>> a discussion of the effects of a downstream equivalent of this suggested >>> patch >>> at: >>> https://github.com/raspberrypi/firmware/issues/1026#issuecomment-415746016. >> >> Thank you for the link, it clarified for me what you try to achieve. >> >> On 10/22/18 21:17, Mike Brady wrote: >>> When the BCM2835 audio output is used, userspace sees a jitter up to 10ms >>> in the audio position, aka "delay" -- the number of frames that must >>> be output before a new frame would be played. >>> Make this a bit nicer for userspace by interpolating the position >>> using the CPU clock. >>> The overhead is small -- an extra ktime_get() every time a GPU message >>> is sent -- and another call and a few calculations whenever the delay >>> is sought from userland. >>> At 48,000 frames per second, i.e. approximately 20 microseconds per >>> frame, it would take a clock inaccuracy of >>> 20 microseconds in 10 milliseconds -- 2,000 parts per million -- >>> to result in an inaccurate estimate, whereas >>> crystal- or resonator-based clocks typically have an >>> inaccuracy of 10s to 100s of parts per million. >>> >>> Signed-off-by: Mike Brady >>> --- >>> Changes in v2 -- remove inappropriate addition of SNDRV_PCM_INFO_BATCH flag >>> >>> .../vc04_services/bcm2835-audio/bcm2835-pcm.c | 20 +++ >>> .../vc04_services/bcm2835-audio/bcm2835.h | 1 + >>> 2 files changed, 21 insertions(+) >>> >>> diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c >>> b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c >>> index e66da11af5cf..9053b996cada 100644 >>> --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c >>> +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c >>> @@ -74,6 +74,7 @@ void bcm2835_playback_fifo(struct bcm2835_alsa_stream >>> *alsa_stream, >>> atomic_set(_stream->pos, pos); >>> >>> alsa_stream->period_offset += bytes; >>> + alsa_stream->interpolate_start = ktime_get(); >>> if (alsa_stream->period_offset >= alsa_stream->period_size) { >>> alsa_stream->period_offset %= alsa_stream->period_size; >>>
Re: [alsa-devel] [PATCH v2] staging: bcm2835-audio: interpolate audio delay
Hello Mike, On 10/24/18 10:20, Mike Brady wrote: > Hi Kirill. Thanks for your comments. > >> On 22 Oct 2018, at 23:25, Kirill Marinushkin wrote: >> >> AFAIU, this patch is wrong. Please correct me, maybe I misunderstand >> something. >> >>> The problem that this patch seeks to resolve is that when userland asks for >>> the delay >> >> The userspace asks not for delay, but for the pointer. > > The call in question is snd_pcm_delay. I presume this delay is calculated > from knowledge of the stream position “pos", the period (buffer?) number (and > period/buffer size) and the snd_pcm_runtime structure’s “delay" field > (“runtime->delay”). > In kernel, this delay is calculated in `snd_pcm_calc_delay()`, defined at `sound/core/pcm_native.c:889`. If you analyze how this calculation is done, you will see that the returned value is a summary of the following fields: * runtime->status->hw_ptr * runtime->buffer_size * runtime->control->appl_ptr * runtime->boundary * runtime->delay >> You modify the function, which is called `snd_bcm2835_pcm_pointer`. Here you >> are >> supposed to increase `alsa_stream->pos` with the proper offset. Instead, you >> imitate a delay, but in fact the delay is not increased. >> >> So, the proper solution should be to fix the reported pointer. > > I think there is a difficulty with this. The “pos” pointer looks to have to > be modulo the buffer size. This causes a problem, as I see it, in that if the > calculated (pos + interpolated delay in bytes) is longer than the buffer size There is no "interpolated delay". The concept of "interpolated delay" is incorrect. When you play sound - the pointer increments. But in this commit you increment the delay, as if sound doesn't play. >> As a result, >> userspace will recieve the correct delay, instead of these crazy 10 ms. > > Just to point out that with the proposed patch, it appears that the correct > delay is being reported, (apart, possibly, from any delay originally set in > the snd_pcm_delay field, as mentioned above). Then I would like to point out the alsa-lib function `snd_pcm_avail()` - it will return the wrong value. > > All the best, > Mike > >> FYI, there is >>> a discussion of the effects of a downstream equivalent of this suggested >>> patch >>> at: >>> https://github.com/raspberrypi/firmware/issues/1026#issuecomment-415746016. >> >> Thank you for the link, it clarified for me what you try to achieve. >> >> On 10/22/18 21:17, Mike Brady wrote: >>> When the BCM2835 audio output is used, userspace sees a jitter up to 10ms >>> in the audio position, aka "delay" -- the number of frames that must >>> be output before a new frame would be played. >>> Make this a bit nicer for userspace by interpolating the position >>> using the CPU clock. >>> The overhead is small -- an extra ktime_get() every time a GPU message >>> is sent -- and another call and a few calculations whenever the delay >>> is sought from userland. >>> At 48,000 frames per second, i.e. approximately 20 microseconds per >>> frame, it would take a clock inaccuracy of >>> 20 microseconds in 10 milliseconds -- 2,000 parts per million -- >>> to result in an inaccurate estimate, whereas >>> crystal- or resonator-based clocks typically have an >>> inaccuracy of 10s to 100s of parts per million. >>> >>> Signed-off-by: Mike Brady >>> --- >>> Changes in v2 -- remove inappropriate addition of SNDRV_PCM_INFO_BATCH flag >>> >>> .../vc04_services/bcm2835-audio/bcm2835-pcm.c | 20 +++ >>> .../vc04_services/bcm2835-audio/bcm2835.h | 1 + >>> 2 files changed, 21 insertions(+) >>> >>> diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c >>> b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c >>> index e66da11af5cf..9053b996cada 100644 >>> --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c >>> +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c >>> @@ -74,6 +74,7 @@ void bcm2835_playback_fifo(struct bcm2835_alsa_stream >>> *alsa_stream, >>> atomic_set(_stream->pos, pos); >>> >>> alsa_stream->period_offset += bytes; >>> + alsa_stream->interpolate_start = ktime_get(); >>> if (alsa_stream->period_offset >= alsa_stream->period_size) { >>> alsa_stream->period_offset %= alsa_stream->period_size; >>>
Re: [PATCH v2] staging: bcm2835-audio: interpolate audio delay
Hello Mike, AFAIU, this patch is wrong. Please correct me, maybe I misunderstand something. > The problem that this patch seeks to resolve is that when userland asks for > the delay The userspace asks not for delay, but for the pointer. You modify the function, which is called `snd_bcm2835_pcm_pointer`. Here you are supposed to increase `alsa_stream->pos` with the proper offset. Instead, you imitate a delay, but in fact the delay is not increased. So, the proper solution should be to fix the reported pointer. As a result, userspace will recieve the correct delay, instead of these crazy 10 ms. > FYI, there is > a discussion of the effects of a downstream equivalent of this suggested patch > at: > https://github.com/raspberrypi/firmware/issues/1026#issuecomment-415746016. Thank you for the link, it clarified for me what you try to achieve. On 10/22/18 21:17, Mike Brady wrote: > When the BCM2835 audio output is used, userspace sees a jitter up to 10ms > in the audio position, aka "delay" -- the number of frames that must > be output before a new frame would be played. > Make this a bit nicer for userspace by interpolating the position > using the CPU clock. > The overhead is small -- an extra ktime_get() every time a GPU message > is sent -- and another call and a few calculations whenever the delay > is sought from userland. > At 48,000 frames per second, i.e. approximately 20 microseconds per > frame, it would take a clock inaccuracy of > 20 microseconds in 10 milliseconds -- 2,000 parts per million -- > to result in an inaccurate estimate, whereas > crystal- or resonator-based clocks typically have an > inaccuracy of 10s to 100s of parts per million. > > Signed-off-by: Mike Brady > --- > Changes in v2 -- remove inappropriate addition of SNDRV_PCM_INFO_BATCH flag > > .../vc04_services/bcm2835-audio/bcm2835-pcm.c | 20 +++ > .../vc04_services/bcm2835-audio/bcm2835.h | 1 + > 2 files changed, 21 insertions(+) > > diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c > b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c > index e66da11af5cf..9053b996cada 100644 > --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c > +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c > @@ -74,6 +74,7 @@ void bcm2835_playback_fifo(struct bcm2835_alsa_stream > *alsa_stream, > atomic_set(_stream->pos, pos); > > alsa_stream->period_offset += bytes; > + alsa_stream->interpolate_start = ktime_get(); > if (alsa_stream->period_offset >= alsa_stream->period_size) { > alsa_stream->period_offset %= alsa_stream->period_size; > snd_pcm_period_elapsed(substream); > @@ -243,6 +244,7 @@ static int snd_bcm2835_pcm_prepare(struct > snd_pcm_substream *substream) > atomic_set(_stream->pos, 0); > alsa_stream->period_offset = 0; > alsa_stream->draining = false; > + alsa_stream->interpolate_start = ktime_get(); > > return 0; > } > @@ -292,6 +294,24 @@ snd_bcm2835_pcm_pointer(struct snd_pcm_substream > *substream) > { > struct snd_pcm_runtime *runtime = substream->runtime; > struct bcm2835_alsa_stream *alsa_stream = runtime->private_data; > + ktime_t now = ktime_get(); > + > + /* Give userspace better delay reporting by interpolating between GPU > + * notifications, assuming audio speed is close enough to the clock > + * used for ktime > + */ > + > + if ((ktime_to_ns(alsa_stream->interpolate_start)) && > + (ktime_compare(alsa_stream->interpolate_start, now) < 0)) { > + u64 interval = > + (ktime_to_ns(ktime_sub(now, > + alsa_stream->interpolate_start))); > + u64 frames_output_in_interval = > + div_u64((interval * runtime->rate), 10); > + snd_pcm_sframes_t frames_output_in_interval_sized = > + -frames_output_in_interval; > + runtime->delay = frames_output_in_interval_sized; > + } > > return snd_pcm_indirect_playback_pointer(substream, > _stream->pcm_indirect, > diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.h > b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.h > index e13435d1c205..595ad584243f 100644 > --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.h > +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.h > @@ -78,6 +78,7 @@ struct bcm2835_alsa_stream { > unsigned int period_offset; > unsigned int buffer_size; > unsigned int period_size; > + ktime_t interpolate_start; > > struct bcm2835_audio_instance *instance; > int idx; >
Re: [PATCH v2] staging: bcm2835-audio: interpolate audio delay
Hello Mike, AFAIU, this patch is wrong. Please correct me, maybe I misunderstand something. > The problem that this patch seeks to resolve is that when userland asks for > the delay The userspace asks not for delay, but for the pointer. You modify the function, which is called `snd_bcm2835_pcm_pointer`. Here you are supposed to increase `alsa_stream->pos` with the proper offset. Instead, you imitate a delay, but in fact the delay is not increased. So, the proper solution should be to fix the reported pointer. As a result, userspace will recieve the correct delay, instead of these crazy 10 ms. > FYI, there is > a discussion of the effects of a downstream equivalent of this suggested patch > at: > https://github.com/raspberrypi/firmware/issues/1026#issuecomment-415746016. Thank you for the link, it clarified for me what you try to achieve. On 10/22/18 21:17, Mike Brady wrote: > When the BCM2835 audio output is used, userspace sees a jitter up to 10ms > in the audio position, aka "delay" -- the number of frames that must > be output before a new frame would be played. > Make this a bit nicer for userspace by interpolating the position > using the CPU clock. > The overhead is small -- an extra ktime_get() every time a GPU message > is sent -- and another call and a few calculations whenever the delay > is sought from userland. > At 48,000 frames per second, i.e. approximately 20 microseconds per > frame, it would take a clock inaccuracy of > 20 microseconds in 10 milliseconds -- 2,000 parts per million -- > to result in an inaccurate estimate, whereas > crystal- or resonator-based clocks typically have an > inaccuracy of 10s to 100s of parts per million. > > Signed-off-by: Mike Brady > --- > Changes in v2 -- remove inappropriate addition of SNDRV_PCM_INFO_BATCH flag > > .../vc04_services/bcm2835-audio/bcm2835-pcm.c | 20 +++ > .../vc04_services/bcm2835-audio/bcm2835.h | 1 + > 2 files changed, 21 insertions(+) > > diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c > b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c > index e66da11af5cf..9053b996cada 100644 > --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c > +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-pcm.c > @@ -74,6 +74,7 @@ void bcm2835_playback_fifo(struct bcm2835_alsa_stream > *alsa_stream, > atomic_set(_stream->pos, pos); > > alsa_stream->period_offset += bytes; > + alsa_stream->interpolate_start = ktime_get(); > if (alsa_stream->period_offset >= alsa_stream->period_size) { > alsa_stream->period_offset %= alsa_stream->period_size; > snd_pcm_period_elapsed(substream); > @@ -243,6 +244,7 @@ static int snd_bcm2835_pcm_prepare(struct > snd_pcm_substream *substream) > atomic_set(_stream->pos, 0); > alsa_stream->period_offset = 0; > alsa_stream->draining = false; > + alsa_stream->interpolate_start = ktime_get(); > > return 0; > } > @@ -292,6 +294,24 @@ snd_bcm2835_pcm_pointer(struct snd_pcm_substream > *substream) > { > struct snd_pcm_runtime *runtime = substream->runtime; > struct bcm2835_alsa_stream *alsa_stream = runtime->private_data; > + ktime_t now = ktime_get(); > + > + /* Give userspace better delay reporting by interpolating between GPU > + * notifications, assuming audio speed is close enough to the clock > + * used for ktime > + */ > + > + if ((ktime_to_ns(alsa_stream->interpolate_start)) && > + (ktime_compare(alsa_stream->interpolate_start, now) < 0)) { > + u64 interval = > + (ktime_to_ns(ktime_sub(now, > + alsa_stream->interpolate_start))); > + u64 frames_output_in_interval = > + div_u64((interval * runtime->rate), 10); > + snd_pcm_sframes_t frames_output_in_interval_sized = > + -frames_output_in_interval; > + runtime->delay = frames_output_in_interval_sized; > + } > > return snd_pcm_indirect_playback_pointer(substream, > _stream->pcm_indirect, > diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.h > b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.h > index e13435d1c205..595ad584243f 100644 > --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.h > +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.h > @@ -78,6 +78,7 @@ struct bcm2835_alsa_stream { > unsigned int period_offset; > unsigned int buffer_size; > unsigned int period_size; > + ktime_t interpolate_start; > > struct bcm2835_audio_instance *instance; > int idx; >
Re: [PATCH] staging: bcm2835-audio: interpolate audio delay
Hello Mike, On 10/18/18 12:57, Mike Brady wrote: > + ktime_t now = ktime_get(); > + > + /* Give userspace better delay reporting by interpolating between GPU > + * notifications, assuming audio speed is close enough to the clock > + * used for ktime > + */ > + > + if ((ktime_to_ns(alsa_stream->interpolate_start)) && > + (ktime_compare(alsa_stream->interpolate_start, now) < 0)) { > + u64 interval = > + (ktime_to_ns(ktime_sub(now, > + alsa_stream->interpolate_start))); > + u64 frames_output_in_interval = > + div_u64((interval * runtime->rate), 10); > + snd_pcm_sframes_t frames_output_in_interval_sized = > + -frames_output_in_interval; > + runtime->delay = frames_output_in_interval_sized; > + } This doesn't look like a good solution for me. More like a workaround. What is the root cause of the delay? Best Regards, Kirill
Re: [PATCH] staging: bcm2835-audio: interpolate audio delay
Hello Mike, On 10/18/18 12:57, Mike Brady wrote: > + ktime_t now = ktime_get(); > + > + /* Give userspace better delay reporting by interpolating between GPU > + * notifications, assuming audio speed is close enough to the clock > + * used for ktime > + */ > + > + if ((ktime_to_ns(alsa_stream->interpolate_start)) && > + (ktime_compare(alsa_stream->interpolate_start, now) < 0)) { > + u64 interval = > + (ktime_to_ns(ktime_sub(now, > + alsa_stream->interpolate_start))); > + u64 frames_output_in_interval = > + div_u64((interval * runtime->rate), 10); > + snd_pcm_sframes_t frames_output_in_interval_sized = > + -frames_output_in_interval; > + runtime->delay = frames_output_in_interval_sized; > + } This doesn't look like a good solution for me. More like a workaround. What is the root cause of the delay? Best Regards, Kirill
[PATCH 2/2] ASoC: pcm3060: Improve legibility of if-statements
Modified some if-statements to make them more clear Signed-off-by: Kirill Marinushkin Cc: Mark Brown Cc: alsa-de...@alsa-project.org Cc: linux-kernel@vger.kernel.org --- sound/soc/codecs/pcm3060.c | 10 -- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sound/soc/codecs/pcm3060.c b/sound/soc/codecs/pcm3060.c index 5b9718fa766d..494d9d662be8 100644 --- a/sound/soc/codecs/pcm3060.c +++ b/sound/soc/codecs/pcm3060.c @@ -68,7 +68,10 @@ static int pcm3060_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) return -EINVAL; } - reg = (dai->id == PCM3060_DAI_ID_DAC ? PCM3060_REG67 : PCM3060_REG72); + if (dai->id == PCM3060_DAI_ID_DAC) + reg = PCM3060_REG67; + else + reg = PCM3060_REG72; regmap_update_bits(priv->regmap, reg, PCM3060_REG_MASK_FMT, val); @@ -124,7 +127,10 @@ static int pcm3060_hw_params(struct snd_pcm_substream *substream, } val_ready: - reg = (dai->id == PCM3060_DAI_ID_DAC ? PCM3060_REG67 : PCM3060_REG72); + if (dai->id == PCM3060_DAI_ID_DAC) + reg = PCM3060_REG67; + else + reg = PCM3060_REG72; regmap_update_bits(priv->regmap, reg, PCM3060_REG_MASK_MS, val); -- 2.13.6
[PATCH 2/2] ASoC: pcm3060: Improve legibility of if-statements
Modified some if-statements to make them more clear Signed-off-by: Kirill Marinushkin Cc: Mark Brown Cc: alsa-de...@alsa-project.org Cc: linux-kernel@vger.kernel.org --- sound/soc/codecs/pcm3060.c | 10 -- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sound/soc/codecs/pcm3060.c b/sound/soc/codecs/pcm3060.c index 5b9718fa766d..494d9d662be8 100644 --- a/sound/soc/codecs/pcm3060.c +++ b/sound/soc/codecs/pcm3060.c @@ -68,7 +68,10 @@ static int pcm3060_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) return -EINVAL; } - reg = (dai->id == PCM3060_DAI_ID_DAC ? PCM3060_REG67 : PCM3060_REG72); + if (dai->id == PCM3060_DAI_ID_DAC) + reg = PCM3060_REG67; + else + reg = PCM3060_REG72; regmap_update_bits(priv->regmap, reg, PCM3060_REG_MASK_FMT, val); @@ -124,7 +127,10 @@ static int pcm3060_hw_params(struct snd_pcm_substream *substream, } val_ready: - reg = (dai->id == PCM3060_DAI_ID_DAC ? PCM3060_REG67 : PCM3060_REG72); + if (dai->id == PCM3060_DAI_ID_DAC) + reg = PCM3060_REG67; + else + reg = PCM3060_REG72; regmap_update_bits(priv->regmap, reg, PCM3060_REG_MASK_MS, val); -- 2.13.6
[PATCH 1/2] ASoC: pcm3060: Improve stylistics of file comments
Modified the complete file comments in C++ style, to make them look more intentional Signed-off-by: Kirill Marinushkin Cc: Mark Brown Cc: alsa-de...@alsa-project.org Cc: linux-kernel@vger.kernel.org --- sound/soc/codecs/pcm3060-i2c.c | 9 - sound/soc/codecs/pcm3060-spi.c | 9 - sound/soc/codecs/pcm3060.c | 9 - 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/sound/soc/codecs/pcm3060-i2c.c b/sound/soc/codecs/pcm3060-i2c.c index 03d2b4323626..cdc8314882bc 100644 --- a/sound/soc/codecs/pcm3060-i2c.c +++ b/sound/soc/codecs/pcm3060-i2c.c @@ -1,9 +1,8 @@ // SPDX-License-Identifier: GPL-2.0 -/* - * PCM3060 I2C driver - * - * Copyright (C) 2018 Kirill Marinushkin - */ +// +// PCM3060 I2C driver +// +// Copyright (C) 2018 Kirill Marinushkin #include #include diff --git a/sound/soc/codecs/pcm3060-spi.c b/sound/soc/codecs/pcm3060-spi.c index 8961e095ae73..f6f19fa80932 100644 --- a/sound/soc/codecs/pcm3060-spi.c +++ b/sound/soc/codecs/pcm3060-spi.c @@ -1,9 +1,8 @@ // SPDX-License-Identifier: GPL-2.0 -/* - * PCM3060 SPI driver - * - * Copyright (C) 2018 Kirill Marinushkin - */ +// +// PCM3060 SPI driver +// +// Copyright (C) 2018 Kirill Marinushkin #include #include diff --git a/sound/soc/codecs/pcm3060.c b/sound/soc/codecs/pcm3060.c index ef7c627c9ac5..5b9718fa766d 100644 --- a/sound/soc/codecs/pcm3060.c +++ b/sound/soc/codecs/pcm3060.c @@ -1,9 +1,8 @@ // SPDX-License-Identifier: GPL-2.0 -/* - * PCM3060 codec driver - * - * Copyright (C) 2018 Kirill Marinushkin - */ +// +// PCM3060 codec driver +// +// Copyright (C) 2018 Kirill Marinushkin #include #include -- 2.13.6
[PATCH 1/2] ASoC: pcm3060: Improve stylistics of file comments
Modified the complete file comments in C++ style, to make them look more intentional Signed-off-by: Kirill Marinushkin Cc: Mark Brown Cc: alsa-de...@alsa-project.org Cc: linux-kernel@vger.kernel.org --- sound/soc/codecs/pcm3060-i2c.c | 9 - sound/soc/codecs/pcm3060-spi.c | 9 - sound/soc/codecs/pcm3060.c | 9 - 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/sound/soc/codecs/pcm3060-i2c.c b/sound/soc/codecs/pcm3060-i2c.c index 03d2b4323626..cdc8314882bc 100644 --- a/sound/soc/codecs/pcm3060-i2c.c +++ b/sound/soc/codecs/pcm3060-i2c.c @@ -1,9 +1,8 @@ // SPDX-License-Identifier: GPL-2.0 -/* - * PCM3060 I2C driver - * - * Copyright (C) 2018 Kirill Marinushkin - */ +// +// PCM3060 I2C driver +// +// Copyright (C) 2018 Kirill Marinushkin #include #include diff --git a/sound/soc/codecs/pcm3060-spi.c b/sound/soc/codecs/pcm3060-spi.c index 8961e095ae73..f6f19fa80932 100644 --- a/sound/soc/codecs/pcm3060-spi.c +++ b/sound/soc/codecs/pcm3060-spi.c @@ -1,9 +1,8 @@ // SPDX-License-Identifier: GPL-2.0 -/* - * PCM3060 SPI driver - * - * Copyright (C) 2018 Kirill Marinushkin - */ +// +// PCM3060 SPI driver +// +// Copyright (C) 2018 Kirill Marinushkin #include #include diff --git a/sound/soc/codecs/pcm3060.c b/sound/soc/codecs/pcm3060.c index ef7c627c9ac5..5b9718fa766d 100644 --- a/sound/soc/codecs/pcm3060.c +++ b/sound/soc/codecs/pcm3060.c @@ -1,9 +1,8 @@ // SPDX-License-Identifier: GPL-2.0 -/* - * PCM3060 codec driver - * - * Copyright (C) 2018 Kirill Marinushkin - */ +// +// PCM3060 codec driver +// +// Copyright (C) 2018 Kirill Marinushkin #include #include -- 2.13.6
[PATCH 1/1] ASoC: pcm3060: Add codec driver
This commit adds support for TI PCM3060 CODEC. The technical documentation is available at [1]. [1] http://ti.com/product/pcm3060 Signed-off-by: Kirill Marinushkin Cc: Mark Brown Cc: Liam Girdwood Cc: Jaroslav Kysela Cc: Takashi Iwai Cc: M R Swami Reddy Cc: Vishwas A Deshpande Cc: Kevin Cernekee Cc: Peter Ujfalusi Cc: alsa-de...@alsa-project.org Cc: linux-kernel@vger.kernel.org --- .../devicetree/bindings/sound/pcm3060.txt | 17 ++ MAINTAINERS| 7 + sound/soc/codecs/Kconfig | 17 ++ sound/soc/codecs/Makefile | 6 + sound/soc/codecs/pcm3060-i2c.c | 61 + sound/soc/codecs/pcm3060-spi.c | 60 + sound/soc/codecs/pcm3060.c | 290 + sound/soc/codecs/pcm3060.h | 88 +++ 8 files changed, 546 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/pcm3060.txt create mode 100644 sound/soc/codecs/pcm3060-i2c.c create mode 100644 sound/soc/codecs/pcm3060-spi.c create mode 100644 sound/soc/codecs/pcm3060.c create mode 100644 sound/soc/codecs/pcm3060.h diff --git a/Documentation/devicetree/bindings/sound/pcm3060.txt b/Documentation/devicetree/bindings/sound/pcm3060.txt new file mode 100644 index ..90fcb8523099 --- /dev/null +++ b/Documentation/devicetree/bindings/sound/pcm3060.txt @@ -0,0 +1,17 @@ +PCM3060 audio CODEC + +This driver supports both I2C and SPI. + +Required properties: + +- compatible: "ti,pcm3060" + +- reg : the I2C address of the device for I2C, the chip select +number for SPI. + +Examples: + + pcm3060: pcm3060@46 { +compatible = "ti,pcm3060"; +reg = <0x46>; + }; diff --git a/MAINTAINERS b/MAINTAINERS index 955463f8d518..ee605559d4ab 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14540,6 +14540,13 @@ L: net...@vger.kernel.org S: Maintained F: drivers/net/ethernet/ti/netcp* +TI PCM3060 ASoC CODEC DRIVER +M: Kirill Marinushkin +L: alsa-de...@alsa-project.org (moderated for non-subscribers) +S: Maintained +F: Documentation/devicetree/bindings/sound/pcm3060.txt +F: sound/soc/codecs/pcm3060* + TI TAS571X FAMILY ASoC CODEC DRIVER M: Kevin Cernekee L: alsa-de...@alsa-project.org (moderated for non-subscribers) diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig index efb095dbcd71..2756e883a116 100644 --- a/sound/soc/codecs/Kconfig +++ b/sound/soc/codecs/Kconfig @@ -119,6 +119,8 @@ config SND_SOC_ALL_CODECS select SND_SOC_PCM186X_I2C if I2C select SND_SOC_PCM186X_SPI if SPI_MASTER select SND_SOC_PCM3008 + select SND_SOC_PCM3060_I2C if I2C + select SND_SOC_PCM3060_SPI if SPI_MASTER select SND_SOC_PCM3168A_I2C if I2C select SND_SOC_PCM3168A_SPI if SPI_MASTER select SND_SOC_PCM5102A @@ -732,6 +734,21 @@ config SND_SOC_PCM186X_SPI config SND_SOC_PCM3008 tristate +config SND_SOC_PCM3060 + tristate + +config SND_SOC_PCM3060_I2C + tristate "Texas Instruments PCM3060 CODEC - I2C" + depends on I2C + select SND_SOC_PCM3060 + select REGMAP_I2C + +config SND_SOC_PCM3060_SPI + tristate "Texas Instruments PCM3060 CODEC - SPI" + depends on SPI_MASTER + select SND_SOC_PCM3060 + select REGMAP_SPI + config SND_SOC_PCM3168A tristate diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile index 7ae7c85e8219..8071c66811d4 100644 --- a/sound/soc/codecs/Makefile +++ b/sound/soc/codecs/Makefile @@ -119,6 +119,9 @@ snd-soc-pcm186x-objs := pcm186x.o snd-soc-pcm186x-i2c-objs := pcm186x-i2c.o snd-soc-pcm186x-spi-objs := pcm186x-spi.o snd-soc-pcm3008-objs := pcm3008.o +snd-soc-pcm3060-objs := pcm3060.o +snd-soc-pcm3060-i2c-objs := pcm3060-i2c.o +snd-soc-pcm3060-spi-objs := pcm3060-spi.o snd-soc-pcm3168a-objs := pcm3168a.o snd-soc-pcm3168a-i2c-objs := pcm3168a-i2c.o snd-soc-pcm3168a-spi-objs := pcm3168a-spi.o @@ -379,6 +382,9 @@ obj-$(CONFIG_SND_SOC_PCM186X) += snd-soc-pcm186x.o obj-$(CONFIG_SND_SOC_PCM186X_I2C) += snd-soc-pcm186x-i2c.o obj-$(CONFIG_SND_SOC_PCM186X_SPI) += snd-soc-pcm186x-spi.o obj-$(CONFIG_SND_SOC_PCM3008) += snd-soc-pcm3008.o +obj-$(CONFIG_SND_SOC_PCM3060) += snd-soc-pcm3060.o +obj-$(CONFIG_SND_SOC_PCM3060_I2C) += snd-soc-pcm3060-i2c.o +obj-$(CONFIG_SND_SOC_PCM3060_SPI) += snd-soc-pcm3060-spi.o obj-$(CONFIG_SND_SOC_PCM3168A) += snd-soc-pcm3168a.o obj-$(CONFIG_SND_SOC_PCM3168A_I2C) += snd-soc-pcm3168a-i2c.o obj-$(CONFIG_SND_SOC_PCM3168A_SPI) += snd-soc-pcm3168a-spi.o diff --git a/sound/soc/codecs/pcm3060-i2c.c b/sound/soc/codecs/pcm3060-i2c.c new file mode 100644 index ..03d2b4323626 --- /dev/null +++ b/sound/soc/codecs/pcm3060-i2c.c @@ -0,0 +1,61 @@ +// SPDX-License-Identifier: GPL-2.0 +
[PATCH 1/1] ASoC: pcm3060: Add codec driver
This commit adds support for TI PCM3060 CODEC. The technical documentation is available at [1]. [1] http://ti.com/product/pcm3060 Signed-off-by: Kirill Marinushkin Cc: Mark Brown Cc: Liam Girdwood Cc: Jaroslav Kysela Cc: Takashi Iwai Cc: M R Swami Reddy Cc: Vishwas A Deshpande Cc: Kevin Cernekee Cc: Peter Ujfalusi Cc: alsa-de...@alsa-project.org Cc: linux-kernel@vger.kernel.org --- .../devicetree/bindings/sound/pcm3060.txt | 17 ++ MAINTAINERS| 7 + sound/soc/codecs/Kconfig | 17 ++ sound/soc/codecs/Makefile | 6 + sound/soc/codecs/pcm3060-i2c.c | 61 + sound/soc/codecs/pcm3060-spi.c | 60 + sound/soc/codecs/pcm3060.c | 290 + sound/soc/codecs/pcm3060.h | 88 +++ 8 files changed, 546 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/pcm3060.txt create mode 100644 sound/soc/codecs/pcm3060-i2c.c create mode 100644 sound/soc/codecs/pcm3060-spi.c create mode 100644 sound/soc/codecs/pcm3060.c create mode 100644 sound/soc/codecs/pcm3060.h diff --git a/Documentation/devicetree/bindings/sound/pcm3060.txt b/Documentation/devicetree/bindings/sound/pcm3060.txt new file mode 100644 index ..90fcb8523099 --- /dev/null +++ b/Documentation/devicetree/bindings/sound/pcm3060.txt @@ -0,0 +1,17 @@ +PCM3060 audio CODEC + +This driver supports both I2C and SPI. + +Required properties: + +- compatible: "ti,pcm3060" + +- reg : the I2C address of the device for I2C, the chip select +number for SPI. + +Examples: + + pcm3060: pcm3060@46 { +compatible = "ti,pcm3060"; +reg = <0x46>; + }; diff --git a/MAINTAINERS b/MAINTAINERS index 955463f8d518..ee605559d4ab 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14540,6 +14540,13 @@ L: net...@vger.kernel.org S: Maintained F: drivers/net/ethernet/ti/netcp* +TI PCM3060 ASoC CODEC DRIVER +M: Kirill Marinushkin +L: alsa-de...@alsa-project.org (moderated for non-subscribers) +S: Maintained +F: Documentation/devicetree/bindings/sound/pcm3060.txt +F: sound/soc/codecs/pcm3060* + TI TAS571X FAMILY ASoC CODEC DRIVER M: Kevin Cernekee L: alsa-de...@alsa-project.org (moderated for non-subscribers) diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig index efb095dbcd71..2756e883a116 100644 --- a/sound/soc/codecs/Kconfig +++ b/sound/soc/codecs/Kconfig @@ -119,6 +119,8 @@ config SND_SOC_ALL_CODECS select SND_SOC_PCM186X_I2C if I2C select SND_SOC_PCM186X_SPI if SPI_MASTER select SND_SOC_PCM3008 + select SND_SOC_PCM3060_I2C if I2C + select SND_SOC_PCM3060_SPI if SPI_MASTER select SND_SOC_PCM3168A_I2C if I2C select SND_SOC_PCM3168A_SPI if SPI_MASTER select SND_SOC_PCM5102A @@ -732,6 +734,21 @@ config SND_SOC_PCM186X_SPI config SND_SOC_PCM3008 tristate +config SND_SOC_PCM3060 + tristate + +config SND_SOC_PCM3060_I2C + tristate "Texas Instruments PCM3060 CODEC - I2C" + depends on I2C + select SND_SOC_PCM3060 + select REGMAP_I2C + +config SND_SOC_PCM3060_SPI + tristate "Texas Instruments PCM3060 CODEC - SPI" + depends on SPI_MASTER + select SND_SOC_PCM3060 + select REGMAP_SPI + config SND_SOC_PCM3168A tristate diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile index 7ae7c85e8219..8071c66811d4 100644 --- a/sound/soc/codecs/Makefile +++ b/sound/soc/codecs/Makefile @@ -119,6 +119,9 @@ snd-soc-pcm186x-objs := pcm186x.o snd-soc-pcm186x-i2c-objs := pcm186x-i2c.o snd-soc-pcm186x-spi-objs := pcm186x-spi.o snd-soc-pcm3008-objs := pcm3008.o +snd-soc-pcm3060-objs := pcm3060.o +snd-soc-pcm3060-i2c-objs := pcm3060-i2c.o +snd-soc-pcm3060-spi-objs := pcm3060-spi.o snd-soc-pcm3168a-objs := pcm3168a.o snd-soc-pcm3168a-i2c-objs := pcm3168a-i2c.o snd-soc-pcm3168a-spi-objs := pcm3168a-spi.o @@ -379,6 +382,9 @@ obj-$(CONFIG_SND_SOC_PCM186X) += snd-soc-pcm186x.o obj-$(CONFIG_SND_SOC_PCM186X_I2C) += snd-soc-pcm186x-i2c.o obj-$(CONFIG_SND_SOC_PCM186X_SPI) += snd-soc-pcm186x-spi.o obj-$(CONFIG_SND_SOC_PCM3008) += snd-soc-pcm3008.o +obj-$(CONFIG_SND_SOC_PCM3060) += snd-soc-pcm3060.o +obj-$(CONFIG_SND_SOC_PCM3060_I2C) += snd-soc-pcm3060-i2c.o +obj-$(CONFIG_SND_SOC_PCM3060_SPI) += snd-soc-pcm3060-spi.o obj-$(CONFIG_SND_SOC_PCM3168A) += snd-soc-pcm3168a.o obj-$(CONFIG_SND_SOC_PCM3168A_I2C) += snd-soc-pcm3168a-i2c.o obj-$(CONFIG_SND_SOC_PCM3168A_SPI) += snd-soc-pcm3168a-spi.o diff --git a/sound/soc/codecs/pcm3060-i2c.c b/sound/soc/codecs/pcm3060-i2c.c new file mode 100644 index ..03d2b4323626 --- /dev/null +++ b/sound/soc/codecs/pcm3060-i2c.c @@ -0,0 +1,61 @@ +// SPDX-License-Identifier: GPL-2.0 +
[PATCH 0/1] ASoC: pcm3060: Add codec driver
Hello Mark, I am developing sound support for a Linux-based device, with playback and capture through the TI PCM3060 codec. With the following patch, I propose to add the PCM3060 codec driver into the kernel. Best Regards, Kirill Kirill Marinushkin (1): ASoC: pcm3060: Add codec driver .../devicetree/bindings/sound/pcm3060.txt | 17 ++ MAINTAINERS| 7 + sound/soc/codecs/Kconfig | 17 ++ sound/soc/codecs/Makefile | 6 + sound/soc/codecs/pcm3060-i2c.c | 61 + sound/soc/codecs/pcm3060-spi.c | 60 + sound/soc/codecs/pcm3060.c | 290 + sound/soc/codecs/pcm3060.h | 88 +++ 8 files changed, 546 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/pcm3060.txt create mode 100644 sound/soc/codecs/pcm3060-i2c.c create mode 100644 sound/soc/codecs/pcm3060-spi.c create mode 100644 sound/soc/codecs/pcm3060.c create mode 100644 sound/soc/codecs/pcm3060.h -- 2.13.6
[PATCH 0/1] ASoC: pcm3060: Add codec driver
Hello Mark, I am developing sound support for a Linux-based device, with playback and capture through the TI PCM3060 codec. With the following patch, I propose to add the PCM3060 codec driver into the kernel. Best Regards, Kirill Kirill Marinushkin (1): ASoC: pcm3060: Add codec driver .../devicetree/bindings/sound/pcm3060.txt | 17 ++ MAINTAINERS| 7 + sound/soc/codecs/Kconfig | 17 ++ sound/soc/codecs/Makefile | 6 + sound/soc/codecs/pcm3060-i2c.c | 61 + sound/soc/codecs/pcm3060-spi.c | 60 + sound/soc/codecs/pcm3060.c | 290 + sound/soc/codecs/pcm3060.h | 88 +++ 8 files changed, 546 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/pcm3060.txt create mode 100644 sound/soc/codecs/pcm3060-i2c.c create mode 100644 sound/soc/codecs/pcm3060-spi.c create mode 100644 sound/soc/codecs/pcm3060.c create mode 100644 sound/soc/codecs/pcm3060.h -- 2.13.6
[PATCH v3] staging: bcm2835-audio: Disconnect and free vchi_instance on module_exit()
In the current implementation, vchi_instance is inited during the first call of bcm2835_audio_open_connection(), and is never freed. It causes a memory leak when the module `snd_bcm2835` is removed. Here is how this commit fixes it: * the VCHI context (including vchi_instance) is created once in the platform's devres * the VCHI context is allocated and connected once during module_init() * all created bcm2835_chips have a pointer to this VCHI context * bcm2835_audio_open_connection() can access the VCHI context through the associated bcm2835_chip * the VCHI context is disconnected and freed once during module_exit() After this commit is applied, I don't see other issues with the module's init/exit, so I also remove the associated TODO task. Steps to reproduce the memory leak before this commit: root@raspberrypi:/home/pi# aplay test0.wav Playing WAVE 'test0.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Ster ^CAborted by signal Interrupt... root@raspberrypi:/home/pi# rmmod snd_bcm2835 root@raspberrypi:/home/pi# modprobe snd_bcm2835 root@raspberrypi:/home/pi# aplay test0.wav Playing WAVE 'test0.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Ster ^CAborted by signal Interrupt... root@raspberrypi:/home/pi# echo scan > /sys/kernel/debug/kmemleak root@raspberrypi:/home/pi# cat /sys/kernel/debug/kmemleak unreferenced object 0xb6794c00 (size 128): comm "aplay", pid 406, jiffies 36870 (age 116.650s) hex dump (first 32 bytes): 08 a5 82 81 01 00 00 00 08 4c 79 b6 08 4c 79 b6 .Ly..Ly. 00 00 00 00 00 00 00 00 ad 4e ad de ff ff ff ff .N.. backtrace: [<802af5e0>] kmem_cache_alloc_trace+0x294/0x3d0 [<806ce620>] vchiq_initialise+0x98/0x1b0 [<806d0b34>] vchi_initialise+0x24/0x34 [<7f1311ec>] 0x7f1311ec [<7f1303bc>] 0x7f1303bc [<7f130590>] 0x7f130590 [<7f111fd8>] snd_pcm_open_substream+0x68/0xc4 [snd_pcm] [<7f112108>] snd_pcm_open+0xd4/0x248 [snd_pcm] [<7f112334>] snd_pcm_playback_open+0x4c/0x6c [snd_pcm] [<7f0e250c>] snd_open+0xa8/0x14c [snd] [<802ce590>] chrdev_open+0xac/0x188 [<802c57b4>] do_dentry_open+0x10c/0x314 [<802c6ba8>] vfs_open+0x5c/0x88 [<802d9a68>] path_openat+0x368/0x944 [<802dacd4>] do_filp_open+0x70/0xc4 [<802c6f70>] do_sys_open+0x110/0x1d4 Signed-off-by: Kirill Marinushkin <k.marinush...@gmail.com> Cc: Eric Anholt <e...@anholt.net> Cc: Stefan Wahren <stefan.wah...@i2se.com> Cc: Greg Kroah-Hartman <gre...@linuxfoundation.org> Cc: Florian Fainelli <f.faine...@gmail.com> Cc: Ray Jui <r...@broadcom.com> Cc: Scott Branden <sbran...@broadcom.com> Cc: Andy Shevchenko <andy.shevche...@gmail.com> Cc: Dan Carpenter <dan.carpen...@oracle.com> Cc: bcm-kernel-feedback-l...@broadcom.com Cc: linux-rpi-ker...@lists.infradead.org Cc: linux-arm-ker...@lists.infradead.org Cc: de...@driverdev.osuosl.org Cc: linux-kernel@vger.kernel.org --- Chagelog v1: Initial patch v2: Fixed the compiler warning @drivers/staging/vc04_services/bcm2835-audio/bcm2835.c:168 if (!chip->vchi_ctx) { kfree(chip); - return err; + return -ENODEV; } v3: Appended this changelog .../vc04_services/bcm2835-audio/bcm2835-vchiq.c| 64 +- .../staging/vc04_services/bcm2835-audio/bcm2835.c | 43 ++- .../staging/vc04_services/bcm2835-audio/bcm2835.h | 12 3 files changed, 91 insertions(+), 28 deletions(-) diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c index 3c6f1d91d22d..389a18f9350a 100644 --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c @@ -33,7 +33,6 @@ /* Include Files */ -#include "interface/vchi/vchi.h" #include "vc_vchi_audioserv_defs.h" /* Private Constants and Types -- */ @@ -371,14 +370,46 @@ static int vc_vchi_audio_deinit(struct bcm2835_audio_instance *instance) return 0; } +int bcm2835_new_vchi_ctx(struct bcm2835_vchi_ctx *vchi_ctx) +{ + int ret; + + /* Initialize and create a VCHI connection */ + ret = vchi_initialise(_ctx->vchi_instance); + if (ret) { + LOG_ERR("%s: failed to initialise VCHI instance (ret=%d)\n", + __func__, ret); + + return -EIO; + } + + ret = vchi_connect(NULL, 0, vchi_ctx->vchi_instance); + if (ret) { + LOG_ERR("%s: failed to connect VCHI instance (ret=%d)\n", + __func__, ret); + + kfree(vchi_ctx->vchi_instance); + vchi_ctx->vchi_i
[PATCH v3] staging: bcm2835-audio: Disconnect and free vchi_instance on module_exit()
In the current implementation, vchi_instance is inited during the first call of bcm2835_audio_open_connection(), and is never freed. It causes a memory leak when the module `snd_bcm2835` is removed. Here is how this commit fixes it: * the VCHI context (including vchi_instance) is created once in the platform's devres * the VCHI context is allocated and connected once during module_init() * all created bcm2835_chips have a pointer to this VCHI context * bcm2835_audio_open_connection() can access the VCHI context through the associated bcm2835_chip * the VCHI context is disconnected and freed once during module_exit() After this commit is applied, I don't see other issues with the module's init/exit, so I also remove the associated TODO task. Steps to reproduce the memory leak before this commit: root@raspberrypi:/home/pi# aplay test0.wav Playing WAVE 'test0.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Ster ^CAborted by signal Interrupt... root@raspberrypi:/home/pi# rmmod snd_bcm2835 root@raspberrypi:/home/pi# modprobe snd_bcm2835 root@raspberrypi:/home/pi# aplay test0.wav Playing WAVE 'test0.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Ster ^CAborted by signal Interrupt... root@raspberrypi:/home/pi# echo scan > /sys/kernel/debug/kmemleak root@raspberrypi:/home/pi# cat /sys/kernel/debug/kmemleak unreferenced object 0xb6794c00 (size 128): comm "aplay", pid 406, jiffies 36870 (age 116.650s) hex dump (first 32 bytes): 08 a5 82 81 01 00 00 00 08 4c 79 b6 08 4c 79 b6 .Ly..Ly. 00 00 00 00 00 00 00 00 ad 4e ad de ff ff ff ff .N.. backtrace: [<802af5e0>] kmem_cache_alloc_trace+0x294/0x3d0 [<806ce620>] vchiq_initialise+0x98/0x1b0 [<806d0b34>] vchi_initialise+0x24/0x34 [<7f1311ec>] 0x7f1311ec [<7f1303bc>] 0x7f1303bc [<7f130590>] 0x7f130590 [<7f111fd8>] snd_pcm_open_substream+0x68/0xc4 [snd_pcm] [<7f112108>] snd_pcm_open+0xd4/0x248 [snd_pcm] [<7f112334>] snd_pcm_playback_open+0x4c/0x6c [snd_pcm] [<7f0e250c>] snd_open+0xa8/0x14c [snd] [<802ce590>] chrdev_open+0xac/0x188 [<802c57b4>] do_dentry_open+0x10c/0x314 [<802c6ba8>] vfs_open+0x5c/0x88 [<802d9a68>] path_openat+0x368/0x944 [<802dacd4>] do_filp_open+0x70/0xc4 [<802c6f70>] do_sys_open+0x110/0x1d4 Signed-off-by: Kirill Marinushkin Cc: Eric Anholt Cc: Stefan Wahren Cc: Greg Kroah-Hartman Cc: Florian Fainelli Cc: Ray Jui Cc: Scott Branden Cc: Andy Shevchenko Cc: Dan Carpenter Cc: bcm-kernel-feedback-l...@broadcom.com Cc: linux-rpi-ker...@lists.infradead.org Cc: linux-arm-ker...@lists.infradead.org Cc: de...@driverdev.osuosl.org Cc: linux-kernel@vger.kernel.org --- Chagelog v1: Initial patch v2: Fixed the compiler warning @drivers/staging/vc04_services/bcm2835-audio/bcm2835.c:168 if (!chip->vchi_ctx) { kfree(chip); - return err; + return -ENODEV; } v3: Appended this changelog .../vc04_services/bcm2835-audio/bcm2835-vchiq.c| 64 +- .../staging/vc04_services/bcm2835-audio/bcm2835.c | 43 ++- .../staging/vc04_services/bcm2835-audio/bcm2835.h | 12 3 files changed, 91 insertions(+), 28 deletions(-) diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c index 3c6f1d91d22d..389a18f9350a 100644 --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c @@ -33,7 +33,6 @@ /* Include Files */ -#include "interface/vchi/vchi.h" #include "vc_vchi_audioserv_defs.h" /* Private Constants and Types -- */ @@ -371,14 +370,46 @@ static int vc_vchi_audio_deinit(struct bcm2835_audio_instance *instance) return 0; } +int bcm2835_new_vchi_ctx(struct bcm2835_vchi_ctx *vchi_ctx) +{ + int ret; + + /* Initialize and create a VCHI connection */ + ret = vchi_initialise(_ctx->vchi_instance); + if (ret) { + LOG_ERR("%s: failed to initialise VCHI instance (ret=%d)\n", + __func__, ret); + + return -EIO; + } + + ret = vchi_connect(NULL, 0, vchi_ctx->vchi_instance); + if (ret) { + LOG_ERR("%s: failed to connect VCHI instance (ret=%d)\n", + __func__, ret); + + kfree(vchi_ctx->vchi_instance); + vchi_ctx->vchi_instance = NULL; + + return -EIO; + } + + return 0; +} + +void bcm2835_free_vchi_ctx(struct bcm2835_vchi_ctx *vchi_ctx) +{ + /* Close the VCHI connection - it will also free vchi_instance */ + WARN_ON(vchi_disconnect(vchi_ctx-&g
Re: [PATCH v2] staging: bcm2835-audio: Disconnect and free vchi_instance on module_exit()
On 04/25/18 08:16, Greg Kroah-Hartman wrote: > On Tue, Apr 24, 2018 at 09:57:29PM +0200, Kirill Marinushkin wrote: >> In the current implementation, vchi_instance is inited during the first >> call of bcm2835_audio_open_connection(), and is never freed. It causes a >> memory leak when the module `snd_bcm2835` is removed. >> >> Here is how this commit fixes it: >> >> * the VCHI context (including vchi_instance) is created once in the >> platform's devres >> * the VCHI context is allocated and connected once during module_init() >> * all created bcm2835_chips have a pointer to this VCHI context >> * bcm2835_audio_open_connection() can access the VCHI context through the >> associated bcm2835_chip >> * the VCHI context is disconnected and freed once during module_exit() >> >> After this commit is applied, I don't see other issues with the module's >> init/exit, so I also remove the associated TODO task. >> >> Steps to reproduce the memory leak before this commit: >> >> >> root@raspberrypi:/home/pi# aplay test0.wav >> Playing WAVE 'test0.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Ster >> ^CAborted by signal Interrupt... >> root@raspberrypi:/home/pi# rmmod snd_bcm2835 >> root@raspberrypi:/home/pi# modprobe snd_bcm2835 >> root@raspberrypi:/home/pi# aplay test0.wav >> Playing WAVE 'test0.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Ster >> ^CAborted by signal Interrupt... >> root@raspberrypi:/home/pi# echo scan > /sys/kernel/debug/kmemleak >> root@raspberrypi:/home/pi# cat /sys/kernel/debug/kmemleak >> unreferenced object 0xb6794c00 (size 128): >> comm "aplay", pid 406, jiffies 36870 (age 116.650s) >> hex dump (first 32 bytes): >> 08 a5 82 81 01 00 00 00 08 4c 79 b6 08 4c 79 b6 .Ly..Ly. >> 00 00 00 00 00 00 00 00 ad 4e ad de ff ff ff ff .N.. >> backtrace: >> [<802af5e0>] kmem_cache_alloc_trace+0x294/0x3d0 >> [<806ce620>] vchiq_initialise+0x98/0x1b0 >> [<806d0b34>] vchi_initialise+0x24/0x34 >> [<7f1311ec>] 0x7f1311ec >> [<7f1303bc>] 0x7f1303bc >> [<7f130590>] 0x7f130590 >> [<7f111fd8>] snd_pcm_open_substream+0x68/0xc4 [snd_pcm] >> [<7f112108>] snd_pcm_open+0xd4/0x248 [snd_pcm] >> [<7f112334>] snd_pcm_playback_open+0x4c/0x6c [snd_pcm] >> [<7f0e250c>] snd_open+0xa8/0x14c [snd] >> [<802ce590>] chrdev_open+0xac/0x188 >> [<802c57b4>] do_dentry_open+0x10c/0x314 >> [<802c6ba8>] vfs_open+0x5c/0x88 >> [<802d9a68>] path_openat+0x368/0x944 >> [<802dacd4>] do_filp_open+0x70/0xc4 >> [<802c6f70>] do_sys_open+0x110/0x1d4 >> >> >> Signed-off-by: Kirill Marinushkin <k.marinush...@gmail.com> >> Cc: Eric Anholt <e...@anholt.net> >> Cc: Stefan Wahren <stefan.wah...@i2se.com> >> Cc: Greg Kroah-Hartman <gre...@linuxfoundation.org> >> Cc: Florian Fainelli <f.faine...@gmail.com> >> Cc: Ray Jui <r...@broadcom.com> >> Cc: Scott Branden <sbran...@broadcom.com> >> Cc: Andy Shevchenko <andy.shevche...@gmail.com> >> Cc: Dan Carpenter <dan.carpen...@oracle.com> >> Cc: bcm-kernel-feedback-l...@broadcom.com >> Cc: linux-rpi-ker...@lists.infradead.org >> Cc: linux-arm-ker...@lists.infradead.org >> Cc: de...@driverdev.osuosl.org >> Cc: linux-kernel@vger.kernel.org >> --- >> .../vc04_services/bcm2835-audio/bcm2835-vchiq.c| 64 >> +- >> .../staging/vc04_services/bcm2835-audio/bcm2835.c | 43 ++- >> .../staging/vc04_services/bcm2835-audio/bcm2835.h | 12 >> 3 files changed, 91 insertions(+), 28 deletions(-) > What changed from v1? Always put that below the --- line as the > documentation says to do so. > > v3? :) > > thanks, > > greg k-h :) Below is the git diff v1..v2 diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c index 009c972d93d6..662e05bd8f05 100644 --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c @@ -165,7 +165,7 @@ static int snd_bcm2835_create(struct snd_card *card, bcm2835_devm_free_vchi_ctx, NULL, NULL); if (!chip->vchi_ctx) { kfree(chip); - return err; + return -ENODEV; } err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, ); Best Regards, Kirill
Re: [PATCH v2] staging: bcm2835-audio: Disconnect and free vchi_instance on module_exit()
On 04/25/18 08:16, Greg Kroah-Hartman wrote: > On Tue, Apr 24, 2018 at 09:57:29PM +0200, Kirill Marinushkin wrote: >> In the current implementation, vchi_instance is inited during the first >> call of bcm2835_audio_open_connection(), and is never freed. It causes a >> memory leak when the module `snd_bcm2835` is removed. >> >> Here is how this commit fixes it: >> >> * the VCHI context (including vchi_instance) is created once in the >> platform's devres >> * the VCHI context is allocated and connected once during module_init() >> * all created bcm2835_chips have a pointer to this VCHI context >> * bcm2835_audio_open_connection() can access the VCHI context through the >> associated bcm2835_chip >> * the VCHI context is disconnected and freed once during module_exit() >> >> After this commit is applied, I don't see other issues with the module's >> init/exit, so I also remove the associated TODO task. >> >> Steps to reproduce the memory leak before this commit: >> >> >> root@raspberrypi:/home/pi# aplay test0.wav >> Playing WAVE 'test0.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Ster >> ^CAborted by signal Interrupt... >> root@raspberrypi:/home/pi# rmmod snd_bcm2835 >> root@raspberrypi:/home/pi# modprobe snd_bcm2835 >> root@raspberrypi:/home/pi# aplay test0.wav >> Playing WAVE 'test0.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Ster >> ^CAborted by signal Interrupt... >> root@raspberrypi:/home/pi# echo scan > /sys/kernel/debug/kmemleak >> root@raspberrypi:/home/pi# cat /sys/kernel/debug/kmemleak >> unreferenced object 0xb6794c00 (size 128): >> comm "aplay", pid 406, jiffies 36870 (age 116.650s) >> hex dump (first 32 bytes): >> 08 a5 82 81 01 00 00 00 08 4c 79 b6 08 4c 79 b6 .Ly..Ly. >> 00 00 00 00 00 00 00 00 ad 4e ad de ff ff ff ff .N.. >> backtrace: >> [<802af5e0>] kmem_cache_alloc_trace+0x294/0x3d0 >> [<806ce620>] vchiq_initialise+0x98/0x1b0 >> [<806d0b34>] vchi_initialise+0x24/0x34 >> [<7f1311ec>] 0x7f1311ec >> [<7f1303bc>] 0x7f1303bc >> [<7f130590>] 0x7f130590 >> [<7f111fd8>] snd_pcm_open_substream+0x68/0xc4 [snd_pcm] >> [<7f112108>] snd_pcm_open+0xd4/0x248 [snd_pcm] >> [<7f112334>] snd_pcm_playback_open+0x4c/0x6c [snd_pcm] >> [<7f0e250c>] snd_open+0xa8/0x14c [snd] >> [<802ce590>] chrdev_open+0xac/0x188 >> [<802c57b4>] do_dentry_open+0x10c/0x314 >> [<802c6ba8>] vfs_open+0x5c/0x88 >> [<802d9a68>] path_openat+0x368/0x944 >> [<802dacd4>] do_filp_open+0x70/0xc4 >> [<802c6f70>] do_sys_open+0x110/0x1d4 >> >> >> Signed-off-by: Kirill Marinushkin >> Cc: Eric Anholt >> Cc: Stefan Wahren >> Cc: Greg Kroah-Hartman >> Cc: Florian Fainelli >> Cc: Ray Jui >> Cc: Scott Branden >> Cc: Andy Shevchenko >> Cc: Dan Carpenter >> Cc: bcm-kernel-feedback-l...@broadcom.com >> Cc: linux-rpi-ker...@lists.infradead.org >> Cc: linux-arm-ker...@lists.infradead.org >> Cc: de...@driverdev.osuosl.org >> Cc: linux-kernel@vger.kernel.org >> --- >> .../vc04_services/bcm2835-audio/bcm2835-vchiq.c| 64 >> +- >> .../staging/vc04_services/bcm2835-audio/bcm2835.c | 43 ++- >> .../staging/vc04_services/bcm2835-audio/bcm2835.h | 12 >> 3 files changed, 91 insertions(+), 28 deletions(-) > What changed from v1? Always put that below the --- line as the > documentation says to do so. > > v3? :) > > thanks, > > greg k-h :) Below is the git diff v1..v2 diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c index 009c972d93d6..662e05bd8f05 100644 --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c @@ -165,7 +165,7 @@ static int snd_bcm2835_create(struct snd_card *card, bcm2835_devm_free_vchi_ctx, NULL, NULL); if (!chip->vchi_ctx) { kfree(chip); - return err; + return -ENODEV; } err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, ); Best Regards, Kirill
[PATCH v2] staging: bcm2835-audio: Disconnect and free vchi_instance on module_exit()
In the current implementation, vchi_instance is inited during the first call of bcm2835_audio_open_connection(), and is never freed. It causes a memory leak when the module `snd_bcm2835` is removed. Here is how this commit fixes it: * the VCHI context (including vchi_instance) is created once in the platform's devres * the VCHI context is allocated and connected once during module_init() * all created bcm2835_chips have a pointer to this VCHI context * bcm2835_audio_open_connection() can access the VCHI context through the associated bcm2835_chip * the VCHI context is disconnected and freed once during module_exit() After this commit is applied, I don't see other issues with the module's init/exit, so I also remove the associated TODO task. Steps to reproduce the memory leak before this commit: root@raspberrypi:/home/pi# aplay test0.wav Playing WAVE 'test0.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Ster ^CAborted by signal Interrupt... root@raspberrypi:/home/pi# rmmod snd_bcm2835 root@raspberrypi:/home/pi# modprobe snd_bcm2835 root@raspberrypi:/home/pi# aplay test0.wav Playing WAVE 'test0.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Ster ^CAborted by signal Interrupt... root@raspberrypi:/home/pi# echo scan > /sys/kernel/debug/kmemleak root@raspberrypi:/home/pi# cat /sys/kernel/debug/kmemleak unreferenced object 0xb6794c00 (size 128): comm "aplay", pid 406, jiffies 36870 (age 116.650s) hex dump (first 32 bytes): 08 a5 82 81 01 00 00 00 08 4c 79 b6 08 4c 79 b6 .Ly..Ly. 00 00 00 00 00 00 00 00 ad 4e ad de ff ff ff ff .N.. backtrace: [<802af5e0>] kmem_cache_alloc_trace+0x294/0x3d0 [<806ce620>] vchiq_initialise+0x98/0x1b0 [<806d0b34>] vchi_initialise+0x24/0x34 [<7f1311ec>] 0x7f1311ec [<7f1303bc>] 0x7f1303bc [<7f130590>] 0x7f130590 [<7f111fd8>] snd_pcm_open_substream+0x68/0xc4 [snd_pcm] [<7f112108>] snd_pcm_open+0xd4/0x248 [snd_pcm] [<7f112334>] snd_pcm_playback_open+0x4c/0x6c [snd_pcm] [<7f0e250c>] snd_open+0xa8/0x14c [snd] [<802ce590>] chrdev_open+0xac/0x188 [<802c57b4>] do_dentry_open+0x10c/0x314 [<802c6ba8>] vfs_open+0x5c/0x88 [<802d9a68>] path_openat+0x368/0x944 [<802dacd4>] do_filp_open+0x70/0xc4 [<802c6f70>] do_sys_open+0x110/0x1d4 Signed-off-by: Kirill Marinushkin <k.marinush...@gmail.com> Cc: Eric Anholt <e...@anholt.net> Cc: Stefan Wahren <stefan.wah...@i2se.com> Cc: Greg Kroah-Hartman <gre...@linuxfoundation.org> Cc: Florian Fainelli <f.faine...@gmail.com> Cc: Ray Jui <r...@broadcom.com> Cc: Scott Branden <sbran...@broadcom.com> Cc: Andy Shevchenko <andy.shevche...@gmail.com> Cc: Dan Carpenter <dan.carpen...@oracle.com> Cc: bcm-kernel-feedback-l...@broadcom.com Cc: linux-rpi-ker...@lists.infradead.org Cc: linux-arm-ker...@lists.infradead.org Cc: de...@driverdev.osuosl.org Cc: linux-kernel@vger.kernel.org --- .../vc04_services/bcm2835-audio/bcm2835-vchiq.c| 64 +- .../staging/vc04_services/bcm2835-audio/bcm2835.c | 43 ++- .../staging/vc04_services/bcm2835-audio/bcm2835.h | 12 3 files changed, 91 insertions(+), 28 deletions(-) diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c index 3c6f1d91d22d..389a18f9350a 100644 --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c @@ -33,7 +33,6 @@ /* Include Files */ -#include "interface/vchi/vchi.h" #include "vc_vchi_audioserv_defs.h" /* Private Constants and Types -- */ @@ -371,14 +370,46 @@ static int vc_vchi_audio_deinit(struct bcm2835_audio_instance *instance) return 0; } +int bcm2835_new_vchi_ctx(struct bcm2835_vchi_ctx *vchi_ctx) +{ + int ret; + + /* Initialize and create a VCHI connection */ + ret = vchi_initialise(_ctx->vchi_instance); + if (ret) { + LOG_ERR("%s: failed to initialise VCHI instance (ret=%d)\n", + __func__, ret); + + return -EIO; + } + + ret = vchi_connect(NULL, 0, vchi_ctx->vchi_instance); + if (ret) { + LOG_ERR("%s: failed to connect VCHI instance (ret=%d)\n", + __func__, ret); + + kfree(vchi_ctx->vchi_instance); + vchi_ctx->vchi_instance = NULL; + + return -EIO; + } + + return 0; +} + +void bcm2835_free_vchi_ctx(struct bcm2835_vchi_ctx *vchi_ctx) +{ + /* Close the VCHI connection - it will also free vchi_instance */ + WARN_ON(vchi_disconnect(vchi_ctx->vchi_instan
[PATCH v2] staging: bcm2835-audio: Disconnect and free vchi_instance on module_exit()
In the current implementation, vchi_instance is inited during the first call of bcm2835_audio_open_connection(), and is never freed. It causes a memory leak when the module `snd_bcm2835` is removed. Here is how this commit fixes it: * the VCHI context (including vchi_instance) is created once in the platform's devres * the VCHI context is allocated and connected once during module_init() * all created bcm2835_chips have a pointer to this VCHI context * bcm2835_audio_open_connection() can access the VCHI context through the associated bcm2835_chip * the VCHI context is disconnected and freed once during module_exit() After this commit is applied, I don't see other issues with the module's init/exit, so I also remove the associated TODO task. Steps to reproduce the memory leak before this commit: root@raspberrypi:/home/pi# aplay test0.wav Playing WAVE 'test0.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Ster ^CAborted by signal Interrupt... root@raspberrypi:/home/pi# rmmod snd_bcm2835 root@raspberrypi:/home/pi# modprobe snd_bcm2835 root@raspberrypi:/home/pi# aplay test0.wav Playing WAVE 'test0.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Ster ^CAborted by signal Interrupt... root@raspberrypi:/home/pi# echo scan > /sys/kernel/debug/kmemleak root@raspberrypi:/home/pi# cat /sys/kernel/debug/kmemleak unreferenced object 0xb6794c00 (size 128): comm "aplay", pid 406, jiffies 36870 (age 116.650s) hex dump (first 32 bytes): 08 a5 82 81 01 00 00 00 08 4c 79 b6 08 4c 79 b6 .Ly..Ly. 00 00 00 00 00 00 00 00 ad 4e ad de ff ff ff ff .N.. backtrace: [<802af5e0>] kmem_cache_alloc_trace+0x294/0x3d0 [<806ce620>] vchiq_initialise+0x98/0x1b0 [<806d0b34>] vchi_initialise+0x24/0x34 [<7f1311ec>] 0x7f1311ec [<7f1303bc>] 0x7f1303bc [<7f130590>] 0x7f130590 [<7f111fd8>] snd_pcm_open_substream+0x68/0xc4 [snd_pcm] [<7f112108>] snd_pcm_open+0xd4/0x248 [snd_pcm] [<7f112334>] snd_pcm_playback_open+0x4c/0x6c [snd_pcm] [<7f0e250c>] snd_open+0xa8/0x14c [snd] [<802ce590>] chrdev_open+0xac/0x188 [<802c57b4>] do_dentry_open+0x10c/0x314 [<802c6ba8>] vfs_open+0x5c/0x88 [<802d9a68>] path_openat+0x368/0x944 [<802dacd4>] do_filp_open+0x70/0xc4 [<802c6f70>] do_sys_open+0x110/0x1d4 Signed-off-by: Kirill Marinushkin Cc: Eric Anholt Cc: Stefan Wahren Cc: Greg Kroah-Hartman Cc: Florian Fainelli Cc: Ray Jui Cc: Scott Branden Cc: Andy Shevchenko Cc: Dan Carpenter Cc: bcm-kernel-feedback-l...@broadcom.com Cc: linux-rpi-ker...@lists.infradead.org Cc: linux-arm-ker...@lists.infradead.org Cc: de...@driverdev.osuosl.org Cc: linux-kernel@vger.kernel.org --- .../vc04_services/bcm2835-audio/bcm2835-vchiq.c| 64 +- .../staging/vc04_services/bcm2835-audio/bcm2835.c | 43 ++- .../staging/vc04_services/bcm2835-audio/bcm2835.h | 12 3 files changed, 91 insertions(+), 28 deletions(-) diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c index 3c6f1d91d22d..389a18f9350a 100644 --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c @@ -33,7 +33,6 @@ /* Include Files */ -#include "interface/vchi/vchi.h" #include "vc_vchi_audioserv_defs.h" /* Private Constants and Types -- */ @@ -371,14 +370,46 @@ static int vc_vchi_audio_deinit(struct bcm2835_audio_instance *instance) return 0; } +int bcm2835_new_vchi_ctx(struct bcm2835_vchi_ctx *vchi_ctx) +{ + int ret; + + /* Initialize and create a VCHI connection */ + ret = vchi_initialise(_ctx->vchi_instance); + if (ret) { + LOG_ERR("%s: failed to initialise VCHI instance (ret=%d)\n", + __func__, ret); + + return -EIO; + } + + ret = vchi_connect(NULL, 0, vchi_ctx->vchi_instance); + if (ret) { + LOG_ERR("%s: failed to connect VCHI instance (ret=%d)\n", + __func__, ret); + + kfree(vchi_ctx->vchi_instance); + vchi_ctx->vchi_instance = NULL; + + return -EIO; + } + + return 0; +} + +void bcm2835_free_vchi_ctx(struct bcm2835_vchi_ctx *vchi_ctx) +{ + /* Close the VCHI connection - it will also free vchi_instance */ + WARN_ON(vchi_disconnect(vchi_ctx->vchi_instance)); + + vchi_ctx->vchi_instance = NULL; +} + static int bcm2835_audio_open_connection(struct bcm2835_alsa_stream *alsa_stream) { - static VCHI_INSTANCE_T vchi_instance; - static VCHI_CONNECTION_T *vchi_connection; - static
Re: [RESEND PATCH] staging: bcm2835-audio: Disconnect and free vchi_instance on module_exit()
On 04/24/18 20:35, Andy Shevchenko wrote: > On Tue, Apr 24, 2018 at 9:27 PM, Kirill Marinushkin > <k.marinush...@gmail.com> wrote: > >> @Andy >> >>> AFAIR I gave you a tag and you again missed it. >>> Before sending anything just check twice if all prerequisites are fulfilled. >> I think you mix it up. This is a new patch, you didn't review it before. > Ah, okay, send new version as a separate thread and if I have time I > would review it. > Thank you! But it will be in the same thread. From my understanding, keeping the thread when sending new versions of a patch helps to keep tracking of the conversation
Re: [RESEND PATCH] staging: bcm2835-audio: Disconnect and free vchi_instance on module_exit()
On 04/24/18 20:35, Andy Shevchenko wrote: > On Tue, Apr 24, 2018 at 9:27 PM, Kirill Marinushkin > wrote: > >> @Andy >> >>> AFAIR I gave you a tag and you again missed it. >>> Before sending anything just check twice if all prerequisites are fulfilled. >> I think you mix it up. This is a new patch, you didn't review it before. > Ah, okay, send new version as a separate thread and if I have time I > would review it. > Thank you! But it will be in the same thread. From my understanding, keeping the thread when sending new versions of a patch helps to keep tracking of the conversation
Re: [RESEND PATCH] staging: bcm2835-audio: Disconnect and free vchi_instance on module_exit()
@Greg > I have no idea as the patch is long gone from my queue now. If you > think all is fine, please resend it and I will be glad to review it > again. Stefan, Dan and Andy explained me, what caused the compiler warning in my patch, and why I couldn't reproduce it. I will fix the root cause, and send the patch v2. @Stefan > this is an old toolchain. You can download newer ones here (even for i686): > https://releases.linaro.org/components/toolchain/binaries/7.2-2017.11/arm-linux-gnueabihf/ Thank you for the hint. Looks like I will be able to catch this compiler warning with the newer toolchain. @Dan > kbuild is complaining that "err" is uninitialized here but for some > reason the line numbers are off. It's a real bug. Thank you for the review. Yes, indeed, this is not correct. I will fix it. @Andy > AFAIR I gave you a tag and you again missed it. > Before sending anything just check twice if all prerequisites are fulfilled. I think you mix it up. This is a new patch, you didn't review it before. > And yes, kbuild bot is right. You need to return known value. Yes, that's right. I will fix it. Best Regards, Kirill On 04/24/18 09:44, Kirill Marinushkin wrote: > In the current implementation, vchi_instance is inited during the first > call of bcm2835_audio_open_connection(), and is never freed. It causes a > memory leak when the module `snd_bcm2835` is removed. > > Here is how this commit fixes it: > > * the VCHI context (including vchi_instance) is created once in the > platform's devres > * the VCHI context is allocated and connected once during module_init() > * all created bcm2835_chips have a pointer to this VCHI context > * bcm2835_audio_open_connection() can access the VCHI context through the > associated bcm2835_chip > * the VCHI context is disconnected and freed once during module_exit() > > After this commit is applied, I don't see other issues with the module's > init/exit, so I also remove the associated TODO task. > > Steps to reproduce the memory leak before this commit: > > > root@raspberrypi:/home/pi# aplay test0.wav > Playing WAVE 'test0.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Ster > ^CAborted by signal Interrupt... > root@raspberrypi:/home/pi# rmmod snd_bcm2835 > root@raspberrypi:/home/pi# modprobe snd_bcm2835 > root@raspberrypi:/home/pi# aplay test0.wav > Playing WAVE 'test0.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Ster > ^CAborted by signal Interrupt... > root@raspberrypi:/home/pi# echo scan > /sys/kernel/debug/kmemleak > root@raspberrypi:/home/pi# cat /sys/kernel/debug/kmemleak > unreferenced object 0xb6794c00 (size 128): > comm "aplay", pid 406, jiffies 36870 (age 116.650s) > hex dump (first 32 bytes): > 08 a5 82 81 01 00 00 00 08 4c 79 b6 08 4c 79 b6 .Ly..Ly. > 00 00 00 00 00 00 00 00 ad 4e ad de ff ff ff ff .N.. > backtrace: > [<802af5e0>] kmem_cache_alloc_trace+0x294/0x3d0 > [<806ce620>] vchiq_initialise+0x98/0x1b0 > [<806d0b34>] vchi_initialise+0x24/0x34 > [<7f1311ec>] 0x7f1311ec > [<7f1303bc>] 0x7f1303bc > [<7f130590>] 0x7f130590 > [<7f111fd8>] snd_pcm_open_substream+0x68/0xc4 [snd_pcm] > [<7f112108>] snd_pcm_open+0xd4/0x248 [snd_pcm] > [<7f112334>] snd_pcm_playback_open+0x4c/0x6c [snd_pcm] > [<7f0e250c>] snd_open+0xa8/0x14c [snd] > [<802ce590>] chrdev_open+0xac/0x188 > [<802c57b4>] do_dentry_open+0x10c/0x314 > [<802c6ba8>] vfs_open+0x5c/0x88 > [<802d9a68>] path_openat+0x368/0x944 > [<802dacd4>] do_filp_open+0x70/0xc4 > [<802c6f70>] do_sys_open+0x110/0x1d4 > > > Signed-off-by: Kirill Marinushkin <k.marinush...@gmail.com> > Cc: Eric Anholt <e...@anholt.net> > Cc: Stefan Wahren <stefan.wah...@i2se.com> > Cc: Greg Kroah-Hartman <gre...@linuxfoundation.org> > Cc: Florian Fainelli <f.faine...@gmail.com> > Cc: Ray Jui <r...@broadcom.com> > Cc: Scott Branden <sbran...@broadcom.com> > Cc: Andy Shevchenko <andy.shevche...@gmail.com> > Cc: bcm-kernel-feedback-l...@broadcom.com > Cc: linux-rpi-ker...@lists.infradead.org > Cc: linux-arm-ker...@lists.infradead.org > Cc: de...@driverdev.osuosl.org > Cc: linux-kernel@vger.kernel.org > --- > .../vc04_services/bcm2835-audio/bcm2835-vchiq.c| 64 > +- > .../staging/vc04_services/bcm2835-audio/bcm2835.c | 43 ++- > .../staging/vc04_services/bcm2835-audio/bcm2835.h | 12 > 3 files changed, 91 insertions(+), 28 deletions(-) > > diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c > b/drivers/staging/vc04_servi
Re: [RESEND PATCH] staging: bcm2835-audio: Disconnect and free vchi_instance on module_exit()
@Greg > I have no idea as the patch is long gone from my queue now. If you > think all is fine, please resend it and I will be glad to review it > again. Stefan, Dan and Andy explained me, what caused the compiler warning in my patch, and why I couldn't reproduce it. I will fix the root cause, and send the patch v2. @Stefan > this is an old toolchain. You can download newer ones here (even for i686): > https://releases.linaro.org/components/toolchain/binaries/7.2-2017.11/arm-linux-gnueabihf/ Thank you for the hint. Looks like I will be able to catch this compiler warning with the newer toolchain. @Dan > kbuild is complaining that "err" is uninitialized here but for some > reason the line numbers are off. It's a real bug. Thank you for the review. Yes, indeed, this is not correct. I will fix it. @Andy > AFAIR I gave you a tag and you again missed it. > Before sending anything just check twice if all prerequisites are fulfilled. I think you mix it up. This is a new patch, you didn't review it before. > And yes, kbuild bot is right. You need to return known value. Yes, that's right. I will fix it. Best Regards, Kirill On 04/24/18 09:44, Kirill Marinushkin wrote: > In the current implementation, vchi_instance is inited during the first > call of bcm2835_audio_open_connection(), and is never freed. It causes a > memory leak when the module `snd_bcm2835` is removed. > > Here is how this commit fixes it: > > * the VCHI context (including vchi_instance) is created once in the > platform's devres > * the VCHI context is allocated and connected once during module_init() > * all created bcm2835_chips have a pointer to this VCHI context > * bcm2835_audio_open_connection() can access the VCHI context through the > associated bcm2835_chip > * the VCHI context is disconnected and freed once during module_exit() > > After this commit is applied, I don't see other issues with the module's > init/exit, so I also remove the associated TODO task. > > Steps to reproduce the memory leak before this commit: > > > root@raspberrypi:/home/pi# aplay test0.wav > Playing WAVE 'test0.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Ster > ^CAborted by signal Interrupt... > root@raspberrypi:/home/pi# rmmod snd_bcm2835 > root@raspberrypi:/home/pi# modprobe snd_bcm2835 > root@raspberrypi:/home/pi# aplay test0.wav > Playing WAVE 'test0.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Ster > ^CAborted by signal Interrupt... > root@raspberrypi:/home/pi# echo scan > /sys/kernel/debug/kmemleak > root@raspberrypi:/home/pi# cat /sys/kernel/debug/kmemleak > unreferenced object 0xb6794c00 (size 128): > comm "aplay", pid 406, jiffies 36870 (age 116.650s) > hex dump (first 32 bytes): > 08 a5 82 81 01 00 00 00 08 4c 79 b6 08 4c 79 b6 .Ly..Ly. > 00 00 00 00 00 00 00 00 ad 4e ad de ff ff ff ff .N.. > backtrace: > [<802af5e0>] kmem_cache_alloc_trace+0x294/0x3d0 > [<806ce620>] vchiq_initialise+0x98/0x1b0 > [<806d0b34>] vchi_initialise+0x24/0x34 > [<7f1311ec>] 0x7f1311ec > [<7f1303bc>] 0x7f1303bc > [<7f130590>] 0x7f130590 > [<7f111fd8>] snd_pcm_open_substream+0x68/0xc4 [snd_pcm] > [<7f112108>] snd_pcm_open+0xd4/0x248 [snd_pcm] > [<7f112334>] snd_pcm_playback_open+0x4c/0x6c [snd_pcm] > [<7f0e250c>] snd_open+0xa8/0x14c [snd] > [<802ce590>] chrdev_open+0xac/0x188 > [<802c57b4>] do_dentry_open+0x10c/0x314 > [<802c6ba8>] vfs_open+0x5c/0x88 > [<802d9a68>] path_openat+0x368/0x944 > [<802dacd4>] do_filp_open+0x70/0xc4 > [<802c6f70>] do_sys_open+0x110/0x1d4 > > > Signed-off-by: Kirill Marinushkin > Cc: Eric Anholt > Cc: Stefan Wahren > Cc: Greg Kroah-Hartman > Cc: Florian Fainelli > Cc: Ray Jui > Cc: Scott Branden > Cc: Andy Shevchenko > Cc: bcm-kernel-feedback-l...@broadcom.com > Cc: linux-rpi-ker...@lists.infradead.org > Cc: linux-arm-ker...@lists.infradead.org > Cc: de...@driverdev.osuosl.org > Cc: linux-kernel@vger.kernel.org > --- > .../vc04_services/bcm2835-audio/bcm2835-vchiq.c| 64 > +- > .../staging/vc04_services/bcm2835-audio/bcm2835.c | 43 ++- > .../staging/vc04_services/bcm2835-audio/bcm2835.h | 12 > 3 files changed, 91 insertions(+), 28 deletions(-) > > diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c > b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c > index 3c6f1d91d22d..389a18f9350a 100644 > --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c > +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c > @@ -33,7
[RESEND PATCH] staging: bcm2835-audio: Disconnect and free vchi_instance on module_exit()
In the current implementation, vchi_instance is inited during the first call of bcm2835_audio_open_connection(), and is never freed. It causes a memory leak when the module `snd_bcm2835` is removed. Here is how this commit fixes it: * the VCHI context (including vchi_instance) is created once in the platform's devres * the VCHI context is allocated and connected once during module_init() * all created bcm2835_chips have a pointer to this VCHI context * bcm2835_audio_open_connection() can access the VCHI context through the associated bcm2835_chip * the VCHI context is disconnected and freed once during module_exit() After this commit is applied, I don't see other issues with the module's init/exit, so I also remove the associated TODO task. Steps to reproduce the memory leak before this commit: root@raspberrypi:/home/pi# aplay test0.wav Playing WAVE 'test0.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Ster ^CAborted by signal Interrupt... root@raspberrypi:/home/pi# rmmod snd_bcm2835 root@raspberrypi:/home/pi# modprobe snd_bcm2835 root@raspberrypi:/home/pi# aplay test0.wav Playing WAVE 'test0.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Ster ^CAborted by signal Interrupt... root@raspberrypi:/home/pi# echo scan > /sys/kernel/debug/kmemleak root@raspberrypi:/home/pi# cat /sys/kernel/debug/kmemleak unreferenced object 0xb6794c00 (size 128): comm "aplay", pid 406, jiffies 36870 (age 116.650s) hex dump (first 32 bytes): 08 a5 82 81 01 00 00 00 08 4c 79 b6 08 4c 79 b6 .Ly..Ly. 00 00 00 00 00 00 00 00 ad 4e ad de ff ff ff ff .N.. backtrace: [<802af5e0>] kmem_cache_alloc_trace+0x294/0x3d0 [<806ce620>] vchiq_initialise+0x98/0x1b0 [<806d0b34>] vchi_initialise+0x24/0x34 [<7f1311ec>] 0x7f1311ec [<7f1303bc>] 0x7f1303bc [<7f130590>] 0x7f130590 [<7f111fd8>] snd_pcm_open_substream+0x68/0xc4 [snd_pcm] [<7f112108>] snd_pcm_open+0xd4/0x248 [snd_pcm] [<7f112334>] snd_pcm_playback_open+0x4c/0x6c [snd_pcm] [<7f0e250c>] snd_open+0xa8/0x14c [snd] [<802ce590>] chrdev_open+0xac/0x188 [<802c57b4>] do_dentry_open+0x10c/0x314 [<802c6ba8>] vfs_open+0x5c/0x88 [<802d9a68>] path_openat+0x368/0x944 [<802dacd4>] do_filp_open+0x70/0xc4 [<802c6f70>] do_sys_open+0x110/0x1d4 Signed-off-by: Kirill Marinushkin <k.marinush...@gmail.com> Cc: Eric Anholt <e...@anholt.net> Cc: Stefan Wahren <stefan.wah...@i2se.com> Cc: Greg Kroah-Hartman <gre...@linuxfoundation.org> Cc: Florian Fainelli <f.faine...@gmail.com> Cc: Ray Jui <r...@broadcom.com> Cc: Scott Branden <sbran...@broadcom.com> Cc: Andy Shevchenko <andy.shevche...@gmail.com> Cc: bcm-kernel-feedback-l...@broadcom.com Cc: linux-rpi-ker...@lists.infradead.org Cc: linux-arm-ker...@lists.infradead.org Cc: de...@driverdev.osuosl.org Cc: linux-kernel@vger.kernel.org --- .../vc04_services/bcm2835-audio/bcm2835-vchiq.c| 64 +- .../staging/vc04_services/bcm2835-audio/bcm2835.c | 43 ++- .../staging/vc04_services/bcm2835-audio/bcm2835.h | 12 3 files changed, 91 insertions(+), 28 deletions(-) diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c index 3c6f1d91d22d..389a18f9350a 100644 --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c @@ -33,7 +33,6 @@ /* Include Files */ -#include "interface/vchi/vchi.h" #include "vc_vchi_audioserv_defs.h" /* Private Constants and Types -- */ @@ -371,14 +370,46 @@ static int vc_vchi_audio_deinit(struct bcm2835_audio_instance *instance) return 0; } +int bcm2835_new_vchi_ctx(struct bcm2835_vchi_ctx *vchi_ctx) +{ + int ret; + + /* Initialize and create a VCHI connection */ + ret = vchi_initialise(_ctx->vchi_instance); + if (ret) { + LOG_ERR("%s: failed to initialise VCHI instance (ret=%d)\n", + __func__, ret); + + return -EIO; + } + + ret = vchi_connect(NULL, 0, vchi_ctx->vchi_instance); + if (ret) { + LOG_ERR("%s: failed to connect VCHI instance (ret=%d)\n", + __func__, ret); + + kfree(vchi_ctx->vchi_instance); + vchi_ctx->vchi_instance = NULL; + + return -EIO; + } + + return 0; +} + +void bcm2835_free_vchi_ctx(struct bcm2835_vchi_ctx *vchi_ctx) +{ + /* Close the VCHI connection - it will also free vchi_instance */ + WARN_ON(vchi_disconnect(vchi_ctx->vchi_instance)); + + vchi_ctx->vchi_instance = NULL;
[RESEND PATCH] staging: bcm2835-audio: Disconnect and free vchi_instance on module_exit()
In the current implementation, vchi_instance is inited during the first call of bcm2835_audio_open_connection(), and is never freed. It causes a memory leak when the module `snd_bcm2835` is removed. Here is how this commit fixes it: * the VCHI context (including vchi_instance) is created once in the platform's devres * the VCHI context is allocated and connected once during module_init() * all created bcm2835_chips have a pointer to this VCHI context * bcm2835_audio_open_connection() can access the VCHI context through the associated bcm2835_chip * the VCHI context is disconnected and freed once during module_exit() After this commit is applied, I don't see other issues with the module's init/exit, so I also remove the associated TODO task. Steps to reproduce the memory leak before this commit: root@raspberrypi:/home/pi# aplay test0.wav Playing WAVE 'test0.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Ster ^CAborted by signal Interrupt... root@raspberrypi:/home/pi# rmmod snd_bcm2835 root@raspberrypi:/home/pi# modprobe snd_bcm2835 root@raspberrypi:/home/pi# aplay test0.wav Playing WAVE 'test0.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Ster ^CAborted by signal Interrupt... root@raspberrypi:/home/pi# echo scan > /sys/kernel/debug/kmemleak root@raspberrypi:/home/pi# cat /sys/kernel/debug/kmemleak unreferenced object 0xb6794c00 (size 128): comm "aplay", pid 406, jiffies 36870 (age 116.650s) hex dump (first 32 bytes): 08 a5 82 81 01 00 00 00 08 4c 79 b6 08 4c 79 b6 .Ly..Ly. 00 00 00 00 00 00 00 00 ad 4e ad de ff ff ff ff .N.. backtrace: [<802af5e0>] kmem_cache_alloc_trace+0x294/0x3d0 [<806ce620>] vchiq_initialise+0x98/0x1b0 [<806d0b34>] vchi_initialise+0x24/0x34 [<7f1311ec>] 0x7f1311ec [<7f1303bc>] 0x7f1303bc [<7f130590>] 0x7f130590 [<7f111fd8>] snd_pcm_open_substream+0x68/0xc4 [snd_pcm] [<7f112108>] snd_pcm_open+0xd4/0x248 [snd_pcm] [<7f112334>] snd_pcm_playback_open+0x4c/0x6c [snd_pcm] [<7f0e250c>] snd_open+0xa8/0x14c [snd] [<802ce590>] chrdev_open+0xac/0x188 [<802c57b4>] do_dentry_open+0x10c/0x314 [<802c6ba8>] vfs_open+0x5c/0x88 [<802d9a68>] path_openat+0x368/0x944 [<802dacd4>] do_filp_open+0x70/0xc4 [<802c6f70>] do_sys_open+0x110/0x1d4 Signed-off-by: Kirill Marinushkin Cc: Eric Anholt Cc: Stefan Wahren Cc: Greg Kroah-Hartman Cc: Florian Fainelli Cc: Ray Jui Cc: Scott Branden Cc: Andy Shevchenko Cc: bcm-kernel-feedback-l...@broadcom.com Cc: linux-rpi-ker...@lists.infradead.org Cc: linux-arm-ker...@lists.infradead.org Cc: de...@driverdev.osuosl.org Cc: linux-kernel@vger.kernel.org --- .../vc04_services/bcm2835-audio/bcm2835-vchiq.c| 64 +- .../staging/vc04_services/bcm2835-audio/bcm2835.c | 43 ++- .../staging/vc04_services/bcm2835-audio/bcm2835.h | 12 3 files changed, 91 insertions(+), 28 deletions(-) diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c index 3c6f1d91d22d..389a18f9350a 100644 --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c @@ -33,7 +33,6 @@ /* Include Files */ -#include "interface/vchi/vchi.h" #include "vc_vchi_audioserv_defs.h" /* Private Constants and Types -- */ @@ -371,14 +370,46 @@ static int vc_vchi_audio_deinit(struct bcm2835_audio_instance *instance) return 0; } +int bcm2835_new_vchi_ctx(struct bcm2835_vchi_ctx *vchi_ctx) +{ + int ret; + + /* Initialize and create a VCHI connection */ + ret = vchi_initialise(_ctx->vchi_instance); + if (ret) { + LOG_ERR("%s: failed to initialise VCHI instance (ret=%d)\n", + __func__, ret); + + return -EIO; + } + + ret = vchi_connect(NULL, 0, vchi_ctx->vchi_instance); + if (ret) { + LOG_ERR("%s: failed to connect VCHI instance (ret=%d)\n", + __func__, ret); + + kfree(vchi_ctx->vchi_instance); + vchi_ctx->vchi_instance = NULL; + + return -EIO; + } + + return 0; +} + +void bcm2835_free_vchi_ctx(struct bcm2835_vchi_ctx *vchi_ctx) +{ + /* Close the VCHI connection - it will also free vchi_instance */ + WARN_ON(vchi_disconnect(vchi_ctx->vchi_instance)); + + vchi_ctx->vchi_instance = NULL; +} + static int bcm2835_audio_open_connection(struct bcm2835_alsa_stream *alsa_stream) { - static VCHI_INSTANCE_T vchi_instance; - static VCHI_CONNECTION_T *vchi_connection; - static int initted; struc
Re: [PATCH] staging: bcm2835-audio: Disconnect and free vchi_instance on module_exit()
On 04/23/18 15:50, Greg Kroah-Hartman wrote: > On Tue, Apr 17, 2018 at 07:00:28AM +0200, Kirill Marinushkin wrote: >> In the current implementation, vchi_instance is inited during the first >> call of bcm2835_audio_open_connection(), and is never freed. It causes a >> memory leak when the module `snd_bcm2835` is removed. >> >> Here is how this commit fixes it: >> >> * the VCHI context (including vchi_instance) is created once in the >> platform's devres >> * the VCHI context is allocated and connected once during module_init() >> * all created bcm2835_chips have a pointer to this VCHI context >> * bcm2835_audio_open_connection() can access the VCHI context through the >> associated bcm2835_chip >> * the VCHI context is disconnected and freed once during module_exit() >> >> After this commit is applied, I don't see other issues with the module's >> init/exit, so I also remove the associated TODO task. >> >> Steps to reproduce the memory leak before this commit: > > > Patch dropped due to kbuild complaints. > > Please fix up and resend. > > thanks, > > greg k-h Hello Greg, Due to which complains of kbuild is the patch dropped? I would like to fix the complains, but I don't see any errors or warnings on my side. Are you sure that the kbuild test robot did it's job correctly? The log says: >> it may well be a FALSE warning Please show me what is wrong in my patch. The log from kbuild test robot says: >> [auto build test WARNING on staging/staging-testing] >> [also build test WARNING on v4.17-rc1] >> [cannot apply to anholt/for-next] >> [if your patch is applied to the wrong git tree, please drop us a note to help improve the system] >> >> url: https://github.com/0day-ci/linux/commits/Kirill-Marinushkin/staging-bcm2835-audio-Disconnect-and-free-vchi_instance-on-module_exit/20180417-193147 >> config: arm-allmodconfig >> compiler: arm-linux-gnueabi-gcc (Debian 7.2.0-11) 7.2.0 >> reproduce: >> wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross >> chmod +x ~/bin/make.cross >> make.cross ARCH=arm allmodconfig >> make.cross ARCH=arm >> >> Note: it may well be a FALSE warning. FWIW you are at least aware of it now. >> http://gcc.gnu.org/wiki/Better_Uninitialized_Warnings I cannot clone from the given url, because it does not exist. I cannot use the compiler from the log, because it is built for x86_64, and my host machine is i686. Below are the steps how I tried to reproduce the issue, but errors or warnings didn't happen. I applied the patch on top of the following upstream tag: 60cc43fc8884 (tag: v4.17-rc1) Linux 4.17-rc1 And executed: make CROSS_COMPILE=arm-linux-gnueabihf- --jobs=4 ARCH=arm allmodconfig make CROSS_COMPILE=arm-linux-gnueabihf- --jobs=4 ARCH=arm But the compilation succeed without any errors or warnings. My compiler version is: arm-linux-gnueabihf-gcc (crosstool-NG linaro-1.13.1-4.8-2014.01 - Linaro GCC 2013.11) 4.8.3 20140106 (prerelease) Best Regards, Kirill
Re: [PATCH] staging: bcm2835-audio: Disconnect and free vchi_instance on module_exit()
On 04/23/18 15:50, Greg Kroah-Hartman wrote: > On Tue, Apr 17, 2018 at 07:00:28AM +0200, Kirill Marinushkin wrote: >> In the current implementation, vchi_instance is inited during the first >> call of bcm2835_audio_open_connection(), and is never freed. It causes a >> memory leak when the module `snd_bcm2835` is removed. >> >> Here is how this commit fixes it: >> >> * the VCHI context (including vchi_instance) is created once in the >> platform's devres >> * the VCHI context is allocated and connected once during module_init() >> * all created bcm2835_chips have a pointer to this VCHI context >> * bcm2835_audio_open_connection() can access the VCHI context through the >> associated bcm2835_chip >> * the VCHI context is disconnected and freed once during module_exit() >> >> After this commit is applied, I don't see other issues with the module's >> init/exit, so I also remove the associated TODO task. >> >> Steps to reproduce the memory leak before this commit: > > > Patch dropped due to kbuild complaints. > > Please fix up and resend. > > thanks, > > greg k-h Hello Greg, Due to which complains of kbuild is the patch dropped? I would like to fix the complains, but I don't see any errors or warnings on my side. Are you sure that the kbuild test robot did it's job correctly? The log says: >> it may well be a FALSE warning Please show me what is wrong in my patch. The log from kbuild test robot says: >> [auto build test WARNING on staging/staging-testing] >> [also build test WARNING on v4.17-rc1] >> [cannot apply to anholt/for-next] >> [if your patch is applied to the wrong git tree, please drop us a note to help improve the system] >> >> url: https://github.com/0day-ci/linux/commits/Kirill-Marinushkin/staging-bcm2835-audio-Disconnect-and-free-vchi_instance-on-module_exit/20180417-193147 >> config: arm-allmodconfig >> compiler: arm-linux-gnueabi-gcc (Debian 7.2.0-11) 7.2.0 >> reproduce: >> wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross >> chmod +x ~/bin/make.cross >> make.cross ARCH=arm allmodconfig >> make.cross ARCH=arm >> >> Note: it may well be a FALSE warning. FWIW you are at least aware of it now. >> http://gcc.gnu.org/wiki/Better_Uninitialized_Warnings I cannot clone from the given url, because it does not exist. I cannot use the compiler from the log, because it is built for x86_64, and my host machine is i686. Below are the steps how I tried to reproduce the issue, but errors or warnings didn't happen. I applied the patch on top of the following upstream tag: 60cc43fc8884 (tag: v4.17-rc1) Linux 4.17-rc1 And executed: make CROSS_COMPILE=arm-linux-gnueabihf- --jobs=4 ARCH=arm allmodconfig make CROSS_COMPILE=arm-linux-gnueabihf- --jobs=4 ARCH=arm But the compilation succeed without any errors or warnings. My compiler version is: arm-linux-gnueabihf-gcc (crosstool-NG linaro-1.13.1-4.8-2014.01 - Linaro GCC 2013.11) 4.8.3 20140106 (prerelease) Best Regards, Kirill
[PATCH] staging: bcm2835-audio: Disconnect and free vchi_instance on module_exit()
In the current implementation, vchi_instance is inited during the first call of bcm2835_audio_open_connection(), and is never freed. It causes a memory leak when the module `snd_bcm2835` is removed. Here is how this commit fixes it: * the VCHI context (including vchi_instance) is created once in the platform's devres * the VCHI context is allocated and connected once during module_init() * all created bcm2835_chips have a pointer to this VCHI context * bcm2835_audio_open_connection() can access the VCHI context through the associated bcm2835_chip * the VCHI context is disconnected and freed once during module_exit() After this commit is applied, I don't see other issues with the module's init/exit, so I also remove the associated TODO task. Steps to reproduce the memory leak before this commit: root@raspberrypi:/home/pi# aplay test0.wav Playing WAVE 'test0.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Ster ^CAborted by signal Interrupt... root@raspberrypi:/home/pi# rmmod snd_bcm2835 root@raspberrypi:/home/pi# modprobe snd_bcm2835 root@raspberrypi:/home/pi# aplay test0.wav Playing WAVE 'test0.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Ster ^CAborted by signal Interrupt... root@raspberrypi:/home/pi# echo scan > /sys/kernel/debug/kmemleak root@raspberrypi:/home/pi# cat /sys/kernel/debug/kmemleak unreferenced object 0xb6794c00 (size 128): comm "aplay", pid 406, jiffies 36870 (age 116.650s) hex dump (first 32 bytes): 08 a5 82 81 01 00 00 00 08 4c 79 b6 08 4c 79 b6 .Ly..Ly. 00 00 00 00 00 00 00 00 ad 4e ad de ff ff ff ff .N.. backtrace: [<802af5e0>] kmem_cache_alloc_trace+0x294/0x3d0 [<806ce620>] vchiq_initialise+0x98/0x1b0 [<806d0b34>] vchi_initialise+0x24/0x34 [<7f1311ec>] 0x7f1311ec [<7f1303bc>] 0x7f1303bc [<7f130590>] 0x7f130590 [<7f111fd8>] snd_pcm_open_substream+0x68/0xc4 [snd_pcm] [<7f112108>] snd_pcm_open+0xd4/0x248 [snd_pcm] [<7f112334>] snd_pcm_playback_open+0x4c/0x6c [snd_pcm] [<7f0e250c>] snd_open+0xa8/0x14c [snd] [<802ce590>] chrdev_open+0xac/0x188 [<802c57b4>] do_dentry_open+0x10c/0x314 [<802c6ba8>] vfs_open+0x5c/0x88 [<802d9a68>] path_openat+0x368/0x944 [<802dacd4>] do_filp_open+0x70/0xc4 [<802c6f70>] do_sys_open+0x110/0x1d4 Signed-off-by: Kirill Marinushkin <k.marinush...@gmail.com> Cc: Eric Anholt <e...@anholt.net> Cc: Stefan Wahren <stefan.wah...@i2se.com> Cc: Greg Kroah-Hartman <gre...@linuxfoundation.org> Cc: Florian Fainelli <f.faine...@gmail.com> Cc: Ray Jui <r...@broadcom.com> Cc: Scott Branden <sbran...@broadcom.com> Cc: Andy Shevchenko <andy.shevche...@gmail.com> Cc: bcm-kernel-feedback-l...@broadcom.com Cc: linux-rpi-ker...@lists.infradead.org Cc: linux-arm-ker...@lists.infradead.org Cc: de...@driverdev.osuosl.org Cc: linux-kernel@vger.kernel.org --- .../vc04_services/bcm2835-audio/bcm2835-vchiq.c| 64 +- .../staging/vc04_services/bcm2835-audio/bcm2835.c | 43 ++- .../staging/vc04_services/bcm2835-audio/bcm2835.h | 12 3 files changed, 91 insertions(+), 28 deletions(-) diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c index 3c6f1d91d22d..389a18f9350a 100644 --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c @@ -33,7 +33,6 @@ /* Include Files */ -#include "interface/vchi/vchi.h" #include "vc_vchi_audioserv_defs.h" /* Private Constants and Types -- */ @@ -371,14 +370,46 @@ static int vc_vchi_audio_deinit(struct bcm2835_audio_instance *instance) return 0; } +int bcm2835_new_vchi_ctx(struct bcm2835_vchi_ctx *vchi_ctx) +{ + int ret; + + /* Initialize and create a VCHI connection */ + ret = vchi_initialise(_ctx->vchi_instance); + if (ret) { + LOG_ERR("%s: failed to initialise VCHI instance (ret=%d)\n", + __func__, ret); + + return -EIO; + } + + ret = vchi_connect(NULL, 0, vchi_ctx->vchi_instance); + if (ret) { + LOG_ERR("%s: failed to connect VCHI instance (ret=%d)\n", + __func__, ret); + + kfree(vchi_ctx->vchi_instance); + vchi_ctx->vchi_instance = NULL; + + return -EIO; + } + + return 0; +} + +void bcm2835_free_vchi_ctx(struct bcm2835_vchi_ctx *vchi_ctx) +{ + /* Close the VCHI connection - it will also free vchi_instance */ + WARN_ON(vchi_disconnect(vchi_ctx->vchi_instance)); + + vchi_ctx->vchi_instance = NULL;
[PATCH] staging: bcm2835-audio: Disconnect and free vchi_instance on module_exit()
In the current implementation, vchi_instance is inited during the first call of bcm2835_audio_open_connection(), and is never freed. It causes a memory leak when the module `snd_bcm2835` is removed. Here is how this commit fixes it: * the VCHI context (including vchi_instance) is created once in the platform's devres * the VCHI context is allocated and connected once during module_init() * all created bcm2835_chips have a pointer to this VCHI context * bcm2835_audio_open_connection() can access the VCHI context through the associated bcm2835_chip * the VCHI context is disconnected and freed once during module_exit() After this commit is applied, I don't see other issues with the module's init/exit, so I also remove the associated TODO task. Steps to reproduce the memory leak before this commit: root@raspberrypi:/home/pi# aplay test0.wav Playing WAVE 'test0.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Ster ^CAborted by signal Interrupt... root@raspberrypi:/home/pi# rmmod snd_bcm2835 root@raspberrypi:/home/pi# modprobe snd_bcm2835 root@raspberrypi:/home/pi# aplay test0.wav Playing WAVE 'test0.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Ster ^CAborted by signal Interrupt... root@raspberrypi:/home/pi# echo scan > /sys/kernel/debug/kmemleak root@raspberrypi:/home/pi# cat /sys/kernel/debug/kmemleak unreferenced object 0xb6794c00 (size 128): comm "aplay", pid 406, jiffies 36870 (age 116.650s) hex dump (first 32 bytes): 08 a5 82 81 01 00 00 00 08 4c 79 b6 08 4c 79 b6 .Ly..Ly. 00 00 00 00 00 00 00 00 ad 4e ad de ff ff ff ff .N.. backtrace: [<802af5e0>] kmem_cache_alloc_trace+0x294/0x3d0 [<806ce620>] vchiq_initialise+0x98/0x1b0 [<806d0b34>] vchi_initialise+0x24/0x34 [<7f1311ec>] 0x7f1311ec [<7f1303bc>] 0x7f1303bc [<7f130590>] 0x7f130590 [<7f111fd8>] snd_pcm_open_substream+0x68/0xc4 [snd_pcm] [<7f112108>] snd_pcm_open+0xd4/0x248 [snd_pcm] [<7f112334>] snd_pcm_playback_open+0x4c/0x6c [snd_pcm] [<7f0e250c>] snd_open+0xa8/0x14c [snd] [<802ce590>] chrdev_open+0xac/0x188 [<802c57b4>] do_dentry_open+0x10c/0x314 [<802c6ba8>] vfs_open+0x5c/0x88 [<802d9a68>] path_openat+0x368/0x944 [<802dacd4>] do_filp_open+0x70/0xc4 [<802c6f70>] do_sys_open+0x110/0x1d4 Signed-off-by: Kirill Marinushkin Cc: Eric Anholt Cc: Stefan Wahren Cc: Greg Kroah-Hartman Cc: Florian Fainelli Cc: Ray Jui Cc: Scott Branden Cc: Andy Shevchenko Cc: bcm-kernel-feedback-l...@broadcom.com Cc: linux-rpi-ker...@lists.infradead.org Cc: linux-arm-ker...@lists.infradead.org Cc: de...@driverdev.osuosl.org Cc: linux-kernel@vger.kernel.org --- .../vc04_services/bcm2835-audio/bcm2835-vchiq.c| 64 +- .../staging/vc04_services/bcm2835-audio/bcm2835.c | 43 ++- .../staging/vc04_services/bcm2835-audio/bcm2835.h | 12 3 files changed, 91 insertions(+), 28 deletions(-) diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c index 3c6f1d91d22d..389a18f9350a 100644 --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c @@ -33,7 +33,6 @@ /* Include Files */ -#include "interface/vchi/vchi.h" #include "vc_vchi_audioserv_defs.h" /* Private Constants and Types -- */ @@ -371,14 +370,46 @@ static int vc_vchi_audio_deinit(struct bcm2835_audio_instance *instance) return 0; } +int bcm2835_new_vchi_ctx(struct bcm2835_vchi_ctx *vchi_ctx) +{ + int ret; + + /* Initialize and create a VCHI connection */ + ret = vchi_initialise(_ctx->vchi_instance); + if (ret) { + LOG_ERR("%s: failed to initialise VCHI instance (ret=%d)\n", + __func__, ret); + + return -EIO; + } + + ret = vchi_connect(NULL, 0, vchi_ctx->vchi_instance); + if (ret) { + LOG_ERR("%s: failed to connect VCHI instance (ret=%d)\n", + __func__, ret); + + kfree(vchi_ctx->vchi_instance); + vchi_ctx->vchi_instance = NULL; + + return -EIO; + } + + return 0; +} + +void bcm2835_free_vchi_ctx(struct bcm2835_vchi_ctx *vchi_ctx) +{ + /* Close the VCHI connection - it will also free vchi_instance */ + WARN_ON(vchi_disconnect(vchi_ctx->vchi_instance)); + + vchi_ctx->vchi_instance = NULL; +} + static int bcm2835_audio_open_connection(struct bcm2835_alsa_stream *alsa_stream) { - static VCHI_INSTANCE_T vchi_instance; - static VCHI_CONNECTION_T *vchi_connection; - static int initted; struc
[PATCH alsa-lib v4 1/4] ASoC: topology: Fix bclk and fsync inversion in set_link_hw_format()
The values of bclk and fsync are inverted WRT the codec. But the existing solution already works for Broadwell, see the alsa-lib config: `alsa-lib/src/conf/topology/broadwell/broadwell.conf` This commit provides the backwards-compatible solution to fix this misuse. This commit goes in pair with the corresponding patch for linux. Signed-off-by: Kirill Marinushkin <k.marinush...@gmail.com> Reviewed-by: Pierre-Louis Bossart <pierre-louis.boss...@linux.intel.com> Tested-by: Pan Xiuli <xiuli@linux.intel.com> Tested-by: Pierre-Louis Bossart <pierre-louis.boss...@linux.intel.com> Cc: Jaroslav Kysela <pe...@perex.cz> Cc: Takashi Iwai <ti...@suse.de> Cc: Mark Brown <broo...@kernel.org> Cc: Liam Girdwood <liam.r.girdw...@linux.intel.com> Cc: linux-kernel@vger.kernel.org Cc: alsa-de...@alsa-project.org --- include/sound/asoc.h | 16 ++-- include/topology.h | 4 ++-- src/conf/topology/broadwell/broadwell.conf | 4 ++-- src/topology/pcm.c | 30 ++ 4 files changed, 44 insertions(+), 10 deletions(-) diff --git a/include/sound/asoc.h b/include/sound/asoc.h index 0f5d9f9a..89b00703 100644 --- a/include/sound/asoc.h +++ b/include/sound/asoc.h @@ -156,6 +156,18 @@ #define SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_SAMPLEBITS(1 << 2) #define SND_SOC_TPLG_LNK_FLGBIT_VOICE_WAKEUP(1 << 3) +/* DAI topology BCLK parameter + * For the backwards capability, by default codec is bclk master + */ +#define SND_SOC_TPLG_BCLK_CM 0 /* codec is bclk master */ +#define SND_SOC_TPLG_BCLK_CS 1 /* codec is bclk slave */ + +/* DAI topology FSYNC parameter + * For the backwards capability, by default codec is fsync master + */ +#define SND_SOC_TPLG_FSYNC_CM 0 /* codec is fsync master */ +#define SND_SOC_TPLG_FSYNC_CS 1 /* codec is fsync slave */ + /* * Block Header. * This header precedes all object and object arrays below. @@ -311,8 +323,8 @@ struct snd_soc_tplg_hw_config { __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 bclk_master; /* SND_SOC_TPLG_BCLK_ value */ + __u8 fsync_master; /* SND_SOC_TPLG_FSYNC_ value */ __u8 mclk_direction;/* 0 for input, 1 for output */ __le16 reserved;/* for 32bit alignment */ __le32 mclk_rate; /* MCLK or SYSCLK freqency in Hz */ diff --git a/include/topology.h b/include/topology.h index 8779da4d..5d7b46df 100644 --- a/include/topology.h +++ b/include/topology.h @@ -1000,8 +1000,8 @@ struct snd_tplg_hw_config_template { unsigned char clock_gated; /* 1 if clock can be gated to save power */ unsigned char invert_bclk; /* 1 for inverted BCLK, 0 for normal */ unsigned char invert_fsync;/* 1 for inverted frame clock, 0 for normal */ - unsigned char bclk_master; /* 1 for master of BCLK, 0 for slave */ - unsigned char fsync_master;/* 1 for master of FSYNC, 0 for slave */ + unsigned char bclk_master; /* SND_SOC_TPLG_BCLK_ value */ + unsigned char fsync_master;/* SND_SOC_TPLG_FSYNC_ value */ unsigned char mclk_direction; /* 0 for input, 1 for output */ unsigned short reserved;/* for 32bit alignment */ unsigned int mclk_rate; /* MCLK or SYSCLK freqency in Hz */ diff --git a/src/conf/topology/broadwell/broadwell.conf b/src/conf/topology/broadwell/broadwell.conf index b8405d93..09fc4daa 100644 --- a/src/conf/topology/broadwell/broadwell.conf +++ b/src/conf/topology/broadwell/broadwell.conf @@ -393,8 +393,8 @@ SectionGraph."dsp" { SectionHWConfig."CodecHWConfig" { id "1" format "I2S"# physical audio format. - bclk "master" # Platform is master of bit clock - fsync "master" # platform is master of fsync + bclk "codec_slave"# platform is master of bit clock (codec is slave) + fsync "codec_slave"# platform is master of fsync (codec is slave) } SectionLink."Codec" { diff --git a/src/topology/pcm.c b/src/topology/pcm.c index bb47b9af..d0395182 100644 --- a/src/topology/pcm.c +++ b/src/topology/pcm.c @@ -1141,8 +1141,19 @@ int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg, if (snd_config_get_string(n, ) < 0) return -EINVAL; - if (!strcmp(val, "master")) - hw_cfg->bclk_master
[PATCH alsa-lib v4 1/4] ASoC: topology: Fix bclk and fsync inversion in set_link_hw_format()
The values of bclk and fsync are inverted WRT the codec. But the existing solution already works for Broadwell, see the alsa-lib config: `alsa-lib/src/conf/topology/broadwell/broadwell.conf` This commit provides the backwards-compatible solution to fix this misuse. This commit goes in pair with the corresponding patch for linux. Signed-off-by: Kirill Marinushkin Reviewed-by: Pierre-Louis Bossart Tested-by: Pan Xiuli Tested-by: Pierre-Louis Bossart Cc: Jaroslav Kysela Cc: Takashi Iwai Cc: Mark Brown Cc: Liam Girdwood Cc: linux-kernel@vger.kernel.org Cc: alsa-de...@alsa-project.org --- include/sound/asoc.h | 16 ++-- include/topology.h | 4 ++-- src/conf/topology/broadwell/broadwell.conf | 4 ++-- src/topology/pcm.c | 30 ++ 4 files changed, 44 insertions(+), 10 deletions(-) diff --git a/include/sound/asoc.h b/include/sound/asoc.h index 0f5d9f9a..89b00703 100644 --- a/include/sound/asoc.h +++ b/include/sound/asoc.h @@ -156,6 +156,18 @@ #define SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_SAMPLEBITS(1 << 2) #define SND_SOC_TPLG_LNK_FLGBIT_VOICE_WAKEUP(1 << 3) +/* DAI topology BCLK parameter + * For the backwards capability, by default codec is bclk master + */ +#define SND_SOC_TPLG_BCLK_CM 0 /* codec is bclk master */ +#define SND_SOC_TPLG_BCLK_CS 1 /* codec is bclk slave */ + +/* DAI topology FSYNC parameter + * For the backwards capability, by default codec is fsync master + */ +#define SND_SOC_TPLG_FSYNC_CM 0 /* codec is fsync master */ +#define SND_SOC_TPLG_FSYNC_CS 1 /* codec is fsync slave */ + /* * Block Header. * This header precedes all object and object arrays below. @@ -311,8 +323,8 @@ struct snd_soc_tplg_hw_config { __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 bclk_master; /* SND_SOC_TPLG_BCLK_ value */ + __u8 fsync_master; /* SND_SOC_TPLG_FSYNC_ value */ __u8 mclk_direction;/* 0 for input, 1 for output */ __le16 reserved;/* for 32bit alignment */ __le32 mclk_rate; /* MCLK or SYSCLK freqency in Hz */ diff --git a/include/topology.h b/include/topology.h index 8779da4d..5d7b46df 100644 --- a/include/topology.h +++ b/include/topology.h @@ -1000,8 +1000,8 @@ struct snd_tplg_hw_config_template { unsigned char clock_gated; /* 1 if clock can be gated to save power */ unsigned char invert_bclk; /* 1 for inverted BCLK, 0 for normal */ unsigned char invert_fsync;/* 1 for inverted frame clock, 0 for normal */ - unsigned char bclk_master; /* 1 for master of BCLK, 0 for slave */ - unsigned char fsync_master;/* 1 for master of FSYNC, 0 for slave */ + unsigned char bclk_master; /* SND_SOC_TPLG_BCLK_ value */ + unsigned char fsync_master;/* SND_SOC_TPLG_FSYNC_ value */ unsigned char mclk_direction; /* 0 for input, 1 for output */ unsigned short reserved;/* for 32bit alignment */ unsigned int mclk_rate; /* MCLK or SYSCLK freqency in Hz */ diff --git a/src/conf/topology/broadwell/broadwell.conf b/src/conf/topology/broadwell/broadwell.conf index b8405d93..09fc4daa 100644 --- a/src/conf/topology/broadwell/broadwell.conf +++ b/src/conf/topology/broadwell/broadwell.conf @@ -393,8 +393,8 @@ SectionGraph."dsp" { SectionHWConfig."CodecHWConfig" { id "1" format "I2S"# physical audio format. - bclk "master" # Platform is master of bit clock - fsync "master" # platform is master of fsync + bclk "codec_slave"# platform is master of bit clock (codec is slave) + fsync "codec_slave"# platform is master of fsync (codec is slave) } SectionLink."Codec" { diff --git a/src/topology/pcm.c b/src/topology/pcm.c index bb47b9af..d0395182 100644 --- a/src/topology/pcm.c +++ b/src/topology/pcm.c @@ -1141,8 +1141,19 @@ int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg, if (snd_config_get_string(n, ) < 0) return -EINVAL; - if (!strcmp(val, "master")) - hw_cfg->bclk_master = true; + if (!strcmp(val, "master")) { + /* For backwards capability, +* "master" == "codec is slave" +
[PATCH alsa-lib v4 2/4] ASoC: topology: Add missing clock gating parameter when parsing hw_configs
Clock gating parameter is a part of `dai_fmt`. It is supported by `alsa-lib` when creating a topology binary file, but ignored by kernel when loading this topology file. After applying this commit, the clock gating parameter is not ignored any more. This solution is backwards compatible. The existing behaviour is not broken, because by default the parameter value is 0 and is ignored. snd_soc_tplg_hw_config.clock_gated = 0 => no effect snd_soc_tplg_hw_config.clock_gated = 1 => SND_SOC_DAIFMT_GATED snd_soc_tplg_hw_config.clock_gated = 2 => SND_SOC_DAIFMT_CONT For example, the following config, based on alsa-lib/src/conf/topology/broadwell/broadwell.conf, is now supported: SectionHWConfig."CodecHWConfig" { id "1" format "I2S"# physical audio format. pm_gate_clocks "true" # clock can be gated } SectionLink."Codec" { # used for binding to the physical link id "0" hw_configs [ "CodecHWConfig" ] default_hw_conf_id "1" } Signed-off-by: Kirill Marinushkin <k.marinush...@gmail.com> Reviewed-by: Pierre-Louis Bossart <pierre-louis.boss...@linux.intel.com> Cc: Jaroslav Kysela <pe...@perex.cz> Cc: Takashi Iwai <ti...@suse.de> Cc: Mark Brown <broo...@kernel.org> Cc: Pan Xiuli <xiuli@linux.intel.com> Cc: Liam Girdwood <liam.r.girdw...@linux.intel.com> Cc: linux-kernel@vger.kernel.org Cc: alsa-de...@alsa-project.org --- include/sound/asoc.h | 7 ++- include/topology.h | 2 +- src/topology/pcm.c | 6 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/include/sound/asoc.h b/include/sound/asoc.h index 89b00703..297e837c 100644 --- a/include/sound/asoc.h +++ b/include/sound/asoc.h @@ -135,6 +135,11 @@ #define SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_CHANNELS (1 << 1) #define SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_SAMPLEBITS(1 << 2) +/* DAI clock gating */ +#define SND_SOC_TPLG_DAI_CLK_GATE_UNDEFINED0 +#define SND_SOC_TPLG_DAI_CLK_GATE_GATED1 +#define SND_SOC_TPLG_DAI_CLK_GATE_CONT 2 + /* DAI physical PCM data formats. * Add new formats to the end of the list. */ @@ -320,7 +325,7 @@ 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 clock_gated; /* SND_SOC_TPLG_DAI_CLK_GATE_ value */ __u8 invert_bclk; /* 1 for inverted BCLK, 0 for normal */ __u8 invert_fsync; /* 1 for inverted frame clock, 0 for normal */ __u8 bclk_master; /* SND_SOC_TPLG_BCLK_ value */ diff --git a/include/topology.h b/include/topology.h index 5d7b46df..3793115c 100644 --- a/include/topology.h +++ b/include/topology.h @@ -997,7 +997,7 @@ struct snd_tplg_pcm_template { struct snd_tplg_hw_config_template { int id; /* unique ID - - used to match */ unsigned int fmt; /* SND_SOC_DAI_FORMAT_ format value */ - unsigned char clock_gated; /* 1 if clock can be gated to save power */ + unsigned char clock_gated; /* SND_SOC_TPLG_DAI_CLK_GATE_ value */ unsigned char invert_bclk; /* 1 for inverted BCLK, 0 for normal */ unsigned char invert_fsync;/* 1 for inverted frame clock, 0 for normal */ unsigned char bclk_master; /* SND_SOC_TPLG_BCLK_ value */ diff --git a/src/topology/pcm.c b/src/topology/pcm.c index d0395182..b53f6b03 100644 --- a/src/topology/pcm.c +++ b/src/topology/pcm.c @@ -1233,7 +1233,11 @@ int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg, return -EINVAL; if (!strcmp(val, "true")) - hw_cfg->clock_gated = true; + hw_cfg->clock_gated = + SND_SOC_TPLG_DAI_CLK_GATE_GATED; + else + hw_cfg->clock_gated = + SND_SOC_TPLG_DAI_CLK_GATE_CONT; continue; } -- 2.13.6
[PATCH alsa-lib v4 2/4] ASoC: topology: Add missing clock gating parameter when parsing hw_configs
Clock gating parameter is a part of `dai_fmt`. It is supported by `alsa-lib` when creating a topology binary file, but ignored by kernel when loading this topology file. After applying this commit, the clock gating parameter is not ignored any more. This solution is backwards compatible. The existing behaviour is not broken, because by default the parameter value is 0 and is ignored. snd_soc_tplg_hw_config.clock_gated = 0 => no effect snd_soc_tplg_hw_config.clock_gated = 1 => SND_SOC_DAIFMT_GATED snd_soc_tplg_hw_config.clock_gated = 2 => SND_SOC_DAIFMT_CONT For example, the following config, based on alsa-lib/src/conf/topology/broadwell/broadwell.conf, is now supported: SectionHWConfig."CodecHWConfig" { id "1" format "I2S"# physical audio format. pm_gate_clocks "true" # clock can be gated } SectionLink."Codec" { # used for binding to the physical link id "0" hw_configs [ "CodecHWConfig" ] default_hw_conf_id "1" } Signed-off-by: Kirill Marinushkin Reviewed-by: Pierre-Louis Bossart Cc: Jaroslav Kysela Cc: Takashi Iwai Cc: Mark Brown Cc: Pan Xiuli Cc: Liam Girdwood Cc: linux-kernel@vger.kernel.org Cc: alsa-de...@alsa-project.org --- include/sound/asoc.h | 7 ++- include/topology.h | 2 +- src/topology/pcm.c | 6 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/include/sound/asoc.h b/include/sound/asoc.h index 89b00703..297e837c 100644 --- a/include/sound/asoc.h +++ b/include/sound/asoc.h @@ -135,6 +135,11 @@ #define SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_CHANNELS (1 << 1) #define SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_SAMPLEBITS(1 << 2) +/* DAI clock gating */ +#define SND_SOC_TPLG_DAI_CLK_GATE_UNDEFINED0 +#define SND_SOC_TPLG_DAI_CLK_GATE_GATED1 +#define SND_SOC_TPLG_DAI_CLK_GATE_CONT 2 + /* DAI physical PCM data formats. * Add new formats to the end of the list. */ @@ -320,7 +325,7 @@ 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 clock_gated; /* SND_SOC_TPLG_DAI_CLK_GATE_ value */ __u8 invert_bclk; /* 1 for inverted BCLK, 0 for normal */ __u8 invert_fsync; /* 1 for inverted frame clock, 0 for normal */ __u8 bclk_master; /* SND_SOC_TPLG_BCLK_ value */ diff --git a/include/topology.h b/include/topology.h index 5d7b46df..3793115c 100644 --- a/include/topology.h +++ b/include/topology.h @@ -997,7 +997,7 @@ struct snd_tplg_pcm_template { struct snd_tplg_hw_config_template { int id; /* unique ID - - used to match */ unsigned int fmt; /* SND_SOC_DAI_FORMAT_ format value */ - unsigned char clock_gated; /* 1 if clock can be gated to save power */ + unsigned char clock_gated; /* SND_SOC_TPLG_DAI_CLK_GATE_ value */ unsigned char invert_bclk; /* 1 for inverted BCLK, 0 for normal */ unsigned char invert_fsync;/* 1 for inverted frame clock, 0 for normal */ unsigned char bclk_master; /* SND_SOC_TPLG_BCLK_ value */ diff --git a/src/topology/pcm.c b/src/topology/pcm.c index d0395182..b53f6b03 100644 --- a/src/topology/pcm.c +++ b/src/topology/pcm.c @@ -1233,7 +1233,11 @@ int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg, return -EINVAL; if (!strcmp(val, "true")) - hw_cfg->clock_gated = true; + hw_cfg->clock_gated = + SND_SOC_TPLG_DAI_CLK_GATE_GATED; + else + hw_cfg->clock_gated = + SND_SOC_TPLG_DAI_CLK_GATE_CONT; continue; } -- 2.13.6
[PATCH] ASoC: topology: Modify clock gating parameter parsing to switch
This improves the coding style of this piece of code. Signed-off-by: Kirill Marinushkin <k.marinush...@gmail.com> Cc: Mark Brown <broo...@kernel.org> Cc: Pierre-Louis Bossart <pierre-louis.boss...@linux.intel.com> Cc: Jaroslav Kysela <pe...@perex.cz> Cc: Takashi Iwai <ti...@suse.de> Cc: Pan Xiuli <xiuli@linux.intel.com> Cc: Liam Girdwood <liam.r.girdw...@linux.intel.com> Cc: linux-kernel@vger.kernel.org Cc: alsa-de...@alsa-project.org --- sound/soc/soc-topology.c | 14 +++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c index 04f834e6a6b5..802bad7ddcb4 100644 --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -1982,11 +1982,19 @@ static void set_link_hw_format(struct snd_soc_dai_link *link, link->dai_fmt = hw_config->fmt & SND_SOC_DAIFMT_FORMAT_MASK; /* clock gating */ - if (hw_config->clock_gated == SND_SOC_TPLG_DAI_CLK_GATE_GATED) + switch (hw_config->clock_gated) { + case SND_SOC_TPLG_DAI_CLK_GATE_GATED: link->dai_fmt |= SND_SOC_DAIFMT_GATED; - else if (hw_config->clock_gated == -SND_SOC_TPLG_DAI_CLK_GATE_CONT) + break; + + case SND_SOC_TPLG_DAI_CLK_GATE_CONT: link->dai_fmt |= SND_SOC_DAIFMT_CONT; + break; + + default: + /* ignore the value */ + break; + } /* clock signal polarity */ invert_bclk = hw_config->invert_bclk; -- 2.13.6
[PATCH] ASoC: topology: Modify clock gating parameter parsing to switch
This improves the coding style of this piece of code. Signed-off-by: Kirill Marinushkin Cc: Mark Brown Cc: Pierre-Louis Bossart Cc: Jaroslav Kysela Cc: Takashi Iwai Cc: Pan Xiuli Cc: Liam Girdwood Cc: linux-kernel@vger.kernel.org Cc: alsa-de...@alsa-project.org --- sound/soc/soc-topology.c | 14 +++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c index 04f834e6a6b5..802bad7ddcb4 100644 --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -1982,11 +1982,19 @@ static void set_link_hw_format(struct snd_soc_dai_link *link, link->dai_fmt = hw_config->fmt & SND_SOC_DAIFMT_FORMAT_MASK; /* clock gating */ - if (hw_config->clock_gated == SND_SOC_TPLG_DAI_CLK_GATE_GATED) + switch (hw_config->clock_gated) { + case SND_SOC_TPLG_DAI_CLK_GATE_GATED: link->dai_fmt |= SND_SOC_DAIFMT_GATED; - else if (hw_config->clock_gated == -SND_SOC_TPLG_DAI_CLK_GATE_CONT) + break; + + case SND_SOC_TPLG_DAI_CLK_GATE_CONT: link->dai_fmt |= SND_SOC_DAIFMT_CONT; + break; + + default: + /* ignore the value */ + break; + } /* clock signal polarity */ invert_bclk = hw_config->invert_bclk; -- 2.13.6
[PATCH v4 0/3] ASoC: topology: Improve hw_configs
Hello Mark, This patch series waits since 20th of February, because it modifies UAPI headers and should be done in sync with ALSA. I see that previously there was no clear understanding, how to do this in sync. Two days ago I discussed with Takashi, and he suggested the following steps: Step 1. A person from Intel, who knows the topic (Pierre), adds his "Reviewed-by" or "Acked-by" tags Step 2. I clarify with you to apply the Linux part (this patch series) Step 3. After that, I clarify with Takashi to apply the ALSA part (it is ready, but not sent untill we apply the Linux part) The step 1 is done. Old patches are reviewed by Pierre, so they have his "Reviewed-by" tag. New patches are suggested by him, and we agreed on the implementation, so they have his "Acked-by" tag. Now we are on the step 2. If you don't have anything against this patch series, please apply it to Linux. Best Regards, Kirill Kirill Marinushkin (3): ASoC: topology: Fix bclk and fsync inversion in set_link_hw_format() ASoC: topology: Add missing clock gating parameter when parsing hw_configs ASoC: topology: Add definitions for mclk_direction values include/uapi/sound/asoc.h | 29 + sound/soc/soc-topology.c | 19 ++- 2 files changed, 39 insertions(+), 9 deletions(-) -- 2.13.6
[PATCH v4 2/3] ASoC: topology: Add missing clock gating parameter when parsing hw_configs
Clock gating parameter is a part of `dai_fmt`. It is supported by `alsa-lib` when creating a topology binary file, but ignored by kernel when loading this topology file. After applying this commit, the clock gating parameter is not ignored any more. This solution is backwards compatible. The existing behaviour is not broken, because by default the parameter value is 0 and is ignored. snd_soc_tplg_hw_config.clock_gated = 0 => no effect snd_soc_tplg_hw_config.clock_gated = 1 => SND_SOC_DAIFMT_GATED snd_soc_tplg_hw_config.clock_gated = 2 => SND_SOC_DAIFMT_CONT For example, the following config, based on alsa-lib/src/conf/topology/broadwell/broadwell.conf, is now supported: SectionHWConfig."CodecHWConfig" { id "1" format "I2S"# physical audio format. pm_gate_clocks "true" # clock can be gated } SectionLink."Codec" { # used for binding to the physical link id "0" hw_configs [ "CodecHWConfig" ] default_hw_conf_id "1" } Signed-off-by: Kirill Marinushkin <k.marinush...@gmail.com> Reviewed-by: Pierre-Louis Bossart <pierre-louis.boss...@linux.intel.com> Cc: Jaroslav Kysela <pe...@perex.cz> Cc: Takashi Iwai <ti...@suse.de> Cc: Mark Brown <broo...@kernel.org> Cc: Pan Xiuli <xiuli@linux.intel.com> Cc: Liam Girdwood <liam.r.girdw...@linux.intel.com> Cc: linux-kernel@vger.kernel.org Cc: alsa-de...@alsa-project.org --- include/uapi/sound/asoc.h | 7 ++- sound/soc/soc-topology.c | 7 +++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/uapi/sound/asoc.h b/include/uapi/sound/asoc.h index f0e5e21efa54..f3c4b46e39d8 100644 --- a/include/uapi/sound/asoc.h +++ b/include/uapi/sound/asoc.h @@ -139,6 +139,11 @@ #define SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_CHANNELS (1 << 1) #define SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_SAMPLEBITS(1 << 2) +/* DAI clock gating */ +#define SND_SOC_TPLG_DAI_CLK_GATE_UNDEFINED0 +#define SND_SOC_TPLG_DAI_CLK_GATE_GATED1 +#define SND_SOC_TPLG_DAI_CLK_GATE_CONT 2 + /* DAI physical PCM data formats. * Add new formats to the end of the list. */ @@ -324,7 +329,7 @@ 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 clock_gated; /* SND_SOC_TPLG_DAI_CLK_GATE_ value */ __u8 invert_bclk; /* 1 for inverted BCLK, 0 for normal */ __u8 invert_fsync; /* 1 for inverted frame clock, 0 for normal */ __u8 bclk_master; /* SND_SOC_TPLG_BCLK_ value */ diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c index c5bdc673b195..04f834e6a6b5 100644 --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -1981,6 +1981,13 @@ static void set_link_hw_format(struct snd_soc_dai_link *link, link->dai_fmt = hw_config->fmt & SND_SOC_DAIFMT_FORMAT_MASK; + /* clock gating */ + if (hw_config->clock_gated == SND_SOC_TPLG_DAI_CLK_GATE_GATED) + link->dai_fmt |= SND_SOC_DAIFMT_GATED; + else if (hw_config->clock_gated == +SND_SOC_TPLG_DAI_CLK_GATE_CONT) + link->dai_fmt |= SND_SOC_DAIFMT_CONT; + /* clock signal polarity */ invert_bclk = hw_config->invert_bclk; invert_fsync = hw_config->invert_fsync; -- 2.13.6
[PATCH v4 1/3] ASoC: topology: Fix bclk and fsync inversion in set_link_hw_format()
The values of bclk and fsync are inverted WRT the codec. But the existing solution already works for Broadwell, see the alsa-lib config: `alsa-lib/src/conf/topology/broadwell/broadwell.conf` This commit provides the backwards-compatible solution to fix this misuse. Signed-off-by: Kirill Marinushkin <k.marinush...@gmail.com> Reviewed-by: Pierre-Louis Bossart <pierre-louis.boss...@linux.intel.com> Tested-by: Pan Xiuli <xiuli@linux.intel.com> Tested-by: Pierre-Louis Bossart <pierre-louis.boss...@linux.intel.com> Cc: Jaroslav Kysela <pe...@perex.cz> Cc: Takashi Iwai <ti...@suse.de> Cc: Mark Brown <broo...@kernel.org> Cc: Liam Girdwood <liam.r.girdw...@linux.intel.com> Cc: linux-kernel@vger.kernel.org Cc: alsa-de...@alsa-project.org --- include/uapi/sound/asoc.h | 16 ++-- sound/soc/soc-topology.c | 12 +++- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/include/uapi/sound/asoc.h b/include/uapi/sound/asoc.h index 69c37ecbff7e..f0e5e21efa54 100644 --- a/include/uapi/sound/asoc.h +++ b/include/uapi/sound/asoc.h @@ -160,6 +160,18 @@ #define SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_SAMPLEBITS(1 << 2) #define SND_SOC_TPLG_LNK_FLGBIT_VOICE_WAKEUP(1 << 3) +/* DAI topology BCLK parameter + * For the backwards capability, by default codec is bclk master + */ +#define SND_SOC_TPLG_BCLK_CM 0 /* codec is bclk master */ +#define SND_SOC_TPLG_BCLK_CS 1 /* codec is bclk slave */ + +/* DAI topology FSYNC parameter + * For the backwards capability, by default codec is fsync master + */ +#define SND_SOC_TPLG_FSYNC_CM 0 /* codec is fsync master */ +#define SND_SOC_TPLG_FSYNC_CS 1 /* codec is fsync slave */ + /* * Block Header. * This header precedes all object and object arrays below. @@ -315,8 +327,8 @@ struct snd_soc_tplg_hw_config { __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 bclk_master; /* SND_SOC_TPLG_BCLK_ value */ + __u8 fsync_master; /* SND_SOC_TPLG_FSYNC_ value */ __u8 mclk_direction;/* 0 for input, 1 for output */ __le16 reserved;/* for 32bit alignment */ __le32 mclk_rate; /* MCLK or SYSCLK freqency in Hz */ diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c index 01a50413c66f..c5bdc673b195 100644 --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -1994,13 +1994,15 @@ static void set_link_hw_format(struct snd_soc_dai_link *link, 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) + bclk_master = (hw_config->bclk_master == + SND_SOC_TPLG_BCLK_CM); + fsync_master = (hw_config->fsync_master == + SND_SOC_TPLG_FSYNC_CM); + 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_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; -- 2.13.6
[PATCH v4 0/3] ASoC: topology: Improve hw_configs
Hello Mark, This patch series waits since 20th of February, because it modifies UAPI headers and should be done in sync with ALSA. I see that previously there was no clear understanding, how to do this in sync. Two days ago I discussed with Takashi, and he suggested the following steps: Step 1. A person from Intel, who knows the topic (Pierre), adds his "Reviewed-by" or "Acked-by" tags Step 2. I clarify with you to apply the Linux part (this patch series) Step 3. After that, I clarify with Takashi to apply the ALSA part (it is ready, but not sent untill we apply the Linux part) The step 1 is done. Old patches are reviewed by Pierre, so they have his "Reviewed-by" tag. New patches are suggested by him, and we agreed on the implementation, so they have his "Acked-by" tag. Now we are on the step 2. If you don't have anything against this patch series, please apply it to Linux. Best Regards, Kirill Kirill Marinushkin (3): ASoC: topology: Fix bclk and fsync inversion in set_link_hw_format() ASoC: topology: Add missing clock gating parameter when parsing hw_configs ASoC: topology: Add definitions for mclk_direction values include/uapi/sound/asoc.h | 29 + sound/soc/soc-topology.c | 19 ++- 2 files changed, 39 insertions(+), 9 deletions(-) -- 2.13.6
[PATCH v4 2/3] ASoC: topology: Add missing clock gating parameter when parsing hw_configs
Clock gating parameter is a part of `dai_fmt`. It is supported by `alsa-lib` when creating a topology binary file, but ignored by kernel when loading this topology file. After applying this commit, the clock gating parameter is not ignored any more. This solution is backwards compatible. The existing behaviour is not broken, because by default the parameter value is 0 and is ignored. snd_soc_tplg_hw_config.clock_gated = 0 => no effect snd_soc_tplg_hw_config.clock_gated = 1 => SND_SOC_DAIFMT_GATED snd_soc_tplg_hw_config.clock_gated = 2 => SND_SOC_DAIFMT_CONT For example, the following config, based on alsa-lib/src/conf/topology/broadwell/broadwell.conf, is now supported: SectionHWConfig."CodecHWConfig" { id "1" format "I2S"# physical audio format. pm_gate_clocks "true" # clock can be gated } SectionLink."Codec" { # used for binding to the physical link id "0" hw_configs [ "CodecHWConfig" ] default_hw_conf_id "1" } Signed-off-by: Kirill Marinushkin Reviewed-by: Pierre-Louis Bossart Cc: Jaroslav Kysela Cc: Takashi Iwai Cc: Mark Brown Cc: Pan Xiuli Cc: Liam Girdwood Cc: linux-kernel@vger.kernel.org Cc: alsa-de...@alsa-project.org --- include/uapi/sound/asoc.h | 7 ++- sound/soc/soc-topology.c | 7 +++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/uapi/sound/asoc.h b/include/uapi/sound/asoc.h index f0e5e21efa54..f3c4b46e39d8 100644 --- a/include/uapi/sound/asoc.h +++ b/include/uapi/sound/asoc.h @@ -139,6 +139,11 @@ #define SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_CHANNELS (1 << 1) #define SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_SAMPLEBITS(1 << 2) +/* DAI clock gating */ +#define SND_SOC_TPLG_DAI_CLK_GATE_UNDEFINED0 +#define SND_SOC_TPLG_DAI_CLK_GATE_GATED1 +#define SND_SOC_TPLG_DAI_CLK_GATE_CONT 2 + /* DAI physical PCM data formats. * Add new formats to the end of the list. */ @@ -324,7 +329,7 @@ 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 clock_gated; /* SND_SOC_TPLG_DAI_CLK_GATE_ value */ __u8 invert_bclk; /* 1 for inverted BCLK, 0 for normal */ __u8 invert_fsync; /* 1 for inverted frame clock, 0 for normal */ __u8 bclk_master; /* SND_SOC_TPLG_BCLK_ value */ diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c index c5bdc673b195..04f834e6a6b5 100644 --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -1981,6 +1981,13 @@ static void set_link_hw_format(struct snd_soc_dai_link *link, link->dai_fmt = hw_config->fmt & SND_SOC_DAIFMT_FORMAT_MASK; + /* clock gating */ + if (hw_config->clock_gated == SND_SOC_TPLG_DAI_CLK_GATE_GATED) + link->dai_fmt |= SND_SOC_DAIFMT_GATED; + else if (hw_config->clock_gated == +SND_SOC_TPLG_DAI_CLK_GATE_CONT) + link->dai_fmt |= SND_SOC_DAIFMT_CONT; + /* clock signal polarity */ invert_bclk = hw_config->invert_bclk; invert_fsync = hw_config->invert_fsync; -- 2.13.6
[PATCH v4 1/3] ASoC: topology: Fix bclk and fsync inversion in set_link_hw_format()
The values of bclk and fsync are inverted WRT the codec. But the existing solution already works for Broadwell, see the alsa-lib config: `alsa-lib/src/conf/topology/broadwell/broadwell.conf` This commit provides the backwards-compatible solution to fix this misuse. Signed-off-by: Kirill Marinushkin Reviewed-by: Pierre-Louis Bossart Tested-by: Pan Xiuli Tested-by: Pierre-Louis Bossart Cc: Jaroslav Kysela Cc: Takashi Iwai Cc: Mark Brown Cc: Liam Girdwood Cc: linux-kernel@vger.kernel.org Cc: alsa-de...@alsa-project.org --- include/uapi/sound/asoc.h | 16 ++-- sound/soc/soc-topology.c | 12 +++- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/include/uapi/sound/asoc.h b/include/uapi/sound/asoc.h index 69c37ecbff7e..f0e5e21efa54 100644 --- a/include/uapi/sound/asoc.h +++ b/include/uapi/sound/asoc.h @@ -160,6 +160,18 @@ #define SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_SAMPLEBITS(1 << 2) #define SND_SOC_TPLG_LNK_FLGBIT_VOICE_WAKEUP(1 << 3) +/* DAI topology BCLK parameter + * For the backwards capability, by default codec is bclk master + */ +#define SND_SOC_TPLG_BCLK_CM 0 /* codec is bclk master */ +#define SND_SOC_TPLG_BCLK_CS 1 /* codec is bclk slave */ + +/* DAI topology FSYNC parameter + * For the backwards capability, by default codec is fsync master + */ +#define SND_SOC_TPLG_FSYNC_CM 0 /* codec is fsync master */ +#define SND_SOC_TPLG_FSYNC_CS 1 /* codec is fsync slave */ + /* * Block Header. * This header precedes all object and object arrays below. @@ -315,8 +327,8 @@ struct snd_soc_tplg_hw_config { __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 bclk_master; /* SND_SOC_TPLG_BCLK_ value */ + __u8 fsync_master; /* SND_SOC_TPLG_FSYNC_ value */ __u8 mclk_direction;/* 0 for input, 1 for output */ __le16 reserved;/* for 32bit alignment */ __le32 mclk_rate; /* MCLK or SYSCLK freqency in Hz */ diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c index 01a50413c66f..c5bdc673b195 100644 --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -1994,13 +1994,15 @@ static void set_link_hw_format(struct snd_soc_dai_link *link, 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) + bclk_master = (hw_config->bclk_master == + SND_SOC_TPLG_BCLK_CM); + fsync_master = (hw_config->fsync_master == + SND_SOC_TPLG_FSYNC_CM); + 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_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; -- 2.13.6
[PATCH v4 3/3] ASoC: topology: Add definitions for mclk_direction values
Current comment makes not clear the direction of mclk. Previously, similar description caused a misunderstanding for bclk_master and fsync_master. This commit solves the potential confusion the same way it is solved for bclk_master and fsync_master. Signed-off-by: Kirill Marinushkin <k.marinush...@gmail.com> Acked-by: Pierre-Louis Bossart <pierre-louis.boss...@linux.intel.com> Cc: Jaroslav Kysela <pe...@perex.cz> Cc: Takashi Iwai <ti...@suse.de> Cc: Mark Brown <broo...@kernel.org> Cc: Pan Xiuli <xiuli@linux.intel.com> Cc: Liam Girdwood <liam.r.girdw...@linux.intel.com> Cc: linux-kernel@vger.kernel.org Cc: alsa-de...@alsa-project.org --- include/uapi/sound/asoc.h | 6 +- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/uapi/sound/asoc.h b/include/uapi/sound/asoc.h index f3c4b46e39d8..b901cdbe532a 100644 --- a/include/uapi/sound/asoc.h +++ b/include/uapi/sound/asoc.h @@ -144,6 +144,10 @@ #define SND_SOC_TPLG_DAI_CLK_GATE_GATED1 #define SND_SOC_TPLG_DAI_CLK_GATE_CONT 2 +/* DAI mclk_direction */ +#define SND_SOC_TPLG_MCLK_CO0 /* for codec, mclk is output */ +#define SND_SOC_TPLG_MCLK_CI1 /* for codec, mclk is input */ + /* DAI physical PCM data formats. * Add new formats to the end of the list. */ @@ -334,7 +338,7 @@ struct snd_soc_tplg_hw_config { __u8 invert_fsync; /* 1 for inverted frame clock, 0 for normal */ __u8 bclk_master; /* SND_SOC_TPLG_BCLK_ value */ __u8 fsync_master; /* SND_SOC_TPLG_FSYNC_ value */ - __u8 mclk_direction;/* 0 for input, 1 for output */ + __u8 mclk_direction;/* SND_SOC_TPLG_MCLK_ value */ __le16 reserved;/* for 32bit alignment */ __le32 mclk_rate; /* MCLK or SYSCLK freqency in Hz */ __le32 bclk_rate; /* BCLK freqency in Hz */ -- 2.13.6
[PATCH v4 3/3] ASoC: topology: Add definitions for mclk_direction values
Current comment makes not clear the direction of mclk. Previously, similar description caused a misunderstanding for bclk_master and fsync_master. This commit solves the potential confusion the same way it is solved for bclk_master and fsync_master. Signed-off-by: Kirill Marinushkin Acked-by: Pierre-Louis Bossart Cc: Jaroslav Kysela Cc: Takashi Iwai Cc: Mark Brown Cc: Pan Xiuli Cc: Liam Girdwood Cc: linux-kernel@vger.kernel.org Cc: alsa-de...@alsa-project.org --- include/uapi/sound/asoc.h | 6 +- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/uapi/sound/asoc.h b/include/uapi/sound/asoc.h index f3c4b46e39d8..b901cdbe532a 100644 --- a/include/uapi/sound/asoc.h +++ b/include/uapi/sound/asoc.h @@ -144,6 +144,10 @@ #define SND_SOC_TPLG_DAI_CLK_GATE_GATED1 #define SND_SOC_TPLG_DAI_CLK_GATE_CONT 2 +/* DAI mclk_direction */ +#define SND_SOC_TPLG_MCLK_CO0 /* for codec, mclk is output */ +#define SND_SOC_TPLG_MCLK_CI1 /* for codec, mclk is input */ + /* DAI physical PCM data formats. * Add new formats to the end of the list. */ @@ -334,7 +338,7 @@ struct snd_soc_tplg_hw_config { __u8 invert_fsync; /* 1 for inverted frame clock, 0 for normal */ __u8 bclk_master; /* SND_SOC_TPLG_BCLK_ value */ __u8 fsync_master; /* SND_SOC_TPLG_FSYNC_ value */ - __u8 mclk_direction;/* 0 for input, 1 for output */ + __u8 mclk_direction;/* SND_SOC_TPLG_MCLK_ value */ __le16 reserved;/* for 32bit alignment */ __le32 mclk_rate; /* MCLK or SYSCLK freqency in Hz */ __le32 bclk_rate; /* BCLK freqency in Hz */ -- 2.13.6
Re: [alsa-devel] [PATCH v3 0/2] ASoC: topology: Improve parsing hw_configs
On 04/03/18 19:21, Pierre-Louis Bossart wrote: > > > On 04/03/2018 12:15 AM, Kirill Marinushkin wrote: >> On 04/03/18 02:57, Pierre-Louis Bossart wrote: >>> >>> On 04/02/2018 04:17 PM, Kirill Marinushkin wrote: >>>> Hello Pierre-Louis, >>>> >>>> I explicitly clarified with Takashi: to have this patch series merged, we >>>> need a >>>> tag "Reviewed-by" from you. >>> I am fine with the changes, but maybe while we are at it, we should clarify >>> what mclk_direction means? >> That's a good idea to have it solved within this patch series. >> >>> __u8 mclk_direction; /* 0 for input, 1 for output */ >>> >>> This is really awful and might benefit for additional clarity using >>> codec-centric conventions. >>> >> I agree that having a clear naming will avoid confusion for future usage. >> I see from the code, that this variable is ignored. So we have no technical >> restriction on how to interpret this. >> I suggest to do similar to what we did for bclk_master: >> >> /* DAI mclk_direction */ >> #define SND_SOC_TPLG_MCLK_CO 0 /* for codec, mclk is output */ >> #define SND_SOC_TPLG_MCLK_CI 1 /* for codec, mclk is input */ >> >>> We also had a discussion internally and can't figure out why the strings are >>> different from the fields in the structure, I feel it'd be simpler to align >>> config and code to avoid issues but keep existing notation for backwards >>> compatibility, e.g. >>> >>> if (strcmp(id, "mclk_freq") == 0) || strcmp(id, "mclk_rate") == 0) { >>> if (snd_config_get_string(n, ) < 0) >>> return -EINVAL; >>> >>> hw_cfg->mclk_rate = atoi(val); >>> continue; >>> } >> I agree with this. I will also do the same (keeping backwards-compatibility) >> for: >> >> "format" => "fmt" >> "bclk" => "bclk_master" >> "bclk_freq" => "bclk_rate" >> "bclk_invert" => "invert_bclk" >> "fsync" => "fsync_master" >> "fsync_invert" => "invert_fsync" >> "fsync_freq" => "fsync_rate" >> "mclk_freq" => "mclk_rate" >> "mclk" => "mclk_direction" >> "pm_gate_clocks" => "clock_gated" >> >> If you agree with both proposals, I will add patches to this patch series, >> and >> re-send as patch v4. >> Or can we handle it in a better way? > A v4 is fine with me. > > These topology definitions appear in hindsight quite problematic, there are > missing definitions and capabilities, e.g we have the ability to 'gate the > clock' but without knowing which clock, and we have no ability to force the > mclk/bclk/fsync on (be it on demand from a codec driver or on startup as a > system requirement). And there is no real extension capability with a protocol > version. The net effect is that people will have to create custom tokens and > parsing for things that should be common... > Yes, definitions which you mentioned really can become a problem. But, I see from the header that topology files support versioning: #define SND_SOC_TPLG_ABI_VERSION 0x5 /* current version */ So, in future such problems can be solved by incrementing the version, if no backwards capabilities are available. Before I continue with the patch v4, I want to clarify with you, so that we avoid the misunderstanding: * in the existing 4 patches, I will add a tag "Reviewed-by: Pierre-Louis Bossart <pierre-louis.boss...@linux.intel.com>" * in the new 2 patches, which we recently discussed, I will add a tag "Acked-by: Pierre-Louis Bossart <pierre-louis.boss...@linux.intel.com>" Do you agree with that? Best Regards, Kirill > Thanks > -Pierre
Re: [alsa-devel] [PATCH v3 0/2] ASoC: topology: Improve parsing hw_configs
On 04/03/18 19:21, Pierre-Louis Bossart wrote: > > > On 04/03/2018 12:15 AM, Kirill Marinushkin wrote: >> On 04/03/18 02:57, Pierre-Louis Bossart wrote: >>> >>> On 04/02/2018 04:17 PM, Kirill Marinushkin wrote: >>>> Hello Pierre-Louis, >>>> >>>> I explicitly clarified with Takashi: to have this patch series merged, we >>>> need a >>>> tag "Reviewed-by" from you. >>> I am fine with the changes, but maybe while we are at it, we should clarify >>> what mclk_direction means? >> That's a good idea to have it solved within this patch series. >> >>> __u8 mclk_direction; /* 0 for input, 1 for output */ >>> >>> This is really awful and might benefit for additional clarity using >>> codec-centric conventions. >>> >> I agree that having a clear naming will avoid confusion for future usage. >> I see from the code, that this variable is ignored. So we have no technical >> restriction on how to interpret this. >> I suggest to do similar to what we did for bclk_master: >> >> /* DAI mclk_direction */ >> #define SND_SOC_TPLG_MCLK_CO 0 /* for codec, mclk is output */ >> #define SND_SOC_TPLG_MCLK_CI 1 /* for codec, mclk is input */ >> >>> We also had a discussion internally and can't figure out why the strings are >>> different from the fields in the structure, I feel it'd be simpler to align >>> config and code to avoid issues but keep existing notation for backwards >>> compatibility, e.g. >>> >>> if (strcmp(id, "mclk_freq") == 0) || strcmp(id, "mclk_rate") == 0) { >>> if (snd_config_get_string(n, ) < 0) >>> return -EINVAL; >>> >>> hw_cfg->mclk_rate = atoi(val); >>> continue; >>> } >> I agree with this. I will also do the same (keeping backwards-compatibility) >> for: >> >> "format" => "fmt" >> "bclk" => "bclk_master" >> "bclk_freq" => "bclk_rate" >> "bclk_invert" => "invert_bclk" >> "fsync" => "fsync_master" >> "fsync_invert" => "invert_fsync" >> "fsync_freq" => "fsync_rate" >> "mclk_freq" => "mclk_rate" >> "mclk" => "mclk_direction" >> "pm_gate_clocks" => "clock_gated" >> >> If you agree with both proposals, I will add patches to this patch series, >> and >> re-send as patch v4. >> Or can we handle it in a better way? > A v4 is fine with me. > > These topology definitions appear in hindsight quite problematic, there are > missing definitions and capabilities, e.g we have the ability to 'gate the > clock' but without knowing which clock, and we have no ability to force the > mclk/bclk/fsync on (be it on demand from a codec driver or on startup as a > system requirement). And there is no real extension capability with a protocol > version. The net effect is that people will have to create custom tokens and > parsing for things that should be common... > Yes, definitions which you mentioned really can become a problem. But, I see from the header that topology files support versioning: #define SND_SOC_TPLG_ABI_VERSION 0x5 /* current version */ So, in future such problems can be solved by incrementing the version, if no backwards capabilities are available. Before I continue with the patch v4, I want to clarify with you, so that we avoid the misunderstanding: * in the existing 4 patches, I will add a tag "Reviewed-by: Pierre-Louis Bossart " * in the new 2 patches, which we recently discussed, I will add a tag "Acked-by: Pierre-Louis Bossart " Do you agree with that? Best Regards, Kirill > Thanks > -Pierre
Re: [PATCH v3 0/2] ASoC: topology: Improve parsing hw_configs
On 04/03/18 02:57, Pierre-Louis Bossart wrote: > > > On 04/02/2018 04:17 PM, Kirill Marinushkin wrote: >> Hello Pierre-Louis, >> >> I explicitly clarified with Takashi: to have this patch series merged, we >> need a >> tag "Reviewed-by" from you. > I am fine with the changes, but maybe while we are at it, we should clarify > what mclk_direction means? That's a good idea to have it solved within this patch series. > > __u8 mclk_direction; /* 0 for input, 1 for output */ > > This is really awful and might benefit for additional clarity using > codec-centric conventions. > I agree that having a clear naming will avoid confusion for future usage. I see from the code, that this variable is ignored. So we have no technical restriction on how to interpret this. I suggest to do similar to what we did for bclk_master: /* DAI mclk_direction */ #define SND_SOC_TPLG_MCLK_CO 0 /* for codec, mclk is output */ #define SND_SOC_TPLG_MCLK_CI 1 /* for codec, mclk is input */ > We also had a discussion internally and can't figure out why the strings are > different from the fields in the structure, I feel it'd be simpler to align > config and code to avoid issues but keep existing notation for backwards > compatibility, e.g. > > if (strcmp(id, "mclk_freq") == 0) || strcmp(id, "mclk_rate") == 0) { > if (snd_config_get_string(n, ) < 0) > return -EINVAL; > > hw_cfg->mclk_rate = atoi(val); > continue; > } I agree with this. I will also do the same (keeping backwards-compatibility) for: "format" => "fmt" "bclk" => "bclk_master" "bclk_freq" => "bclk_rate" "bclk_invert" => "invert_bclk" "fsync" => "fsync_master" "fsync_invert" => "invert_fsync" "fsync_freq" => "fsync_rate" "mclk_freq" => "mclk_rate" "mclk" => "mclk_direction" "pm_gate_clocks" => "clock_gated" If you agree with both proposals, I will add patches to this patch series, and re-send as patch v4. Or can we handle it in a better way? >> >> Patches [2] and [5]: >> You already tested them. May I put a tag "Reviewed-by" with your name into >> them? >> >> Patches [3] and [6]: >> Those are new for you; I added them to this patch series, because they are >> logically similar to [2] and [5]. >> Could you please review these patches? >> >> Best Regards, >> Kirill >> >> [1] [PATCH v3 0/2] ASoC: topology: Improve parsing hw_configs >> [2] [PATCH v3 1/2] ASoC: topology: Fix bclk and fsync inversion in >> set_link_hw_format() >> [3] [PATCH v3 2/2] ASoC: topology: Add missing clock gating parameter when >> parsing hw_configs >> [4] [PATCH, alsa-lib, v3 0/2] alsa-lib: ASoC: topology: Improve parsing >> hw_configs >> [5] [PATCH, alsa-lib, v3 1/2] ASoC: topology: Fix bclk and fsync inversion in >> set_link_hw_format() >> [6] [PATCH, alsa-lib, v3 2/2] ASoC: topology: Add missing clock gating >> parameter when parsing hw_configs >> >> >> On 03/27/18 22:56, Kirill Marinushkin wrote: >>> Hello Jaroslav, Takashi, Mark, >>> >>> This patch series is a resend of [1] and [2], rebased on top of the latest >>> head. It was logical to resend them together. >>> >>> It includes 2 patches for linux + 2 patches for alsa-lib. >>> >>> Please have a look. >>> >>> Best Regards, >>> Kirill >>> >>> [1] https://patchwork.kernel.org/patch/10250485/ >>> [2] https://patchwork.kernel.org/patch/10230611/ >>> >>> Kirill Marinushkin (2): >>> ASoC: topology: Fix bclk and fsync inversion in set_link_hw_format() >>> ASoC: topology: Add missing clock gating parameter when parsing >>> hw_configs >>> >>> include/uapi/sound/asoc.h | 23 --- >>> sound/soc/soc-topology.c | 19 ++- >>> 2 files changed, 34 insertions(+), 8 deletions(-) >>> >
Re: [PATCH v3 0/2] ASoC: topology: Improve parsing hw_configs
On 04/03/18 02:57, Pierre-Louis Bossart wrote: > > > On 04/02/2018 04:17 PM, Kirill Marinushkin wrote: >> Hello Pierre-Louis, >> >> I explicitly clarified with Takashi: to have this patch series merged, we >> need a >> tag "Reviewed-by" from you. > I am fine with the changes, but maybe while we are at it, we should clarify > what mclk_direction means? That's a good idea to have it solved within this patch series. > > __u8 mclk_direction; /* 0 for input, 1 for output */ > > This is really awful and might benefit for additional clarity using > codec-centric conventions. > I agree that having a clear naming will avoid confusion for future usage. I see from the code, that this variable is ignored. So we have no technical restriction on how to interpret this. I suggest to do similar to what we did for bclk_master: /* DAI mclk_direction */ #define SND_SOC_TPLG_MCLK_CO 0 /* for codec, mclk is output */ #define SND_SOC_TPLG_MCLK_CI 1 /* for codec, mclk is input */ > We also had a discussion internally and can't figure out why the strings are > different from the fields in the structure, I feel it'd be simpler to align > config and code to avoid issues but keep existing notation for backwards > compatibility, e.g. > > if (strcmp(id, "mclk_freq") == 0) || strcmp(id, "mclk_rate") == 0) { > if (snd_config_get_string(n, ) < 0) > return -EINVAL; > > hw_cfg->mclk_rate = atoi(val); > continue; > } I agree with this. I will also do the same (keeping backwards-compatibility) for: "format" => "fmt" "bclk" => "bclk_master" "bclk_freq" => "bclk_rate" "bclk_invert" => "invert_bclk" "fsync" => "fsync_master" "fsync_invert" => "invert_fsync" "fsync_freq" => "fsync_rate" "mclk_freq" => "mclk_rate" "mclk" => "mclk_direction" "pm_gate_clocks" => "clock_gated" If you agree with both proposals, I will add patches to this patch series, and re-send as patch v4. Or can we handle it in a better way? >> >> Patches [2] and [5]: >> You already tested them. May I put a tag "Reviewed-by" with your name into >> them? >> >> Patches [3] and [6]: >> Those are new for you; I added them to this patch series, because they are >> logically similar to [2] and [5]. >> Could you please review these patches? >> >> Best Regards, >> Kirill >> >> [1] [PATCH v3 0/2] ASoC: topology: Improve parsing hw_configs >> [2] [PATCH v3 1/2] ASoC: topology: Fix bclk and fsync inversion in >> set_link_hw_format() >> [3] [PATCH v3 2/2] ASoC: topology: Add missing clock gating parameter when >> parsing hw_configs >> [4] [PATCH, alsa-lib, v3 0/2] alsa-lib: ASoC: topology: Improve parsing >> hw_configs >> [5] [PATCH, alsa-lib, v3 1/2] ASoC: topology: Fix bclk and fsync inversion in >> set_link_hw_format() >> [6] [PATCH, alsa-lib, v3 2/2] ASoC: topology: Add missing clock gating >> parameter when parsing hw_configs >> >> >> On 03/27/18 22:56, Kirill Marinushkin wrote: >>> Hello Jaroslav, Takashi, Mark, >>> >>> This patch series is a resend of [1] and [2], rebased on top of the latest >>> head. It was logical to resend them together. >>> >>> It includes 2 patches for linux + 2 patches for alsa-lib. >>> >>> Please have a look. >>> >>> Best Regards, >>> Kirill >>> >>> [1] https://patchwork.kernel.org/patch/10250485/ >>> [2] https://patchwork.kernel.org/patch/10230611/ >>> >>> Kirill Marinushkin (2): >>> ASoC: topology: Fix bclk and fsync inversion in set_link_hw_format() >>> ASoC: topology: Add missing clock gating parameter when parsing >>> hw_configs >>> >>> include/uapi/sound/asoc.h | 23 --- >>> sound/soc/soc-topology.c | 19 ++- >>> 2 files changed, 34 insertions(+), 8 deletions(-) >>> >
Re: [PATCH v3 0/2] ASoC: topology: Improve parsing hw_configs
Hello Pierre-Louis, I explicitly clarified with Takashi: to have this patch series merged, we need a tag "Reviewed-by" from you. Patches [2] and [5]: You already tested them. May I put a tag "Reviewed-by" with your name into them? Patches [3] and [6]: Those are new for you; I added them to this patch series, because they are logically similar to [2] and [5]. Could you please review these patches? Best Regards, Kirill [1] [PATCH v3 0/2] ASoC: topology: Improve parsing hw_configs [2] [PATCH v3 1/2] ASoC: topology: Fix bclk and fsync inversion in set_link_hw_format() [3] [PATCH v3 2/2] ASoC: topology: Add missing clock gating parameter when parsing hw_configs [4] [PATCH, alsa-lib, v3 0/2] alsa-lib: ASoC: topology: Improve parsing hw_configs [5] [PATCH, alsa-lib, v3 1/2] ASoC: topology: Fix bclk and fsync inversion in set_link_hw_format() [6] [PATCH, alsa-lib, v3 2/2] ASoC: topology: Add missing clock gating parameter when parsing hw_configs On 03/27/18 22:56, Kirill Marinushkin wrote: > Hello Jaroslav, Takashi, Mark, > > This patch series is a resend of [1] and [2], rebased on top of the latest > head. It was logical to resend them together. > > It includes 2 patches for linux + 2 patches for alsa-lib. > > Please have a look. > > Best Regards, > Kirill > > [1] https://patchwork.kernel.org/patch/10250485/ > [2] https://patchwork.kernel.org/patch/10230611/ > > Kirill Marinushkin (2): > ASoC: topology: Fix bclk and fsync inversion in set_link_hw_format() > ASoC: topology: Add missing clock gating parameter when parsing > hw_configs > > include/uapi/sound/asoc.h | 23 --- > sound/soc/soc-topology.c | 19 ++- > 2 files changed, 34 insertions(+), 8 deletions(-) >
Re: [PATCH v3 0/2] ASoC: topology: Improve parsing hw_configs
Hello Pierre-Louis, I explicitly clarified with Takashi: to have this patch series merged, we need a tag "Reviewed-by" from you. Patches [2] and [5]: You already tested them. May I put a tag "Reviewed-by" with your name into them? Patches [3] and [6]: Those are new for you; I added them to this patch series, because they are logically similar to [2] and [5]. Could you please review these patches? Best Regards, Kirill [1] [PATCH v3 0/2] ASoC: topology: Improve parsing hw_configs [2] [PATCH v3 1/2] ASoC: topology: Fix bclk and fsync inversion in set_link_hw_format() [3] [PATCH v3 2/2] ASoC: topology: Add missing clock gating parameter when parsing hw_configs [4] [PATCH, alsa-lib, v3 0/2] alsa-lib: ASoC: topology: Improve parsing hw_configs [5] [PATCH, alsa-lib, v3 1/2] ASoC: topology: Fix bclk and fsync inversion in set_link_hw_format() [6] [PATCH, alsa-lib, v3 2/2] ASoC: topology: Add missing clock gating parameter when parsing hw_configs On 03/27/18 22:56, Kirill Marinushkin wrote: > Hello Jaroslav, Takashi, Mark, > > This patch series is a resend of [1] and [2], rebased on top of the latest > head. It was logical to resend them together. > > It includes 2 patches for linux + 2 patches for alsa-lib. > > Please have a look. > > Best Regards, > Kirill > > [1] https://patchwork.kernel.org/patch/10250485/ > [2] https://patchwork.kernel.org/patch/10230611/ > > Kirill Marinushkin (2): > ASoC: topology: Fix bclk and fsync inversion in set_link_hw_format() > ASoC: topology: Add missing clock gating parameter when parsing > hw_configs > > include/uapi/sound/asoc.h | 23 --- > sound/soc/soc-topology.c | 19 ++- > 2 files changed, 34 insertions(+), 8 deletions(-) >
[PATCH, alsa-lib, v3 1/2] ASoC: topology: Fix bclk and fsync inversion in set_link_hw_format()
The values of bclk and fsync are inverted WRT the codec. But the existing solution already works for Broadwell, see the alsa-lib config: `alsa-lib/src/conf/topology/broadwell/broadwell.conf` This commit provides the backwards-compatible solution to fix this misuse. This commit goes in pair with the corresponding patch for linux. Signed-off-by: Kirill Marinushkin <k.marinush...@gmail.com> Tested-by: Pan Xiuli <xiuli@linux.intel.com> Tested-by: Pierre-Louis Bossart <pierre-louis.boss...@linux.intel.com> Cc: Jaroslav Kysela <pe...@perex.cz> Cc: Takashi Iwai <ti...@suse.de> Cc: Mark Brown <broo...@kernel.org> Cc: Liam Girdwood <liam.r.girdw...@linux.intel.com> Cc: linux-kernel@vger.kernel.org Cc: alsa-de...@alsa-project.org --- include/sound/asoc.h | 16 ++-- include/topology.h | 4 ++-- src/conf/topology/broadwell/broadwell.conf | 4 ++-- src/topology/pcm.c | 30 ++ 4 files changed, 44 insertions(+), 10 deletions(-) diff --git a/include/sound/asoc.h b/include/sound/asoc.h index 0f5d9f9a..89b00703 100644 --- a/include/sound/asoc.h +++ b/include/sound/asoc.h @@ -156,6 +156,18 @@ #define SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_SAMPLEBITS(1 << 2) #define SND_SOC_TPLG_LNK_FLGBIT_VOICE_WAKEUP(1 << 3) +/* DAI topology BCLK parameter + * For the backwards capability, by default codec is bclk master + */ +#define SND_SOC_TPLG_BCLK_CM 0 /* codec is bclk master */ +#define SND_SOC_TPLG_BCLK_CS 1 /* codec is bclk slave */ + +/* DAI topology FSYNC parameter + * For the backwards capability, by default codec is fsync master + */ +#define SND_SOC_TPLG_FSYNC_CM 0 /* codec is fsync master */ +#define SND_SOC_TPLG_FSYNC_CS 1 /* codec is fsync slave */ + /* * Block Header. * This header precedes all object and object arrays below. @@ -311,8 +323,8 @@ struct snd_soc_tplg_hw_config { __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 bclk_master; /* SND_SOC_TPLG_BCLK_ value */ + __u8 fsync_master; /* SND_SOC_TPLG_FSYNC_ value */ __u8 mclk_direction;/* 0 for input, 1 for output */ __le16 reserved;/* for 32bit alignment */ __le32 mclk_rate; /* MCLK or SYSCLK freqency in Hz */ diff --git a/include/topology.h b/include/topology.h index 8779da4d..5d7b46df 100644 --- a/include/topology.h +++ b/include/topology.h @@ -1000,8 +1000,8 @@ struct snd_tplg_hw_config_template { unsigned char clock_gated; /* 1 if clock can be gated to save power */ unsigned char invert_bclk; /* 1 for inverted BCLK, 0 for normal */ unsigned char invert_fsync;/* 1 for inverted frame clock, 0 for normal */ - unsigned char bclk_master; /* 1 for master of BCLK, 0 for slave */ - unsigned char fsync_master;/* 1 for master of FSYNC, 0 for slave */ + unsigned char bclk_master; /* SND_SOC_TPLG_BCLK_ value */ + unsigned char fsync_master;/* SND_SOC_TPLG_FSYNC_ value */ unsigned char mclk_direction; /* 0 for input, 1 for output */ unsigned short reserved;/* for 32bit alignment */ unsigned int mclk_rate; /* MCLK or SYSCLK freqency in Hz */ diff --git a/src/conf/topology/broadwell/broadwell.conf b/src/conf/topology/broadwell/broadwell.conf index b8405d93..09fc4daa 100644 --- a/src/conf/topology/broadwell/broadwell.conf +++ b/src/conf/topology/broadwell/broadwell.conf @@ -393,8 +393,8 @@ SectionGraph."dsp" { SectionHWConfig."CodecHWConfig" { id "1" format "I2S"# physical audio format. - bclk "master" # Platform is master of bit clock - fsync "master" # platform is master of fsync + bclk "codec_slave"# platform is master of bit clock (codec is slave) + fsync "codec_slave"# platform is master of fsync (codec is slave) } SectionLink."Codec" { diff --git a/src/topology/pcm.c b/src/topology/pcm.c index bb47b9af..d0395182 100644 --- a/src/topology/pcm.c +++ b/src/topology/pcm.c @@ -1141,8 +1141,19 @@ int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg, if (snd_config_get_string(n, ) < 0) return -EINVAL; - if (!strcmp(val, "master")) - hw_cfg->bclk_master = true; +
[PATCH, alsa-lib, v3 1/2] ASoC: topology: Fix bclk and fsync inversion in set_link_hw_format()
The values of bclk and fsync are inverted WRT the codec. But the existing solution already works for Broadwell, see the alsa-lib config: `alsa-lib/src/conf/topology/broadwell/broadwell.conf` This commit provides the backwards-compatible solution to fix this misuse. This commit goes in pair with the corresponding patch for linux. Signed-off-by: Kirill Marinushkin Tested-by: Pan Xiuli Tested-by: Pierre-Louis Bossart Cc: Jaroslav Kysela Cc: Takashi Iwai Cc: Mark Brown Cc: Liam Girdwood Cc: linux-kernel@vger.kernel.org Cc: alsa-de...@alsa-project.org --- include/sound/asoc.h | 16 ++-- include/topology.h | 4 ++-- src/conf/topology/broadwell/broadwell.conf | 4 ++-- src/topology/pcm.c | 30 ++ 4 files changed, 44 insertions(+), 10 deletions(-) diff --git a/include/sound/asoc.h b/include/sound/asoc.h index 0f5d9f9a..89b00703 100644 --- a/include/sound/asoc.h +++ b/include/sound/asoc.h @@ -156,6 +156,18 @@ #define SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_SAMPLEBITS(1 << 2) #define SND_SOC_TPLG_LNK_FLGBIT_VOICE_WAKEUP(1 << 3) +/* DAI topology BCLK parameter + * For the backwards capability, by default codec is bclk master + */ +#define SND_SOC_TPLG_BCLK_CM 0 /* codec is bclk master */ +#define SND_SOC_TPLG_BCLK_CS 1 /* codec is bclk slave */ + +/* DAI topology FSYNC parameter + * For the backwards capability, by default codec is fsync master + */ +#define SND_SOC_TPLG_FSYNC_CM 0 /* codec is fsync master */ +#define SND_SOC_TPLG_FSYNC_CS 1 /* codec is fsync slave */ + /* * Block Header. * This header precedes all object and object arrays below. @@ -311,8 +323,8 @@ struct snd_soc_tplg_hw_config { __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 bclk_master; /* SND_SOC_TPLG_BCLK_ value */ + __u8 fsync_master; /* SND_SOC_TPLG_FSYNC_ value */ __u8 mclk_direction;/* 0 for input, 1 for output */ __le16 reserved;/* for 32bit alignment */ __le32 mclk_rate; /* MCLK or SYSCLK freqency in Hz */ diff --git a/include/topology.h b/include/topology.h index 8779da4d..5d7b46df 100644 --- a/include/topology.h +++ b/include/topology.h @@ -1000,8 +1000,8 @@ struct snd_tplg_hw_config_template { unsigned char clock_gated; /* 1 if clock can be gated to save power */ unsigned char invert_bclk; /* 1 for inverted BCLK, 0 for normal */ unsigned char invert_fsync;/* 1 for inverted frame clock, 0 for normal */ - unsigned char bclk_master; /* 1 for master of BCLK, 0 for slave */ - unsigned char fsync_master;/* 1 for master of FSYNC, 0 for slave */ + unsigned char bclk_master; /* SND_SOC_TPLG_BCLK_ value */ + unsigned char fsync_master;/* SND_SOC_TPLG_FSYNC_ value */ unsigned char mclk_direction; /* 0 for input, 1 for output */ unsigned short reserved;/* for 32bit alignment */ unsigned int mclk_rate; /* MCLK or SYSCLK freqency in Hz */ diff --git a/src/conf/topology/broadwell/broadwell.conf b/src/conf/topology/broadwell/broadwell.conf index b8405d93..09fc4daa 100644 --- a/src/conf/topology/broadwell/broadwell.conf +++ b/src/conf/topology/broadwell/broadwell.conf @@ -393,8 +393,8 @@ SectionGraph."dsp" { SectionHWConfig."CodecHWConfig" { id "1" format "I2S"# physical audio format. - bclk "master" # Platform is master of bit clock - fsync "master" # platform is master of fsync + bclk "codec_slave"# platform is master of bit clock (codec is slave) + fsync "codec_slave"# platform is master of fsync (codec is slave) } SectionLink."Codec" { diff --git a/src/topology/pcm.c b/src/topology/pcm.c index bb47b9af..d0395182 100644 --- a/src/topology/pcm.c +++ b/src/topology/pcm.c @@ -1141,8 +1141,19 @@ int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg, if (snd_config_get_string(n, ) < 0) return -EINVAL; - if (!strcmp(val, "master")) - hw_cfg->bclk_master = true; + if (!strcmp(val, "master")) { + /* For backwards capability, +* "master" == "codec is slave" +*/ +
[PATCH, alsa-lib, v3 2/2] ASoC: topology: Add missing clock gating parameter when parsing hw_configs
Clock gating parameter is a part of `dai_fmt`. It is supported by `alsa-lib` when creating a topology binary file, but ignored by kernel when loading this topology file. After applying this commit, the clock gating parameter is not ignored any more. This solution is backwards compatible. The existing behaviour is not broken, because by default the parameter value is 0 and is ignored. snd_soc_tplg_hw_config.clock_gated = 0 => no effect snd_soc_tplg_hw_config.clock_gated = 1 => SND_SOC_DAIFMT_GATED snd_soc_tplg_hw_config.clock_gated = 2 => SND_SOC_DAIFMT_CONT For example, the following config, based on alsa-lib/src/conf/topology/broadwell/broadwell.conf, is now supported: SectionHWConfig."CodecHWConfig" { id "1" format "I2S"# physical audio format. pm_gate_clocks "true" # clock can be gated } SectionLink."Codec" { # used for binding to the physical link id "0" hw_configs [ "CodecHWConfig" ] default_hw_conf_id "1" } Signed-off-by: Kirill Marinushkin <k.marinush...@gmail.com> Cc: Jaroslav Kysela <pe...@perex.cz> Cc: Takashi Iwai <ti...@suse.de> Cc: Mark Brown <broo...@kernel.org> Cc: Pan Xiuli <xiuli@linux.intel.com> Cc: Pierre-Louis Bossart <pierre-louis.boss...@linux.intel.com> Cc: Liam Girdwood <liam.r.girdw...@linux.intel.com> Cc: linux-kernel@vger.kernel.org Cc: alsa-de...@alsa-project.org --- include/sound/asoc.h | 7 ++- include/topology.h | 2 +- src/topology/pcm.c | 6 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/include/sound/asoc.h b/include/sound/asoc.h index 89b00703..297e837c 100644 --- a/include/sound/asoc.h +++ b/include/sound/asoc.h @@ -135,6 +135,11 @@ #define SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_CHANNELS (1 << 1) #define SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_SAMPLEBITS(1 << 2) +/* DAI clock gating */ +#define SND_SOC_TPLG_DAI_CLK_GATE_UNDEFINED0 +#define SND_SOC_TPLG_DAI_CLK_GATE_GATED1 +#define SND_SOC_TPLG_DAI_CLK_GATE_CONT 2 + /* DAI physical PCM data formats. * Add new formats to the end of the list. */ @@ -320,7 +325,7 @@ 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 clock_gated; /* SND_SOC_TPLG_DAI_CLK_GATE_ value */ __u8 invert_bclk; /* 1 for inverted BCLK, 0 for normal */ __u8 invert_fsync; /* 1 for inverted frame clock, 0 for normal */ __u8 bclk_master; /* SND_SOC_TPLG_BCLK_ value */ diff --git a/include/topology.h b/include/topology.h index 5d7b46df..3793115c 100644 --- a/include/topology.h +++ b/include/topology.h @@ -997,7 +997,7 @@ struct snd_tplg_pcm_template { struct snd_tplg_hw_config_template { int id; /* unique ID - - used to match */ unsigned int fmt; /* SND_SOC_DAI_FORMAT_ format value */ - unsigned char clock_gated; /* 1 if clock can be gated to save power */ + unsigned char clock_gated; /* SND_SOC_TPLG_DAI_CLK_GATE_ value */ unsigned char invert_bclk; /* 1 for inverted BCLK, 0 for normal */ unsigned char invert_fsync;/* 1 for inverted frame clock, 0 for normal */ unsigned char bclk_master; /* SND_SOC_TPLG_BCLK_ value */ diff --git a/src/topology/pcm.c b/src/topology/pcm.c index d0395182..b53f6b03 100644 --- a/src/topology/pcm.c +++ b/src/topology/pcm.c @@ -1233,7 +1233,11 @@ int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg, return -EINVAL; if (!strcmp(val, "true")) - hw_cfg->clock_gated = true; + hw_cfg->clock_gated = + SND_SOC_TPLG_DAI_CLK_GATE_GATED; + else + hw_cfg->clock_gated = + SND_SOC_TPLG_DAI_CLK_GATE_CONT; continue; } -- 2.13.6
[PATCH, alsa-lib, v3 2/2] ASoC: topology: Add missing clock gating parameter when parsing hw_configs
Clock gating parameter is a part of `dai_fmt`. It is supported by `alsa-lib` when creating a topology binary file, but ignored by kernel when loading this topology file. After applying this commit, the clock gating parameter is not ignored any more. This solution is backwards compatible. The existing behaviour is not broken, because by default the parameter value is 0 and is ignored. snd_soc_tplg_hw_config.clock_gated = 0 => no effect snd_soc_tplg_hw_config.clock_gated = 1 => SND_SOC_DAIFMT_GATED snd_soc_tplg_hw_config.clock_gated = 2 => SND_SOC_DAIFMT_CONT For example, the following config, based on alsa-lib/src/conf/topology/broadwell/broadwell.conf, is now supported: SectionHWConfig."CodecHWConfig" { id "1" format "I2S"# physical audio format. pm_gate_clocks "true" # clock can be gated } SectionLink."Codec" { # used for binding to the physical link id "0" hw_configs [ "CodecHWConfig" ] default_hw_conf_id "1" } Signed-off-by: Kirill Marinushkin Cc: Jaroslav Kysela Cc: Takashi Iwai Cc: Mark Brown Cc: Pan Xiuli Cc: Pierre-Louis Bossart Cc: Liam Girdwood Cc: linux-kernel@vger.kernel.org Cc: alsa-de...@alsa-project.org --- include/sound/asoc.h | 7 ++- include/topology.h | 2 +- src/topology/pcm.c | 6 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/include/sound/asoc.h b/include/sound/asoc.h index 89b00703..297e837c 100644 --- a/include/sound/asoc.h +++ b/include/sound/asoc.h @@ -135,6 +135,11 @@ #define SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_CHANNELS (1 << 1) #define SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_SAMPLEBITS(1 << 2) +/* DAI clock gating */ +#define SND_SOC_TPLG_DAI_CLK_GATE_UNDEFINED0 +#define SND_SOC_TPLG_DAI_CLK_GATE_GATED1 +#define SND_SOC_TPLG_DAI_CLK_GATE_CONT 2 + /* DAI physical PCM data formats. * Add new formats to the end of the list. */ @@ -320,7 +325,7 @@ 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 clock_gated; /* SND_SOC_TPLG_DAI_CLK_GATE_ value */ __u8 invert_bclk; /* 1 for inverted BCLK, 0 for normal */ __u8 invert_fsync; /* 1 for inverted frame clock, 0 for normal */ __u8 bclk_master; /* SND_SOC_TPLG_BCLK_ value */ diff --git a/include/topology.h b/include/topology.h index 5d7b46df..3793115c 100644 --- a/include/topology.h +++ b/include/topology.h @@ -997,7 +997,7 @@ struct snd_tplg_pcm_template { struct snd_tplg_hw_config_template { int id; /* unique ID - - used to match */ unsigned int fmt; /* SND_SOC_DAI_FORMAT_ format value */ - unsigned char clock_gated; /* 1 if clock can be gated to save power */ + unsigned char clock_gated; /* SND_SOC_TPLG_DAI_CLK_GATE_ value */ unsigned char invert_bclk; /* 1 for inverted BCLK, 0 for normal */ unsigned char invert_fsync;/* 1 for inverted frame clock, 0 for normal */ unsigned char bclk_master; /* SND_SOC_TPLG_BCLK_ value */ diff --git a/src/topology/pcm.c b/src/topology/pcm.c index d0395182..b53f6b03 100644 --- a/src/topology/pcm.c +++ b/src/topology/pcm.c @@ -1233,7 +1233,11 @@ int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg, return -EINVAL; if (!strcmp(val, "true")) - hw_cfg->clock_gated = true; + hw_cfg->clock_gated = + SND_SOC_TPLG_DAI_CLK_GATE_GATED; + else + hw_cfg->clock_gated = + SND_SOC_TPLG_DAI_CLK_GATE_CONT; continue; } -- 2.13.6
[PATCH, alsa-lib, v3 0/2] alsa-lib: ASoC: topology: Improve parsing hw_configs
Below is the alsa-lib part of the patch-series "ASoC: topology: Improve parsing hw_configs" Kirill Marinushkin (2): ASoC: topology: Fix bclk and fsync inversion in set_link_hw_format() ASoC: topology: Add missing clock gating parameter when parsing hw_configs include/sound/asoc.h | 23 --- include/topology.h | 6 ++--- src/conf/topology/broadwell/broadwell.conf | 4 ++-- src/topology/pcm.c | 36 +- 4 files changed, 56 insertions(+), 13 deletions(-) -- 2.13.6
[PATCH, alsa-lib, v3 0/2] alsa-lib: ASoC: topology: Improve parsing hw_configs
Below is the alsa-lib part of the patch-series "ASoC: topology: Improve parsing hw_configs" Kirill Marinushkin (2): ASoC: topology: Fix bclk and fsync inversion in set_link_hw_format() ASoC: topology: Add missing clock gating parameter when parsing hw_configs include/sound/asoc.h | 23 --- include/topology.h | 6 ++--- src/conf/topology/broadwell/broadwell.conf | 4 ++-- src/topology/pcm.c | 36 +- 4 files changed, 56 insertions(+), 13 deletions(-) -- 2.13.6
[PATCH v3 2/2] ASoC: topology: Add missing clock gating parameter when parsing hw_configs
Clock gating parameter is a part of `dai_fmt`. It is supported by `alsa-lib` when creating a topology binary file, but ignored by kernel when loading this topology file. After applying this commit, the clock gating parameter is not ignored any more. This solution is backwards compatible. The existing behaviour is not broken, because by default the parameter value is 0 and is ignored. snd_soc_tplg_hw_config.clock_gated = 0 => no effect snd_soc_tplg_hw_config.clock_gated = 1 => SND_SOC_DAIFMT_GATED snd_soc_tplg_hw_config.clock_gated = 2 => SND_SOC_DAIFMT_CONT For example, the following config, based on alsa-lib/src/conf/topology/broadwell/broadwell.conf, is now supported: SectionHWConfig."CodecHWConfig" { id "1" format "I2S"# physical audio format. pm_gate_clocks "true" # clock can be gated } SectionLink."Codec" { # used for binding to the physical link id "0" hw_configs [ "CodecHWConfig" ] default_hw_conf_id "1" } Signed-off-by: Kirill Marinushkin <k.marinush...@gmail.com> Cc: Jaroslav Kysela <pe...@perex.cz> Cc: Takashi Iwai <ti...@suse.de> Cc: Mark Brown <broo...@kernel.org> Cc: Pan Xiuli <xiuli@linux.intel.com> Cc: Pierre-Louis Bossart <pierre-louis.boss...@linux.intel.com> Cc: Liam Girdwood <liam.r.girdw...@linux.intel.com> Cc: linux-kernel@vger.kernel.org Cc: alsa-de...@alsa-project.org --- include/uapi/sound/asoc.h | 7 ++- sound/soc/soc-topology.c | 7 +++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/uapi/sound/asoc.h b/include/uapi/sound/asoc.h index f0e5e21efa54..f3c4b46e39d8 100644 --- a/include/uapi/sound/asoc.h +++ b/include/uapi/sound/asoc.h @@ -139,6 +139,11 @@ #define SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_CHANNELS (1 << 1) #define SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_SAMPLEBITS(1 << 2) +/* DAI clock gating */ +#define SND_SOC_TPLG_DAI_CLK_GATE_UNDEFINED0 +#define SND_SOC_TPLG_DAI_CLK_GATE_GATED1 +#define SND_SOC_TPLG_DAI_CLK_GATE_CONT 2 + /* DAI physical PCM data formats. * Add new formats to the end of the list. */ @@ -324,7 +329,7 @@ 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 clock_gated; /* SND_SOC_TPLG_DAI_CLK_GATE_ value */ __u8 invert_bclk; /* 1 for inverted BCLK, 0 for normal */ __u8 invert_fsync; /* 1 for inverted frame clock, 0 for normal */ __u8 bclk_master; /* SND_SOC_TPLG_BCLK_ value */ diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c index c5bdc673b195..04f834e6a6b5 100644 --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -1981,6 +1981,13 @@ static void set_link_hw_format(struct snd_soc_dai_link *link, link->dai_fmt = hw_config->fmt & SND_SOC_DAIFMT_FORMAT_MASK; + /* clock gating */ + if (hw_config->clock_gated == SND_SOC_TPLG_DAI_CLK_GATE_GATED) + link->dai_fmt |= SND_SOC_DAIFMT_GATED; + else if (hw_config->clock_gated == +SND_SOC_TPLG_DAI_CLK_GATE_CONT) + link->dai_fmt |= SND_SOC_DAIFMT_CONT; + /* clock signal polarity */ invert_bclk = hw_config->invert_bclk; invert_fsync = hw_config->invert_fsync; -- 2.13.6
[PATCH v3 2/2] ASoC: topology: Add missing clock gating parameter when parsing hw_configs
Clock gating parameter is a part of `dai_fmt`. It is supported by `alsa-lib` when creating a topology binary file, but ignored by kernel when loading this topology file. After applying this commit, the clock gating parameter is not ignored any more. This solution is backwards compatible. The existing behaviour is not broken, because by default the parameter value is 0 and is ignored. snd_soc_tplg_hw_config.clock_gated = 0 => no effect snd_soc_tplg_hw_config.clock_gated = 1 => SND_SOC_DAIFMT_GATED snd_soc_tplg_hw_config.clock_gated = 2 => SND_SOC_DAIFMT_CONT For example, the following config, based on alsa-lib/src/conf/topology/broadwell/broadwell.conf, is now supported: SectionHWConfig."CodecHWConfig" { id "1" format "I2S"# physical audio format. pm_gate_clocks "true" # clock can be gated } SectionLink."Codec" { # used for binding to the physical link id "0" hw_configs [ "CodecHWConfig" ] default_hw_conf_id "1" } Signed-off-by: Kirill Marinushkin Cc: Jaroslav Kysela Cc: Takashi Iwai Cc: Mark Brown Cc: Pan Xiuli Cc: Pierre-Louis Bossart Cc: Liam Girdwood Cc: linux-kernel@vger.kernel.org Cc: alsa-de...@alsa-project.org --- include/uapi/sound/asoc.h | 7 ++- sound/soc/soc-topology.c | 7 +++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/uapi/sound/asoc.h b/include/uapi/sound/asoc.h index f0e5e21efa54..f3c4b46e39d8 100644 --- a/include/uapi/sound/asoc.h +++ b/include/uapi/sound/asoc.h @@ -139,6 +139,11 @@ #define SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_CHANNELS (1 << 1) #define SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_SAMPLEBITS(1 << 2) +/* DAI clock gating */ +#define SND_SOC_TPLG_DAI_CLK_GATE_UNDEFINED0 +#define SND_SOC_TPLG_DAI_CLK_GATE_GATED1 +#define SND_SOC_TPLG_DAI_CLK_GATE_CONT 2 + /* DAI physical PCM data formats. * Add new formats to the end of the list. */ @@ -324,7 +329,7 @@ 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 clock_gated; /* SND_SOC_TPLG_DAI_CLK_GATE_ value */ __u8 invert_bclk; /* 1 for inverted BCLK, 0 for normal */ __u8 invert_fsync; /* 1 for inverted frame clock, 0 for normal */ __u8 bclk_master; /* SND_SOC_TPLG_BCLK_ value */ diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c index c5bdc673b195..04f834e6a6b5 100644 --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -1981,6 +1981,13 @@ static void set_link_hw_format(struct snd_soc_dai_link *link, link->dai_fmt = hw_config->fmt & SND_SOC_DAIFMT_FORMAT_MASK; + /* clock gating */ + if (hw_config->clock_gated == SND_SOC_TPLG_DAI_CLK_GATE_GATED) + link->dai_fmt |= SND_SOC_DAIFMT_GATED; + else if (hw_config->clock_gated == +SND_SOC_TPLG_DAI_CLK_GATE_CONT) + link->dai_fmt |= SND_SOC_DAIFMT_CONT; + /* clock signal polarity */ invert_bclk = hw_config->invert_bclk; invert_fsync = hw_config->invert_fsync; -- 2.13.6
[PATCH v3 1/2] ASoC: topology: Fix bclk and fsync inversion in set_link_hw_format()
The values of bclk and fsync are inverted WRT the codec. But the existing solution already works for Broadwell, see the alsa-lib config: `alsa-lib/src/conf/topology/broadwell/broadwell.conf` This commit provides the backwards-compatible solution to fix this misuse. Signed-off-by: Kirill Marinushkin <k.marinush...@gmail.com> Tested-by: Pan Xiuli <xiuli@linux.intel.com> Tested-by: Pierre-Louis Bossart <pierre-louis.boss...@linux.intel.com> Cc: Jaroslav Kysela <pe...@perex.cz> Cc: Takashi Iwai <ti...@suse.de> Cc: Mark Brown <broo...@kernel.org> Cc: Liam Girdwood <liam.r.girdw...@linux.intel.com> Cc: linux-kernel@vger.kernel.org Cc: alsa-de...@alsa-project.org --- include/uapi/sound/asoc.h | 16 ++-- sound/soc/soc-topology.c | 12 +++- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/include/uapi/sound/asoc.h b/include/uapi/sound/asoc.h index 69c37ecbff7e..f0e5e21efa54 100644 --- a/include/uapi/sound/asoc.h +++ b/include/uapi/sound/asoc.h @@ -160,6 +160,18 @@ #define SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_SAMPLEBITS(1 << 2) #define SND_SOC_TPLG_LNK_FLGBIT_VOICE_WAKEUP(1 << 3) +/* DAI topology BCLK parameter + * For the backwards capability, by default codec is bclk master + */ +#define SND_SOC_TPLG_BCLK_CM 0 /* codec is bclk master */ +#define SND_SOC_TPLG_BCLK_CS 1 /* codec is bclk slave */ + +/* DAI topology FSYNC parameter + * For the backwards capability, by default codec is fsync master + */ +#define SND_SOC_TPLG_FSYNC_CM 0 /* codec is fsync master */ +#define SND_SOC_TPLG_FSYNC_CS 1 /* codec is fsync slave */ + /* * Block Header. * This header precedes all object and object arrays below. @@ -315,8 +327,8 @@ struct snd_soc_tplg_hw_config { __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 bclk_master; /* SND_SOC_TPLG_BCLK_ value */ + __u8 fsync_master; /* SND_SOC_TPLG_FSYNC_ value */ __u8 mclk_direction;/* 0 for input, 1 for output */ __le16 reserved;/* for 32bit alignment */ __le32 mclk_rate; /* MCLK or SYSCLK freqency in Hz */ diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c index 01a50413c66f..c5bdc673b195 100644 --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -1994,13 +1994,15 @@ static void set_link_hw_format(struct snd_soc_dai_link *link, 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) + bclk_master = (hw_config->bclk_master == + SND_SOC_TPLG_BCLK_CM); + fsync_master = (hw_config->fsync_master == + SND_SOC_TPLG_FSYNC_CM); + 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_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; -- 2.13.6