Skip to content

Commit 000d8b9

Browse files
committed
ASoC: mediatek: use reserved memory or enable
Merge series from Chen-Yu Tsai <wenst@chromium.org>: Angelo requested that these platforms use reserved memory regions if possible, and fall back to pre-allocated buffers only if that fails, to align with other MediaTek SoCs / platforms that already use reserved memory. The series covers MediaTek's MT8173, MT8183, MT8186, and MT8192 SoCs. There are three parts to the series: - Part one (patches 1 through 5) update the DT bindings to allow having a memory region. The text binding for the MT8173 was converted to YAML and also aligned with current usage by addition of a power domain. Note that the MT8183 text binding was _not_ converted. It is drastically different from what was landed in the device trees. Some time is needed to work out the differences. I might try to recombine the audio clocks (which are actually part of the same hardware block) as well. - Part two (patches 6 through 9) update the audio frontend drivers for the various platforms covered in this series. - Patch 6 is the evolution of version 1, now defaulting to reserved memory if possible. - Patch 7 adds support for >32 bit DMA addresses to the MT8183 driver. This was missing, and prevents the memory regions, which are allocated from the top end of main memory by default, from working. - Patch 8 and 9 are just some minor cleanups to reduce the number of "&pdev->dev" style dereferences. They are placed after the other changes to make it easier for the fixes to be backported. - Part three (patches 10 through 13) add a reserved memory region for the audio frontend on the various platforms. (This part is queued up and therefore not included in v3.) For the MT8173, the change covers the whole platform. In practice there are only ChromeOS devices. For the other platforms, only the ChromeOS devices are covered. These are what I have available for testing. Please have a look. I assume the DT binding and driver changes will go through the ASoC tree, while the device tree changes will go through the MediaTek tree.
2 parents 5eb8a0d + bb8d8ba commit 000d8b9

10 files changed

Lines changed: 200 additions & 94 deletions

File tree

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
2+
%YAML 1.2
3+
---
4+
$id: http://devicetree.org/schemas/sound/mediatek,mt8173-afe-pcm.yaml#
5+
$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+
title: Mediatek AFE PCM controller for MT8173
8+
9+
maintainers:
10+
- Trevor Wu <trevor.wu@mediatek.com>
11+
12+
properties:
13+
compatible:
14+
const: mediatek,mt8173-afe-pcm
15+
16+
reg:
17+
maxItems: 1
18+
19+
interrupts:
20+
maxItems: 1
21+
22+
clocks:
23+
items:
24+
- description: audio infra sys clock
25+
- description: audio top mux
26+
- description: audio intbus mux
27+
- description: apll1 clock
28+
- description: apll2 clock
29+
- description: i2s0 mclk mux
30+
- description: i2s1 mclk mux
31+
- description: i2s2 mclk mux
32+
- description: i2s3 mclk mux
33+
- description: i2s3 bclk mux
34+
35+
clock-names:
36+
items:
37+
- const: infra_sys_audio_clk
38+
- const: top_pdn_audio
39+
- const: top_pdn_aud_intbus
40+
- const: bck0
41+
- const: bck1
42+
- const: i2s0_m
43+
- const: i2s1_m
44+
- const: i2s2_m
45+
- const: i2s3_m
46+
- const: i2s3_b
47+
48+
power-domains:
49+
maxItems: 1
50+
51+
memory-region:
52+
description: memory region for audio DMA buffers
53+
maxItems: 1
54+
55+
required:
56+
- compatible
57+
- reg
58+
- interrupts
59+
- clocks
60+
- clock-names
61+
- power-domains
62+
63+
additionalProperties: false
64+
65+
examples:
66+
- |
67+
#include <dt-bindings/clock/mt8173-clk.h>
68+
#include <dt-bindings/interrupt-controller/arm-gic.h>
69+
#include <dt-bindings/interrupt-controller/irq.h>
70+
#include <dt-bindings/power/mt8173-power.h>
71+
72+
mt8173-afe-pcm@11220000 {
73+
compatible = "mediatek,mt8173-afe-pcm";
74+
reg = <0x11220000 0x1000>;
75+
interrupts = <GIC_SPI 134 IRQ_TYPE_EDGE_FALLING>;
76+
power-domains = <&spm MT8173_POWER_DOMAIN_AUDIO>;
77+
clocks = <&infracfg CLK_INFRA_AUDIO>,
78+
<&topckgen CLK_TOP_AUDIO_SEL>,
79+
<&topckgen CLK_TOP_AUD_INTBUS_SEL>,
80+
<&topckgen CLK_TOP_APLL1_DIV0>,
81+
<&topckgen CLK_TOP_APLL2_DIV0>,
82+
<&topckgen CLK_TOP_I2S0_M_SEL>,
83+
<&topckgen CLK_TOP_I2S1_M_SEL>,
84+
<&topckgen CLK_TOP_I2S2_M_SEL>,
85+
<&topckgen CLK_TOP_I2S3_M_SEL>,
86+
<&topckgen CLK_TOP_I2S3_B_SEL>;
87+
clock-names = "infra_sys_audio_clk",
88+
"top_pdn_audio",
89+
"top_pdn_aud_intbus",
90+
"bck0",
91+
"bck1",
92+
"i2s0_m",
93+
"i2s1_m",
94+
"i2s2_m",
95+
"i2s3_m",
96+
"i2s3_b";
97+
memory-region = <&afe_dma_mem>;
98+
};

