diff mbox

[1/3] ASoC: sun4i-i2s: Add set_tdm_slot functionality

Message ID 20180124141101.12867-2-codekipper@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Code Kipper Jan. 24, 2018, 2:10 p.m. UTC
From: Marcus Cooper <codekipper@gmail.com>

Some codecs require a different amount of a bit clocks per frame than
what is calculated by the sample width. Use the tdm slot bindings to
provide this mechanism.

Signed-off-by: Marcus Cooper <codekipper@gmail.com>
---
 sound/soc/sunxi/sun4i-i2s.c | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

Comments

Chen-Yu Tsai Jan. 29, 2018, 1:50 a.m. UTC | #1
On Wed, Jan 24, 2018 at 10:10 PM,  <codekipper@gmail.com> wrote:
> From: Marcus Cooper <codekipper@gmail.com>
>
> Some codecs require a different amount of a bit clocks per frame than
> what is calculated by the sample width. Use the tdm slot bindings to
> provide this mechanism.
>
> Signed-off-by: Marcus Cooper <codekipper@gmail.com>
> ---
>  sound/soc/sunxi/sun4i-i2s.c | 23 +++++++++++++++++++++--
>  1 file changed, 21 insertions(+), 2 deletions(-)
>
> diff --git a/sound/soc/sunxi/sun4i-i2s.c b/sound/soc/sunxi/sun4i-i2s.c
> index dca1143c1150..d7a9141514cf 100644
> --- a/sound/soc/sunxi/sun4i-i2s.c
> +++ b/sound/soc/sunxi/sun4i-i2s.c
> @@ -96,6 +96,7 @@
>  #define SUN8I_I2S_CTRL_BCLK_OUT                        BIT(18)
>  #define SUN8I_I2S_CTRL_LRCK_OUT                        BIT(17)
>
> +#define SUN8I_I2S_FMT0_LRCK_MAX_PERIOD         (GENMASK(17, 8) >> 8)
>  #define SUN8I_I2S_FMT0_LRCK_PERIOD_MASK                GENMASK(17, 8)
>  #define SUN8I_I2S_FMT0_LRCK_PERIOD(period)     ((period - 1) << 8)
>
> @@ -193,6 +194,9 @@ struct sun4i_i2s {
>         struct regmap_field     *field_rxchansel;
>
>         const struct sun4i_i2s_quirks   *variant;
> +
> +       unsigned int    tdm_slots;
> +       unsigned int    slot_width;
>  };
>
>  struct sun4i_i2s_clk_div {
> @@ -344,7 +348,7 @@ static int sun4i_i2s_set_clk_rate(struct snd_soc_dai *dai,
>         if (i2s->variant->has_fmt_set_lrck_period)
>                 regmap_update_bits(i2s->regmap, SUN4I_I2S_FMT0_REG,
>                                    SUN8I_I2S_FMT0_LRCK_PERIOD_MASK,
> -                                  SUN8I_I2S_FMT0_LRCK_PERIOD(32));
> +                                  SUN8I_I2S_FMT0_LRCK_PERIOD(word_size));
>
>         return 0;
>  }
> @@ -418,7 +422,8 @@ static int sun4i_i2s_hw_params(struct snd_pcm_substream *substream,
>                            sr + i2s->variant->fmt_offset);
>
>         return sun4i_i2s_set_clk_rate(dai, params_rate(params),
> -                                     params_width(params));
> +                                     i2s->tdm_slots ?
> +                                     i2s->slot_width : params_width(params));
>  }
>
>  static int sun4i_i2s_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
> @@ -691,6 +696,19 @@ static int sun4i_i2s_set_sysclk(struct snd_soc_dai *dai, int clk_id,
>         return 0;
>  }
>
> +static int sun4i_i2s_set_dai_tdm_slot(struct snd_soc_dai *dai,
> +       unsigned int tx_mask, unsigned int rx_mask,
> +       int slots, int width)
> +{
> +       struct sun4i_i2s *i2s = snd_soc_dai_get_drvdata(dai);
> +
> +       i2s->tdm_slots = slots;
> +
> +       i2s->slot_width = width;
> +
> +       return 0;
> +}
> +

