mbox series

[0/7] ASoC: mediatek: Add support for MT79xx SoC

Message ID 20230612105250.15441-1-maso.huang@mediatek.com
Headers show
Series ASoC: mediatek: Add support for MT79xx SoC | expand

Message

Maso Huang June 12, 2023, 10:52 a.m. UTC
From: Maso Huang <maso.huang@mediatek.com>

This series of patches adds support for MediaTek AFE of MT79xx SoC.
Patches are based on broonie tree "for-next" branch.

Maso Huang (7):
  ASoC: mediatek: mt79xx: add common header
  ASoC: mediatek: mt79xx: support audio clock control
  ASoC: mediatek: mt79xx: add platform driver
  ASoC: mediatek: mt79xx: support etdm in platform driver
  ASoC: mediatek: mt79xx: add machine driver with wm8960
  ASoC: dt-bindings: mediatek,mt79xx-wm8960: add mt79xx-wm8960 document
  ASoC: dt-bindings: mediatek,mt79xx-afe: add audio afe document

 .../bindings/sound/mediatek,mt79xx-afe.yaml   | 102 +++
 .../sound/mediatek,mt79xx-wm8960.yaml         |  53 ++
 sound/soc/mediatek/Kconfig                    |  20 +
 sound/soc/mediatek/Makefile                   |   1 +
 sound/soc/mediatek/mt79xx/Makefile            |  10 +
 sound/soc/mediatek/mt79xx/mt79xx-afe-clk.c    | 123 ++++
 sound/soc/mediatek/mt79xx/mt79xx-afe-clk.h    |  18 +
 sound/soc/mediatek/mt79xx/mt79xx-afe-common.h |  49 ++
 sound/soc/mediatek/mt79xx/mt79xx-afe-pcm.c    | 608 ++++++++++++++++++
 sound/soc/mediatek/mt79xx/mt79xx-dai-etdm.c   | 421 ++++++++++++
 sound/soc/mediatek/mt79xx/mt79xx-reg.h        | 206 ++++++
 sound/soc/mediatek/mt79xx/mt79xx-wm8960.c     | 185 ++++++
 12 files changed, 1796 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/mediatek,mt79xx-afe.yaml
 create mode 100644 Documentation/devicetree/bindings/sound/mediatek,mt79xx-wm8960.yaml
 create mode 100644 sound/soc/mediatek/mt79xx/Makefile
 create mode 100644 sound/soc/mediatek/mt79xx/mt79xx-afe-clk.c
 create mode 100644 sound/soc/mediatek/mt79xx/mt79xx-afe-clk.h
 create mode 100644 sound/soc/mediatek/mt79xx/mt79xx-afe-common.h
 create mode 100644 sound/soc/mediatek/mt79xx/mt79xx-afe-pcm.c
 create mode 100644 sound/soc/mediatek/mt79xx/mt79xx-dai-etdm.c
 create mode 100644 sound/soc/mediatek/mt79xx/mt79xx-reg.h
 create mode 100644 sound/soc/mediatek/mt79xx/mt79xx-wm8960.c

Comments

