Commit 8dc08c82 authored by Mark Brown's avatar Mark Brown

ASoC: mediatek: Add support for MT8188 SoC

Merge series from Trevor Wu <trevor.wu@mediatek.com>:

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

Changes since v4:
  - refine etdm dai driver based on reviewer's suggestions
  - refine dt-binding files based on reviewer's suggestions

Changes since v3:
  - replace apll_ck with apll to sync with the relationship in CCF
  - add mtk-soundcard-driver.c to support codec parsing
  - drop mclk-always-on-rates support in mt8188-dai-etdm.c
  - refine dt-binding files based on reviewer's suggestions

Changes since v2:
  - drop CLK_IGNORE_UNUSED flag
  - include bitfield.h to reslove the issue reported by kernel test robot
  - rename mt8188-afe-pcm.yaml to mt8188-afe.yaml
  - refine dt-binding files based on reviewer's suggestions

Changes since v1:
  - remove bus protection functions in case of unmerged dependency problem
  - replace some bit operation macro with FIELD_PREP
  - simplify register control by regmap_set_bits and regmap_clear_bits
  - fix dt-binding errors
  - rename compatible string for recognition

Trevor Wu (13):
  ASoC: mediatek: common: add SMC ops and SMC CMD
  ASoC: mediatek: mt8188: add common header
  ASoC: mediatek: mt8188: support audsys clock
  ASoC: mediatek: mt8188: support adda in platform driver
  ASoC: mediatek: mt8188: support etdm in platform driver
  ASoC: mediatek: mt8188: support pcmif in platform driver
  ASoC: mediatek: mt8188: support audio clock control
  ASoC: mediatek: mt8188: add platform driver
  ASoC: mediatek: mt8188: add control for timing select
  ASoC: dt-bindings: mediatek,mt8188-afe: add audio afe document
  ASoC: mediatek: common: add soundcard driver common code
  ASoC: mediatek: mt8188: add machine driver with mt6359
  ASoC: dt-bindings: mediatek,mt8188-mt6359: add mt8188-mt6359 document

 .../bindings/sound/mediatek,mt8188-afe.yaml   |  208 +
 .../sound/mediatek,mt8188-mt6359.yaml         |   97 +
 sound/soc/mediatek/Kconfig                    |   23 +
 sound/soc/mediatek/Makefile                   |    1 +
 sound/soc/mediatek/common/Makefile            |    2 +-
 sound/soc/mediatek/common/mtk-base-afe.h      |   19 +
 .../mediatek/common/mtk-soundcard-driver.c    |   79 +
 .../mediatek/common/mtk-soundcard-driver.h    |   14 +
 sound/soc/mediatek/mt8188/Makefile            |   15 +
 sound/soc/mediatek/mt8188/mt8188-afe-clk.c    |  658 ++++
 sound/soc/mediatek/mt8188/mt8188-afe-clk.h    |  115 +
 sound/soc/mediatek/mt8188/mt8188-afe-common.h |  151 +
 sound/soc/mediatek/mt8188/mt8188-afe-pcm.c    | 3359 +++++++++++++++++
 sound/soc/mediatek/mt8188/mt8188-audsys-clk.c |  205 +
 sound/soc/mediatek/mt8188/mt8188-audsys-clk.h |   15 +
 .../soc/mediatek/mt8188/mt8188-audsys-clkid.h |   83 +
 sound/soc/mediatek/mt8188/mt8188-dai-adda.c   |  632 ++++
 sound/soc/mediatek/mt8188/mt8188-dai-etdm.c   | 2588 +++++++++++++
 sound/soc/mediatek/mt8188/mt8188-dai-pcm.c    |  367 ++
 sound/soc/mediatek/mt8188/mt8188-mt6359.c     |  785 ++++
 sound/soc/mediatek/mt8188/mt8188-reg.h        | 3180 ++++++++++++++++
 21 files changed, 12595 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/sound/mediatek,mt8188-afe.yaml
 create mode 100644 Documentation/devicetree/bindings/sound/mediatek,mt8188-mt6359.yaml
 create mode 100644 sound/soc/mediatek/common/mtk-soundcard-driver.c
 create mode 100644 sound/soc/mediatek/common/mtk-soundcard-driver.h
 create mode 100644 sound/soc/mediatek/mt8188/Makefile
 create mode 100644 sound/soc/mediatek/mt8188/mt8188-afe-clk.c
 create mode 100644 sound/soc/mediatek/mt8188/mt8188-afe-clk.h
 create mode 100644 sound/soc/mediatek/mt8188/mt8188-afe-common.h
 create mode 100644 sound/soc/mediatek/mt8188/mt8188-afe-pcm.c
 create mode 100644 sound/soc/mediatek/mt8188/mt8188-audsys-clk.c
 create mode 100644 sound/soc/mediatek/mt8188/mt8188-audsys-clk.h
 create mode 100644 sound/soc/mediatek/mt8188/mt8188-audsys-clkid.h
 create mode 100644 sound/soc/mediatek/mt8188/mt8188-dai-adda.c
 create mode 100644 sound/soc/mediatek/mt8188/mt8188-dai-etdm.c
 create mode 100644 sound/soc/mediatek/mt8188/mt8188-dai-pcm.c
 create mode 100644 sound/soc/mediatek/mt8188/mt8188-mt6359.c
 create mode 100644 sound/soc/mediatek/mt8188/mt8188-reg.h

