ASoC: mediatek: add initial MT6572 + MT6323 PMIC audio (PAP5500 DUO + Lenovo A369i)#9
ASoC: mediatek: add initial MT6572 + MT6323 PMIC audio (PAP5500 DUO + Lenovo A369i)#9gabin8 wants to merge 13 commits into
Conversation
| - Custom Firmware <gabin278@gmail.com> | ||
|
|
||
| description: | ||
| The MT6572 Audio Front-End (AFE) is a sub-node of the audsys syscon. It |
There was a problem hiding this comment.
drop sub-node and syscon wording. dt-bindings should describe hardware, not the kernel stuff.
| $ref: /schemas/types.yaml#/definitions/phandle | ||
| description: the MT6323 PMIC analog codec DAI. | ||
|
|
||
| iram: |
There was a problem hiding this comment.
SRAM is a distinct block at 0x11141000. AFE control window is 0x11140000–0x11140fff, so it's a standard mmio-sram node handed to the DL1.
Making it a reg of the AFE is not correct: AFE has no reg of its own (it maps the parent audsys window).
I can rename the property iram -> mediatek,sram if the name is the concern.
There was a problem hiding this comment.
i think iram is fine, it's used in few kernel DTs
| $ref: /schemas/types.yaml#/definitions/phandle | ||
| description: on-chip audio SRAM used for the DL1 playback buffers. | ||
|
|
||
| mediatek,speaker-amp: |
There was a problem hiding this comment.
i feel this should be separate. AFE is AFE, codec is codec, and the audio is the glue. i found this for mt8186:
sound: mt8186-sound {
compatible = "mediatek,mt8186-mt6366-da7219-max98357-sound";
model = "mt8186_da7219_m98357";
pinctrl-names = "aud_clk_mosi_off",
"aud_clk_mosi_on";
pinctrl-0 = <&aud_clk_mosi_off>;
pinctrl-1 = <&aud_clk_mosi_on>;
mediatek,platform = <&afe>;
audio-routing =
"Headphones", "HPL",
"Headphones", "HPR",
"MIC", "Headset Mic",
"Speakers", "Speaker",
"HDMI1", "TX";
hs-playback-dai-link {
link-name = "I2S0";
dai-format = "i2s";
mediatek,clk-provider = "cpu";
codec {
sound-dai = <&da7219>;
};
};
hs-capture-dai-link {
link-name = "I2S1";
dai-format = "i2s";
mediatek,clk-provider = "cpu";
codec {
sound-dai = <&da7219>;
};
};
spk-dp-playback-dai-link {
link-name = "I2S3";
dai-format = "i2s";
mediatek,clk-provider = "cpu";
codec {
sound-dai = <&anx_bridge_dp>, <&max98357a>;
};
};
};
There was a problem hiding this comment.
Checked the MT6572W functional spec: the MT6323 link isn't a board I2S bus - it's the AFE's output-only I2S (AFE_I2S_CON1) + ADDA downlink SRC out the fixed PMIC pins (AUD_*_MOSI/ADC_DAT_MISO), i.e. the exact equivalent of mt8183's "ADDA" back-end to mt6358.
So I'll match mt8183: AFE platform-only, a separate mt6572-mt6323 machine driver, the codec as a hardcoded ADDA-style back-end in C, and a minimal sound node
| - mediatek,audio-codec | ||
| - iram | ||
|
|
||
| additionalProperties: false |
There was a problem hiding this comment.
also unsquash. 6397 is one change, new binding is another
| @@ -0,0 +1,336 @@ | |||
| // SPDX-License-Identifier: GPL-2.0 | |||
| // | |||
| // MediaTek MT6323 PMIC analog audio codec. | |||
| | power key: mediatek,mt6323-keys | 🟢 OK | 🟢 OK | 🔴 TBD | 🟢 OK | | ||
| | haptics: regulator-haptic | 🟢 OK | 🔴 TBD | 🔴 TBD | 🟢 OK | | ||
| | charger | 🔴 DEAD | 🔴 DEAD | 🔴 DEAD | 🔴 DEAD | | ||
| | audio (playback + headphone jack) | 🔴 TBD | 🔴 TBD | 🔴 TBD | 🟡 initial: playback + headphone jack, no mic/earpiece | |
There was a problem hiding this comment.
partial.
DEAD means there's no such feature, TBD means it exists on other devices but not working yet. partial means something is working but not really usable (this one you want), OK means no major issues
| needs afe/i2s/etc drivers | ||
| | component | driver | status | note | | ||
| |--------------------|---------------------------|---------|--------------------------------------------------| | ||
| | AFE (DL1 playback) | mediatek,mt6572-audio | 🟢 OK | DL1 (loudspeaker) playback only; no earpiece/UL | |
There was a problem hiding this comment.
...but there's jack detection? or it doesn't support audio playback?
There was a problem hiding this comment.
is supports both jack detection and jack audio playback. And also auto-switch between speakers and HP
| |--------------------|---------------------------|---------|--------------------------------------------------| | ||
| | AFE (DL1 playback) | mediatek,mt6572-audio | 🟢 OK | DL1 (loudspeaker) playback only; no earpiece/UL | | ||
| | analog codec | mediatek,mt6323-sound | 🟢 OK | MT6323 PMIC: DAC + headphone output + volume | | ||
| | speaker amp | simple-audio-amplifier | 🟢 OK | YDA145, gpio-enabled, fed from the headphone out | |
| | AFE (DL1 playback) | mediatek,mt6572-audio | 🟢 OK | DL1 (loudspeaker) playback only; no earpiece/UL | | ||
| | analog codec | mediatek,mt6323-sound | 🟢 OK | MT6323 PMIC: DAC + headphone output + volume | | ||
| | speaker amp | simple-audio-amplifier | 🟢 OK | YDA145, gpio-enabled, fed from the headphone out | | ||
| | headphone jack | hp-det-gpios/snd_soc_jack | 🟢 OK | EINT7 plug detect, auto-routes speaker <-> HP | |
| | speaker amp | simple-audio-amplifier | 🟢 OK | YDA145, gpio-enabled, fed from the headphone out | | ||
| | headphone jack | hp-det-gpios/snd_soc_jack | 🟢 OK | EINT7 plug detect, auto-routes speaker <-> HP | | ||
| | capture (mic) | | 🔴 DEAD | uplink path not implemented yet | | ||
| | i2s | | 🔴 DEAD | not needed for the internal codec | |
|
btw did you test on your devices? |
rva3
left a comment
There was a problem hiding this comment.
all commits are missing signed-off-by. also i don't see changes to the drivers.
| $ref: /schemas/iio/adc/mediatek,mt6359-auxadc.yaml# | ||
| unevaluatedProperties: false | ||
|
|
||
| audio-codec: |
There was a problem hiding this comment.
missing signed-off-by in the commit message
| @@ -0,0 +1,41 @@ | |||
| # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) | |||
There was a problem hiding this comment.
missing signed-off-by in the commit message
| description: | ||
| The Audio Front-End (AFE) of the MediaTek MT6572 SoC. It provides the DL1 | ||
| playback memif (a DMA engine streaming from the on-chip audio SRAM) and the | ||
| digital side of the serial audio link to the MT6323 PMIC analog codec. |
There was a problem hiding this comment.
this sounds generic... probably drop (like all other SoCs do for AFE)?
| clocks: | ||
| maxItems: 1 | ||
|
|
||
| clock-names: |
There was a problem hiding this comment.
clock-names is not needed if clocks maxItems = 1
| @@ -0,0 +1,39 @@ | |||
| # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) | |||
There was a problem hiding this comment.
missing signed-off-by in the commit message
|
|
||
| hp-det-gpios: | ||
| maxItems: 1 | ||
| description: Optional headphone-jack plug-detect GPIO (high = inserted). |
There was a problem hiding this comment.
GPIO_ACTIVE_LOW can invert this. remove the (high = insert).
| // | ||
| // mt6323.c -- MediaTek MT6323 PMIC analog audio codec | ||
| // | ||
| // The analog audio back-end (DAC, headphone driver, path to an external |
| module_platform_driver(mt6323_codec_driver); | ||
|
|
||
| MODULE_DESCRIPTION("MediaTek MT6323 PMIC audio codec driver"); | ||
| MODULE_LICENSE("GPL"); |
There was a problem hiding this comment.
please check comments about the driver from the previous review. i don't see them applied
| @@ -0,0 +1,4 @@ | |||
| # SPDX-License-Identifier: GPL-2.0 | |||
| # MediaTek MT6572 AFE platform + machine drivers | |||
| .num_resources = ARRAY_SIZE(mt6323_pwrc_resources), | ||
| .resources = mt6323_pwrc_resources, | ||
| .of_compatible = "mediatek,mt6323-pwrc" | ||
| }, { |
There was a problem hiding this comment.
missing signed-off-by in the commit message
no, i'll check later |
|
on hold until i get it working on some of my devices i guess |
Document mediatek,mt6323-sound in the audio-codec node, alongside the existing MT6358/MT6397 codecs. Signed-off-by: Custom Firmware <gabin278@gmail.com>
The MT6572 Audio Front-End: a DL1 playback memif streaming from the on-chip audio SRAM to the MT6323 PMIC codec. Signed-off-by: Custom Firmware <gabin278@gmail.com>
rva3
left a comment
There was a problem hiding this comment.
i can't verify this on my a369i, probably they wired audio differently in my revision. i'll ask someone to check with the other a369i though.
| @@ -0,0 +1,41 @@ | |||
| # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) | |||
There was a problem hiding this comment.
'the machine binding'? perhaps devicetree?
There was a problem hiding this comment.
rephrased similar to other mtk socs
| /* | ||
| * MediaTek MT6323 PMIC analog audio codec. | ||
| * | ||
| * The analog audio back-end (DAC, headphone driver, path to an external |
| SNDRV_PCM_FMTBIT_S32_LE) | ||
|
|
||
| /* | ||
| * Audio registers in the PMIC 16-bit space: ABB_AFE<->PMIC bridge @ 0x4000, |
| #define PMIC_CKCON1_AUD_BITS GENMASK(13, 12) | ||
|
|
||
| /* | ||
| * Output gain lives in the ZCD (zero-cross-detect) block. Each register packs |
| /* | ||
| * Analog idle baseline from the stock power-on; the MT6323 audio fields are | ||
| * undocumented. Per the BSP: NEWIF_CFG0 = sample_rate << 12 | 0x330, and | ||
| * NEWIF_CFG2 = 0x302f selects the up8x receive-interface ADC voice mode. |
| }; | ||
| module_platform_driver(mt6323_codec_driver); | ||
|
|
||
| MODULE_DESCRIPTION("MediaTek MT6323 PMIC audio codec driver"); |
| compatible = "mediatek,mt6572-mt6323-sound"; | ||
| mediatek,platform = <&afe>; | ||
| audio-routing = "Speaker", "Speaker Driver"; | ||
| /* Headphone-jack detect on GPIO136 (low = inserted). */ |
| MTK_PIN( | ||
| 136, "GPIO136", | ||
| MTK_EINT_FUNCTION(NO_EINT_SUPPORT, NO_EINT_SUPPORT), | ||
| MTK_EINT_FUNCTION(4, 2), |
There was a problem hiding this comment.
unsquash. this should be separate commit so i can squash this with initial pinctrl commit
| | haptics: regulator-haptic | 🟢 OK | 🔴 TBD | 🔴 TBD | 🟢 OK | | ||
| | charger | 🔴 DEAD | 🔴 DEAD | 🔴 DEAD | 🔴 DEAD | | ||
| | audio (playback + headphone jack) | 🔴 TBD | 🔴 TBD | 🔴 TBD | 🟡 partial: playback + jack | | ||
| | audio (playback + headphone jack) | 🔴 TBD | 🟢 OK: playback + jack + speaker | 🔴 TBD | 🟢 OK: playback + jack + speaker | |
There was a problem hiding this comment.
yep, no mic support.
downgraded to partial
| | haptics: regulator-haptic | 🟢 OK | 🔴 TBD | 🔴 TBD | 🟢 OK | | ||
| | charger | 🔴 DEAD | 🔴 DEAD | 🔴 DEAD | 🔴 DEAD | | ||
| | audio (playback + headphone jack) | 🔴 TBD | 🔴 TBD | 🔴 TBD | 🟡 partial: playback + jack | | ||
| | audio (playback + headphone jack) | 🔴 TBD | 🟢 OK: playback + jack + speaker | 🔴 TBD | 🟢 OK: playback + jack + speaker | |
The machine binding tying the MT6572 AFE to the MT6323 PMIC codec, with standard aux-devs/audio-routing, optional headphone-jack detection and a speaker amplifier. Signed-off-by: Custom Firmware <gabin278@gmail.com>
DAC, headphone output, internal class-D speaker and volume controls on the MT6323 PMIC, reached over the parent MT6397 PMIC-wrapper regmap. The analog register fields are undocumented; the init values come from the stock power-on sequence. Signed-off-by: Custom Firmware <gabin278@gmail.com>
AFE platform driver (DL1 playback memif + ADDA/PMIC link) plus the mt6572-mt6323 machine driver: a DL1 -> mt6323 dai-link, headphone-jack auto-routing between speaker and headphones, and an optional speaker amplifier via the standard aux-devs/audio-routing bindings. Earpiece and uplink/capture are not yet supported. Signed-off-by: Custom Firmware <gabin278@gmail.com>
Add an mt6323-sound MFD cell so the MT6323 ASoC codec driver probes. Signed-off-by: Custom Firmware <gabin278@gmail.com>
GPIO142 is the PAP5500 headphone-jack plug-detect line; give it its EINT7 mapping so gpiod_to_irq() works. Signed-off-by: Custom Firmware <gabin278@gmail.com>
Sub-node of the audsys syscon for the DL1 playback front-end + the on-chip audio SRAM. Signed-off-by: Custom Firmware <gabin278@gmail.com>
The MT6323 PMIC analog codec (mediatek,mt6323-sound). Signed-off-by: Custom Firmware <gabin278@gmail.com>
The sound card (mediatek,mt6572-mt6323-sound) with the AFE platform, an external speaker amplifier (simple-audio-amplifier on GPIO139) and headphone-jack detect (GPIO142/EINT7). Signed-off-by: Custom Firmware <gabin278@gmail.com>
Signed-off-by: Custom Firmware <gabin278@gmail.com>
GPIO136 is the Lenovo A369i headphone-jack plug-detect line; give it its EINT2 mapping so gpiod_to_irq() works. Signed-off-by: Custom Firmware <gabin278@gmail.com>
Add the MT6572 AFE + MT6323 sound card with the internal class-D speaker and headphone-jack detection on GPIO136. Signed-off-by: Custom Firmware <gabin278@gmail.com>
rva3
left a comment
There was a problem hiding this comment.
minor comments
i'll check what's wrong with audio on my a369i today
| @@ -0,0 +1,355 @@ | |||
| // SPDX-License-Identifier: GPL-2.0 | |||
| // | |||
| // mt6323.c -- MT6323 PMIC analog audio codec driver | |||
There was a problem hiding this comment.
drop filename. just MT6323 PMIC analog audio codec driver is fine
| #define ABB_AFE_CON(n) (0x4000 + (n) * 2) | ||
| #define AUDTOP_CON(n) (0x0700 + (n) * 2) | ||
| #define SPK_CON(n) (0x0052 + (n) * 2) | ||
| /* Speaker clock gate lives in TOP_CKPDN1 (cleared to enable). */ |
There was a problem hiding this comment.
?
should we mention topckgen here? i guess devicetree should provide clocks? drop.
| #define AUDTOP_CON(n) (0x0700 + (n) * 2) | ||
| #define SPK_CON(n) (0x0052 + (n) * 2) | ||
| /* Speaker clock gate lives in TOP_CKPDN1 (cleared to enable). */ | ||
| #define PMIC_RG_AUD_SPK_PDN 0x000e |
There was a problem hiding this comment.
also align regs with tabs (not sure if it's github issue or actually not aligned) like MT6323_TOP_CKPDN0_SET, MT6323_TOP_CKPDN0_CLR, ... are
| #define MT6323_TOP_CKPDN0_SET 0x0104 | ||
| #define MT6323_TOP_CKPDN0_CLR 0x0106 | ||
| #define PMIC_RG_CLKSQ_EN_AUD BIT(0) | ||
| #define MT6323_TOP_CKPDN1_SET 0x010a |
There was a problem hiding this comment.
space between field of the previous reg and new reg, e.g.
#define MT6323_TOP_CKPDN0_SET 0x0104
#define MT6323_TOP_CKPDN0_CLR 0x0106
#define PMIC_RG_CLKSQ_EN_AUD BIT(0)
#define MT6323_TOP_CKPDN1_SET 0x010a
|
|
||
| struct mt6323_codec_priv { | ||
| struct device *dev; | ||
| struct regmap *regmap; /* borrowed from the parent MT6323 MFD */ |
There was a problem hiding this comment.
comment should be on top, e.g.
/* borrowed from the parent MT6323 MFD */
struct regmap *regmap;
| #define AFE_DAC_CON1_DL1_RATE GENMASK(3, 0) | ||
| #define AFE_DL1_BASE 0x0040 | ||
| #define AFE_DL1_CUR 0x0044 | ||
| #define AFE_DL1_END 0x0048 /* ring end, inclusive */ |
| #define AFE_IRQ_MCU_STATUS_IRQ1 BIT(0) | ||
| #define AFE_IRQ_MCU_STATUS_MASK GENMASK(3, 0) | ||
| #define AFE_IRQ_MCU_CLR 0x03a8 | ||
| /* IRQ fired with no status bit set (status == 0): clear-mask to ack and return. */ |
| regmap_read(afe->regmap, AFE_IRQ_MCU_STATUS, &status); | ||
| status &= AFE_IRQ_MCU_STATUS_MASK; | ||
| if (!status) { | ||
| regmap_write(afe->regmap, AFE_IRQ_MCU_CLR, AFE_IRQ_MCU_CLR_NOSTATUS); |
There was a problem hiding this comment.
is write of the whole AFE_IRQ_MCU_CLR_NOSTATUS required here? can it be just regmap_write(afe->regmap, AFE_IRQ_MCU_CLR, status);?
| @@ -0,0 +1,137 @@ | |||
| // SPDX-License-Identifier: GPL-2.0 | |||
| // | |||
| // mt6572-mt6323.c -- MediaTek MT6572 + MT6323 sound card | |||
| static struct snd_soc_jack_gpio mt6572_mt6323_jack_gpio = { | ||
| .name = "hp-det", | ||
| .report = SND_JACK_HEADPHONE, | ||
| .debounce_time = 256, /* ms */ |
Audio support for the MT6572 AFE + MT6323 PMIC codec, verified on the Prestigio PAP5500 DUO and the Lenovo A369i.
What it brings up
simple-audio-amplifieraux device, fed from the headphone output.SPK_CON), driven directly on the SPK_P/SPK_N pins, with an analog "Speaker Volume" control.Tested on hardware
aplay), volume (AFE digital gain), jack insert/removal auto-switching.Structure
The original MT6572 AFE + MT6323 codec + PAP5500 DUO enablement, plus three commits for the Lenovo A369i: internal class-D speaker support in the codec, the board DTS + jack EINT pin, and the README status.