Documentation/devicetree/bindings/sound/mt8186-afe-pcm.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ properties:
2525
reset-names:
2626
const: audiosys
2727

28+
memory-region:
29+
description: memory region for audio DMA buffers
30+
maxItems: 1
31+
2832
mediatek,apmixedsys:
2933
$ref: /schemas/types.yaml#/definitions/phandle
3034
description: The phandle of the mediatek apmixedsys controller
@@ -170,6 +174,7 @@ examples:
170174
"top_apll12_div_tdm",
171175
"top_mux_audio_h",
172176
"top_clk26m_clk";
177+
memory-region = <&afe_dma_mem>;
173178
};
174179
175180
...

Documentation/devicetree/bindings/sound/mt8192-afe-pcm.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ properties:
2323
reset-names:
2424
const: audiosys
2525

26+
memory-region:
27+
description: memory region for audio DMA buffers
28+
maxItems: 1
29+
2630
mediatek,apmixedsys:
2731
$ref: /schemas/types.yaml#/definitions/phandle
2832
description: The phandle of the mediatek apmixedsys controller
@@ -95,6 +99,7 @@ examples:
9599
"aud_dac_predis_clk",
96100
"aud_infra_clk",
97101
"aud_infra_26m_clk";
102+
memory-region = <&afe_dma_mem>;
98103
};
99104
100105
...

Documentation/devicetree/bindings/sound/mtk-afe-pcm.txt

Lines changed: 0 additions & 45 deletions
This file was deleted.

sound/soc/mediatek/common/mtk-afe-platform-driver.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ int mtk_afe_pcm_new(struct snd_soc_component *component,
120120
struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component);
121121

122122
size = afe->mtk_afe_hardware->buffer_bytes_max;
123-
snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, afe->dev, 0, size);
123+
snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, afe->dev,
124+
afe->preallocate_buffers ? size : 0,
125+
size);
124126

125127
return 0;
126128
}

sound/soc/mediatek/common/mtk-base-afe.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ struct mtk_base_afe {
117117
struct mtk_base_afe_irq *irqs;
118118
int irqs_size;
119119
int memif_32bit_supported;
120+
bool preallocate_buffers;
120121

121122
struct list_head sub_dais;
122123
struct snd_soc_dai_driver *dai_drivers;

sound/soc/mediatek/mt8173/mt8173-afe-pcm.c

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/module.h>
1414
#include <linux/of.h>
1515
#include <linux/of_address.h>
16+
#include <linux/of_reserved_mem.h>
1617
#include <linux/dma-mapping.h>
1718
#include <linux/pm_runtime.h>
1819
#include <sound/soc.h>
@@ -1053,22 +1054,28 @@ static int mt8173_afe_pcm_dev_probe(struct platform_device *pdev)
10531054
struct mtk_base_afe *afe;
10541055
struct mt8173_afe_private *afe_priv;
10551056
struct snd_soc_component *comp_pcm, *comp_hdmi;
1057+
struct device *dev = &pdev->dev;
10561058

1057-
ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(33));
1059+
ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(33));
10581060
if (ret)
10591061
return ret;
10601062