IIRC some of the DAI controllers actually support TDM. Would this
change conflict with that in the future?

Thanks
ChenYu

>  static const struct snd_soc_dai_ops sun4i_i2s_dai_ops = {
>         .hw_params      = sun4i_i2s_hw_params,
>         .set_fmt        = sun4i_i2s_set_fmt,
> @@ -698,6 +716,7 @@ static const struct snd_soc_dai_ops sun4i_i2s_dai_ops = {
>         .shutdown       = sun4i_i2s_shutdown,
>         .startup        = sun4i_i2s_startup,
>         .trigger        = sun4i_i2s_trigger,
> +       .set_tdm_slot   = sun4i_i2s_set_dai_tdm_slot,
>  };
>
>  static int sun4i_i2s_dai_probe(struct snd_soc_dai *dai)
> --
> 2.16.0
>
> --
> You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Code Kipper Jan. 29, 2018, 7:34 a.m. UTC | #2
On 29 January 2018 at 02:50, Chen-Yu Tsai <wens@csie.org> wrote:
> On Wed, Jan 24, 2018 at 10:10 PM,  <codekipper@gmail.com> wrote:
>> From: Marcus Cooper <codekipper@gmail.com>
>>
>> Some codecs require a different amount of a bit clocks per frame than
>> what is calculated by the sample width. Use the tdm slot bindings to
>> provide this mechanism.
>>
>> Signed-off-by: Marcus Cooper <codekipper@gmail.com>
>> ---
>>  sound/soc/sunxi/sun4i-i2s.c | 23 +++++++++++++++++++++--
>>  1 file changed, 21 insertions(+), 2 deletions(-)
>>
>> diff --git a/sound/soc/sunxi/sun4i-i2s.c b/sound/soc/sunxi/sun4i-i2s.c
>> index dca1143c1150..d7a9141514cf 100644
>> --- a/sound/soc/sunxi/sun4i-i2s.c
>> +++ b/sound/soc/sunxi/sun4i-i2s.c
>> @@ -96,6 +96,7 @@
>>  #define SUN8I_I2S_CTRL_BCLK_OUT                        BIT(18)
>>  #define SUN8I_I2S_CTRL_LRCK_OUT                        BIT(17)
>>
>> +#define SUN8I_I2S_FMT0_LRCK_MAX_PERIOD         (GENMASK(17, 8) >> 8)
>>  #define SUN8I_I2S_FMT0_LRCK_PERIOD_MASK                GENMASK(17, 8)
>>  #define SUN8I_I2S_FMT0_LRCK_PERIOD(period)     ((period - 1) << 8)
>>
>> @@ -193,6 +194,9 @@ struct sun4i_i2s {
>>         struct regmap_field     *field_rxchansel;
>>
>>         const struct sun4i_i2s_quirks   *variant;
>> +
>> +       unsigned int    tdm_slots;
>> +       unsigned int    slot_width;
>>  };
>>
>>  struct sun4i_i2s_clk_div {
>> @@ -344,7 +348,7 @@ static int sun4i_i2s_set_clk_rate(struct snd_soc_dai *dai,
>>         if (i2s->variant->has_fmt_set_lrck_period)
>>                 regmap_update_bits(i2s->regmap, SUN4I_I2S_FMT0_REG,
>>                                    SUN8I_I2S_FMT0_LRCK_PERIOD_MASK,
>> -                                  SUN8I_I2S_FMT0_LRCK_PERIOD(32));
>> +                                  SUN8I_I2S_FMT0_LRCK_PERIOD(word_size));
>>
>>         return 0;
>>  }
>> @@ -418,7 +422,8 @@ static int sun4i_i2s_hw_params(struct snd_pcm_substream *substream,
>>                            sr + i2s->variant->fmt_offset);
>>
>>         return sun4i_i2s_set_clk_rate(dai, params_rate(params),
>> -                                     params_width(params));
>> +                                     i2s->tdm_slots ?
>> +                                     i2s->slot_width : params_width(params));
>>  }
>>
>>  static int sun4i_i2s_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
>> @@ -691,6 +696,19 @@ static int sun4i_i2s_set_sysclk(struct snd_soc_dai *dai, int clk_id,
>>         return 0;
>>  }
>>
>> +static int sun4i_i2s_set_dai_tdm_slot(struct snd_soc_dai *dai,
>> +       unsigned int tx_mask, unsigned int rx_mask,
>> +       int slots, int width)
>> +{
>> +       struct sun4i_i2s *i2s = snd_soc_dai_get_drvdata(dai);
>> +
>> +       i2s->tdm_slots = slots;
>> +
>> +       i2s->slot_width = width;
>> +
>> +       return 0;
>> +}
>> +
>
> IIRC some of the DAI controllers actually support TDM. Would this
> change conflict with that in the future?

