Skip to content

Commit 63c13d6

Browse files
erinloandersson
authored andcommitted
remoteproc/mediatek: add SCP support for mt8183
Provide a basic driver to control Cortex M4 co-processor Signed-off-by: Erin Lo <[email protected]> Signed-off-by: Nicolas Boichat <[email protected]> Signed-off-by: Pi-Hsun Shih <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Bjorn Andersson <[email protected]>
1 parent e47e988 commit 63c13d6

File tree

6 files changed

+995
-0
lines changed

6 files changed

+995
-0
lines changed

drivers/remoteproc/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ config IMX_REMOTEPROC
2323

2424
It's safe to say N here.
2525

26+
config MTK_SCP
27+
tristate "Mediatek SCP support"
28+
depends on ARCH_MEDIATEK
29+
help
30+
Say y here to support Mediatek's System Companion Processor (SCP) via
31+
the remote processor framework.
32+
33+
It's safe to say N here.
34+
2635
config OMAP_REMOTEPROC
2736
tristate "OMAP remoteproc support"
2837
depends on ARCH_OMAP4 || SOC_OMAP5

drivers/remoteproc/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ remoteproc-y += remoteproc_sysfs.o
1010
remoteproc-y += remoteproc_virtio.o
1111
remoteproc-y += remoteproc_elf_loader.o
1212
obj-$(CONFIG_IMX_REMOTEPROC) += imx_rproc.o
13+
obj-$(CONFIG_MTK_SCP) += mtk_scp.o mtk_scp_ipi.o
1314
obj-$(CONFIG_OMAP_REMOTEPROC) += omap_remoteproc.o
1415
obj-$(CONFIG_WKUP_M3_RPROC) += wkup_m3_rproc.o
1516
obj-$(CONFIG_DA8XX_REMOTEPROC) += da8xx_remoteproc.o

drivers/remoteproc/mtk_common.h

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* Copyright (c) 2019 MediaTek Inc.
4+
*/
5+
6+
#ifndef __RPROC_MTK_COMMON_H
7+
#define __RPROC_MTK_COMMON_H
8+
9+
#include <linux/interrupt.h>
10+
#include <linux/kernel.h>
11+
#include <linux/platform_device.h>
12+
#include <linux/remoteproc.h>
13+
#include <linux/remoteproc/mtk_scp.h>
14+
15+
#define MT8183_SW_RSTN 0x0
16+
#define MT8183_SW_RSTN_BIT BIT(0)
17+
#define MT8183_SCP_TO_HOST 0x1C
18+
#define MT8183_SCP_IPC_INT_BIT BIT(0)
19+
#define MT8183_SCP_WDT_INT_BIT BIT(8)
20+
#define MT8183_HOST_TO_SCP 0x28
21+
#define MT8183_HOST_IPC_INT_BIT BIT(0)
22+
#define MT8183_WDT_CFG 0x84
23+
#define MT8183_SCP_CLK_SW_SEL 0x4000
24+
#define MT8183_SCP_CLK_DIV_SEL 0x4024
25+
#define MT8183_SCP_SRAM_PDN 0x402C
26+
#define MT8183_SCP_L1_SRAM_PD 0x4080
27+
#define MT8183_SCP_TCM_TAIL_SRAM_PD 0x4094
28+
29+
#define MT8183_SCP_CACHE_SEL(x) (0x14000 + (x) * 0x3000)
30+
#define MT8183_SCP_CACHE_CON MT8183_SCP_CACHE_SEL(0)
31+
#define MT8183_SCP_DCACHE_CON MT8183_SCP_CACHE_SEL(1)
32+
#define MT8183_SCP_CACHESIZE_8KB BIT(8)
33+
#define MT8183_SCP_CACHE_CON_WAYEN BIT(10)
34+
35+
#define SCP_FW_VER_LEN 32
36+
#define SCP_SHARE_BUFFER_SIZE 288
37+
38+
struct scp_run {
39+
u32 signaled;
40+
s8 fw_ver[SCP_FW_VER_LEN];
41+
u32 dec_capability;
42+
u32 enc_capability;
43+
wait_queue_head_t wq;
44+
};
45+
46+
struct scp_ipi_desc {
47+
/* For protecting handler. */
48+
struct mutex lock;
49+
scp_ipi_handler_t handler;
50+
void *priv;
51+
};
52+
53+
struct mtk_scp {
54+
struct device *dev;
55+
struct rproc *rproc;
56+
struct clk *clk;
57+
void __iomem *reg_base;
58+
void __iomem *sram_base;
59+
size_t sram_size;
60+
61+
struct mtk_share_obj __iomem *recv_buf;
62+
struct mtk_share_obj __iomem *send_buf;
63+
struct scp_run run;
64+
/* To prevent multiple ipi_send run concurrently. */
65+
struct mutex send_lock;
66+
struct scp_ipi_desc ipi_desc[SCP_IPI_MAX];
67+
bool ipi_id_ack[SCP_IPI_MAX];
68+
wait_queue_head_t ack_wq;
69+
70+
void __iomem *cpu_addr;
71+
phys_addr_t phys_addr;
72+
size_t dram_size;
73+
};
74+
75+
/**
76+
* struct mtk_share_obj - SRAM buffer shared with AP and SCP
77+
*
78+
* @id: IPI id
79+
* @len: share buffer length
80+
* @share_buf: share buffer data
81+
*/
82+
struct mtk_share_obj {
83+
u32 id;
84+
u32 len;
85+
u8 share_buf[SCP_SHARE_BUFFER_SIZE];
86+
};
87+
88+
void scp_memcpy_aligned(void __iomem *dst, const void *src, unsigned int len);
89+
void scp_ipi_lock(struct mtk_scp *scp, u32 id);
90+
void scp_ipi_unlock(struct mtk_scp *scp, u32 id);
91+
92+
#endif

0 commit comments

Comments
 (0)