Skip to content

Commit b5ff606

Browse files
tinghan-shenplbossart
authored andcommitted
ASoC: SOF: mediatek: Add mt8186 dsp clock support
Add adsp clock on/off support on mt8186 SoC. Signed-off-by: Allen-KH Cheng <allen-kh.cheng@mediatek.com> Signed-off-by: Tinghan Shen <tinghan.shen@mediatek.com>
1 parent 6cbd290 commit b5ff606

4 files changed

Lines changed: 141 additions & 1 deletion

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
2-
snd-sof-mt8186-objs := mt8186.o mt8186-loader.o
2+
snd-sof-mt8186-objs := mt8186.o mt8186-clk.o mt8186-loader.o
33
obj-$(CONFIG_SND_SOC_SOF_MT8186) += snd-sof-mt8186.o
44

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

sound/soc/sof/mediatek/mt8186/mt8186.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "../../sof-audio.h"
2626
#include "../adsp_helper.h"
2727
#include "mt8186.h"
28+
#include "mt8186-clk.h"
2829

2930
static int platform_parse_resource(struct platform_device *pdev, void *data)
3031
{
@@ -276,6 +277,19 @@ static int mt8186_dsp_probe(struct snd_sof_dev *sdev)
276277
return ret;
277278
}
278279

280+
/* enable adsp clock before touching registers */
281+
ret = mt8186_adsp_init_clock(sdev);
282+
if (ret) {
283+
dev_err(sdev->dev, "mt8186_adsp_init_clock failed\n");
284+
return ret;
285+
}
286+
287+
ret = adsp_clock_on(sdev);
288+
if (ret) {
289+
dev_err(sdev->dev, "adsp_clock_on fail!\n");
290+
return ret;
291+
}
292+
279293
adsp_sram_power_on(sdev);
280294

281295
return 0;
@@ -285,6 +299,7 @@ static int mt8186_dsp_remove(struct snd_sof_dev *sdev)
285299
{
286300
sof_hifixdsp_shutdown(sdev);
287301
adsp_sram_power_off(sdev);
302+
adsp_clock_off(sdev);
288303

289304
return 0;
290305
}

0 commit comments

Comments
 (0)