1061-
afe = devm_kzalloc(&pdev->dev, sizeof(*afe), GFP_KERNEL);
1063+
afe = devm_kzalloc(dev, sizeof(*afe), GFP_KERNEL);
10621064
if (!afe)
10631065
return -ENOMEM;
10641066

1065-
afe->platform_priv = devm_kzalloc(&pdev->dev, sizeof(*afe_priv),
1066-
GFP_KERNEL);
1067+
afe->platform_priv = devm_kzalloc(dev, sizeof(*afe_priv), GFP_KERNEL);
10671068
afe_priv = afe->platform_priv;
10681069
if (!afe_priv)
10691070
return -ENOMEM;
10701071

1071-
afe->dev = &pdev->dev;
1072+
afe->dev = dev;
1073+
1074+
ret = of_reserved_mem_device_init(dev);
1075+
if (ret) {
1076+
dev_info(dev, "no reserved memory found, pre-allocating buffers instead\n");
1077+
afe->preallocate_buffers = true;
1078+
}
10721079

10731080
irq_id = platform_get_irq(pdev, 0);
10741081
if (irq_id <= 0)
@@ -1078,27 +1085,27 @@ static int mt8173_afe_pcm_dev_probe(struct platform_device *pdev)
10781085
if (IS_ERR(afe->base_addr))
10791086
return PTR_ERR(afe->base_addr);
10801087

1081-
afe->regmap = devm_regmap_init_mmio(&pdev->dev, afe->base_addr,
1082-
&mt8173_afe_regmap_config);
1088+
afe->regmap = devm_regmap_init_mmio(dev, afe->base_addr,
1089+
&mt8173_afe_regmap_config);
10831090
if (IS_ERR(afe->regmap))
10841091
return PTR_ERR(afe->regmap);
10851092

10861093
/* initial audio related clock */
10871094
ret = mt8173_afe_init_audio_clk(afe);
10881095
if (ret) {
1089-
dev_err(afe->dev, "mt8173_afe_init_audio_clk fail\n");
1096+
dev_err(dev, "mt8173_afe_init_audio_clk fail\n");
10901097
return ret;
10911098
}
10921099

10931100
/* memif % irq initialize*/
10941101
afe->memif_size = MT8173_AFE_MEMIF_NUM;
1095-
afe->memif = devm_kcalloc(afe->dev, afe->memif_size,
1102+
afe->memif = devm_kcalloc(dev, afe->memif_size,
10961103
sizeof(*afe->memif), GFP_KERNEL);
10971104
if (!afe->memif)
10981105
return -ENOMEM;
10991106

11001107
afe->irqs_size = MT8173_AFE_IRQ_NUM;
1101-
afe->irqs = devm_kcalloc(afe->dev, afe->irqs_size,
1108+
afe->irqs = devm_kcalloc(dev, afe->irqs_size,
11021109
sizeof(*afe->irqs), GFP_KERNEL);
11031110
if (!afe->irqs)
11041111
return -ENOMEM;
@@ -1117,9 +1124,9 @@ static int mt8173_afe_pcm_dev_probe(struct platform_device *pdev)
11171124

11181125
platform_set_drvdata(pdev, afe);
11191126

1120-
pm_runtime_enable(&pdev->dev);
1121-
if (!pm_runtime_enabled(&pdev->dev)) {
1122-
ret = mt8173_afe_runtime_resume(&pdev->dev);
1127+
pm_runtime_enable(dev);
1128+
if (!pm_runtime_enabled(dev)) {
1129+
ret = mt8173_afe_runtime_resume(dev);
11231130
if (ret)
11241131
goto err_pm_disable;
11251132
}
@@ -1129,21 +1136,20 @@ static int mt8173_afe_pcm_dev_probe(struct platform_device *pdev)
11291136
afe->runtime_resume = mt8173_afe_runtime_resume;
11301137
afe->runtime_suspend = mt8173_afe_runtime_suspend;
11311138

1132-
ret = devm_snd_soc_register_component(&pdev->dev,
1133-
&mtk_afe_pcm_platform,
1134-
NULL, 0);
1139+
ret = devm_snd_soc_register_component(dev, &mtk_afe_pcm_platform,
1140+
NULL, 0);
11351141
if (ret)
11361142
goto err_pm_disable;
11371143

1138-
comp_pcm = devm_kzalloc(&pdev->dev, sizeof(*comp_pcm), GFP_KERNEL);
1144+
comp_pcm = devm_kzalloc(dev, sizeof(*comp_pcm), GFP_KERNEL);
11391145
if (!comp_pcm) {
11401146
ret = -ENOMEM;
11411147
goto err_pm_disable;
11421148
}
11431149

11441150
ret = snd_soc_component_initialize(comp_pcm,
11451151
&mt8173_afe_pcm_dai_component,
1146-
&pdev->dev);
1152+
dev);
11471153
if (ret)
11481154
goto err_pm_disable;
11491155

@@ -1157,15 +1163,15 @@ static int mt8173_afe_pcm_dev_probe(struct platform_device *pdev)
11571163
if (ret)
11581164
goto err_pm_disable;
11591165

1160-
comp_hdmi = devm_kzalloc(&pdev->dev, sizeof(*comp_hdmi), GFP_KERNEL);
1166+
comp_hdmi = devm_kzalloc(dev, sizeof(*comp_hdmi), GFP_KERNEL);
11611167
if (!comp_hdmi) {
11621168
ret = -ENOMEM;
11631169
goto err_cleanup_components;
11641170
}
11651171

11661172
ret = snd_soc_component_initialize(comp_hdmi,
11671173
&mt8173_afe_hdmi_dai_component,
1168-
&pdev->dev);
1174+
dev);
11691175
if (ret)
11701176
goto err_cleanup_components;
11711177

@@ -1179,30 +1185,32 @@ static int mt8173_afe_pcm_dev_probe(struct platform_device *pdev)
11791185
if (ret)
11801186
goto err_cleanup_components;
11811187

1182-
ret = devm_request_irq(afe->dev, irq_id, mt8173_afe_irq_handler,
1188+
ret = devm_request_irq(dev, irq_id, mt8173_afe_irq_handler,
11831189
0, "Afe_ISR_Handle", (void *)afe);
11841190
if (ret) {
1185-
dev_err(afe->dev, "could not request_irq\n");
1191+
dev_err(dev, "could not request_irq\n");
11861192
goto err_cleanup_components;
11871193
}
11881194

1189-
dev_info(&pdev->dev, "MT8173 AFE driver initialized.\n");
1195+
dev_info(dev, "MT8173 AFE driver initialized.\n");
11901196
return 0;
11911197

11921198
err_cleanup_components:
1193-
snd_soc_unregister_component(&pdev->dev);
1199+
snd_soc_unregister_component(dev);
11941200
err_pm_disable:
1195-
pm_runtime_disable(&pdev->dev);
1201+
pm_runtime_disable(dev);
11961202
return ret;
11971203
}
11981204

11991205
static void mt8173_afe_pcm_dev_remove(struct platform_device *pdev)
12001206
{
1201-
snd_soc_unregister_component(&pdev->dev);
1207+
struct device *dev = &pdev->dev;
1208+
1209+
snd_soc_unregister_component(dev);
12021210

1203-
pm_runtime_disable(&pdev->dev);
1204-
if (!pm_runtime_status_suspended(&pdev->dev))
1205-
mt8173_afe_runtime_suspend(&pdev->dev);
1211+
pm_runtime_disable(dev);
1212+
if (!pm_runtime_status_suspended(dev))
1213+
mt8173_afe_runtime_suspend(dev);
12061214
}
12071215

12081216
static const struct of_device_id mt8173_afe_pcm_dt_match[] = {

0 commit comments

Comments
 (0)