Hi Wens,
I'm not sure..I was looking for a clean example of being able to
override the number of bclks in the lrclk width and some other
devices(Rpi) were doing it this way.  I open to suggestions,
BR,
CK
>
> Thanks
> ChenYu
>
>>  static const struct snd_soc_dai_ops sun4i_i2s_dai_ops = {
>>         .hw_params      = sun4i_i2s_hw_params,
>>         .set_fmt        = sun4i_i2s_set_fmt,
>> @@ -698,6 +716,7 @@ static const struct snd_soc_dai_ops sun4i_i2s_dai_ops = {
>>         .shutdown       = sun4i_i2s_shutdown,
>>         .startup        = sun4i_i2s_startup,
>>         .trigger        = sun4i_i2s_trigger,
>> +       .set_tdm_slot   = sun4i_i2s_set_dai_tdm_slot,
>>  };
>>
>>  static int sun4i_i2s_dai_probe(struct snd_soc_dai *dai)
>> --
>> 2.16.0
>>
>> --
>> You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
Chen-Yu Tsai Jan. 29, 2018, 7:38 a.m. UTC | #3
On Mon, Jan 29, 2018 at 3:34 PM, Code Kipper <codekipper@gmail.com> wrote:
> On 29 January 2018 at 02:50, Chen-Yu Tsai <wens@csie.org> wrote:
>> On Wed, Jan 24, 2018 at 10:10 PM,  <codekipper@gmail.com> wrote:
>>> From: Marcus Cooper <codekipper@gmail.com>
>>>
>>> Some codecs require a different amount of a bit clocks per frame than
>>> what is calculated by the sample width. Use the tdm slot bindings to
>>> provide this mechanism.
>>>
>>> Signed-off-by: Marcus Cooper <codekipper@gmail.com>
>>> ---
>>>  sound/soc/sunxi/sun4i-i2s.c | 23 +++++++++++++++++++++--
>>>  1 file changed, 21 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/sound/soc/sunxi/sun4i-i2s.c b/sound/soc/sunxi/sun4i-i2s.c
>>> index dca1143c1150..d7a9141514cf 100644
>>> --- a/sound/soc/sunxi/sun4i-i2s.c
>>> +++ b/sound/soc/sunxi/sun4i-i2s.c
>>> @@ -96,6 +96,7 @@
>>>  #define SUN8I_I2S_CTRL_BCLK_OUT                        BIT(18)
>>>  #define SUN8I_I2S_CTRL_LRCK_OUT                        BIT(17)
>>>
>>> +#define SUN8I_I2S_FMT0_LRCK_MAX_PERIOD         (GENMASK(17, 8) >> 8)
>>>  #define SUN8I_I2S_FMT0_LRCK_PERIOD_MASK                GENMASK(17, 8)
>>>  #define SUN8I_I2S_FMT0_LRCK_PERIOD(period)     ((period - 1) << 8)
>>>
>>> @@ -193,6 +194,9 @@ struct sun4i_i2s {
>>>         struct regmap_field     *field_rxchansel;
>>>
>>>         const struct sun4i_i2s_quirks   *variant;
>>> +
>>> +       unsigned int    tdm_slots;
>>> +       unsigned int    slot_width;
>>>  };
>>>
>>>  struct sun4i_i2s_clk_div {
>>> @@ -344,7 +348,7 @@ static int sun4i_i2s_set_clk_rate(struct snd_soc_dai *dai,
>>>         if (i2s->variant->has_fmt_set_lrck_period)
>>>                 regmap_update_bits(i2s->regmap, SUN4I_I2S_FMT0_REG,
>>>                                    SUN8I_I2S_FMT0_LRCK_PERIOD_MASK,
>>> -                                  SUN8I_I2S_FMT0_LRCK_PERIOD(32));
>>> +                                  SUN8I_I2S_FMT0_LRCK_PERIOD(word_size));
>>>
>>>         return 0;
>>>  }
>>> @@ -418,7 +422,8 @@ static int sun4i_i2s_hw_params(struct snd_pcm_substream *substream,
>>>                            sr + i2s->variant->fmt_offset);
>>>
>>>         return sun4i_i2s_set_clk_rate(dai, params_rate(params),
>>> -                                     params_width(params));
>>> +                                     i2s->tdm_slots ?
>>> +                                     i2s->slot_width : params_width(params));
>>>  }
>>>
>>>  static int sun4i_i2s_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
>>> @@ -691,6 +696,19 @@ static int sun4i_i2s_set_sysclk(struct snd_soc_dai *dai, int clk_id,
>>>         return 0;
>>>  }
>>>
>>> +static int sun4i_i2s_set_dai_tdm_slot(struct snd_soc_dai *dai,
>>> +       unsigned int tx_mask, unsigned int rx_mask,
>>> +       int slots, int width)
>>> +{
>>> +       struct sun4i_i2s *i2s = snd_soc_dai_get_drvdata(dai);
>>> +
>>> +       i2s->tdm_slots = slots;
>>> +
>>> +       i2s->slot_width = width;
>>> +
>>> +       return 0;
>>> +}
>>> +
>>
>> IIRC some of the DAI controllers actually support TDM. Would this
>> change conflict with that in the future?
>
> Hi Wens,
> I'm not sure..I was looking for a clean example of being able to
> override the number of bclks in the lrclk width and some other
> devices(Rpi) were doing it this way.  I open to suggestions,