Claudiu Beznea June 13, 2023, 7:27 a.m. UTC | #1
On 12.06.2023 13:52, Maso Hunag wrote:
> [You don't often get email from maso.huang@mediatek.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
> 
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> From: Maso Huang <maso.huang@mediatek.com>
> 
> Add audio clock wrapper and audio tuner control.
> 
> Signed-off-by: Maso Huang <maso.huang@mediatek.com>
> ---
>  sound/soc/mediatek/mt79xx/mt79xx-afe-clk.c | 123 +++++++++++++++++++++
>  sound/soc/mediatek/mt79xx/mt79xx-afe-clk.h |  18 +++
>  2 files changed, 141 insertions(+)
>  create mode 100644 sound/soc/mediatek/mt79xx/mt79xx-afe-clk.c
>  create mode 100644 sound/soc/mediatek/mt79xx/mt79xx-afe-clk.h
> 
> diff --git a/sound/soc/mediatek/mt79xx/mt79xx-afe-clk.c b/sound/soc/mediatek/mt79xx/mt79xx-afe-clk.c
> new file mode 100644
> index 000000000000..f00f0d7de861
> --- /dev/null
> +++ b/sound/soc/mediatek/mt79xx/mt79xx-afe-clk.c
> @@ -0,0 +1,123 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * mt79xx-afe-clk.c  --  MediaTek 79xx afe clock ctrl
> + *
> + * Copyright (c) 2021 MediaTek Inc.
> + * Author: Vic Wu <vic.wu@mediatek.com>
> + *         Maso Huang <maso.huang@mediatek.com>
> + */
> +
> +#include <linux/clk.h>
> +
> +#include "mt79xx-afe-common.h"
> +#include "mt79xx-afe-clk.h"
> +#include "mt79xx-reg.h"
> +
> +enum {
> +       CK_INFRA_AUD_BUS_CK = 0,
> +       CK_INFRA_AUD_26M_CK,
> +       CK_INFRA_AUD_L_CK,
> +       CK_INFRA_AUD_AUD_CK,
> +       CK_INFRA_AUD_EG2_CK,
> +       CLK_NUM
> +};
> +
> +static const char *aud_clks[CLK_NUM] = {
> +       [CK_INFRA_AUD_BUS_CK] = "aud_bus_ck",
> +       [CK_INFRA_AUD_26M_CK] = "aud_26m_ck",
> +       [CK_INFRA_AUD_L_CK] = "aud_l_ck",
> +       [CK_INFRA_AUD_AUD_CK] = "aud_aud_ck",
> +       [CK_INFRA_AUD_EG2_CK] = "aud_eg2_ck",
> +};
> +
> +int mt79xx_init_clock(struct mtk_base_afe *afe)
> +{
> +       struct mt79xx_afe_private *afe_priv = afe->platform_priv;
> +       int i;
> +
> +       afe_priv->clk = devm_kcalloc(afe->dev, CLK_NUM, sizeof(*afe_priv->clk),
> +                                    GFP_KERNEL);
> +       if (!afe_priv->clk)
> +               return -ENOMEM;
> +
> +       for (i = 0; i < CLK_NUM; i++) {
> +               afe_priv->clk[i] = devm_clk_get(afe->dev, aud_clks[i]);
> +               if (IS_ERR(afe_priv->clk[i])) {
> +                       dev_err(afe->dev, "%s(), devm_clk_get %s fail,
> +                               ret %ld\n", __func__, aud_clks[i],
> +                               PTR_ERR(afe_priv->clk[i]));
> +                       return PTR_ERR(afe_priv->clk[i]);
> +               }
> +       }

You can use devm_clk_bulk_get()

> +
> +       return 0;
> +}
> +
> +int mt79xx_afe_enable_clock(struct mtk_base_afe *afe)
> +{
> +       struct mt79xx_afe_private *afe_priv = afe->platform_priv;
> +       int ret;
> +
> +       ret = clk_prepare_enable(afe_priv->clk[CK_INFRA_AUD_BUS_CK]);
> +       if (ret) {
> +               dev_err(afe->dev, "%s(), clk_prepare_enable %s fail %d\n",
> +                       __func__, aud_clks[CK_INFRA_AUD_BUS_CK], ret);
> +               goto CK_INFRA_AUD_BUS_CK_ERR;
> +       }
> +
> +       ret = clk_prepare_enable(afe_priv->clk[CK_INFRA_AUD_26M_CK]);
> +       if (ret) {
> +               dev_err(afe->dev, "%s(), clk_prepare_enable %s fail %d\n",
> +                       __func__, aud_clks[CK_INFRA_AUD_26M_CK], ret);
> +               goto CK_INFRA_AUD_26M_ERR;
> +       }
> +
> +       ret = clk_prepare_enable(afe_priv->clk[CK_INFRA_AUD_L_CK]);
> +       if (ret) {
> +               dev_err(afe->dev, "%s(), clk_prepare_enable %s fail %d\n",
> +                       __func__, aud_clks[CK_INFRA_AUD_L_CK], ret);
> +               goto CK_INFRA_AUD_L_CK_ERR;
> +       }
> +
> +       ret = clk_prepare_enable(afe_priv->clk[CK_INFRA_AUD_AUD_CK]);
> +       if (ret) {
> +               dev_err(afe->dev, "%s clk_prepare_enable %s fail %d\n",
> +                       __func__, aud_clks[CK_INFRA_AUD_AUD_CK], ret);
> +               goto CK_INFRA_AUD_AUD_CK_ERR;
> +       }
> +
> +       ret = clk_prepare_enable(afe_priv->clk[CK_INFRA_AUD_EG2_CK]);
> +       if (ret) {
> +               dev_err(afe->dev, "%s clk_prepare_enable %s fail %d\n",
> +                       __func__, aud_clks[CK_INFRA_AUD_EG2_CK], ret);
> +               goto CK_INFRA_AUD_EG2_CK_ERR;
> +       }

And clk_bulk_prepare_enable() instead all these.

> +
> +       return 0;
> +
> +CK_INFRA_AUD_EG2_CK_ERR:
> +       clk_disable_unprepare(afe_priv->clk[CK_INFRA_AUD_AUD_CK]);
> +CK_INFRA_AUD_AUD_CK_ERR:
> +       clk_disable_unprepare(afe_priv->clk[CK_INFRA_AUD_L_CK]);
> +CK_INFRA_AUD_L_CK_ERR:
> +       clk_disable_unprepare(afe_priv->clk[CK_INFRA_AUD_26M_CK]);
> +CK_INFRA_AUD_26M_ERR:
> +       clk_disable_unprepare(afe_priv->clk[CK_INFRA_AUD_BUS_CK]);
> +CK_INFRA_AUD_BUS_CK_ERR:
> +       return ret;
> +}
> +EXPORT_SYMBOL_GPL(mt79xx_afe_enable_clock);
> +
> +int mt79xx_afe_disable_clock(struct mtk_base_afe *afe)
> +{
> +       struct mt79xx_afe_private *afe_priv = afe->platform_priv;
> +
> +       clk_disable_unprepare(afe_priv->clk[CK_INFRA_AUD_EG2_CK]);
> +       clk_disable_unprepare(afe_priv->clk[CK_INFRA_AUD_AUD_CK]);
> +       clk_disable_unprepare(afe_priv->clk[CK_INFRA_AUD_L_CK]);
> +       clk_disable_unprepare(afe_priv->clk[CK_INFRA_AUD_26M_CK]);
> +       clk_disable_unprepare(afe_priv->clk[CK_INFRA_AUD_BUS_CK]);
> +

And also clk_bulk_disable_unprepare() here.

> +       return 0;
> +}
> +EXPORT_SYMBOL_GPL(mt79xx_afe_disable_clock);
> diff --git a/sound/soc/mediatek/mt79xx/mt79xx-afe-clk.h b/sound/soc/mediatek/mt79xx/mt79xx-afe-clk.h
> new file mode 100644
> index 000000000000..bf9c3edb6922
> --- /dev/null
> +++ b/sound/soc/mediatek/mt79xx/mt79xx-afe-clk.h
> @@ -0,0 +1,18 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/*
> + * mt79xx-afe-clk.h  --  MediaTek 79xx afe clock ctrl definition
> + *
> + * Copyright (c) 2021 MediaTek Inc.
> + * Author: Vic Wu <vic.wu@mediatek.com>
> + *         Maso Huang <maso.huang@mediatek.com>
> + */
> +
> +#ifndef _MT79XX_AFE_CLK_H_
> +#define _MT79XX_AFE_CLK_H_
> +
> +struct mtk_base_afe;
> +
> +int mt79xx_init_clock(struct mtk_base_afe *afe);
> +int mt79xx_afe_enable_clock(struct mtk_base_afe *afe);
> +int mt79xx_afe_disable_clock(struct mtk_base_afe *afe);
> +#endif
> --
> 2.18.0
> 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Krzysztof Kozlowski June 13, 2023, 8:51 a.m. UTC | #2
On 12/06/2023 12:52, Maso Hunag wrote:
> From: Maso Huang <maso.huang@mediatek.com>
> 
> Add mt79xx audio afe document.

Please use scripts/get_maintainers.pl to get a list of necessary people
and lists to CC.  It might happen, that command when run on an older
kernel, gives you outdated entries.  Therefore please be sure you base
your patches on recent Linux kernel.

> 
> Signed-off-by: Maso Huang <maso.huang@mediatek.com>
> ---
>  .../bindings/sound/mediatek,mt79xx-afe.yaml   | 102 ++++++++++++++++++
>  1 file changed, 102 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/sound/mediatek,mt79xx-afe.yaml
> 
> diff --git a/Documentation/devicetree/bindings/sound/mediatek,mt79xx-afe.yaml b/Documentation/devicetree/bindings/sound/mediatek,mt79xx-afe.yaml
> new file mode 100644
> index 000000000000..11ef1cfdf49b
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/sound/mediatek,mt79xx-afe.yaml
> @@ -0,0 +1,102 @@
> +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/sound/mediatek,mt79xx-afe.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: MediaTek AFE PCM controller for MT79xx

79XX sounds weird. Are you sure you are not using wildcards (which are
not allowed)?

> +
> +maintainers:
> +  - Maso Huang <maso.huang@mediatek.com>
> +
> +properties:
> +  compatible:
> +    oneOf:
> +      - const: mediatek,mt79xx-afe
> +      - items:
> +          - enum:
> +              - mediatek,mt7981-afe
> +              - mediatek,mt7986-afe
> +              - mediatek,mt7988-afe
> +          - const: mediatek,mt79xx-afe

I already saw AFE, why it cannot be part of existing bindings?

This list is odd. 79xx, 7981? So it is wildcard?

> +
> +  reg:
> +    maxItems: 1
> +
> +  interrupts:
> +    maxItems: 1
> +
> +  clocks:
> +    minItems: 5
> +    items:
> +      - description: audio bus clock
> +      - description: audio 26M clock
> +      - description: audio intbus clock
> +      - description: audio hopping clock
> +      - description: audio pll clock
> +      - description: mux for pcm_mck
> +      - description: audio i2s/pcm mck
> +
> +  clock-names:
> +    minItems: 5
> +    items:
> +      - const: aud_bus_ck
> +      - const: aud_26m_ck
> +      - const: aud_l_ck
> +      - const: aud_aud_ck
> +      - const: aud_eg2_ck
> +      - const: aud_sel
> +      - const: aud_i2s_m

Why this is variable?

> +
> +  assigned-clocks:
> +    minItems: 3
> +    maxItems: 4

Drop assigned-clocks

> +
> +  assigned-clock-parents:
> +    minItems: 3
> +    maxItems: 4

Drop



Best regards,
Krzysztof
Krzysztof Kozlowski June 14, 2023, 6:34 a.m. UTC | #3
On 14/06/2023 05:17, Maso Huang (黃加竹) wrote:
> On Tue, 2023-06-13 at 10:51 +0200, Krzysztof Kozlowski wrote:
>>  	 
>> External email : Please do not click links or open attachments until
>> you have verified the sender or the content.
>>  
>> On 12/06/2023 12:52, Maso Hunag wrote:
>>> From: Maso Huang <maso.huang@mediatek.com>
>>>
>>> Add mt79xx audio afe document.
>>
>> Please use scripts/get_maintainers.pl to get a list of necessary
>> people
>> and lists to CC.  It might happen, that command when run on an older
>> kernel, gives you outdated entries.  Therefore please be sure you
>> base
>> your patches on recent Linux kernel.
>>
> 
> Hi Krzysztif, 
> 
> Thanks for your review. And sorry for missing some necessary
> maintainers.
> What's your suggestion, resend these patches again with them, or add
> them back in v2 patch?


You need to fix the patch anyway, so use get_maintainers.pl in v2. I
don't understand why you Cc here many unrelated people but not the
actual maintainers which get_maintainers.pl asks you to Cc!

> 
>>>
>>> Signed-off-by: Maso Huang <maso.huang@mediatek.com>
>>> ---
>>>  .../bindings/sound/mediatek,mt79xx-afe.yaml   | 102
>> ++++++++++++++++++
>>>  1 file changed, 102 insertions(+)
>>>  create mode 100644
>> Documentation/devicetree/bindings/sound/mediatek,mt79xx-afe.yaml
>>>
>>> diff --git
>> a/Documentation/devicetree/bindings/sound/mediatek,mt79xx-afe.yaml
>> b/Documentation/devicetree/bindings/sound/mediatek,mt79xx-afe.yaml
>>> new file mode 100644
>>> index 000000000000..11ef1cfdf49b
>>> --- /dev/null
>>> +++ b/Documentation/devicetree/bindings/sound/mediatek,mt79xx-
>> afe.yaml
>>> @@ -0,0 +1,102 @@
>>> +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
>>> +%YAML 1.2
>>> +---
>>> +$id: http://devicetree.org/schemas/sound/mediatek,mt79xx-afe.yaml#
>>> +$schema: http://devicetree.org/meta-schemas/core.yaml#
>>> +
>>> +title: MediaTek AFE PCM controller for MT79xx
>>
>> 79XX sounds weird. Are you sure you are not using wildcards (which
>> are
>> not allowed)?
>>
> 
> We would like to use mt79xx for mt7986/mt7981/mt7988 series.
> Or is it better to just use mt7986 for this series?

You cannot use wildcard. Get some internal review of your patches prior
to submission to mailing list.

https://elixir.bootlin.com/linux/v6.1-rc1/source/Documentation/devicetree/bindings/writing-bindings.rst

> 
>>> +
>>> +maintainers:
>>> +  - Maso Huang <maso.huang@mediatek.com>
>>> +
>>> +properties:
>>> +  compatible:
>>> +    oneOf:
>>> +      - const: mediatek,mt79xx-afe
>>> +      - items:
>>> +          - enum:
>>> +              - mediatek,mt7981-afe
>>> +              - mediatek,mt7986-afe
>>> +              - mediatek,mt7988-afe
>>> +          - const: mediatek,mt79xx-afe
>>
>> I already saw AFE, why it cannot be part of existing bindings?

Can you answer this?

>>
>> This list is odd. 79xx, 7981? So it is wildcard?
>>
> 
> Yes, it is wildcard for mt7986/mt7981/mt7988 series.
> Is it better to just use mt7986 for this series? 

No wildcards.


Best regards,
Krzysztof
Krzysztof Kozlowski June 14, 2023, 8:21 a.m. UTC | #4
On 14/06/2023 09:37, Maso Huang (黃加竹) wrote:
>>>> I already saw AFE, why it cannot be part of existing bindings?
>>
>> Can you answer this?
>>
> 
> Did you mean mtk-afe-pcm.txt?
> If yes, I'll modify mtk-afe-pcm.txt to yaml format, and add mt7986 to
> its compatible list.
> 

No, I meant mediatek,mt8188-afe.yaml.

Aren't you working on some old tree? If so, please don't...

Best regards,
Krzysztof
Krzysztof Kozlowski June 14, 2023, 10:26 a.m. UTC | #5
On 14/06/2023 11:19, Maso Huang (黃加竹) wrote:
> On Wed, 2023-06-14 at 10:21 +0200, Krzysztof Kozlowski wrote:
>>  	 
>> External email : Please do not click links or open attachments until
>> you have verified the sender or the content.
>>  On 14/06/2023 09:37, Maso Huang (黃加竹) wrote:
>>>>>> I already saw AFE, why it cannot be part of existing bindings?
>>>>
>>>> Can you answer this?
>>>>
>>>
>>> Did you mean mtk-afe-pcm.txt?
>>> If yes, I'll modify mtk-afe-pcm.txt to yaml format, and add mt7986
>> to
>>> its compatible list.
>>>
>>
>> No, I meant mediatek,mt8188-afe.yaml.
>>
>> Aren't you working on some old tree? If so, please don't...
>>
>> Best regards,
>> Krzysztof
>>
> 
> Hi Krzysztof,
> AFE is common name for our audio hardware, and the design might be
> different for soc, like clock.
> 
> And the design is the same for mt7981/mt7986/mt7988.
> Is it better to create a new dtbinding file mediatk,mt7986-afe.yaml?

Is it different? That was my question whether it can be part of existing
bindings.

Best regards,
Krzysztof