Commit 85780eb5 authored by Mark Brown's avatar Mark Brown

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.
parents e5737cce 0e0b83cc
......@@ -21,6 +21,15 @@ config SND_SOC_SOF_MTK_COMMON
This option is not user-selectable but automagically handled by
'select' statements at a higher level
config SND_SOC_SOF_MT8186
tristate "SOF support for MT8186 audio DSP"
select SND_SOC_SOF_MTK_COMMON
help
This adds support for Sound Open Firmware for Mediatek platforms
using the mt8186 processors.
Say Y if you have such a device.
If unsure select "N".
config SND_SOC_SOF_MT8195
tristate "SOF support for MT8195 audio DSP"
select SND_SOC_SOF_MTK_COMMON
......
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
obj-$(CONFIG_SND_SOC_SOF_MT8195) += mt8195/
obj-$(CONFIG_SND_SOC_SOF_MT8186) += mt8186/
......@@ -29,6 +29,14 @@ struct mtk_adsp_chip_info {
void __iomem *shared_dram; /* part of va_dram */
phys_addr_t adsp_bootup_addr;
int dram_offset; /*dram offset between system and dsp view*/
phys_addr_t pa_secreg;
u32 secregsize;
void __iomem *va_secreg;
phys_addr_t pa_busreg;
u32 busregsize;
void __iomem *va_busreg;
};
struct adsp_priv {
......
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
snd-sof-mt8186-objs := mt8186.o mt8186-clk.o mt8186-loader.o
obj-$(CONFIG_SND_SOC_SOF_MT8186) += snd-sof-mt8186.o
// SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
//
// Copyright(c) 2022 Mediatek Corporation. All rights reserved.
//
// Author: Allen-KH Cheng <allen-kh.cheng@mediatek.com>
// Tinghan Shen <tinghan.shen@mediatek.com>
//
// Hardware interface for mt8186 DSP clock
#include <linux/clk.h>
#include <linux/pm_runtime.h>
#include <linux/io.h>
#include "../../sof-audio.h"
#include "../../ops.h"
#include "../adsp_helper.h"
#include "mt8186.h"
#include "mt8186-clk.h"
static const char *adsp_clks[ADSP_CLK_MAX] = {
[CLK_TOP_AUDIODSP] = "audiodsp_sel",
[CLK_TOP_ADSP_BUS] = "adsp_bus_sel",
};
int mt8186_adsp_init_clock(struct snd_sof_dev *sdev)
{
struct adsp_priv *priv = sdev->pdata->hw_pdata;
struct device *dev = sdev->dev;
int i;
priv->clk = devm_kcalloc(dev, ADSP_CLK_MAX, sizeof(*priv->clk), GFP_KERNEL);
if (!priv->clk)
return -ENOMEM;
for (i = 0; i < ADSP_CLK_MAX; i++) {
priv->clk[i] = devm_clk_get(dev, adsp_clks[i]);
if (IS_ERR(priv->clk[i]))
return PTR_ERR(priv->clk[i]);
}
return 0;
}
static int adsp_enable_all_clock(struct snd_sof_dev *sdev)
{
struct adsp_priv *priv = sdev->pdata->hw_pdata;
struct device *dev = sdev->dev;
int ret;
ret = clk_prepare_enable(priv->clk[CLK_TOP_AUDIODSP]);
if (ret) {
dev_err(dev, "%s clk_prepare_enable(audiodsp) fail %d\n",
__func__, ret);
return ret;
}
ret = clk_prepare_enable(priv->clk[CLK_TOP_ADSP_BUS]);
if (ret) {
dev_err(dev, "%s clk_prepare_enable(adsp_bus) fail %d\n",
__func__, ret);
clk_disable_unprepare(priv->clk[CLK_TOP_AUDIODSP]);
return ret;
}
return 0;
}
static void adsp_disable_all_clock(struct snd_sof_dev *sdev)
{
struct adsp_priv *priv = sdev->pdata->hw_pdata;
clk_disable_unprepare(priv->clk[CLK_TOP_ADSP_BUS]);
clk_disable_unprepare(priv->clk[CLK_TOP_AUDIODSP]);
}
int adsp_clock_on(struct snd_sof_dev *sdev)
{
struct device *dev = sdev->dev;
int ret;
ret = adsp_enable_all_clock(sdev);
if (ret) {
dev_err(dev, "failed to adsp_enable_clock: %d\n", ret);
return ret;
}
snd_sof_dsp_write(sdev, DSP_REG_BAR, ADSP_CK_EN,
UART_EN | DMA_EN | TIMER_EN | COREDBG_EN | CORE_CLK_EN);
snd_sof_dsp_write(sdev, DSP_REG_BAR, ADSP_UART_CTRL,
UART_BCLK_CG | UART_RSTN);
return 0;
}
void adsp_clock_off(struct snd_sof_dev *sdev)
{
snd_sof_dsp_write(sdev, DSP_REG_BAR, ADSP_CK_EN, 0);
snd_sof_dsp_write(sdev, DSP_REG_BAR, ADSP_UART_CTRL, 0);
adsp_disable_all_clock(sdev);
}
/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
/*
* Copyright (c) 2022 MediaTek Corporation. All rights reserved.
*
* Header file for the mt8186 DSP clock definition
*/
#ifndef __MT8186_CLK_H
#define __MT8186_CLK_H
struct snd_sof_dev;
/* DSP clock */
enum adsp_clk_id {
CLK_TOP_AUDIODSP,
CLK_TOP_ADSP_BUS,
ADSP_CLK_MAX
};
int mt8186_adsp_init_clock(struct snd_sof_dev *sdev);
int adsp_clock_on(struct snd_sof_dev *sdev);
void adsp_clock_off(struct snd_sof_dev *sdev);
#endif
// SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
//
// Copyright (c) 2022 Mediatek Corporation. All rights reserved.
//
// Author: Allen-KH Cheng <allen-kh.cheng@mediatek.com>
// Tinghan Shen <tinghan.shen@mediatek.com>
//
// Hardware interface for mt8186 DSP code loader
#include <sound/sof.h>
#include "mt8186.h"
#include "../../ops.h"
void sof_hifixdsp_boot_sequence(struct snd_sof_dev *sdev, u32 boot_addr)
{
/* set RUNSTALL to stop core */
snd_sof_dsp_update_bits(sdev, DSP_REG_BAR, ADSP_HIFI_IO_CONFIG,
RUNSTALL, RUNSTALL);
/* set core boot address */
snd_sof_dsp_write(sdev, DSP_SECREG_BAR, ADSP_ALTVEC_C0, boot_addr);
snd_sof_dsp_write(sdev, DSP_SECREG_BAR, ADSP_ALTVECSEL, ADSP_ALTVECSEL_C0);
/* assert core reset */
snd_sof_dsp_update_bits(sdev, DSP_REG_BAR, ADSP_CFGREG_SW_RSTN,
SW_RSTN_C0 | SW_DBG_RSTN_C0,
SW_RSTN_C0 | SW_DBG_RSTN_C0);
/* hardware requirement */
udelay(1);
/* release core reset */
snd_sof_dsp_update_bits(sdev, DSP_REG_BAR, ADSP_CFGREG_SW_RSTN,
SW_RSTN_C0 | SW_DBG_RSTN_C0,
0);
/* clear RUNSTALL (bit31) to start core */
snd_sof_dsp_update_bits(sdev, DSP_REG_BAR, ADSP_HIFI_IO_CONFIG,
RUNSTALL, 0);
}
void sof_hifixdsp_shutdown(struct snd_sof_dev *sdev)
{
/* set RUNSTALL to stop core */
snd_sof_dsp_update_bits(sdev, DSP_REG_BAR, ADSP_HIFI_IO_CONFIG,
RUNSTALL, RUNSTALL);
/* assert core reset */
snd_sof_dsp_update_bits(sdev, DSP_REG_BAR, ADSP_CFGREG_SW_RSTN,
SW_RSTN_C0 | SW_DBG_RSTN_C0,
SW_RSTN_C0 | SW_DBG_RSTN_C0);
}
This diff is collapsed.
/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
/*
* Copyright (c) 2022 MediaTek Corporation. All rights reserved.
*
* Header file for the mt8186 DSP register definition
*/
#ifndef __MT8186_H
#define __MT8186_H
struct mtk_adsp_chip_info;
struct snd_sof_dev;
#define DSP_REG_BAR 4
#define DSP_SECREG_BAR 5
#define DSP_BUSREG_BAR 6
/*****************************************************************************
* R E G I S T E R TABLE
*****************************************************************************/
/* dsp cfg */
#define ADSP_CFGREG_SW_RSTN 0x0000
#define SW_DBG_RSTN_C0 BIT(0)
#define SW_RSTN_C0 BIT(4)
#define ADSP_HIFI_IO_CONFIG 0x000C
#define TRACEMEMREADY BIT(15)
#define RUNSTALL BIT(31)
#define ADSP_IRQ_MASK 0x0030
#define ADSP_DVFSRC_REQ 0x0040
#define ADSP_DDREN_REQ_0 0x0044
#define ADSP_SEMAPHORE 0x0064
#define ADSP_WDT_CON_C0 0x007C
#define ADSP_MBOX_IRQ_EN 0x009C
#define DSP_MBOX0_IRQ_EN BIT(0)
#define DSP_MBOX1_IRQ_EN BIT(1)
#define DSP_MBOX2_IRQ_EN BIT(2)
#define DSP_MBOX3_IRQ_EN BIT(3)
#define DSP_MBOX4_IRQ_EN BIT(4)
#define DSP_PDEBUGPC 0x013C
#define ADSP_CK_EN 0x1000
#define CORE_CLK_EN BIT(0)
#define COREDBG_EN BIT(1)
#define TIMER_EN BIT(3)
#define DMA_EN BIT(4)
#define UART_EN BIT(5)
#define ADSP_UART_CTRL 0x1010
#define UART_BCLK_CG BIT(0)
#define UART_RSTN BIT(3)
/* dsp sec */
#define ADSP_PRID 0x0
#define ADSP_ALTVEC_C0 0x04
#define ADSP_ALTVECSEL 0x0C
#define ADSP_ALTVECSEL_C0 BIT(1)
/* dsp bus */
#define ADSP_SRAM_POOL_CON 0x190
#define DSP_SRAM_POOL_PD_MASK 0xF00F /* [0:3] and [12:15] */
#define DSP_C0_EMI_MAP_ADDR 0xA00 /* ADSP Core0 To EMI Address Remap */
#define DSP_C0_DMAEMI_MAP_ADDR 0xA08 /* DMA0 To EMI Address Remap */
/* DSP memories */
#define MBOX_OFFSET 0x500000 /* DRAM */
#define MBOX_SIZE 0x1000 /* consistent with which in memory.h of sof fw */
#define DSP_DRAM_SIZE 0xA00000 /* 16M */
/*remap dram between AP and DSP view, 4KB aligned*/
#define SRAM_PHYS_BASE_FROM_DSP_VIEW 0x4E100000 /* MT8186 DSP view */
#define DRAM_PHYS_BASE_FROM_DSP_VIEW 0x60000000 /* MT8186 DSP view */
#define DRAM_REMAP_SHIFT 12
#define DRAM_REMAP_MASK 0xFFF
#define SIZE_SHARED_DRAM_DL 0x40000 /*Shared buffer for Downlink*/
#define SIZE_SHARED_DRAM_UL 0x40000 /*Shared buffer for Uplink*/
#define TOTAL_SIZE_SHARED_DRAM_FROM_TAIL (SIZE_SHARED_DRAM_DL + SIZE_SHARED_DRAM_UL)
void sof_hifixdsp_boot_sequence(struct snd_sof_dev *sdev, u32 boot_addr);
void sof_hifixdsp_shutdown(struct snd_sof_dev *sdev);
#endif
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