I'm not familiar with the issue either. If Mark doesn't have any
objections, we could merge it for now, and fix it later if there
are any complications.

BTW, you didn't provide a device tree example (if any) for how
to use this.

ChenYu

> BR,
> CK
>>
>> Thanks
>> ChenYu
>>
>>>  static const struct snd_soc_dai_ops sun4i_i2s_dai_ops = {
>>>         .hw_params      = sun4i_i2s_hw_params,
>>>         .set_fmt        = sun4i_i2s_set_fmt,
>>> @@ -698,6 +716,7 @@ static const struct snd_soc_dai_ops sun4i_i2s_dai_ops = {
>>>         .shutdown       = sun4i_i2s_shutdown,
>>>         .startup        = sun4i_i2s_startup,
>>>         .trigger        = sun4i_i2s_trigger,
>>> +       .set_tdm_slot   = sun4i_i2s_set_dai_tdm_slot,
>>>  };
>>>
>>>  static int sun4i_i2s_dai_probe(struct snd_soc_dai *dai)
>>> --
>>> 2.16.0
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
Code Kipper Jan. 29, 2018, 7:52 a.m. UTC | #4
On 29 January 2018 at 08:38, Chen-Yu Tsai <wens@csie.org> wrote:
> On Mon, Jan 29, 2018 at 3:34 PM, Code Kipper <codekipper@gmail.com> wrote:
>> On 29 January 2018 at 02:50, Chen-Yu Tsai <wens@csie.org> wrote:
>>> On Wed, Jan 24, 2018 at 10:10 PM,  <codekipper@gmail.com> wrote:
>>>> From: Marcus Cooper <codekipper@gmail.com>
>>>>
>>>> Some codecs require a different amount of a bit clocks per frame than
>>>> what is calculated by the sample width. Use the tdm slot bindings to
>>>> provide this mechanism.
>>>>
>>>> Signed-off-by: Marcus Cooper <codekipper@gmail.com>
>>>> ---
>>>>  sound/soc/sunxi/sun4i-i2s.c | 23 +++++++++++++++++++++--
>>>>  1 file changed, 21 insertions(+), 2 deletions(-)
>>>>
>>>> diff --git a/sound/soc/sunxi/sun4i-i2s.c b/sound/soc/sunxi/sun4i-i2s.c
>>>> index dca1143c1150..d7a9141514cf 100644
>>>> --- a/sound/soc/sunxi/sun4i-i2s.c
>>>> +++ b/sound/soc/sunxi/sun4i-i2s.c
>>>> @@ -96,6 +96,7 @@
>>>>  #define SUN8I_I2S_CTRL_BCLK_OUT                        BIT(18)
>>>>  #define SUN8I_I2S_CTRL_LRCK_OUT                        BIT(17)
>>>>
>>>> +#define SUN8I_I2S_FMT0_LRCK_MAX_PERIOD         (GENMASK(17, 8) >> 8)
>>>>  #define SUN8I_I2S_FMT0_LRCK_PERIOD_MASK                GENMASK(17, 8)
>>>>  #define SUN8I_I2S_FMT0_LRCK_PERIOD(period)     ((period - 1) << 8)
>>>>
>>>> @@ -193,6 +194,9 @@ struct sun4i_i2s {
>>>>         struct regmap_field     *field_rxchansel;
>>>>
>>>>         const struct sun4i_i2s_quirks   *variant;
>>>> +
>>>> +       unsigned int    tdm_slots;
>>>> +       unsigned int    slot_width;
>>>>  };
>>>>
>>>>  struct sun4i_i2s_clk_div {
>>>> @@ -344,7 +348,7 @@ static int sun4i_i2s_set_clk_rate(struct snd_soc_dai *dai,
>>>>         if (i2s->variant->has_fmt_set_lrck_period)
>>>>                 regmap_update_bits(i2s->regmap, SUN4I_I2S_FMT0_REG,
>>>>                                    SUN8I_I2S_FMT0_LRCK_PERIOD_MASK,
>>>> -                                  SUN8I_I2S_FMT0_LRCK_PERIOD(32));
>>>> +                                  SUN8I_I2S_FMT0_LRCK_PERIOD(word_size));
>>>>
>>>>         return 0;
>>>>  }
>>>> @@ -418,7 +422,8 @@ static int sun4i_i2s_hw_params(struct snd_pcm_substream *substream,
>>>>                            sr + i2s->variant->fmt_offset);
>>>>
>>>>         return sun4i_i2s_set_clk_rate(dai, params_rate(params),
>>>> -                                     params_width(params));
>>>> +                                     i2s->tdm_slots ?
>>>> +                                     i2s->slot_width : params_width(params));
>>>>  }
>>>>
>>>>  static int sun4i_i2s_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
>>>> @@ -691,6 +696,19 @@ static int sun4i_i2s_set_sysclk(struct snd_soc_dai *dai, int clk_id,
>>>>         return 0;
>>>>  }
>>>>
>>>> +static int sun4i_i2s_set_dai_tdm_slot(struct snd_soc_dai *dai,
>>>> +       unsigned int tx_mask, unsigned int rx_mask,
>>>> +       int slots, int width)
>>>> +{
>>>> +       struct sun4i_i2s *i2s = snd_soc_dai_get_drvdata(dai);
>>>> +
>>>> +       i2s->tdm_slots = slots;
>>>> +
>>>> +       i2s->slot_width = width;
>>>> +
>>>> +       return 0;
>>>> +}
>>>> +
>>>
>>> IIRC some of the DAI controllers actually support TDM. Would this
>>> change conflict with that in the future?
>>
>> Hi Wens,
>> I'm not sure..I was looking for a clean example of being able to
>> override the number of bclks in the lrclk width and some other
>> devices(Rpi) were doing it this way.  I open to suggestions,
>
> I'm not familiar with the issue either. If Mark doesn't have any
> objections, we could merge it for now, and fix it later if there
> are any complications.
>
> BTW, you didn't provide a device tree example (if any) for how
> to use this.