--
2.18.0
parents ae7c40bc ce038238
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
%YAML 1.2
---
$id: http://devicetree.org/schemas/sound/mediatek,mt8188-afe.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#
title: MediaTek AFE PCM controller for mt8188
maintainers:
- Trevor Wu <trevor.wu@mediatek.com>
properties:
compatible:
const: mediatek,mt8188-afe
reg:
maxItems: 1
interrupts:
maxItems: 1
resets:
maxItems: 1
reset-names:
const: audiosys
mediatek,topckgen:
$ref: /schemas/types.yaml#/definitions/phandle
description: The phandle of the mediatek topckgen controller
power-domains:
maxItems: 1
clocks:
items:
- description: 26M clock
- description: audio pll1 clock
- description: audio pll2 clock
- description: clock divider for i2si1_mck
- description: clock divider for i2si2_mck
- description: clock divider for i2so1_mck
- description: clock divider for i2so2_mck
- description: clock divider for dptx_mck
- description: a1sys hoping clock
- description: audio intbus clock
- description: audio hires clock
- description: audio local bus clock
- description: mux for dptx_mck
- description: mux for i2so1_mck
- description: mux for i2so2_mck
- description: mux for i2si1_mck
- description: mux for i2si2_mck
- description: audio 26m clock
clock-names:
items:
- const: clk26m
- const: apll1
- const: apll2
- const: apll12_div0
- const: apll12_div1
- const: apll12_div2
- const: apll12_div3
- const: apll12_div9
- const: a1sys_hp_sel
- const: aud_intbus_sel
- const: audio_h_sel
- const: audio_local_bus_sel
- const: dptx_m_sel
- const: i2so1_m_sel
- const: i2so2_m_sel
- const: i2si1_m_sel
- const: i2si2_m_sel
- const: adsp_audio_26m
mediatek,etdm-in1-cowork-source:
$ref: /schemas/types.yaml#/definitions/uint32
description:
etdm modules can share the same external clock pin. Specify
which etdm clock source is required by this etdm in module.
enum:
- 1 # etdm2_in
- 2 # etdm1_out
- 3 # etdm2_out
mediatek,etdm-in2-cowork-source:
$ref: /schemas/types.yaml#/definitions/uint32
description:
etdm modules can share the same external clock pin. Specify
which etdm clock source is required by this etdm in module.
enum:
- 0 # etdm1_in
- 2 # etdm1_out
- 3 # etdm2_out
mediatek,etdm-out1-cowork-source:
$ref: /schemas/types.yaml#/definitions/uint32
description:
etdm modules can share the same external clock pin. Specify
which etdm clock source is required by this etdm out module.
enum:
- 0 # etdm1_in
- 1 # etdm2_in
- 3 # etdm2_out
mediatek,etdm-out2-cowork-source:
$ref: /schemas/types.yaml#/definitions/uint32
description:
etdm modules can share the same external clock pin. Specify
which etdm clock source is required by this etdm out module.
enum:
- 0 # etdm1_in
- 1 # etdm2_in
- 2 # etdm1_out
patternProperties:
"^mediatek,etdm-in[1-2]-chn-disabled$":
$ref: /schemas/types.yaml#/definitions/uint8-array
minItems: 1
maxItems: 16
description:
This is a list of channel IDs which should be disabled.
By default, all data received from ETDM pins will be outputed to
memory. etdm in supports disable_out in direct mode(w/o interconn),
so user can disable the specified channels by the property.
uniqueItems: true
items:
minimum: 0
maximum: 15
"^mediatek,etdm-in[1-2]-multi-pin-mode$":
type: boolean
description: if present, the etdm data mode is I2S.
"^mediatek,etdm-out[1-3]-multi-pin-mode$":
type: boolean
description: if present, the etdm data mode is I2S.
required:
- compatible
- reg
- interrupts
- resets
- reset-names
- mediatek,topckgen
- power-domains
- clocks
- clock-names
additionalProperties: false
examples:
- |
#include <dt-bindings/interrupt-controller/arm-gic.h>
#include <dt-bindings/interrupt-controller/irq.h>
afe@10b10000 {
compatible = "mediatek,mt8188-afe";
reg = <0x10b10000 0x10000>;
interrupts = <GIC_SPI 822 IRQ_TYPE_LEVEL_HIGH 0>;
resets = <&watchdog 14>;
reset-names = "audiosys";
mediatek,topckgen = <&topckgen>;
power-domains = <&spm 13>; //MT8188_POWER_DOMAIN_AUDIO
mediatek,etdm-in2-cowork-source = <2>;
mediatek,etdm-out2-cowork-source = <0>;
mediatek,etdm-in1-multi-pin-mode;
mediatek,etdm-in1-chn-disabled = /bits/ 8 <0x0 0x2>;
clocks = <&clk26m>,
<&apmixedsys 9>, //CLK_APMIXED_APLL1
<&apmixedsys 10>, //CLK_APMIXED_APLL2
<&topckgen 186>, //CLK_TOP_APLL12_CK_DIV0
<&topckgen 187>, //CLK_TOP_APLL12_CK_DIV1
<&topckgen 188>, //CLK_TOP_APLL12_CK_DIV2
<&topckgen 189>, //CLK_TOP_APLL12_CK_DIV3
<&topckgen 191>, //CLK_TOP_APLL12_CK_DIV9
<&topckgen 83>, //CLK_TOP_A1SYS_HP
<&topckgen 31>, //CLK_TOP_AUD_INTBUS
<&topckgen 32>, //CLK_TOP_AUDIO_H
<&topckgen 69>, //CLK_TOP_AUDIO_LOCAL_BUS
<&topckgen 81>, //CLK_TOP_DPTX
<&topckgen 77>, //CLK_TOP_I2SO1
<&topckgen 78>, //CLK_TOP_I2SO2
<&topckgen 79>, //CLK_TOP_I2SI1
<&topckgen 80>, //CLK_TOP_I2SI2
<&adsp_audio26m 0>; //CLK_AUDIODSP_AUDIO26M
clock-names = "clk26m",
"apll1",
"apll2",
"apll12_div0",
"apll12_div1",
"apll12_div2",
"apll12_div3",
"apll12_div9",
"a1sys_hp_sel",
"aud_intbus_sel",
"audio_h_sel",
"audio_local_bus_sel",
"dptx_m_sel",
"i2so1_m_sel",
"i2so2_m_sel",
"i2si1_m_sel",
"i2si2_m_sel",
"adsp_audio_26m";
};
...
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
%YAML 1.2
---
$id: http://devicetree.org/schemas/sound/mediatek,mt8188-mt6359.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#
title: MediaTek MT8188 ASoC sound card
maintainers:
- Trevor Wu <trevor.wu@mediatek.com>
properties:
compatible:
const: mediatek,mt8188-mt6359-evb
model:
$ref: /schemas/types.yaml#/definitions/string
description: User specified audio sound card name
audio-routing:
$ref: /schemas/types.yaml#/definitions/non-unique-string-array
description:
A list of the connections between audio components. Each entry is a
sink/source pair of strings. Valid names could be the input or output
widgets of audio components, power supplies, MicBias of codec and the
software switch.
mediatek,platform:
$ref: /schemas/types.yaml#/definitions/phandle
description: The phandle of MT8188 ASoC platform.
patternProperties:
"^dai-link-[0-9]+$":
type: object
description:
Container for dai-link level properties and CODEC sub-nodes.
properties:
link-name:
description:
This property corresponds to the name of the BE dai-link to which
we are going to update parameters in this node.
items:
enum:
- ADDA_BE
- DPTX_BE
- ETDM1_IN_BE
- ETDM2_IN_BE
- ETDM1_OUT_BE
- ETDM2_OUT_BE
- ETDM3_OUT_BE
- PCM1_BE
codec:
description: Holds subnode which indicates codec dai.
type: object
additionalProperties: false
properties:
sound-dai:
minItems: 1
maxItems: 2
required:
- sound-dai
additionalProperties: false
required:
- link-name
- codec
additionalProperties: false
required:
- compatible
- mediatek,platform
examples:
- |
sound {
compatible = "mediatek,mt8188-mt6359-evb";
mediatek,platform = <&afe>;
pinctrl-names = "default";
pinctrl-0 = <&aud_pins_default>;
audio-routing =
"Headphone", "Headphone L",
"Headphone", "Headphone R",
"AIN1", "Headset Mic";
dai-link-0 {
link-name = "ETDM3_OUT_BE";
codec {
sound-dai = <&hdmi0>;
};
};
};
...
......@@ -208,6 +208,29 @@ config SND_SOC_MTK_BTCVSD
Select Y if you have such device.
If unsure select "N".
config SND_SOC_MT8188
tristate "ASoC support for MediaTek MT8188 chip"
depends on ARCH_MEDIATEK || COMPILE_TEST
depends on COMMON_CLK
select SND_SOC_MEDIATEK
select MFD_SYSCON if SND_SOC_MT6359
help
This adds ASoC platform driver support for MediaTek MT8188 chip
that can be used with other codecs.
Select Y if you have such device.
If unsure select "N".
config SND_SOC_MT8188_MT6359
tristate "ASoC Audio driver for MT8188 with MT6359 and I2S codecs"
depends on SND_SOC_MT8188 && MTK_PMIC_WRAP
select SND_SOC_MT6359
select SND_SOC_HDMI_CODEC
help
This adds support for ASoC machine driver for MediaTek MT8188
boards with the MT6359 and other I2S audio codecs.
Select Y if you have such device.
If unsure select "N".
config SND_SOC_MT8192
tristate "ASoC support for Mediatek MT8192 chip"
depends on ARCH_MEDIATEK
......
......@@ -5,5 +5,6 @@ obj-$(CONFIG_SND_SOC_MT6797) += mt6797/
obj-$(CONFIG_SND_SOC_MT8173) += mt8173/
obj-$(CONFIG_SND_SOC_MT8183) += mt8183/
obj-$(CONFIG_SND_SOC_MT8186) += mt8186/
obj-$(CONFIG_SND_SOC_MT8188) += mt8188/
obj-$(CONFIG_SND_SOC_MT8192) += mt8192/
obj-$(CONFIG_SND_SOC_MT8195) += mt8195/
# SPDX-License-Identifier: GPL-2.0
# platform driver
snd-soc-mtk-common-objs := mtk-afe-platform-driver.o mtk-afe-fe-dai.o mtk-dsp-sof-common.o
snd-soc-mtk-common-objs := mtk-afe-platform-driver.o mtk-afe-fe-dai.o mtk-dsp-sof-common.o mtk-soundcard-driver.o
obj-$(CONFIG_SND_SOC_MEDIATEK) += snd-soc-mtk-common.o
obj-$(CONFIG_SND_SOC_MTK_BTCVSD) += mtk-btcvsd.o
......@@ -9,7 +9,26 @@
#ifndef _MTK_BASE_AFE_H_
#define _MTK_BASE_AFE_H_
#include <linux/soc/mediatek/mtk_sip_svc.h>
#define MTK_STREAM_NUM (SNDRV_PCM_STREAM_LAST + 1)
#define MTK_SIP_AUDIO_CONTROL MTK_SIP_SMC_CMD(0x517)
/* SMC CALL Operations */
enum mtk_audio_smc_call_op {
MTK_AUDIO_SMC_OP_INIT = 0,
MTK_AUDIO_SMC_OP_DRAM_REQUEST,
MTK_AUDIO_SMC_OP_DRAM_RELEASE,
MTK_AUDIO_SMC_OP_SRAM_REQUEST,
MTK_AUDIO_SMC_OP_SRAM_RELEASE,
MTK_AUDIO_SMC_OP_ADSP_REQUEST,
MTK_AUDIO_SMC_OP_ADSP_RELEASE,
MTK_AUDIO_SMC_OP_DOMAIN_SIDEBANDS,
MTK_AUDIO_SMC_OP_BTCVSD_WRITE,
MTK_AUDIO_SMC_OP_BTCVSD_UPDATE_CTRL_CLEAR,
MTK_AUDIO_SMC_OP_BTCVSD_UPDATE_CTRL_UNDERFLOW,
MTK_AUDIO_SMC_OP_NUM
};
struct mtk_base_memif_data {
int id;
......
// SPDX-License-Identifier: GPL-2.0
/*
* mtk-soundcard-driver.c -- MediaTek soundcard driver common
*
* Copyright (c) 2022 MediaTek Inc.
* Author: Trevor Wu <trevor.wu@mediatek.com>
*/
#include <linux/module.h>
#include <linux/of.h>
#include <sound/soc.h>
#include "mtk-soundcard-driver.h"
static int set_card_codec_info(struct snd_soc_card *card,
struct device_node *sub_node,
struct snd_soc_dai_link *dai_link)
{
struct device *dev = card->dev;
struct device_node *codec_node;
int ret;
codec_node = of_get_child_by_name(sub_node, "codec");
if (!codec_node)
return -EINVAL;
/* set card codec info */
ret = snd_soc_of_get_dai_link_codecs(dev, codec_node, dai_link);
of_node_put(codec_node);
if (ret < 0)
return dev_err_probe(dev, ret, "%s: codec dai not found\n",
dai_link->name);
return 0;
}
int parse_dai_link_info(struct snd_soc_card *card)
{
struct device *dev = card->dev;
struct device_node *sub_node;
struct snd_soc_dai_link *dai_link;
const char *dai_link_name;
int ret, i;
/* Loop over all the dai link sub nodes */
for_each_available_child_of_node(dev->of_node, sub_node) {
if (of_property_read_string(sub_node, "link-name",
&dai_link_name))
return -EINVAL;
for_each_card_prelinks(card, i, dai_link) {
if (!strcmp(dai_link_name, dai_link->name))
break;
}
if (i >= card->num_links)
return -EINVAL;
ret = set_card_codec_info(card, sub_node, dai_link);
if (ret < 0)
return ret;
}
return 0;
}
EXPORT_SYMBOL_GPL(parse_dai_link_info);
void clean_card_reference(struct snd_soc_card *card)
{
struct snd_soc_dai_link *dai_link;
int i;
/* release codec reference gotten by set_card_codec_info */
for_each_card_prelinks(card, i, dai_link)
snd_soc_of_put_dai_link_codecs(dai_link);
}
EXPORT_SYMBOL_GPL(clean_card_reference);
/* SPDX-License-Identifier: GPL-2.0 */
/*
* mtk-soundcard-driver.h -- MediaTek soundcard driver common definition
*
* Copyright (c) 2022 MediaTek Inc.
* Author: Trevor Wu <trevor.wu@mediatek.com>
*/
#ifndef _MTK_SOUNDCARD_DRIVER_H_
#define _MTK_SOUNDCARD_DRIVER_H_
int parse_dai_link_info(struct snd_soc_card *card);
void clean_card_reference(struct snd_soc_card *card);
#endif
# SPDX-License-Identifier: GPL-2.0
# platform driver
snd-soc-mt8188-afe-objs := \
mt8188-afe-clk.o \
mt8188-afe-pcm.o \
mt8188-audsys-clk.o \
mt8188-dai-adda.o \
mt8188-dai-etdm.o \
mt8188-dai-pcm.o
obj-$(CONFIG_SND_SOC_MT8188) += snd-soc-mt8188-afe.o
# machine driver
obj-$(CONFIG_SND_SOC_MT8188_MT6359) += mt8188-mt6359.o
This diff is collapsed.
/* SPDX-License-Identifier: GPL-2.0 */
/*
* mt8188-afe-clk.h -- MediaTek 8188 afe clock ctrl definition
*
* Copyright (c) 2022 MediaTek Inc.
* Author: Bicycle Tsai <bicycle.tsai@mediatek.com>
* Trevor Wu <trevor.wu@mediatek.com>
* Chun-Chia Chiu <chun-chia.chiu@mediatek.com>
*/
#ifndef _MT8188_AFE_CLK_H_
#define _MT8188_AFE_CLK_H_
enum {
/* xtal */
MT8188_CLK_XTAL_26M,
/* pll */
MT8188_CLK_APMIXED_APLL1,
MT8188_CLK_APMIXED_APLL2,
/* divider */
MT8188_CLK_TOP_APLL12_DIV0,
MT8188_CLK_TOP_APLL12_DIV1,
MT8188_CLK_TOP_APLL12_DIV2,
MT8188_CLK_TOP_APLL12_DIV3,
MT8188_CLK_TOP_APLL12_DIV9,
/* mux */
MT8188_CLK_TOP_A1SYS_HP_SEL,
MT8188_CLK_TOP_AUD_INTBUS_SEL,
MT8188_CLK_TOP_AUDIO_H_SEL,
MT8188_CLK_TOP_AUDIO_LOCAL_BUS_SEL,
MT8188_CLK_TOP_DPTX_M_SEL,
MT8188_CLK_TOP_I2SO1_M_SEL,
MT8188_CLK_TOP_I2SO2_M_SEL,
MT8188_CLK_TOP_I2SI1_M_SEL,
MT8188_CLK_TOP_I2SI2_M_SEL,
/* clock gate */
MT8188_CLK_ADSP_AUDIO_26M,
MT8188_CLK_AUD_AFE,
MT8188_CLK_AUD_APLL1_TUNER,
MT8188_CLK_AUD_APLL2_TUNER,
MT8188_CLK_AUD_TOP0_SPDF,
MT8188_CLK_AUD_APLL,
MT8188_CLK_AUD_APLL2,
MT8188_CLK_AUD_DAC,
MT8188_CLK_AUD_ADC,
MT8188_CLK_AUD_DAC_HIRES,
MT8188_CLK_AUD_A1SYS_HP,
MT8188_CLK_AUD_ADC_HIRES,
MT8188_CLK_AUD_I2SIN,
MT8188_CLK_AUD_TDM_IN,
MT8188_CLK_AUD_I2S_OUT,
MT8188_CLK_AUD_TDM_OUT,
MT8188_CLK_AUD_HDMI_OUT,
MT8188_CLK_AUD_ASRC11,
MT8188_CLK_AUD_ASRC12,
MT8188_CLK_AUD_A1SYS,
MT8188_CLK_AUD_A2SYS,
MT8188_CLK_AUD_PCMIF,
MT8188_CLK_AUD_MEMIF_UL1,
MT8188_CLK_AUD_MEMIF_UL2,
MT8188_CLK_AUD_MEMIF_UL3,
MT8188_CLK_AUD_MEMIF_UL4,
MT8188_CLK_AUD_MEMIF_UL5,
MT8188_CLK_AUD_MEMIF_UL6,
MT8188_CLK_AUD_MEMIF_UL8,
MT8188_CLK_AUD_MEMIF_UL9,
MT8188_CLK_AUD_MEMIF_UL10,
MT8188_CLK_AUD_MEMIF_DL2,
MT8188_CLK_AUD_MEMIF_DL3,
MT8188_CLK_AUD_MEMIF_DL6,
MT8188_CLK_AUD_MEMIF_DL7,
MT8188_CLK_AUD_MEMIF_DL8,
MT8188_CLK_AUD_MEMIF_DL10,
MT8188_CLK_AUD_MEMIF_DL11,
MT8188_CLK_NUM,
};
enum {
MT8188_AUD_PLL1,
MT8188_AUD_PLL2,
MT8188_AUD_PLL3,
MT8188_AUD_PLL4,
MT8188_AUD_PLL5,
MT8188_AUD_PLL_NUM,
};
enum {
MT8188_MCK_SEL_26M,
MT8188_MCK_SEL_APLL1,
MT8188_MCK_SEL_APLL2,
MT8188_MCK_SEL_APLL3,
MT8188_MCK_SEL_APLL4,
MT8188_MCK_SEL_APLL5,
MT8188_MCK_SEL_NUM,
};
struct mtk_base_afe;
int mt8188_afe_get_mclk_source_clk_id(int sel);
int mt8188_afe_get_mclk_source_rate(struct mtk_base_afe *afe, int apll);
int mt8188_afe_get_default_mclk_source_by_rate(int rate);
int mt8188_afe_init_clock(struct mtk_base_afe *afe);
void mt8188_afe_deinit_clock(void *priv);
int mt8188_afe_enable_clk(struct mtk_base_afe *afe, struct clk *clk);
void mt8188_afe_disable_clk(struct mtk_base_afe *afe, struct clk *clk);
int mt8188_afe_set_clk_rate(struct mtk_base_afe *afe, struct clk *clk,
unsigned int rate);
int mt8188_afe_set_clk_parent(struct mtk_base_afe *afe, struct clk *clk,
struct clk *parent);
int mt8188_afe_enable_main_clock(struct mtk_base_afe *afe);
int mt8188_afe_disable_main_clock(struct mtk_base_afe *afe);
int mt8188_afe_enable_reg_rw_clk(struct mtk_base_afe *afe);
int mt8188_afe_disable_reg_rw_clk(struct mtk_base_afe *afe);
#endif
/* SPDX-License-Identifier: GPL-2.0 */
/*
* mt8188-afe-common.h -- MediaTek 8188 audio driver definitions
*
* Copyright (c) 2022 MediaTek Inc.
* Author: Bicycle Tsai <bicycle.tsai@mediatek.com>
* Trevor Wu <trevor.wu@mediatek.com>
* Chun-Chia Chiu <chun-chia.chiu@mediatek.com>
*/
#ifndef _MT_8188_AFE_COMMON_H_
#define _MT_8188_AFE_COMMON_H_
#include <linux/list.h>
#include <linux/regmap.h>
#include <sound/soc.h>
#include "../common/mtk-base-afe.h"
enum {
MT8188_DAI_START,
MT8188_AFE_MEMIF_START = MT8188_DAI_START,
MT8188_AFE_MEMIF_DL2 = MT8188_AFE_MEMIF_START,
MT8188_AFE_MEMIF_DL3,
MT8188_AFE_MEMIF_DL6,
MT8188_AFE_MEMIF_DL7,
MT8188_AFE_MEMIF_DL8,
MT8188_AFE_MEMIF_DL10,
MT8188_AFE_MEMIF_DL11,
MT8188_AFE_MEMIF_UL_START,
MT8188_AFE_MEMIF_UL1 = MT8188_AFE_MEMIF_UL_START,
MT8188_AFE_MEMIF_UL2,
MT8188_AFE_MEMIF_UL3,
MT8188_AFE_MEMIF_UL4,
MT8188_AFE_MEMIF_UL5,
MT8188_AFE_MEMIF_UL6,
MT8188_AFE_MEMIF_UL8,
MT8188_AFE_MEMIF_UL9,
MT8188_AFE_MEMIF_UL10,
MT8188_AFE_MEMIF_END,
MT8188_AFE_MEMIF_NUM = (MT8188_AFE_MEMIF_END - MT8188_AFE_MEMIF_START),
MT8188_AFE_IO_START = MT8188_AFE_MEMIF_END,
MT8188_AFE_IO_ADDA = MT8188_AFE_IO_START,
MT8188_AFE_IO_DMIC_IN,
MT8188_AFE_IO_DPTX,
MT8188_AFE_IO_ETDM_START,
MT8188_AFE_IO_ETDM1_IN = MT8188_AFE_IO_ETDM_START,
MT8188_AFE_IO_ETDM2_IN,
MT8188_AFE_IO_ETDM1_OUT,
MT8188_AFE_IO_ETDM2_OUT,
MT8188_AFE_IO_ETDM3_OUT,
MT8188_AFE_IO_ETDM_END,
MT8188_AFE_IO_ETDM_NUM =
(MT8188_AFE_IO_ETDM_END - MT8188_AFE_IO_ETDM_START),
MT8188_AFE_IO_PCM = MT8188_AFE_IO_ETDM_END,
MT8188_AFE_IO_END,
MT8188_AFE_IO_NUM = (MT8188_AFE_IO_END - MT8188_AFE_IO_START),
MT8188_DAI_END = MT8188_AFE_IO_END,
MT8188_DAI_NUM = (MT8188_DAI_END - MT8188_DAI_START),
};
enum {
MT8188_TOP_CG_A1SYS_TIMING,
MT8188_TOP_CG_A2SYS_TIMING,
MT8188_TOP_CG_26M_TIMING,
MT8188_TOP_CG_NUM,
};
enum {
MT8188_AFE_IRQ_1,
MT8188_AFE_IRQ_2,
MT8188_AFE_IRQ_3,
MT8188_AFE_IRQ_8,
MT8188_AFE_IRQ_9,
MT8188_AFE_IRQ_10,
MT8188_AFE_IRQ_13,
MT8188_AFE_IRQ_14,
MT8188_AFE_IRQ_15,
MT8188_AFE_IRQ_16,
MT8188_AFE_IRQ_17,
MT8188_AFE_IRQ_18,
MT8188_AFE_IRQ_19,
MT8188_AFE_IRQ_20,
MT8188_AFE_IRQ_21,
MT8188_AFE_IRQ_22,
MT8188_AFE_IRQ_23,
MT8188_AFE_IRQ_24,
MT8188_AFE_IRQ_25,
MT8188_AFE_IRQ_26,
MT8188_AFE_IRQ_27,
MT8188_AFE_IRQ_28,
MT8188_AFE_IRQ_NUM,
};
enum {
MT8188_ETDM_OUT1_1X_EN = 9,
MT8188_ETDM_OUT2_1X_EN = 10,
MT8188_ETDM_OUT3_1X_EN = 11,
MT8188_ETDM_IN1_1X_EN = 12,
MT8188_ETDM_IN2_1X_EN = 13,
MT8188_ETDM_IN1_NX_EN = 25,
MT8188_ETDM_IN2_NX_EN = 26,
};
enum {
MT8188_MTKAIF_MISO_0,
MT8188_MTKAIF_MISO_1,
MT8188_MTKAIF_MISO_NUM,
};
struct mtk_dai_memif_irq_priv {
unsigned int asys_timing_sel;
};
struct mtkaif_param {
bool mtkaif_calibration_ok;
int mtkaif_chosen_phase[MT8188_MTKAIF_MISO_NUM];
int mtkaif_phase_cycle[MT8188_MTKAIF_MISO_NUM];
int mtkaif_dmic_on;
};
struct clk;
struct mt8188_afe_private {
struct clk **clk;
struct clk_lookup **lookup;
struct regmap *topckgen;
int pm_runtime_bypass_reg_ctl;
spinlock_t afe_ctrl_lock; /* Lock for afe control */
struct mtk_dai_memif_irq_priv irq_priv[MT8188_AFE_IRQ_NUM];
struct mtkaif_param mtkaif_params;
/* dai */
void *dai_priv[MT8188_DAI_NUM];
};
int mt8188_afe_fs_timing(unsigned int rate);
/* dai register */
int mt8188_dai_adda_register(struct mtk_base_afe *afe);
int mt8188_dai_etdm_register(struct mtk_base_afe *afe);
int mt8188_dai_pcm_register(struct mtk_base_afe *afe);
#define MT8188_SOC_ENUM_EXT(xname, xenum, xhandler_get, xhandler_put, id) \
{ \
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
.info = snd_soc_info_enum_double, \
.get = xhandler_get, .put = xhandler_put, \
.device = id, \
.private_value = (unsigned long)&(xenum), \
}
#endif
This diff is collapsed.
// SPDX-License-Identifier: GPL-2.0
/*
* mt8188-audsys-clk.c -- MediaTek 8188 audsys clock control
*
* Copyright (c) 2022 MediaTek Inc.
* Author: Chun-Chia Chiu <chun-chia.chiu@mediatek.com>
*/
#include <linux/clk.h>
#include <linux/clk-provider.h>
#include <linux/clkdev.h>
#include "mt8188-afe-common.h"
#include "mt8188-audsys-clk.h"
#include "mt8188-audsys-clkid.h"
#include "mt8188-reg.h"
struct afe_gate {
int id;
const char *name;
const char *parent_name;
int reg;
u8 bit;
const struct clk_ops *ops;
unsigned long flags;
u8 cg_flags;
};
#define GATE_AFE_FLAGS(_id, _name, _parent, _reg, _bit, _flags, _cgflags) {\
.id = _id, \
.name = _name, \
.parent_name = _parent, \
.reg = _reg, \
.bit = _bit, \
.flags = _flags, \
.cg_flags = _cgflags, \
}
#define GATE_AFE(_id, _name, _parent, _reg, _bit) \
GATE_AFE_FLAGS(_id, _name, _parent, _reg, _bit, \
CLK_SET_RATE_PARENT, CLK_GATE_SET_TO_DISABLE)
#define GATE_AUD0(_id, _name, _parent, _bit) \
GATE_AFE(_id, _name, _parent, AUDIO_TOP_CON0, _bit)
#define GATE_AUD1(_id, _name, _parent, _bit) \
GATE_AFE(_id, _name, _parent, AUDIO_TOP_CON1, _bit)
#define GATE_AUD3(_id, _name, _parent, _bit) \
GATE_AFE(_id, _name, _parent, AUDIO_TOP_CON3, _bit)
#define GATE_AUD4(_id, _name, _parent, _bit) \
GATE_AFE(_id, _name, _parent, AUDIO_TOP_CON4, _bit)
#define GATE_AUD5(_id, _name, _parent, _bit) \
GATE_AFE(_id, _name, _parent, AUDIO_TOP_CON5, _bit)
#define GATE_AUD6(_id, _name, _parent, _bit) \
GATE_AFE(_id, _name, _parent, AUDIO_TOP_CON6, _bit)
static const struct afe_gate aud_clks[CLK_AUD_NR_CLK] = {
/* AUD0 */
GATE_AUD0(CLK_AUD_AFE, "aud_afe", "top_a1sys_hp", 2),
GATE_AUD0(CLK_AUD_LRCK_CNT, "aud_lrck_cnt", "top_a1sys_hp", 4),
GATE_AUD0(CLK_AUD_SPDIFIN_TUNER_APLL, "aud_spdifin_tuner_apll", "top_apll4", 10),
GATE_AUD0(CLK_AUD_SPDIFIN_TUNER_DBG, "aud_spdifin_tuner_dbg", "top_apll4", 11),
GATE_AUD0(CLK_AUD_UL_TML, "aud_ul_tml", "top_a1sys_hp", 18),
GATE_AUD0(CLK_AUD_APLL1_TUNER, "aud_apll1_tuner", "top_apll1", 19),
GATE_AUD0(CLK_AUD_APLL2_TUNER, "aud_apll2_tuner", "top_apll2", 20),
GATE_AUD0(CLK_AUD_TOP0_SPDF, "aud_top0_spdf", "top_aud_iec_clk", 21),
GATE_AUD0(CLK_AUD_APLL, "aud_apll", "top_apll1", 23),
GATE_AUD0(CLK_AUD_APLL2, "aud_apll2", "top_apll2", 24),
GATE_AUD0(CLK_AUD_DAC, "aud_dac", "top_a1sys_hp", 25),
GATE_AUD0(CLK_AUD_DAC_PREDIS, "aud_dac_predis", "top_a1sys_hp", 26),
GATE_AUD0(CLK_AUD_TML, "aud_tml", "top_a1sys_hp", 27),
GATE_AUD0(CLK_AUD_ADC, "aud_adc", "top_a1sys_hp", 28),
GATE_AUD0(CLK_AUD_DAC_HIRES, "aud_dac_hires", "top_audio_h", 31),
/* AUD1 */
GATE_AUD1(CLK_AUD_A1SYS_HP, "aud_a1sys_hp", "top_a1sys_hp", 2),
GATE_AUD1(CLK_AUD_AFE_DMIC1, "aud_afe_dmic1", "top_a1sys_hp", 10),
GATE_AUD1(CLK_AUD_AFE_DMIC2, "aud_afe_dmic2", "top_a1sys_hp", 11),
GATE_AUD1(CLK_AUD_AFE_DMIC3, "aud_afe_dmic3", "top_a1sys_hp", 12),
GATE_AUD1(CLK_AUD_AFE_DMIC4, "aud_afe_dmic4", "top_a1sys_hp", 13),
GATE_AUD1(CLK_AUD_AFE_26M_DMIC_TM, "aud_afe_26m_dmic_tm", "top_a1sys_hp", 14),
GATE_AUD1(CLK_AUD_UL_TML_HIRES, "aud_ul_tml_hires", "top_audio_h", 16),
GATE_AUD1(CLK_AUD_ADC_HIRES, "aud_adc_hires", "top_audio_h", 17),
/* AUD3 */
GATE_AUD3(CLK_AUD_LINEIN_TUNER, "aud_linein_tuner", "top_apll5", 5),
GATE_AUD3(CLK_AUD_EARC_TUNER, "aud_earc_tuner", "top_apll3", 7),
/* AUD4 */
GATE_AUD4(CLK_AUD_I2SIN, "aud_i2sin", "top_a1sys_hp", 0),
GATE_AUD4(CLK_AUD_TDM_IN, "aud_tdm_in", "top_a1sys_hp", 1),
GATE_AUD4(CLK_AUD_I2S_OUT, "aud_i2s_out", "top_a1sys_hp", 6),
GATE_AUD4(CLK_AUD_TDM_OUT, "aud_tdm_out", "top_a1sys_hp", 7),
GATE_AUD4(CLK_AUD_HDMI_OUT, "aud_hdmi_out", "top_a1sys_hp", 8),
GATE_AUD4(CLK_AUD_ASRC11, "aud_asrc11", "top_a1sys_hp", 16),
GATE_AUD4(CLK_AUD_ASRC12, "aud_asrc12", "top_a1sys_hp", 17),
GATE_AUD4(CLK_AUD_MULTI_IN, "aud_multi_in", "mphone_slave_b", 19),
GATE_AUD4(CLK_AUD_INTDIR, "aud_intdir", "top_intdir", 20),
GATE_AUD4(CLK_AUD_A1SYS, "aud_a1sys", "top_a1sys_hp", 21),
GATE_AUD4(CLK_AUD_A2SYS, "aud_a2sys", "top_a2sys", 22),
GATE_AUD4(CLK_AUD_PCMIF, "aud_pcmif", "top_a1sys_hp", 24),
GATE_AUD4(CLK_AUD_A3SYS, "aud_a3sys", "top_a3sys", 30),
GATE_AUD4(CLK_AUD_A4SYS, "aud_a4sys", "top_a4sys", 31),
/* AUD5 */
GATE_AUD5(CLK_AUD_MEMIF_UL1, "aud_memif_ul1", "top_a1sys_hp", 0),
GATE_AUD5(CLK_AUD_MEMIF_UL2, "aud_memif_ul2", "top_a1sys_hp", 1),
GATE_AUD5(CLK_AUD_MEMIF_UL3, "aud_memif_ul3", "top_a1sys_hp", 2),
GATE_AUD5(CLK_AUD_MEMIF_UL4, "aud_memif_ul4", "top_a1sys_hp", 3),
GATE_AUD5(CLK_AUD_MEMIF_UL5, "aud_memif_ul5", "top_a1sys_hp", 4),
GATE_AUD5(CLK_AUD_MEMIF_UL6, "aud_memif_ul6", "top_a1sys_hp", 5),
GATE_AUD5(CLK_AUD_MEMIF_UL8, "aud_memif_ul8", "top_a1sys_hp", 7),
GATE_AUD5(CLK_AUD_MEMIF_UL9, "aud_memif_ul9", "top_a1sys_hp", 8),
GATE_AUD5(CLK_AUD_MEMIF_UL10, "aud_memif_ul10", "top_a1sys_hp", 9),
GATE_AUD5(CLK_AUD_MEMIF_DL2, "aud_memif_dl2", "top_a1sys_hp", 18),
GATE_AUD5(CLK_AUD_MEMIF_DL3, "aud_memif_dl3", "top_a1sys_hp", 19),
GATE_AUD5(CLK_AUD_MEMIF_DL6, "aud_memif_dl6", "top_a1sys_hp", 22),
GATE_AUD5(CLK_AUD_MEMIF_DL7, "aud_memif_dl7", "top_a1sys_hp", 23),
GATE_AUD5(CLK_AUD_MEMIF_DL8, "aud_memif_dl8", "top_a1sys_hp", 24),
GATE_AUD5(CLK_AUD_MEMIF_DL10, "aud_memif_dl10", "top_a1sys_hp", 26),
GATE_AUD5(CLK_AUD_MEMIF_DL11, "aud_memif_dl11", "top_a1sys_hp", 27),
/* AUD6 */
GATE_AUD6(CLK_AUD_GASRC0, "aud_gasrc0", "top_asm_h", 0),
GATE_AUD6(CLK_AUD_GASRC1, "aud_gasrc1", "top_asm_h", 1),
GATE_AUD6(CLK_AUD_GASRC2, "aud_gasrc2", "top_asm_h", 2),
GATE_AUD6(CLK_AUD_GASRC3, "aud_gasrc3", "top_asm_h", 3),
GATE_AUD6(CLK_AUD_GASRC4, "aud_gasrc4", "top_asm_h", 4),
GATE_AUD6(CLK_AUD_GASRC5, "aud_gasrc5", "top_asm_h", 5),
GATE_AUD6(CLK_AUD_GASRC6, "aud_gasrc6", "top_asm_h", 6),
GATE_AUD6(CLK_AUD_GASRC7, "aud_gasrc7", "top_asm_h", 7),
GATE_AUD6(CLK_AUD_GASRC8, "aud_gasrc8", "top_asm_h", 8),
GATE_AUD6(CLK_AUD_GASRC9, "aud_gasrc9", "top_asm_h", 9),
GATE_AUD6(CLK_AUD_GASRC10, "aud_gasrc10", "top_asm_h", 10),
GATE_AUD6(CLK_AUD_GASRC11, "aud_gasrc11", "top_asm_h", 11),
};
int mt8188_audsys_clk_register(struct mtk_base_afe *afe)
{
struct mt8188_afe_private *afe_priv = afe->platform_priv;
struct clk *clk;
struct clk_lookup *cl;
int i;
afe_priv->lookup = devm_kcalloc(afe->dev, CLK_AUD_NR_CLK,
sizeof(*afe_priv->lookup),
GFP_KERNEL);
if (!afe_priv->lookup)
return -ENOMEM;
for (i = 0; i < ARRAY_SIZE(aud_clks); i++) {
const struct afe_gate *gate = &aud_clks[i];
clk = clk_register_gate(afe->dev, gate->name, gate->parent_name,
gate->flags, afe->base_addr + gate->reg,
gate->bit, gate->cg_flags, NULL);
if (IS_ERR(clk)) {
dev_err(afe->dev, "Failed to register clk %s: %ld\n",
gate->name, PTR_ERR(clk));
continue;
}
/* add clk_lookup for devm_clk_get(SND_SOC_DAPM_CLOCK_SUPPLY) */
cl = kzalloc(sizeof(*cl), GFP_KERNEL);
if (!cl)
return -ENOMEM;
cl->clk = clk;
cl->con_id = gate->name;
cl->dev_id = dev_name(afe->dev);
cl->clk_hw = NULL;
clkdev_add(cl);
afe_priv->lookup[i] = cl;
}
return 0;
}
void mt8188_audsys_clk_unregister(struct mtk_base_afe *afe)
{
struct mt8188_afe_private *afe_priv = afe->platform_priv;
struct clk *clk;
struct clk_lookup *cl;
int i;
if (!afe_priv)
return;
for (i = 0; i < CLK_AUD_NR_CLK; i++) {
cl = afe_priv->lookup[i];
if (!cl)
continue;
clk = cl->clk;
clk_unregister_gate(clk);
clkdev_drop(cl);
}
}
/* SPDX-License-Identifier: GPL-2.0 */
/*
* mt8188-audsys-clk.h -- MediaTek 8188 audsys clock definition
*
* Copyright (c) 2022 MediaTek Inc.
* Author: Chun-Chia Chiu <chun-chia.chiu@mediatek.com>
*/
#ifndef _MT8188_AUDSYS_CLK_H_
#define _MT8188_AUDSYS_CLK_H_
int mt8188_audsys_clk_register(struct mtk_base_afe *afe);
void mt8188_audsys_clk_unregister(struct mtk_base_afe *afe);
#endif
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment