Skip to content

Commit 85780eb

Browse files
committed
Add support of MediaTek mt8186 to SOF
Merge series from Tinghan Shen <tinghan.shen@mediatek.com>: Add support of MediaTek mt8186 SoC DSP to SOF.
2 parents e5737cc + 0e0b83c commit 85780eb

9 files changed

Lines changed: 693 additions & 0 deletions

File tree

sound/soc/sof/mediatek/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ config SND_SOC_SOF_MTK_COMMON
2121
This option is not user-selectable but automagically handled by
2222
'select' statements at a higher level
2323

24+
config SND_SOC_SOF_MT8186
25+
tristate "SOF support for MT8186 audio DSP"
26+
select SND_SOC_SOF_MTK_COMMON
27+
help
28+
This adds support for Sound Open Firmware for Mediatek platforms
29+
using the mt8186 processors.
30+
Say Y if you have such a device.
31+
If unsure select "N".
32+
2433
config SND_SOC_SOF_MT8195
2534
tristate "SOF support for MT8195 audio DSP"
2635
select SND_SOC_SOF_MTK_COMMON

sound/soc/sof/mediatek/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
22
obj-$(CONFIG_SND_SOC_SOF_MT8195) += mt8195/
3+
obj-$(CONFIG_SND_SOC_SOF_MT8186) += mt8186/

sound/soc/sof/mediatek/adsp_helper.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ struct mtk_adsp_chip_info {
2929
void __iomem *shared_dram; /* part of va_dram */
3030
phys_addr_t adsp_bootup_addr;
3131
int dram_offset; /*dram offset between system and dsp view*/
32+
33+
phys_addr_t pa_secreg;
34+
u32 secregsize;
35+
void __iomem *va_secreg;
36+
37+
phys_addr_t pa_busreg;
38+
u32 busregsize;
39+
void __iomem *va_busreg;
3240
};
3341

3442
struct adsp_priv {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
2+
snd-sof-mt8186-objs := mt8186.o mt8186-clk.o mt8186-loader.o
3+
obj-$(CONFIG_SND_SOC_SOF_MT8186) += snd-sof-mt8186.o
4+
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
2+
//
3+
// Copyright(c) 2022 Mediatek Corporation. All rights reserved.
4+
//
5+
// Author: Allen-KH Cheng <allen-kh.cheng@mediatek.com>
6+
// Tinghan Shen <tinghan.shen@mediatek.com>
7+
//
8+
// Hardware interface for mt8186 DSP clock
9+
10+
#include <linux/clk.h>
11+
#include <linux/pm_runtime.h>
12+
#include <linux/io.h>
13+
14+
#include "../../sof-audio.h"
15+
#include "../../ops.h"
16+
#include "../adsp_helper.h"
17+
#include "mt8186.h"
18+
#include "mt8186-clk.h"
19+
20+
static const char *adsp_clks[ADSP_CLK_MAX] = {
21+
[CLK_TOP_AUDIODSP] = "audiodsp_sel",
22+
[CLK_TOP_ADSP_BUS] = "adsp_bus_sel",
23+
};
24+
25+
int mt8186_adsp_init_clock(struct snd_sof_dev *sdev)
26+
{
27+
struct adsp_priv *priv = sdev->pdata->hw_pdata;
28+
struct device *dev = sdev->dev;
29+
int i;
30+
31+
priv->clk = devm_kcalloc(dev, ADSP_CLK_MAX, sizeof(*priv->clk), GFP_KERNEL);
32+
if (!priv->clk)
33+
return -ENOMEM;
34+
35+
for (i = 0; i < ADSP_CLK_MAX; i++) {
36+
priv->clk[i] = devm_clk_get(dev, adsp_clks[i]);
37+
38+
if (IS_ERR(priv->clk[i]))
39+
return PTR_ERR(priv->clk[i]);
40+
}
41+
42+
return 0;
43+
}
44+
45+
static int adsp_enable_all_clock(struct snd_sof_dev *sdev)
46+
{
47+
struct adsp_priv *priv = sdev->pdata->hw_pdata;
48+
struct device *dev = sdev->dev;
49+
int ret;
50+
51+
ret = clk_prepare_enable(priv->clk[CLK_TOP_AUDIODSP]);
52+
if (ret) {
53+
dev_err(dev, "%s clk_prepare_enable(audiodsp) fail %d\n",
54+
__func__, ret);
55+
return ret;
56+
}
57+
58+
ret = clk_prepare_enable(priv->clk[CLK_TOP_ADSP_BUS]);
59+
if (ret) {
60+
dev_err(dev, "%s clk_prepare_enable(adsp_bus) fail %d\n",
61+
__func__, ret);
62+
clk_disable_unprepare(priv->clk[CLK_TOP_AUDIODSP]);
63+
return ret;
64+
}
65+
66+
return 0;
67+
}
68+
69+
static void adsp_disable_all_clock(struct snd_sof_dev *sdev)
70+
{
71+
struct adsp_priv *priv = sdev->pdata->hw_pdata;
72+
73+
clk_disable_unprepare(priv->clk[CLK_TOP_ADSP_BUS]);
74+
clk_disable_unprepare(priv->clk[CLK_TOP_AUDIODSP]);
75+
}
76+
77+
int adsp_clock_on(struct snd_sof_dev *sdev)
78+
{
79+
struct device *dev = sdev->dev;
80+
int ret;
81+
82+
ret = adsp_enable_all_clock(sdev);
83+
if (ret) {
84+
dev_err(dev, "failed to adsp_enable_clock: %d\n", ret);
85+
return ret;
86+
}
87+
snd_sof_dsp_write(sdev, DSP_REG_BAR, ADSP_CK_EN,
88+
UART_EN | DMA_EN | TIMER_EN | COREDBG_EN | CORE_CLK_EN);
89+
snd_sof_dsp_write(sdev, DSP_REG_BAR, ADSP_UART_CTRL,
90+
UART_BCLK_CG | UART_RSTN);
91+
92+
return 0;
93+
}
94+
95+
void adsp_clock_off(struct snd_sof_dev *sdev)
96+
{
97+
snd_sof_dsp_write(sdev, DSP_REG_BAR, ADSP_CK_EN, 0);
98+
snd_sof_dsp_write(sdev, DSP_REG_BAR, ADSP_UART_CTRL, 0);
99+
adsp_disable_all_clock(sdev);
100+
}
101+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
2+
3+
/*
4+
* Copyright (c) 2022 MediaTek Corporation. All rights reserved.
5+
*
6+
* Header file for the mt8186 DSP clock definition
7+
*/
8+
9+
#ifndef __MT8186_CLK_H
10+
#define __MT8186_CLK_H
11+
12+
struct snd_sof_dev;
13+
14+
/* DSP clock */
15+
enum adsp_clk_id {
16+
CLK_TOP_AUDIODSP,
17+
CLK_TOP_ADSP_BUS,
18+
ADSP_CLK_MAX
19+
};
20+
21+
int mt8186_adsp_init_clock(struct snd_sof_dev *sdev);
22+
int adsp_clock_on(struct snd_sof_dev *sdev);
23+
void adsp_clock_off(struct snd_sof_dev *sdev);
24+
#endif
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
2+
//
3+
// Copyright (c) 2022 Mediatek Corporation. All rights reserved.
4+
//
5+
// Author: Allen-KH Cheng <allen-kh.cheng@mediatek.com>
6+
// Tinghan Shen <tinghan.shen@mediatek.com>
7+
//
8+
// Hardware interface for mt8186 DSP code loader
9+
10+
#include <sound/sof.h>
11+
#include "mt8186.h"
12+
#include "../../ops.h"
13+
14+
void sof_hifixdsp_boot_sequence(struct snd_sof_dev *sdev, u32 boot_addr)
15+
{
16+
/* set RUNSTALL to stop core */
17+
snd_sof_dsp_update_bits(sdev, DSP_REG_BAR, ADSP_HIFI_IO_CONFIG,
18+
RUNSTALL, RUNSTALL);
19+
20+
/* set core boot address */
21+
snd_sof_dsp_write(sdev, DSP_SECREG_BAR, ADSP_ALTVEC_C0, boot_addr);
22+
snd_sof_dsp_write(sdev, DSP_SECREG_BAR, ADSP_ALTVECSEL, ADSP_ALTVECSEL_C0);
23+
24+
/* assert core reset */
25+
snd_sof_dsp_update_bits(sdev, DSP_REG_BAR, ADSP_CFGREG_SW_RSTN,
26+
SW_RSTN_C0 | SW_DBG_RSTN_C0,
27+
SW_RSTN_C0 | SW_DBG_RSTN_C0);
28+
29+
/* hardware requirement */
30+
udelay(1);
31+
32+
/* release core reset */
33+
snd_sof_dsp_update_bits(sdev, DSP_REG_BAR, ADSP_CFGREG_SW_RSTN,
34+
SW_RSTN_C0 | SW_DBG_RSTN_C0,
35+
0);
36+
37+
/* clear RUNSTALL (bit31) to start core */
38+
snd_sof_dsp_update_bits(sdev, DSP_REG_BAR, ADSP_HIFI_IO_CONFIG,
39+
RUNSTALL, 0);
40+
}
41+
42+
void sof_hifixdsp_shutdown(struct snd_sof_dev *sdev)
43+
{
44+
/* set RUNSTALL to stop core */
45+
snd_sof_dsp_update_bits(sdev, DSP_REG_BAR, ADSP_HIFI_IO_CONFIG,
46+
RUNSTALL, RUNSTALL);
47+
48+
/* assert core reset */
49+
snd_sof_dsp_update_bits(sdev, DSP_REG_BAR, ADSP_CFGREG_SW_RSTN,
50+
SW_RSTN_C0 | SW_DBG_RSTN_C0,
51+
SW_RSTN_C0 | SW_DBG_RSTN_C0);
52+
}
53+

0 commit comments

Comments
 (0)