Hi Wens,

here is an example that I use for the Pine64 audio hat.
https://github.com/codekipper/linux-sunxi/commit/faa9dfba955bf71ca23b089b1cb678a14443216f#diff-1473a38b339685d191c5a87aab9c0fdfR80

I've done the same on the A64 for HDMI and analog audio which both use
the i2s and seem to require 32bit LRCK width.

BR,
CK

>
> ChenYu
>
>> BR,
>> CK
>>>
>>> Thanks
>>> ChenYu
>>>
>>>>  static const struct snd_soc_dai_ops sun4i_i2s_dai_ops = {
>>>>         .hw_params      = sun4i_i2s_hw_params,
>>>>         .set_fmt        = sun4i_i2s_set_fmt,
>>>> @@ -698,6 +716,7 @@ static const struct snd_soc_dai_ops sun4i_i2s_dai_ops = {
>>>>         .shutdown       = sun4i_i2s_shutdown,
>>>>         .startup        = sun4i_i2s_startup,
>>>>         .trigger        = sun4i_i2s_trigger,
>>>> +       .set_tdm_slot   = sun4i_i2s_set_dai_tdm_slot,
>>>>  };
>>>>
>>>>  static int sun4i_i2s_dai_probe(struct snd_soc_dai *dai)
>>>> --
>>>> 2.16.0
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe@googlegroups.com.
>>>> For more options, visit https://groups.google.com/d/optout.
Maxime Ripard Jan. 29, 2018, 8:40 a.m. UTC | #5
On Mon, Jan 29, 2018 at 03:38:40PM +0800, Chen-Yu Tsai wrote:
> On Mon, Jan 29, 2018 at 3:34 PM, Code Kipper <codekipper@gmail.com> wrote:
> > On 29 January 2018 at 02:50, Chen-Yu Tsai <wens@csie.org> wrote:
> >> On Wed, Jan 24, 2018 at 10:10 PM,  <codekipper@gmail.com> wrote:
> >>> From: Marcus Cooper <codekipper@gmail.com>
> >>>
> >>> Some codecs require a different amount of a bit clocks per frame than
> >>> what is calculated by the sample width. Use the tdm slot bindings to
> >>> provide this mechanism.
> >>>
> >>> Signed-off-by: Marcus Cooper <codekipper@gmail.com>
> >>> ---
> >>>  sound/soc/sunxi/sun4i-i2s.c | 23 +++++++++++++++++++++--
> >>>  1 file changed, 21 insertions(+), 2 deletions(-)
> >>>
> >>> diff --git a/sound/soc/sunxi/sun4i-i2s.c b/sound/soc/sunxi/sun4i-i2s.c
> >>> index dca1143c1150..d7a9141514cf 100644
> >>> --- a/sound/soc/sunxi/sun4i-i2s.c
> >>> +++ b/sound/soc/sunxi/sun4i-i2s.c
> >>> @@ -96,6 +96,7 @@
> >>>  #define SUN8I_I2S_CTRL_BCLK_OUT                        BIT(18)
> >>>  #define SUN8I_I2S_CTRL_LRCK_OUT                        BIT(17)
> >>>
> >>> +#define SUN8I_I2S_FMT0_LRCK_MAX_PERIOD         (GENMASK(17, 8) >> 8)
> >>>  #define SUN8I_I2S_FMT0_LRCK_PERIOD_MASK                GENMASK(17, 8)
> >>>  #define SUN8I_I2S_FMT0_LRCK_PERIOD(period)     ((period - 1) << 8)
> >>>
> >>> @@ -193,6 +194,9 @@ struct sun4i_i2s {
> >>>         struct regmap_field     *field_rxchansel;
> >>>
> >>>         const struct sun4i_i2s_quirks   *variant;
> >>> +
> >>> +       unsigned int    tdm_slots;
> >>> +       unsigned int    slot_width;
> >>>  };
> >>>
> >>>  struct sun4i_i2s_clk_div {
> >>> @@ -344,7 +348,7 @@ static int sun4i_i2s_set_clk_rate(struct snd_soc_dai *dai,
> >>>         if (i2s->variant->has_fmt_set_lrck_period)
> >>>                 regmap_update_bits(i2s->regmap, SUN4I_I2S_FMT0_REG,
> >>>                                    SUN8I_I2S_FMT0_LRCK_PERIOD_MASK,
> >>> -                                  SUN8I_I2S_FMT0_LRCK_PERIOD(32));
> >>> +                                  SUN8I_I2S_FMT0_LRCK_PERIOD(word_size));
> >>>
> >>>         return 0;
> >>>  }
> >>> @@ -418,7 +422,8 @@ static int sun4i_i2s_hw_params(struct snd_pcm_substream *substream,
> >>>                            sr + i2s->variant->fmt_offset);
> >>>
> >>>         return sun4i_i2s_set_clk_rate(dai, params_rate(params),
> >>> -                                     params_width(params));
> >>> +                                     i2s->tdm_slots ?
> >>> +                                     i2s->slot_width : params_width(params));
> >>>  }
> >>>
> >>>  static int sun4i_i2s_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
> >>> @@ -691,6 +696,19 @@ static int sun4i_i2s_set_sysclk(struct snd_soc_dai *dai, int clk_id,
> >>>         return 0;
> >>>  }
> >>>
> >>> +static int sun4i_i2s_set_dai_tdm_slot(struct snd_soc_dai *dai,
> >>> +       unsigned int tx_mask, unsigned int rx_mask,
> >>> +       int slots, int width)
> >>> +{
> >>> +       struct sun4i_i2s *i2s = snd_soc_dai_get_drvdata(dai);
> >>> +
> >>> +       i2s->tdm_slots = slots;
> >>> +
> >>> +       i2s->slot_width = width;
> >>> +
> >>> +       return 0;
> >>> +}
> >>> +
> >>
> >> IIRC some of the DAI controllers actually support TDM. Would this
> >> change conflict with that in the future?
> >
> > Hi Wens,
> > I'm not sure..I was looking for a clean example of being able to
> > override the number of bclks in the lrclk width and some other
> > devices(Rpi) were doing it this way.  I open to suggestions,
> 
> I'm not familiar with the issue either. If Mark doesn't have any
> objections, we could merge it for now, and fix it later if there
> are any complications.
> 
> BTW, you didn't provide a device tree example (if any) for how
> to use this.

Could it be that it's just not i2s but some other format?

Maxime
Mark Brown Jan. 29, 2018, 11:32 a.m. UTC | #6
On Mon, Jan 29, 2018 at 08:34:00AM +0100, Code Kipper wrote:

> I'm not sure..I was looking for a clean example of being able to
> override the number of bclks in the lrclk width and some other
> devices(Rpi) were doing it this way.  I open to suggestions,

You're looking for set_bclk_ratio() I think.
Code Kipper Jan. 29, 2018, 12:28 p.m. UTC | #7
On 29 January 2018 at 12:32, Mark Brown <broonie@kernel.org> wrote:
> On Mon, Jan 29, 2018 at 08:34:00AM +0100, Code Kipper wrote:
>
>> I'm not sure..I was looking for a clean example of being able to
>> override the number of bclks in the lrclk width and some other
>> devices(Rpi) were doing it this way.  I open to suggestions,
>
> You're looking for set_bclk_ratio() I think.
Hi Mark,
I'm looking for a mechanism to be able to override the bclk width
(usually it's based on param_width) from the device tree. The tdm slot
functionality looked just what I needed.
BR,
CK
Mark Brown Jan. 29, 2018, 12:31 p.m. UTC | #8
On Mon, Jan 29, 2018 at 01:28:51PM +0100, Code Kipper wrote:
> On 29 January 2018 at 12:32, Mark Brown <broonie@kernel.org> wrote:

> > You're looking for set_bclk_ratio() I think.

> I'm looking for a mechanism to be able to override the bclk width
> (usually it's based on param_width) from the device tree. The tdm slot
> functionality looked just what I needed.

The simple and graph cards have support for bclk ratio configuration as
well.
diff mbox

Patch

diff --git a/sound/soc/sunxi/sun4i-i2s.c b/sound/soc/sunxi/sun4i-i2s.c
index dca1143c1150..d7a9141514cf 100644
--- a/sound/soc/sunxi/sun4i-i2s.c
+++ b/sound/soc/sunxi/sun4i-i2s.c
@@ -96,6 +96,7 @@ 
 #define SUN8I_I2S_CTRL_BCLK_OUT			BIT(18)
 #define SUN8I_I2S_CTRL_LRCK_OUT			BIT(17)
 
+#define SUN8I_I2S_FMT0_LRCK_MAX_PERIOD		(GENMASK(17, 8) >> 8)
 #define SUN8I_I2S_FMT0_LRCK_PERIOD_MASK		GENMASK(17, 8)
 #define SUN8I_I2S_FMT0_LRCK_PERIOD(period)	((period - 1) << 8)
 
@@ -193,6 +194,9 @@  struct sun4i_i2s {
 	struct regmap_field	*field_rxchansel;
 
 	const struct sun4i_i2s_quirks	*variant;
+
+	unsigned int	tdm_slots;
+	unsigned int	slot_width;
 };
 
 struct sun4i_i2s_clk_div {
@@ -344,7 +348,7 @@  static int sun4i_i2s_set_clk_rate(struct snd_soc_dai *dai,
 	if (i2s->variant->has_fmt_set_lrck_period)
 		regmap_update_bits(i2s->regmap, SUN4I_I2S_FMT0_REG,
 				   SUN8I_I2S_FMT0_LRCK_PERIOD_MASK,
-				   SUN8I_I2S_FMT0_LRCK_PERIOD(32));
+				   SUN8I_I2S_FMT0_LRCK_PERIOD(word_size));
 
 	return 0;
 }
@@ -418,7 +422,8 @@  static int sun4i_i2s_hw_params(struct snd_pcm_substream *substream,
 			   sr + i2s->variant->fmt_offset);
 
 	return sun4i_i2s_set_clk_rate(dai, params_rate(params),
-				      params_width(params));
+				      i2s->tdm_slots ?
+				      i2s->slot_width : params_width(params));
 }
 
 static int sun4i_i2s_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
@@ -691,6 +696,19 @@  static int sun4i_i2s_set_sysclk(struct snd_soc_dai *dai, int clk_id,
 	return 0;
 }
 
+static int sun4i_i2s_set_dai_tdm_slot(struct snd_soc_dai *dai,
+	unsigned int tx_mask, unsigned int rx_mask,
+	int slots, int width)
+{
+	struct sun4i_i2s *i2s = snd_soc_dai_get_drvdata(dai);
+
+	i2s->tdm_slots = slots;
+
+	i2s->slot_width = width;
+
+	return 0;
+}
+
 static const struct snd_soc_dai_ops sun4i_i2s_dai_ops = {
 	.hw_params	= sun4i_i2s_hw_params,
 	.set_fmt	= sun4i_i2s_set_fmt,
@@ -698,6 +716,7 @@  static const struct snd_soc_dai_ops sun4i_i2s_dai_ops = {
 	.shutdown	= sun4i_i2s_shutdown,
 	.startup	= sun4i_i2s_startup,
 	.trigger	= sun4i_i2s_trigger,
+	.set_tdm_slot	= sun4i_i2s_set_dai_tdm_slot,
 };
 
 static int sun4i_i2s_dai_probe(struct snd_soc_dai *dai)