Initial commit: Linux kernel 4.19 for Unplugged OS

This commit is contained in:
ziv committed 2025-10-06 13:52:42 +00:00
commit d30235b04c
80519 files changed
+35800681

No files matched your search

+10
View File
@@ -0,0 +1,10 @@
config MTK_AUDIODSP_SUPPORT
bool "Specifiy If Platform Support Audio dsp"
default n
select MTK_AUDIO_IPI
help
AUDIO_DSP is a MediaTek in-house DSP which can do
different audio process.
Set Y to enable this feature.
If unsure,
Set N to stay with legancy feature.
+29
View File
@@ -0,0 +1,29 @@
#
# Copyright (C) 2015 MediaTek Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
subdir-ccflags-y += -Wformat
ifeq ($(CONFIG_MACH_MT6781), y)
MTK_PLATFORM := mt6781
obj-y += $(MTK_PLATFORM)/
else
obj-y += $(subst ",,$(CONFIG_MTK_PLATFORM))/
endif
ifeq ($(CONFIG_MACH_MT6785), y)
MTK_ADSP_HW_VER := 0
else ifeq ($(CONFIG_MACH_MT6781), y)
MTK_ADSP_HW_VER := 0
else
MTK_ADSP_HW_VER := 1
endif
subdir-ccflags-y += -DMTK_ADSP_HW_VER=$(MTK_ADSP_HW_VER)
@@ -0,0 +1,29 @@
obj-y += adsp.o
adsp-y := adsp_helper.o adsp_excep.o adsp_excep.o adsp_ipi.o adsp_irq.o
adsp-y += adsp_logger.o adsp_service.o adsp_timesync.o
#adsp-y += adsp_timesync.o adsp_trace.o
ccflags-y += -I$(srctree)/drivers/misc/mediatek/audio_ipi/common_v1/framework
ccflags-y += -I$(srctree)/drivers/misc/mediatek/scp/$(CONFIG_MTK_PLATFORM)
ifeq ($(CONFIG_MACH_MT6781),y)
ADSP_PLATFORM := mt6781
else
ADSP_PLATFORM := $(subst ",,$(CONFIG_MTK_PLATFORM))
endif
ccflags-y += -I$(srctree)/drivers/misc/mediatek/adsp/$(ADSP_PLATFORM)
# include emi_mpu.h
ccflags-y += -I$(srctree)/drivers/misc/mediatek/include/mt-plat/$(ADSP_PLATFORM)/include/mach
ccflags-y += -I$(srctree)/drivers/misc/mediatek/emi/$(CONFIG_MTK_PLATFORM)
ccflags-y += -I$(srctree)/drivers/misc/mediatek/base/power/include/spm
ifeq ($(CONFIG_MTK_ENG_BUILD),y)
CFLAGS_adsp_logger.o += -DDEBUG
CFLAGS_adsp_helper.o += -DDEBUG
CFLAGS_adsp_excep.o += -DDEBUG
CFLAGS_adsp_ipi.o += -DDEBUG
CFLAGS_adsp_irq.o += -DDEBUG
CFLAGS_adsp_dvfs.o += -DDEBUG
CFLAGS_adsp_clk.o += -DDEBUG
CFLAGS_adsp_service.o += -DDEBUG
CFLAGS_adsp_timesync.o += -DDEBUG
endif
@@ -0,0 +1,659 @@
// SPDX-License-Identifier: GPL-2.0
//
// adsp_excep.c-- Mediatek ADSP exception handling
//
// Copyright (c) 2018 MediaTek Inc.
// Author: HsinYi Chang <hsin-yi.chang@mediatek.com>
#include <linux/vmalloc.h> /* needed by vmalloc */
#include <linux/slab.h> /* needed by kmalloc */
#include <linux/sysfs.h>
#include <linux/device.h> /* needed by device_* */
#include <linux/workqueue.h>
#include <linux/io.h>
#include <linux/mutex.h>
#include <mt-plat/aee.h>
#include <mt-plat/sync_write.h>
#include <linux/sched_clock.h>
#include <linux/ratelimit.h>
#include "adsp_ipi.h"
#include "adsp_helper.h"
#include "adsp_clk.h"
#include "adsp_excep.h"
#include "adsp_feature_define.h"
#include "adsp_reserved_mem.h"
static unsigned char *adsp_ke_buffer;
static unsigned char *adsp_A_dump_buffer;
unsigned char *adsp_A_dram_dump_buffer;
static struct adsp_work_t adsp_aed_work;
static struct mutex adsp_excep_mutex;
static struct mutex adsp_A_excep_dump_mutex;
static int adsp_A_dram_dump(void);
static ssize_t adsp_A_ramdump(char *buf, loff_t offset, size_t size);
#define ADSP_KE_DUMP_LEN (ADSP_A_CFG_SIZE + ADSP_A_TCM_SIZE)
#define DRV_SetReg32(addr, val) writel(readl(addr) | (val), addr)
/* An ELF note in memory */
struct memelfnote {
const char *name;
int type;
unsigned int datasz;
void *data;
};
static int notesize(struct memelfnote *en)
{
int sz;
sz = sizeof(struct elf32_note);
sz += roundup((strlen(en->name) + 1), 4);
sz += roundup(en->datasz, 4);
return sz;
}
static uint8_t *storenote(struct memelfnote *men, uint8_t *bufp)
{
struct elf32_note en;
en.n_namesz = strlen(men->name) + 1;
en.n_descsz = men->datasz;
en.n_type = men->type;
memcpy(bufp, &en, sizeof(en));
bufp += sizeof(en);
memcpy(bufp, men->name, en.n_namesz);
bufp += en.n_namesz;
bufp = (uint8_t *) roundup((unsigned long)bufp, 4);
memcpy(bufp, men->data, men->datasz);
bufp += men->datasz;
bufp = (uint8_t *) roundup((unsigned long)bufp, 4);
return bufp;
}
static uint8_t *core_write_cpu_note(int cpu, struct elf32_phdr *nhdr,
uint8_t *bufp, enum adsp_core_id id)
{
struct memelfnote notes;
struct elf32_prstatus prstatus;
char cpustr[16];
int n;
memset(&prstatus, 0, sizeof(struct elf32_prstatus));
n = snprintf(cpustr, sizeof(cpustr), "CPU%d", cpu);
if (n < 0)
pr_info("%s, snprintf return error", __func__);
/* set up the process status */
notes.name = cpustr;
notes.type = NT_PRSTATUS;
notes.datasz = sizeof(struct elf32_prstatus);
notes.data = &prstatus;
prstatus.pr_pid = cpu + 1;
if (prstatus.pr_reg[15] == 0x0 && (id == ADSP_A_ID))
prstatus.pr_reg[15] = readl(ADSP_A_WDT_DEBUG_PC_REG);
nhdr->p_filesz += notesize(&notes);
return storenote(&notes, bufp);
}
void adsp_exception_header_init(void *oldbufp, enum adsp_core_id id)
{
struct elf32_phdr *nhdr, *phdr;
struct elf32_hdr *elf;
off_t offset = 0;
uint8_t *bufp = oldbufp;
uint32_t cpu;
/* NT_PRPSINFO */
struct elf32_prpsinfo prpsinfo;
struct memelfnote notes;
elf = (struct elf32_hdr *) bufp;
bufp += sizeof(struct elf32_hdr);
offset += sizeof(struct elf32_hdr);
elf_setup_eident(elf->e_ident, ELFCLASS32);
/*setup elf header*/
elf->e_type = ET_CORE;
elf->e_machine = EM_ARM;
elf->e_version = EV_CURRENT;
elf->e_entry = 0;
elf->e_phoff = sizeof(struct elf32_hdr);
elf->e_shoff = 0;
elf->e_flags = ELF_CORE_EFLAGS;
elf->e_ehsize = sizeof(struct elf32_hdr);
elf->e_phentsize = sizeof(struct elf32_phdr);
elf->e_phnum = 2;
elf->e_shentsize = 0;
elf->e_shnum = 0;
elf->e_shstrndx = 0;
nhdr = (struct elf32_phdr *) bufp;
bufp += sizeof(struct elf32_phdr);
offset += sizeof(struct elf32_phdr);
memset(nhdr, 0, sizeof(struct elf32_phdr));
nhdr->p_type = PT_NOTE;
phdr = (struct elf32_phdr *) bufp;
bufp += sizeof(struct elf32_phdr);
offset += sizeof(struct elf32_phdr);
phdr->p_flags = PF_R | PF_W | PF_X;
phdr->p_offset = CRASH_MEMORY_HEADER_SIZE;
phdr->p_vaddr = CRASH_MEMORY_OFFSET;
phdr->p_paddr = CRASH_MEMORY_OFFSET;
phdr->p_filesz = (ADSP_A_TCM_SIZE - CRASH_MEMORY_OFFSET);
phdr->p_memsz = (ADSP_A_TCM_SIZE - CRASH_MEMORY_OFFSET);
phdr->p_align = 0;
phdr->p_type = PT_LOAD;
nhdr->p_offset = offset;
/* set up the process info */
notes.name = CORE_STR;
notes.type = NT_PRPSINFO;
notes.datasz = sizeof(struct elf32_prpsinfo);
notes.data = &prpsinfo;
memset(&prpsinfo, 0, sizeof(struct elf32_prpsinfo));
prpsinfo.pr_state = 0;
prpsinfo.pr_sname = 'R';
prpsinfo.pr_zomb = 0;
prpsinfo.pr_gid = prpsinfo.pr_uid = 0x0;
strlcpy(prpsinfo.pr_fname, "freertos8", sizeof(prpsinfo.pr_fname));
strlcpy(prpsinfo.pr_psargs, "freertos8", ELF_PRARGSZ);
nhdr->p_filesz += notesize(&notes);
bufp = storenote(&notes, bufp);
/* Store pre-cpu backtrace */
for (cpu = 0; cpu < 1; cpu++)
bufp = core_write_cpu_note(cpu, nhdr, bufp, id);
}
static u32 copy_from_buffer(void *dest, size_t destsize, void *src,
size_t srcsize, u32 offset, size_t request)
{
/* if request == -1, offset == 0, copy full srcsize */
if (offset + request > srcsize)
request = srcsize - offset;
/* if destsize == -1, don't check the request size */
if (!dest || destsize < request) {
pr_warn("%s, buffer null or not enough space", __func__);
return 0;
}
memcpy(dest, src + offset, request);
return request;
}
static u32 dump_adsp_cfg_reg(void *buf, size_t size)
{
u32 clk_cfg = 0, uart_cfg = 0, n = 0;
/* record CFG registers */
clk_cfg = readl(ADSP_CLK_CTRL_BASE);
uart_cfg = readl(ADSP_UART_CTRL);
DRV_SetReg32(ADSP_CLK_CTRL_BASE, ADSP_CLK_UART_EN);
DRV_SetReg32(ADSP_UART_CTRL, ADSP_UART_RST_N | ADSP_UART_BCLK_CG);
n += copy_from_buffer(buf, size, ADSP_A_CFG, ADSP_A_CFG_SIZE, 0, -1);
/* Restore ADSP CLK and UART setting */
writel(clk_cfg, ADSP_CLK_CTRL_BASE);
writel(uart_cfg, ADSP_UART_CTRL);
return n;
}
static u32 dump_adsp_tcm(void *buf, size_t size)
{
u32 n = 0;
n += copy_from_buffer(buf, size,
ADSP_A_ITCM, ADSP_A_ITCM_SIZE, 0, -1);
n += copy_from_buffer(buf + n, size - n,
ADSP_A_DTCM, ADSP_A_DTCM_SIZE, 0, -1);
return n;
}
static inline u32 dump_adsp_shared_memory(void *buf, size_t size, int id)
{
void *mem_addr = adsp_get_reserve_mem_virt(id);
size_t mem_size = adsp_get_reserve_mem_size(id);
if (!mem_addr)
return 0;
return copy_from_buffer(buf, size, mem_addr, mem_size, 0, -1);
}
static inline u32 copy_from_adsp_shared_memory(void *buf, u32 offset,
size_t size, int id)
{
void *mem_addr = adsp_get_reserve_mem_virt(id);
size_t mem_size = adsp_get_reserve_mem_size(id);
if (!mem_addr)
return 0;
return copy_from_buffer(buf, -1, mem_addr, mem_size, offset, size);
}
/*
* this function need ADSP to keeping awaken
* adsp_crash_dump: dump adsp tcm info.
* @param MemoryDump: adsp dump struct
* @param adsp_core_id: core id
* @return: adsp dump size
*/
static u32 adsp_crash_dump(struct MemoryDump *pMemoryDump,
enum adsp_core_id id)
{
u32 n = 0;
adsp_enable_dsp_clk(true);
mutex_lock(&adsp_sw_reset_mutex);
adsp_exception_header_init(pMemoryDump, id);
n += CRASH_MEMORY_HEADER_SIZE;
n += dump_adsp_tcm((void *)&(pMemoryDump->memory), CRASH_MEMORY_LENGTH);
n += CRASH_CORE_REG_SIZE;
n += dump_adsp_cfg_reg((void *)&(pMemoryDump->cfg_reg),
CRASH_CFG_REG_SIZE);
if (n != sizeof(struct MemoryDump))
pr_info("%s(), size not match n(%x) != MemoryDump(%zd)",
__func__, n, sizeof(struct MemoryDump));
mutex_unlock(&adsp_sw_reset_mutex);
adsp_enable_dsp_clk(false);
return n;
}
/*
* generate aee argument with adsp register dump
* @param aed_str: exception description
* @param aed: struct to store argument for aee api
* @param id: identify adsp core id
*/
static void adsp_prepare_aed_dump(void)
{
struct MemoryDump *pMemoryDump = NULL;
u32 n = 0;
/*prepare adsp A db file*/
pMemoryDump = (struct MemoryDump *)adsp_A_dump_buffer;
if (!pMemoryDump) {
pr_debug("[ADSP AEE]MemoryDump buf is null");
} else {
memset(pMemoryDump, 0, sizeof(*pMemoryDump));
n = adsp_crash_dump(pMemoryDump, ADSP_A_ID);
}
}
/*
* generate an exception according to exception type
* @param type: exception type
*/
void adsp_aed(enum adsp_excep_id type, enum adsp_core_id id)
{
char detail[ADSP_AED_STR_LEN];
struct MemoryDump *pMemoryDump;
struct adsp_coredump *coredump;
u32 n = 0;
char *aed_type;
int db_opt = DB_OPT_DEFAULT;
int ret = 0;
mutex_lock(&adsp_excep_mutex);
/* get adsp title and exception type*/
switch (type) {
case EXCEP_LOAD_FIRMWARE:
aed_type = "load firmware exception";
break;
case EXCEP_RESET:
aed_type = "reset exception";
break;
case EXCEP_BOOTUP:
aed_type = "boot exception";
break;
case EXCEP_RUNTIME:
aed_type = "runtime exception";
break;
case EXCEP_KERNEL:
aed_type = "kernel exception";
db_opt |= DB_OPT_FTRACE;
break;
default:
aed_type = "unknown exception";
break;
}
if (type != EXCEP_LOAD_FIRMWARE) {
mutex_lock(&adsp_A_excep_dump_mutex);
adsp_prepare_aed_dump();
ret = adsp_A_dram_dump();
mutex_unlock(&adsp_A_excep_dump_mutex);
}
pMemoryDump = (struct MemoryDump *)adsp_A_dump_buffer;
coredump = adsp_get_reserve_mem_virt(ADSP_A_CORE_DUMP_MEM_ID);
/*print detail info. in kernel*/
n += snprintf(detail + n, ADSP_AED_STR_LEN - n, "%s %s\n",
adsp_core_ids[ADSP_A_ID], aed_type);
n += snprintf(detail + n, ADSP_AED_STR_LEN - n,
"adsp pc=0x%08x,exccause=0x%x,excvaddr=0x%x\n",
coredump->pc, coredump->exccause, coredump->excvaddr);
n += snprintf(detail + n, ADSP_AED_STR_LEN - n,
"latch pc=0x%08x,sp=0x%08x\n",
*((u32 *)(pMemoryDump->cfg_reg + 0x0170)),
*((u32 *)(pMemoryDump->cfg_reg + 0x0174)));
n += snprintf(detail + n, ADSP_AED_STR_LEN - n,
"CRDISPATCH_KEY:ADSP exception/%s\n",
coredump->task_name);
n += snprintf(detail + n, ADSP_AED_STR_LEN - n, "%s",
coredump->assert_log);
pr_debug("%s", detail);
#ifdef CFG_RECOVERY_SUPPORT
if (ret > 0 && /* if dram backup done, notify reset.work it's okay */
(atomic_read(&adsp_reset_status) == ADSP_RESET_STATUS_START ||
adsp_recovery_flag[ADSP_A_ID] == ADSP_RECOVERY_START)) {
/*complete adsp ee, if adsp reset by wdt or awake fail*/
pr_info("[ADSP]aed finished, complete it\n");
complete(&adsp_sys_reset_cp);
}
#endif
/* adsp aed api, only detail information available*/
aed_common_exception_api("adsp", NULL, 0, NULL, 0, detail, db_opt);
pr_info("[ADSP] adsp exception dump is done\n");
mutex_unlock(&adsp_excep_mutex);
}
/*
* callback function for work struct
* generate an exception and reset adsp
* NOTE: this function may be blocked
* and should not be called in interrupt context
* @param ws: work struct
*/
static void adsp_aed_reset_ws(struct work_struct *ws)
{
struct adsp_work_t *sws = container_of(ws, struct adsp_work_t, work);
enum adsp_excep_id type = sws->flags;
enum adsp_core_id id = sws->id;
pr_debug("[ADSP]%s: adsp_excep_id=%u adsp_core_id=%u\n",
__func__, type, id);
adsp_reset_ready(ADSP_A_ID);
adsp_aed(type, id);
}
/*
* schedule a work to generate an exception and reset adsp
* @param type: exception type
*/
void adsp_aed_reset(enum adsp_excep_id type, enum adsp_core_id id)
{
adsp_aed_work.flags = (unsigned int) type;
adsp_aed_work.id = (unsigned int) id;
queue_work(adsp_workqueue, &adsp_aed_work.work);
}
#if ADSP_TRAX
static ssize_t adsp_A_trax_show(struct file *filep, struct kobject *kobj,
struct bin_attribute *attr,
char *buf, loff_t offset, size_t size)
{
unsigned int length = 0;
void *trax_addr = adsp_get_reserve_mem_virt(ADSP_A_TRAX_MEM_ID);
pr_debug("[ADSP] trax initiated=%d, done=%d, length=%d, offset=%lld\n",
adsp_get_trax_initiated(), adsp_get_trax_done(),
adsp_get_trax_length(), offset);
if (adsp_get_trax_initiated() && adsp_get_trax_done()) {
if (offset >= 0 && offset < adsp_get_trax_length()) {
if ((offset + size) > adsp_get_trax_length())
size = adsp_get_trax_length() - offset;
memcpy(buf, trax_addr + offset, size);
length = size;
}
}
return length;
}
struct bin_attribute bin_attr_adsp_trax = {
.attr = {
.name = "adsp_trax",
.mode = 0444,
},
.size = 0,
.read = adsp_A_trax_show,
};
#endif
static int adsp_A_dram_dump(void)
{
unsigned int dram_total = 0;
void *dump_buf = NULL;
uint32_t n = 0;
/*wait EE dump done*/
#ifdef CFG_RECOVERY_SUPPORT
if (wdt_counter == WDT_FIRST_WAIT_COUNT ||
wdt_counter == WDT_LAST_WAIT_COUNT)
return -1;
#endif
/* all dram */
dram_total = adsp_get_reserve_mem_size(ADSP_A_SYSTEM_MEM_ID)
+ adsp_get_reserve_mem_size(ADSP_A_CORE_DUMP_MEM_ID)
+ adsp_get_reserve_mem_size(ADSP_A_IPI_MEM_ID)
+ adsp_get_reserve_mem_size(ADSP_A_LOGGER_MEM_ID);
/* allocate adsp dump dram buffer*/
if (adsp_A_dram_dump_buffer == NULL)
adsp_A_dram_dump_buffer = vmalloc(dram_total);
if (!adsp_A_dram_dump_buffer)
return -1;
dump_buf = adsp_A_dram_dump_buffer;
n += dump_adsp_shared_memory(dump_buf + n, dram_total - n,
ADSP_A_SYSTEM_MEM_ID);
n += dump_adsp_shared_memory(dump_buf + n, dram_total - n,
ADSP_A_CORE_DUMP_MEM_ID);
n += dump_adsp_shared_memory(dump_buf + n, dram_total - n,
ADSP_A_IPI_MEM_ID);
n += dump_adsp_shared_memory(dump_buf + n, dram_total - n,
ADSP_A_LOGGER_MEM_ID);
return n;
}
static ssize_t adsp_A_ramdump(char *buf, loff_t offset, size_t size)
{
ssize_t n = 0;
ssize_t threshold[5];
threshold[0] = sizeof(struct MemoryDump);
threshold[1] = threshold[0] +
adsp_get_reserve_mem_size(ADSP_A_SYSTEM_MEM_ID);
threshold[2] = threshold[1] +
adsp_get_reserve_mem_size(ADSP_A_CORE_DUMP_MEM_ID);
threshold[3] = threshold[2] +
adsp_get_reserve_mem_size(ADSP_A_IPI_MEM_ID);
threshold[4] = threshold[3] +
adsp_get_reserve_mem_size(ADSP_A_LOGGER_MEM_ID);
mutex_lock(&adsp_A_excep_dump_mutex);
if (offset >= 0 && offset < threshold[0]) {
n = copy_from_buffer(buf, -1, adsp_A_dump_buffer,
threshold[0], offset, size);
goto DONE;
}
if (adsp_A_dram_dump_buffer) { /* backup before: adsp_A_dram_dump */
n = copy_from_buffer(buf, -1, adsp_A_dram_dump_buffer,
threshold[4] - threshold[0],
offset - threshold[0], size);
if (n == 0) {
vfree(adsp_A_dram_dump_buffer);
adsp_A_dram_dump_buffer = NULL;
}
goto DONE;
}
/* not backup, dump immediately */
if (offset >= threshold[0] && offset < threshold[1]) {
n = copy_from_adsp_shared_memory(
buf, offset - threshold[0],
size, ADSP_A_SYSTEM_MEM_ID);
} else if (offset >= threshold[1] && offset < threshold[2]) {
n = copy_from_adsp_shared_memory(
buf, offset - threshold[1],
size, ADSP_A_CORE_DUMP_MEM_ID);
} else if (offset >= threshold[2] && offset < threshold[3]) {
n = copy_from_adsp_shared_memory(
buf, offset - threshold[2],
size, ADSP_A_IPI_MEM_ID);
} else if (offset >= threshold[3] && offset < threshold[4]) {
n = copy_from_adsp_shared_memory(
buf, offset - threshold[3],
size, ADSP_A_LOGGER_MEM_ID);
}
/* dump done*/
#ifdef CFG_RECOVERY_SUPPORT
if (!n &&
(atomic_read(&adsp_reset_status) == ADSP_RESET_STATUS_START ||
adsp_recovery_flag[ADSP_A_ID] == ADSP_RECOVERY_START)) {
/*complete scp ee, if scp reset by wdt or awake fail*/
pr_info("[ADSP]aed finished, complete it\n");
complete(&adsp_sys_reset_cp);
}
#endif
DONE:
mutex_unlock(&adsp_A_excep_dump_mutex);
return n;
}
static ssize_t adsp_A_dump_show(struct file *filep, struct kobject *kobj,
struct bin_attribute *attr,
char *buf, loff_t offset, size_t size)
{
return adsp_A_ramdump(buf, offset, size);
}
static ssize_t adsp_A_dump_ke_show(struct file *filep, struct kobject *kobj,
struct bin_attribute *attr,
char *buf, loff_t offset, size_t size)
{
if (offset == 0) /* only do ITCM/DTCM ramdump once at start */
adsp_prepare_aed_dump();
return adsp_A_ramdump(buf, offset, size);
}
static struct bin_attribute bin_attr_adsp_dump = {
.attr = {
.name = "adsp_dump",
.mode = 0444,
},
.size = 0,
.read = adsp_A_dump_show,
};
static struct bin_attribute bin_attr_adsp_dump_ke = {
.attr = {
.name = "adsp_dump_ke",
.mode = 0444,
},
.size = 0,
.read = adsp_A_dump_ke_show,
};
static struct bin_attribute *adsp_excep_bin_attrs[] = {
&bin_attr_adsp_dump,
&bin_attr_adsp_dump_ke,
#if ADSP_TRAX
&bin_attr_adsp_trax,
#endif
NULL,
};
struct attribute_group adsp_excep_attr_group = {
.bin_attrs = adsp_excep_bin_attrs,
};
/*
* init a work struct
*/
int adsp_excep_init(void)
{
mutex_init(&adsp_excep_mutex);
mutex_init(&adsp_A_excep_dump_mutex);
INIT_WORK(&adsp_aed_work.work, adsp_aed_reset_ws);
/* alloc dump memory*/
adsp_A_dump_buffer = vmalloc(sizeof(struct MemoryDump));
if (!adsp_A_dump_buffer)
return -1;
adsp_ke_buffer = kmalloc(ADSP_KE_DUMP_LEN, GFP_KERNEL);
if (!adsp_ke_buffer)
return -1;
return 0;
}
/*
* cleanup adsp exception
*/
void adsp_excep_cleanup(void)
{
vfree(adsp_A_dump_buffer);
kfree(adsp_ke_buffer);
pr_debug("[ADSP] %s done\n", __func__);
}
void get_adsp_aee_buffer(unsigned long *vaddr, unsigned long *size)
{
u32 n = 0;
if (adsp_ke_buffer) {
adsp_enable_dsp_clk(true);
n += dump_adsp_cfg_reg(adsp_ke_buffer, ADSP_KE_DUMP_LEN);
n += dump_adsp_tcm(adsp_ke_buffer + n, ADSP_KE_DUMP_LEN - n);
adsp_enable_dsp_clk(false);
*vaddr = (unsigned long)adsp_ke_buffer;
*size = ADSP_KE_DUMP_LEN;
}
}
EXPORT_SYMBOL(get_adsp_aee_buffer);
@@ -0,0 +1,949 @@
// SPDX-License-Identifier: GPL-2.0
//
// adsp_helper.c-- Mediatek ADSP kernel entry
//
// Copyright (c) 2018 MediaTek Inc.
// Author: HsinYi Chang <hsin-yi.chang@mediatek.com>
#include <linux/module.h> /* needed by all modules */
#include <linux/init.h> /* needed by module macros */
#include <linux/fs.h> /* needed by file_operations* */
#include <linux/miscdevice.h> /* needed by miscdevice* */
#include <linux/sysfs.h>
#include <linux/platform_device.h>
#include <linux/device.h> /* needed by device_* */
#include <linux/vmalloc.h> /* needed by vmalloc */
#include <linux/uaccess.h> /* needed by copy_to_user */
#include <linux/fs.h> /* needed by file_operations* */
#include <linux/slab.h> /* needed by kmalloc */
#include <linux/poll.h> /* needed by poll */
#include <linux/mutex.h>
#include <linux/sched.h>
#include <linux/interrupt.h>
#include <linux/suspend.h>
#include <linux/timer.h>
#include <linux/kobject.h>
#include <linux/notifier.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/of_irq.h>
#include <linux/of_fdt.h>
#include <linux/ioport.h>
#include <linux/debugfs.h>
#include <linux/syscore_ops.h>
#include <linux/io.h>
#include <linux/clk.h>
#include <linux/delay.h>
#ifdef wakelock
#include <linux/wakelock.h>
#endif
#include <mt-plat/sync_write.h>
#include <mt-plat/aee.h>
#ifdef CONFIG_MTK_TIMER_TIMESYNC
#include <mtk_sys_timer.h>
#include <mtk_sys_timer_typedefs.h>
#endif
#include <mtk_spm_sleep.h>
#ifdef CONFIG_MTK_EMI
#include <plat_debug_api.h>
#endif
#include "adsp_helper.h"
#include "adsp_excep.h"
#include "adsp_dvfs.h"
#include "adsp_clk.h"
#include "adsp_service.h"
#include "adsp_logger.h"
#include "adsp_bus_monitor.h"
#include "adsp_timesync.h"
#define ADSP_READY_TIMEOUT (40 * HZ) /* 40 seconds*/
struct adsp_regs adspreg;
char *adsp_core_ids[ADSP_CORE_TOTAL] = {"ADSP A"};
unsigned int adsp_ready[ADSP_CORE_TOTAL];
unsigned int adsp_enable;
#ifdef CONFIG_DEBUG_FS
static struct dentry *adsp_debugfs;
#endif
/* adsp workqueue & work */
struct workqueue_struct *adsp_workqueue;
static void adsp_notify_ws(struct work_struct *ws);
static void adsp_timeout_ws(struct work_struct *ws);
static DECLARE_WORK(adsp_notify_work, adsp_notify_ws);
static DECLARE_DELAYED_WORK(adsp_timeout_work, adsp_timeout_ws);
/* adsp notify */
static DEFINE_MUTEX(adsp_A_notify_mutex);
static BLOCKING_NOTIFIER_HEAD(adsp_A_notifier_list);
#ifdef CFG_RECOVERY_SUPPORT
static unsigned int adsp_timeout_times;
static struct workqueue_struct *adsp_reset_workqueue;
unsigned int adsp_recovery_flag[ADSP_CORE_TOTAL];
atomic_t adsp_reset_status = ATOMIC_INIT(ADSP_RESET_STATUS_STOP);
struct completion adsp_sys_reset_cp;
struct adsp_work_t adsp_sys_reset_work;
struct wakeup_source *adsp_reset_lock;
DEFINE_SPINLOCK(adsp_reset_spinlock);
#endif
/*
* register apps notification
* NOTE: this function may be blocked
* and should not be called in interrupt context
* @param nb: notifier block struct
*/
void adsp_A_register_notify(struct notifier_block *nb)
{
mutex_lock(&adsp_A_notify_mutex);
blocking_notifier_chain_register(&adsp_A_notifier_list, nb);
pr_debug("[ADSP] register adsp A notify callback..\n");
if (is_adsp_ready(ADSP_A_ID) == 1)
nb->notifier_call(nb, ADSP_EVENT_READY, NULL);
mutex_unlock(&adsp_A_notify_mutex);
}
EXPORT_SYMBOL_GPL(adsp_A_register_notify);
/*
* unregister apps notification
* NOTE: this function may be blocked
* and should not be called in interrupt context
* @param nb: notifier block struct
*/
void adsp_A_unregister_notify(struct notifier_block *nb)
{
mutex_lock(&adsp_A_notify_mutex);
blocking_notifier_chain_unregister(&adsp_A_notifier_list, nb);
mutex_unlock(&adsp_A_notify_mutex);
}
EXPORT_SYMBOL_GPL(adsp_A_unregister_notify);
#ifdef CFG_RECOVERY_SUPPORT
void adsp_extern_notify(enum ADSP_NOTIFY_EVENT notify_status)
{
blocking_notifier_call_chain(&adsp_A_notifier_list,
notify_status, NULL);
}
/*
* adsp_set_reset_status, set and return scp reset status function
* return value:
* 0: scp not in reset status
* 1: scp in reset status
*/
unsigned int adsp_set_reset_status(void)
{
unsigned long spin_flags;
spin_lock_irqsave(&adsp_reset_spinlock, spin_flags);
if (atomic_read(&adsp_reset_status) == ADSP_RESET_STATUS_START) {
spin_unlock_irqrestore(&adsp_reset_spinlock, spin_flags);
return 1;
}
/* adsp not in reset status, set it and return*/
atomic_set(&adsp_reset_status, ADSP_RESET_STATUS_START);
spin_unlock_irqrestore(&adsp_reset_spinlock, spin_flags);
return 0;
}
/*
* callback function for work struct
* NOTE: this function may be blocked
* and should not be called in interrupt context
* @param ws: work struct
*/
void adsp_sys_reset_ws(struct work_struct *ws)
{
struct adsp_work_t *sws = container_of(ws, struct adsp_work_t, work);
unsigned int adsp_reset_type = sws->flags;
unsigned int adsp_reset_flag = 0; /* make sure adsp is in idle state */
int timeout = 100; /* max wait 2s */
/*set adsp not ready*/
adsp_recovery_flag[ADSP_A_ID] = ADSP_RECOVERY_START;
adsp_ready[ADSP_A_ID] = 0;
adsp_register_feature(SYSTEM_FEATURE_ID);
adsp_extern_notify(ADSP_EVENT_STOP);
/* wake lock AP*/
__pm_stay_awake(adsp_reset_lock);
pr_info("%s(): adsp_aed_reset\n", __func__);
if (adsp_reset_type == ADSP_RESET_TYPE_AWAKE)
adsp_aed_reset(EXCEP_KERNEL, ADSP_A_ID);
else
adsp_aed_reset(EXCEP_RUNTIME, ADSP_A_ID);
/*wait adsp ee finished in 10s*/
if (wait_for_completion_interruptible_timeout(&adsp_sys_reset_cp,
msecs_to_jiffies(10000)) == 0) {
pr_info("%s: adsp ee time out\n", __func__);
/*timeout check adsp status again*/
if (is_adsp_ready(ADSP_A_ID) != -1) {
pr_info("%s: adsp reset state incorrect\n", __func__);
return;
}
}
/* enable clock for access ADSP Reg*/
adsp_enable_dsp_clk(true);
/* dump bus status if has bus hang*/
if (is_adsp_bus_monitor_alert()) {
#ifdef CONFIG_MTK_EMI
#ifdef CONFIG_MTK_LASTBUS_INTERFACE
dump_emi_outstanding(); /* check infra, dump all info*/
lastbus_timeout_dump(); /* check infra/peri, dump both info */
#endif
#endif
adsp_bus_monitor_dump();
}
if (adsp_reset_type == ADSP_RESET_TYPE_AWAKE)
pr_info("%s(): adsp awake fail, wait system back\n", __func__);
/* make sure adsp is in idle state */
while (--timeout) {
if ((readl(ADSP_SLEEP_STATUS_REG) & ADSP_A_IS_WFI) &&
(readl(ADSP_DBG_PEND_CNT) == 0)) {
adsp_reset();
if (readl(ADSP_SLEEP_STATUS_REG) & ADSP_A_IS_ACTIVE) {
adsp_reset_flag = 1;
break;
}
}
msleep(20);
}
if (!adsp_reset_flag) {
if (readl(ADSP_DBG_PEND_CNT))
pr_info("%s(): failed, bypass and wait\n", __func__);
else
adsp_reset();
}
#if ADSP_BOOT_TIME_OUT_MONITOR
if (!work_busy(&adsp_timeout_work.work))
queue_delayed_work(adsp_workqueue, &adsp_timeout_work,
jiffies + ADSP_READY_TIMEOUT);
#endif
adsp_enable_dsp_clk(false);
}
/*
*/
void adsp_send_reset_wq(enum ADSP_RESET_TYPE type, enum adsp_core_id core_id)
{
adsp_sys_reset_work.flags = (unsigned int) type;
queue_work(adsp_reset_workqueue, &adsp_sys_reset_work.work);
}
void adsp_recovery_init(void)
{
/*create wq for scp reset*/
adsp_reset_workqueue = create_singlethread_workqueue("ADSP_RESET_WQ");
/*init reset work*/
INIT_WORK(&adsp_sys_reset_work.work, adsp_sys_reset_ws);
/*init completion for identify adsp aed finished*/
init_completion(&adsp_sys_reset_cp);
adsp_reset_lock = wakeup_source_register(NULL, "adsp reset wakelock");
/* init reset by cmd flag*/
adsp_recovery_flag[ADSP_A_ID] = ADSP_RECOVERY_OK;
}
#endif
/*
* callback function for work struct
* notify apps to start their tasks or generate an exception according to flag
* NOTE: this function may be blocked
* and should not be called in interrupt context
* @param ws: work struct
*/
static void adsp_notify_ws(struct work_struct *ws)
{
#ifdef CFG_RECOVERY_SUPPORT
if (adsp_recovery_flag[ADSP_A_ID] == ADSP_RECOVERY_START) {
mutex_lock(&adsp_A_notify_mutex);
adsp_recovery_flag[ADSP_A_ID] = ADSP_RECOVERY_OK;
atomic_set(&adsp_reset_status, ADSP_RESET_STATUS_STOP);
adsp_extern_notify(ADSP_EVENT_READY);
adsp_deregister_feature(SYSTEM_FEATURE_ID);
mutex_unlock(&adsp_A_notify_mutex);
__pm_relax(adsp_reset_lock);
}
#endif
}
/*
* callback function for work struct
* notify apps to start their tasks or generate an exception according to flag
* NOTE: this function may be blocked
* and should not be called in interrupt context
* @param ws: work struct
*/
static void adsp_timeout_ws(struct work_struct *ws)
{
#ifdef CFG_RECOVERY_SUPPORT
if (adsp_timeout_times < 5) {
adsp_timeout_times++;
__pm_relax(adsp_reset_lock);
pr_debug("%s(): cnt (%d)\n", __func__, adsp_timeout_times);
adsp_send_reset_wq(ADSP_RESET_TYPE_AWAKE, ADSP_A_ID);
} else
WARN_ON(1); /* reboot */
#else
adsp_aed(EXCEP_BOOTUP, ADSP_A_ID);
#endif
}
void adsp_reset_ready(uint32_t id)
{
adsp_ready[id] = 0;
}
/*
* handle notification from adsp
* mark adsp is ready for running tasks
* @param id: ipi id
* @param data: ipi data
* @param len: length of ipi data
*/
void adsp_A_ready_ipi_handler(int id, void *data, unsigned int len)
{
unsigned int adsp_image_size = *(unsigned int *)data;
if (!adsp_ready[ADSP_A_ID]) {
#if ADSP_BOOT_TIME_OUT_MONITOR
cancel_delayed_work(&adsp_timeout_work);
#endif
/* set adsp ready flag and clear SPM interrupt */
adsp_ready[ADSP_A_ID] = 1;
writel(0x0, ADSP_TO_SPM_REG);
#ifdef CFG_RECOVERY_SUPPORT
adsp_timeout_times = 0;
queue_work(adsp_workqueue, &adsp_notify_work);
#endif
}
/* verify adsp image size */
if (adsp_image_size != ADSP_A_TCM_SIZE) {
pr_info("[ADSP]image size ERROR! AP=0x%zx,ADSP=0x%x\n",
ADSP_A_TCM_SIZE, adsp_image_size);
WARN_ON(1);
}
}
/*
* @return: 1 if adsp is ready for running tasks
*/
int is_adsp_ready(uint32_t id)
{
if (id >= ADSP_CORE_TOTAL)
return -EINVAL;
#ifdef CFG_RECOVERY_SUPPORT
/* exception */
if (atomic_read(&adsp_reset_status) == ADSP_RESET_STATUS_START ||
adsp_recovery_flag[ADSP_A_ID] == ADSP_RECOVERY_START)
return -1;
#endif
return adsp_ready[id];
}
/*
* power on adsp
* generate error if power on fail
* @return: 1 if success
*/
uint32_t adsp_power_on(uint32_t enable)
{
if (enable) {
adsp_enable_clock();
adsp_sw_reset();
adsp_set_clock_freq(CLK_DEFAULT_ACTIVE_CK);
adsp_A_send_spm_request(true);
} else {
adsp_set_clock_freq(CLK_DEFAULT_26M_CK);
adsp_disable_clock();
}
pr_debug("-%s (%x)\n", __func__, enable);
return 1;
}
static inline ssize_t adsp_A_status_show(struct device *kobj,
struct device_attribute *attr,
char *buf)
{
unsigned int status = 0;
char *adsp_status;
adsp_enable_dsp_clk(true);
status = readl(ADSP_A_SYS_STATUS);
adsp_enable_dsp_clk(false);
switch (status) {
case ADSP_STATUS_ACTIVE:
adsp_status = "ADSP A is active";
break;
case ADSP_STATUS_SUSPEND:
adsp_status = "ADSP A is suspend";
break;
case ADSP_STATUS_SLEEP:
adsp_status = "ADSP A is sleep";
break;
case ADSP_STATUS_RESET:
adsp_status = "ADSP A is reset";
break;
default:
adsp_status = "ADSP A in unknown status";
break;
}
return scnprintf(buf, PAGE_SIZE, "%s\n", adsp_status);
}
DEVICE_ATTR_RO(adsp_A_status);
static inline ssize_t adsp_ipi_test_store(struct device *kobj,
struct device_attribute *attr,
const char *buf, size_t count)
{
enum adsp_ipi_status ret;
int value = 0;
if (kstrtoint(buf, 10, &value))
return -EINVAL;
adsp_register_feature(SYSTEM_FEATURE_ID);
if (is_adsp_ready(ADSP_A_ID) == 1) {
ret = adsp_ipi_send(ADSP_IPI_TEST1, &value, sizeof(value),
0, ADSP_A_ID);
}
/*
* BE CAREFUL! this cmd shouldn't let adsp process over 1s.
* Otherwise, you should register other feature before.
*/
adsp_deregister_feature(SYSTEM_FEATURE_ID);
return count;
}
static inline ssize_t adsp_ipi_test_show(struct device *kobj,
struct device_attribute *attr,
char *buf)
{
unsigned int value = 0x5A5A;
enum adsp_ipi_status ret;
if (is_adsp_ready(ADSP_A_ID) == 1) {
ret = adsp_ipi_send(ADSP_IPI_TEST1, &value, sizeof(value),
0, ADSP_A_ID);
return scnprintf(buf, PAGE_SIZE, "ADSP ipi send ret=%d\n", ret);
} else
return scnprintf(buf, PAGE_SIZE, "ADSP is not ready\n");
}
DEVICE_ATTR_RW(adsp_ipi_test);
static inline ssize_t adsp_uart_switch_store(struct device *kobj,
struct device_attribute *attr,
const char *buf, size_t count)
{
enum adsp_ipi_status ret;
unsigned int value = 0;
if (kstrtoint(buf, 10, &value))
return -EINVAL;
if (is_adsp_ready(ADSP_A_ID) == 1) {
ret = adsp_ipi_send(ADSP_IPI_TEST1, &value, sizeof(value),
0, ADSP_A_ID);
}
return count;
}
DEVICE_ATTR_WO(adsp_uart_switch);
static inline ssize_t adsp_suspend_cmd_show(struct device *kobj,
struct device_attribute *attr,
char *buf)
{
return adsp_dump_feature_state(buf, PAGE_SIZE);
}
static inline ssize_t adsp_suspend_cmd_store(struct device *kobj,
struct device_attribute *attr,
const char *buf, size_t count)
{
uint32_t id = 0;
char *temp = NULL, *token1 = NULL, *token2 = NULL;
char *pin = NULL;
char delim[] = " ,\t\n";
temp = kstrdup(buf, GFP_KERNEL);
pin = temp;
token1 = strsep(&pin, delim);
if (token1 == NULL)
return -EINVAL;
token2 = strsep(&pin, delim);
if (token2 == NULL)
return -EINVAL;
id = adsp_get_feature_index(token2);
if ((strcmp(token1, "regi") == 0) && (id >= 0))
adsp_register_feature(id);
if ((strcmp(token1, "deregi") == 0) && (id >= 0))
adsp_deregister_feature(id);
kfree(temp);
return count;
}
DEVICE_ATTR_RW(adsp_suspend_cmd);
#ifdef CFG_RECOVERY_SUPPORT
static ssize_t adsp_recovery_flag_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
return scnprintf(buf, PAGE_SIZE, "%d\n", adsp_recovery_flag[ADSP_A_ID]);
}
DEVICE_ATTR_RO(adsp_recovery_flag);
#endif
static struct attribute *adsp_default_attrs[] = {
&dev_attr_adsp_A_status.attr,
&dev_attr_adsp_ipi_test.attr,
&dev_attr_adsp_uart_switch.attr,
&dev_attr_adsp_suspend_cmd.attr,
#ifdef CFG_RECOVERY_SUPPORT
&dev_attr_adsp_recovery_flag.attr,
#endif
NULL,
};
static struct attribute_group adsp_default_attr_group = {
.attrs = adsp_default_attrs,
};
static const struct attribute_group *adsp_attr_groups[] = {
&adsp_default_attr_group,
&adsp_awake_attr_group,
&adsp_dvfs_attr_group,
&adsp_excep_attr_group,
NULL,
};
const struct file_operations adsp_device_fops = {
.owner = THIS_MODULE,
.open = adsp_A_log_if_open,
.unlocked_ioctl = adsp_driver_ioctl,
#ifdef CONFIG_COMPAT
.compat_ioctl = adsp_driver_compat_ioctl,
#endif
};
static struct miscdevice adsp_device = {
.minor = MISC_DYNAMIC_MINOR,
.name = "adsp",
.groups = adsp_attr_groups,
.fops = &adsp_device_fops,
};
const struct file_operations adsp_core_device_fops = {
.owner = THIS_MODULE,
.read = adsp_A_log_if_read,
.open = adsp_A_log_if_open,
.poll = adsp_A_log_if_poll,
};
static const struct attribute_group *adsp_core_attr_groups[] = {
&adsp_logger_attr_group,
NULL,
};
static struct miscdevice adsp_core_device = {
.minor = MISC_DYNAMIC_MINOR,
.name = "adsp_0",
.groups = adsp_core_attr_groups,
.fops = &adsp_core_device_fops,
};
static ssize_t adsp_debug_read(struct file *file, char __user *buf,
size_t count, loff_t *pos)
{
char *buffer = NULL; /* for reduce kernel stack */
int ret = 0;
size_t n = 0, max_size;
buffer = adsp_get_reserve_mem_virt(ADSP_A_DEBUG_DUMP_MEM_ID);
max_size = adsp_get_reserve_mem_size(ADSP_A_DEBUG_DUMP_MEM_ID);
n = strnlen(buffer, max_size);
ret = simple_read_from_buffer(buf, count, pos, buffer, n);
return ret;
}
static ssize_t adsp_debug_write(struct file *filp, const char __user *buffer,
size_t count, loff_t *ppos)
{
char buf[64];
if (copy_from_user(buf, buffer, min(count, sizeof(buf))))
return -EFAULT;
if (adsp_register_feature(SYSTEM_FEATURE_ID) == 0) {
adsp_ipi_send(ADSP_IPI_ADSP_TIMER, buf,
min(count, sizeof(buf)), 0, ADSP_A_ID);
adsp_deregister_feature(SYSTEM_FEATURE_ID);
}
return count;
}
static const struct file_operations adsp_debug_ops = {
.open = simple_open,
.read = adsp_debug_read,
.write = adsp_debug_write,
};
void adsp_update_memory_protect_info(void)
{
struct adsp_mpu_info_t *mpu_info;
phys_addr_t nc_addr = adsp_get_reserve_mem_phys(ADSP_MPU_NONCACHE_ID);
mpu_info = (struct adsp_mpu_info_t *)ADSP_A_MPUINFO_BUFFER;
mpu_info->data_non_cache_addr = nc_addr;
mpu_info->data_non_cache_size =
adsp_get_reserve_mem_phys(ADSP_A_SHARED_MEM_END)
+ adsp_get_reserve_mem_size(ADSP_A_SHARED_MEM_END)
- nc_addr;
}
void adsp_enable_dsp_clk(bool enable)
{
if (enable) {
pr_debug("enable dsp clk\n");
adsp_enable_clock();
} else {
pr_debug("disable dsp clk\n");
adsp_disable_clock();
}
}
static int adsp_system_sleep_suspend(struct device *dev)
{
mutex_lock(&adsp_suspend_mutex);
if ((is_adsp_ready(ADSP_A_ID) == 1) || adsp_feature_is_active()) {
adsp_timesync_suspend(1);
adsp_awake_unlock_adsppll(ADSP_A_ID, 1);
}
mutex_unlock(&adsp_suspend_mutex);
return 0;
}
static int adsp_system_sleep_resume(struct device *dev)
{
mutex_lock(&adsp_suspend_mutex);
if ((is_adsp_ready(ADSP_A_ID) == 1) || adsp_feature_is_active()) {
/*wake adsp up*/
adsp_awake_unlock_adsppll(ADSP_A_ID, 0);
adsp_timesync_resume();
}
mutex_unlock(&adsp_suspend_mutex);
return 0;
}
static int adsp_syscore_suspend(void)
{
if ((is_adsp_ready(ADSP_A_ID) != 1) && !adsp_feature_is_active()) {
adsp_bus_sleep_protect(true);
spm_adsp_mem_protect();
}
return 0;
}
static void adsp_syscore_resume(void)
{
if ((is_adsp_ready(ADSP_A_ID) != 1) && !adsp_feature_is_active()) {
spm_adsp_mem_unprotect();
adsp_bus_sleep_protect(false);
/* release adsp sw_reset,
* let ap is able to write adsp cfg/dtcm
* no matter adsp is suspend.
*/
adsp_enable_clock();
writel((ADSP_A_SW_RSTN | ADSP_A_SW_DBG_RSTN), ADSP_A_REBOOT);
udelay(1);
writel(0, ADSP_A_REBOOT);
#if ADSP_BUS_MONITOR_INIT_ENABLE
adsp_bus_monitor_init(); /* reinit bus monitor hw */
#endif
adsp_disable_clock();
}
}
#ifdef CFG_RECOVERY_SUPPORT
/* user-space event notify */
static int adsp_user_event_notify(struct notifier_block *nb,
unsigned long event, void *ptr)
{
struct device *dev = adsp_device.this_device;
int ret = 0;
if (!dev)
return NOTIFY_DONE;
switch (event) {
case ADSP_EVENT_STOP:
ret = kobject_uevent(&dev->kobj, KOBJ_OFFLINE);
break;
case ADSP_EVENT_READY:
ret = kobject_uevent(&dev->kobj, KOBJ_ONLINE);
break;
default:
pr_info("%s, ignore event %lu", __func__, event);
break;
}
if (ret)
pr_info("%s, uevent(%lu) fail, ret %d", __func__, event, ret);
return NOTIFY_OK;
}
struct notifier_block adsp_uevent_notifier = {
.notifier_call = adsp_user_event_notify,
.priority = AUDIO_HAL_FEATURE_PRI,
};
#endif
static int adsp_device_probe(struct platform_device *pdev)
{
struct resource *res;
u64 sysram[2] = {0, 0};
struct device *dev = &pdev->dev;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
adspreg.cfg = devm_ioremap_resource(dev, res);
adspreg.cfgregsize = resource_size(res);
if (IS_ERR(adspreg.cfg))
goto ERROR;
res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
adspreg.iram = devm_ioremap_resource(dev, res);
adspreg.i_tcmsize = resource_size(res);
if (IS_ERR(adspreg.iram))
goto ERROR;
res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
adspreg.dram = devm_ioremap_resource(dev, res);
adspreg.d_tcmsize = resource_size(res);
if (IS_ERR(adspreg.dram))
goto ERROR;
adspreg.infracfg_ao = of_iomap(dev->of_node, 3);
if (IS_ERR(adspreg.infracfg_ao))
goto ERROR;
adspreg.pericfg = of_iomap(dev->of_node, 4);
if (IS_ERR(adspreg.pericfg))
goto ERROR;
adspreg.total_tcmsize = adspreg.i_tcmsize + adspreg.d_tcmsize;
adspreg.wdt_irq = platform_get_irq(pdev, 0);
if (request_irq(adspreg.wdt_irq, adsp_A_wdt_handler,
IRQF_TRIGGER_LOW, "ADSP A WDT", NULL))
goto ERROR;
adspreg.ipc_irq = platform_get_irq(pdev, 1);
if (request_irq(adspreg.ipc_irq, adsp_A_irq_handler,
IRQF_TRIGGER_LOW, "ADSP A IPC2HOST", NULL))
goto ERROR;
of_property_read_u64_array(pdev->dev.of_node, "sysram",
sysram, ARRAY_SIZE(sysram));
adspreg.sysram = ioremap_wc(sysram[0], sysram[1]);
adspreg.sysram_size = sysram[1];
if (IS_ERR(adspreg.sysram))
goto ERROR;
adsp_set_reserve_mblock(ADSP_A_SYSTEM_MEM_ID, sysram[0],
adspreg.sysram, adspreg.sysram_size);
adsp_reserve_memory_ioremap(adspreg.sharedram, adspreg.shared_size);
adspreg.clkctrl = adspreg.cfg + ADSP_CLK_CTRL_OFFSET;
adsp_clk_device_probe(&pdev->dev);
adsp_enable = 1;
return 0;
ERROR:
return -ENODEV;
}
static int adsp_device_remove(struct platform_device *pdev)
{
adsp_clk_device_remove(&pdev->dev);
return 0;
}
static const struct of_device_id adsp_of_ids[] = {
{ .compatible = "mediatek,audio_dsp", },
{}
};
static const struct dev_pm_ops adsp_pm_ops = {
SET_SYSTEM_SLEEP_PM_OPS(adsp_system_sleep_suspend,
adsp_system_sleep_resume)
};
static struct syscore_ops adsp_syscore_ops = {
.resume = adsp_syscore_resume,
.suspend = adsp_syscore_suspend,
};
static struct platform_driver mtk_adsp_device = {
.probe = adsp_device_probe,
.remove = adsp_device_remove,
.driver = {
.name = "adsp",
.owner = THIS_MODULE,
#ifdef CONFIG_OF
.of_match_table = adsp_of_ids,
#endif
#ifdef CONFIG_PM
.pm = &adsp_pm_ops,
#endif
},
};
/*
* driver initialization entry point
*/
static int __init adsp_init(void)
{
int ret = 0;
adsp_enable = 0;
ret = platform_driver_register(&mtk_adsp_device);
if (unlikely(ret != 0)) {
pr_err("[ADSP] platform driver register fail\n");
return ret;
}
ret = misc_register(&adsp_device);
if (unlikely(ret != 0)) {
pr_err("[ADSP] misc adsp register failed\n");
return ret;
}
ret = misc_register(&adsp_core_device);
if (unlikely(ret != 0)) {
pr_err("[ADSP] misc adsp_core register failed\n");
return ret;
}
register_syscore_ops(&adsp_syscore_ops);
return ret;
}
static int __init adsp_module_init(void)
{
int ret = 0;
if (!adsp_enable) {
pr_info("[adsp] core 0 is not enabled\n");
return ret;
}
adsp_workqueue = create_workqueue("ADSP_WQ");
#ifdef CONFIG_DEBUG_FS
adsp_debugfs = debugfs_create_file("audiodsp", S_IFREG | 0644, NULL,
(void *)&adsp_device, &adsp_debug_ops);
if (IS_ERR(adsp_debugfs))
return PTR_ERR(adsp_debugfs);
#endif
/* adsp initialize */
adsp_dvfs_init();
adsp_power_on(true);
adsp_update_memory_protect_info();
adsp_awake_init();
ret = adsp_excep_init();
if (ret)
goto ERROR;
adsp_suspend_init();
adsp_A_irq_init();
adsp_A_ipi_init();
adsp_ipi_registration(ADSP_IPI_ADSP_A_READY, adsp_A_ready_ipi_handler,
"adsp_A_ready");
ret = adsp_timesync_init();
if (ret)
goto ERROR;
#if ADSP_LOGGER_ENABLE
ret = adsp_logger_init();
if (ret)
goto ERROR;
#endif
#if ADSP_TRAX
ret = adsp_trax_init();
if (ret)
goto ERROR;
#endif
#ifdef CFG_RECOVERY_SUPPORT
adsp_recovery_init();
adsp_A_register_notify(&adsp_uevent_notifier);
#endif
#if ADSP_BUS_MONITOR_INIT_ENABLE
adsp_bus_monitor_init();
#endif
adsp_release_runstall(true);
#if ADSP_BOOT_TIME_OUT_MONITOR
queue_delayed_work(adsp_workqueue, &adsp_timeout_work,
jiffies + ADSP_READY_TIMEOUT);
#endif
pr_debug("[ADSP] driver_init_done\n");
return ret;
ERROR:
pr_info("%s fail ret(%d)\n", __func__, ret);
return ret;
}
/*
* driver exit point
*/
static void __exit adsp_exit(void)
{
free_irq(adspreg.wdt_irq, NULL);
free_irq(adspreg.ipc_irq, NULL);
misc_deregister(&adsp_device);
#ifdef CONFIG_DEBUG_FS
debugfs_remove(adsp_debugfs);
#endif
flush_workqueue(adsp_workqueue);
destroy_workqueue(adsp_workqueue);
#ifdef CFG_RECOVERY_SUPPORT
flush_workqueue(adsp_reset_workqueue);
destroy_workqueue(adsp_reset_workqueue);
#endif
}
static int __init adsp_late_init(void)
{
adsp_set_emimpu_region();
pr_info("[ADSP] late_init done\n");
return 0;
}
subsys_initcall(adsp_init);
module_init(adsp_module_init);
module_exit(adsp_exit);
late_initcall(adsp_late_init);
@@ -0,0 +1,266 @@
// SPDX-License-Identifier: GPL-2.0
//
// adsp_ipi.h -- Mediatek ADSP IPI interface
//
// Copyright (c) 2018 MediaTek Inc.
#include <linux/mutex.h>
#include <mt-plat/sync_write.h>
#include <linux/io.h>
#include <linux/hrtimer.h>
#include <linux/ktime.h>
#include <audio_ipi_platform.h>
#include "adsp_ipi.h"
#include "adsp_helper.h"
#include "adsp_excep.h"
#include <adsp_ipi_queue.h>
#include <audio_messenger_ipi.h>
/*
* =============================================================================
* log
* =============================================================================
*/
#ifdef pr_fmt
#undef pr_fmt
#endif
#define pr_fmt(fmt) "[IPI][IPC] %s(), " fmt "\n", __func__
#define PRINT_THRESHOLD 10000
enum adsp_ipi_id adsp_ipi_mutex_owner[ADSP_CORE_TOTAL];
enum adsp_ipi_id adsp_ipi_owner[ADSP_CORE_TOTAL];
struct adsp_ipi_desc adsp_ipi_desc[ADSP_NR_IPI];
struct adsp_share_obj *adsp_send_obj[ADSP_CORE_TOTAL];
struct adsp_share_obj *adsp_rcv_obj[ADSP_CORE_TOTAL];
struct mutex adsp_ipi_mutex[ADSP_CORE_TOTAL];
/*
* find an ipi handler and invoke it
*/
void adsp_A_ipi_handler(void)
{
enum adsp_ipi_id ipi_id;
struct ipi_msg_t *ipi_msg = NULL;
u8 share_buf[SHARE_BUF_SIZE - 16];
u32 len;
ktime_t start_time;
s64 stop_time;
start_time = ktime_get();
ipi_id = adsp_rcv_obj[ADSP_A_ID]->id;
len = adsp_rcv_obj[ADSP_A_ID]->len;
if (ipi_id >= ADSP_NR_IPI || ipi_id < 0)
pr_debug("[ADSP] A ipi handler id abnormal, id=%d", ipi_id);
else if (adsp_ipi_desc[ipi_id].handler) {
memcpy_fromio(share_buf,
(void *)adsp_rcv_obj[ADSP_A_ID]->share_buf, len);
if (ipi_id == ADSP_IPI_ADSP_A_READY ||
ipi_id == ADSP_IPI_LOGGER_INIT_A) {
/*
* adsp_ready & logger init ipi bypass send to ipi
* queue and do callback directly. (which will in isr)
* Must ensure the callback can do in isr
*/
adsp_ipi_desc[ipi_id].handler(ipi_id, share_buf, len);
} else if (is_scp_ipi_queue_init(AUDIO_OPENDSP_USE_HIFI3_A)) {
scp_dispatch_ipi_hanlder_to_queue(
AUDIO_OPENDSP_USE_HIFI3_A,
ipi_id, share_buf, len,
adsp_ipi_desc[ipi_id].handler);
} else {
ipi_msg = (struct ipi_msg_t *)share_buf;
if (ipi_msg->magic == IPI_MSG_MAGIC_NUMBER)
DUMP_IPI_MSG("ipi queue not ready!", ipi_msg);
else
pr_info("ipi queue not ready!! opendsp_id: %u, ipi_id: %u, buf: %p, len: %u, ipi_handler: %p",
AUDIO_OPENDSP_USE_HIFI3_A,
ipi_id, share_buf, len,
adsp_ipi_desc[ipi_id].handler);
WARN_ON(1);
}
} else {
pr_debug("[ADSP] A ipi handler is null or abnormal, id=%d",
ipi_id);
}
/* ADSP side write 1 to assert SPM wakeup src,
* while AP side write 0 to clear wakeup src.
*/
writel(0x0, ADSP_TO_SPM_REG);
stop_time = ktime_us_delta(ktime_get(), start_time);
if (stop_time > 1000) /* 1 ms */
pr_notice("IPC ISR %lld us too long!!", stop_time);
}
/*
* ipi initialize
*/
void adsp_A_ipi_init(void)
{
mutex_init(&adsp_ipi_mutex[ADSP_A_ID]);
adsp_rcv_obj[ADSP_A_ID] = ADSP_A_IPC_BUFFER;
adsp_send_obj[ADSP_A_ID] = adsp_rcv_obj[ADSP_A_ID] + 1;
pr_debug("adsp_rcv_obj[ADSP_A_ID] = 0x%p", adsp_rcv_obj[ADSP_A_ID]);
pr_debug("adsp_send_obj[ADSP_A_ID] = 0x%p", adsp_send_obj[ADSP_A_ID]);
}
/*
* API let apps can register an ipi handler to receive IPI
* @param id: IPI ID
* @param handler: IPI handler
* @param name: IPI name
*/
enum adsp_ipi_status adsp_ipi_registration(
enum adsp_ipi_id id,
void (*ipi_handler)(int id, void *data, unsigned int len),
const char *name)
{
if (id < ADSP_NR_IPI && id >= 0) {
adsp_ipi_desc[id].name = name;
if (ipi_handler == NULL)
return ADSP_IPI_ERROR;
adsp_ipi_desc[id].handler = ipi_handler;
return ADSP_IPI_DONE;
} else
return ADSP_IPI_ERROR;
}
EXPORT_SYMBOL_GPL(adsp_ipi_registration);
/*
* API let apps unregister an ipi handler
* @param id: IPI ID
*/
enum adsp_ipi_status adsp_ipi_unregistration(enum adsp_ipi_id id)
{
if (id < ADSP_NR_IPI && id >= 0) {
adsp_ipi_desc[id].name = "";
adsp_ipi_desc[id].handler = NULL;
return ADSP_IPI_DONE;
} else
return ADSP_IPI_ERROR;
}
EXPORT_SYMBOL_GPL(adsp_ipi_unregistration);
/*
* API for apps to send an IPI to adsp
* @param id: IPI ID
* @param buf: the pointer of data
* @param len: data length
* @param wait: If true, wait (atomically) until data have been gotten by Host
* @param len: data length
*/
enum adsp_ipi_status adsp_ipi_send(enum adsp_ipi_id id, void *buf,
unsigned int len, unsigned int wait,
enum adsp_core_id adsp_id)
{
int retval = 0;
uint32_t wait_ms = (wait) ? ADSP_IPI_QUEUE_DEFAULT_WAIT_MS : 0;
/* wait until IPC done */
retval = scp_send_msg_to_queue(
AUDIO_OPENDSP_USE_HIFI3_A, id, buf, len, wait_ms);
return (retval == 0) ? ADSP_IPI_DONE : ADSP_IPI_ERROR;
}
enum adsp_ipi_status adsp_ipi_send_ipc(enum adsp_ipi_id id, void *buf,
unsigned int len, unsigned int wait,
enum adsp_core_id adsp_id)
{
struct ipi_msg_t *p_ipi_msg = NULL;
ktime_t start_time;
s64 time_ipc_us;
static bool busy_log_flag;
static u8 share_buf[SHARE_BUF_SIZE - 16];
if (in_interrupt() && wait) {
pr_info("adsp_ipi_send: cannot use in isr");
return ADSP_IPI_ERROR;
}
if (adsp_id >= ADSP_CORE_TOTAL || adsp_id < 0) {
pr_notice("adsp_ipi_send: adsp_id %d is invalid", adsp_id);
return ADSP_IPI_ERROR;
}
if (is_adsp_ready(adsp_id) != 1) {
pr_notice("adsp_ipi_send: %s not enabled, id=%d",
adsp_core_ids[adsp_id], id);
return ADSP_IPI_ERROR;
}
if (len > sizeof(adsp_send_obj[adsp_id]->share_buf) || buf == NULL) {
pr_info("adsp_ipi_send: %s buffer error",
adsp_core_ids[adsp_id]);
return ADSP_IPI_ERROR;
}
if (mutex_trylock(&adsp_ipi_mutex[adsp_id]) == 0) {
pr_info("adsp_ipi_send:%s %d mutex_trylock busy,owner=%d",
adsp_core_ids[adsp_id], id,
adsp_ipi_mutex_owner[adsp_id]);
return ADSP_IPI_BUSY;
}
/* get adsp ipi mutex owner */
adsp_ipi_mutex_owner[adsp_id] = id;
if ((readl(ADSP_SWINT_REG) & (1 << adsp_id)) > 0) {
if (busy_log_flag == false) {
busy_log_flag = true;
p_ipi_msg = (struct ipi_msg_t *)share_buf;
if (p_ipi_msg->magic == IPI_MSG_MAGIC_NUMBER)
DUMP_IPI_MSG("busy. ipc owner", p_ipi_msg);
else
pr_info("adsp_ipi_send: %s %d host to adsp busy, ipi last time = %d",
adsp_core_ids[adsp_id], id,
adsp_ipi_owner[adsp_id]);
}
mutex_unlock(&adsp_ipi_mutex[adsp_id]);
return ADSP_IPI_BUSY;
}
busy_log_flag = false;
/* get adsp ipi send owner */
adsp_ipi_owner[adsp_id] = id;
memcpy(share_buf, buf, len);
memcpy_toio((void *)adsp_send_obj[adsp_id]->share_buf, buf, len);
adsp_send_obj[adsp_id]->len = len;
adsp_send_obj[adsp_id]->id = id;
dsb(SY);
/* send host to adsp ipi */
writel((1 << adsp_id), ADSP_SWINT_REG);
if (wait) {
start_time = ktime_get();
while ((readl(ADSP_SWINT_REG) & (1 << adsp_id)) > 0) {
time_ipc_us = ktime_us_delta(ktime_get(), start_time);
if (time_ipc_us > 1000) /* 1 ms */
break;
}
}
#ifdef Liang_Check
if (adsp_awake_unlock(adsp_id) == -1)
pr_debug("adsp_ipi_send: awake unlock fail");
#endif
mutex_unlock(&adsp_ipi_mutex[adsp_id]);
return ADSP_IPI_DONE;
}
EXPORT_SYMBOL_GPL(adsp_ipi_send);
@@ -0,0 +1,97 @@
// SPDX-License-Identifier: GPL-2.0
//
// adsp_irq.c-- Mediatek ADSP IRQ handling
//
// Copyright (c) 2018 MediaTek Inc.
#include <linux/spinlock.h>
#include <linux/slab.h>
#include <linux/delay.h>
#include <mt-plat/aee.h>
#include <linux/interrupt.h>
#include <mt-plat/sync_write.h>
#include "adsp_ipi.h"
#include "adsp_helper.h"
#include "adsp_excep.h"
#include "adsp_dvfs.h"
/*
* handler for wdt irq for adsp
* dump adsp register
*/
#define DRV_Reg32(addr) readl(addr)
#define DRV_WriteReg32(addr, val) writel(val, addr)
#define DRV_SetReg32(addr, val) DRV_WriteReg32(addr, DRV_Reg32(addr) | (val))
#define DRV_ClrReg32(addr, val) DRV_WriteReg32(addr, DRV_Reg32(addr) & ~(val))
#ifdef CFG_RECOVERY_SUPPORT
#define ADSP_WDT_TIMEOUT (60 * HZ) /* 60 seconds*/
static struct timer_list adsp_wdt_timer;
unsigned int wdt_counter;
#endif
irqreturn_t adsp_A_wdt_handler(int irq, void *dev_id)
{
/* disable wdt */
DRV_ClrReg32(ADSP_A_WDT_REG, WDT_EN_BIT);
#ifdef CFG_RECOVERY_SUPPORT
if (!wdt_counter && !timer_pending(&adsp_wdt_timer))
mod_timer(&adsp_wdt_timer, jiffies + ADSP_WDT_TIMEOUT);
/* recovery failed reboot*/
if (wdt_counter > WDT_LAST_WAIT_COUNT)
WARN_ON(1);
if (adsp_set_reset_status() == ADSP_RESET_STATUS_STOP) {
wdt_counter++;
pr_info("[ADSP] WDT exception (%u)\n", wdt_counter);
adsp_send_reset_wq(ADSP_RESET_TYPE_WDT, ADSP_A_ID);
} else
pr_notice("[ADSP] resetting (%u)\n", wdt_counter);
#else
adsp_aed_reset(EXCEP_RUNTIME, ADSP_A_ID);
#endif
/* clear spm wakeup src */
writel(0x0, ADSP_TO_SPM_REG);
return IRQ_HANDLED;
}
#ifdef CFG_RECOVERY_SUPPORT
static void adsp_wdt_counter_reset(struct timer_list *t)
{
del_timer(&adsp_wdt_timer);
wdt_counter = 0;
pr_info("[ADSP] %s\n", __func__);
}
#endif
/*
* dispatch adsp irq
* reset adsp and generate exception if needed
* @param irq: irq id
* @param dev_id: should be NULL
*/
irqreturn_t adsp_A_irq_handler(int irq, void *dev_id)
{
adsp_A_ipi_handler();
/* write 1 clear */
writel(ADSP_IRQ_ADSP2HOST, ADSP_A_TO_HOST_REG);
dsb(SY);
return IRQ_HANDLED;
}
/*
* adsp irq initialize
*/
void adsp_A_irq_init(void)
{
writel(ADSP_IRQ_ADSP2HOST, ADSP_A_TO_HOST_REG); /* clear adsp irq */
#ifdef CFG_RECOVERY_SUPPORT
timer_setup(&adsp_wdt_timer, adsp_wdt_counter_reset, 0);
#endif
}
@@ -0,0 +1,543 @@
// SPDX-License-Identifier: GPL-2.0
//
// adsp_logger.c-- Mediatek ADSP logger control
//
// Copyright (c) 2018 MediaTek Inc.
// Author: HsinYi Chang <hsin-yi.chang@mediatek.com>
#include <linux/fs.h> /* needed by file_operations* */
#include <linux/device.h> /* needed by device_* */
#include <linux/uaccess.h> /* needed by copy_to_user */
#include <linux/poll.h> /* needed by poll */
#include <linux/vmalloc.h> /* needed by vmalloc */
#include <linux/mutex.h>
#include <linux/spinlock.h>
#include <linux/delay.h>
#include <mt-plat/sync_write.h>
#include "adsp_helper.h"
#include "adsp_ipi.h"
#include "adsp_logger.h"
#define ADSP_TIMER_TIMEOUT (1 * HZ) /* 1 seconds */
#define ROUNDUP(a, b) (((a) + ((b)-1)) & ~((b)-1))
#define PLT_LOG_ENABLE 0x504C5402 /* magic */
static unsigned int adsp_A_logger_inited;
static struct log_ctrl_s *ADSP_A_log_ctl;
static struct buffer_info_s *ADSP_A_buf_info;
static DEFINE_MUTEX(adsp_A_log_mutex);
static void adsp_logger_init_ws(struct work_struct *ws);
static DECLARE_WORK(adsp_logger_init_work, adsp_logger_init_ws);
#if ADSP_TRAX
struct trax_ctrl_s *pADSP_A_trax_ctl, ADSP_A_trax_ctl;
static void adsp_trax_init_ws(struct work_struct *ws);
static DECLARE_WORK(adsp_trax_init_work, adsp_trax_init_ws);
#endif
/*adsp last log info*/
static unsigned int dram_buf_len;
ssize_t adsp_A_log_read(char __user *data, size_t len)
{
unsigned int w_pos, r_pos, datalen = 0;
char *buf, *to_user_buf;
mutex_lock(&adsp_A_log_mutex);
r_pos = ADSP_A_buf_info->r_pos;
w_pos = ADSP_A_buf_info->w_pos;
if (r_pos == w_pos)
goto error;
if (r_pos > w_pos)
datalen = dram_buf_len - r_pos; /* not wrap */
else
datalen = w_pos - r_pos;
if (datalen > len)
datalen = len;
/* debug for logger pos fail */
if (r_pos >= dram_buf_len) {
pr_info("[ADSP] %s(): r_pos >= dram_buf_len,%x,%x\n", __func__,
r_pos, ADSP_A_log_ctl->buff_ofs);
return 0;
}
buf = ((char *) ADSP_A_log_ctl) + ADSP_A_log_ctl->buff_ofs + r_pos;
to_user_buf = vmalloc(len);
len = datalen;
/* memory copy from log buf */
if (to_user_buf) {
memcpy_fromio(to_user_buf, buf, len);
if (copy_to_user(data, to_user_buf, len))
pr_debug("[ADSP]copy to user buf failed..\n");
vfree(to_user_buf);
} else {
pr_debug("[ADSP]create log buffer failed..\n");
goto error;
}
r_pos += datalen;
if (r_pos >= dram_buf_len)
r_pos -= dram_buf_len;
ADSP_A_buf_info->r_pos = r_pos;
error:
mutex_unlock(&adsp_A_log_mutex);
return datalen;
}
unsigned int adsp_A_log_poll(void)
{
if (!adsp_A_logger_inited)
return 0;
if (ADSP_A_buf_info->r_pos != ADSP_A_buf_info->w_pos)
return POLLIN | POLLRDNORM;
/* adsp_log_timer_add(); */
return 0;
}
ssize_t adsp_A_log_if_read(struct file *file, char __user *data,
size_t len, loff_t *ppos)
{
if (!adsp_A_logger_inited)
return 0;
return adsp_A_log_read(data, len);
}
int adsp_A_log_if_open(struct inode *inode, struct file *file)
{
/* pr_debug("[ADSP A] adsp_A_log_if_open\n"); */
return nonseekable_open(inode, file);
}
unsigned int adsp_A_log_if_poll(struct file *file, poll_table *wait)
{
unsigned int ret = 0;
if (!adsp_A_logger_inited)
return 0;
if (!(file->f_mode & FMODE_READ))
return ret;
ret = adsp_A_log_poll();
return ret;
}
/*
* ipi send to enable adsp logger flag
*/
static unsigned int adsp_A_log_enable_set(unsigned int enable)
{
int ret = 0;
if (adsp_A_logger_inited) {
enable = (enable) ? 1 : 0;
adsp_register_feature(ADSP_LOGGER_FEATURE_ID);
ret = adsp_ipi_send(ADSP_IPI_LOGGER_ENABLE, &enable,
sizeof(enable), 1, ADSP_A_ID);
adsp_deregister_feature(ADSP_LOGGER_FEATURE_ID);
if (ret != ADSP_IPI_DONE) {
pr_err("%s(), logger enable fail ret=%d\n",
__func__, ret);
goto error;
}
ADSP_A_log_ctl->enable = enable;
}
error:
return 0;
}
#if ADSP_TRAX
static unsigned int adsp_A_trax_enable_set(unsigned int enable)
{
int ret = 0;
if (pADSP_A_trax_ctl->initiated) {
enable = (enable) ? 1 : 0;
adsp_register_feature(ADSP_LOGGER_FEATURE_ID);
ret = adsp_ipi_send(ADSP_IPI_TRAX_ENABLE, &enable,
sizeof(enable), 1, ADSP_A_ID);
adsp_deregister_feature(ADSP_LOGGER_FEATURE_ID);
if (ret != ADSP_IPI_DONE) {
pr_err("%s(), trax enable fail ret=%d\n",
__func__, ret);
goto error;
}
pADSP_A_trax_ctl->enable = enable;
if (enable)
pADSP_A_trax_ctl->done = 0;
}
error:
return 0;
}
#endif
/*
* create device sysfs, adsp logger status
*/
static ssize_t log_enable_show(struct device *kobj, struct device_attribute *attr, char *buf)
{
unsigned int stat;
stat = (adsp_A_logger_inited && ADSP_A_log_ctl->enable) ? 1 : 0;
return scnprintf(buf, PAGE_SIZE, "[ADSP A] mobile log is %s\n",
(stat == 0x1) ? "enabled" : "disabled");
}
static ssize_t log_enable_store(struct device *kobj, struct device_attribute *attr,
const char *buf, size_t n)
{
unsigned int enable;
if (kstrtouint(buf, 0, &enable) != 0)
return -EINVAL;
mutex_lock(&adsp_A_log_mutex);
adsp_A_log_enable_set(enable);
mutex_unlock(&adsp_A_log_mutex);
return n;
}
DEVICE_ATTR_RW(log_enable);
/*
* logger UT test
*
*/
#if ADSP_LOGGER_UT
static ssize_t adsp_A_mobile_log_UT_show(struct device *kobj,
struct device_attribute *attr,
char *buf)
{
unsigned int w_pos, r_pos, datalen;
char *logger_buf;
size_t len = 1024;
if (!adsp_A_logger_inited)
return 0;
datalen = 0;
mutex_lock(&adsp_A_log_mutex);
r_pos = ADSP_A_buf_info->r_pos;
w_pos = ADSP_A_buf_info->w_pos;
pr_debug("%s r_pos=%d, w_pos=%d\n", __func__, r_pos, w_pos);
if (r_pos == w_pos)
goto error;
if (r_pos > w_pos)
datalen = dram_buf_len - r_pos; /* not wrap */
else
datalen = w_pos - r_pos;
if (datalen > len)
datalen = len;
logger_buf = ((char *)ADSP_A_log_ctl) +
ADSP_A_log_ctl->buff_ofs + r_pos;
pr_debug("%s buff_ofs=%d, logger_buf=%p\n", __func__,
ADSP_A_log_ctl->buff_ofs, logger_buf);
len = datalen;
/*memory copy from log buf*/
memcpy_fromio(buf, logger_buf, len);
r_pos += datalen;
if (r_pos >= dram_buf_len)
r_pos -= dram_buf_len;
ADSP_A_buf_info->r_pos = r_pos;
error:
mutex_unlock(&adsp_A_log_mutex);
return len;
}
static ssize_t adsp_A_mobile_log_UT_store(struct device *kobj,
struct device_attribute *attr,
const char *buf, size_t n)
{
unsigned int enable;
if (kstrtouint(buf, 0, &enable) != 0)
return -EINVAL;
mutex_lock(&adsp_A_log_mutex);
adsp_A_log_enable_set(enable);
mutex_unlock(&adsp_A_log_mutex);
return n;
}
DEVICE_ATTR_RW(adsp_A_mobile_log_UT);
#endif
#if ADSP_TRAX
static ssize_t adsp_A_trax_show(struct device *kobj,
struct device_attribute *attr,
char *buf)
{
pr_info("[ADSP] %s initiated=%d, done=%d, length=%d\n",
__func__, pADSP_A_trax_ctl->initiated, pADSP_A_trax_ctl->done,
pADSP_A_trax_ctl->length);
if (!pADSP_A_trax_ctl->initiated || !pADSP_A_trax_ctl->done)
return 0;
memcpy(buf, adsp_get_reserve_mem_virt(ADSP_A_TRAX_MEM_ID),
pADSP_A_trax_ctl->length);
return pADSP_A_trax_ctl->length;
}
static ssize_t adsp_A_trax_store(struct device *kobj,
struct device_attribute *attr,
const char *buf, size_t n)
{
unsigned int enable;
if (kstrtouint(buf, 0, &enable) != 0)
return -EINVAL;
adsp_A_trax_enable_set(enable);
return n;
}
DEVICE_ATTR_RW(adsp_A_trax);
#endif
static struct attribute *adsp_logger_attrs[] = {
&dev_attr_log_enable.attr,
#if ADSP_LOGGER_UT
&dev_attr_adsp_A_mobile_log_UT.attr,
#endif
#if ADSP_TRAX
&dev_attr_adsp_A_trax.attr,
#endif
NULL,
};
struct attribute_group adsp_logger_attr_group = {
.attrs = adsp_logger_attrs,
};
/*
* IPI for logger init
* @param id: IPI id
* @param data: IPI data
* @param len: IPI data length
*/
static void adsp_A_logger_init_handler(int id, void *data, unsigned int len)
{
/* send work to initialize logger*/
queue_work(adsp_workqueue, &adsp_logger_init_work);
}
#if ADSP_TRAX
static void adsp_A_trax_init_handler(int id, void *data, unsigned int len)
{
/*send work to initialize trax */
queue_work(adsp_workqueue, &adsp_trax_init_work);
}
static void adsp_A_trax_done_handler(int id, void *data, unsigned int len)
{
/* sync adsp trax length information*/
pADSP_A_trax_ctl->length = *((int *)data);
pADSP_A_trax_ctl->done = 1;
pr_debug("[ADSP] %s length=%d\n", __func__,
pADSP_A_trax_ctl->length);
}
#endif
/*
* callback function for work struct
* notify apps to start their tasks or generate an exception according to flag
* NOTE: this function may be blocked
* and should not be called in interrupt context
* @param ws: work struct
*/
static void adsp_logger_init_ws(struct work_struct *ws)
{
enum adsp_ipi_status ret;
uint64_t mem_info[6];
memset(adsp_get_reserve_mem_virt(ADSP_A_CORE_DUMP_MEM_ID), 0,
adsp_get_reserve_mem_size(ADSP_A_CORE_DUMP_MEM_ID));
/* 0: logger buf addr, 1: logger buf size */
/* 2: coredump buf addr, 3: coredump buf size */
mem_info[0] = adsp_get_reserve_mem_phys(ADSP_A_LOGGER_MEM_ID);
mem_info[1] = adsp_get_reserve_mem_size(ADSP_A_LOGGER_MEM_ID);
mem_info[2] = adsp_get_reserve_mem_phys(ADSP_A_CORE_DUMP_MEM_ID);
mem_info[3] = adsp_get_reserve_mem_size(ADSP_A_CORE_DUMP_MEM_ID);
mem_info[4] = adsp_get_reserve_mem_phys(ADSP_A_DEBUG_DUMP_MEM_ID);
mem_info[5] = adsp_get_reserve_mem_size(ADSP_A_DEBUG_DUMP_MEM_ID);
pr_info("[ADSP] logger addr 0x%llx, size 0x%llx\n",
mem_info[0], mem_info[1]);
pr_info("[ADSP] coredump addr 0x%llx, size 0x%llx\n",
mem_info[2], mem_info[3]);
pr_info("[ADSP] debugdump addr 0x%llx, size 0x%llx\n",
mem_info[4], mem_info[5]);
adsp_register_feature(ADSP_LOGGER_FEATURE_ID);
ret = adsp_ipi_send(ADSP_IPI_LOGGER_INIT_A, (void *)mem_info,
sizeof(mem_info), 1, ADSP_A_ID);
adsp_deregister_feature(ADSP_LOGGER_FEATURE_ID);
if (ret != ADSP_IPI_DONE)
pr_err("[ADSP]logger initial fail, ipi ret=%d\n", ret);
}
#if ADSP_TRAX
static void adsp_trax_init_ws(struct work_struct *ws)
{
enum adsp_ipi_status ret;
phys_addr_t reserved_phys_trax;
unsigned int phys_u32;
reserved_phys_trax = adsp_get_reserve_mem_phys(ADSP_A_TRAX_MEM_ID);
pr_info("[ADSP]reserved_phys_trax=0x%llx, size=%lu\n",
reserved_phys_trax, sizeof(reserved_phys_trax));
phys_u32 = (unsigned int)reserved_phys_trax;
pr_info("[ADSP]phys_u32=0x%x, size=%lu\n", phys_u32, sizeof(phys_u32));
adsp_register_feature(ADSP_LOGGER_FEATURE_ID);
ret = adsp_ipi_send(ADSP_IPI_TRAX_INIT_A, (void *)&phys_u32,
sizeof(phys_u32), 1, ADSP_A_ID);
adsp_deregister_feature(ADSP_LOGGER_FEATURE_ID);
if (ret != ADSP_IPI_DONE)
pr_err("[ADSP]trax initial fail, ipi ret=%d\n", ret);
pADSP_A_trax_ctl->initiated = 1;
}
#endif
/*
* init adsp logger dram ctrl structure
* @return: 0: success, otherwise: fail
*/
int adsp_logger_init(void)
{
int last_ofs;
void *addr = adsp_get_reserve_mem_virt(ADSP_A_LOGGER_MEM_ID);
size_t size = adsp_get_reserve_mem_size(ADSP_A_LOGGER_MEM_ID);
/*init dram ctrl table*/
last_ofs = 0;
ADSP_A_log_ctl = (struct log_ctrl_s *)addr;
ADSP_A_log_ctl->base = PLT_LOG_ENABLE; /* magic */
ADSP_A_log_ctl->enable = 0;
ADSP_A_log_ctl->size = sizeof(*ADSP_A_log_ctl);
last_ofs += ADSP_A_log_ctl->size;
ADSP_A_log_ctl->info_ofs = last_ofs;
last_ofs += sizeof(*ADSP_A_buf_info);
last_ofs = ROUNDUP(last_ofs, 4);
ADSP_A_log_ctl->buff_ofs = last_ofs;
dram_buf_len =
adsp_get_reserve_mem_size(ADSP_A_LOGGER_MEM_ID) - last_ofs;
ADSP_A_log_ctl->buff_size = dram_buf_len;
pr_info("[ADSP] logger dram_buf_len=0x%x\n", dram_buf_len);
ADSP_A_buf_info = (struct buffer_info_s *)
(((unsigned char *) ADSP_A_log_ctl) +
ADSP_A_log_ctl->info_ofs);
ADSP_A_buf_info->r_pos = 0;
ADSP_A_buf_info->w_pos = 0;
last_ofs += ADSP_A_log_ctl->buff_size;
if (last_ofs > size) {
pr_warn("[ADSP]:%s() initial fail, last_ofs=%u, size=%zu\n",
__func__, last_ofs, size);
goto error;
}
/* register logger ini IPI */
adsp_ipi_registration(ADSP_IPI_LOGGER_INIT_A,
adsp_A_logger_init_handler,
"loggerA");
adsp_A_logger_inited = 1;
return 0;
error:
adsp_A_logger_inited = 0;
ADSP_A_log_ctl = NULL;
ADSP_A_buf_info = NULL;
return -1;
}
#if ADSP_TRAX
int adsp_trax_init(void)
{
adsp_ipi_registration(ADSP_IPI_TRAX_INIT_A, adsp_A_trax_init_handler,
"trax init");
adsp_ipi_registration(ADSP_IPI_TRAX_DONE, adsp_A_trax_done_handler,
"trax done");
memset(&ADSP_A_trax_ctl, 0, sizeof(ADSP_A_trax_ctl));
pADSP_A_trax_ctl = &ADSP_A_trax_ctl;
return 0;
}
#endif
#if ADSP_TRAX
int adsp_get_trax_initiated(void)
{
return pADSP_A_trax_ctl->initiated;
}
int adsp_get_trax_done(void)
{
return pADSP_A_trax_ctl->done;
}
int adsp_get_trax_length(void)
{
return pADSP_A_trax_ctl->length;
}
#endif
@@ -0,0 +1,51 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* adsp_logger.h -- Mediatek ADSP logger
*
* Copyright (c) 2018 MediaTek Inc.
* Author: HsinYi Chang <hsin-yi.chang@mediatek.com>
*/
#ifndef __ADSP_LOGGER_H__
#define __ADSP_LOGGER_H__
#define ADSP_LOGGER_UT (0)
struct log_ctrl_s {
unsigned int base;
unsigned int size;
unsigned int enable;
unsigned int info_ofs;
unsigned int buff_ofs;
unsigned int buff_size;
unsigned char resv1[104]; /* dummy bytes for 128-byte align */
};
struct buffer_info_s {
unsigned int r_pos;
unsigned char resv1[124]; /* dummy bytes for 128-byte align */
unsigned int w_pos;
unsigned char resv2[124]; /* dummy bytes for 128-byte align */
};
int adsp_logger_init(void);
/* device fops */
ssize_t adsp_A_log_if_read(struct file *file, char __user *data,
size_t len, loff_t *ppos);
int adsp_A_log_if_open(struct inode *inode, struct file *file);
unsigned int adsp_A_log_if_poll(struct file *file, poll_table *wait);
#if ADSP_TRAX
struct trax_ctrl_s {
unsigned int done;
unsigned int length;
unsigned int enable;
unsigned int initiated;
};
int adsp_trax_init(void);
#endif
#endif /* __ADSP_LOGGER_H__ */
@@ -0,0 +1,222 @@
// SPDX-License-Identifier: GPL-2.0
//
// adsp_service.c -- Mediatek ADSP service for ioctrl handling
//
// Copyright (c) 2018 MediaTek Inc.
// Author: HsinYi Chang <hsin-yi.chang@mediatek.com>
#include <linux/module.h> /* needed by all modules */
#include <linux/init.h> /* needed by module macros */
#include <linux/fs.h> /* needed by file_operations* */
#include <linux/miscdevice.h> /* needed by miscdevice* */
#include <linux/sysfs.h>
#include <linux/device.h> /* needed by device_* */
#include <linux/vmalloc.h> /* needed by kmalloc */
#include <linux/uaccess.h> /* needed by copy_to_user */
#include <linux/slab.h> /* needed by kmalloc */
#include <linux/poll.h> /* needed by poll */
#include <linux/mutex.h>
#include <linux/sched.h>
#include <linux/interrupt.h>
#include <linux/suspend.h>
#include <linux/timer.h>
#include <linux/notifier.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/of_irq.h>
#include <linux/of_fdt.h>
#include <linux/ioport.h>
#include <linux/io.h>
#include <adsp_ipi.h>
#include <adsp_helper.h>
#include <adsp_dvfs.h>
/*==============================================================================
* ioctl
*==============================================================================
*/
#define AUDIO_DSP_DEVICE_PATH "/dev/adsp"
#define AUDIO_DSP_IOC_MAGIC 'a'
#define AUDIO_DSP_IOCTL_ADSP_REG_FEATURE \
_IOW(AUDIO_DSP_IOC_MAGIC, 0, unsigned int)
#define AUDIO_DSP_IOCTL_ADSP_QUERY_STATUS \
_IOR(AUDIO_DSP_IOC_MAGIC, 1, unsigned int)
#define AUDIO_DSP_IOCTL_ADSP_RESET_CBK \
_IOR(AUDIO_DSP_IOC_MAGIC, 2, unsigned int)
/*
* =============================================================================
* struct
* =============================================================================
*/
struct audio_dsp_reg_feature_t {
uint16_t reg_flag;
uint16_t feature_id;
};
struct audio_dsp_query_status_t {
int16_t ready_flag;
uint16_t core_id;
};
/*
* =============================================================================
* static var
* =============================================================================
*/
static long status_update_flag;
static DECLARE_WAIT_QUEUE_HEAD(status_wq);
static unsigned long last_dsp_status;
static int16_t last_ready_flag;
static int adsp_hal_feature_table[ADSP_NUM_FEATURE_ID];
/*==============================================================================
* functions - implementation
*==============================================================================
*/
void adsp_read_status_release(const unsigned long dsp_event)
{
last_dsp_status = dsp_event;
if (status_update_flag == 0) {
status_update_flag = 1;
pr_info("wake up event: %lu\n", dsp_event);
wake_up_interruptible(&status_wq);
}
}
static int adsp_read_status_blocked(void)
{
int status = 0;
int retval = 0;
retval = wait_event_interruptible(status_wq,
(status_update_flag > 0));
if (retval == -ERESTARTSYS) {
pr_info("query adsp status -ERESTARTSYS");
status = -EINTR;
} else if (retval == 0) {
status = last_dsp_status;
status_update_flag = 0;
pr_info("query adsp status wakeup %d\n", status);
} else
status = -1;
return status;
}
#ifdef CONFIG_COMPAT
long adsp_driver_compat_ioctl(
struct file *file, unsigned int cmd, unsigned long arg)
{
if (!file->f_op || !file->f_op->unlocked_ioctl) {
pr_notice("op null\n");
return -ENOTTY;
}
return file->f_op->unlocked_ioctl(file, cmd, arg);
}
#endif
void reset_hal_feature_table(void)
{
int i;
for (i = 0; i < ADSP_NUM_FEATURE_ID; i++) {
while (adsp_hal_feature_table[i] > 0) {
adsp_deregister_feature(i);
adsp_hal_feature_table[i]--;
}
}
}
long adsp_driver_ioctl(
struct file *file, unsigned int cmd, unsigned long arg)
{
struct audio_dsp_reg_feature_t feat_reg;
struct audio_dsp_query_status_t adsp_status;
int retval = 0;
unsigned int magic[2];
switch (cmd) {
case AUDIO_DSP_IOCTL_ADSP_REG_FEATURE: {
if (((void __user *)arg) == NULL) {
retval = -1;
break;
}
retval = copy_from_user(
&feat_reg,
(void __user *)arg,
sizeof(struct audio_dsp_reg_feature_t));
if (retval != 0) {
pr_notice("%s(), feature reg copy_from_user retval %d\n",
__func__, retval);
break;
}
if (feat_reg.feature_id >= ADSP_NUM_FEATURE_ID) {
retval = -EINVAL;
break;
}
if (feat_reg.reg_flag)
retval = adsp_register_feature(feat_reg.feature_id);
else
retval = adsp_deregister_feature(feat_reg.feature_id);
if (retval == 0) {
if (feat_reg.reg_flag)
adsp_hal_feature_table[feat_reg.feature_id]++;
else
adsp_hal_feature_table[feat_reg.feature_id]--;
if (adsp_hal_feature_table[feat_reg.feature_id] < 0)
adsp_hal_feature_table[feat_reg.feature_id] = 0;
}
break;
}
case AUDIO_DSP_IOCTL_ADSP_QUERY_STATUS: {
if (((void __user *)arg) == NULL) {
retval = -EINVAL;
break;
}
retval = copy_from_user(
&adsp_status,
(void __user *)arg,
sizeof(struct audio_dsp_query_status_t));
if (retval)
pr_debug("%s copy_from_user fail line %d\n",
__func__, __LINE__);
adsp_status.ready_flag = is_adsp_ready(adsp_status.core_id);
retval = copy_to_user((void __user *)arg, &adsp_status,
sizeof(struct audio_dsp_reg_feature_t));
if (retval)
pr_debug("%s copy_to_user fail line %d\n",
__func__, __LINE__);
if (adsp_status.ready_flag != last_ready_flag)
pr_debug("%s(), AUDIO_DSP_IOCTL_ADSP_QUERY_STATUS(%d)\n",
__func__, adsp_status.ready_flag);
last_ready_flag = adsp_status.ready_flag;
break;
}
case AUDIO_DSP_IOCTL_ADSP_RESET_CBK: {
if (copy_from_user(&magic, (void *)arg, sizeof(magic))) {
retval = -EINVAL;
break;
}
if (magic[0] + magic[1] == 0xFFFFFFFF) {
retval = adsp_read_status_blocked();
pr_debug("%s(), AUDIO_DSP_IOCTL_ADSP_RESET_CBK(%d)\n",
__func__, retval);
}
break;
}
}
return retval;
}
@@ -0,0 +1,185 @@
// SPDX-License-Identifier: GPL-2.0
//
// adsp_timesync.c-- Mediatek ADSP timesync
//
// Copyright (c) 2020 MediaTek Inc.
// Author: Celine Liu <Celine.liu@mediatek.com>
#include <linux/clocksource.h>
#include <linux/sched/clock.h>
#include <linux/suspend.h>
#include <linux/timex.h>
#include <linux/types.h>
#include <linux/io.h>
#include <asm/arch_timer.h>
#include <asm/timex.h>
#include "adsp_helper.h"
#include "adsp_timesync.h"
struct adsp_ts_context_t {
spinlock_t lock;
struct work_struct work;
ktime_t wrap_kt;
u8 enabled;
u8 init_synced;
u64 base_tick;
u64 base_ts;
};
static struct adsp_ts_context_t adsp_ts_ctx;
static struct timecounter adsp_ts_counter;
static struct hrtimer adsp_ts_refresh_timer;
static u32 adsp_base_ver;
static int adsp_ts_update(int fz, u64 tick, u64 ts)
{
adsp_base_ver = (adsp_base_ver+1) & TIMESYNC_MAX_VER;
if (is_adsp_ready(ADSP_A_ID) == 1 || !adsp_ts_ctx.init_synced) {
adsp_reg_sync_writel((tick >> 32) & 0xFFFFFFFF,
ADSP_TIMESYNC_TICK_H);
adsp_reg_sync_writel(tick & 0xFFFFFFFF,
ADSP_TIMESYNC_TICK_L);
adsp_reg_sync_writel((ts >> 32) & 0xFFFFFFFF,
ADSP_TIMESYNC_TS_H);
adsp_reg_sync_writel(ts & 0xFFFFFFFF,
ADSP_TIMESYNC_TS_L);
adsp_reg_sync_writel(fz,
ADSP_TIMESYNC_FREEZE);
return 0;
}
return -1;
}
static u64 adsp_ts_tick_read(const struct cyclecounter *cc)
{
return arch_timer_read_counter();
}
static struct cyclecounter adsp_timesync_cc __ro_after_init = {
.read = adsp_ts_tick_read,
.mask = CLOCKSOURCE_MASK(56),
};
static void adsp_timesync_sync_base_internal(unsigned int flag)
{
u64 tick, ts;
unsigned long irq_flags = 0;
int freeze, unfreeze;
int updated;
spin_lock_irqsave(&adsp_ts_ctx.lock, irq_flags);
ts = timecounter_read(&adsp_ts_counter);
tick = adsp_ts_counter.cycle_last;
adsp_ts_ctx.base_tick = tick;
adsp_ts_ctx.base_ts = ts;
freeze = (flag & TIMESYNC_FLAG_FREEZE) ? 1 : 0;
unfreeze = (flag & TIMESYNC_FLAG_UNFREEZE) ? 1 : 0;
/* sync with adsp */
updated = adsp_ts_update(freeze, tick, ts);
spin_unlock_irqrestore(&adsp_ts_ctx.lock, irq_flags);
pr_info("%s update base: updated=%d, ts=%llu, tick=0x%llx, fz=%d, ver=%d\n",
TIMESYNC_TAG, updated, ts, tick, freeze, adsp_base_ver);
}
void adsp_timesync_sync_base(unsigned int flag)
{
if (!adsp_ts_ctx.enabled)
return;
if (flag & TIMESYNC_FLAG_ASYNC)
schedule_work(&(adsp_ts_ctx.work));
else
adsp_timesync_sync_base_internal(flag);
}
static enum hrtimer_restart adsp_ts_refresh(struct hrtimer *hrt)
{
hrtimer_forward_now(hrt, adsp_ts_ctx.wrap_kt);
/* snchronize new sched_clock base to co-processors */
adsp_timesync_sync_base(TIMESYNC_FLAG_ASYNC);
return HRTIMER_RESTART;
}
static void adsp_timesync_ws(struct work_struct *ws)
{
adsp_timesync_sync_base(TIMESYNC_FLAG_SYNC);
}
int __init adsp_timesync_init(void)
{
adsp_ts_ctx.enabled = 0;
adsp_ts_ctx.init_synced = 0;
INIT_WORK(&(adsp_ts_ctx.work), adsp_timesync_ws);
spin_lock_init(&adsp_ts_ctx.lock);
/* init cyclecounter mult and shift as sched_clock */
clocks_calc_mult_shift(&adsp_timesync_cc.mult, &adsp_timesync_cc.shift,
arch_timer_get_cntfrq(), NSEC_PER_SEC, 3600);
adsp_ts_ctx.wrap_kt = ns_to_ktime(TIMESYNC_WRAP_TIME);
/* Init time counter:
* start_time: current sched_clock
* read: arch timer counter
*/
timecounter_init(&adsp_ts_counter, &adsp_timesync_cc, sched_clock());
hrtimer_init(&adsp_ts_refresh_timer,
CLOCK_MONOTONIC, HRTIMER_MODE_REL);
adsp_ts_refresh_timer.function = adsp_ts_refresh;
hrtimer_start(&adsp_ts_refresh_timer,
adsp_ts_ctx.wrap_kt, HRTIMER_MODE_REL);
pr_info("%s ts: cycle_last %lld, time_base:%lld, wrap:%lld\n",
TIMESYNC_TAG, adsp_ts_counter.cycle_last,
adsp_ts_counter.nsec, adsp_ts_ctx.wrap_kt);
adsp_ts_ctx.enabled = 1;
adsp_timesync_sync_base(TIMESYNC_FLAG_SYNC);
adsp_ts_ctx.init_synced = 1;
return 0;
}
void adsp_timesync_suspend(u8 fz)
{
if (!adsp_ts_ctx.enabled)
return;
hrtimer_cancel(&adsp_ts_refresh_timer);
flush_work(&(adsp_ts_ctx.work));
/* snchronize new sched_clock base to co-processors */
fz = (fz) ? TIMESYNC_FLAG_FREEZE : 0;
adsp_timesync_sync_base(TIMESYNC_FLAG_SYNC | fz);
}
void adsp_timesync_resume(void)
{
if (!adsp_ts_ctx.enabled)
return;
/* re-init timecounter because sched_clock will be stopped during
* suspend but arch timer counter is not, so we need to update
* start time after resume
*/
timecounter_init(&adsp_ts_counter, &adsp_timesync_cc, sched_clock());
hrtimer_start(&adsp_ts_refresh_timer,
adsp_ts_ctx.wrap_kt, HRTIMER_MODE_REL);
/* snchronize new sched_clock base to co-processors */
adsp_timesync_sync_base(TIMESYNC_FLAG_SYNC |
TIMESYNC_FLAG_UNFREEZE);
}
@@ -0,0 +1,39 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
* Author: Celine Liu <Celine.liu@mediatek.com>
*/
#ifndef _ADSP_TIMESYNC_H_
#define _ADSP_TIMESYNC_H_
#ifdef CONFIG_ARM64
#define IOMEM(a) ((void __force __iomem *)((a)))
#endif
#define adsp_reg_sync_writel(v, a) \
do { \
__raw_writel((v), IOMEM(a)); \
dsb(sy); \
} while (0)
#define TIMESYNC_TAG "[ADSP_TS]"
#define TIMESYNC_MAX_VER (0xFF)
#define TIMESYNC_FLAG_SYNC (1 << 0)
#define TIMESYNC_FLAG_ASYNC (1 << 1)
#define TIMESYNC_FLAG_FREEZE (1 << 2)
#define TIMESYNC_FLAG_UNFREEZE (1 << 3)
/* sched_clock wrap time is 4398 seconds for arm arch timer
* applying a period less than it for tinysys timesync
*/
#define TIMESYNC_WRAP_TIME (4000*NSEC_PER_SEC)
void adsp_timesync_suspend(u8 fz);
void adsp_timesync_resume(void);
int __init adsp_timesync_init(void);
#endif // _ADSP_TIMESYNC_H_
@@ -0,0 +1,21 @@
# SPDX-License-Identifier: GPL-2.0
ifeq ($(CONFIG_MACH_MT6781),y)
ADSP_PLATFORM := mt6781
else
ADSP_PLATFORM := $(subst ",,$(CONFIG_MTK_PLATFORM))
endif
obj-y += adsp.o
adsp-y := adsp_core.o adsp_fs.o adsp_semaphore.o adsp_logger.o adsp_feature_table.o adsp_timesync.o
ccflags-y += -I$(srctree)/drivers/misc/mediatek/audio_ipi/common_v2/framework
ccflags-y += -I$(srctree)/drivers/misc/mediatek/adsp/$(ADSP_PLATFORM)
ifeq ($(CONFIG_MTK_ENG_BUILD),y)
CFLAGS_adsp_core.o += -DDEBUG
CFLAGS_adsp_fs.o += -DDEBUG
CFLAGS_adsp_logger.o += -DDEBUG
CFLAGS_adsp_semaphore.o += -DDEBUG
CFLAGS_adsp_feature_table.o += -DDEBUG
endif
@@ -0,0 +1,459 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/module.h> /* needed by all modules */
#include <linux/init.h> /* needed by module macros */
#include <linux/device.h>
#include <linux/io.h>
#include <linux/interrupt.h>
#include "adsp_clk.h"
#include "adsp_platform.h"
#include "adsp_platform_driver.h"
#include "audio_ipi_platform.h"
#include "adsp_ipi_queue.h"
#include "adsp_mbox.h"
#include "adsp_core.h"
#include "adsp_timesync.h"
/* protect access tcm if set reset flag */
rwlock_t access_rwlock;
/* notifier */
static BLOCKING_NOTIFIER_HEAD(adsp_notifier_list);
struct adsp_priv *_get_adsp_core(void *ptr, int id)
{
if (ptr)
return container_of(ptr, struct adsp_priv, mdev);
if (id < ADSP_CORE_TOTAL && id >= 0)
return adsp_cores[id];
return NULL;
}
void set_adsp_state(struct adsp_priv *pdata, int state)
{
pdata->state = state;
}
int get_adsp_state(struct adsp_priv *pdata)
{
return pdata->state;
}
int is_adsp_ready(u32 cid)
{
if (unlikely(cid >= ADSP_CORE_TOTAL))
return -EINVAL;
if (unlikely(!adsp_cores[cid]))
return -EINVAL;
return (adsp_cores[cid]->state == ADSP_RUNNING);
}
bool is_adsp_system_running(void)
{
unsigned int id;
for (id = 0; id < ADSP_CORE_TOTAL; id++) {
if (is_adsp_ready(id) > 0)
return true;
}
return false;
}
EXPORT_SYMBOL(is_adsp_system_running);
void __iomem *adsp_get_sharedmem_base(struct adsp_priv *pdata, int id)
{
void __iomem *dst = NULL;
const struct sharedmem_info *item;
if (unlikely(id >= ADSP_SHAREDMEM_NUM))
return NULL;
item = pdata->mapping_table + id;
if (item->offset)
dst = pdata->dtcm + pdata->dtcm_size - item->offset;
if (unlikely(!dst))
return NULL;
return dst;
}
int adsp_copy_to_sharedmem(struct adsp_priv *pdata, int id, const void *src,
int count)
{
void __iomem *dst = NULL;
const struct sharedmem_info *item;
if (unlikely(id >= ADSP_SHAREDMEM_NUM))
return 0;
item = pdata->mapping_table + id;
if (item->offset)
dst = pdata->dtcm + pdata->dtcm_size - item->offset;
if (unlikely(!dst || !src))
return 0;
if (count > item->size)
count = item->size;
memcpy_toio(dst, src, count);
return count;
}
int adsp_copy_from_sharedmem(struct adsp_priv *pdata, int id, void *dst,
int count)
{
void __iomem *src = NULL;
const struct sharedmem_info *item;
if (unlikely(id >= ADSP_SHAREDMEM_NUM))
return 0;
item = pdata->mapping_table + id;
if (item->offset)
src = pdata->dtcm + pdata->dtcm_size - item->offset;
if (unlikely(!dst || !src))
return 0;
if (count > item->size)
count = item->size;
memcpy_fromio(dst, src, count);
return count;
}
enum adsp_ipi_status adsp_push_message(enum adsp_ipi_id id, void *buf,
unsigned int len, unsigned int wait_ms,
unsigned int core_id)
{
int ret = 0;
u32 queue_id = core_id + AUDIO_OPENDSP_USE_HIFI3_A;
if (is_scp_ipi_queue_init(queue_id))
ret = scp_send_msg_to_queue(queue_id, id, buf, len, wait_ms);
else
ret = adsp_send_message(id, buf, len, wait_ms, core_id);
return (ret == 0) ? ADSP_IPI_DONE : ADSP_IPI_ERROR;
}
enum adsp_ipi_status adsp_send_message(enum adsp_ipi_id id, void *buf,
unsigned int len, unsigned int wait,
unsigned int core_id)
{
#if (MTK_ADSP_HW_VER == 1)
struct mtk_ipi_msg msg;
#endif
struct adsp_priv *pdata = get_adsp_core_by_id(core_id);
if (get_adsp_state(pdata) != ADSP_RUNNING) {
pr_notice("%s, adsp not enabled, id=%d", __func__, id);
return ADSP_IPI_ERROR;
}
if (id == ADSP_IPI_DVFS_SUSPEND) {
set_adsp_state(pdata, ADSP_SUSPENDING);
}
if (len > (SHARE_BUF_SIZE - 16) || buf == NULL) {
pr_info("%s(), %s buffer error", __func__, "adsp");
return ADSP_IPI_ERROR;
}
#if (MTK_ADSP_HW_VER == 1)
msg.ipihd.id = id;
msg.ipihd.len = len;
msg.ipihd.options = 0xffff0000;
msg.ipihd.reserved = 0xdeadbeef;
msg.data = buf;
return adsp_mbox_send(pdata->send_mbox, &msg, wait);
#else
return adsp_ipi_send_ipc(id, buf, len, wait, core_id);
#endif
}
static irqreturn_t adsp_irq_dispatcher(int irq, void *data)
{
struct irq_t *pdata = (struct irq_t *)data;
adsp_mt_clr_spm(pdata->cid);
if (pdata->irq_cb)
pdata->irq_cb(irq, pdata->data, pdata->cid);
if (pdata->clear_irq)
pdata->clear_irq(pdata->cid);
return IRQ_HANDLED;
}
int adsp_irq_registration(u32 core_id, u32 irq_id, void *handler, void *data)
{
int ret;
struct adsp_priv *pdata = get_adsp_core_by_id(core_id);
if (unlikely(!pdata))
return -EACCES;
if (irq_id >= ADSP_IRQ_NUM)
return -EINVAL;
pdata->irq[irq_id].cid = core_id;
pdata->irq[irq_id].irq_cb = handler;
pdata->irq[irq_id].data = data;
ret = request_irq(pdata->irq[irq_id].seq,
(irq_handler_t)adsp_irq_dispatcher,
IRQF_TRIGGER_NONE,
pdata->name,
&pdata->irq[irq_id]);
return ret;
}
void adsp_register_notify(struct notifier_block *nb)
{
blocking_notifier_chain_register(&adsp_notifier_list, nb);
}
void adsp_unregister_notify(struct notifier_block *nb)
{
blocking_notifier_chain_unregister(&adsp_notifier_list, nb);
}
void adsp_extern_notify_chain(enum ADSP_NOTIFY_EVENT event)
{
#ifdef CFG_RECOVERY_SUPPORT
blocking_notifier_call_chain(&adsp_notifier_list, event, NULL);
#endif
}
void switch_adsp_power(bool on)
{
if (on) {
adsp_enable_clock();
adsp_set_clock_freq(CLK_DEFAULT_INIT_CK);
} else {
adsp_set_clock_freq(CLK_DEFAULT_26M_CK);
adsp_disable_clock();
}
}
void adsp_sram_restore_snapshot(struct adsp_priv *pdata)
{
if (!pdata->itcm || !pdata->itcm_snapshot || !pdata->itcm_size ||
!pdata->dtcm || !pdata->dtcm_snapshot || !pdata->dtcm_size)
return;
memcpy_toio(pdata->itcm, pdata->itcm_snapshot, pdata->itcm_size);
memcpy_toio(pdata->dtcm, pdata->dtcm_snapshot, pdata->dtcm_size);
}
void adsp_sram_provide_snapshot(struct adsp_priv *pdata)
{
if (!pdata->itcm || !pdata->dtcm)
return;
if (!pdata->itcm_snapshot)
pdata->itcm_snapshot = vmalloc(pdata->itcm_size);
if (!pdata->dtcm_snapshot)
pdata->dtcm_snapshot = vmalloc(pdata->dtcm_size);
if (!pdata->itcm_snapshot || !pdata->dtcm_snapshot)
return;
memcpy_fromio(pdata->itcm_snapshot, pdata->itcm, pdata->itcm_size);
memcpy_fromio(pdata->dtcm_snapshot, pdata->dtcm, pdata->dtcm_size);
}
int adsp_reset(void)
{
#ifdef CFG_RECOVERY_SUPPORT
int ret = 0, cid = 0;
struct adsp_priv *pdata;
if (!is_adsp_axibus_idle()) {
pr_info("%s, adsp_axibus busy try again", __func__);
return -EAGAIN;
}
/* clear adsp cfg */
adsp_mt_clear();
/* choose default clk mux */
adsp_set_clock_freq(CLK_DEFAULT_26M_CK);
adsp_set_clock_freq(CLK_DEFAULT_INIT_CK);
/* restore tcm to initial state */
for (cid = 0; cid < ADSP_CORE_TOTAL; cid++) {
pdata = adsp_cores[cid];
adsp_sram_restore_snapshot(pdata);
}
/* restart adsp */
for (cid = 0; cid < ADSP_CORE_TOTAL; cid++) {
pdata = adsp_cores[cid];
adsp_mt_sw_reset(cid);
reinit_completion(&pdata->done);
adsp_mt_run(cid);
ret = wait_for_completion_timeout(&pdata->done, HZ);
if (unlikely(ret == 0)) {
pr_warn("%s, core %d reset timeout\n", __func__, cid);
return -ETIME;
}
}
for (cid = 0; cid < ADSP_CORE_TOTAL; cid++) {
pdata = adsp_cores[cid];
if (pdata->ops->after_bootup)
pdata->ops->after_bootup(pdata);
}
pr_info("[ADSP] reset adsp done\n");
#endif
return 0;
}
static void adsp_ready_ipi_handler(int id, void *data, unsigned int len)
{
unsigned int cid = *(unsigned int *)data;
struct adsp_priv *pdata = get_adsp_core_by_id(cid);
if (unlikely(!pdata))
return;
if (get_adsp_state(pdata) != ADSP_RUNNING) {
set_adsp_state(pdata, ADSP_RUNNING);
complete(&pdata->done);
}
}
static void adsp_suspend_ipi_handler(int id, void *data, unsigned int len)
{
unsigned int cid = *(unsigned int *)data;
struct adsp_priv *pdata = get_adsp_core_by_id(cid);
if (unlikely(!pdata))
return;
complete(&pdata->done);
}
static int __init adsp_init(void)
{
int ret = 0;
ret = create_adsp_drivers();
if (!ret) {
pr_info("%s fail\n", __func__);
return -ENODEV;
}
rwlock_init(&access_rwlock);
adsp_platform_init();
adsp_ipi_registration(ADSP_IPI_ADSP_A_READY,
adsp_ready_ipi_handler,
"adsp_ready");
adsp_ipi_registration(ADSP_IPI_DVFS_SUSPEND,
adsp_suspend_ipi_handler,
"adsp_suspend_ack");
adsp_timesync_init();
pr_info("%s, ret(%d)\n", __func__, ret);
return ret;
}
static int __init adsp_module_init(void)
{
int ret = 0, cid = 0;
struct adsp_priv *pdata;
if (!is_adsp_load()) {
ret = -ENODEV;
goto ERROR;
}
switch_adsp_power(true);
for (cid = 0; cid < ADSP_CORE_TOTAL; cid++) {
pdata = adsp_cores[cid];
if (unlikely(!pdata)) {
ret = -EFAULT;
goto ERROR;
}
adsp_mt_sw_reset(cid);
ret = pdata->ops->initialize(pdata);
if (unlikely(ret)) {
pr_warn("%s, initialize %d is fail\n", __func__, cid);
goto ERROR;
}
adsp_sram_provide_snapshot(pdata);
adsp_mt_run(cid);
ret = wait_for_completion_timeout(&pdata->done, HZ);
if (unlikely(ret == 0)) {
pr_warn("%s, core %d boot_up timeout\n", __func__, cid);
ret = -ETIME;
goto ERROR;
}
}
adsp_register_feature(SYSTEM_FEATURE_ID); /* regi for trigger suspend */
for (cid = 0; cid < ADSP_CORE_TOTAL; cid++) {
pdata = adsp_cores[cid];
if (pdata->ops->after_bootup)
pdata->ops->after_bootup(pdata);
}
adsp_deregister_feature(SYSTEM_FEATURE_ID);
pr_info("%s done\n", __func__);
return ret;
ERROR:
pr_info("%s fail ret(%d)\n", __func__, ret);
return ret;
}
/*
* driver exit point
*/
static void __exit adsp_exit(void)
{
}
static int __init adsp_late_init(void)
{
if (!is_adsp_load())
return -ENXIO;
adsp_set_emimpu_shared_region();
pr_info("[ADSP] late_init done\n");
return 0;
}
subsys_initcall(adsp_init);
module_init(adsp_module_init);
module_exit(adsp_exit);
late_initcall(adsp_late_init);
@@ -0,0 +1,45 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __ADSP_CORE_H__
#define __ADSP_CORE_H__
#include "adsp_helper.h"
enum ADSP_CORE_STATE {
ADSP_RESET = 0,
ADSP_SUSPEND = 1,
ADSP_SLEEP = 2,
ADSP_RUNNING = 3,
ADSP_SUSPENDING = 4,
};
struct adsp_priv;
/* core api */
#define get_adsp_core_by_ptr(ptr) _get_adsp_core(ptr, 0)
#define get_adsp_core_by_id(id) _get_adsp_core(NULL, id)
struct adsp_priv *_get_adsp_core(void *ptr, int id);
void set_adsp_state(struct adsp_priv *pdata, int state);
int get_adsp_state(struct adsp_priv *pdata);
bool is_adsp_system_running(void);
void __iomem *adsp_get_sharedmem_base(struct adsp_priv *pdata, int id);
int adsp_copy_to_sharedmem(struct adsp_priv *pdata, int id, const void *src,
int count);
int adsp_copy_from_sharedmem(struct adsp_priv *pdata, int id, void *dst,
int count);
void switch_adsp_power(bool on);
int adsp_reset(void);
void adsp_extern_notify_chain(enum ADSP_NOTIFY_EVENT event);
/* wakelock */
int adsp_awake_init(struct adsp_priv *pdata, u32 mask);
int adsp_awake_lock(u32 cid);
int adsp_awake_unlock(u32 cid);
#endif
@@ -0,0 +1,300 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2018 MediaTek Inc.
*/
#include <linux/module.h> /* needed by all modules */
#include <linux/workqueue.h>
#include <linux/kernel.h>
#include "adsp_feature_define.h"
#include "adsp_platform.h"
struct adsp_feature_tb {
const char *name;
int counter[ADSP_CORE_TOTAL];
};
static struct adsp_feature_control feature_ctrl[ADSP_CORE_TOTAL];
/*adsp feature list*/
static struct adsp_feature_tb feature_table[ADSP_NUM_FEATURE_ID] = {
[SYSTEM_FEATURE_ID] = {.name = "system"},
[ADSP_LOGGER_FEATURE_ID] = {.name = "logger"},
[AURISYS_FEATURE_ID] = {.name = "aurisys"},
[AUDIO_CONTROLLER_FEATURE_ID] = {.name = "audio_controller"},
[PRIMARY_FEATURE_ID] = {.name = "primary"},
[DEEPBUF_FEATURE_ID] = {.name = "deepbuf"},
[OFFLOAD_FEATURE_ID] = {.name = "offload"},
[AUDIO_PLAYBACK_FEATURE_ID] = {.name = "audplayback"},
[AUDIO_MUSIC_FEATURE_ID] = {.name = "music"},
[A2DP_PLAYBACK_FEATURE_ID] = {.name = "a2dp_playback"},
[AUDIO_DATAPROVIDER_FEATURE_ID] = {.name = "dataprovider"},
[SPK_PROTECT_FEATURE_ID] = {.name = "spk_protect"},
[VOICE_CALL_FEATURE_ID] = {.name = "voice_call"},
[VOIP_FEATURE_ID] = {.name = "voip"},
[CAPTURE_UL1_FEATURE_ID] = {.name = "capture_ul1"},
[CALL_FINAL_FEATURE_ID] = {.name = "call_final"},
[FAST_FEATURE_ID] = {.name = "fast"},
[KTV_FEATURE_ID] = {.name = "ktv"},
[CAPTURE_RAW_FEATURE_ID] = {.name = "capture_raw"},
[FM_ADSP_FEATURE_ID] = {.name = "fm_adsp"},
[VOICE_CALL_SUB_FEATURE_ID] = {.name = "voice_call_sub"},
};
int adsp_get_feature_index(const char *str)
{
int i = 0;
size_t len;
struct adsp_feature_tb *unit;
if (!str)
return -EINVAL;
len = strlen(str);
for (i = 0; i < ADSP_NUM_FEATURE_ID; i++) {
unit = &feature_table[i];
if (!unit->name || strlen(unit->name) != len)
continue;
if (strncmp(unit->name, str, len) == 0)
break;
}
return i == ADSP_NUM_FEATURE_ID ? -EINVAL : i;
}
ssize_t adsp_dump_feature_state(u32 cid, char *buffer, int size)
{
int n = 0;
uint32_t i = 0;
struct adsp_feature_tb *unit;
struct adsp_feature_control *ctrl = &feature_ctrl[cid];
n += scnprintf(buffer + n, size - n, "%-20s %-8s %-8s\n",
"Feature_name", "DTS_Set", "Counter");
for (i = 0; i < ADSP_NUM_FEATURE_ID; i++) {
unit = &feature_table[i];
if (!unit->name)
continue;
n += scnprintf(buffer + n, size - n, "%-20s %-8d %-3d\n",
unit->name,
(ctrl->feature_set >> i) & 0x1,
unit->counter[cid]);
}
n += scnprintf(buffer + n, size - n, "Count_total: %d\n", ctrl->total);
return n;
}
bool adsp_feature_is_active(u32 cid)
{
if (cid >= ADSP_CORE_TOTAL)
return false;
return feature_ctrl[cid].total;
}
bool is_adsp_feature_in_active(void)
{
// ADSP_A is the master.
return adsp_feature_is_active(ADSP_A_ID);
}
EXPORT_SYMBOL(is_adsp_feature_in_active);
int _adsp_register_feature(u32 cid, u32 fid, u32 opt)
{
int ret = 0;
struct adsp_feature_control *ctrl;
struct adsp_feature_tb *item;
if (fid >= ADSP_NUM_FEATURE_ID || cid >= ADSP_CORE_TOTAL)
return -EINVAL;
ctrl = &feature_ctrl[cid];
item = &feature_table[fid];
if (!item->name)
return -EINVAL;
if (cid != ADSP_A_ID)
_adsp_register_feature(ADSP_A_ID, SYSTEM_FEATURE_ID, 0);
mutex_lock(&ctrl->lock);
if (ctrl->total == 0 && ctrl->resume) {
cancel_delayed_work(&ctrl->suspend_work);
ret = ctrl->resume();
}
if (ret == 0) {
item->counter[cid] += 1;
ctrl->total += 1;
}
mutex_unlock(&ctrl->lock);
return ret;
}
int _adsp_deregister_feature(u32 cid, u32 fid, u32 opt)
{
struct adsp_feature_control *ctrl;
struct adsp_feature_tb *item;
unsigned long delay;
if (fid >= ADSP_NUM_FEATURE_ID || cid >= ADSP_CORE_TOTAL)
return -EINVAL;
ctrl = &feature_ctrl[cid];
item = &feature_table[fid];
if (!item->name)
return -EINVAL;
mutex_lock(&ctrl->lock);
if (item->counter[cid] == 0) {
pr_err("[%s] error to deregister id=%d\n", __func__, fid);
mutex_unlock(&ctrl->lock);
return -EINVAL;
}
item->counter[cid] -= 1;
ctrl->total -= 1;
if (ctrl->total == 0) {
delay = (opt & DEREGI_FLAG_NODELAY) ?
0 : msecs_to_jiffies(ctrl->delay_ms);
queue_delayed_work(ctrl->wq, &ctrl->suspend_work, delay);
pr_info("%s, send suspend work cid(%u), fid(%u), delay(%lu)",
__func__, cid, fid, delay);
}
mutex_unlock(&ctrl->lock);
if (cid != ADSP_A_ID)
_adsp_deregister_feature(ADSP_A_ID, SYSTEM_FEATURE_ID, 0);
return 0;
}
bool is_feature_in_set(u32 cid, u32 fid)
{
if (fid >= ADSP_NUM_FEATURE_ID || cid >= ADSP_CORE_TOTAL)
return false;
return (feature_ctrl[cid].feature_set >> fid) & 0x1;
}
int adsp_feature_in_which_core(enum adsp_feature_id fid)
{
u32 cid = 0;
if (fid >= ADSP_NUM_FEATURE_ID)
return -1;
for (cid = 0; cid < ADSP_CORE_TOTAL; cid++) {
if (is_feature_in_set(cid, fid))
return cid;
}
return -1;
}
int adsp_register_feature(enum adsp_feature_id fid)
{
int ret = -1, cid;
bool flag = false;
if (fid >= ADSP_NUM_FEATURE_ID || fid < 0)
return -EINVAL;
for (cid = 0; cid < ADSP_CORE_TOTAL; cid++) {
if (!is_feature_in_set(cid, fid))
continue;
flag = true;
ret = _adsp_register_feature(cid, fid, 0);
if (ret)
pr_info("%s, failed core:%d, fid:%d, ret:%d",
__func__, cid, fid, ret);
}
if (!flag)
pr_info("%s, feature '%s' not in any core_set",
__func__, feature_table[fid].name);
return ret;
}
int adsp_deregister_feature(enum adsp_feature_id fid)
{
int ret = -1, cid;
bool flag = false;
if (fid >= ADSP_NUM_FEATURE_ID || fid < 0)
return -EINVAL;
for (cid = 0; cid < ADSP_CORE_TOTAL; cid++) {
if (!is_feature_in_set(cid, fid))
continue;
flag = true;
ret = _adsp_deregister_feature(cid, fid, 0);
if (ret)
pr_info("%s, failed core:%d, fid:%d, ret:%d",
__func__, cid, fid, ret);
}
if (!flag)
pr_info("%s, feature '%s' not in any core_set",
__func__, feature_table[fid].name);
return ret;
}
static void suspend_work_ws(struct work_struct *work)
{
struct adsp_feature_control *ctrl = container_of(work,
struct adsp_feature_control, suspend_work.work);
mutex_lock(&ctrl->lock);
if (ctrl->total == 0 && ctrl->suspend)
ctrl->suspend();
mutex_unlock(&ctrl->lock);
}
bool flush_suspend_work(u32 cid)
{
struct adsp_feature_control *ctrl = &feature_ctrl[cid];
if (ctrl->total == 0)
return flush_delayed_work(&ctrl->suspend_work);
return false;
}
int init_adsp_feature_control(u32 cid, u32 feature_set, int delay_ms,
struct workqueue_struct *wq,
int (*_suspend)(void),
int (*_resume)(void))
{
struct adsp_feature_control *ctrl;
int i = 0;
if (cid >= ADSP_CORE_TOTAL || !wq)
return -EINVAL;
ctrl = &feature_ctrl[cid];
ctrl->wq = wq;
ctrl->suspend = _suspend;
ctrl->resume = _resume;
ctrl->feature_set = feature_set;
ctrl->delay_ms = delay_ms;
mutex_init(&ctrl->lock);
INIT_DELAYED_WORK(&ctrl->suspend_work, suspend_work_ws);
ctrl->total = 0;
for (i = 0; i < ADSP_NUM_FEATURE_ID; i++)
ctrl->total += feature_table[i].counter[cid];
return 0;
}
@@ -0,0 +1,407 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/slab.h>
#include <linux/device.h>
#include <linux/sysfs.h>
#include <linux/debugfs.h>
#include <linux/uaccess.h>
#include <linux/soc/mediatek/mtk-mbox.h>
#include "adsp_reserved_mem.h"
#include "adsp_platform_driver.h"
#include "adsp_logger.h"
#include "adsp_excep.h"
#include "adsp_core.h"
/* ----------------------------- sys fs ------------------------------------ */
static inline ssize_t dev_dump_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct adsp_priv *pdata = container_of(dev_get_drvdata(dev),
struct adsp_priv, mdev);
int n = 0, i = 0;
n += scnprintf(buf + n, PAGE_SIZE - n, "name:%s id = %d\n",
pdata->name, pdata->id);
n += scnprintf(buf + n, PAGE_SIZE - n, "cfg = %p, size = %zu\n",
pdata->cfg, pdata->cfg_size);
n += scnprintf(buf + n, PAGE_SIZE - n, "itcm = %p, size = %zu\n",
pdata->itcm, pdata->itcm_size);
n += scnprintf(buf + n, PAGE_SIZE - n, "dtcm = %p, size = %zu\n",
pdata->dtcm, pdata->dtcm_size);
n += scnprintf(buf + n, PAGE_SIZE - n, "sysram = %p, size = %zu\n",
pdata->sysram, pdata->sysram_size);
for (i = 0; i < ADSP_IRQ_NUM; i++)
n += scnprintf(buf + n, PAGE_SIZE - n, "%d ", pdata->irq[i].seq);
n += scnprintf(buf + n, PAGE_SIZE - n, "\n");
n += scnprintf(buf + n, PAGE_SIZE - n,
"status = %d, feature_set = %X\n",
pdata->state, pdata->feature_set);
if (pdata->send_mbox)
n += scnprintf(buf + n, PAGE_SIZE - n, "mailbox send = %d\n",
pdata->send_mbox->mbox);
if (pdata->recv_mbox)
n += scnprintf(buf + n, PAGE_SIZE - n, "mailbox recv = %d\n",
pdata->recv_mbox->mbox);
return n;
}
DEVICE_ATTR_RO(dev_dump);
static inline ssize_t ipi_test_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct adsp_priv *pdata = container_of(dev_get_drvdata(dev),
struct adsp_priv, mdev);
int value = 0;
if (kstrtoint(buf, 10, &value))
return -EINVAL;
if (_adsp_register_feature(pdata->id, SYSTEM_FEATURE_ID, 0) == 0) {
adsp_push_message(ADSP_IPI_TEST1, &value, sizeof(value),
20, pdata->id);
_adsp_deregister_feature(pdata->id, SYSTEM_FEATURE_ID, 0);
}
return count;
}
static inline ssize_t ipi_test_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct adsp_priv *pdata = container_of(dev_get_drvdata(dev),
struct adsp_priv, mdev);
unsigned int value = 0x5A5A;
int ret;
if (!is_adsp_ready(pdata->id))
return scnprintf(buf, PAGE_SIZE, "ADSP is not ready\n");
if (_adsp_register_feature(pdata->id, SYSTEM_FEATURE_ID, 0) == 0) {
ret = adsp_push_message(ADSP_IPI_TEST1, &value,
sizeof(value), 20, pdata->id);
_adsp_deregister_feature(pdata->id,
SYSTEM_FEATURE_ID, 0);
return scnprintf(buf, PAGE_SIZE, "ADSP ipi send ret=%d\n", ret);
} else
return scnprintf(buf, PAGE_SIZE, "ADSP register fail\n");
}
DEVICE_ATTR_RW(ipi_test);
static inline ssize_t suspend_cmd_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct adsp_priv *pdata = container_of(dev_get_drvdata(dev),
struct adsp_priv, mdev);
return adsp_dump_feature_state(pdata->id, buf, PAGE_SIZE);
}
static inline ssize_t suspend_cmd_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
uint32_t fid = 0;
char *temp = NULL, *token1 = NULL, *token2 = NULL;
char *pin = NULL;
char delim[] = " ,\t\n";
struct adsp_priv *pdata = container_of(dev_get_drvdata(dev),
struct adsp_priv, mdev);
temp = kstrdup(buf, GFP_KERNEL);
pin = temp;
token1 = strsep(&pin, delim);
token2 = strsep(&pin, delim);
if (!token1 || !token2)
goto EXIT;
fid = adsp_get_feature_index(token2);
if (fid == SYSTEM_FEATURE_ID)
goto EXIT;
if (!is_feature_in_set(pdata->id, fid))
goto EXIT;
if (strcmp(token1, "regi") == 0)
_adsp_register_feature(pdata->id, fid, 0);
if (strcmp(token1, "deregi") == 0)
_adsp_deregister_feature(pdata->id, fid, 0);
EXIT:
kfree(temp);
return count;
}
DEVICE_ATTR_RW(suspend_cmd);
static inline ssize_t log_enable_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct adsp_priv *pdata = container_of(dev_get_drvdata(dev),
struct adsp_priv, mdev);
return adsp_dump_log_state(pdata->log_ctrl, buf, PAGE_SIZE);
}
static inline ssize_t log_enable_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
unsigned int enable = 0;
struct adsp_priv *pdata = container_of(dev_get_drvdata(dev),
struct adsp_priv, mdev);
if (kstrtouint(buf, 0, &enable) != 0)
return -EINVAL;
adsp_log_enable(pdata->log_ctrl, pdata->id, enable);
return count;
}
DEVICE_ATTR_RW(log_enable);
static inline ssize_t wakelock_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
unsigned int input = 0;
int ret = 0;
struct adsp_priv *pdata = container_of(dev_get_drvdata(dev),
struct adsp_priv, mdev);
if (kstrtouint(buf, 0, &input) != 0)
return -EINVAL;
if (input == 1)
ret = adsp_awake_lock(pdata->id);
else if (input == 0)
ret = adsp_awake_unlock(pdata->id);
pr_info("%s, input %u, ret = %d", __func__, input, ret);
return count;
}
DEVICE_ATTR_WO(wakelock);
static struct attribute *adsp_default_attrs[] = {
&dev_attr_dev_dump.attr,
&dev_attr_ipi_test.attr,
&dev_attr_suspend_cmd.attr,
&dev_attr_log_enable.attr,
&dev_attr_wakelock.attr,
NULL,
};
struct attribute_group adsp_default_attr_group = {
.attrs = adsp_default_attrs,
};
/* ---------------------------- debug fs ----------------------------------- */
static ssize_t adsp_debug_read(struct file *filp, char __user *buf,
size_t count, loff_t *pos)
{
char *buffer = NULL;
size_t n = 0, max_size;
struct adsp_priv *pdata = filp->private_data;
u32 memid = pdata->id + ADSP_A_DEBUG_DUMP_MEM_ID;
buffer = adsp_get_reserve_mem_virt(memid);
max_size = adsp_get_reserve_mem_size(memid);
if (buffer)
n = strnlen(buffer, max_size);
return simple_read_from_buffer(buf, count, pos, buffer, n);
}
static ssize_t adsp_debug_write(struct file *filp, const char __user *buffer,
size_t count, loff_t *ppos)
{
char buf[64];
struct adsp_priv *pdata = filp->private_data;
if (copy_from_user(buf, buffer, min(count, sizeof(buf))))
return -EFAULT;
if (_adsp_register_feature(pdata->id, SYSTEM_FEATURE_ID, 0) == 0) {
adsp_push_message(ADSP_IPI_ADSP_TIMER,
buf, min(count, sizeof(buf)), 0, pdata->id);
_adsp_deregister_feature(pdata->id, SYSTEM_FEATURE_ID, 0);
}
return count;
}
const struct file_operations adsp_debug_ops = {
.open = simple_open,
.read = adsp_debug_read,
.write = adsp_debug_write,
};
/* ------------------------------ misc device ----------------------------- */
/*==============================================================================
* ioctl
*==============================================================================
*/
#define AUDIO_DSP_IOC_MAGIC 'a'
#define AUDIO_DSP_IOCTL_ADSP_REG_FEATURE \
_IOW(AUDIO_DSP_IOC_MAGIC, 0, unsigned int)
#define AUDIO_DSP_IOCTL_ADSP_QUERY_STATUS \
_IOR(AUDIO_DSP_IOC_MAGIC, 1, unsigned int)
#define AUDIO_DSP_IOCTL_ADSP_RESET_CBK \
_IOR(AUDIO_DSP_IOC_MAGIC, 2, unsigned int)
union ioctl_param {
struct {
uint16_t enable;
uint16_t fid;
} cmd0;
struct {
int16_t flag;
uint16_t cid;
} cmd1;
};
/* user-space feature reset */
static int adsp_hal_feature_table[ADSP_NUM_FEATURE_ID];
void reset_hal_feature_table(void)
{
int i;
for (i = 0; i < ADSP_NUM_FEATURE_ID; i++) {
while (adsp_hal_feature_table[i] > 0) {
adsp_deregister_feature(i);
adsp_hal_feature_table[i]--;
}
}
}
/* file operations */
static ssize_t adsp_driver_read(struct file *filp, char __user *data,
size_t len, loff_t *ppos)
{
struct adsp_priv *pdata = container_of(filp->private_data,
struct adsp_priv, mdev);
return adsp_log_read(pdata->log_ctrl, data, len);
}
static int adsp_driver_open(struct inode *inode, struct file *file)
{
return nonseekable_open(inode, file);
}
static unsigned int adsp_driver_poll(struct file *filp,
struct poll_table_struct *poll)
{
struct adsp_priv *pdata = container_of(filp->private_data,
struct adsp_priv, mdev);
if (!pdata->log_ctrl || !pdata->log_ctrl->inited)
return 0;
if (!(filp->f_mode & FMODE_READ))
return 0;
return adsp_log_poll(pdata->log_ctrl);
}
static long adsp_driver_ioctl(
struct file *filp, unsigned int cmd, unsigned long arg)
{
int ret = 0;
union ioctl_param t;
switch (cmd) {
case AUDIO_DSP_IOCTL_ADSP_REG_FEATURE: {
if (copy_from_user(&t, (void *)arg, sizeof(t))) {
ret = -EFAULT;
break;
}
if (t.cmd0.fid == SYSTEM_FEATURE_ID) {
pr_debug("%s(), reg/dreg SYSTEM_FEATURE_ID is not permitted!\n", __func__);
ret = -EPERM;
break;
}
if (t.cmd0.enable)
ret = adsp_register_feature(t.cmd0.fid);
else
ret = adsp_deregister_feature(t.cmd0.fid);
if (ret == 0) {
if (t.cmd0.enable)
adsp_hal_feature_table[t.cmd0.fid]++;
else
adsp_hal_feature_table[t.cmd0.fid]--;
if (adsp_hal_feature_table[t.cmd0.fid] < 0)
adsp_hal_feature_table[t.cmd0.fid] = 0;
}
break;
}
case AUDIO_DSP_IOCTL_ADSP_QUERY_STATUS: {
if (copy_from_user(&t, (void *)arg, sizeof(t))) {
ret = -EFAULT;
break;
}
t.cmd1.flag = is_adsp_ready(t.cmd1.cid);
if (copy_to_user((void __user *)arg, &t, sizeof(t))) {
ret = -EFAULT;
break;
}
break;
}
default:
pr_debug("%s(), invalid ioctl cmd\n", __func__);
}
if (ret < 0)
pr_info("%s(), ioctl error %d\n", __func__, ret);
return ret;
}
static long adsp_driver_compat_ioctl(
struct file *file, unsigned int cmd, unsigned long arg)
{
if (!file->f_op || !file->f_op->unlocked_ioctl) {
pr_notice("op null\n");
return -ENOTTY;
}
return file->f_op->unlocked_ioctl(file, cmd, arg);
}
const struct file_operations adsp_common_file_ops = {
.owner = THIS_MODULE,
.open = adsp_driver_open,
.unlocked_ioctl = adsp_driver_ioctl,
#ifdef CONFIG_COMPAT
.compat_ioctl = adsp_driver_compat_ioctl,
#endif
};
const struct file_operations adsp_core_file_ops = {
.owner = THIS_MODULE,
.read = adsp_driver_read,
.open = adsp_driver_open,
.poll = adsp_driver_poll,
};
@@ -0,0 +1,254 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/uaccess.h> /* needed by copy_to_user */
#include <linux/vmalloc.h> /* needed by vmalloc */
#include <linux/poll.h> /* needed by poll */
#include <linux/mutex.h>
#include <linux/io.h>
#include <linux/slab.h>
#include "adsp_platform.h"
#include "adsp_platform_driver.h"
#include "adsp_reserved_mem.h"
#include "adsp_core.h"
#include "adsp_logger.h"
#define PLT_LOG_ENABLE 0x504C5402 /* magic */
#define MINIMUM_LOG_BUF_SIZE 0x10000 /* 64k */
unsigned int adsp_log_poll(struct log_ctrl_s *ctrl)
{
struct log_info_s *log_info;
struct buffer_info_s *buf_info;
if (!ctrl || !ctrl->inited)
return 0;
log_info = (struct log_info_s *)ctrl->priv;
buf_info = (struct buffer_info_s *)(ctrl->priv + log_info->info_ofs);
if (buf_info->r_pos != buf_info->w_pos)
return POLLIN | POLLRDNORM;
return 0;
}
ssize_t adsp_log_read(struct log_ctrl_s *ctrl, char __user *userbuf, size_t len)
{
unsigned int w_pos, r_pos, datalen = 0;
unsigned int data_len[2];
void *addr;
void *tmp_area;
struct log_info_s *log_info;
struct buffer_info_s *buf_info;
if (!ctrl || !ctrl->inited)
return 0;
addr = ctrl->priv;
log_info = (struct log_info_s *)ctrl->priv;
buf_info =(struct buffer_info_s *)(ctrl->priv + log_info->info_ofs);
mutex_lock(&ctrl->lock);
memcpy_fromio(&r_pos, &buf_info->r_pos, sizeof(r_pos));
memcpy_fromio(&w_pos, &buf_info->w_pos, sizeof(w_pos));
if (r_pos == w_pos)
goto error;
else if (r_pos < w_pos)
datalen = w_pos - r_pos;
else
datalen = log_info->buff_size - r_pos + w_pos;
if (datalen > len)
datalen = len;
if (r_pos + datalen > log_info->buff_size) {
data_len[0] = log_info->buff_size - r_pos;
data_len[1] = r_pos + datalen - log_info->buff_size;
} else {
data_len[0] = datalen;
data_len[1] = 0;
}
tmp_area = vmalloc(datalen);
if (tmp_area) {
addr += log_info->buff_ofs;
memcpy_fromio(tmp_area, addr + r_pos, data_len[0]);
memcpy_fromio(tmp_area + data_len[0], addr, data_len[1]);
if (copy_to_user(userbuf, tmp_area, datalen))
pr_info("%s, copy to user buf failed\n", __func__);
vfree(tmp_area);
}
r_pos += datalen;
if (r_pos >= log_info->buff_size)
r_pos -= log_info->buff_size;
#ifdef CONFIG_MTK_AEE_FEATURE
if (r_pos >= log_info->buff_size) {
aee_kernel_exception("ADSP", "logger overflow r_pos:%u >= %u\n",
r_pos, log_info->buff_size);
}
#endif
memcpy_toio(&buf_info->r_pos, &r_pos, sizeof(r_pos));
error:
mutex_unlock(&ctrl->lock);
return datalen;
}
/*
* ipi send to enable adsp logger flag
*/
ssize_t adsp_log_enable(struct log_ctrl_s *ctrl, int cid, u32 enable)
{
int ret = 0;
struct log_info_s *log_info;
mutex_lock(&ctrl->lock);
if (ctrl->inited) {
enable = (enable) ? 1 : 0;
_adsp_register_feature(cid, ADSP_LOGGER_FEATURE_ID, 0);
ret = adsp_push_message(ADSP_IPI_LOGGER_ENABLE, &enable,
sizeof(enable), 20, cid);
_adsp_deregister_feature(cid, ADSP_LOGGER_FEATURE_ID, 0);
if (ret != ADSP_IPI_DONE) {
pr_err("%s(), logger enable fail ret=%d\n",
__func__, ret);
goto error;
} else {
log_info = (struct log_info_s *)ctrl->priv;
log_info->enable = enable;
}
}
error:
mutex_unlock(&ctrl->lock);
return 0;
}
/*
* IPI for logger init
* @param id: IPI id
* @param data: IPI data
* @param len: IPI data length
*/
static void adsp_logger_init_handler(int id, void *data, unsigned int len)
{
unsigned int *ptr = (unsigned int *)data;
unsigned int delay = 0;
struct adsp_priv *pdata = get_adsp_core_by_id(*ptr);
if (!pdata) {
pr_info("%s, pdata is NULL\n", __func__);
return;
}
if (len > sizeof(unsigned int)) {
/* sync error, show error message, add delay for re-sync */
delay = msecs_to_jiffies(100);
pr_info("%s, resync fail msg, id(%u), addr(0x%x), size(0x%x), check:[0x%x, 0x%x, 0x%x, 0x%x, 0x%x]\n",
__func__,
*(ptr + 0), *(ptr + 1),
*(ptr + 2), *(ptr + 3),
*(ptr + 4), *(ptr + 5),
*(ptr + 6), *(ptr + 7));
}
/* send work to initialize logger*/
schedule_delayed_work(&pdata->log_ctrl->work, delay);
}
/*
* init adsp logger dram ctrl structure
* @return: 0: success, otherwise: fail
*/
struct log_ctrl_s *adsp_logger_init(int mem_id, void (*work_cb)(struct work_struct *ws))
{
struct log_ctrl_s *ctrl = NULL;
struct log_info_s *log_info;
struct buffer_info_s *buf_info;
int last_ofs;
size_t size;
ctrl = kzalloc(sizeof(*ctrl), GFP_KERNEL);
if (!ctrl)
goto DONE;
ctrl->priv = adsp_get_reserve_mem_virt(mem_id);
size = adsp_get_reserve_mem_size(mem_id);
if (!ctrl->priv || size < MINIMUM_LOG_BUF_SIZE) {
pr_info("%s(), failed addr=%p, size=%zu\n", __func__,
ctrl->priv, size);
kfree(ctrl);
ctrl = NULL;
goto DONE;
}
memset(ctrl->priv, 0, size);
/* init dram ctrl table */
last_ofs = 0;
log_info = (struct log_info_s *)ctrl->priv;
log_info->base = PLT_LOG_ENABLE; /* magic */
log_info->enable = 0;
log_info->size = sizeof(struct log_info_s);
last_ofs += ALIGN(sizeof(struct log_info_s), 128);
log_info->info_ofs = last_ofs;
buf_info = (struct buffer_info_s *)(ctrl->priv + log_info->info_ofs);
buf_info->r_pos = 0;
buf_info->w_pos = 0;
last_ofs += sizeof(struct buffer_info_s);
last_ofs = ALIGN(last_ofs, 128);
log_info->buff_ofs = last_ofs;
log_info->buff_size = size - last_ofs;
/* register logger ini IPI */
adsp_ipi_registration(ADSP_IPI_LOGGER_INIT, adsp_logger_init_handler,
"logger_init");
INIT_DELAYED_WORK(&ctrl->work, work_cb);
/* init ap use struct */
mutex_init(&ctrl->lock);
ctrl->inited = true;
pr_debug("%s, init done, check:[0x%x, 0x%x, 0x%x, 0x%x]", __func__,
log_info->base, log_info->size, log_info->info_ofs, log_info->buff_ofs);
DONE:
return ctrl;
}
ssize_t adsp_dump_log_state(struct log_ctrl_s *ctrl, char *buf, int size)
{
int n = 0;
unsigned int w_pos, r_pos;
struct log_info_s *log_info = (struct log_info_s *)ctrl->priv;
struct buffer_info_s *info = ctrl->priv + log_info->info_ofs;
n += scnprintf(buf + n, size - n, "log_control\n");
n += scnprintf(buf + n, size - n, "base:%X, size: %u\n",
log_info->base, log_info->size);
n += scnprintf(buf + n, size - n, "init:%u, enable:%u\n",
ctrl->inited, log_info->enable);
n += scnprintf(buf + n, size - n, "\nbuffer_info\n");
n += scnprintf(buf + n, size - n,
"info_ofs:%u, buff_ofs:%u, buff_size:%u\n",
log_info->info_ofs, log_info->buff_ofs, log_info->buff_size);
memcpy_fromio(&r_pos, &info->r_pos, sizeof(r_pos));
memcpy_fromio(&w_pos, &info->w_pos, sizeof(w_pos));
n += scnprintf(buf + n, size - n, "r_pos:%u, w_pos:%u\n",
r_pos, w_pos);
return n;
}
@@ -0,0 +1,42 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __ADSP_LOGGER_H__
#define __ADSP_LOGGER_H__
#define ADSP_LOGGER_UT (1)
struct log_ctrl_s { /* ap used */
unsigned int inited;
struct mutex lock;
struct delayed_work work;
void *priv;
};
struct log_info_s {
unsigned int base;
unsigned int size;
unsigned int enable;
unsigned int info_ofs;
unsigned int buff_ofs;
unsigned int buff_size;
};
struct buffer_info_s {
unsigned int r_pos;
unsigned char resv1[124]; /* dummy bytes for 128-byte align */
unsigned int w_pos;
unsigned char resv2[124]; /* dummy bytes for 128-byte align */
};
struct log_ctrl_s *adsp_logger_init(int mem_id, void (*work_cb)(struct work_struct *ws));
unsigned int adsp_log_poll(struct log_ctrl_s *ctrl);
ssize_t adsp_log_read(struct log_ctrl_s *ctrl, char __user *userbuf,
size_t len);
ssize_t adsp_log_enable(struct log_ctrl_s *ctrl, int cid, u32 enable);
ssize_t adsp_dump_log_state(struct log_ctrl_s *ctrl, char *buffer, int size);
#endif /* __ADSP_LOGGER_H__ */
@@ -0,0 +1,117 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/io.h>
#include "adsp_semaphore.h"
#include "adsp_core.h"
DEFINE_SPINLOCK(adsp_sem_spinlock);
struct adsp_sem_info sem_info;
int adsp_sem_init(unsigned int way_bits,
unsigned int ctrl_bit,
unsigned int timeout,
void __iomem *reg)
{
if (ctrl_bit >= way_bits || !reg)
return ADSP_ERROR;
sem_info.way_bits = way_bits;
sem_info.ctrl_bit = ctrl_bit;
sem_info.reg = reg;
if (!timeout)
timeout = 1;
sem_info.timeout = timeout;
return ADSP_OK;
}
static void set_clr_adsp_sem_flag(unsigned int flags)
{
writel((1 << flags), sem_info.reg);
}
static unsigned int get_adsp_sem_flag(unsigned int flags)
{
return (readl(sem_info.reg) >> flags) & 0x1;
}
/*
* acquire a hardware semaphore
* @param flag: semaphore id
* return ADSP_OK: get sema success
* ADSP_ERROR: get sema fail
*/
int get_adsp_semaphore(unsigned int flags)
{
enum adsp_status ret = ADSP_SEMAPHORE_BUSY;
unsigned int cnt;
unsigned long spin_flags;
/* return ADSP_ERROR to prevent from access when adsp not ready.
* Both adsp enter suspend/resume at the same time.
*/
if (!is_adsp_system_running()) {
pr_notice("%s: adsp not enabled.", __func__);
return ADSP_ERROR;
}
/* spinlock context safe*/
spin_lock_irqsave(&adsp_sem_spinlock, spin_flags);
flags = flags * sem_info.way_bits
+ sem_info.ctrl_bit;
if (get_adsp_sem_flag(flags) == 0) {
cnt = sem_info.timeout;
while (cnt-- > 0) {
set_clr_adsp_sem_flag(flags);
if (get_adsp_sem_flag(flags) == 1) {
ret = ADSP_OK;
break;
}
}
}
spin_unlock_irqrestore(&adsp_sem_spinlock, spin_flags);
return ret;
}
/*
* release a hardware semaphore
* @param flag: semaphore id
* return ADSP_OK: release sema success
* ADSP_ERROR: release sema fail
*/
int release_adsp_semaphore(unsigned int flags)
{
enum adsp_status ret = ADSP_SEMAPHORE_BUSY;
unsigned long spin_flags;
if (!is_adsp_system_running()) {
pr_notice("%s: adsp not enabled.", __func__);
return ADSP_ERROR;
}
/* spinlock context safe*/
spin_lock_irqsave(&adsp_sem_spinlock, spin_flags);
flags = flags * sem_info.way_bits
+ sem_info.ctrl_bit;
if (get_adsp_sem_flag(flags) == 1) {
set_clr_adsp_sem_flag(flags);
ret = ADSP_OK;
}
spin_unlock_irqrestore(&adsp_sem_spinlock, spin_flags);
return ret;
}
@@ -0,0 +1,21 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __ADSP_SEMAPHORE_H
#define __ADSP_SEMAPHORE_H
struct adsp_sem_info {
unsigned int way_bits;
unsigned int ctrl_bit;
unsigned int timeout;
void __iomem *reg;
};
int adsp_sem_init(unsigned int way_bits,
unsigned int ctrl_bit,
unsigned int timeout,
void __iomem *reg);
#endif
@@ -0,0 +1,127 @@
// SPDX-License-Identifier: GPL-2.0
//
// adsp_timesync.c-- Mediatek ADSP timesync
//
// Copyright (c) 2020 MediaTek Inc.
// Author: Celine Liu <Celine.liu@mediatek.com>
#include <linux/clocksource.h>
#include <linux/sched/clock.h>
#include <linux/suspend.h>
#include <linux/timex.h>
#include <linux/types.h>
#include <linux/io.h>
#include <asm/arch_timer.h>
#include <asm/timex.h>
#include "adsp_core.h"
#include "adsp_platform.h"
#include "adsp_timesync.h"
struct timesync_info_s {
u32 tick_h;
u32 tick_l;
u32 ts_h;
u32 ts_l;
u32 freeze;
u32 version;
};
struct timesync_control_s {
struct timecounter tc;
struct cyclecounter cc;
struct hrtimer timer;
u32 period_ms;
struct timesync_info_s infos;
};
static struct timesync_control_s timesync_ctrl;
static u64 adsp_ts_tick_read(const struct cyclecounter *cc)
{
return arch_timer_read_counter();
}
static void adsp_timesync_update(u32 fz)
{
u64 tick, ts;
struct timesync_info_s *infos = &timesync_ctrl.infos;
int ret = 0;
ts = timecounter_read(&timesync_ctrl.tc);
tick = timesync_ctrl.tc.cycle_last;
infos->tick_h = (tick >> 32) & 0xFFFFFFFF;
infos->tick_l = tick & 0xFFFFFFFF;
infos->ts_h = (ts >> 32) & 0xFFFFFFFF;
infos->ts_l = ts & 0xFFFFFFFF;
infos->freeze = fz;
infos->version++;
if (is_adsp_system_running()) {
ret = adsp_copy_to_sharedmem(get_adsp_core_by_id(ADSP_A_ID),
ADSP_SHAREDMEM_TIMESYNC,
infos, sizeof(*infos));
}
}
static enum hrtimer_restart adsp_timesync_refresh(struct hrtimer *hrt)
{
adsp_timesync_update(APTIME_UNFREEZE);
hrtimer_forward_now(hrt, ms_to_ktime(timesync_ctrl.period_ms));
return HRTIMER_RESTART;
}
int adsp_timesync_init(void)
{
u32 multiplier, shifter;
/* init cyclecounter mult and shift as sched_clock */
clocks_calc_mult_shift(&multiplier,
&shifter,
arch_timer_get_cntfrq(),
NSEC_PER_SEC, 3600);
timesync_ctrl.cc.read = adsp_ts_tick_read;
timesync_ctrl.cc.mask = CLOCKSOURCE_MASK(56);
timesync_ctrl.cc.mult = multiplier;
timesync_ctrl.cc.shift = shifter;
/* init time counter */
timecounter_init(&timesync_ctrl.tc,
&timesync_ctrl.cc,
sched_clock());
/* init refresh hr_timer */
hrtimer_init(&timesync_ctrl.timer,
CLOCK_MONOTONIC, HRTIMER_MODE_REL);
timesync_ctrl.timer.function = adsp_timesync_refresh;
timesync_ctrl.period_ms = TIMESYNC_WRAP_TIME_MS;
pr_info("%s(), done", __func__);
return 0;
}
void adsp_timesync_suspend(u32 fz)
{
hrtimer_cancel(&timesync_ctrl.timer);
/* update after suspend timer */
adsp_timesync_update(fz);
}
void adsp_timesync_resume(void)
{
/* re-init timecounter because sched_clock will be stopped during
* suspend but arch timer counter is not, so we need to update
* start time after resume
*/
timecounter_init(&timesync_ctrl.tc,
&timesync_ctrl.cc,
sched_clock());
/* kick start the timer immediately */
hrtimer_start(&timesync_ctrl.timer, 0, HRTIMER_MODE_REL);
}
@@ -0,0 +1,25 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
* Author: Celine Liu <Celine.liu@mediatek.com>
*/
#ifndef _ADSP_TIMESYNC_H_
#define _ADSP_TIMESYNC_H_
/* sched_clock wrap time is 4398 seconds for arm arch timer
* applying a period less than it for tinysys timesync
*/
#define TIMESYNC_WRAP_TIME_MS (4390 * 1000)
enum {
APTIME_UNFREEZE = 0,
APTIME_FREEZE = 1,
};
void adsp_timesync_suspend(u32 fz);
void adsp_timesync_resume(void);
int adsp_timesync_init(void);
#endif // _ADSP_TIMESYNC_H_
@@ -0,0 +1,19 @@
SCP_VERSION := common_v1
SCP_VERSION_PATH := ../$(SCP_VERSION)
obj-y += $(SCP_VERSION_PATH)/
obj-y += adsp_feature_table.o
obj-y += adsp_awake.o
obj-y += adsp_dvfs.o
obj-y += adsp_plat.o
obj-y += adsp_clk.o
obj-y += adsp_bus_monitor.o
obj-y += adsp_reserved_mem.o
ccflags-y += -I$(srctree)/drivers/misc/mediatek/adsp/common_v1
ccflags-y += -I$(srctree)/drivers/misc/mediatek/audio_ipi/common_v1/framework
ccflags-y += -I$(srctree)/drivers/misc/mediatek/include/mt-plat/$(CONFIG_MTK_PLATFORM)/include/mach
ccflags-y += -I$(srctree)/drivers/misc/mediatek/base/power/include/
ccflags-y += -I$(srctree)/drivers/misc/mediatek/emi/submodule
ccflags-y += -I$(srctree)/drivers/misc/mediatek/emi/$(CONFIG_MTK_PLATFORM)
@@ -0,0 +1,464 @@
// SPDX-License-Identifier: GPL-2.0
//
// adsp_awake.c -- Mediatek ADSP awake control
//
// Copyright (c) 2018 MediaTek Inc.
// Author: Scholar Chang <scholar.chang@mediatek.com>
#include <linux/module.h> /* needed by all modules */
#include <linux/init.h> /* needed by module macros */
#include <linux/fs.h> /* needed by file_operations* */
#include <linux/miscdevice.h> /* needed by miscdevice* */
#include <linux/sysfs.h>
#include <linux/platform_device.h>
#include <linux/device.h> /* needed by device_* */
#include <linux/vmalloc.h> /* needed by vmalloc */
#include <linux/uaccess.h> /* needed by copy_to_user */
#include <linux/fs.h> /* needed by file_operations* */
#include <linux/slab.h> /* needed by kmalloc */
#include <linux/poll.h> /* needed by poll */
#include <linux/mutex.h>
#include <linux/sched.h>
#include <linux/interrupt.h>
#include <linux/suspend.h>
#include <linux/timer.h>
#include <linux/notifier.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/of_irq.h>
#include <linux/of_fdt.h>
#include <linux/ioport.h>
#include <linux/pm_wakeup.h>
#include <linux/io.h>
#include <linux/errno.h>
#include <mt-plat/sync_write.h>
#include <mt-plat/aee.h>
#include <linux/delay.h>
#include "adsp_feature_define.h"
#include "adsp_ipi.h"
#include "adsp_helper.h"
#include "adsp_excep.h"
#include "adsp_dvfs.h"
#define AP_AWAKE_STATE_NORMAL (0)
#define AP_AWAKE_STATE_FORCE_LOCK (1)
#define AP_AWAKE_STATE_FORCE_UNLOCK (2)
#define ADSP_SW_INT1_BIT (0x1 << ADSP_SW_INT1)
#define AP_AWAKE_LOCK_MASK (0x1 << AP_AWAKE_LOCK_BIT)
#define AP_AWAKE_UNLOCK_MASK (0x1 << AP_AWAKE_UNLOCK_BIT)
#define AP_AWAKE_DUMP_MASK (0x1 << AP_AWAKE_DUMP_BIT)
#define AP_AWAKE_UPDATE_MASK (0x1 << AP_AWAKE_UPDATE_BIT)
#define AP_AWAKE_STATE_MASK (0x3 << AP_AWAKE_STATE_BIT)
#define ADSPPLL_UNLOCK_MASK (0x1 << ADSPPLL_UNLOCK_BIT)
#define REG_AP_AWAKE (readl(ADSP_A_AP_AWAKE))
#define CHECK_AP_AWAKE_MASK(mask) ((REG_AP_AWAKE & mask) == 0)
#define GET_AP_AWAKE_STATE() \
((REG_AP_AWAKE & AP_AWAKE_STATE_MASK) >> AP_AWAKE_STATE_BIT)
#define SET_AP_AWAKE_STATE(reg_val, state) \
((reg_val & ~AP_AWAKE_STATE_MASK) | (state << AP_AWAKE_STATE_BIT))
struct mutex adsp_awake_mutexs[ADSP_CORE_TOTAL];
int adsp_awake_counts[ADSP_CORE_TOTAL];
DEFINE_SPINLOCK(adsp_awake_spinlock);
static int adsp_awake_send_swint (int ret, uint32_t reg_val, uint32_t mask)
{
writel(reg_val | mask, ADSP_A_AP_AWAKE);
writel(ADSP_SW_INT1_BIT, ADSP_SWINT_REG);
{ /* Wait for ADSP response */
uint32_t cnt = 0;
do {
if (CHECK_AP_AWAKE_MASK(mask)) {
ret = 0;
break;
}
udelay(10);
cnt++;
} while (cnt != ADSP_AWAKE_TIMEOUT);
}
return ret;
}
/*
* acquire adsp lock flag, keep adsp awake
* @param adsp_id: adsp core id
* return 0 : get lock success
* non-0 : get lock fail
*/
int adsp_awake_lock(enum adsp_core_id adsp_id)
{
if (adsp_id >= ADSP_CORE_TOTAL) {
pr_err("%s() ID %d >= CORE TOTAL", __func__, adsp_id);
return -EINVAL;
}
if (is_adsp_ready(adsp_id) == 0) {
char *p_id = adsp_core_ids[adsp_id];
pr_warn("%s() %s not enabled\n", __func__, p_id);
return -1;
}
{ /* Protected by spin lock */
int *p_count = (int *)&adsp_awake_counts[adsp_id];
unsigned long spin_flags = 0;
spinlock_t *p_spin = &adsp_awake_spinlock;
spin_lock_irqsave(p_spin, spin_flags);
if (*p_count > 0) {
*p_count += 1;
spin_unlock_irqrestore(p_spin, spin_flags);
return 0;
}
spin_unlock_irqrestore(p_spin, spin_flags);
}
{ /* Protected by mutex lock & spin lock */
int ret = -1;
int *p_count = (int *)&adsp_awake_counts[adsp_id];
unsigned long spin_flags = 0;
spinlock_t *p_spin = &adsp_awake_spinlock;
struct mutex *p_mutex = &adsp_awake_mutexs[adsp_id];
uint32_t reg_val, mask;
mutex_lock(p_mutex);
spin_lock_irqsave(p_spin, spin_flags);
reg_val = REG_AP_AWAKE;
mask = AP_AWAKE_LOCK_MASK;
ret = adsp_awake_send_swint (ret, reg_val, mask);
if (ret != -1)
*p_count += 1;
spin_unlock_irqrestore(p_spin, spin_flags);
if (ret == -1) {
char *p_id = adsp_core_ids[adsp_id];
pr_err("%s() %s fail\n", __func__, p_id);
WARN_ON(1);
}
mutex_unlock(p_mutex);
return ret;
}
}
EXPORT_SYMBOL_GPL(adsp_awake_lock);
/*
* release adsp awake lock flag
* @param adsp_id: adsp core id
* return 0 : release lock success
* non-0 : release lock fail
*/
int adsp_awake_unlock(enum adsp_core_id adsp_id)
{
if (adsp_id >= ADSP_CORE_TOTAL) {
pr_err("%s() ID %d >= CORE TOTAL", __func__, adsp_id);
return -EINVAL;
}
if (is_adsp_ready(adsp_id) == 0) {
char *p_id = adsp_core_ids[adsp_id];
pr_warn("%s() %s not enabled\n", __func__, p_id);
return -1;
}
{ /* Protected by spin lock */
int *p_count = (int *)&adsp_awake_counts[adsp_id];
unsigned long spin_flags = 0;
spinlock_t *p_spin = &adsp_awake_spinlock;
spin_lock_irqsave(p_spin, spin_flags);
if (*p_count > 1) {
*p_count -= 1;
spin_unlock_irqrestore(p_spin, spin_flags);
return 0;
}
spin_unlock_irqrestore(p_spin, spin_flags);
}
{ /* Protected by mutex lock & spin lock */
int ret = -1;
int *p_count = (int *)&adsp_awake_counts[adsp_id];
unsigned long spin_flags = 0;
spinlock_t *p_spin = &adsp_awake_spinlock;
struct mutex *p_mutex = &adsp_awake_mutexs[adsp_id];
uint32_t reg_val, mask;
mutex_lock(p_mutex);
spin_lock_irqsave(p_spin, spin_flags);
reg_val = REG_AP_AWAKE;
mask = AP_AWAKE_UNLOCK_MASK;
ret = adsp_awake_send_swint (ret, reg_val, mask);
if (ret != -1)
*p_count -= 1;
spin_unlock_irqrestore(p_spin, spin_flags);
if (*p_count < 0)
pr_err("%s() count = %d NOT SYNC\n", __func__,
*p_count);
mutex_unlock(p_mutex);
return ret;
}
}
EXPORT_SYMBOL_GPL(adsp_awake_unlock);
void adsp_awake_init(void)
{
uint32_t i = 0;
for (i = 0; i < ADSP_CORE_TOTAL; i++)
adsp_awake_counts[i] = 0;
for (i = 0; i < ADSP_CORE_TOTAL; i++)
mutex_init(&adsp_awake_mutexs[i]);
}
/*
* lock/unlock switch of adsppll clock
* @param adsp_id: adsp core id
* unlock: if unlock adsppll
* return 0 : send command success
* non-0 : adsp is not ready
*/
int adsp_awake_unlock_adsppll(enum adsp_core_id adsp_id, uint32_t unlock)
{
if (adsp_id >= ADSP_CORE_TOTAL) {
pr_err("%s() ID %d >= CORE TOTAL", __func__, adsp_id);
return -EINVAL;
}
if (is_adsp_ready(adsp_id) == 0) {
char *p_id = adsp_core_ids[adsp_id];
pr_warn("%s() %s not enabled\n", __func__, p_id);
return -1;
}
{ /* Protected by mutex lock & spin lock */
int ret = 0;
unsigned long spin_flags = 0;
spinlock_t *p_spin = &adsp_awake_spinlock;
struct mutex *p_mutex = &adsp_awake_mutexs[adsp_id];
uint32_t reg_val;
mutex_lock(p_mutex);
spin_lock_irqsave(p_spin, spin_flags);
reg_val = REG_AP_AWAKE;
if (unlock)
reg_val |= ADSPPLL_UNLOCK_MASK;
else
reg_val &= ~ADSPPLL_UNLOCK_MASK;
writel(reg_val, ADSP_A_AP_AWAKE);
writel(ADSP_SW_INT1_BIT, ADSP_SWINT_REG);
spin_unlock_irqrestore(p_spin, spin_flags);
mutex_unlock(p_mutex);
return ret;
}
}
EXPORT_SYMBOL_GPL(adsp_awake_unlock_adsppll);
/*
* dump adsp lock list in adsp log
* @param adsp_id: adsp core id
* return 0 : dump list success
* non-0 : dump list fail
*/
int adsp_awake_dump_list(enum adsp_core_id adsp_id)
{
if (adsp_id >= ADSP_CORE_TOTAL) {
pr_err("%s() ID %d >= CORE TOTAL", __func__, adsp_id);
return -EINVAL;
}
if (is_adsp_ready(adsp_id) == 0) {
char *p_id = adsp_core_ids[adsp_id];
pr_warn("%s() %s not enabled\n", __func__, p_id);
return -1;
}
{ /* Protected by mutex lock & spin lock */
int ret = -1;
unsigned long spin_flags = 0;
spinlock_t *p_spin = &adsp_awake_spinlock;
struct mutex *p_mutex = &adsp_awake_mutexs[adsp_id];
uint32_t reg_val, mask;
mutex_lock(p_mutex);
spin_lock_irqsave(p_spin, spin_flags);
reg_val = REG_AP_AWAKE;
mask = AP_AWAKE_DUMP_MASK;
ret = adsp_awake_send_swint (ret, reg_val, mask);
spin_unlock_irqrestore(p_spin, spin_flags);
if (ret == -1) {
char *p_id = adsp_core_ids[adsp_id];
pr_err("%s() %s fail\n", __func__, p_id);
WARN_ON(1);
}
mutex_unlock(p_mutex);
return ret;
}
}
EXPORT_SYMBOL_GPL(adsp_awake_dump_list);
static int adsp_awake_set_state(enum adsp_core_id adsp_id, uint32_t next_state)
{
if (adsp_id >= ADSP_CORE_TOTAL) {
pr_err("%s() ID %d >= ADSP_CORE_TOTAL", __func__, adsp_id);
return -EINVAL;
}
if (is_adsp_ready(adsp_id) == 0) {
char *p_id = adsp_core_ids[adsp_id];
pr_warn("%s() %s not enabled\n", __func__, p_id);
return -1;
}
{ /* Protected by spin lock */
unsigned long spin_flags = 0;
spinlock_t *p_spin = &adsp_awake_spinlock;
uint32_t curr_state = GET_AP_AWAKE_STATE();
spin_lock_irqsave(p_spin, spin_flags);
if (curr_state == next_state) {
spin_unlock_irqrestore(p_spin, spin_flags);
return 0;
}
spin_unlock_irqrestore(p_spin, spin_flags);
}
{ /* Protected by mutex lock & spin lock */
int ret = -1;
unsigned long spin_flags = 0;
spinlock_t *p_spin = &adsp_awake_spinlock;
struct mutex *p_mutex = &adsp_awake_mutexs[adsp_id];
uint32_t reg_val, mask;
mutex_lock(p_mutex);
spin_lock_irqsave(p_spin, spin_flags);
reg_val = REG_AP_AWAKE;
mask = AP_AWAKE_UPDATE_MASK;
reg_val = SET_AP_AWAKE_STATE(reg_val, next_state);
ret = adsp_awake_send_swint (ret, reg_val, mask);
spin_unlock_irqrestore(p_spin, spin_flags);
if (ret == -1) {
char *p_id = adsp_core_ids[adsp_id];
pr_err("%s() %s fail\n", __func__, p_id);
WARN_ON(1);
}
mutex_unlock(p_mutex);
return ret;
}
}
/*
* force adsp lock, keep adsp awake
* @param adsp_id: adsp core id
* return 0 : force lock success
* non-0 : force lock fail
*/
int adsp_awake_force_lock(enum adsp_core_id adsp_id)
{
return adsp_awake_set_state(adsp_id, AP_AWAKE_STATE_FORCE_LOCK);
}
EXPORT_SYMBOL_GPL(adsp_awake_force_lock);
/*
* force adsp unlock
* @param adsp_id: adsp core id
* return 0 : force unlock success
* non-0 : force unlock fail
*/
int adsp_awake_force_unlock(enum adsp_core_id adsp_id)
{
return adsp_awake_set_state(adsp_id, AP_AWAKE_STATE_FORCE_UNLOCK);
}
EXPORT_SYMBOL_GPL(adsp_awake_force_unlock);
/*
* set adsp normal
* @param adsp_id: adsp core id
* return 0 : set normal success
* non-0 : set normal fail
*/
int adsp_awake_set_normal(enum adsp_core_id adsp_id)
{
return adsp_awake_set_state(adsp_id, AP_AWAKE_STATE_NORMAL);
}
EXPORT_SYMBOL_GPL(adsp_awake_set_normal);
static inline ssize_t adsp_awake_force_lock_show(struct device *kobj,
struct device_attribute *att,
char *buf)
{
if (is_adsp_ready(ADSP_A_ID) == 1) {
adsp_awake_force_lock(ADSP_A_ID);
return scnprintf(buf, PAGE_SIZE, "ADSP awake force lock\n");
} else
return scnprintf(buf, PAGE_SIZE, "ADSP is not ready\n");
}
DEVICE_ATTR_RO(adsp_awake_force_lock);
static inline ssize_t adsp_awake_force_unlock_show(struct device *kobj,
struct device_attribute *att,
char *buf)
{
if (is_adsp_ready(ADSP_A_ID) == 1) {
adsp_awake_force_unlock(ADSP_A_ID);
return scnprintf(buf, PAGE_SIZE, "ADSP awake force unlock\n");
} else
return scnprintf(buf, PAGE_SIZE, "ADSP is not ready\n");
}
DEVICE_ATTR_RO(adsp_awake_force_unlock);
static inline ssize_t adsp_awake_set_normal_show(struct device *kobj,
struct device_attribute *att,
char *buf)
{
if (is_adsp_ready(ADSP_A_ID) == 1) {
adsp_awake_set_normal(ADSP_A_ID);
return scnprintf(buf, PAGE_SIZE, "ADSP awake set normal\n");
} else
return scnprintf(buf, PAGE_SIZE, "ADSP is not ready\n");
}
DEVICE_ATTR_RO(adsp_awake_set_normal);
static inline ssize_t adsp_awake_dump_list_show(struct device *kobj,
struct device_attribute *att,
char *buf)
{
if (is_adsp_ready(ADSP_A_ID) == 1) {
adsp_awake_dump_list(ADSP_A_ID);
return scnprintf(buf, PAGE_SIZE, "ADSP awake dump list\n");
} else
return scnprintf(buf, PAGE_SIZE, "ADSP is not ready\n");
}
DEVICE_ATTR_RO(adsp_awake_dump_list);
static inline ssize_t adsp_awake_lock_show(struct device *kobj,
struct device_attribute *att,
char *buf)
{
if (is_adsp_ready(ADSP_A_ID) == 1) {
adsp_awake_lock(ADSP_A_ID);
return scnprintf(buf, PAGE_SIZE, "ADSP awake lock\n");
} else
return scnprintf(buf, PAGE_SIZE, "ADSP is not ready\n");
}
DEVICE_ATTR_RO(adsp_awake_lock);
static inline ssize_t adsp_awake_unlock_show(struct device *kobj,
struct device_attribute *att,
char *buf)
{
if (is_adsp_ready(ADSP_A_ID) == 1) {
adsp_awake_unlock(ADSP_A_ID);
return scnprintf(buf, PAGE_SIZE, "ADSP awake unlock\n");
} else
return scnprintf(buf, PAGE_SIZE, "ADSP is not ready\n");
}
DEVICE_ATTR_RO(adsp_awake_unlock);
static struct attribute *adsp_awake_attrs[] = {
&dev_attr_adsp_awake_force_lock.attr,
&dev_attr_adsp_awake_force_unlock.attr,
&dev_attr_adsp_awake_set_normal.attr,
&dev_attr_adsp_awake_dump_list.attr,
&dev_attr_adsp_awake_lock.attr,
&dev_attr_adsp_awake_unlock.attr,
NULL,
};
struct attribute_group adsp_awake_attr_group = {
.attrs = adsp_awake_attrs,
};
@@ -0,0 +1,77 @@
// SPDX-License-Identifier: GPL-2.0
//
// adsp_bus_monitor.c -- Mediatek ADSP bus monitor
//
// Copyright (c) 2018 MediaTek Inc.
// Author: Chien-Wei Hsu <chien-wei.hsu@mediatek.com>
#include <linux/io.h>
#include "adsp_helper.h"
#include "adsp_bus_monitor.h"
/**
* TIMEOUT_VALUE = value * unit(15 cycle count) / clk_src
*/
#define BUS_MON_STAGE1_TIMEOUT_VALUE (0x01DA0A2B) /* 1.00 sec @ 466MHz */
#define BUS_MON_STAGE2_TIMEOUT_VALUE (0x03B41456) /* 2.00 sec @ 466MHz */
#define ADSP_BUS_MON_STATE (ADSP_BUS_MON_BACKUP_BASE)
#define ADSP_BUS_MON_1ST_STAGE_BASE (ADSP_BUS_MON_BACKUP_BASE + sizeof(u32))
#define ADSP_BUS_MON_2ND_STAGE_BASE (ADSP_BUS_MON_1ST_STAGE_BASE + \
sizeof(struct bus_monitor_cblk))
#define ADSP_BUS_MON_BACKUP_SIZE (sizeof(u32) + \
2 * sizeof(struct bus_monitor_cblk))
int adsp_bus_monitor_init(void)
{
/* Clear bus monitor register backup in DTCM */
memset_io((void *)ADSP_BUS_MON_BACKUP_BASE, 0,
(size_t)ADSP_BUS_MON_BACKUP_SIZE);
/* initialize bus monitor */
writel(0xacce55, ADSP_BUS_DBG_EN_LOCK);
writel(0x00011080, ADSP_BUS_DBG_CON); /* reset bus tracker */
writel(BUS_MON_STAGE1_TIMEOUT_VALUE, ADSP_BUS_DBG_TIMER_CON0);
writel(BUS_MON_STAGE2_TIMEOUT_VALUE, ADSP_BUS_DBG_TIMER_CON1);
writel(0x0, ADSP_BUS_DBG_WP);
writel(0x0, ADSP_BUS_DBG_WP_MASK);
writel(0x00002037, ADSP_BUS_DBG_CON); /* timeout control */
writel(STAGE_RUN, ADSP_BUS_MON_STATE);
return 0;
}
bool is_adsp_bus_monitor_alert(void)
{
return readl(ADSP_BUS_MON_STATE) > STAGE_RUN;
}
static void adsp_bus_monitor_stage_info(void *addr)
{
int i = 0;
struct bus_monitor_cblk cblk;
memcpy_fromio(&cblk, addr, sizeof(struct bus_monitor_cblk));
pr_info("BUS_DBG_CON = 0x%08x", cblk.ctrl);
pr_info("TIMER_CON0 = 0x%08x, TIMER_CON01 = 0x%08x",
cblk.timer_ctrl[0], cblk.timer_ctrl[1]);
for (i = 0; i < 8; i++) {
if (!cblk.r_tracks[i] && !cblk.w_tracks[i])
continue;
pr_info("R_TRACK[%d] = 0x%08x, W_TRACK[%d] = 0x%08x",
i, cblk.r_tracks[i],
i, cblk.w_tracks[i]);
}
}
void adsp_bus_monitor_dump(void)
{
pr_info("%s(), BUS_MON_1ST_STAGE BACKUP", __func__);
adsp_bus_monitor_stage_info((void *)ADSP_BUS_MON_1ST_STAGE_BASE);
pr_info("%s(), BUS_MON_2ST_STAGE BACKUP", __func__);
adsp_bus_monitor_stage_info((void *)ADSP_BUS_MON_2ND_STAGE_BASE);
}
@@ -0,0 +1,48 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* adsp_bus_monitor.h -- Mediatek ADSP bus monitor
*
* Copyright (c) 2018 MediaTek Inc.
* Author: Chien-Wei Hsu <chien-wei.hsu@mediatek.com>
*/
#ifndef __ADSP_BUS_MONITOR_H__
#define __ADSP_BUS_MONITOR_H__
#include "adsp_reg.h"
/* bus monitor registers */
#define ADSP_BUS_DBG_CON (ADSP_BUS_MON_BASE + 0x0000)
#define ADSP_BUS_DBG_TIMER_CON0 (ADSP_BUS_MON_BASE + 0x0004)
#define ADSP_BUS_DBG_TIMER_CON1 (ADSP_BUS_MON_BASE + 0x0008)
#define ADSP_BUS_DBG_TIMER0 (ADSP_BUS_MON_BASE + 0x000C)
#define ADSP_BUS_DBG_TIMER1 (ADSP_BUS_MON_BASE + 0x0010)
#define ADSP_BUS_DBG_WP (ADSP_BUS_MON_BASE + 0x0014)
#define ADSP_BUS_DBG_WP_MASK (ADSP_BUS_MON_BASE + 0x0018)
#define ADSP_BUS_DBG_EN_LOCK (ADSP_BUS_MON_BASE + 0x0024)
/* bus monitor enum */
enum bus_monitor_stage {
STAGE_OFF = 0,
STAGE_RUN = 1,
STAGE_1ST = 2,
STAGE_2ND = 3,
};
/* bus monitor structure */
struct bus_monitor_cblk { /* hw related */
u32 ctrl;
u32 timer_ctrl[2];
u32 timer_dbg[2];
u32 watch_point_addr;
u32 watch_point_mask;
u32 r_tracks[8]; /* read tracker 8 channel in hw */
u32 w_tracks[8]; /* write tracker 8 channel in hw */
};
/* bus monitor methods, be care all of them need adsp clk on */
int adsp_bus_monitor_init(void);
bool is_adsp_bus_monitor_alert(void);
void adsp_bus_monitor_dump(void);
#endif
@@ -0,0 +1,149 @@
// SPDX-License-Identifier: GPL-2.0
//
// adsp_clk.c-- Mediatek ADSP clock control
//
// Copyright (c) 2018 MediaTek Inc.
// Author: Celine Liu <Celine.liu@mediatek.com>
#include <linux/clk.h>
#include "adsp_clk.h"
#include "adsp_helper.h"
struct adsp_clock_attr {
const char *name;
bool clk_prepare;
bool clk_status;
struct clk *clock;
};
static struct adsp_clock_attr adsp_clks[ADSP_CLK_NUM] = {
[CLK_ADSP_INFRA] = {"clk_adsp_infra", false, false, NULL},
[CLK_TOP_ADSP_SEL] = {"clk_top_adsp_sel", false, false, NULL},
[CLK_ADSP_CLK26M] = {"clk_adsp_clk26m", false, false, NULL},
[CLK_TOP_MMPLL_D4] = {"clk_top_mmpll_d4", false, false, NULL},
[CLK_TOP_ADSPPLL_D4] = {"clk_top_adsppll_d4", false, false, NULL},
[CLK_TOP_ADSPPLL_D6] = {"clk_top_adsppll_d6", false, false, NULL},
};
static uint32_t adsp_clock_count;
DEFINE_SPINLOCK(adsp_clock_spinlock);
int adsp_set_top_mux(enum adsp_clk clk)
{
int ret = 0;
struct clk *parent;
pr_debug("%s(%x)\n", __func__, clk);
switch (clk) {
case CLK_ADSP_CLK26M:
parent = adsp_clks[CLK_ADSP_CLK26M].clock;
break;
case CLK_TOP_MMPLL_D4:
parent = adsp_clks[CLK_TOP_MMPLL_D4].clock;
break;
case CLK_TOP_ADSPPLL_D4:
parent = adsp_clks[CLK_TOP_ADSPPLL_D4].clock;
break;
case CLK_TOP_ADSPPLL_D6:
parent = adsp_clks[CLK_TOP_ADSPPLL_D6].clock;
break;
default:
parent = adsp_clks[CLK_ADSP_CLK26M].clock;
break;
}
ret = clk_set_parent(adsp_clks[CLK_TOP_ADSP_SEL].clock, parent);
if (IS_ERR(&ret))
pr_err("[ADSP] %s clk_set_parent(clk_top_adsp_sel-%x) fail %d\n",
__func__, clk, ret);
return ret;
}
/* clock init */
int adsp_clk_device_probe(void *dev)
{
size_t i;
int ret = 0;
for (i = 0; i < ARRAY_SIZE(adsp_clks); i++) {
adsp_clks[i].clock = devm_clk_get(dev, adsp_clks[i].name);
if (IS_ERR(adsp_clks[i].clock)) {
ret = PTR_ERR(adsp_clks[i].clock);
pr_err("%s devm_clk_get %s fail %d\n", __func__,
adsp_clks[i].name, ret);
} else {
adsp_clks[i].clk_status = true;
}
}
if (ret)
return ret;
for (i = 0; i < ARRAY_SIZE(adsp_clks); i++) {
if (adsp_clks[i].clk_status) {
ret = clk_prepare(adsp_clks[i].clock);
if (ret) {
pr_err("%s clk_prepare %s fail %d\n", __func__,
adsp_clks[i].name, ret);
} else {
adsp_clks[i].clk_prepare = true;
}
}
}
return ret;
}
/* clock deinit */
void adsp_clk_device_remove(void *dev)
{
size_t i;
pr_debug("%s\n", __func__);
for (i = 0; i < ARRAY_SIZE(adsp_clks); i++) {
if (adsp_clks[i].clock && !IS_ERR(adsp_clks[i].clock) &&
adsp_clks[i].clk_prepare) {
clk_unprepare(adsp_clks[i].clock);
adsp_clks[i].clk_prepare = false;
}
}
}
int adsp_enable_clock(void)
{
int ret = 0;
unsigned long spin_flags;
if (adsp_clks[CLK_ADSP_INFRA].clk_prepare) {
spin_lock_irqsave(&adsp_clock_spinlock, spin_flags);
if (++adsp_clock_count == 1)
/* unable to access adsp sram before set way_en to 1 */
adsp_way_en_ctrl(1);
ret = clk_enable(adsp_clks[CLK_ADSP_INFRA].clock);
if (IS_ERR(&ret))
pr_err("%s(), clk_enable %s fail, ret %d\n", __func__,
adsp_clks[CLK_ADSP_INFRA].name, ret);
spin_unlock_irqrestore(&adsp_clock_spinlock, spin_flags);
} else {
pr_err("%s(), clk %s, not prepared\n",
__func__, adsp_clks[CLK_ADSP_INFRA].name);
ret = -EINVAL;
}
return ret;
}
void adsp_disable_clock(void)
{
unsigned long spin_flags;
if (adsp_clks[CLK_ADSP_INFRA].clk_prepare) {
spin_lock_irqsave(&adsp_clock_spinlock, spin_flags);
if (--adsp_clock_count == 0)
/* unable to access adsp sram before set way_en to 1 */
adsp_way_en_ctrl(0);
clk_disable(adsp_clks[CLK_ADSP_INFRA].clock);
spin_unlock_irqrestore(&adsp_clock_spinlock, spin_flags);
}
}
@@ -0,0 +1,28 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* adsp_clk.h -- Mediatek ADSP clock control
*
* Copyright (c) 2018 MediaTek Inc.
* Author: Celine Liu <Celine.liu@mediatek.com>
*/
#ifndef ADSP_CLK_H
#define ADSP_CLK_H
enum adsp_clk {
CLK_ADSP_INFRA,
CLK_TOP_ADSP_SEL,
CLK_ADSP_CLK26M,
CLK_TOP_MMPLL_D4,
CLK_TOP_ADSPPLL_D4,
CLK_TOP_ADSPPLL_D6,
ADSP_CLK_NUM
};
int adsp_set_top_mux(enum adsp_clk clk);
int adsp_enable_clock(void);
void adsp_disable_clock(void);
int adsp_clk_device_probe(void *dev);
void adsp_clk_device_remove(void *dev);
#endif /* ADSP_CLK_H */
@@ -0,0 +1,740 @@
// SPDX-License-Identifier: GPL-2.0
//
// adsp_dvfs.c -- Mediatek ADSP DVFS control
//
// Copyright (c) 2018 MediaTek Inc.
// Author: Celine Liu <Celine.liu@mediatek.com>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/slab.h>
#include <linux/proc_fs.h>
#include <linux/miscdevice.h>
#include <linux/platform_device.h>
#include <linux/spinlock.h>
#include <linux/kthread.h>
#include <linux/vmalloc.h> /* needed by vmalloc */
#include <linux/hrtimer.h>
#include <linux/ktime.h>
#include <linux/jiffies.h>
#include <linux/fs.h>
#include <linux/seq_file.h>
#include <linux/input.h>
#ifdef wakelock
#include <linux/wakelock.h>
#endif
#include <linux/io.h>
//#include <mt-plat/upmu_common.h>
#include <mtk_spm_sleep.h>
#ifdef CONFIG_OF
#include <linux/of.h>
#include <linux/of_address.h>
#endif
#ifdef CONFIG_MTK_AEE_FEATURE
#include <mt-plat/aee.h>
#endif
#include <linux/uaccess.h>
#include "adsp_ipi.h"
#include <adsp_ipi_queue.h>
#include <audio_ipi_platform.h>
#include "adsp_helper.h"
#include "adsp_excep.h"
#include "adsp_dvfs.h"
#include "adsp_clk.h"
#include "adsp_reg.h"
#include <adsp_timesync.h>
#ifdef CONFIG_MTK_CLKMGR
#include <mach/mt_clkmgr.h>
#else
#include <linux/clk.h>
#endif
#ifdef pr_fmt
#undef pr_fmt
#endif
#define pr_fmt(fmt) "[adsp_dvfs]: " fmt
#define ADSP_DBG(fmt, arg...) pr_debug(fmt, ##arg)
#define ADSP_INFO(fmt, arg...) pr_info(fmt, ##arg)
#define DRV_Reg32(addr) readl(addr)
#define DRV_WriteReg32(addr, val) writel(val, addr)
#define DRV_SetReg32(addr, val) DRV_WriteReg32(addr, DRV_Reg32(addr) | (val))
#define DRV_ClrReg32(addr, val) DRV_WriteReg32(addr, DRV_Reg32(addr) & ~(val))
/* new implement for adsp */
static DEFINE_MUTEX(adsp_timer_mutex);
DEFINE_MUTEX(adsp_suspend_mutex);
static struct timer_list adsp_suspend_timer;
static struct adsp_work_t adsp_suspend_work;
int adsp_is_suspend;
static int adsp_is_force_freq;
static int adsp_is_force_trigger_latmon;
#define ADSP_DELAY_OFF_TIMEOUT (1 * HZ) /* 1 second */
#define ADSP_DELAY_TIMER (0)
#define FORCE_ADSPPLL_BASE (0x10000000)
#define SPM_REQ_BASE (0x20000000)
#define ADSPPLL_ON_BASE (0x30000000)
#define ADD_FREQ_CMD (0x11110000)
#define DEL_FREQ_CMD (0x22220000)
#define QUERY_FREQ_CMD (0xFFFFFFFF)
#define ADSP_FREQ_MAX_VALUE (630) /* 0.725V 70MCPS for sys */
#define TRIGGER_LATMON_IRQ_CMD (0x00010000)
/* Private Macro ---------------------------------------------------------*/
/* The register must sync with ctrl-boards.S in Tinysys */
#define CREG_BOOTUP_MARK (ADSP_CFGREG_RSV_RW_REG0)
/* if equal, bypass clear bss and some init */
#define MAGIC_PATTERN (0xfafafafa)
struct wakeup_source *adsp_suspend_lock;
static inline ssize_t adsp_force_adsppll_store(struct device *kobj,
struct device_attribute *attr,
const char *buf, size_t count)
{
uint32_t value = 0, param = 0;
enum adsp_ipi_status ret;
if (kstrtoint(buf, 10, &value))
return -EINVAL;
switch (value) {
case 480:
param = FORCE_ADSPPLL_BASE+0x01E0;
break;
case 694:
param = FORCE_ADSPPLL_BASE+0x02B6;
break;
case 800:
param = FORCE_ADSPPLL_BASE+0x0320;
break;
default:
break;
}
pr_debug("[%s]force in %d(%x)\n", __func__, value, param);
if (is_adsp_ready(ADSP_A_ID) == 1) {
ret = adsp_ipi_send(ADSP_IPI_DVFS_SLEEP, &param,
sizeof(param), 0, ADSP_A_ID);
}
return count;
}
static inline ssize_t adsp_spm_req_store(struct device *kobj,
struct device_attribute *attr,
const char *buf, size_t count)
{
uint32_t value = 0, param;
enum adsp_ipi_status ret;
if (kstrtoint(buf, 10, &value))
return -EINVAL;
param = SPM_REQ_BASE + value;
pr_debug("[%s]set SPM req in %d(%x)\n", __func__, value, param);
if (is_adsp_ready(ADSP_A_ID) == 1) {
ret = adsp_ipi_send(ADSP_IPI_DVFS_SLEEP, &param,
sizeof(param), 0, ADSP_A_ID);
}
return count;
}
static inline ssize_t adsp_keep_adsppll_on_store(struct device *kobj,
struct device_attribute *attr,
const char *buf, size_t count)
{
uint32_t value = 0, param;
enum adsp_ipi_status ret;
if (kstrtoint(buf, 10, &value))
return -EINVAL;
param = ADSPPLL_ON_BASE + value;
pr_debug("[%s] %d(%x)\n", __func__, value, param);
if (is_adsp_ready(ADSP_A_ID) == 1) {
ret = adsp_ipi_send(ADSP_IPI_DVFS_SLEEP, &param,
sizeof(param), 0, ADSP_A_ID);
}
return count;
}
static inline ssize_t adsp_dvfs_force_opp_show(struct device *kobj,
struct device_attribute *attr,
char *buf)
{
return scnprintf(buf, PAGE_SIZE, "force freq status = %d\n",
adsp_is_force_freq);
}
static inline ssize_t adsp_dvfs_force_opp_store(struct device *kobj,
struct device_attribute *attr,
const char *buf, size_t count)
{
unsigned int value = 0;
enum adsp_ipi_status ret = ADSP_IPI_ERROR;
if (kstrtoint(buf, 10, &value))
return -EINVAL;
if (is_adsp_ready(ADSP_A_ID) == 1) {
if (value == 255) {
/* release force freq mode */
adsp_is_force_freq = 0;
ret = adsp_ipi_send(ADSP_IPI_DVFS_FIX_OPP_SET, &value,
sizeof(value), 0, ADSP_A_ID);
} else if (value == 0 || value == 1) {
/* force adsp freq at specific value */
adsp_is_force_freq = 1;
ret = adsp_ipi_send(ADSP_IPI_DVFS_FIX_OPP_SET, &value,
sizeof(value), 0, ADSP_A_ID);
}
}
return count;
}
static inline ssize_t adsp_dvfs_set_freq_show(struct device *kobj,
struct device_attribute *attr,
char *buf)
{
unsigned int value = QUERY_FREQ_CMD;
enum adsp_ipi_status ret;
ret = adsp_ipi_send(ADSP_IPI_DVFS_SET_FREQ, &value,
sizeof(value), 0, ADSP_A_ID);
/* FIXME: ToDo, get MCPS and freq result from ADSP */
return scnprintf(buf, PAGE_SIZE, "Running on level %d, Total MCPS=%d\n",
0xFF, 0xFF);
}
static inline ssize_t adsp_dvfs_set_freq_store(struct device *kobj,
struct device_attribute *attr,
const char *buf, size_t count)
{
char *temp = NULL, *token1 = NULL, *token2 = NULL;
char *pin = NULL;
char delim[] = " ,";
unsigned int value = 0;
enum adsp_ipi_status ret;
temp = kstrdup(buf, GFP_KERNEL);
pin = temp;
token1 = strsep(&pin, delim);
if (token1 == NULL)
return -EINVAL;
token2 = strsep(&pin, delim);
if (token2 == NULL)
return -EINVAL;
if (kstrtoint(token2, 10, &value))
return -EINVAL;
if (value >= ADSP_FREQ_MAX_VALUE)
return -EINVAL;
if (strcmp(token1, "add") == 0)
value |= ADD_FREQ_CMD;
if (strcmp(token1, "del") == 0)
value |= DEL_FREQ_CMD;
ret = adsp_ipi_send(ADSP_IPI_DVFS_SET_FREQ, &value,
sizeof(value), 0, ADSP_A_ID);
kfree(temp);
return count;
}
static inline ssize_t adsp_dvfs_trigger_latmon_show(struct device *kobj,
struct device_attribute *attr,
char *buf)
{
return scnprintf(buf, PAGE_SIZE, "force trigger latmon irq = %d\n",
adsp_is_force_trigger_latmon);
}
static inline ssize_t adsp_dvfs_trigger_latmon_store(struct device *kobj,
struct device_attribute *attr,
const char *buf, size_t count)
{
unsigned int value = 0;
enum adsp_ipi_status ret = ADSP_IPI_ERROR;
if (kstrtoint(buf, 10, &value))
return -EINVAL;
value |= TRIGGER_LATMON_IRQ_CMD;
if (is_adsp_ready(ADSP_A_ID) == 1) {
if (value == (TRIGGER_LATMON_IRQ_CMD | 0x0)) {
/* release force freq mode */
adsp_is_force_trigger_latmon = 0;
ret = adsp_ipi_send(ADSP_IPI_DVFS_FIX_OPP_SET, &value,
sizeof(value), 0, ADSP_A_ID);
} else if (value == (TRIGGER_LATMON_IRQ_CMD | 0x1)) {
/* force adsp freq at specific value */
adsp_is_force_trigger_latmon = 1;
ret = adsp_ipi_send(ADSP_IPI_DVFS_FIX_OPP_SET, &value,
sizeof(value), 0, ADSP_A_ID);
}
}
return count;
}
DEVICE_ATTR_WO(adsp_force_adsppll);
DEVICE_ATTR_WO(adsp_spm_req);
DEVICE_ATTR_WO(adsp_keep_adsppll_on);
DEVICE_ATTR_RW(adsp_dvfs_force_opp);
DEVICE_ATTR_RW(adsp_dvfs_set_freq);
DEVICE_ATTR_RW(adsp_dvfs_trigger_latmon);
static struct attribute *adsp_dvfs_attrs[] = {
#if ADSP_SLEEP_ENABLE
&dev_attr_adsp_force_adsppll.attr,
&dev_attr_adsp_spm_req.attr,
&dev_attr_adsp_keep_adsppll_on.attr,
#endif
&dev_attr_adsp_dvfs_force_opp.attr,
&dev_attr_adsp_dvfs_set_freq.attr,
&dev_attr_adsp_dvfs_trigger_latmon.attr,
NULL,
};
struct attribute_group adsp_dvfs_attr_group = {
.attrs = adsp_dvfs_attrs,
};
static bool is_adsp_suspend(void)
{
return (readl(ADSP_A_SYS_STATUS) == ADSP_STATUS_SUSPEND)
&& (readl(ADSP_SLEEP_STATUS_REG) & ADSP_A_IS_WFI)
&& (readl(ADSP_SLEEP_STATUS_REG) & ADSP_A_AXI_BUS_IS_IDLE);
}
DEFINE_MUTEX(adsp_sw_reset_mutex);
static DEFINE_SPINLOCK(adsp_sw_reset_spinlock);
void adsp_sw_reset(void)
{
unsigned long flags;
mutex_lock(&adsp_sw_reset_mutex);
spin_lock_irqsave(&adsp_sw_reset_spinlock, flags);
writel((ADSP_A_SW_RSTN | ADSP_A_SW_DBG_RSTN), ADSP_A_REBOOT);
udelay(1);
writel(0, ADSP_A_REBOOT);
spin_unlock_irqrestore(&adsp_sw_reset_spinlock, flags);
mutex_unlock(&adsp_sw_reset_mutex);
}
void adsp_release_runstall(uint32_t release)
{
uint32_t reg_value;
reg_value = readl(ADSP_HIFI3_IO_CONFIG);
if (release) {
writel(reg_value & ~(ADSP_RELEASE_RUNSTALL),
ADSP_HIFI3_IO_CONFIG);
} else {
writel(reg_value | (ADSP_RELEASE_RUNSTALL),
ADSP_HIFI3_IO_CONFIG);
}
}
void adsp_set_clock_freq(enum adsp_clk clk)
{
switch (clk) {
case CLK_ADSP_CLK26M:
case CLK_TOP_MMPLL_D4:
case CLK_TOP_ADSPPLL_D6:
adsp_set_top_mux(clk);
break;
case CLK_TOP_ADSPPLL_D4:
adsp_set_top_mux(clk);
break;
default:
break;
}
}
void adsp_A_send_spm_request(uint32_t enable)
{
int timeout = 1000;
pr_debug("req spm source & ddr enable(%d)\n", enable);
if (enable) {
/* request infra/26M/apsrc/v18/ ddr resource */
writel(readl(ADSP_A_SPM_REQ) | ADSP_A_SPM_SRC_BITS,
ADSP_A_SPM_REQ);
/* hw auto on/off ddren, disable now due to latency concern */
// writel(ADSP_A_DDR_REQ_SEL, ADSP_A_DDREN_REQ);
writel(readl(ADSP_A_DDREN_REQ) | ADSP_A_DDR_ENABLE,
ADSP_A_DDREN_REQ);
/*make sure SPM return ack*/
while (--timeout) {
if (readl(ADSP_A_SPM_ACK) ==
((ADSP_A_DDR_ENABLE << 4) | ADSP_A_SPM_SRC_BITS))
/* hw auto on/off ddren */
// if (readl(ADSP_A_SPM_ACK) == (ADSP_A_SPM_SRC_BITS))
break;
udelay(10);
if (timeout == 0)
pr_err("[ADSP] timeout: cannot get SPM ack\n");
}
} else {
writel(readl(ADSP_A_DDREN_REQ) & ~(ADSP_A_DDR_ENABLE),
ADSP_A_DDREN_REQ);
writel(readl(ADSP_A_SPM_REQ) & ~ADSP_A_SPM_SRC_BITS,
ADSP_A_SPM_REQ);
/*make sure SPM return ack*/
while (--timeout) {
if (readl(ADSP_A_SPM_ACK) == 0x0)
break;
udelay(10);
if (timeout == 0)
pr_err("[ADSP] timeout: cannot get SPM ack\n");
}
}
}
static void adsp_delay_off_handler(struct timer_list *list)
{
if (!adsp_feature_is_active())
queue_work(adsp_workqueue, &adsp_suspend_work.work);
__pm_relax(adsp_suspend_lock);
}
void adsp_start_suspend_timer(void)
{
mutex_lock(&adsp_timer_mutex);
adsp_suspend_timer.function = adsp_delay_off_handler;
//adsp_suspend_timer.data = (unsigned long)ADSP_DELAY_TIMER;
adsp_suspend_timer.expires =
jiffies + ADSP_DELAY_OFF_TIMEOUT;
if (timer_pending(&adsp_suspend_timer))
pr_debug("adsp_suspend_timer has set\n");
else {
__pm_stay_awake(adsp_suspend_lock); /* wake lock AP */
add_timer(&adsp_suspend_timer);
}
mutex_unlock(&adsp_timer_mutex);
}
void adsp_stop_suspend_timer(void)
{
mutex_lock(&adsp_timer_mutex);
if (timer_pending(&adsp_suspend_timer)) {
del_timer(&adsp_suspend_timer);
__pm_relax(adsp_suspend_lock);
}
mutex_unlock(&adsp_timer_mutex);
}
/*
* callback function for work struct
* @param ws: work struct
*/
static void adsp_suspend_ws(struct work_struct *ws)
{
struct adsp_work_t *sws = container_of(ws, struct adsp_work_t, work);
enum adsp_core_id core_id = sws->id;
mutex_lock(&adsp_feature_mutex);
if (!adsp_feature_is_active())
adsp_suspend(core_id);
mutex_unlock(&adsp_feature_mutex);
}
#if ADSP_ITCM_MONITOR
static unsigned int adsp_itcm_gtable[9216]; //ADSP_A_ITCM_SIZE/4
#endif
#if ADSP_DTCM_MONITOR
static unsigned int adsp_dtcm_gtable[8192]; //ADPS_A_DTCM_SIZE/4
#endif
void adsp_sram_reset_init(void)
{
#if ADSP_ITCM_MONITOR
memcpy((void *)(ADSP_A_ITCM),
(void *)adsp_itcm_gtable,
(size_t)ADSP_A_ITCM_SIZE);
#endif
#if ADSP_DTCM_MONITOR
memcpy((void *)(ADSP_A_DTCM),
(void *)adsp_dtcm_gtable,
(size_t)(ADSP_A_DTCM_SIZE - ADSP_A_DTCM_SHARE_SIZE));
#endif
}
void adsp_sram_gtable_init(void)
{
#if ADSP_ITCM_MONITOR
memcpy((void *)adsp_itcm_gtable,
(void *)(ADSP_A_ITCM),
(size_t)ADSP_A_ITCM_SIZE);
#endif
#if ADSP_DTCM_MONITOR
memcpy((void *)adsp_dtcm_gtable,
(void *)(ADSP_A_DTCM),
(size_t)ADSP_A_DTCM_SIZE);
#endif
}
void adsp_sram_gtable_backup(void)
{
#if ADSP_DTCM_MONITOR
memcpy((void *)adsp_dtcm_gtable,
(void *)(ADSP_A_DTCM),
(size_t)ADSP_A_DTCM_SIZE);
#endif
}
int adsp_sram_gtable_check(void)
{
int ret = 0;
int need_assert = 0;
#if (ADSP_ITCM_MONITOR || ADSP_DTCM_MONITOR)
int i;
u32 __iomem *s;
void *tcm_src = NULL;
#endif
#if ADSP_ITCM_MONITOR
tcm_src = vmalloc(sizeof(adsp_itcm_gtable));
if (!tcm_src)
return -1;
memcpy_fromio(tcm_src, (void *)(ADSP_A_ITCM),
(size_t)ADSP_A_ITCM_SIZE);
ret = memcmp((void *)adsp_itcm_gtable,
(void *)tcm_src,
sizeof(adsp_itcm_gtable));
if (ret) {
pr_notice("[%s]memcmp adsp_itcm_gtable != ITCM, ret %d\n",
__func__, ret);
s = (void *)(ADSP_A_ITCM);
for (i = 0; i < ADSP_A_ITCM_SIZE / 4; i++) {
if (adsp_itcm_gtable[i] != *s) {
pr_notice("[%s]adsp_itcm_gtable[%d](0x%x) != ITCM(0x%x)\n",
__func__, i, adsp_itcm_gtable[i], *s);
*s = adsp_itcm_gtable[i];
}
s++;
}
need_assert = 1;
}
if (tcm_src != NULL) {
vfree(tcm_src);
tcm_src = NULL;
}
#endif
#if ADSP_DTCM_MONITOR
tcm_src = vmalloc(sizeof(adsp_dtcm_gtable));
if (!tcm_src)
return -1;
memcpy_fromio(tcm_src, (void *)(ADSP_A_DTCM),
(size_t)ADSP_A_DTCM_SIZE);
ret = memcmp((void *)adsp_dtcm_gtable,
(void *)tcm_src,
(size_t)ADSP_A_DTCM_SIZE - ADSP_A_DTCM_SHARE_SIZE);
if (ret) {
pr_notice("[%s]memcmp adsp_dtcm_gtable != DTCM, ret %d\n",
__func__, ret);
s = (void *)(ADSP_A_DTCM);
for (i = 0;
i < (ADSP_A_DTCM_SIZE - ADSP_A_DTCM_SHARE_SIZE) / 4;
i++) {
if (adsp_dtcm_gtable[i] != *s) {
pr_notice("[%s]adsp_dtcm_gtable[%d](0x%x) != DTCM(0x%x)\n",
__func__, i, adsp_dtcm_gtable[i], *s);
*s = adsp_dtcm_gtable[i];
}
s++;
}
need_assert = 1;
}
if (tcm_src != NULL) {
vfree(tcm_src);
tcm_src = NULL;
}
#endif
#ifdef CONFIG_MTK_AEE_FEATURE
if (need_assert)
aee_kernel_exception_api(__FILE__,
__LINE__,
DB_OPT_DEFAULT,
"[ADSP]",
"ASSERT: adsp tcm check fail!!");
#endif
return ret;
}
int adsp_suspend_init(void)
{
INIT_WORK(&adsp_suspend_work.work, adsp_suspend_ws);
adsp_suspend_lock = wakeup_source_register(NULL,
"adsp suspend wakelock");
timer_setup(&adsp_suspend_timer, adsp_delay_off_handler, 0);
adsp_is_suspend = 0;
adsp_sram_gtable_init();
adsp_sram_gtable_backup();
return 0;
}
/* actually execute suspend flow, which cannot be disabled.
* retry the resume flow after adsp_ready = 0.
*/
void adsp_suspend(enum adsp_core_id core_id)
{
enum adsp_ipi_status ret;
int value = 0;
int timeout = 20000;
#if ADSP_DVFS_PROFILE
ktime_t begin, end;
#endif
mutex_lock(&adsp_suspend_mutex);
if ((is_adsp_ready(core_id) == 1) && !adsp_is_suspend) {
#if ADSP_DVFS_PROFILE
begin = ktime_get();
#endif
adsp_timesync_suspend(0);
ret = scp_send_msg_to_queue(AUDIO_OPENDSP_USE_HIFI3_A,
ADSP_IPI_DVFS_SUSPEND,
&value, sizeof(value), 100);
while (--timeout && !is_adsp_suspend())
usleep_range(100, 200);
if (!is_adsp_suspend()) {
pr_info("[%s]wait adsp suspend timeout ret(%d,%d)\n",
__func__, ret, timeout);
#ifdef CFG_RECOVERY_SUPPORT
adsp_send_reset_wq(ADSP_RESET_TYPE_AWAKE, core_id);
#else
adsp_aed(EXCEP_KERNEL, core_id);
#endif
} else {
adsp_release_runstall(false);
adsp_sram_gtable_backup();
adsp_power_on(false);
adsp_is_suspend = 1;
}
adsp_reset_ready(core_id);
#if ADSP_DVFS_PROFILE
end = ktime_get();
pr_debug("[%s]latency = %lld us, ret(%d)\n",
__func__, ktime_us_delta(end, begin), ret);
#endif
}
mutex_unlock(&adsp_suspend_mutex);
}
int adsp_resume(void)
{
int retry = 20000;
int ret = 0;
int tcm_ret = 0;
#if ADSP_DVFS_PROFILE
ktime_t begin, end;
#endif
mutex_lock(&adsp_suspend_mutex);
if ((is_adsp_ready(ADSP_A_ID) == 0) && adsp_is_suspend) {
#if ADSP_DVFS_PROFILE
begin = ktime_get();
#endif
adsp_power_on(true);
tcm_ret = adsp_sram_gtable_check();
/* To indicate only main_lite() is needed. */
writel(MAGIC_PATTERN, CREG_BOOTUP_MARK);
DRV_ClrReg32(ADSP_A_WDT_REG, WDT_EN_BIT);
adsp_release_runstall(true);
/* busy waiting until adsp is ready */
while (--retry && (is_adsp_ready(ADSP_A_ID) != 1))
usleep_range(100, 200);
if (is_adsp_ready(ADSP_A_ID) != 1) {
pr_warn("[%s]wait for adsp ready timeout\n", __func__);
/* something wrong , dump adsp */
#ifdef CFG_RECOVERY_SUPPORT
adsp_send_reset_wq(ADSP_RESET_TYPE_AWAKE, ADSP_A_ID);
#else
adsp_aed(EXCEP_KERNEL, ADSP_A_ID);
#endif
ret = -ETIME;
}
adsp_timesync_resume();
adsp_is_suspend = 0;
#if ADSP_DVFS_PROFILE
end = ktime_get();
pr_debug("[%s]latency = %lld us, tcm_check(%d), ret(%d)\n",
__func__, ktime_us_delta(end, begin), tcm_ret, ret);
#endif
}
mutex_unlock(&adsp_suspend_mutex);
return ret;
}
void adsp_reset(void)
{
uint32_t reg_val = 0;
#if ADSP_DVFS_PROFILE
ktime_t begin = ktime_get();
ktime_t end;
#endif
adsp_reset_ready(ADSP_A_ID);
adsp_release_runstall(false);
adsp_power_on(false);
adsp_power_on(true);
writel(0, CREG_BOOTUP_MARK);
writel(0x0, ADSP_A_IRQ_EN);
reg_val = readl(ADSP_A_WDT_REG) & ~(WDT_EN_BIT);
writel(reg_val, ADSP_A_WDT_REG);
/** TCM back to initial state **/
adsp_sram_reset_init();
dsb(SY);
adsp_release_runstall(true);
adsp_is_suspend = 0;
#if ADSP_DVFS_PROFILE
end = ktime_get();
pr_debug("[%s]latency = %lld us\n",
__func__, ktime_us_delta(end, begin));
#endif
}
void mt_adsp_dvfs_ipi_init(void)
{
}
int __init adsp_dvfs_init(void)
{
adsp_is_force_freq = 0;
adsp_is_force_trigger_latmon = 0;
adspreg.active_clksrc = CLK_TOP_ADSPPLL_D6;
return 0;
}
void __exit adsp_dvfs_exit(void)
{
}
@@ -0,0 +1,57 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* adsp_dvfs.h -- Mediatek ADSP DVFS control
*
* Copyright (c) 2018 MediaTek Inc.
* Author: Celine Liu <Celine.liu@mediatek.com>
*/
#ifndef __ADSP_DVFS_H__
#define __ADSP_DVFS_H__
#include <adsp_ipi.h>
#include <adsp_clk.h>
#define ADSP_ITCM_MONITOR (0)
#define ADSP_DTCM_MONITOR (0)
#define ADSP_DVFS_PROFILE (1)
#define ADSP_FREQ_METER_ID (43) //hf_fadsp_ck
#define CLK_DEFAULT_ACTIVE_CK adspreg.active_clksrc
#define CLK_DEFAULT_26M_CK CLK_ADSP_CLK26M
enum adsp_cur_status_enum {
ADSP_STATUS_RESET = 0x00,
ADSP_STATUS_SUSPEND = 0x01,
ADSP_STATUS_SLEEP = 0x10,
ADSP_STATUS_ACTIVE = 0x11,
};
enum clk_div_enum {
CLK_DIV_1 = 0,
CLK_DIV_2 = 1,
CLK_DIV_4 = 2,
CLK_DIV_8 = 3,
CLK_DIV_UNKNOWN,
};
extern int __init adsp_dvfs_init(void);
extern void __exit adsp_dvfs_exit(void);
/* adsp dvfs variable*/
extern struct mutex adsp_feature_mutex;
extern struct mutex adsp_suspend_mutex;
extern int adsp_is_suspend;
/* adsp new implement */
void adsp_A_send_spm_request(uint32_t enable);
extern void adsp_reset(void);
void adsp_sw_reset(void);
void adsp_set_clock_freq(enum adsp_clk clk);
extern void adsp_release_runstall(uint32_t release);
extern int adsp_suspend_init(void);
void adsp_start_suspend_timer(void);
void adsp_stop_suspend_timer(void);
int adsp_resume(void);
void adsp_suspend(enum adsp_core_id core_id);
#endif /* __ADSP_DVFS_H__ */
@@ -0,0 +1,168 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* adsp_excep.h -- Mediatek ADSP exception handling
*
* Copyright (c) 2018 MediaTek Inc.
* Author: HsinYi Chang <hsin-yi.chang@mediatek.com>
*/
#ifndef __ADSP_EXCEP_H__
#define __ADSP_EXCEP_H__
#include <linux/sizes.h>
#define AED_LOG_PRINT_SIZE SZ_16K
enum adsp_excep_id {
EXCEP_LOAD_FIRMWARE = 0,
EXCEP_RESET,
EXCEP_BOOTUP,
EXCEP_RUNTIME,
EXCEP_KERNEL,
ADSP_NR_EXCEP,
};
extern void adsp_aed(enum adsp_excep_id type, enum adsp_core_id id);
extern void adsp_aed_reset(enum adsp_excep_id type, enum adsp_core_id id);
extern void adsp_aed_reset_inplace(enum adsp_excep_id type,
enum adsp_core_id id);
extern uint32_t adsp_dump_pc(void);
extern int adsp_get_trax_initiated(void);
extern int adsp_get_trax_done(void);
extern int adsp_get_trax_length(void);
extern void aed_scp_exception_api(const int *log, int log_size, const int *phy,
int phy_size, const char *detail,
const int db_opt);
extern void adsp_excep_cleanup(void);
extern struct mutex adsp_sw_reset_mutex;
enum { r0, r1, r2, r3, r12, lr, pc, psr};
struct TaskContextType {
unsigned int r0;
unsigned int r1;
unsigned int r2;
unsigned int r3;
unsigned int r4;
unsigned int r5;
unsigned int r6;
unsigned int r7;
unsigned int r8;
unsigned int r9;
unsigned int r10;
unsigned int r11;
unsigned int r12;
unsigned int sp; /* after pop r0-r3, lr, pc, xpsr */
unsigned int pc; /* pc before exception */
unsigned int control; /* nPRIV bit&FPCA bit meaningful,SPSEL bit = 0 */
unsigned int exc_return; /* current lr */
unsigned int msp; /* msp */
};
#define CRASH_SUMMARY_LENGTH 12
#define CRASH_MEMORY_HEADER_SIZE (8 * 1024)
#define CRASH_MEMORY_LENGTH (68 * 1024) /* 36k+32k */
#define CRASH_MEMORY_OFFSET (0x800)
#define CRASH_CORE_REG_SIZE (9 * 32)
#define CRASH_CFG_REG_SIZE (64 * 1024)
#include <linux/elf.h>
#define ELF_NGREGS 18
#define CORE_STR "CORE"
#define ELF_PRARGSZ 80
#define ELF_CORE_EFLAGS 0
#define EM_ARM 40
static inline void elf_setup_eident(unsigned char e_ident[EI_NIDENT],
unsigned char elfclasz)
{
memcpy(e_ident, ELFMAG, SELFMAG);
e_ident[EI_CLASS] = elfclasz;
e_ident[EI_DATA] = ELFDATA2LSB;
e_ident[EI_VERSION] = EV_CURRENT;
e_ident[EI_OSABI] = ELFOSABI_NONE;
memset(e_ident + EI_PAD, 0, EI_NIDENT - EI_PAD);
}
struct elf_siginfo {
int si_signo;
int si_code;
int si_errno;
};
struct elf32_note_t {
Elf32_Word n_namesz; /* Name size */
Elf32_Word n_descsz; /* Content size */
Elf32_Word n_type; /* Content type */
};
struct elf32_timeval {
int32_t tv_sec;
int32_t tv_usec;
};
struct elf32_prstatus {
struct elf_siginfo pr_info;
short pr_cursig;
uint32_t pr_sigpend;
uint32_t pr_sighold;
int32_t pr_pid;
int32_t pr_ppid;
int32_t pr_pgrp;
int32_t pr_sid;
struct elf32_timeval pr_utime;
struct elf32_timeval pr_stime;
struct elf32_timeval pr_cutime;
struct elf32_timeval pr_cstime;
uint32_t pr_reg[ELF_NGREGS];
int32_t pr_fpvalid;
};
struct elf32_prpsinfo {
char pr_state;
char pr_sname;
char pr_zomb;
char pr_nice;
uint32_t pr_flag;
uint16_t pr_uid;
uint16_t pr_gid;
int32_t pr_pid;
int32_t pr_ppid;
int32_t pr_pgrp;
int32_t pr_sid;
char pr_fname[16];
char pr_psargs[ELF_PRARGSZ];
};
/* adsp reg dump */
struct adsp_coredump {
u32 reserved_0[67];
u32 pc;
u32 exccause;
u32 excvaddr;
u32 reserved_1[7];
u8 task_name[16];
u32 reserved_2[47];
u8 assert_log[512];
};
struct MemoryDump {
struct elf32_hdr elf;
struct elf32_phdr nhdr;
struct elf32_phdr phdr;
char notes[CRASH_MEMORY_HEADER_SIZE - sizeof(struct elf32_hdr)
- sizeof(struct elf32_phdr) - sizeof(struct elf32_phdr)];
/* ram dump total header size (elf+nhdr+phdr
* must be fixed at CRASH_MEMORY_HEADER_SIZE
*/
char memory[CRASH_MEMORY_LENGTH]; /* adsp tcm */
char core_reg[CRASH_CORE_REG_SIZE]; /* core reg */
char cfg_reg[CRASH_CFG_REG_SIZE]; /* cfg reg */
};
#endif
@@ -0,0 +1,94 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* adsp_feature_define.h -- Mediatek ADSP feature definition
*
* Copyright (c) 2018 MediaTek Inc.
* Author: Celine Liu <Celine.liu@mediatek.com>
*/
#ifndef __ADSP_FEATURE_DEFINE_H__
#define __ADSP_FEATURE_DEFINE_H__
/* reset recovery feature kernel option*/
#define CFG_RECOVERY_SUPPORT
/* adsp platform configs*/
#define ADSP_BOOT_TIME_OUT_MONITOR (1)
#define ADSP_LOGGER_ENABLE (1)
#define ADSP_TRAX (0)
#define ADSP_BUS_MONITOR_INIT_ENABLE (1)
/* adsp aed definition*/
#define ADSP_AED_STR_LEN (512)
#define ADSP_RESERVED_DRAM_SIZE (0x1000000)
/* emi mpu define*/
#ifdef CONFIG_MTK_EMI
#define ENABLE_ADSP_EMI_PROTECTION (1)
#else
#define ENABLE_ADSP_EMI_PROTECTION (0)
#endif
/* adsp feature PRI list */
/* The higher number, higher priority */
enum adsp_feature_pri {
AUDIO_HAL_FEATURE_PRI = 0,
ADSP_LOGGER_FEATURE_PRI,
SPK_PROTECT_FEATURE_PRI,
A2DP_PLAYBACK_FEATURE_PRI,
AURISYS_FEATURE_PRI,
DEEPBUF_FEATURE_PRI,
OFFLOAD_FEATURE_PRI,
PRIMARY_FEATURE_PRI,
VOIP_FEATURE_PRI,
CAPTURE_UL1_FEATURE_PRI,
AUDIO_DATAPROVIDER_FEATURE_PRI,
AUDIO_PLAYBACK_FEATURE_PRI,
VOICE_CALL_FEATURE_PRI,
AUDIO_CONTROLLER_FEATURE_PRI,
SYSTEM_FEATURE_PRI,
};
/* adsp feature ID list */
enum adsp_feature_id {
SYSTEM_FEATURE_ID,
ADSP_LOGGER_FEATURE_ID,
AURISYS_FEATURE_ID,
AUDIO_CONTROLLER_FEATURE_ID,
PRIMARY_FEATURE_ID,
FAST_FEATURE_ID,
DEEPBUF_FEATURE_ID,
OFFLOAD_FEATURE_ID,
AUDIO_PLAYBACK_FEATURE_ID,
AUDIO_MUSIC_FEATURE_ID,
RESERVED0_FEATURE_ID,
RESERVED1_FEATURE_ID,
CAPTURE_UL1_FEATURE_ID,
AUDIO_DATAPROVIDER_FEATURE_ID,
VOICE_CALL_FEATURE_ID,
VOIP_FEATURE_ID,
SPK_PROTECT_FEATURE_ID,
CALL_FINAL_FEATURE_ID,
A2DP_PLAYBACK_FEATURE_ID,
KTV_FEATURE_ID,
CAPTURE_RAW_FEATURE_ID,
VOICE_CALL_SUB_FEATURE_ID,
BLE_CALL_DL_FEATURE_ID,
BLE_CALL_UL_FEATURE_ID,
ADSP_NUM_FEATURE_ID,
};
struct adsp_feature_tb {
const char *name;
uint32_t freq;
int32_t counter;
};
ssize_t adsp_dump_feature_state(char *buffer, int size);
bool adsp_feature_is_active(void);
int adsp_register_feature(enum adsp_feature_id id);
int adsp_deregister_feature(enum adsp_feature_id id);
int adsp_get_feature_index(char *str);
#endif
@@ -0,0 +1,136 @@
// SPDX-License-Identifier: GPL-2.0
//
// adsp_feature_table.c-- Mediatek ADSP feature control
//
// Copyright (c) 2018 MediaTek Inc.
// Author: Celine Liu <Celine.liu@mediatek.com>
#include <linux/module.h> /* needed by all modules */
#include "adsp_feature_define.h"
#include "adsp_dvfs.h"
#define ADSP_SYSTEM_UNIT(fname) {.name = fname, .freq = 0, .counter = 1}
#define ADSP_FEATURE_UNIT(fname) {.name = fname, .freq = 0, .counter = 0}
DEFINE_MUTEX(adsp_feature_mutex);
/*adsp feature list*/
struct adsp_feature_tb adsp_feature_table[ADSP_NUM_FEATURE_ID] = {
[SYSTEM_FEATURE_ID] = ADSP_FEATURE_UNIT("system"),
[ADSP_LOGGER_FEATURE_ID] = ADSP_FEATURE_UNIT("logger"),
[AURISYS_FEATURE_ID] = ADSP_FEATURE_UNIT("aurisys"),
[AUDIO_CONTROLLER_FEATURE_ID] = ADSP_FEATURE_UNIT("audio_controller"),
[PRIMARY_FEATURE_ID] = ADSP_FEATURE_UNIT("primary"),
[DEEPBUF_FEATURE_ID] = ADSP_FEATURE_UNIT("deepbuf"),
[OFFLOAD_FEATURE_ID] = ADSP_FEATURE_UNIT("offload"),
[AUDIO_PLAYBACK_FEATURE_ID] = ADSP_FEATURE_UNIT("audplayback"),
[A2DP_PLAYBACK_FEATURE_ID] = ADSP_FEATURE_UNIT("a2dp_playback"),
[AUDIO_DATAPROVIDER_FEATURE_ID] = ADSP_FEATURE_UNIT("dataprovider"),
[SPK_PROTECT_FEATURE_ID] = ADSP_FEATURE_UNIT("spk_protect"),
[VOICE_CALL_FEATURE_ID] = ADSP_FEATURE_UNIT("voice_call"),
[VOIP_FEATURE_ID] = ADSP_FEATURE_UNIT("voip"),
[CAPTURE_UL1_FEATURE_ID] = ADSP_FEATURE_UNIT("capture_ul1"),
[CALL_FINAL_FEATURE_ID] = ADSP_FEATURE_UNIT("call_final"),
[KTV_FEATURE_ID] = ADSP_FEATURE_UNIT("ktv"),
[CAPTURE_RAW_FEATURE_ID] = ADSP_FEATURE_UNIT("capture_raw"),
[VOICE_CALL_SUB_FEATURE_ID] = ADSP_FEATURE_UNIT("voice_call_sub"),
};
ssize_t adsp_dump_feature_state(char *buffer, int size)
{
int n = 0, i = 0;
struct adsp_feature_tb *unit;
n += scnprintf(buffer + n, size - n, "%-20s %-8s %-8s\n",
"Feature_name", "Freq", "Counter");
for (i = 0; i < ADSP_NUM_FEATURE_ID; i++) {
unit = &adsp_feature_table[i];
if (!unit->name)
continue;
n += scnprintf(buffer + n, size - n, "%-20s %-8d %-3d\n",
unit->name, unit->freq, unit->counter);
}
return n;
}
int adsp_get_feature_index(char *str)
{
int i = 0;
struct adsp_feature_tb *unit;
if (!str)
return -EINVAL;
for (i = 0; i < ADSP_NUM_FEATURE_ID; i++) {
unit = &adsp_feature_table[i];
if (!unit->name)
continue;
if (strncmp(unit->name, str, strlen(unit->name)) == 0)
break;
}
return i == ADSP_NUM_FEATURE_ID ? -EINVAL : i;
}
bool adsp_feature_is_active(void)
{
uint32_t fid;
/* not include system feature */
for (fid = 0; fid < ADSP_NUM_FEATURE_ID ; fid++) {
if (adsp_feature_table[fid].counter > 0)
break;
}
return fid == ADSP_NUM_FEATURE_ID ? false : true;
}
int adsp_register_feature(enum adsp_feature_id id)
{
int ret = 0;
if (id >= ADSP_NUM_FEATURE_ID || id < 0)
return -EINVAL;
if (!adsp_feature_table[id].name)
return -EINVAL;
mutex_lock(&adsp_feature_mutex);
if (!adsp_feature_is_active()) {
pr_debug("[%s]%s, adsp_ready=%x\n", __func__,
adsp_feature_table[id].name, is_adsp_ready(ADSP_A_ID));
adsp_stop_suspend_timer();
ret = adsp_resume();
}
if (ret == 0)
adsp_feature_table[id].counter += 1;
mutex_unlock(&adsp_feature_mutex);
return ret;
}
int adsp_deregister_feature(enum adsp_feature_id id)
{
if (id >= ADSP_NUM_FEATURE_ID || id < 0)
return -EINVAL;
if (!adsp_feature_table[id].name)
return -EINVAL;
mutex_lock(&adsp_feature_mutex);
if (adsp_feature_table[id].counter == 0) {
pr_err("[%s] error to deregister id=%d\n", __func__, id);
mutex_unlock(&adsp_feature_mutex);
return -EINVAL;
}
adsp_feature_table[id].counter -= 1;
/* no feature registered, delay 1s and then suspend adsp. */
if (!adsp_feature_is_active() && (is_adsp_ready(ADSP_A_ID) == 1)) {
pr_debug("[%s]%s, adsp_ready=%x\n", __func__,
adsp_feature_table[id].name, is_adsp_ready(ADSP_A_ID));
adsp_start_suspend_timer();
}
mutex_unlock(&adsp_feature_mutex);
return 0;
}
@@ -0,0 +1,189 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2018 MediaTek Inc.
* Author: HsinYi Chang <hsin-yi.chang@mediatek.com>
*/
#ifndef __ADSP_HELPER_H__
#define __ADSP_HELPER_H__
#include <linux/notifier.h>
#include <linux/interrupt.h>
#include "adsp_reg.h"
#include "adsp_feature_define.h"
#include "adsp_reserved_mem.h"
#include "adsp_clk.h"
#define ADSP_SLEEP_ENABLE (1)
/* adsp config reg. definition*/
#define ADSP_A_TCM_SIZE (adspreg.total_tcmsize)
#define ADSP_A_ITCM_SIZE (adspreg.i_tcmsize)
#define ADSP_A_DTCM_SIZE (adspreg.d_tcmsize)
#define ADSP_A_ITCM (adspreg.iram)
#define ADSP_A_DTCM (adspreg.dram)
#define ADSP_A_SYS_DRAM (adspreg.sysram)
#define ADSP_A_CFG (adspreg.cfg)
#define ADSP_A_CFG_SIZE (adspreg.cfgregsize)
#define ADSP_A_DTCM_SHARE_BASE (adspreg.dram + adspreg.d_tcmsize)
#define ADSP_A_DTCM_SHARE_SIZE (0x1000)
#define ADSP_A_MPUINFO_BUFFER (ADSP_A_DTCM_SHARE_BASE - 0x0020)
#define ADSP_A_OSTIMER_BUFFER (ADSP_A_DTCM_SHARE_BASE - 0x0040)
#define ADSP_A_IPC_BUFFER (ADSP_A_DTCM_SHARE_BASE - 0x0280)
#define ADSP_A_AUDIO_IPI_BUFFER (ADSP_A_DTCM_SHARE_BASE - 0x0680)
#define ADSP_A_WAKELOCK_BUFFER (ADSP_A_DTCM_SHARE_BASE - 0x0684)
#define ADSP_A_SYS_STATUS (ADSP_A_DTCM_SHARE_BASE - 0x0688)
#define ADSP_BUS_MON_BACKUP_BASE (ADSP_A_DTCM_SHARE_BASE - 0x0744)
#define ADSP_INFRA_BUS_DUMP_BASE (ADSP_A_DTCM_SHARE_BASE - 0x07E4)
#define ADSP_A_AP_AWAKE (ADSP_A_WAKELOCK_BUFFER)
/* timesync definition */
#define ADSP_TIMESYNC_TICK_H (ADSP_A_OSTIMER_BUFFER + 0)
#define ADSP_TIMESYNC_TICK_L (ADSP_A_OSTIMER_BUFFER + 4)
#define ADSP_TIMESYNC_TS_H (ADSP_A_OSTIMER_BUFFER + 8)
#define ADSP_TIMESYNC_TS_L (ADSP_A_OSTIMER_BUFFER + 12)
#define ADSP_TIMESYNC_FREEZE (ADSP_A_OSTIMER_BUFFER + 16)
/* Non-Cacheable MPU entry start from this ID. */
#define ADSP_MPU_NONCACHE_ID ADSP_A_DEBUG_DUMP_MEM_ID
#define ADSP_MPU_DATA_RO_ID
#define WDT_FIRST_WAIT_COUNT (2)
#define WDT_LAST_WAIT_COUNT (6)
struct adsp_mpu_info_t {
u32 prog_addr;
u32 prog_size;
u32 data_addr;
u32 data_size;
u32 data_non_cache_addr;
u32 data_non_cache_size;
};
/* adsp notify event */
enum ADSP_NOTIFY_EVENT {
ADSP_EVENT_STOP = 0,
ADSP_EVENT_READY,
};
/* adsp reset status */
enum ADSP_RESET_STATUS {
ADSP_RESET_STATUS_STOP = 0,
ADSP_RESET_STATUS_START = 1,
};
enum ADSP_RECOVERY_FLAG {
ADSP_RECOVERY_START,
ADSP_RECOVERY_OK,
};
/* adsp reset status */
enum ADSP_RESET_TYPE {
ADSP_RESET_TYPE_WDT = 0,
ADSP_RESET_TYPE_AWAKE = 1,
};
/* adsp semaphore definition*/
enum semaphore_2way_flag {
SEMA_2WAY_AUDIOREG = 0,
SEMA_2WAY_NUM = 4,
};
#define SEMA_AUDIOREG SEMA_2WAY_AUDIOREG
enum adsp_status {
ADSP_ERROR = -1,
ADSP_OK,
ADSP_SEMAPHORE_BUSY,
};
/* adsp Core ID definition*/
enum adsp_core_id {
ADSP_A_ID = 0,
ADSP_CORE_TOTAL = 1,
};
struct adsp_regs {
void __iomem *adspsys;
void __iomem *iram;
void __iomem *dram;
void __iomem *sysram;
void __iomem *cfg;
void __iomem *clkctrl;
void __iomem *infracfg_ao;
void __iomem *pericfg;
phys_addr_t sharedram;
int wdt_irq;
int ipc_irq;
size_t i_tcmsize;
size_t d_tcmsize;
size_t cfgregsize;
size_t total_tcmsize;
size_t sysram_size;
size_t shared_size;
enum adsp_clk active_clksrc;
};
/* adsp work struct definition*/
struct adsp_work_t {
struct work_struct work;
unsigned int flags;
unsigned int id;
};
/* adsp device attribute group*/
extern struct attribute_group adsp_awake_attr_group;
extern struct attribute_group adsp_dvfs_attr_group;
extern struct attribute_group adsp_logger_attr_group;
extern struct attribute_group adsp_excep_attr_group;
extern struct adsp_regs adspreg;
#ifdef CFG_RECOVERY_SUPPORT
extern atomic_t adsp_reset_status;
extern unsigned int adsp_recovery_flag[ADSP_CORE_TOTAL];
extern struct completion adsp_sys_reset_cp;
extern unsigned int wdt_counter;
extern unsigned char *adsp_A_dram_dump_buffer;
#endif
/* adsp exception */
extern int adsp_excep_init(void);
extern void adsp_excep_cleanup(void);
/* adsp irq */
extern irqreturn_t adsp_A_irq_handler(int irq, void *dev_id);
extern irqreturn_t adsp_A_wdt_handler(int irq, void *dev_id);
extern void adsp_A_irq_init(void);
extern void adsp_A_ipi_init(void);
/* adsp helper */
extern void adsp_A_register_notify(struct notifier_block *nb);
extern void adsp_A_unregister_notify(struct notifier_block *nb);
extern struct workqueue_struct *adsp_workqueue;
extern void adsp_enable_dsp_clk(bool enable);
void adsp_set_emimpu_region(void);
void adsp_bus_sleep_protect(uint32_t enable);
void adsp_way_en_ctrl(uint32_t enable);
extern void adsp_send_reset_wq(enum ADSP_RESET_TYPE type,
enum adsp_core_id core_id);
extern void adsp_extern_notify(enum ADSP_NOTIFY_EVENT notify_status);
extern unsigned int adsp_set_reset_status(void);
extern int is_adsp_ready(uint32_t adsp_id);
extern bool adsp_feature_is_active(void);
void adsp_reset_ready(uint32_t id);
void adsp_A_ready_ipi_handler(int id, void *data, unsigned int len);
extern int get_adsp_semaphore(unsigned int flag);
extern int release_adsp_semaphore(unsigned int flag);
uint32_t adsp_power_on(uint32_t enable);
#endif
@@ -0,0 +1,100 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* adsp_ipi.h -- Mediatek ADSP IPI interface
*
* Copyright (c) 2018 MediaTek Inc.
*/
#ifndef __ADSP_IPI_H
#define __ADSP_IPI_H
#include "adsp_reg.h"
#include "adsp_helper.h"
#define SHARE_BUF_SIZE 288
/* adsp awake timeout count definition*/
#define ADSP_AWAKE_TIMEOUT 5000
#define ADSP_IPI_STAMP_SUPPORT 0
/* adsp ipi ID definition
* need to sync with ADSP-side
*/
enum adsp_ipi_id {
ADSP_IPI_WDT = 0,
ADSP_IPI_TEST1,
ADSP_IPI_LOGGER_ENABLE,
ADSP_IPI_LOGGER_WAKEUP,
ADSP_IPI_LOGGER_INIT_A,
ADSP_IPI_TRAX_ENABLE,
ADSP_IPI_TRAX_DONE,
ADSP_IPI_TRAX_INIT_A,
ADSP_IPI_VOW,
ADSP_IPI_AUDIO,
ADSP_IPI_DVT_TEST,
ADSP_IPI_TIME_SYNC,
ADSP_IPI_CONSYS,
ADSP_IPI_ADSP_A_READY,
ADSP_IPI_APCCCI,
ADSP_IPI_ADSP_A_RAM_DUMP,
ADSP_IPI_DVFS_DEBUG,
ADSP_IPI_DVFS_FIX_OPP_SET,
ADSP_IPI_DVFS_FIX_OPP_EN,
ADSP_IPI_DVFS_LIMIT_OPP_SET,
ADSP_IPI_DVFS_LIMIT_OPP_EN,
ADSP_IPI_DVFS_SUSPEND,
ADSP_IPI_DVFS_SLEEP,
ADSP_IPI_DVFS_WAKE,
ADSP_IPI_DVFS_SET_FREQ,
ADSP_IPI_ADSP_PLL_CTRL = 27,
ADSP_IPI_MET_ADSP = 30,
ADSP_IPI_ADSP_TIMER = 31,
ADSP_NR_IPI,
};
enum adsp_ipi_status {
ADSP_IPI_ERROR = -1,
ADSP_IPI_DONE,
ADSP_IPI_BUSY,
};
struct adsp_ipi_desc {
void (*handler)(int id, void *data, unsigned int len);
const char *name;
};
struct adsp_share_obj {
enum adsp_ipi_id id;
unsigned int len;
unsigned char reserve[8];
unsigned char share_buf[SHARE_BUF_SIZE - 16];
};
extern enum adsp_ipi_status adsp_ipi_registration(enum adsp_ipi_id id,
void (*ipi_handler)(int id,
void *data, unsigned int len),
const char *name);
extern enum adsp_ipi_status adsp_ipi_unregistration(enum adsp_ipi_id id);
extern enum adsp_ipi_status adsp_ipi_send(enum adsp_ipi_id id, void *buf,
unsigned int len, unsigned int wait,
enum adsp_core_id adsp_id);
extern enum adsp_ipi_status adsp_ipi_send_ipc(enum adsp_ipi_id id, void *buf,
unsigned int len, unsigned int wait,
enum adsp_core_id adsp_id);
extern void adsp_A_ipi_handler(void);
extern char *adsp_core_ids[ADSP_CORE_TOTAL];
extern int adsp_awake_lock(enum adsp_core_id adsp_id);
extern int adsp_awake_unlock(enum adsp_core_id adsp_id);
extern void adsp_awake_init(void);
extern int adsp_awake_dump_list(enum adsp_core_id adsp_id);
extern int adsp_awake_force_lock(enum adsp_core_id adsp_id);
extern int adsp_awake_force_unlock(enum adsp_core_id adsp_id);
extern int adsp_awake_set_normal(enum adsp_core_id adsp_id);
extern int adsp_awake_unlock_adsppll(enum adsp_core_id adsp_id,
uint32_t unlock);
#endif
@@ -0,0 +1,199 @@
// SPDX-License-Identifier: GPL-2.0
//
// adsp_plat.c-- Mediatek ADSP platform control
//
// Copyright (c) 2018 MediaTek Inc.
// Author: Celine Liu <Celine.liu@mediatek.com>
#include <linux/module.h> /* needed by all modules */
#include <linux/init.h> /* needed by module macros */
#include <linux/fs.h> /* needed by file_operations* */
#include <linux/miscdevice.h> /* needed by miscdevice* */
#include <linux/sysfs.h>
#include <linux/platform_device.h>
#include <linux/device.h> /* needed by device_* */
#include <linux/vmalloc.h> /* needed by vmalloc */
#include <linux/uaccess.h> /* needed by copy_to_user */
#include <linux/fs.h> /* needed by file_operations* */
#include <linux/slab.h> /* needed by kmalloc */
#include <linux/poll.h> /* needed by poll */
#include <linux/mutex.h>
#include <linux/sched.h>
#include <linux/interrupt.h>
#include <linux/suspend.h>
#include <linux/timer.h>
#include <linux/notifier.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/of_irq.h>
#include <linux/of_fdt.h>
#include <linux/ioport.h>
#ifdef wakelock
#include <linux/wakelock.h>
#endif
#include <linux/io.h>
#include <mt-plat/sync_write.h>
#include <mt-plat/aee.h>
#include <linux/delay.h>
#include "adsp_feature_define.h"
#include "adsp_ipi.h"
#include "adsp_helper.h"
#include "adsp_excep.h"
#include "adsp_dvfs.h"
#include <memory/mediatek/emi.h>
/* emi mpu define */
#define MPU_PROCT_D0_AP 0
#define MPU_PROCT_D10_ADSP 10
#define MPU_PROCT_REGION_ADSP 30
#ifdef CONFIG_ARM64
#define IOMEM(a) ((void __force __iomem *)((a)))
#endif
#define INFRA_AXI_PROT (adspreg.infracfg_ao + 0x0220)
#define INFRA_AXI_PROT_STA1 (adspreg.infracfg_ao + 0x0228)
#define INFRA_AXI_PROT_SET (adspreg.infracfg_ao + 0x02A0)
#define INFRA_AXI_PROT_CLR (adspreg.infracfg_ao + 0x02A4)
#define ADSP_AXI_PROT_MASK (0x1 << 15)
#define ADSP_AXI_PROT_READY_MASK (0x1 << 15)
#define ADSP_WAY_EN_CTRL (adspreg.pericfg + 0x0240)
#define ADSP_WAY_EN_MASK (0x1 << 13)
#define adsp_reg_read(addr) __raw_readl(IOMEM(addr))
#define adsp_reg_sync_write(addr, val) mt_reg_sync_writel(val, addr)
/* adsp has only 1 emimpu region in mt6779 */
void adsp_set_emimpu_region(void)
{
#if ENABLE_ADSP_EMI_PROTECTION
struct emimpu_region_t adsp_region;
int ret = 0;
ret = mtk_emimpu_init_region(&adsp_region,
MPU_PROCT_REGION_ADSP);
if (ret < 0)
pr_info("%s fail to init emimpu region\n", __func__);
mtk_emimpu_set_addr(&adsp_region, adspreg.sharedram,
(adspreg.sharedram + adspreg.shared_size - 0x1));
mtk_emimpu_set_apc(&adsp_region, MPU_PROCT_D0_AP,
MTK_EMIMPU_NO_PROTECTION);
mtk_emimpu_set_apc(&adsp_region, MPU_PROCT_D10_ADSP,
MTK_EMIMPU_NO_PROTECTION);
ret = mtk_emimpu_set_protection(&adsp_region);
if (ret < 0)
pr_info("%s fail to set emimpu protection\n", __func__);
mtk_emimpu_free_region(&adsp_region);
#endif
}
static bool is_adsp_bus_protect_ready(void)
{
return ((adsp_reg_read(INFRA_AXI_PROT_STA1) & ADSP_AXI_PROT_READY_MASK)
== ADSP_AXI_PROT_READY_MASK);
}
void adsp_bus_sleep_protect(uint32_t enable)
{
int timeout = 1000;
if (enable) {
/* enable adsp bus protect */
adsp_reg_sync_write(INFRA_AXI_PROT_SET, ADSP_AXI_PROT_MASK);
while (--timeout && !is_adsp_bus_protect_ready())
udelay(1);
if (!is_adsp_bus_protect_ready())
pr_err("%s() ready timeout\n", __func__);
} else {
/* disable adsp bus protect */
adsp_reg_sync_write(INFRA_AXI_PROT_CLR, ADSP_AXI_PROT_MASK);
}
}
void adsp_way_en_ctrl(uint32_t enable)
{
if (enable)
adsp_reg_sync_write(ADSP_WAY_EN_CTRL,
adsp_reg_read(ADSP_WAY_EN_CTRL) | ADSP_WAY_EN_MASK);
else
adsp_reg_sync_write(ADSP_WAY_EN_CTRL,
adsp_reg_read(ADSP_WAY_EN_CTRL) & ~ADSP_WAY_EN_MASK);
}
#define SEMAPHORE_TIMEOUT 5000
/*
* acquire a hardware semaphore
* @param flag: semaphore id
* return ADSP_OK: get sema success
* ADSP_ERROR: adsp is disabled
* ADSP_SEMAPHORE_BUSY: release sema fail
*/
int get_adsp_semaphore(unsigned int flag)
{
int read_back;
int count = 0;
int ret = ADSP_SEMAPHORE_BUSY;
/* return 1 to prevent from access when driver not ready */
if (is_adsp_ready(ADSP_A_ID) != 1)
return ADSP_ERROR;
flag = (flag * 2) + 1;
read_back = (readl(ADSP_SEMAPHORE) >> flag) & 0x1;
if (read_back == 0) {
writel((1 << flag), ADSP_SEMAPHORE);
while (count != SEMAPHORE_TIMEOUT) {
/* repeat test if we get semaphore */
read_back = (readl(ADSP_SEMAPHORE) >> flag) & 0x1;
if (read_back == 1) {
ret = ADSP_OK;
break;
}
writel((1 << flag), ADSP_SEMAPHORE);
count++;
}
if (ret)
pr_debug("[ADSP] get adsp sema. %d TIMEOUT..!\n", flag);
} else
pr_debug("[ADSP] already hold adsp sema. %d\n", flag);
return ret;
}
/*
* release a hardware semaphore
* @param flag: semaphore id
* return ADSP_OK: release sema success
* ADSP_ERROR: adsp is disabled
* ADSP_SEMAPHORE_BUSY: release sema fail
*/
int release_adsp_semaphore(unsigned int flag)
{
int read_back;
int ret = ADSP_SEMAPHORE_BUSY;
/* return 1 to prevent from access when driver not ready */
if (is_adsp_ready(ADSP_A_ID) != 1)
return ADSP_ERROR;
flag = (flag * 2) + 1;
read_back = (readl(ADSP_SEMAPHORE) >> flag) & 0x1;
if (read_back == 1) {
/* Write 1 clear */
writel((1 << flag), ADSP_SEMAPHORE);
read_back = (readl(ADSP_SEMAPHORE) >> flag) & 0x1;
if (read_back == 0)
ret = ADSP_OK;
else
pr_debug("[ADSP] %s %d failed\n", __func__, flag);
} else
pr_debug("[ADSP] %s %d not own by me\n", __func__, flag);
return ret;
}
@@ -0,0 +1,130 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* adsp_reg.h -- Mediatek ADSP HW register
*
* Copyright (c) 2018 MediaTek Inc.
*/
#ifndef __ADSP_REG_H
#define __ADSP_REG_H
/*#define ADSP_BASE (adspreg.cfg)*/
#define ADSP_A_REBOOT (adspreg.cfg + 0x00)
#define ADSP_A_SW_RSTN (1 << 0)
#define ADSP_A_SW_DBG_RSTN (1 << 4)
#define ADSP_A_IO_CONFIG (adspreg.cfg + 0x0008)
#define ADSP_HIFI3_IO_CONFIG ADSP_A_IO_CONFIG
#define ADSP_RELEASE_RUNSTALL (1 << 31)
#define ADSP_SWINT_REG (adspreg.cfg + 0x001C) //sw int set
#define ADSP_SW_INT0 (0)
#define ADSP_SW_INT1 (1)
#define ADSP_SW_INT2 (2)
#define ADSP_SW_INT3 (3)
#define HOST_TO_ADSP_A (1 << 0)
#define ADSP_A_TO_HOST_REG (adspreg.cfg + 0x0038) //syscirq_clr
#define ADSP_IRQ_ADSP2HOST (1 << 0)
#define ADSP_A_DVFSRC_STATE (adspreg.cfg + 0x003C)
#define ADSP_A_DVFSRC_REQ (adspreg.cfg + 0x0040)
#define ADSP_A_DDREN_REQ (adspreg.cfg + 0x0044)
#define ADSP_A_DDR_REQ_SEL (0x3 << 4) // hw auto ddren
#define ADSP_A_DDR_ENABLE (1 << 0)
#define ADSP_A_SPM_REQ (adspreg.cfg + 0x0048)
#define ADSP_A_SPM_ACK (adspreg.cfg + 0x004C)
#define ADSP_A_SPM_SRC_BITS (0xF << 0)
#define ADSP_A_IRQ_EN (adspreg.cfg + 0x0050)
#define ADSP_TO_SPM_REG (adspreg.cfg + 0x005C) //spm wakeup
#define ADSP_SEMAPHORE (adspreg.cfg + 0x0058)
#define ADSP_A_WDT_REG (adspreg.cfg + 0x007C)
#define ADSP_A_WDT_INIT_VALUE (adspreg.cfg + 0x0080)
#define ADSP_A_WDT_CNT (adspreg.cfg + 0x0084)
#define ADSP_WDT_TRIGGER (ADSP_A_WDT_INIT_VALUE)
#define WDT_EN_BIT (1 << 31)
#define WDT_DIS_BIT (0 << 31)
#define WDT_KICK_BIT 0
#define ADSP_CFGREG_RSV_RW_REG0 (adspreg.cfg + 0x008C)
#define ADSP_CFGREG_RSV_RW_REG1 (adspreg.cfg + 0x0090)
#define ADSP_CFGREG_RSV_RW_REG2 (adspreg.cfg + 0x0094)
#define ADSP_SEGMENT_CON ADSP_CFGREG_RSV_RW_REG2
/* Latch Debug info after WDT */
#define ADSP_A_WDT_DEBUG_PC_REG (adspreg.cfg + 0x0170)
#define ADSP_A_WDT_DEBUG_SP_REG (adspreg.cfg + 0x0174)
/* TODO : add in aee dump */
#define ADSP_A_WDT_EXCVADDR_REG (adspreg.cfg + 0x0178)
/* TODO : add in aee dump */
#define ADSP_A_WDT_EXCCAUSE_REG (adspreg.cfg + 0x017C)
/* Wakeup ADSP interrupt */
#define ADSP_WAKEUPSRC_MASK (adspreg.cfg + 0x00A8)
#define ADSP_WAKEUPSRC_IRQ (adspreg.cfg + 0x00AC)
/*latency monitor*/
#define ADSP_LATMON_DVFS_MODE (adspreg.cfg + 0x0100)
#define ADSP_LATMON_CON1 (adspreg.cfg + 0x0104)
#define ADSP_LATMON_CON2 (adspreg.cfg + 0x0108)
#define ADSP_LATMON_MARGIN (adspreg.cfg + 0x010C)
#define ADSP_LATMON_THRESHOLD (adspreg.cfg + 0x0110)
#define ADSP_LATMON_STATE (adspreg.cfg + 0x0114)
#define ADSP_LATMON_ACCCNT (adspreg.cfg + 0x0118)
/* latency threshold & budget for 0.8V. 0.7V. 0.625V */
#define ADSP_LATMON_CONT0 (adspreg.cfg + 0x012C)
#define ADSP_LATMON_CONT1 (adspreg.cfg + 0x0130)
#define ADSP_LATMON_CONT2 (adspreg.cfg + 0x0134)
#define ADSP_A_DEBUG_PC_REG (adspreg.cfg + 0x013C)
#define ADSP_DBG_PEND_CNT (adspreg.cfg + 0x015C)
#define ADSP_SLEEP_STATUS_REG (adspreg.cfg + 0x0158)
#define ADSP_BUS_MON_BASE (adspreg.cfg + 0x5000)
/* adsp power state*/
#define ADSP_A_IS_RESET (0x00)
#define ADSP_A_IS_ACTIVE (0x10)
#define ADSP_A_IS_WFI (0x20)
/* adsp current state */
#define ADSP_A_CUR_RESET (0x0)
#define ADSP_A_CUR_STALL (0x1)
#define ADSP_A_CUR_ACTIVE (0x3)
#define ADSP_A_CUR_WFI (0x4)
#define ADSP_A_CUR_WAKEUP (0x5) //Wakeup state (Receive irq)
#define ADSP_A_AXI_BUS_IS_IDLE (1 << 1)
/* clk reg */
#define ADSP_CLK_CTRL_OFFSET (0x1000)
#define ADSP_CLK_CTRL_BASE (adspreg.clkctrl)
#define ADSP_CLK_UART_EN (1 << 5)
#define ADSP_CLK_DMA_EN (1 << 4)
#define ADSP_CLK_TIMER_EN (1 << 3)
#define ADSP_MCLK_DIV_REG (adspreg.clkctrl + 0x0004)
#define ADSP_MCLK_DIV_MASK (0x3 << 0)
#define ADSP_UART_CTRL (adspreg.clkctrl + 0x0010)
#define ADSP_UART_RST_N (1 << 3)
#define ADSP_UART_CLK_SEL (1 << 1)
#define ADSP_UART_BCLK_CG (1 << 0)
#define ADSP_A_SLEEP_DEBUG_REG (adspreg.clkctrl + 0x0028)
#define ADSP_CLK_HIGH_CORE_CG (adspreg.clkctrl + 0x005C)
/* INFRA_IRQ (always on register) */
#define AP_AWAKE_LOCK_BIT (0)
#define AP_AWAKE_UNLOCK_BIT (1)
#define CONNSYS_AWAKE_LOCK (2)
#define CONNSYS_AWAKE_UNLOCK (3)
#define AP_AWAKE_DUMP_BIT (4)
#define AP_AWAKE_UPDATE_BIT (5)
#define AP_AWAKE_STATE_BIT (6)
#define ADSPPLL_UNLOCK_BIT (8)
#define ADSP_ADSP2SPM_VOL_LV (adspreg.cfg + 0x0094)
#endif
@@ -0,0 +1,165 @@
// SPDX-License-Identifier: GPL-2.0
//
// adsp_reserved_mem.c-- Mediatek ADSP memory control
//
// Copyright (c) 2018 MediaTek Inc.
// Author: Celine Liu <Celine.liu@mediatek.com>
#include <linux/io.h>
#include "adsp_reserved_mem.h"
#include "adsp_helper.h"
#ifdef CONFIG_OF_RESERVED_MEM
#include <linux/of.h>
#include <linux/of_reserved_mem.h>
#endif
#define ADSP_RESERVE_MEMORY_BLOCK(xsize) {.phys_addr = 0x0, .virt_addr = NULL, \
.size = xsize}
static struct adsp_reserve_mblock adsp_reserve_mem = {0};
static struct adsp_reserve_mblock adsp_reserve_mblocks[] = {
#ifdef FPGA_EARLY_DEVELOPMENT
[ADSP_A_SYSTEM_MEM_ID] = ADSP_RESERVE_MEMORY_BLOCK(0x40000),
[ADSP_A_IPI_MEM_ID] = ADSP_RESERVE_MEMORY_BLOCK(0x80000),
[ADSP_A_LOGGER_MEM_ID] = ADSP_RESERVE_MEMORY_BLOCK(0x80000),
[ADSP_A_DEBUG_DUMP_MEM_ID] = ADSP_RESERVE_MEMORY_BLOCK(0x80000),
[ADSP_A_CORE_DUMP_MEM_ID] = ADSP_RESERVE_MEMORY_BLOCK(0x400),
#else
[ADSP_A_SYSTEM_MEM_ID] = ADSP_RESERVE_MEMORY_BLOCK(0x700000),
[ADSP_A_IPI_MEM_ID] = ADSP_RESERVE_MEMORY_BLOCK(0x500000),
[ADSP_A_LOGGER_MEM_ID] = ADSP_RESERVE_MEMORY_BLOCK(0x200000),
[ADSP_A_TRAX_MEM_ID] = ADSP_RESERVE_MEMORY_BLOCK(0x1000),
[ADSP_SPK_PROTECT_MEM_ID] = ADSP_RESERVE_MEMORY_BLOCK(0x20000),
[ADSP_VOIP_MEM_ID] = ADSP_RESERVE_MEMORY_BLOCK(0x30000),
[ADSP_A2DP_PLAYBACK_MEM_ID] = ADSP_RESERVE_MEMORY_BLOCK(0x40000),
[ADSP_OFFLOAD_MEM_ID] = ADSP_RESERVE_MEMORY_BLOCK(0x400000),
[ADSP_EFFECT_MEM_ID] = ADSP_RESERVE_MEMORY_BLOCK(0x60000),
[ADSP_VOICE_CALL_MEM_ID] = ADSP_RESERVE_MEMORY_BLOCK(0x60000),
[ADSP_AFE_MEM_ID] = ADSP_RESERVE_MEMORY_BLOCK(0x40000),
[ADSP_PLAYBACK_MEM_ID] = ADSP_RESERVE_MEMORY_BLOCK(0x30000),
[ADSP_DEEPBUF_MEM_ID] = ADSP_RESERVE_MEMORY_BLOCK(0x30000),
[ADSP_PRIMARY_MEM_ID] = ADSP_RESERVE_MEMORY_BLOCK(0x30000),
[ADSP_CAPTURE_UL1_MEM_ID] = ADSP_RESERVE_MEMORY_BLOCK(0x20000),
[ADSP_DATAPROVIDER_MEM_ID] = ADSP_RESERVE_MEMORY_BLOCK(0x30000),
[ADSP_CALL_FINAL_MEM_ID] = ADSP_RESERVE_MEMORY_BLOCK(0x30000),
[ADSP_KTV_MEM_ID] = ADSP_RESERVE_MEMORY_BLOCK(0x30000),
[ADSP_CAPTURE_RAW_MEM_ID] = ADSP_RESERVE_MEMORY_BLOCK(0x20000),
[ADSP_A_DEBUG_DUMP_MEM_ID] = ADSP_RESERVE_MEMORY_BLOCK(0x80000),
[ADSP_A_CORE_DUMP_MEM_ID] = ADSP_RESERVE_MEMORY_BLOCK(0x400),
#endif
};
static struct adsp_reserve_mblock *adsp_get_reserve_mblock(
enum adsp_reserve_mem_id_t id)
{
if (id >= ADSP_NUMS_MEM_ID) {
pr_info("[ADSP] no reserve memory for %d", id);
return NULL;
}
return &adsp_reserve_mblocks[id];
}
int adsp_set_reserve_mblock(
enum adsp_reserve_mem_id_t id, phys_addr_t phys_addr,
void *virt_addr, size_t size)
{
if (id >= ADSP_NUMS_MEM_ID || id < 0) {
pr_info("[ADSP] no reserve memory for %d", id);
return -1;
}
adsp_reserve_mblocks[id].phys_addr = phys_addr;
adsp_reserve_mblocks[id].virt_addr = virt_addr;
adsp_reserve_mblocks[id].size = size;
return 0;
}
phys_addr_t adsp_get_reserve_mem_phys(enum adsp_reserve_mem_id_t id)
{
struct adsp_reserve_mblock *mblk = adsp_get_reserve_mblock(id);
return mblk ? mblk->phys_addr : 0;
}
void *adsp_get_reserve_mem_virt(enum adsp_reserve_mem_id_t id)
{
struct adsp_reserve_mblock *mblk = adsp_get_reserve_mblock(id);
return mblk ? mblk->virt_addr : NULL;
}
size_t adsp_get_reserve_mem_size(enum adsp_reserve_mem_id_t id)
{
struct adsp_reserve_mblock *mblk = adsp_get_reserve_mblock(id);
return mblk ? mblk->size : 0;
}
void *adsp_reserve_memory_ioremap(phys_addr_t phys_addr, size_t size)
{
enum adsp_reserve_mem_id_t id;
struct adsp_reserve_mblock *mem = &adsp_reserve_mem;
size_t acc_size = 0;
if (!phys_addr || !size) {
pr_info("[ADSP] set reserve memory illegal addr:%llu, size:%zu",
phys_addr, size);
return NULL;
}
mem->phys_addr = phys_addr;
mem->size = size;
mem->virt_addr = ioremap_wc(mem->phys_addr, mem->size);
if (!mem->virt_addr)
return NULL;
/* assign to each memory block */
for (id = ADSP_A_SHARED_MEM_BEGIN; id < ADSP_NUMS_MEM_ID; id++) {
adsp_reserve_mblocks[id].phys_addr = mem->phys_addr + acc_size;
adsp_reserve_mblocks[id].virt_addr = mem->virt_addr + acc_size;
acc_size += adsp_reserve_mblocks[id].size;
}
WARN_ON(acc_size > mem->size);
return mem->virt_addr;
}
ssize_t adsp_reserve_memory_dump(char *buffer, int size)
{
int n = 0, i = 0;
struct adsp_reserve_mblock *mem = &adsp_reserve_mem;
n += scnprintf(buffer + n, size - n,
"Reserve-memory-all:0x%llx 0x%p 0x%zx\n",
mem->phys_addr, mem->virt_addr, mem->size);
for (i = 0; i < ADSP_NUMS_MEM_ID; i++) {
mem = &adsp_reserve_mblocks[i];
n += scnprintf(buffer + n, size - n,
"Reserve-memory-Block[%02d]:0x%llx 0x%p 0x%zx\n",
i, mem->phys_addr, mem->virt_addr, mem->size);
}
return n;
}
#ifdef CONFIG_OF_RESERVED_MEM
#define ADSP_MEM_RESERVED_KEY "mediatek,reserve-memory-adsp_share"
static int __init adsp_reserve_mem_of_init(struct reserved_mem *rmem)
{
adspreg.sharedram = (phys_addr_t) rmem->base;
adspreg.shared_size = (size_t) rmem->size;
return 0;
}
RESERVEDMEM_OF_DECLARE(adsp_reserve_mem_init,
ADSP_MEM_RESERVED_KEY, adsp_reserve_mem_of_init);
#endif /* defined(CONFIG_OF_RESERVED_MEM) */
@@ -0,0 +1,60 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* adsp_reserved_mem.h -- Mediatek ADSP memory control
*
* Copyright (c) 2018 MediaTek Inc.
* Author: Celine Liu <Celine.liu@mediatek.com>
*/
#ifndef __ADSP_RESERVEDMEM_DEFINE_H__
#define __ADSP_RESERVEDMEM_DEFINE_H__
//#define FPGA_EARLY_DEVELOPMENT
/* adsp reserve memory ID definition*/
enum adsp_reserve_mem_id_t {
ADSP_A_SYSTEM_MEM_ID, /*not for share, reserved for system*/
ADSP_A_IPI_MEM_ID,
ADSP_A_LOGGER_MEM_ID,
#ifndef FPGA_EARLY_DEVELOPMENT
ADSP_A_TRAX_MEM_ID,
ADSP_SPK_PROTECT_MEM_ID,
ADSP_VOIP_MEM_ID,
ADSP_A2DP_PLAYBACK_MEM_ID,
ADSP_OFFLOAD_MEM_ID,
ADSP_EFFECT_MEM_ID,
ADSP_VOICE_CALL_MEM_ID,
ADSP_AFE_MEM_ID,
ADSP_PLAYBACK_MEM_ID,
ADSP_DEEPBUF_MEM_ID,
ADSP_PRIMARY_MEM_ID,
ADSP_CAPTURE_UL1_MEM_ID,
ADSP_DATAPROVIDER_MEM_ID,
ADSP_CALL_FINAL_MEM_ID,
ADSP_KTV_MEM_ID,
ADSP_CAPTURE_RAW_MEM_ID,
#endif
ADSP_A_DEBUG_DUMP_MEM_ID,
ADSP_A_CORE_DUMP_MEM_ID,
ADSP_NUMS_MEM_ID,
ADSP_A_SHARED_MEM_BEGIN = ADSP_A_IPI_MEM_ID,
ADSP_A_SHARED_MEM_END = ADSP_A_CORE_DUMP_MEM_ID,
};
struct adsp_reserve_mblock {
phys_addr_t phys_addr;
void *virt_addr;
size_t size;
};
/* Reserved Memory Method */
phys_addr_t adsp_get_reserve_mem_phys(enum adsp_reserve_mem_id_t id);
void *adsp_get_reserve_mem_virt(enum adsp_reserve_mem_id_t id);
size_t adsp_get_reserve_mem_size(enum adsp_reserve_mem_id_t id);
int adsp_set_reserve_mblock(
enum adsp_reserve_mem_id_t id, phys_addr_t phys_addr,
void *virt_addr, size_t size);
void *adsp_reserve_memory_ioremap(phys_addr_t phys_addr, size_t size);
ssize_t adsp_reserve_memory_dump(char *buffer, int size);
#endif /* __ADSP_RESERVEDMEM_DEFINE_H__ */
@@ -0,0 +1,25 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* adsp_service.h -- Mediatek ADSP service for ioctrl handling
*
* Copyright (c) 2018 MediaTek Inc.
* Author: HsinYi Chang <hsin-yi.chang@mediatek.com>
*/
#ifndef __ADSP_SERVICE_H__
#define __ADSP_SERVICE_H__
#include <linux/notifier.h>
#include <linux/interrupt.h>
#include "adsp_reg.h"
#include "adsp_feature_define.h"
#include "adsp_ipi.h"
void adsp_read_status_release(const unsigned long dsp_event);
void reset_hal_feature_table(void);
long adsp_driver_ioctl(
struct file *file, unsigned int cmd, unsigned long arg);
long adsp_driver_compat_ioctl(
struct file *file, unsigned int cmd, unsigned long arg);
#endif
@@ -0,0 +1,28 @@
# SPDX-License-Identifier: GPL-2.0
ADSP_VERSION := common_v2
ADSP_VERSION_PATH := ../$(ADSP_VERSION)
ifeq ($(CONFIG_MACH_MT6781),y)
AUDIO_PLATFORM := mt6781
endif
obj-y += $(ADSP_VERSION_PATH)/
obj-y += adsp_awake.o
obj-y += adsp_clk.o
obj-y += adsp_bus_monitor.o
obj-y += adsp_reserved_mem.o
obj-y += adsp_platform_driver.o adsp_platform.o
obj-y += adsp_ipi.o
obj-y += adsp_excep.o
ccflags-y += -I$(srctree)/drivers/misc/mediatek/adsp/common_v2
ccflags-y += -I$(srctree)/drivers/misc/mediatek/audio_ipi/common_v2/framework
ccflags-y += -I$(srctree)/drivers/misc/mediatek/include/mt-plat/$(CONFIG_MTK_PLATFORM)/include/mach
ccflags-y += -I$(srctree)/drivers/misc/mediatek/emi/submodule
ccflags-y += -I$(srctree)/drivers/misc/mediatek/emi/$(CONFIG_MTK_PLATFORM)
ccflags-y += -I$(srctree)/sound/soc/mediatek/$(AUDIO_PLATFORM)
ifeq ($(CONFIG_MTK_ENG_BUILD),y)
CFLAGS_adsp_excep.o += -DDEBUG
endif
@@ -0,0 +1,132 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#include <linux/io.h>
#include <linux/mutex.h>
#include <linux/ktime.h>
#include "adsp_core.h"
#include "adsp_platform.h"
#include "adsp_platform_driver.h"
#include "adsp_reg.h"
#ifdef ADSP_BASE
#undef ADSP_BASE
#endif
#define ADSP_BASE (pdata->cfg)
#define AP_AWAKE_LOCK_MASK (0x1 << AP_AWAKE_LOCK_BIT)
#define AP_AWAKE_UNLOCK_MASK (0x1 << AP_AWAKE_UNLOCK_BIT)
struct adsp_sysevent_ctrl {
struct adsp_priv *pdata;
struct mutex lock;
void __iomem *swint;
u32 mask;
};
static struct adsp_sysevent_ctrl sysevent_ctrls[ADSP_CORE_TOTAL];
static int adsp_send_sys_event(struct adsp_sysevent_ctrl *ctrl,
u32 event, bool wait)
{
ktime_t start_time;
s64 time_ipc_us;
if (mutex_trylock(&ctrl->lock) == 0) {
pr_info("%s(), mutex_trylock busy", __func__);
return ADSP_IPI_BUSY;
}
if (readl(ctrl->swint) & ctrl->mask) {
mutex_unlock(&ctrl->lock);
return ADSP_IPI_BUSY;
}
adsp_copy_to_sharedmem(ctrl->pdata, ADSP_SHAREDMEM_WAKELOCK,
&event, sizeof(event));
writel(ctrl->mask, ctrl->swint);
if (wait) {
start_time = ktime_get();
while (readl(ctrl->swint) & ctrl->mask) {
time_ipc_us = ktime_us_delta(ktime_get(), start_time);
if (time_ipc_us > 1000) /* 1 ms */
break;
}
}
mutex_unlock(&ctrl->lock);
return ADSP_IPI_DONE;
}
int adsp_awake_init(struct adsp_priv *pdata, u32 mask)
{
struct adsp_sysevent_ctrl *ctrl;
if (!pdata)
return -EINVAL;
ctrl = &sysevent_ctrls[pdata->id];
ctrl->pdata = pdata;
ctrl->swint = ADSP_SW_INT_SET;
ctrl->mask = mask;
mutex_init(&ctrl->lock);
return 0;
}
/*
* acquire adsp lock flag, keep adsp awake
* @param adsp_id: adsp core id
* return 0 : get lock success
* non-0 : get lock fail
*/
int adsp_awake_lock(u32 cid)
{
int ret = -1;
uint32_t val = 0;
if (cid >= ADSP_CORE_TOTAL)
return -EINVAL;
if (!is_adsp_ready(cid) || !adsp_feature_is_active(cid))
return -ENODEV;
val = AP_AWAKE_LOCK_MASK;
ret = adsp_send_sys_event(&sysevent_ctrls[cid], val, true);
if (ret)
pr_info("%s, lock fail", __func__);
return ret;
}
/*
* release adsp awake lock flag
* @param adsp_id: adsp core id
* return 0 : release lock success
* non-0 : release lock fail
*/
int adsp_awake_unlock(u32 cid)
{
int ret = -1;
uint32_t val = 0;
if (cid >= ADSP_CORE_TOTAL)
return -EINVAL;
if (!is_adsp_ready(cid) || !adsp_feature_is_active(cid))
return -ENODEV;
val = AP_AWAKE_UNLOCK_MASK;
ret = adsp_send_sys_event(&sysevent_ctrls[cid], val, true);
if (ret)
pr_info("%s, unlock fail", __func__);
return ret;
}
@@ -0,0 +1,93 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#include <linux/io.h>
#include "adsp_bus_monitor.h"
#include "adsp_helper.h"
#include "adsp_core.h"
#include "adsp_platform_driver.h"
#ifdef ADSP_BASE
#undef ADSP_BASE
#endif
#define ADSP_BASE mt_base
#define ADSP_BUS_MON_BACKUP_BASE mt_bus_backup_base
/**
* TIMEOUT_VALUE = value * unit(15 cycle count) / clk_src
*/
#define BUS_MON_STAGE1_TIMEOUT_VALUE (0x01DA0A2B) /* 1.00 sec @ 466MHz */
#define BUS_MON_STAGE2_TIMEOUT_VALUE (0x03B41456) /* 2.00 sec @ 466MHz */
#define ADSP_BUS_MON_STATE (ADSP_BUS_MON_BACKUP_BASE)
#define ADSP_BUS_MON_1ST_STAGE_BASE (ADSP_BUS_MON_BACKUP_BASE + sizeof(u32))
#define ADSP_BUS_MON_2ND_STAGE_BASE (ADSP_BUS_MON_1ST_STAGE_BASE + \
sizeof(struct bus_monitor_cblk))
#define ADSP_BUS_MON_BACKUP_SIZE (sizeof(u32) + \
2 * sizeof(struct bus_monitor_cblk))
static void __iomem *mt_base;
static void __iomem *mt_bus_backup_base;
int adsp_bus_monitor_init(struct adsp_priv *pdata)
{
if (unlikely(!pdata))
return -EINVAL;
mt_base = pdata->cfg;
mt_bus_backup_base = adsp_get_sharedmem_base(pdata,
ADSP_SHAREDMEM_BUS_MON_DUMP);
/* Clear bus monitor register backup in DTCM */
memset_io((void *)ADSP_BUS_MON_BACKUP_BASE, 0,
(size_t)ADSP_BUS_MON_BACKUP_SIZE);
/* initialize bus monitor */
writel(0xacce55, ADSP_BUS_DBG_EN_LOCK);
writel(0x00011080, ADSP_BUS_DBG_CON); /* reset bus tracker */
writel(BUS_MON_STAGE1_TIMEOUT_VALUE, ADSP_BUS_DBG_TIMER_CON0);
writel(BUS_MON_STAGE2_TIMEOUT_VALUE, ADSP_BUS_DBG_TIMER_CON1);
writel(0x0, ADSP_BUS_DBG_WP);
writel(0x0, ADSP_BUS_DBG_WP_MASK);
writel(0x00002037, ADSP_BUS_DBG_CON); /* timeout control */
writel(STAGE_RUN, ADSP_BUS_MON_STATE);
return 0;
}
bool is_adsp_bus_monitor_alert(void)
{
return readl(ADSP_BUS_MON_STATE) > STAGE_RUN;
}
static void adsp_bus_monitor_stage_info(void *addr)
{
int i = 0;
struct bus_monitor_cblk cblk;
memcpy_fromio(&cblk, addr, sizeof(struct bus_monitor_cblk));
pr_info("BUS_DBG_CON = 0x%08x", cblk.ctrl);
pr_info("TIMER_CON0 = 0x%08x, TIMER_CON01 = 0x%08x",
cblk.timer_ctrl[0], cblk.timer_ctrl[1]);
for (i = 0; i < 8; i++) {
if (!cblk.r_tracks[i] && !cblk.w_tracks[i])
continue;
pr_info("R_TRACK[%d] = 0x%08x, W_TRACK[%d] = 0x%08x",
i, cblk.r_tracks[i],
i, cblk.w_tracks[i]);
}
}
void adsp_bus_monitor_dump(void)
{
pr_info("%s(), BUS_MON_1ST_STAGE BACKUP", __func__);
adsp_bus_monitor_stage_info((void *)ADSP_BUS_MON_1ST_STAGE_BASE);
pr_info("%s(), BUS_MON_2ST_STAGE BACKUP", __func__);
adsp_bus_monitor_stage_info((void *)ADSP_BUS_MON_2ND_STAGE_BASE);
}
@@ -0,0 +1,47 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __ADSP_BUS_MONITOR_H__
#define __ADSP_BUS_MONITOR_H__
#include "adsp_reg.h"
/* bus monitor registers */
#define ADSP_BUS_DBG_CON (ADSP_BUS_MON_BASE + 0x0000)
#define ADSP_BUS_DBG_TIMER_CON0 (ADSP_BUS_MON_BASE + 0x0004)
#define ADSP_BUS_DBG_TIMER_CON1 (ADSP_BUS_MON_BASE + 0x0008)
#define ADSP_BUS_DBG_TIMER0 (ADSP_BUS_MON_BASE + 0x000C)
#define ADSP_BUS_DBG_TIMER1 (ADSP_BUS_MON_BASE + 0x0010)
#define ADSP_BUS_DBG_WP (ADSP_BUS_MON_BASE + 0x0014)
#define ADSP_BUS_DBG_WP_MASK (ADSP_BUS_MON_BASE + 0x0018)
#define ADSP_BUS_DBG_EN_LOCK (ADSP_BUS_MON_BASE + 0x0024)
/* bus monitor enum */
enum bus_monitor_stage {
STAGE_OFF = 0,
STAGE_RUN = 1,
STAGE_1ST = 2,
STAGE_2ND = 3,
};
/* bus monitor structure */
struct bus_monitor_cblk { /* hw related */
u32 ctrl;
u32 timer_ctrl[2];
u32 timer_dbg[2];
u32 watch_point_addr;
u32 watch_point_mask;
u32 r_tracks[8]; /* read tracker 8 channel in hw */
u32 w_tracks[8]; /* write tracker 8 channel in hw */
};
struct adsp_priv;
/* bus monitor methods, be care all of them need adsp clk on */
int adsp_bus_monitor_init(struct adsp_priv *pdata);
bool is_adsp_bus_monitor_alert(void);
void adsp_bus_monitor_dump(void);
#endif
@@ -0,0 +1,133 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#include <linux/clk.h>
#include "adsp_clk.h"
#include "adsp_platform.h"
static uint32_t adsp_clock_count;
DEFINE_SPINLOCK(adsp_clock_spinlock);
struct adsp_clock_attr {
const char *name;
struct clk *clock;
};
static struct adsp_clock_attr adsp_clks[ADSP_CLK_NUM] = {
[CLK_ADSP_INFRA] = {"clk_adsp_infra", NULL},
[CLK_ADSP_INFRA_26M] = {"clk_adsp_infra_26m", NULL},
[CLK_ADSP_INFRA_32K] = {"clk_adsp_infra_32k", NULL},
[CLK_TOP_ADSP_SEL] = {"clk_top_adsp_sel", NULL},
[CLK_TOP_CLK26M] = {"clk_adsp_clk26m", NULL},
[CLK_TOP_ADSPPLL] = {"clk_top_adsppll_ck", NULL},
};
int adsp_set_top_mux(enum adsp_clk clk)
{
int ret = 0;
pr_debug("%s(%x)\n", __func__, clk);
if (clk >= ADSP_CLK_NUM || clk < 0)
return -EINVAL;
ret = clk_set_parent(adsp_clks[CLK_TOP_ADSP_SEL].clock,
adsp_clks[clk].clock);
if (IS_ERR(&ret))
pr_err("%s() clk_set_parent(clk_top_adsp_sel-%x) fail %d\n",
__func__, clk, ret);
return ret;
}
void adsp_set_clock_freq(enum adsp_clk clk)
{
switch (clk) {
case CLK_TOP_CLK26M:
case CLK_TOP_ADSPPLL:
adsp_set_top_mux(clk);
break;
default:
break;
}
}
/* clock init */
int adsp_clk_device_probe(struct platform_device *pdev)
{
int ret = 0;
size_t i;
struct device *dev = &pdev->dev;
for (i = 0; i < ARRAY_SIZE(adsp_clks); i++) {
adsp_clks[i].clock = devm_clk_get(dev, adsp_clks[i].name);
if (IS_ERR(adsp_clks[i].clock)) {
ret = PTR_ERR(adsp_clks[i].clock);
pr_err("%s devm_clk_get %s fail %d\n", __func__,
adsp_clks[i].name, ret);
}
}
return ret;
}
/* clock deinit */
void adsp_clk_device_remove(void *dev)
{
pr_info("%s\n", __func__);
}
int adsp_enable_clock(void)
{
int ret = 0;
unsigned long spin_flags;
pr_info("%s()\n", __func__);
spin_lock_irqsave(&adsp_clock_spinlock, spin_flags);
if (++adsp_clock_count == 1)
/* unable to access adsp sram before set way_en to 1 */
adsp_way_en_ctrl(1);
spin_unlock_irqrestore(&adsp_clock_spinlock, spin_flags);
ret = clk_prepare_enable(adsp_clks[CLK_ADSP_INFRA_26M].clock);
if (IS_ERR(&ret)) {
pr_err("%s(), clk_prepare_enable %s fail, ret %d\n",
__func__, adsp_clks[CLK_ADSP_INFRA_26M].name, ret);
return -EINVAL;
}
ret = clk_prepare_enable(adsp_clks[CLK_ADSP_INFRA_32K].clock);
if (IS_ERR(&ret)) {
pr_err("%s(), clk_prepare_enable %s fail, ret %d\n",
__func__, adsp_clks[CLK_ADSP_INFRA_32K].name, ret);
return -EINVAL;
}
ret = clk_prepare_enable(adsp_clks[CLK_ADSP_INFRA].clock);
if (IS_ERR(&ret)) {
pr_err("%s(), clk_prepare_enable %s fail, ret %d\n",
__func__, adsp_clks[CLK_ADSP_INFRA].name, ret);
adsp_clock_count--;
return -EINVAL;
}
return 0;
}
void adsp_disable_clock(void)
{
unsigned long spin_flags;
pr_info("%s()\n", __func__);
clk_disable_unprepare(adsp_clks[CLK_ADSP_INFRA].clock);
clk_disable_unprepare(adsp_clks[CLK_ADSP_INFRA_32K].clock);
clk_disable_unprepare(adsp_clks[CLK_ADSP_INFRA_26M].clock);
spin_lock_irqsave(&adsp_clock_spinlock, spin_flags);
if (--adsp_clock_count == 0)
/* unable to access adsp sram before set way_en to 1 */
adsp_way_en_ctrl(0);
spin_unlock_irqrestore(&adsp_clock_spinlock, spin_flags);
}
@@ -0,0 +1,31 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef ADSP_CLK_H
#define ADSP_CLK_H
#include <linux/platform_device.h>
enum adsp_clk {
CLK_ADSP_INFRA_26M,
CLK_ADSP_INFRA_32K,
CLK_ADSP_INFRA,
CLK_TOP_ADSP_SEL,
CLK_TOP_CLK26M,
CLK_TOP_ADSPPLL,
ADSP_CLK_NUM
};
#define CLK_DEFAULT_INIT_CK CLK_TOP_ADSPPLL
#define CLK_DEFAULT_26M_CK CLK_TOP_CLK26M
void adsp_set_clock_freq(enum adsp_clk clk);
int adsp_set_top_mux(enum adsp_clk clk);
int adsp_enable_clock(void);
void adsp_disable_clock(void);
int adsp_clk_device_probe(struct platform_device *pdev);
void adsp_clk_device_remove(void *dev);
#endif /* ADSP_CLK_H */
@@ -0,0 +1,122 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __ADSP_DVFS_H__
#define __ADSP_DVFS_H__
#include <adsp_ipi.h>
#include <adsp_clk.h>
#define ADSP_ITCM_MONITOR (1)
#define ADSP_DTCM_MONITOR (1)
#define ADSP_CFG_MONITOR (0)
#define ADSP_DVFS_PROFILE (1)
#define ADSP_FREQ_METER_ID (43) //hf_fadsp_ck
#define ADSP_DVFS_USE_PLL 1
#define PLL_ENABLE (1)
#define PLL_DISABLE (0)
#define DVFS_STATUS_OK (0)
#define DVFS_STATUS_BUSY (-1)
#define DVFS_REQUEST_SAME_CLOCK (-2)
#define DVFS_STATUS_ERR (-3)
#define DVFS_STATUS_TIMEOUT (-4)
#define DVFS_CLK_ERROR (-5)
#define DVFS_STATUS_CMD_FIX (-6)
#define DVFS_STATUS_CMD_LIMITED (-7)
#define DVFS_STATUS_CMD_DISABLE (-8)
enum adsp_cur_status_enum {
ADSP_STATUS_RESET = 0x00,
ADSP_STATUS_SUSPEND = 0x01,
ADSP_STATUS_SLEEP = 0x10,
ADSP_STATUS_ACTIVE = 0x11,
};
enum adsp_state_enum {
IN_DEBUG_IDLE = 1,
ENTERING_SLEEP = 2,
IN_SLEEP = 4,
ENTERING_ACTIVE = 8,
IN_ACTIVE = 16,
};
enum {
CLK_SYS_EN_BIT = 0,
CLK_HIGH_EN_BIT = 1,
CLK_HIGH_CG_BIT = 2,
CLK_SYS_IRQ_EN_BIT = 16,
CLK_HIGH_IRQ_EN_BIT = 17,
};
/*#ifdef CONFIG_PINCTRL_MT6797*/
enum clk_opp_enum {
CLK_OPP0 = 125,
CLK_OPP1 = 330,
CLK_OPP2 = 416,
CLK_INVALID_OPP,
};
enum clk_div_enum {
CLK_DIV_1 = 0,
CLK_DIV_2 = 1,
CLK_DIV_4 = 2,
CLK_DIV_8 = 3,
CLK_DIV_UNKNOWN,
};
enum voltage_enum {
SPM_VOLTAGE_800_D = 0,
SPM_VOLTAGE_800,
SPM_VOLTAGE_900,
SPM_VOLTAGE_1000,
SPM_VOLTAGE_TYPE_NUM,
};
struct mt_adsp_pll_t {
/* main clock for mfg setting */
struct clk *clk_mux;
/* substitution clock for adsp transient parent setting */
struct clk *clk_pll0;
struct clk *clk_pll1;
struct clk *clk_pll2;
struct clk *clk_pll3;
struct clk *clk_pll4;
struct clk *clk_pll5;
struct clk *clk_pll6;
struct clk *clk_pll7;
};
extern int adsp_pll_ctrl_set(unsigned int pll_ctrl_flag, unsigned int pll_sel);
extern int adsp_set_pmic_vcore(unsigned int cur_freq);
extern unsigned int adsp_get_dvfs_opp(void);
extern uint32_t adsp_get_freq(void);
extern int adsp_request_freq(void);
extern void adsp_pll_mux_set(unsigned int pll_ctrl_flag);
extern void wait_adsp_dvfs_init_done(void);
extern int __init adsp_dvfs_init(void);
extern void __exit adsp_dvfs_exit(void);
/* adsp dvfs variable*/
extern struct mutex adsp_feature_mutex;
extern struct mutex adsp_suspend_mutex;
extern struct completion adsp_suspend_cp;
extern struct completion adsp_resume_cp;
extern int adsp_is_suspend;
/* adsp new implement */
void adsp_A_send_spm_request(uint32_t enable);
extern void adsp_reset(void);
void adsp_sw_reset(enum adsp_core_id core_id);
extern void adsp_release_runstall(enum adsp_core_id, uint32_t release);
extern int adsp_suspend_init(void);
void adsp_start_suspend_timer(void);
void adsp_stop_suspend_timer(void);
int adsp_resume(void);
void adsp_suspend(enum adsp_core_id core_id);
/***************************/
#endif /* __ADSP_DVFS_H__ */
@@ -0,0 +1,564 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#include <linux/vmalloc.h> /* needed by vmalloc */
#include <linux/slab.h> /* needed by kmalloc */
#include <linux/sysfs.h>
#include <linux/device.h> /* needed by device_* */
#include <linux/workqueue.h>
#include <linux/mutex.h>
#include <linux/delay.h>
#include <linux/io.h>
#if IS_ENABLED(CONFIG_PM_WAKELOCKS)
#include <linux/pm_wakeup.h>
#endif
#include <mt-plat/aee.h>
#include "adsp_reg.h"
#include "adsp_core.h"
#include "adsp_clk.h"
#include "adsp_platform_driver.h"
#include "adsp_excep.h"
#include "adsp_logger.h"
#define ADSP_MISC_EXTRA_SIZE 0x400 //1KB
#define ADSP_MISC_BUF_SIZE 0x10000 //64KB
#define ADSP_TEST_EE_PATTERN "Assert-Test"
static char adsp_ke_buffer[ADSP_KE_DUMP_LEN];
static struct adsp_exception_control excep_ctrl;
static bool suppress_test_ee;
static u32 copy_from_buffer(void *dest, size_t destsize, const void *src,
size_t srcsize, u32 offset, size_t request)
{
/* if request == -1, offset == 0, copy full srcsize */
if (offset + request > srcsize)
request = srcsize - offset;
/* if destsize == -1, don't check the request size */
if (!dest || destsize < request) {
pr_warn("%s, buffer null or not enough space", __func__);
return 0;
}
memcpy(dest, src + offset, request);
return request;
}
static inline u32 dump_adsp_shared_memory(void *buf, size_t size, int id)
{
void *mem_addr = adsp_get_reserve_mem_virt(id);
size_t mem_size = adsp_get_reserve_mem_size(id);
if (!mem_addr)
return 0;
return copy_from_buffer(buf, size, mem_addr, mem_size, 0, -1);
}
static inline u32 copy_from_adsp_shared_memory(void *buf, u32 offset,
size_t size, int id)
{
void *mem_addr = adsp_get_reserve_mem_virt(id);
size_t mem_size = adsp_get_reserve_mem_size(id);
if (!mem_addr)
return 0;
return copy_from_buffer(buf, -1, mem_addr, mem_size, offset, size);
}
static u32 dump_adsp_internal_mem(struct adsp_priv *pdata,
void *buf, size_t size)
{
u32 clk_cfg = 0, uart_cfg = 0, n = 0;
u32 clk_mask = ADSP_CLK_UART_EN | ADSP_CLK_CORE_0_EN;
u32 uart_mask = ADSP_UART_RST_N | ADSP_UART_BCLK_CG;
adsp_enable_clock();
mutex_lock(&excep_ctrl.lock);
clk_cfg = switch_adsp_clk_ctrl_cg(true, clk_mask);
uart_cfg = switch_adsp_uart_ctrl_cg(true, uart_mask);
n += copy_from_buffer(buf + n, size - n,
pdata->cfg, pdata->cfg_size, 0, -1);
n += copy_from_buffer(buf + n, size - n,
pdata->itcm, pdata->itcm_size, 0, -1);
n += copy_from_buffer(buf + n, size - n,
pdata->dtcm, pdata->dtcm_size, 0, -1);
switch_adsp_clk_ctrl_cg(false, (~clk_cfg) & clk_mask);
switch_adsp_uart_ctrl_cg(false, (~uart_cfg) & uart_mask);
mutex_unlock(&excep_ctrl.lock);
adsp_disable_clock();
return n;
}
static int dump_buffer(struct adsp_exception_control *ctrl, int coredump_id)
{
u32 total = 0, n = 0;
void *buf = NULL;
int ret = 0;
struct adsp_priv *pdata = NULL;
if (!ctrl || !ctrl->priv_data)
return -1;
pdata = (struct adsp_priv *)ctrl->priv_data;
if (ctrl->buf_backup) {
/* wait last dump done, and release buf_backup */
ret = wait_for_completion_timeout(&ctrl->done, 10 * HZ);
/* if not release buf, return EBUSY */
if (ctrl->buf_backup)
return -EBUSY;
}
total = pdata->cfg_size
+ pdata->itcm_size
+ pdata->dtcm_size
+ pdata->sysram_size
+ adsp_get_reserve_mem_size(coredump_id)
+ adsp_get_reserve_mem_size(ADSP_A_LOGGER_MEM_ID);
buf = vzalloc(total);
if (!buf)
return -ENOMEM;
n += dump_adsp_internal_mem(pdata, buf + n, total - n);
n += copy_from_buffer(buf + n, total - n,
pdata->sysram, pdata->sysram_size, 0, -1);
n += dump_adsp_shared_memory(buf + n, total - n, coredump_id);
n += dump_adsp_shared_memory(buf + n, total - n, ADSP_A_LOGGER_MEM_ID);
mutex_lock(&ctrl->buffer_lock);
reinit_completion(&ctrl->done);
ctrl->buf_backup = buf;
ctrl->buf_size = total;
mutex_unlock(&ctrl->buffer_lock);
pr_debug("%s, vmalloc size %u, buffer %p, dump_size %u",
__func__, total, buf, n);
return n;
}
static void adsp_exception_dump(struct adsp_exception_control *ctrl)
{
char detail[ADSP_AED_STR_LEN];
int db_opt = DB_OPT_DEFAULT;
char *aed_type;
bool dump_flag = true;
int ret = 0, n = 0, coredump_id = 0, coredump_size = 0;
struct adsp_priv *pdata = (struct adsp_priv *)ctrl->priv_data;
struct adsp_coredump *coredump;
/* get adsp title and exception type*/
switch (ctrl->excep_id) {
case EXCEP_BOOTUP:
aed_type = "boot exception";
break;
case EXCEP_RUNTIME:
aed_type = "runtime exception";
db_opt |= DB_OPT_FTRACE;
break;
case EXCEP_KERNEL:
aed_type = "kernel exception";
db_opt |= DB_OPT_FTRACE;
break;
default:
dump_flag = false;
aed_type = "unknown exception";
break;
}
if (pdata->id == ADSP_A_ID)
coredump_id = ADSP_A_CORE_DUMP_MEM_ID;
coredump = adsp_get_reserve_mem_virt(coredump_id);
coredump_size = adsp_get_reserve_mem_size(coredump_id);
if (suppress_test_ee && coredump
&& strstr(coredump->assert_log, ADSP_TEST_EE_PATTERN)) {
pr_info("%s, suppress Test EE dump", __func__);
return;
}
if (dump_flag) {
ret = dump_buffer(ctrl, coredump_id);
if (ret < 0)
pr_info("%s, excep dump fail ret(%d)", __func__, ret);
}
n += snprintf(detail + n, ADSP_AED_STR_LEN - n, "%s %s\n",
pdata->name, aed_type);
if (coredump) {
n += snprintf(detail + n, ADSP_AED_STR_LEN - n,
"adsp pc=0x%08x,exccause=0x%x,excvaddr=0x%x\n",
coredump->pc,
coredump->exccause,
coredump->excvaddr);
n += snprintf(detail + n, ADSP_AED_STR_LEN - n,
"CRDISPATCH_KEY:ADSP exception/%s\n",
coredump->task_name);
n += snprintf(detail + n, ADSP_AED_STR_LEN - n, "%s",
coredump->assert_log);
}
pr_info("%s", detail);
/* adsp aed api, only detail information available*/
aed_common_exception_api("adsp", (const int *)coredump, coredump_size,
NULL, 0, detail, db_opt);
}
void adsp_aed_worker(struct work_struct *ws)
{
struct adsp_exception_control *ctrl = container_of(ws,
struct adsp_exception_control,
aed_work);
struct adsp_priv *pdata = NULL;
int cid = 0, ret = 0, retry = 0;
/* wake lock AP*/
#if IS_ENABLED(CONFIG_PM_WAKELOCKS)
__pm_stay_awake(ctrl->wakeup_lock);
#endif
/* stop adsp, set reset state */
for (cid = 0; cid < ADSP_CORE_TOTAL; cid++) {
pdata = get_adsp_core_by_id(cid);
set_adsp_state(pdata, ADSP_RESET);
complete_all(&pdata->done);
}
/* force wake up if suspend thread wait reset event */
if (ctrl->waitq)
wake_up(ctrl->waitq);
adsp_register_feature(SYSTEM_FEATURE_ID);
adsp_extern_notify_chain(ADSP_EVENT_STOP);
/* exception dump */
adsp_exception_dump(ctrl);
/* reset adsp */
adsp_enable_clock();
for (retry = 0; retry < ADSP_RESET_RETRY_MAXTIME; retry++) {
ret = adsp_reset();
if (ret == 0)
break;
/* reset fail & retry */
pr_info("%s, reset retry.... (%d)", __func__, retry);
msleep(20);
}
adsp_disable_clock();
if (ret) {
pr_info("%s, adsp dead, wait dump dead body", __func__);
aee_kernel_exception_api(__FILE__,
__LINE__,
DB_OPT_DEFAULT,
"[ADSP]",
"ASSERT: ADSP DEAD! Recovery Fail");
/* BUG_ON(1); */
}
adsp_extern_notify_chain(ADSP_EVENT_READY);
adsp_deregister_feature(SYSTEM_FEATURE_ID);
#if IS_ENABLED(CONFIG_PM_WAKELOCKS)
__pm_relax(ctrl->wakeup_lock);
#endif
}
bool adsp_aed_dispatch(enum adsp_excep_id type, void *data)
{
struct adsp_exception_control *ctrl = &excep_ctrl;
if (work_busy(&ctrl->aed_work))
return false;
ctrl->excep_id = type;
ctrl->priv_data = data;
return queue_work(ctrl->workq, &ctrl->aed_work);
}
static void adsp_wdt_counter_reset(struct timer_list *t)
{
excep_ctrl.wdt_counter = 0;
pr_info("[ADSP] %s\n", __func__);
}
/*
* init a work struct
*/
int init_adsp_exception_control(struct device *dev,
struct workqueue_struct *workq,
struct wait_queue_head *waitq)
{
struct adsp_exception_control *ctrl = &excep_ctrl;
ctrl->waitq = waitq;
ctrl->workq = workq;
ctrl->buf_backup = NULL;
ctrl->buf_size = 0;
mutex_init(&ctrl->lock);
mutex_init(&ctrl->buffer_lock);
init_completion(&ctrl->done);
INIT_WORK(&ctrl->aed_work, adsp_aed_worker);
#if IS_ENABLED(CONFIG_PM_WAKELOCKS)
ctrl->wakeup_lock = wakeup_source_register(dev, "adsp wakelock");
#endif
timer_setup(&ctrl->wdt_timer, adsp_wdt_counter_reset, 0);
return 0;
}
void adsp_wdt_handler(int irq, void *data, int cid)
{
struct adsp_priv *pdata = (struct adsp_priv *)data;
if (!adsp_aed_dispatch(EXCEP_RUNTIME, data))
pr_info("%s, already resetting, ignore core%d wdt",
__func__, pdata->id);
}
void get_adsp_misc_buffer(unsigned long *vaddr, unsigned long *size)
{
struct adsp_priv *pdata = NULL;
struct log_info_s *log_info = NULL;
struct buffer_info_s *buf_info = NULL;
void *buf = adsp_ke_buffer;
void *addr = NULL;
unsigned int w_pos, r_pos, buf_size;
unsigned int data_len[2];
unsigned int id = 0, n = 0;
unsigned int part_len = ADSP_MISC_BUF_SIZE / ADSP_CORE_TOTAL;
memset(buf, 0, ADSP_KE_DUMP_LEN);
for (id = 0; id < ADSP_CORE_TOTAL; id++) {
w_pos = 0;
pdata = get_adsp_core_by_id(id);
if (!pdata || !pdata->log_ctrl ||
!pdata->log_ctrl->inited || !pdata->log_ctrl->priv)
goto ERROR;
log_info = (struct log_info_s *)pdata->log_ctrl->priv;
buf_info = (struct buffer_info_s *)(pdata->log_ctrl->priv
+ log_info->info_ofs);
buf_size = log_info->buff_size;
memcpy_fromio(&w_pos, &buf_info->w_pos, sizeof(w_pos));
if (w_pos >= buf_size)
w_pos -= buf_size;
if (w_pos < part_len) {
r_pos = buf_size + w_pos - part_len;
data_len[0] = part_len - w_pos;
data_len[1] = w_pos;
} else {
r_pos = w_pos - part_len;
data_len[0] = part_len;
data_len[1] = 0;
}
addr = pdata->log_ctrl->priv + log_info->buff_ofs;
memcpy(buf + n, addr + r_pos, data_len[0]);
n += data_len[0];
memcpy(buf + n, addr, data_len[1]);
n += data_len[1];
}
/* return value */
*vaddr = (unsigned long)buf;
*size = n;
return;
ERROR:
/* return value */
*vaddr = (unsigned long)buf;
*size = 0;
}
EXPORT_SYMBOL(get_adsp_misc_buffer);
void get_adsp_aee_buffer(unsigned long *vaddr, unsigned long *size)
{
u32 clk_cfg = 0, uart_cfg = 0, n = 0;
u32 clk_mask = ADSP_CLK_UART_EN | ADSP_CLK_CORE_0_EN;
u32 uart_mask = ADSP_UART_RST_N | ADSP_UART_BCLK_CG;
struct adsp_priv *pdata = NULL;
void *buf = adsp_ke_buffer;
u32 len = ADSP_KE_DUMP_LEN;
memset(buf, 0, len);
adsp_enable_clock();
mutex_lock(&excep_ctrl.lock);
read_lock(&access_rwlock);
adsp_mt_clr_sw_reset();
clk_cfg = switch_adsp_clk_ctrl_cg(true, clk_mask);
uart_cfg = switch_adsp_uart_ctrl_cg(true, uart_mask);
pdata = get_adsp_core_by_id(ADSP_A_ID);
n += copy_from_buffer(buf + n, len - n,
pdata->cfg, pdata->cfg_size, 0, -1);
n += copy_from_buffer(buf + n, len - n,
pdata->dtcm, pdata->dtcm_size, 0, -1);
switch_adsp_clk_ctrl_cg(false, (~clk_cfg) & clk_mask);
switch_adsp_uart_ctrl_cg(false, (~uart_cfg) & uart_mask);
read_unlock(&access_rwlock);
mutex_unlock(&excep_ctrl.lock);
adsp_disable_clock();
/* last adsp_log */
//n += dump_adsp_partial_log(buf + n, len - n);
/* return value */
*vaddr = (unsigned long)buf;
*size = len;
}
EXPORT_SYMBOL(get_adsp_aee_buffer);
/*
* sysfs bin_attribute node
*/
static ssize_t adsp_dump_show(struct file *filep, struct kobject *kobj,
struct bin_attribute *attr,
char *buf, loff_t offset, size_t size)
{
ssize_t n = 0;
struct adsp_exception_control *ctrl = &excep_ctrl;
mutex_lock(&ctrl->buffer_lock);
if (ctrl->buf_backup) {
n = copy_from_buffer(buf, -1, ctrl->buf_backup,
ctrl->buf_size, offset, size);
if (n == 0) {
vfree(ctrl->buf_backup);
ctrl->buf_backup = NULL;
ctrl->buf_size = 0;
/* if dump_buffer wait for dump, wake up it */
complete(&ctrl->done);
}
}
mutex_unlock(&ctrl->buffer_lock);
return n;
}
static ssize_t adsp_dump_ke_show(struct file *filep, struct kobject *kobj,
struct bin_attribute *attr,
char *buf, loff_t offset, size_t size)
{
unsigned long tmp[2];
ssize_t n = 0;
ssize_t threshold[2];
if (offset == 0) /* only do ke ramdump once at start */
get_adsp_aee_buffer(&tmp[0], &tmp[1]);
threshold[0] = ADSP_KE_DUMP_LEN;
threshold[1] = threshold[0] +
adsp_get_reserve_mem_size(ADSP_A_LOGGER_MEM_ID);
if (offset >= 0 && offset < threshold[0]) {
n = copy_from_buffer(buf, -1, adsp_ke_buffer,
threshold[0], offset, size);
} else if (offset >= threshold[0] && offset < threshold[1]) {
n = copy_from_adsp_shared_memory(
buf, offset - threshold[0],
size, ADSP_A_LOGGER_MEM_ID);
}
return n;
}
static ssize_t adsp_dump_log_show(struct file *filep, struct kobject *kobj,
struct bin_attribute *attr,
char *buf, loff_t offset, size_t size)
{
ssize_t n = 0;
ssize_t threshold;
threshold = adsp_get_reserve_mem_size(ADSP_A_LOGGER_MEM_ID);
if (offset >= 0 && offset < threshold) {
n = copy_from_adsp_shared_memory(buf, offset,
size, ADSP_A_LOGGER_MEM_ID);
}
return n;
}
static struct bin_attribute bin_attr_adsp_dump = {
.attr = {
.name = "adsp_dump",
.mode = 0444,
},
.size = 0,
.read = adsp_dump_show,
};
static struct bin_attribute bin_attr_adsp_dump_ke = {
.attr = {
.name = "adsp_dump_ke",
.mode = 0444,
},
.size = 0,
.read = adsp_dump_ke_show,
};
struct bin_attribute bin_attr_adsp_dump_log = {
.attr = {
.name = "adsp_last_log",
.mode = 0444,
},
.size = 0,
.read = adsp_dump_log_show,
};
static inline ssize_t suppress_ee_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
unsigned int input = 0;
if (kstrtouint(buf, 0, &input) != 0)
return -EINVAL;
suppress_test_ee = !!input;
return count;
}
DEVICE_ATTR_WO(suppress_ee);
static struct bin_attribute *adsp_excep_bin_attrs[] = {
&bin_attr_adsp_dump,
&bin_attr_adsp_dump_ke,
&bin_attr_adsp_dump_log,
NULL,
};
static struct attribute *adsp_excep_attrs[] = {
&dev_attr_suppress_ee.attr,
NULL,
};
struct attribute_group adsp_excep_attr_group = {
.attrs = adsp_excep_attrs,
.bin_attrs = adsp_excep_bin_attrs,
};
@@ -0,0 +1,61 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __ADSP_EXCEP_H__
#define __ADSP_EXCEP_H__
#include <linux/interrupt.h>
#define ADSP_AED_STR_LEN (512)
#define ADSP_WDT_TIMEOUT (60 * HZ) /* 60 seconds*/
#define ADSP_KE_DUMP_LEN (256 * 1024)
#define ADSP_RESET_RETRY_MAXTIME (7)
enum adsp_excep_id {
EXCEP_LOAD_FIRMWARE = 0,
EXCEP_RESET,
EXCEP_BOOTUP,
EXCEP_RUNTIME,
EXCEP_KERNEL,
ADSP_NR_EXCEP,
};
/* adsp reg dump */
struct adsp_coredump {
u32 reserved_0[67];
u32 pc;
u32 exccause;
u32 excvaddr;
u32 reserved_1[7];
u8 task_name[16];
u32 reserved_2[47];
u8 assert_log[512];
};
struct adsp_exception_control {
int excep_id;
void *priv_data;
void *buf_backup;
size_t buf_size;
struct mutex lock;
struct mutex buffer_lock;
struct workqueue_struct *workq;
struct wait_queue_head *waitq;
struct work_struct aed_work;
struct wakeup_source *wakeup_lock;
struct completion done;
struct timer_list wdt_timer;
unsigned int wdt_counter;
};
void adsp_wdt_handler(int irq, void *data, int cid);
bool adsp_aed_dispatch(enum adsp_excep_id type, void *data);
int init_adsp_exception_control(struct device *dev,
struct workqueue_struct *wq,
struct wait_queue_head *waitq);
#endif
@@ -0,0 +1,94 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __ADSP_FEATURE_DEFINE_H__
#define __ADSP_FEATURE_DEFINE_H__
/* reset recovery feature kernel option*/
#define CFG_RECOVERY_SUPPORT
/* adsp platform configs*/
#define ADSP_BUS_MONITOR_INIT_ENABLE (1)
/* adsp feature PRI list */
/* The higher number, higher priority */
enum adsp_feature_pri {
AUDIO_HAL_FEATURE_PRI = 0,
ADSP_LOGGER_FEATURE_PRI,
SPK_PROTECT_FEATURE_PRI,
A2DP_PLAYBACK_FEATURE_PRI,
AURISYS_FEATURE_PRI,
DEEPBUF_FEATURE_PRI,
OFFLOAD_FEATURE_PRI,
PRIMARY_FEATURE_PRI,
VOIP_FEATURE_PRI,
CAPTURE_UL1_FEATURE_PRI,
AUDIO_DATAPROVIDER_FEATURE_PRI,
AUDIO_PLAYBACK_FEATURE_PRI,
VOICE_CALL_FEATURE_PRI,
AUDIO_CONTROLLER_FEATURE_PRI,
SYSTEM_FEATURE_PRI,
};
/* adsp feature ID list */
enum adsp_feature_id {
SYSTEM_FEATURE_ID = 0,
ADSP_LOGGER_FEATURE_ID = 1,
AURISYS_FEATURE_ID = 2,
AUDIO_CONTROLLER_FEATURE_ID = 3,
PRIMARY_FEATURE_ID = 4,
FAST_FEATURE_ID = 5,
DEEPBUF_FEATURE_ID = 6,
OFFLOAD_FEATURE_ID = 7,
AUDIO_PLAYBACK_FEATURE_ID = 8,
AUDIO_MUSIC_FEATURE_ID = 9,
RESERVED0_FEATURE_ID = 10,
RESERVED1_FEATURE_ID = 11,
CAPTURE_UL1_FEATURE_ID = 12,
AUDIO_DATAPROVIDER_FEATURE_ID = 13,
VOICE_CALL_FEATURE_ID = 14,
VOIP_FEATURE_ID = 15,
SPK_PROTECT_FEATURE_ID = 16,
CALL_FINAL_FEATURE_ID = 17,
A2DP_PLAYBACK_FEATURE_ID = 18,
KTV_FEATURE_ID = 19,
CAPTURE_RAW_FEATURE_ID = 20,
FM_ADSP_FEATURE_ID = 21,
VOICE_CALL_SUB_FEATURE_ID = 22,
BLE_CALL_DL_FEATURE_ID = 27,
BLE_CALL_UL_FEATURE_ID = 28,
ADSP_NUM_FEATURE_ID,
};
enum {
DEREGI_FLAG_NODELAY = 1 << 0,
};
struct adsp_feature_control {
int total;
unsigned int feature_set; /* from dts */
struct mutex lock;
struct workqueue_struct *wq;
struct delayed_work suspend_work;
int delay_ms;
int (*suspend)(void);
int (*resume)(void);
};
ssize_t adsp_dump_feature_state(u32 cid, char *buffer, int size);
int adsp_get_feature_index(const char *str);
bool is_feature_in_set(u32 cid, u32 fid);
bool adsp_feature_is_active(u32 cid);
bool is_adsp_feature_in_active(void);
bool flush_suspend_work(u32 cid);
int _adsp_register_feature(u32 cid, u32 fid, u32 opt);
int _adsp_deregister_feature(u32 cid, u32 fid, u32 opt);
int init_adsp_feature_control(u32 cid, u32 feature_set, int delay_ms,
struct workqueue_struct *wq,
int (*_suspend)(void),
int (*_resume)(void));
#endif
@@ -0,0 +1,103 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __ADSP_HELPER_H__
#define __ADSP_HELPER_H__
#include <linux/notifier.h>
#include "adsp_reserved_mem.h"
#include "adsp_feature_define.h"
enum adsp_ipi_id {
ADSP_IPI_WDT = 0,
ADSP_IPI_TEST1,
ADSP_IPI_LOGGER_ENABLE,
ADSP_IPI_LOGGER_WAKEUP,
ADSP_IPI_LOGGER_INIT,
ADSP_IPI_TRAX_ENABLE,
ADSP_IPI_TRAX_DONE,
ADSP_IPI_TRAX_INIT_A,
ADSP_IPI_VOW,
ADSP_IPI_AUDIO,
ADSP_IPI_DVT_TEST,
ADSP_IPI_TIME_SYNC,
ADSP_IPI_CONSYS,
ADSP_IPI_ADSP_A_READY,
ADSP_IPI_APCCCI,
ADSP_IPI_ADSP_A_RAM_DUMP,
ADSP_IPI_DVFS_DEBUG,
ADSP_IPI_DVFS_FIX_OPP_SET,
ADSP_IPI_DVFS_FIX_OPP_EN,
ADSP_IPI_DVFS_LIMIT_OPP_SET,
ADSP_IPI_DVFS_LIMIT_OPP_EN,
ADSP_IPI_DVFS_SUSPEND,
ADSP_IPI_DVFS_SLEEP,
ADSP_IPI_DVFS_WAKE,
ADSP_IPI_DVFS_SET_FREQ,
ADSP_IPI_ADSP_PLL_CTRL = 27,
ADSP_IPI_MET_ADSP = 30,
ADSP_IPI_ADSP_TIMER = 31,
ADSP_NR_IPI,
};
enum adsp_ipi_status {
ADSP_IPI_ERROR = -1,
ADSP_IPI_DONE,
ADSP_IPI_BUSY,
};
enum adsp_status {
ADSP_ERROR = -1,
ADSP_OK,
ADSP_SEMAPHORE_BUSY,
};
/* adsp notify event */
enum ADSP_NOTIFY_EVENT {
ADSP_EVENT_STOP = 0,
ADSP_EVENT_READY,
};
enum semaphore_2way_flag {
SEMA_2WAY_AUDIOREG = 0,
SEMA_2WAY_NUM = 4,
};
#define SEMA_AUDIO SEMA_2WAY_NUM
#define SEMA_AUDIOREG SEMA_2WAY_AUDIOREG
#define ADSP_OSTIMER_BUFFER (adsp_timesync_ptr)
extern void *adsp_timesync_ptr;
extern enum adsp_ipi_status adsp_ipi_registration(enum adsp_ipi_id id,
void (*ipi_handler)(int id,
void *data, unsigned int len),
const char *name);
extern enum adsp_ipi_status adsp_ipi_unregistration(enum adsp_ipi_id id);
extern enum adsp_ipi_status adsp_push_message(enum adsp_ipi_id id, void *buf,
unsigned int len, unsigned int wait_ms,
unsigned int core_id);
extern enum adsp_ipi_status adsp_send_message(enum adsp_ipi_id id, void *buf,
unsigned int len, unsigned int wait,
unsigned int core_id);
extern int is_adsp_ready(u32 cid);
extern bool is_adsp_feature_in_active(void);
extern int adsp_feature_in_which_core(enum adsp_feature_id fid);
extern int adsp_register_feature(enum adsp_feature_id fid);
extern int adsp_deregister_feature(enum adsp_feature_id fid);
extern void adsp_register_notify(struct notifier_block *nb);
extern void adsp_unregister_notify(struct notifier_block *nb);
extern void reset_hal_feature_table(void);
/* If device interrupt is not connected, return -ENOTCONN. */
extern int adsp_irq_registration(u32 core_id, u32 irq_id, void *handler,
void *data);
/* semaphore */
extern int get_adsp_semaphore(unsigned int flags);
extern int release_adsp_semaphore(unsigned int flags);
#endif
@@ -0,0 +1,282 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#include <linux/mutex.h>
#include <linux/io.h>
#include <linux/ktime.h>
#include "adsp_ipi.h"
#include "adsp_platform.h"
#include "adsp_core.h"
#include "adsp_platform_driver.h"
#include "adsp_excep.h"
#include <adsp_ipi_queue.h>
#include <audio_ipi_platform.h>
#include <audio_messenger_ipi.h>
#include "adsp_reg.h"
/*
* =============================================================================
* log
* =============================================================================
*/
#ifdef pr_fmt
#undef pr_fmt
#endif
#define pr_fmt(fmt) "[IPI][IPC] %s(), " fmt "\n", __func__
char *adsp_core_ids[ADSP_CORE_TOTAL] = {"ADSP A"};
#define PRINT_THRESHOLD 10000
struct adsp_ipi_desc adsp_ipi_desc[ADSP_NR_IPI];
struct ipi_ctrl_s adsp_ipi_ctrl;
/*
* find an ipi handler and invoke it
*/
void adsp_ipi_handler(int irq, void *data, int cid)
{
struct adsp_priv *pdata = (struct adsp_priv *)data;
struct ipi_ctrl_s *ctrl;
struct adsp_share_obj *recv_obj;
enum adsp_ipi_id ipi_id;
struct ipi_msg_t *ipi_msg = NULL;
u8 share_buf[SHARE_BUF_SIZE - 16];
u32 len;
ktime_t start_time;
s64 stop_time;
start_time = ktime_get();
if (!pdata) {
pr_err("%s pdata[%p]\n", __func__, pdata);
return;
}
if (pdata->id >= ADSP_CORE_TOTAL) {
pr_err("%s core_id[%d] is invalid\n", __func__, pdata->id);
return;
}
ctrl = pdata->ipi_ctrl;
recv_obj = ctrl->recv_obj;
ipi_id = recv_obj->id;
len = recv_obj->len;
memcpy_fromio(share_buf,
(void *)recv_obj->share_buf, len);
adsp_mt_clr_sysirq(cid);
if (ipi_id >= ADSP_NR_IPI || ipi_id < 0)
pr_debug("[ADSP] A ipi handler id abnormal, id=%d", ipi_id);
else if (adsp_ipi_desc[ipi_id].handler) {
if (ipi_id == ADSP_IPI_ADSP_A_READY ||
ipi_id == ADSP_IPI_DVFS_SUSPEND ||
ipi_id == ADSP_IPI_LOGGER_INIT) {
/*
* adsp_ready & logger init ipi bypass send to ipi
* queue and do callback directly. (which will in isr)
* Must ensure the callback can do in isr
*/
adsp_ipi_desc[ipi_id].handler(ipi_id, share_buf, len);
} else if (is_scp_ipi_queue_init(AUDIO_OPENDSP_USE_HIFI3_A)) {
scp_dispatch_ipi_hanlder_to_queue(
AUDIO_OPENDSP_USE_HIFI3_A,
ipi_id, share_buf, len,
adsp_ipi_desc[ipi_id].handler);
} else {
ipi_msg = (struct ipi_msg_t *)share_buf;
if (ipi_msg->magic == IPI_MSG_MAGIC_NUMBER)
DUMP_IPI_MSG("ipi queue not ready!", ipi_msg);
else
pr_info("ipi queue not ready!! opendsp_id: %u, ipi_id: %u, buf: %p, len: %u, ipi_handler: %p",
AUDIO_OPENDSP_USE_HIFI3_A,
ipi_id, share_buf, len,
adsp_ipi_desc[ipi_id].handler);
WARN_ON(1);
}
} else {
pr_debug("[ADSP] A ipi handler is null or abnormal, id=%d",
ipi_id);
}
stop_time = ktime_us_delta(ktime_get(), start_time);
if (stop_time > 1000) /* 1 ms */
pr_notice("IPC ISR %lld us too long!!", stop_time);
}
/*
* ipi initialize
*/
void adsp_ipi_init(void)
{
struct adsp_priv *pdata = get_adsp_core_by_id(ADSP_A_ID);
struct ipi_ctrl_s *ctrl = NULL;
void __iomem *base = adsp_get_sharedmem_base(pdata, ADSP_SHAREDMEM_IPCBUF);
pdata->ipi_ctrl = &adsp_ipi_ctrl;
ctrl = pdata->ipi_ctrl;
mutex_init(&ctrl->lock);
ctrl->recv_obj = (struct adsp_share_obj *)base;
ctrl->send_obj = ctrl->recv_obj + 1;
pr_debug("[adsp_ipi]ctrl->recv_obj = 0x%p\n", ctrl->recv_obj);
pr_debug("[adsp_ipi]ctrl->send_obj = 0x%p\n", ctrl->send_obj);
}
/*
* API let apps can register an ipi handler to receive IPI
* @param id: IPI ID
* @param handler: IPI handler
* @param name: IPI name
*/
enum adsp_ipi_status adsp_ipi_registration(
enum adsp_ipi_id id,
void (*ipi_handler)(int id, void *data, unsigned int len),
const char *name)
{
if (id < ADSP_NR_IPI && id >= 0) {
adsp_ipi_desc[id].name = name;
if (ipi_handler == NULL)
return ADSP_IPI_ERROR;
adsp_ipi_desc[id].handler = ipi_handler;
return ADSP_IPI_DONE;
} else
return ADSP_IPI_ERROR;
}
EXPORT_SYMBOL_GPL(adsp_ipi_registration);
/*
* API let apps unregister an ipi handler
* @param id: IPI ID
*/
enum adsp_ipi_status adsp_ipi_unregistration(enum adsp_ipi_id id)
{
if (id < ADSP_NR_IPI && id >= 0) {
adsp_ipi_desc[id].name = "";
adsp_ipi_desc[id].handler = NULL;
return ADSP_IPI_DONE;
} else
return ADSP_IPI_ERROR;
}
EXPORT_SYMBOL_GPL(adsp_ipi_unregistration);
/*
* API for apps to send an IPI to adsp
* @param id: IPI ID
* @param buf: the pointer of data
* @param len: data length
* @param wait: If true, wait (atomically) until data have been gotten by Host
* @param len: data length
*/
enum adsp_ipi_status adsp_ipi_send(enum adsp_ipi_id id, void *buf,
unsigned int len, unsigned int wait,
enum adsp_core_id adsp_id)
{
int retval = 0;
uint32_t wait_ms = (wait) ? ADSP_IPI_QUEUE_DEFAULT_WAIT_MS : 0;
/* wait until IPC done */
retval = scp_send_msg_to_queue(
AUDIO_OPENDSP_USE_HIFI3_A, id, buf, len, wait_ms);
return (retval == 0) ? ADSP_IPI_DONE : ADSP_IPI_ERROR;
}
enum adsp_ipi_status adsp_ipi_send_ipc(enum adsp_ipi_id id, void *buf,
unsigned int len, unsigned int wait,
unsigned int adsp_id)
{
struct adsp_priv *pdata = get_adsp_core_by_id(adsp_id);
struct ipi_ctrl_s *ctrl;
struct adsp_share_obj *send_obj;
struct ipi_msg_t *p_ipi_msg = NULL;
ktime_t start_time;
s64 time_ipc_us;
static bool busy_log_flag;
static u8 share_buf[SHARE_BUF_SIZE - 16];
if (unlikely(!pdata))
return -EACCES;
ctrl = pdata->ipi_ctrl;
send_obj = ctrl->send_obj;
if (in_interrupt() && wait) {
pr_info("adsp_ipi_send: cannot use in isr");
return ADSP_IPI_ERROR;
}
if (len > sizeof(send_obj->share_buf) || buf == NULL) {
pr_info("adsp_ipi_send: %s buffer error",
adsp_core_ids[pdata->id]);
return ADSP_IPI_ERROR;
}
if (mutex_trylock(&ctrl->lock) == 0) {
pr_info("adsp_ipi_send:%s %d mutex_trylock busy,owner=%d",
adsp_core_ids[pdata->id], id,
ctrl->ipi_mutex_owner);
return ADSP_IPI_BUSY;
}
/* get adsp ipi mutex owner */
ctrl->ipi_mutex_owner = id;
if (adsp_mt_check_sw_int(pdata->id) > 0) {
if (busy_log_flag == false) {
busy_log_flag = true;
p_ipi_msg = (struct ipi_msg_t *)share_buf;
if (p_ipi_msg->magic == IPI_MSG_MAGIC_NUMBER)
DUMP_IPI_MSG("busy. ipc owner", p_ipi_msg);
else
pr_info("adsp_ipi_send: %s %d host to adsp busy, ipi last time = %d",
adsp_core_ids[pdata->id], id,
ctrl->ipi_owner);
}
mutex_unlock(&ctrl->lock);
return ADSP_IPI_BUSY;
}
busy_log_flag = false;
/* get adsp ipi send owner */
ctrl->ipi_owner = id;
memcpy(share_buf, buf, len);
memcpy_toio((void *)send_obj->share_buf, buf, len);
send_obj->len = len;
send_obj->id = id;
dsb(SY);
/* send host to adsp ipi */
adsp_mt_set_sw_int(pdata->id);
if (wait) {
start_time = ktime_get();
while (adsp_mt_check_sw_int(pdata->id) > 0) {
time_ipc_us = ktime_us_delta(ktime_get(), start_time);
if (time_ipc_us > 1000) /* 1 ms */
break;
}
}
#ifdef Liang_Check
if (adsp_awake_unlock(pdata->id) == -1)
pr_debug("adsp_ipi_send: awake unlock fail");
#endif
mutex_unlock(&ctrl->lock);
return ADSP_IPI_DONE;
}
EXPORT_SYMBOL_GPL(adsp_ipi_send);
@@ -0,0 +1,42 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __ADSP_IPI_H
#define __ADSP_IPI_H
#include "adsp_helper.h"
#define SHARE_BUF_SIZE 288
/* adsp awake timeout count definition*/
#define ADSP_AWAKE_TIMEOUT 5000
struct adsp_ipi_desc {
void (*handler)(int id, void *data, unsigned int len);
const char *name;
};
struct adsp_share_obj {
enum adsp_ipi_id id;
unsigned int len;
unsigned char reserve[8];
unsigned char share_buf[SHARE_BUF_SIZE - 16];
};
struct ipi_ctrl_s {
enum adsp_ipi_id ipi_mutex_owner;
enum adsp_ipi_id ipi_owner;
struct adsp_share_obj *send_obj;
struct adsp_share_obj *recv_obj;
struct mutex lock; /* ap used */
};
void adsp_ipi_init(void);
void adsp_ipi_handler(int irq, void *data, int cid);
enum adsp_ipi_status adsp_ipi_send_ipc(enum adsp_ipi_id id, void *buf,
unsigned int len, unsigned int wait,
unsigned int adsp_id);
#endif
@@ -0,0 +1,11 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __ADSP_MBOX_H__
#define __ADSP_MBOX_H__
#include "adsp_ipi.h"
#endif /* __ADSP_MBOX_H__ */
@@ -0,0 +1,238 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#include <linux/io.h>
#include <linux/delay.h>
#include <mt-plat/sync_write.h>
#include "adsp_platform.h"
#include "adsp_reg.h"
#include "adsp_reserved_mem.h"
#include "adsp_semaphore.h"
#include "adsp_platform_driver.h"
#ifdef ADSP_BASE
#undef ADSP_BASE
#endif
#define ADSP_BASE mt_base
#define INFRACFG_AO_BASE infracfg_ao
#define PERICFG_BASE pericfg
#define SET_BITS(addr, mask) writel(readl(addr) | (mask), addr)
#define CLR_BITS(addr, mask) writel(readl(addr) & ~(mask), addr)
#ifdef CONFIG_ARM64
#define IOMEM(a) ((void __force __iomem *)((a)))
#endif
#define adsp_reg_read(addr) __raw_readl(IOMEM(addr))
#define adsp_reg_sync_write(addr, val) mt_reg_sync_writel(val, addr)
#define MAGIC_PATTERN (0xfafafafa)
static void __iomem *mt_base;
static void __iomem *infracfg_ao;
static void __iomem *pericfg;
void adsp_mt_sw_reset(u32 cid)
{
unsigned long flags;
if (unlikely(cid >= ADSP_CORE_TOTAL))
return;
write_lock_irqsave(&access_rwlock, flags);
SET_BITS(ADSP_CFGREG_SW_RSTN, ADSP_A_SW_RSTN);
udelay(1);
CLR_BITS(ADSP_CFGREG_SW_RSTN, ADSP_A_SW_RSTN);
write_unlock_irqrestore(&access_rwlock, flags);
}
void adsp_mt_run(u32 cid)
{
int timeout = 1000;
if (unlikely(cid >= ADSP_CORE_TOTAL))
return;
/* request infra/26M/apsrc/v18/ ddr resource */
SET_BITS(ADSP_SPM_REQ, ADSP_SPM_SRC_BITS);
SET_BITS(ADSP_DDREN_REQ, ADSP_DDR_ENABLE);
/* make sure SPM return ack */
while (timeout) {
if (readl(ADSP_SPM_ACK) == ((ADSP_DDR_ENABLE << 4) | ADSP_SPM_SRC_BITS))
break;
udelay(10);
if (--timeout == 0) {
pr_err("[ADSP] timeout: cannot get SPM ack\n");
break;
}
}
CLR_BITS(ADSP_HIFI3_IO_CONFIG, ADSP_A_RUNSTALL);
}
void adsp_mt_stop(u32 cid)
{
if (unlikely(cid >= ADSP_CORE_TOTAL))
return;
SET_BITS(ADSP_HIFI3_IO_CONFIG, ADSP_A_RUNSTALL);
}
void adsp_mt_clear(void)
{
writel(0x0, ADSP_CFGREG_SW_RSTN);
writel(0xC0001002, ADSP_HIFI3_IO_CONFIG);
writel(0, ADSP_CREG_BOOTUP_MARK);
writel(0xdf, ADSP_CLK_CTRL_BASE);
writel(0x0, ADSP_IRQ_EN);
writel(0x0, ADSP_A_WDT_REG);
}
void adsp_mt_clr_spm(u32 cid)
{
if (unlikely(cid >= ADSP_CORE_TOTAL))
return;
CLR_BITS(ADSP_A_SPM_WAKEUPSRC, ADSP_WAKEUP_SPM);
}
void adsp_mt_clr_sysirq(u32 cid)
{
if (unlikely(cid >= ADSP_CORE_TOTAL))
return;
writel(ADSP_A_2HOST_IRQ_BIT, ADSP_GENERAL_IRQ_CLR);
}
bool is_adsp_genirq_idle(u32 cid)
{
if (unlikely(cid >= ADSP_CORE_TOTAL))
return false;
return ((readl(ADSP_GENERAL_IRQ_SET) & ADSP_GENERAL_IRQ_INUSED)
== ADSP_GENERAL_IRQ_INUSED);
}
void adsp_mt_disable_wdt(u32 cid)
{
if (unlikely(cid >= ADSP_CORE_TOTAL))
return;
CLR_BITS(ADSP_A_WDT_REG, WDT_EN_BIT);
}
bool check_hifi_status(u32 mask)
{
return (readl(ADSP_SLEEP_STATUS_REG) & mask);
}
bool is_adsp_axibus_idle(void)
{
/* no pending counter found when ap read this reg in mt6785 */
return (readl(ADSP_DBG_PEND_CNT) == 0x000000);
}
void adsp_mt_set_bootup_mark(u32 cid)
{
if (unlikely(cid >= ADSP_CORE_TOTAL))
return;
writel(MAGIC_PATTERN, ADSP_CREG_BOOTUP_MARK);
}
u32 switch_adsp_clk_ctrl_cg(bool en, u32 mask)
{
u32 retval = readl(ADSP_CLK_CTRL_BASE);
if (en)
SET_BITS(ADSP_CLK_CTRL_BASE, mask);
else
CLR_BITS(ADSP_CLK_CTRL_BASE, mask);
return retval;
}
u32 switch_adsp_uart_ctrl_cg(bool en, u32 mask)
{
u32 retval = readl(ADSP_UART_CTRL);
if (en)
SET_BITS(ADSP_UART_CTRL, mask);
else
CLR_BITS(ADSP_UART_CTRL, mask);
return retval;
}
void adsp_mt_clr_sw_reset(void)
{
CLR_BITS(ADSP_CFGREG_SW_RSTN, ADSP_A_SW_RSTN);
}
void adsp_mt_set_sw_int(u32 cid)
{
if (unlikely(cid >= ADSP_CORE_TOTAL))
return;
adsp_reg_sync_write(ADSP_SW_INT_SET, (1 << cid));
}
u32 adsp_mt_check_sw_int(u32 cid)
{
if (unlikely(cid >= ADSP_CORE_TOTAL))
return 0;
return (adsp_reg_read(ADSP_SW_INT_SET) & (1 << cid));
}
void adsp_platform_init(void)
{
if (unlikely(!adsp_cores[0]))
return;
mt_base = adsp_cores[0]->cfg;
infracfg_ao = adsp_common.infracfg_ao;
pericfg = adsp_common.pericfg;
adsp_init_reserve_memory();
adsp_sem_init(SEMA_WAY_BITS, SEMA_CTRL_BIT,
SEMA_TIMEOUT, ADSP_SEMAPHORE);
}
/* mt6785 only */
static bool is_adsp_bus_protect_ready(void)
{
return ((adsp_reg_read(INFRA_AXI_PROT_STA1) & ADSP_AXI_PROT_READY_MASK)
== ADSP_AXI_PROT_READY_MASK);
}
void adsp_bus_sleep_protect(uint32_t enable)
{
int timeout = 1000;
if (enable) {
/* enable adsp bus protect */
adsp_reg_sync_write(INFRA_AXI_PROT_SET, ADSP_AXI_PROT_MASK);
while (--timeout && !is_adsp_bus_protect_ready())
udelay(1);
if (!is_adsp_bus_protect_ready())
pr_err("%s() ready timeout\n", __func__);
} else {
/* disable adsp bus protect */
adsp_reg_sync_write(INFRA_AXI_PROT_CLR, ADSP_AXI_PROT_MASK);
}
}
void adsp_way_en_ctrl(uint32_t enable)
{
if (enable)
adsp_reg_sync_write(ADSP_WAY_EN_CTRL,
adsp_reg_read(ADSP_WAY_EN_CTRL) | ADSP_WAY_EN_MASK);
else
adsp_reg_sync_write(ADSP_WAY_EN_CTRL,
adsp_reg_read(ADSP_WAY_EN_CTRL) & ~ADSP_WAY_EN_MASK);
}
@@ -0,0 +1,64 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __ADSP_PLATFORM_H__
#define __ADSP_PLATFORM_H__
enum adsp_irq_id {
ADSP_IRQ_WDT_ID = 0,
ADSP_IRQ_IPC_ID,
ADSP_IRQ_NUM, /* id > ADSP_IRQ_NUM: not support */
ADSP_IRQ_AUDIO_ID,
};
enum adsp_core_id {
ADSP_A_ID = 0,
ADSP_CORE_TOTAL,
};
enum adsp_sharedmem_id {
ADSP_SHAREDMEM_MPUINFO,
ADSP_SHAREDMEM_TIMESYNC,
ADSP_SHAREDMEM_IPCBUF,
ADSP_SHAREDMEM_AUDIO_IPIBUF,
ADSP_SHAREDMEM_WAKELOCK,
ADSP_SHAREDMEM_SYS_STATUS,
ADSP_SHAREDMEM_BUS_MON_DUMP,
ADSP_SHAREDMEM_INFRA_BUS_DUMP,
ADSP_SHAREDMEM_NUM,
};
/* semaphore */
#define SEMA_TIMEOUT 5000
#define SEMA_WAY_BITS 2
#define SEMA_CTRL_BIT 1
/* platform method */
void adsp_mt_sw_reset(u32 cid);
void adsp_mt_run(u32 cid);
void adsp_mt_stop(u32 cid);
void adsp_mt_clear(void);
void adsp_mt_clr_sw_reset(void);
void adsp_mt_clr_sysirq(u32 cid);
void adsp_mt_clr_spm(u32 cid);
void adsp_mt_disable_wdt(u32 cid);
void adsp_mt_set_sw_int(u32 cid);
u32 adsp_mt_check_sw_int(u32 cid);
void adsp_mt_set_bootup_mark(u32 cid);
bool check_hifi_status(u32 mask);
bool is_adsp_axibus_idle(void);
bool is_adsp_genirq_idle(u32 cid);
u32 switch_adsp_clk_ctrl_cg(bool en, u32 mask);
u32 switch_adsp_uart_ctrl_cg(bool en, u32 mask);
void adsp_platform_init(void);
/* mt6785 only: system usage */
void adsp_bus_sleep_protect(uint32_t enable);
void adsp_way_en_ctrl(uint32_t enable);
extern rwlock_t access_rwlock;
#endif
@@ -0,0 +1,577 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#include <linux/sysfs.h>
#ifdef CONFIG_DEBUG_FS
#include <linux/debugfs.h>
#endif
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/io.h>
#include <linux/delay.h>
#include <linux/platform_device.h>
#include <linux/kobject.h>
#include <linux/ktime.h>
#include <linux/syscore_ops.h>
#include "adsp_clk.h"
#include "adsp_reserved_mem.h"
#include "adsp_logger.h"
#include "adsp_excep.h"
#include "adsp_reg.h"
#include "adsp_platform.h"
#include "adsp_platform_driver.h"
#include "adsp_core.h"
#include "adsp_ipi.h"
#include "adsp_bus_monitor.h"
#include "adsp_timesync.h"
#include <linux/suspend.h>
#include <linux/arm-smccc.h> /* for Kernel Native SMC API */
#include <mt-plat/mtk_secure_api.h> /* for SMC ID table */
#include <mt6781-afe-common.h>
struct wait_queue_head adsp_waitq;
struct workqueue_struct *adsp_wq;
struct adsp_com adsp_common;
struct adsp_priv *adsp_cores[ADSP_CORE_TOTAL];
static u32 adsp_load;
static int adsp_core0_init(struct adsp_priv *pdata);
static int adsp_core0_suspend(void);
static int adsp_core0_resume(void);
static void adsp_logger_init0_cb(struct work_struct *ws);
static int adsp_after_bootup(struct adsp_priv *pdata);
static const struct adsp_description adsp_c0_desc = {
.id = 0,
.name = "adsp_0",
.sharedmems = {
[ADSP_SHAREDMEM_MPUINFO] = {0x0020, 0x0020},
[ADSP_SHAREDMEM_TIMESYNC] = {0x0040, 0x0020},
[ADSP_SHAREDMEM_IPCBUF] = {0x0280, 0x0240},
[ADSP_SHAREDMEM_AUDIO_IPIBUF] = {0x0680, 0x0400},
[ADSP_SHAREDMEM_WAKELOCK] = {0x0684, 0x0004},
[ADSP_SHAREDMEM_SYS_STATUS] = {0x0688, 0x0004},
[ADSP_SHAREDMEM_BUS_MON_DUMP] = {0x0744, 0x00BC},
[ADSP_SHAREDMEM_INFRA_BUS_DUMP] = {0x07E4, 0x00A0},
},
.ops = {
.initialize = adsp_core0_init,
.after_bootup = adsp_after_bootup,
}
};
/*------------------------------------------------------------*/
/* adsp operation */
int adsp_core0_init(struct adsp_priv *pdata)
{
int ret = 0;
#ifdef CONFIG_DEBUG_FS
pdata->debugfs = debugfs_create_file("audiodsp0", S_IFREG | 0644, NULL,
pdata, &adsp_debug_ops);
#endif
adsp_wq = alloc_workqueue("adsp_wq", WORK_CPU_UNBOUND | WQ_HIGHPRI, 0);
pdata->wq = adsp_wq;
init_waitqueue_head(&adsp_waitq);
init_adsp_feature_control(pdata->id, pdata->feature_set, 1000,
adsp_wq,
adsp_core0_suspend,
adsp_core0_resume);
adsp_update_mpu_memory_info(pdata);
/* exception init & irq */
init_adsp_exception_control(pdata->dev, adsp_wq, &adsp_waitq);
adsp_irq_registration(pdata->id, ADSP_IRQ_WDT_ID, adsp_wdt_handler,
pdata);
/* logger */
pdata->log_ctrl = adsp_logger_init(ADSP_A_LOGGER_MEM_ID, adsp_logger_init0_cb);
/* ipi */
adsp_ipi_init();
adsp_irq_registration(pdata->id, ADSP_IRQ_IPC_ID, adsp_ipi_handler,
pdata);
adsp_awake_init(pdata, ADSP_A_SW_INT);
#if ADSP_BUS_MONITOR_INIT_ENABLE
adsp_bus_monitor_init(pdata);
#endif
return ret;
}
bool is_adsp_load(void)
{
return adsp_load;
}
static int adsp_after_bootup(struct adsp_priv *pdata)
{
#ifdef BRINGUP_ADSP
/* disable adsp suspend by registering feature */
_adsp_register_feature(pdata->id, SYSTEM_FEATURE_ID, 0);
#endif
return adsp_awake_unlock(pdata->id);
}
static bool is_adsp_core_suspend(struct adsp_priv *pdata)
{
u32 status = 0;
if (unlikely(!pdata))
return false;
adsp_copy_from_sharedmem(pdata,
ADSP_SHAREDMEM_SYS_STATUS,
&status, sizeof(status));
return check_hifi_status(ADSP_A_IS_WFI) &&
check_hifi_status(ADSP_AXI_BUS_IS_IDLE) &&
(status == ADSP_SUSPEND) &&
is_adsp_genirq_idle(pdata->id);
}
static void show_adsp_core_suspend(struct adsp_priv *pdata)
{
u32 status = 0;
if (unlikely(!pdata))
return;
adsp_copy_from_sharedmem(pdata,
ADSP_SHAREDMEM_SYS_STATUS,
&status, sizeof(status));
pr_info("%s(), IS_WFI(%d), IS_BUS_IDLE(%d), STATUS(%d), IRQ_IDLE(%d)",
__func__,
check_hifi_status(ADSP_A_IS_WFI),
check_hifi_status(ADSP_AXI_BUS_IS_IDLE),
status,
is_adsp_genirq_idle(pdata->id));
}
int adsp_core0_suspend(void)
{
int ret = 0, retry = 10;
u32 status = 0;
struct adsp_priv *pdata = adsp_cores[ADSP_A_ID];
ktime_t start = ktime_get();
if (get_adsp_state(pdata) == ADSP_RUNNING) {
reinit_completion(&pdata->done);
adsp_timesync_suspend(APTIME_UNFREEZE);
ret = adsp_push_message(ADSP_IPI_DVFS_SUSPEND, &status,
sizeof(status), 2000, pdata->id);
if (ret != ADSP_IPI_DONE) {
ret = -EPIPE;
goto ERROR;
}
/* wait core suspend ack timeout 2s */
ret = wait_for_completion_timeout(&pdata->done, 2 * HZ);
if (!ret) {
ret = -ETIMEDOUT;
goto ERROR;
}
while (--retry && !is_adsp_core_suspend(pdata))
usleep_range(100, 200);
if (retry == 0 || get_adsp_state(pdata) == ADSP_RESET) {
show_adsp_core_suspend(pdata);
ret = -ETIME;
goto ERROR;
}
if (get_adsp_state(pdata) == ADSP_RESET) {
ret = -EFAULT;
goto ERROR;
}
adsp_mt_stop(pdata->id);
switch_adsp_power(false);
set_adsp_state(pdata, ADSP_SUSPEND);
}
pr_info("%s(), done elapse %lld us", __func__,
ktime_us_delta(ktime_get(), start));
return 0;
ERROR:
pr_warn("%s(), can't going to suspend, ret(%d)\n", __func__, ret);
adsp_aed_dispatch(EXCEP_KERNEL, pdata);
return ret;
}
int adsp_core0_resume(void)
{
int ret = 0;
struct adsp_priv *pdata = adsp_cores[ADSP_A_ID];
ktime_t start = ktime_get();
if (get_adsp_state(pdata) == ADSP_SUSPEND) {
switch_adsp_power(true);
adsp_mt_sw_reset(pdata->id);
#if ADSP_BUS_MONITOR_INIT_ENABLE
adsp_bus_monitor_init(pdata);
#endif
adsp_mt_set_bootup_mark(pdata->id);
reinit_completion(&pdata->done);
adsp_mt_run(pdata->id);
ret = wait_for_completion_timeout(&pdata->done, 2 * HZ);
if (get_adsp_state(pdata) != ADSP_RUNNING) {
pr_warn("%s, can't going to resume\n", __func__);
adsp_aed_dispatch(EXCEP_KERNEL, pdata);
return -ETIME;
}
adsp_timesync_resume();
}
pr_info("%s(), done elapse %lld us", __func__,
ktime_us_delta(ktime_get(), start));
return 0;
}
void adsp_logger_init0_cb(struct work_struct *ws)
{
int ret;
uint64_t info[6];
info[0] = adsp_get_reserve_mem_phys(ADSP_A_LOGGER_MEM_ID);
info[1] = (uint64_t)adsp_get_reserve_mem_size(ADSP_A_LOGGER_MEM_ID);
info[2] = adsp_get_reserve_mem_phys(ADSP_A_CORE_DUMP_MEM_ID);
info[3] = (uint64_t)adsp_get_reserve_mem_size(ADSP_A_CORE_DUMP_MEM_ID);
info[4] = adsp_get_reserve_mem_phys(ADSP_A_DEBUG_DUMP_MEM_ID);
info[5] = (uint64_t)adsp_get_reserve_mem_size(ADSP_A_DEBUG_DUMP_MEM_ID);
_adsp_register_feature(ADSP_A_ID, ADSP_LOGGER_FEATURE_ID, 0);
ret = adsp_push_message(ADSP_IPI_LOGGER_INIT, (void *)info,
sizeof(info), 20, ADSP_A_ID);
_adsp_deregister_feature(ADSP_A_ID, ADSP_LOGGER_FEATURE_ID, 0);
if (ret != ADSP_IPI_DONE)
pr_err("[ADSP]logger initial fail, ipi ret=%d\n", ret);
}
/*---------------------------------------------------------------------------*/
static const struct of_device_id adsp_of_ids[] = {
{ .compatible = "mediatek,adsp_core_0", .data = &adsp_c0_desc},
{}
};
static const struct of_device_id adsp_common_of_ids[] = {
{ .compatible = "mediatek,adsp_common"},
{}
};
const struct attribute_group *adsp_common_attr_groups[] = {
&adsp_excep_attr_group,
NULL,
};
const struct attribute_group *adsp_core_attr_groups[] = {
&adsp_default_attr_group,
NULL,
};
static struct miscdevice adsp_common_device = {
.minor = MISC_DYNAMIC_MINOR,
.name = "adsp",
.groups = adsp_common_attr_groups,
.fops = &adsp_common_file_ops,
};
/* user-space event notify */
static int adsp_user_event_notify(struct notifier_block *nb,
unsigned long event, void *ptr)
{
struct device *dev = adsp_common_device.this_device;
int ret = 0;
if (!dev)
return NOTIFY_DONE;
switch (event) {
case ADSP_EVENT_STOP:
ret = kobject_uevent(&dev->kobj, KOBJ_OFFLINE);
break;
case ADSP_EVENT_READY:
ret = kobject_uevent(&dev->kobj, KOBJ_ONLINE);
break;
default:
pr_info("%s, ignore event %lu", __func__, event);
break;
}
if (ret)
pr_info("%s, uevnet(%lu) fail, ret %d", __func__, event, ret);
return NOTIFY_OK;
}
struct notifier_block adsp_uevent_notifier = {
.notifier_call = adsp_user_event_notify,
.priority = AUDIO_HAL_FEATURE_PRI,
};
#ifdef CONFIG_PM
static int adsp_pm_event(struct notifier_block *notifier
, unsigned long pm_event, void *unused)
{
struct arm_smccc_res res;
switch (pm_event) {
case PM_POST_HIBERNATION:
pr_notice("[ADSP] %s: reboot\n", __func__);
adsp_reset();
return NOTIFY_DONE;
case PM_SUSPEND_PREPARE:
if (adsp_feature_is_active(ADSP_A_ID))
arm_smccc_smc(MTK_SIP_AUDIO_CONTROL,
MTK_AUDIO_SMC_OP_ADSP_REQUEST,
0, 0, 0, 0, 0, 0, &res);
return NOTIFY_DONE;
case PM_POST_SUSPEND:
if (adsp_feature_is_active(ADSP_A_ID))
arm_smccc_smc(MTK_SIP_AUDIO_CONTROL,
MTK_AUDIO_SMC_OP_ADSP_RELEASE,
0, 0, 0, 0, 0, 0, &res);
return NOTIFY_DONE;
}
return NOTIFY_OK;
}
static struct notifier_block adsp_pm_notifier_block = {
.notifier_call = adsp_pm_event,
.priority = 0,
};
#endif
static int adsp_common_drv_probe(struct platform_device *pdev)
{
int ret = 0;
struct device *dev = &pdev->dev;
/* indicate if adsp images is loaded successfully */
of_property_read_u32(dev->of_node, "load", &adsp_load);
if (!adsp_load)
pr_info("%s adsp disable\n", __func__);
adsp_common.infracfg_ao = of_iomap(dev->of_node, 0);
if (IS_ERR(adsp_common.infracfg_ao))
goto ERROR;
adsp_common.pericfg = of_iomap(dev->of_node, 1);
if (IS_ERR(adsp_common.pericfg))
goto ERROR;
ret = adsp_clk_device_probe(pdev);
if (ret) {
pr_warn("%s(), clk probe fail, %d\n", __func__, ret);
goto ERROR;
}
ret = adsp_mem_device_probe(pdev);
if (ret) {
pr_info("%s(), memory probe fail, %d\n", __func__, ret);
goto ERROR;
}
ret = misc_register(&adsp_common_device);
if (ret) {
pr_warn("%s(), misc_register fail, %d\n", __func__, ret);
goto ERROR;
}
adsp_register_notify(&adsp_uevent_notifier);
#ifdef CONFIG_PM
ret = register_pm_notifier(&adsp_pm_notifier_block);
if (ret)
pr_info("[ADSP] failed to register PM notifier %d\n", ret);
#endif
pr_info("%s, success\n", __func__);
ERROR:
return ret;
}
static int adsp_common_drv_remove(struct platform_device *pdev)
{
return 0;
}
static int adsp_core_drv_probe(struct platform_device *pdev)
{
int ret = 0;
struct resource *res;
struct device *dev = &pdev->dev;
struct adsp_priv *pdata;
const struct adsp_description *desc;
const struct of_device_id *match;
u32 temp = 0;
/* create private data */
pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
if (!pdata)
return -ENOMEM;
match = of_match_node(adsp_of_ids, dev->of_node);
if (!match)
return -ENODEV;
desc = (struct adsp_description *)match->data;
pdata->id = desc->id;
pdata->name = desc->name;
pdata->ops = &desc->ops;
pdata->mapping_table = desc->sharedmems;
pdata->dev = dev;
init_completion(&pdata->done);
/* get resource from platform_device */
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
pdata->cfg = devm_ioremap_resource(dev, res);
pdata->cfg_size = resource_size(res);
res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
pdata->itcm = devm_ioremap_resource(dev, res);
pdata->itcm_size = resource_size(res);
res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
pdata->dtcm = devm_ioremap_resource(dev, res);
pdata->dtcm_size = resource_size(res);
pdata->irq[ADSP_IRQ_WDT_ID].seq = platform_get_irq(pdev, 0);
pdata->irq[ADSP_IRQ_WDT_ID].clear_irq = adsp_mt_disable_wdt;
pdata->irq[ADSP_IRQ_IPC_ID].seq = platform_get_irq(pdev, 1);
/* adsp_ipi clr irq by itself */
/* pdata->irq[ADSP_IRQ_IPC_ID].clear_irq = adsp_mt_clr_sysirq; */
of_property_read_u32(dev->of_node, "sysram", &temp);
pdata->sysram_phys = (phys_addr_t)temp;
of_property_read_u32(dev->of_node, "sysram_size", &temp);
pdata->sysram_size = (size_t)temp;
if (pdata->sysram_phys == 0 || pdata->sysram_size == 0) {
ret = -ENODEV;
goto ERROR;
}
pdata->sysram = ioremap_wc(pdata->sysram_phys, pdata->sysram_size);
pdata->feature_set = 0xffffffff; //no need for one core platform
/* register misc device */
pdata->mdev.minor = MISC_DYNAMIC_MINOR;
pdata->mdev.name = desc->name;
pdata->mdev.fops = &adsp_core_file_ops;
pdata->mdev.groups = adsp_core_attr_groups;
ret = misc_register(&pdata->mdev);
if (unlikely(ret != 0))
goto ERROR;
/* add to adsp_core list */
adsp_cores[desc->id] = pdata;
pr_info("%s, id:%d success\n", __func__, pdata->id);
return 0;
ERROR:
pr_err("%s id:%d fail, ret = %d", __func__, pdata->id, ret);
return ret;
}
static int adsp_core_drv_remove(struct platform_device *pdev)
{
return 0;
}
static int adsp_ap_suspend(struct device *dev)
{
int cid = 0, ret = 0;
struct adsp_priv *pdata = NULL;
for (cid = ADSP_CORE_TOTAL - 1; cid >= 0; cid--) {
pdata = adsp_cores[cid];
if (pdata->state == ADSP_RUNNING) {
ret = flush_suspend_work(pdata->id);
pr_info("%s, flush_suspend_work ret %d, cid %d",
__func__, ret, cid);
}
}
if (is_adsp_system_running()) {
adsp_timesync_suspend(APTIME_FREEZE);
pr_info("%s, time sync freeze", __func__);
}
return 0;
}
static int adsp_ap_resume(struct device *dev)
{
if (is_adsp_system_running()) {
adsp_timesync_resume();
pr_info("%s, time sync unfreeze", __func__);
}
return 0;
}
static const struct dev_pm_ops adsp_ap_pm_ops = {
SET_SYSTEM_SLEEP_PM_OPS(adsp_ap_suspend,
adsp_ap_resume)
};
static struct platform_driver adsp_common_driver = {
.probe = adsp_common_drv_probe,
.remove = adsp_common_drv_remove,
.driver = {
.name = "adsp_common",
.owner = THIS_MODULE,
#ifdef CONFIG_OF
.of_match_table = adsp_common_of_ids,
#endif
#ifdef CONFIG_PM
.pm = &adsp_ap_pm_ops,
#endif
},
};
static struct platform_driver adsp_core0_driver = {
.probe = adsp_core_drv_probe,
.remove = adsp_core_drv_remove,
.driver = {
.name = "adsp_core0",
.owner = THIS_MODULE,
#ifdef CONFIG_OF
.of_match_table = adsp_of_ids,
#endif
},
};
static struct platform_driver * const drivers[] = {
&adsp_common_driver,
&adsp_core0_driver,
};
int create_adsp_drivers(void)
{
int ret = 0;
ret = platform_register_drivers(drivers, ARRAY_SIZE(drivers));
return (is_adsp_load() && adsp_cores[0] && ~ret);
}
@@ -0,0 +1,105 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __ADSP_PLATFORM_DRIVER_H__
#define __ADSP_PLATFORM_DRIVER_H__
#include <linux/miscdevice.h> /* needed by miscdevice* */
#include <linux/workqueue.h>
#include <linux/interrupt.h>
#include "adsp_platform.h"
struct adsp_priv;
struct log_ctrl_s;
struct sharedmem_info {
unsigned int offset;
unsigned int size;
};
struct adsp_operations {
int (*initialize)(struct adsp_priv *pdata);
int (*after_bootup)(struct adsp_priv *pdata);
};
struct adsp_description {
u32 id;
const char *name;
const struct sharedmem_info sharedmems[ADSP_SHAREDMEM_NUM];
const struct adsp_operations ops;
};
struct irq_t {
u32 cid;
u32 seq;
void (*irq_cb)(int irq, void *data, int cid);
void (*clear_irq)(u32 cid);
void *data;
};
struct adsp_com {
void __iomem *infracfg_ao;
void __iomem *pericfg;
};
struct adsp_priv {
u32 id;
const char *name;
int state;
unsigned int feature_set;
/* address & size */
void __iomem *cfg;
void __iomem *itcm;
void __iomem *dtcm;
void __iomem *sysram;
size_t cfg_size;
size_t itcm_size;
size_t dtcm_size;
size_t sysram_size;
phys_addr_t sysram_phys;
const struct sharedmem_info *mapping_table;
/* irq */
struct irq_t irq[ADSP_IRQ_NUM];
/* mailbox info: keep for dev_dump_show() in adsp_fs.c */
struct mtk_mbox_pin_send *send_mbox;
struct mtk_mbox_pin_recv *recv_mbox;
/* ipi info */
struct ipi_ctrl_s *ipi_ctrl;
/* logger control */
struct log_ctrl_s *log_ctrl;
struct device *dev;
struct dentry *debugfs;
struct miscdevice mdev;
struct workqueue_struct *wq;
struct completion done;
/* method */
const struct adsp_operations *ops;
/* snapshot for recovery restore */
void *itcm_snapshot;
void *dtcm_snapshot;
};
struct adsp_c2c_share_dram_info_t {
u32 share_dram_addr;
u32 share_dram_size;
};
int create_adsp_drivers(void);
bool is_adsp_load(void);
extern struct attribute_group adsp_default_attr_group;
extern struct attribute_group adsp_excep_attr_group;
extern const struct file_operations adsp_debug_ops;
extern const struct file_operations adsp_common_file_ops;
extern const struct file_operations adsp_core_file_ops;
extern struct adsp_priv *adsp_cores[ADSP_CORE_TOTAL];
extern struct adsp_com adsp_common;
#endif
@@ -0,0 +1,126 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __ADSP_REG_H
#define __ADSP_REG_H
#define ADSP_CFGREG_SW_RSTN (ADSP_BASE + 0x00)
#define ADSP_A_SW_RSTN (0x11)
#define ADSP_HIFI3_IO_CONFIG (ADSP_BASE + 0x0008)
#define ADSP_A_RUNSTALL (1 << 31)
#define ADSP_RUNSTALL (ADSP_A_RUNSTALL)
/* swint register no update naming */
#define ADSP_SW_INT_SET (ADSP_BASE + 0x001C)
#define ADSP_SW_INT_CLR (ADSP_BASE + 0x0020)
#define ADSP_SW_INT0 (0)
#define ADSP_SW_INT1 (1)
#define ADSP_SW_INT2 (2)
#define ADSP_SW_INT3 (3)
#define HOST_TO_ADSP_A (1 << 0)
#define ADSP_A_SW_INT (1 << ADSP_SW_INT1)
#define ADSP_GENERAL_IRQ_SET (ADSP_BASE + 0x0034)
#define ADSP_GENERAL_IRQ_CLR (ADSP_BASE + 0x0038)
#define ADSP_A_2HOST_IRQ_BIT (1 << 0)
#define ADSP_A_2CONN_IRQ_BIT (1 << 4)
#define ADSP_GENERAL_IRQ_INUSED \
(ADSP_A_2HOST_IRQ_BIT)
#define ADSP_DVFSRC_STATE (ADSP_BASE + 0x003C)
#define ADSP_DVFSRC_REQ (ADSP_BASE + 0x0040)
#define ADSP_DDREN_REQ (ADSP_BASE + 0x0044)
#define ADSP_DDR_REQ_SEL (0x3 << 4) // hw auto ddren
#define ADSP_DDR_ENABLE (1 << 0)
#define ADSP_SPM_REQ (ADSP_BASE + 0x0048)
#define ADSP_SPM_ACK (ADSP_BASE + 0x004C)
#define ADSP_SPM_SRC_BITS (0xF << 0)
#define ADSP_IRQ_EN (ADSP_BASE + 0x0050)
#define ADSP_A_SPM_WAKEUPSRC (ADSP_BASE + 0x005C)
#define ADSP_WAKEUP_SPM (0x1 << 0)
#define ADSP_SEMAPHORE (ADSP_BASE + 0x0058)
#define ADSP_A_WDT_REG (ADSP_BASE + 0x007C)
#define ADSP_A_WDT_INIT_VALUE (ADSP_BASE + 0x0080)
#define ADSP_A_WDT_CNT (ADSP_BASE + 0x0084)
#define ADSP_WDT_TRIGGER (ADSP_A_WDT_INIT_VALUE)
#define WDT_EN_BIT (1 << 31)
#define WDT_DIS_BIT (0 << 31)
#define WDT_KICK_BIT 0
#define ADSP_CFGREG_RSV_RW_REG0 (ADSP_BASE + 0x008C)
#define ADSP_CFGREG_RSV_RW_REG1 (ADSP_BASE + 0x0090)
#define ADSP_CREG_BOOTUP_MARK ADSP_CFGREG_RSV_RW_REG0
/* Latch Debug info after WDT */
#define ADSP_A_WDT_DEBUG_PC_REG (ADSP_BASE + 0x0170)
#define ADSP_A_WDT_DEBUG_SP_REG (ADSP_BASE + 0x0174)
/* TODO : add in aee dump */
#define ADSP_A_WDT_EXCVADDR_REG (ADSP_BASE + 0x0178)
/* TODO : add in aee dump */
#define ADSP_A_WDT_EXCCAUSE_REG (ADSP_BASE + 0x017C)
/* Wakeup ADSP interrupt */
#define ADSP_WAKEUPSRC_MASK (ADSP_BASE + 0x00A8)
#define ADSP_WAKEUPSRC_IRQ (ADSP_BASE + 0x00AC)
/*latency monitor*/
#define ADSP_LATMON_DVFS_MODE (ADSP_BASE + 0x0100)
#define ADSP_LATMON_CON1 (ADSP_BASE + 0x0104)
#define ADSP_LATMON_CON2 (ADSP_BASE + 0x0108)
#define ADSP_LATMON_MARGIN (ADSP_BASE + 0x010C)
#define ADSP_LATMON_THRESHOLD (ADSP_BASE + 0x0110)
#define ADSP_LATMON_STATE (ADSP_BASE + 0x0114)
#define ADSP_LATMON_ACCCNT (ADSP_BASE + 0x0118)
/* latency threshold & budget for 0.8V. 0.7V. 0.625V */
#define ADSP_LATMON_CONT0 (ADSP_BASE + 0x012C)
#define ADSP_LATMON_CONT1 (ADSP_BASE + 0x0130)
#define ADSP_LATMON_CONT2 (ADSP_BASE + 0x0134)
#define ADSP_A_DEBUG_PC_REG (ADSP_BASE + 0x013C)
#define ADSP_DBG_PEND_CNT (ADSP_BASE + 0x015C)
#define ADSP_SLEEP_STATUS_REG (ADSP_BASE + 0x0158)
#define ADSP_BUS_MON_BASE (ADSP_BASE + 0x5000)
#define ADSP_A_IS_WFI (1 << 0)
#define ADSP_AXI_BUS_IS_IDLE (1 << 1)
/* clk reg */
#define ADSP_CLK_CTRL_BASE (ADSP_BASE + 0x1000)
#define ADSP_CLK_UART_EN (1 << 5)
#define ADSP_CLK_DMA_EN (1 << 4)
#define ADSP_CLK_TIMER_EN (1 << 3)
#define ADSP_CLK_CORE_0_EN (1 << 0)
#define ADSP_UART_CTRL (ADSP_BASE + 0x1010)
#define ADSP_UART_RST_N (1 << 3)
#define ADSP_UART_CLK_SEL (1 << 1)
#define ADSP_UART_BCLK_CG (1 << 0)
/* INFRA_IRQ (always on register) */
#define INFRA_AXI_PROT (INFRACFG_AO_BASE + 0x0220)
#define INFRA_AXI_PROT_STA1 (INFRACFG_AO_BASE + 0x0228)
#define INFRA_AXI_PROT_SET (INFRACFG_AO_BASE + 0x02A0)
#define INFRA_AXI_PROT_CLR (INFRACFG_AO_BASE + 0x02A4)
#define ADSP_AXI_PROT_MASK (0x1 << 15)
#define ADSP_AXI_PROT_READY_MASK (0x1 << 15)
#define ADSP_WAY_EN_CTRL (PERICFG_BASE + 0x0210)
#define ADSP_WAY_EN_MASK (0x1 << 9)
#define AP_AWAKE_LOCK_BIT (0)
#define AP_AWAKE_UNLOCK_BIT (1)
#define CONNSYS_AWAKE_LOCK (2)
#define CONNSYS_AWAKE_UNLOCK (3)
#define AP_AWAKE_DUMP_BIT (4)
#define AP_AWAKE_UPDATE_BIT (5)
#define AP_AWAKE_STATE_BIT (6)
#define ADSPPLL_UNLOCK_BIT (8)
#define ADSP_ADSP2SPM_VOL_LV (ADSP_BASE + 0x0094)
#endif
@@ -0,0 +1,205 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#include <linux/io.h>
#ifdef CONFIG_OF_RESERVED_MEM
#include <linux/of.h>
#include <linux/of_reserved_mem.h>
#endif
#if defined(CONFIG_MEDIATEK_EMI)
#include <memory/mediatek/emi.h>
#endif
#include "adsp_reserved_mem.h"
#include "adsp_feature_define.h"
#include "adsp_platform.h"
#include "adsp_core.h"
#define ADSP_RESERVE_MEMORY_BLOCK(xname) \
{.phys_addr = 0x0, .virt_addr = NULL, \
.size = 0, .name = xname}
static struct adsp_reserve_mblock adsp_reserve_mem = {0};
static struct adsp_reserve_mblock adsp_reserve_mblocks[] = {
[ADSP_A_IPI_DMA_MEM_ID]
= ADSP_RESERVE_MEMORY_BLOCK("adsp-rsv-ipidma-a"),
[ADSP_A_LOGGER_MEM_ID]
= ADSP_RESERVE_MEMORY_BLOCK("adsp-rsv-logger-a"),
[ADSP_A_DEBUG_DUMP_MEM_ID]
= ADSP_RESERVE_MEMORY_BLOCK("adsp-rsv-dbg-dump-a"),
[ADSP_A_CORE_DUMP_MEM_ID]
= ADSP_RESERVE_MEMORY_BLOCK("adsp-rsv-core-dump-a"),
#ifndef CONFIG_FPGA_EARLY_PORTING
[ADSP_AUDIO_COMMON_MEM_ID]
= ADSP_RESERVE_MEMORY_BLOCK("adsp-rsv-audio"),
#endif
};
static struct adsp_reserve_mblock *adsp_get_reserve_mblock(
enum adsp_reserve_mem_id_t id)
{
void *va_start = adsp_reserve_mblocks[0].virt_addr;
if (id >= ADSP_NUMS_MEM_ID) {
pr_info("%s no reserve memory for %d\n", __func__, id);
return NULL;
}
if (!va_start) {
pr_info("%s va_start is NULL\n", __func__);
return NULL;
}
return &adsp_reserve_mblocks[id];
}
phys_addr_t adsp_get_reserve_mem_phys(enum adsp_reserve_mem_id_t id)
{
struct adsp_reserve_mblock *mblk = adsp_get_reserve_mblock(id);
return mblk ? mblk->phys_addr : 0;
}
void *adsp_get_reserve_mem_virt(enum adsp_reserve_mem_id_t id)
{
struct adsp_reserve_mblock *mblk = adsp_get_reserve_mblock(id);
return mblk ? mblk->virt_addr : NULL;
}
size_t adsp_get_reserve_mem_size(enum adsp_reserve_mem_id_t id)
{
struct adsp_reserve_mblock *mblk = adsp_get_reserve_mblock(id);
return mblk ? mblk->size : 0;
}
void adsp_set_emimpu_shared_region(void)
{
#if defined(CONFIG_MEDIATEK_EMI)
struct emimpu_region_t adsp_region;
struct adsp_reserve_mblock *mem = &adsp_reserve_mem;
int ret = 0;
ret = mtk_emimpu_init_region(&adsp_region,
MPU_PROCT_REGION_ADSP_SHARED);
if (ret < 0) {
pr_info("%s fail to init emimpu region\n", __func__);
return;
}
mtk_emimpu_set_addr(&adsp_region, mem->phys_addr,
(mem->phys_addr + mem->size - 0x1));
mtk_emimpu_set_apc(&adsp_region, MPU_PROCT_D0_AP,
MTK_EMIMPU_NO_PROTECTION);
mtk_emimpu_set_apc(&adsp_region, MPU_PROCT_D10_ADSP,
MTK_EMIMPU_NO_PROTECTION);
ret = mtk_emimpu_set_protection(&adsp_region);
if (ret < 0)
pr_info("%s fail to set emimpu protection\n", __func__);
mtk_emimpu_free_region(&adsp_region);
#else
pr_info("%s(), emi config not enable", __func__);
#endif
}
int adsp_mem_device_probe(struct platform_device *pdev)
{
int ret = 0;
int i = 0;
uint32_t size = 0;
struct device *dev = &pdev->dev;
for (i = 0; i < ADSP_NUMS_MEM_ID; i++) {
ret = of_property_read_u32(dev->of_node,
adsp_reserve_mblocks[i].name, &size);
if (!ret)
adsp_reserve_mblocks[i].size = (size_t)size;
}
return 0;
}
void adsp_init_reserve_memory(void)
{
enum adsp_reserve_mem_id_t id;
struct adsp_reserve_mblock *mem = &adsp_reserve_mem;
size_t acc_size = 0;
if (!mem->phys_addr || !mem->size) {
pr_info("%s() reserve memory illegal addr:%llx, size:%zx\n",
__func__, mem->phys_addr, mem->size);
return;
}
mem->virt_addr = ioremap_wc(mem->phys_addr, mem->size);
if (!mem->virt_addr) {
pr_info("%s() ioremap fail\n", __func__);
return;
}
/* assign to each memory block */
for (id = 0; id < ADSP_NUMS_MEM_ID; id++) {
adsp_reserve_mblocks[id].phys_addr = mem->phys_addr + acc_size;
adsp_reserve_mblocks[id].virt_addr = mem->virt_addr + acc_size;
acc_size += ALIGN(adsp_reserve_mblocks[id].size, RSV_BLOCK_ALIGN);
#ifdef MEM_DEBUG
pr_info("adsp_reserve_mblocks[%d] phys_addr:%llx, size:0x%zx\n",
id,
adsp_reserve_mblocks[id].phys_addr,
adsp_reserve_mblocks[id].size);
#endif
}
WARN_ON(acc_size > mem->size);
}
ssize_t adsp_reserve_memory_dump(char *buffer, int size)
{
int n = 0, i = 0;
struct adsp_reserve_mblock *mem = &adsp_reserve_mem;
n += scnprintf(buffer + n, size - n,
"Reserve-memory-all:0x%llx 0x%p 0x%zx\n",
mem->phys_addr, mem->virt_addr, mem->size);
for (i = 0; i < ADSP_NUMS_MEM_ID; i++) {
mem = &adsp_reserve_mblocks[i];
n += scnprintf(buffer + n, size - n,
"Reserve-memory-Block[%02d]:0x%llx 0x%p 0x%zx\n",
i, mem->phys_addr, mem->virt_addr, mem->size);
}
return n;
}
#ifdef CONFIG_OF_RESERVED_MEM
#define ADSP_MEM_RESERVED_KEY "mediatek,reserve-memory-adsp_share"
static int __init adsp_reserve_mem_of_init(struct reserved_mem *rmem)
{
adsp_reserve_mem.phys_addr = (phys_addr_t) rmem->base;
adsp_reserve_mem.size = (size_t) rmem->size;
return 0;
}
RESERVEDMEM_OF_DECLARE(adsp_reserve_mem_init,
ADSP_MEM_RESERVED_KEY, adsp_reserve_mem_of_init);
#endif /* defined(CONFIG_OF_RESERVED_MEM) */
void adsp_update_mpu_memory_info(struct adsp_priv *pdata)
{
struct adsp_mpu_info_t mpu_info;
memset(&mpu_info, 0, sizeof(struct adsp_mpu_info_t));
mpu_info.share_dram_addr = (u32)adsp_reserve_mem.phys_addr;
mpu_info.share_dram_size = (u32)adsp_reserve_mem.size;
pr_info("[ADSP] mpu info=(0x%x, 0x%x)\n",
mpu_info.share_dram_addr, mpu_info.share_dram_size);
adsp_copy_to_sharedmem(pdata, ADSP_SHAREDMEM_MPUINFO,
&mpu_info, sizeof(struct adsp_mpu_info_t));
}
@@ -0,0 +1,58 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __ADSP_RESERVEDMEM_DEFINE_H__
#define __ADSP_RESERVEDMEM_DEFINE_H__
#include <linux/platform_device.h>
//#define MEM_DEBUG
/* emi mpu define */
#define MPU_PROCT_REGION_ADSP_SHARED 30
#define MPU_PROCT_D0_AP 0
#define MPU_PROCT_D10_ADSP 10
/* adsp mpu alignment = 4KB */
#define RSV_BLOCK_ALIGN 0x1000
/* adsp reserve memory ID definition*/
enum adsp_reserve_mem_id_t {
ADSP_A_IPI_DMA_MEM_ID = 0,
ADSP_A_LOGGER_MEM_ID,
ADSP_A_DEBUG_DUMP_MEM_ID,
ADSP_A_CORE_DUMP_MEM_ID,
#ifndef CONFIG_FPGA_EARLY_PORTING
ADSP_AUDIO_COMMON_MEM_ID,
#endif
ADSP_NUMS_MEM_ID,
};
struct adsp_reserve_mblock {
phys_addr_t phys_addr;
void *virt_addr;
size_t size;
char *name;
};
struct adsp_mpu_info_t {
u32 share_dram_addr;
u32 share_dram_size;
};
struct adsp_priv;
/* Reserved Memory Method */
phys_addr_t adsp_get_reserve_mem_phys(enum adsp_reserve_mem_id_t id);
void *adsp_get_reserve_mem_virt(enum adsp_reserve_mem_id_t id);
size_t adsp_get_reserve_mem_size(enum adsp_reserve_mem_id_t id);
int adsp_mem_device_probe(struct platform_device *pdev);
void adsp_init_reserve_memory(void);
ssize_t adsp_reserve_memory_dump(char *buffer, int size);
void adsp_set_emimpu_shared_region(void);
void adsp_update_mpu_memory_info(struct adsp_priv *pdata);
#endif /* __ADSP_RESERVEDMEM_DEFINE_H__ */
@@ -0,0 +1,22 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __ADSP_SERVICE_H__
#define __ADSP_SERVICE_H__
#include <linux/notifier.h>
#include <linux/interrupt.h>
#include "adsp_reg.h"
#include "adsp_feature_define.h"
#include "adsp_ipi.h"
void adsp_read_status_release(const unsigned long dsp_event);
void reset_hal_feature_table(void);
long adsp_driver_ioctl(
struct file *file, unsigned int cmd, unsigned long arg);
long adsp_driver_compat_ioctl(
struct file *file, unsigned int cmd, unsigned long arg);
#endif
@@ -0,0 +1,24 @@
# SPDX-License-Identifier: GPL-2.0
ADSP_VERSION := common_v2
ADSP_VERSION_PATH := ../$(ADSP_VERSION)
obj-y += $(ADSP_VERSION_PATH)/
obj-y += adsp_awake.o
obj-y += adsp_clk.o
obj-y += adsp_bus_monitor.o
obj-y += adsp_reserved_mem.o
obj-y += adsp_platform_driver.o adsp_platform.o
obj-y += adsp_ipi.o
obj-y += adsp_excep.o
ccflags-y += -I$(srctree)/drivers/misc/mediatek/adsp/common_v2
ccflags-y += -I$(srctree)/drivers/misc/mediatek/audio_ipi/common_v2/framework
ccflags-y += -I$(srctree)/drivers/misc/mediatek/include/mt-plat/$(CONFIG_MTK_PLATFORM)/include/mach
ccflags-y += -I$(srctree)/drivers/misc/mediatek/base/power/include/spm
ccflags-y += -I$(srctree)/drivers/misc/mediatek/emi/submodule
ccflags-y += -I$(srctree)/drivers/misc/mediatek/emi/$(CONFIG_MTK_PLATFORM)
ifeq ($(CONFIG_MTK_ENG_BUILD),y)
CFLAGS_adsp_excep.o += -DDEBUG
endif
@@ -0,0 +1,132 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#include <linux/io.h>
#include <linux/mutex.h>
#include <linux/ktime.h>
#include "adsp_core.h"
#include "adsp_platform.h"
#include "adsp_platform_driver.h"
#include "adsp_reg.h"
#ifdef ADSP_BASE
#undef ADSP_BASE
#endif
#define ADSP_BASE (pdata->cfg)
#define AP_AWAKE_LOCK_MASK (0x1 << AP_AWAKE_LOCK_BIT)
#define AP_AWAKE_UNLOCK_MASK (0x1 << AP_AWAKE_UNLOCK_BIT)
struct adsp_sysevent_ctrl {
struct adsp_priv *pdata;
struct mutex lock;
void __iomem *swint;
u32 mask;
};
static struct adsp_sysevent_ctrl sysevent_ctrls[ADSP_CORE_TOTAL];
static int adsp_send_sys_event(struct adsp_sysevent_ctrl *ctrl,
u32 event, bool wait)
{
ktime_t start_time;
s64 time_ipc_us;
if (mutex_trylock(&ctrl->lock) == 0) {
pr_info("%s(), mutex_trylock busy", __func__);
return ADSP_IPI_BUSY;
}
if (readl(ctrl->swint) & ctrl->mask) {
mutex_unlock(&ctrl->lock);
return ADSP_IPI_BUSY;
}
adsp_copy_to_sharedmem(ctrl->pdata, ADSP_SHAREDMEM_WAKELOCK,
&event, sizeof(event));
writel(ctrl->mask, ctrl->swint);
if (wait) {
start_time = ktime_get();
while (readl(ctrl->swint) & ctrl->mask) {
time_ipc_us = ktime_us_delta(ktime_get(), start_time);
if (time_ipc_us > 1000) /* 1 ms */
break;
}
}
mutex_unlock(&ctrl->lock);
return ADSP_IPI_DONE;
}
int adsp_awake_init(struct adsp_priv *pdata, u32 mask)
{
struct adsp_sysevent_ctrl *ctrl;
if (!pdata)
return -EINVAL;
ctrl = &sysevent_ctrls[pdata->id];
ctrl->pdata = pdata;
ctrl->swint = ADSP_SW_INT_SET;
ctrl->mask = mask;
mutex_init(&ctrl->lock);
return 0;
}
/*
* acquire adsp lock flag, keep adsp awake
* @param adsp_id: adsp core id
* return 0 : get lock success
* non-0 : get lock fail
*/
int adsp_awake_lock(u32 cid)
{
int ret = -1;
uint32_t val = 0;
if (cid >= ADSP_CORE_TOTAL)
return -EINVAL;
if (!is_adsp_ready(cid) || !adsp_feature_is_active(cid))
return -ENODEV;
val = AP_AWAKE_LOCK_MASK;
ret = adsp_send_sys_event(&sysevent_ctrls[cid], val, true);
if (ret)
pr_info("%s, lock fail", __func__);
return ret;
}
/*
* release adsp awake lock flag
* @param adsp_id: adsp core id
* return 0 : release lock success
* non-0 : release lock fail
*/
int adsp_awake_unlock(u32 cid)
{
int ret = -1;
uint32_t val = 0;
if (cid >= ADSP_CORE_TOTAL)
return -EINVAL;
if (!is_adsp_ready(cid) || !adsp_feature_is_active(cid))
return -ENODEV;
val = AP_AWAKE_UNLOCK_MASK;
ret = adsp_send_sys_event(&sysevent_ctrls[cid], val, true);
if (ret)
pr_info("%s, unlock fail", __func__);
return ret;
}
@@ -0,0 +1,93 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#include <linux/io.h>
#include "adsp_bus_monitor.h"
#include "adsp_helper.h"
#include "adsp_core.h"
#include "adsp_platform_driver.h"
#ifdef ADSP_BASE
#undef ADSP_BASE
#endif
#define ADSP_BASE mt_base
#define ADSP_BUS_MON_BACKUP_BASE mt_bus_backup_base
/**
* TIMEOUT_VALUE = value * unit(15 cycle count) / clk_src
*/
#define BUS_MON_STAGE1_TIMEOUT_VALUE (0x01DA0A2B) /* 1.00 sec @ 466MHz */
#define BUS_MON_STAGE2_TIMEOUT_VALUE (0x03B41456) /* 2.00 sec @ 466MHz */
#define ADSP_BUS_MON_STATE (ADSP_BUS_MON_BACKUP_BASE)
#define ADSP_BUS_MON_1ST_STAGE_BASE (ADSP_BUS_MON_BACKUP_BASE + sizeof(u32))
#define ADSP_BUS_MON_2ND_STAGE_BASE (ADSP_BUS_MON_1ST_STAGE_BASE + \
sizeof(struct bus_monitor_cblk))
#define ADSP_BUS_MON_BACKUP_SIZE (sizeof(u32) + \
2 * sizeof(struct bus_monitor_cblk))
static void __iomem *mt_base;
static void __iomem *mt_bus_backup_base;
int adsp_bus_monitor_init(struct adsp_priv *pdata)
{
if (unlikely(!pdata))
return -EINVAL;
mt_base = pdata->cfg;
mt_bus_backup_base = adsp_get_sharedmem_base(pdata,
ADSP_SHAREDMEM_BUS_MON_DUMP);
/* Clear bus monitor register backup in DTCM */
memset_io((void *)ADSP_BUS_MON_BACKUP_BASE, 0,
(size_t)ADSP_BUS_MON_BACKUP_SIZE);
/* initialize bus monitor */
writel(0xacce55, ADSP_BUS_DBG_EN_LOCK);
writel(0x00011080, ADSP_BUS_DBG_CON); /* reset bus tracker */
writel(BUS_MON_STAGE1_TIMEOUT_VALUE, ADSP_BUS_DBG_TIMER_CON0);
writel(BUS_MON_STAGE2_TIMEOUT_VALUE, ADSP_BUS_DBG_TIMER_CON1);
writel(0x0, ADSP_BUS_DBG_WP);
writel(0x0, ADSP_BUS_DBG_WP_MASK);
writel(0x00002037, ADSP_BUS_DBG_CON); /* timeout control */
writel(STAGE_RUN, ADSP_BUS_MON_STATE);
return 0;
}
bool is_adsp_bus_monitor_alert(void)
{
return readl(ADSP_BUS_MON_STATE) > STAGE_RUN;
}
static void adsp_bus_monitor_stage_info(void *addr)
{
int i = 0;
struct bus_monitor_cblk cblk;
memcpy_fromio(&cblk, addr, sizeof(struct bus_monitor_cblk));
pr_info("BUS_DBG_CON = 0x%08x", cblk.ctrl);
pr_info("TIMER_CON0 = 0x%08x, TIMER_CON01 = 0x%08x",
cblk.timer_ctrl[0], cblk.timer_ctrl[1]);
for (i = 0; i < 8; i++) {
if (!cblk.r_tracks[i] && !cblk.w_tracks[i])
continue;
pr_info("R_TRACK[%d] = 0x%08x, W_TRACK[%d] = 0x%08x",
i, cblk.r_tracks[i],
i, cblk.w_tracks[i]);
}
}
void adsp_bus_monitor_dump(void)
{
pr_info("%s(), BUS_MON_1ST_STAGE BACKUP", __func__);
adsp_bus_monitor_stage_info((void *)ADSP_BUS_MON_1ST_STAGE_BASE);
pr_info("%s(), BUS_MON_2ST_STAGE BACKUP", __func__);
adsp_bus_monitor_stage_info((void *)ADSP_BUS_MON_2ND_STAGE_BASE);
}
@@ -0,0 +1,47 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __ADSP_BUS_MONITOR_H__
#define __ADSP_BUS_MONITOR_H__
#include "adsp_reg.h"
/* bus monitor registers */
#define ADSP_BUS_DBG_CON (ADSP_BUS_MON_BASE + 0x0000)
#define ADSP_BUS_DBG_TIMER_CON0 (ADSP_BUS_MON_BASE + 0x0004)
#define ADSP_BUS_DBG_TIMER_CON1 (ADSP_BUS_MON_BASE + 0x0008)
#define ADSP_BUS_DBG_TIMER0 (ADSP_BUS_MON_BASE + 0x000C)
#define ADSP_BUS_DBG_TIMER1 (ADSP_BUS_MON_BASE + 0x0010)
#define ADSP_BUS_DBG_WP (ADSP_BUS_MON_BASE + 0x0014)
#define ADSP_BUS_DBG_WP_MASK (ADSP_BUS_MON_BASE + 0x0018)
#define ADSP_BUS_DBG_EN_LOCK (ADSP_BUS_MON_BASE + 0x0024)
/* bus monitor enum */
enum bus_monitor_stage {
STAGE_OFF = 0,
STAGE_RUN = 1,
STAGE_1ST = 2,
STAGE_2ND = 3,
};
/* bus monitor structure */
struct bus_monitor_cblk { /* hw related */
u32 ctrl;
u32 timer_ctrl[2];
u32 timer_dbg[2];
u32 watch_point_addr;
u32 watch_point_mask;
u32 r_tracks[8]; /* read tracker 8 channel in hw */
u32 w_tracks[8]; /* write tracker 8 channel in hw */
};
struct adsp_priv;
/* bus monitor methods, be care all of them need adsp clk on */
int adsp_bus_monitor_init(struct adsp_priv *pdata);
bool is_adsp_bus_monitor_alert(void);
void adsp_bus_monitor_dump(void);
#endif
@@ -0,0 +1,119 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#include <linux/clk.h>
#include "adsp_clk.h"
#include "adsp_platform.h"
static uint32_t adsp_clock_count;
DEFINE_SPINLOCK(adsp_clock_spinlock);
struct adsp_clock_attr {
const char *name;
struct clk *clock;
};
static struct adsp_clock_attr adsp_clks[ADSP_CLK_NUM] = {
[CLK_ADSP_INFRA] = {"clk_adsp_infra", NULL},
[CLK_TOP_ADSP_SEL] = {"clk_top_adsp_sel", NULL},
[CLK_TOP_CLK26M] = {"clk_adsp_clk26m", NULL},
[CLK_TOP_MMPLL_D4] = {"clk_top_mmpll_d4", NULL},
[CLK_TOP_ADSPPLL_D4] = {"clk_top_adsppll_d4", NULL},
[CLK_TOP_ADSPPLL_D6] = {"clk_top_adsppll_d6", NULL},
};
int adsp_set_top_mux(enum adsp_clk clk)
{
int ret = 0;
pr_debug("%s(%x)\n", __func__, clk);
if (clk >= ADSP_CLK_NUM || clk < 0)
return -EINVAL;
ret = clk_set_parent(adsp_clks[CLK_TOP_ADSP_SEL].clock,
adsp_clks[clk].clock);
if (IS_ERR(&ret))
pr_err("%s() clk_set_parent(clk_top_adsp_sel-%x) fail %d\n",
__func__, clk, ret);
return ret;
}
void adsp_set_clock_freq(enum adsp_clk clk)
{
switch (clk) {
case CLK_TOP_CLK26M:
case CLK_TOP_MMPLL_D4:
case CLK_TOP_ADSPPLL_D4:
case CLK_TOP_ADSPPLL_D6:
adsp_set_top_mux(clk);
break;
default:
break;
}
}
/* clock init */
int adsp_clk_device_probe(struct platform_device *pdev)
{
int ret = 0;
size_t i;
struct device *dev = &pdev->dev;
for (i = 0; i < ARRAY_SIZE(adsp_clks); i++) {
adsp_clks[i].clock = devm_clk_get(dev, adsp_clks[i].name);
if (IS_ERR(adsp_clks[i].clock)) {
ret = PTR_ERR(adsp_clks[i].clock);
pr_err("%s devm_clk_get %s fail %d\n", __func__,
adsp_clks[i].name, ret);
}
}
return ret;
}
/* clock deinit */
void adsp_clk_device_remove(void *dev)
{
pr_info("%s\n", __func__);
}
int adsp_enable_clock(void)
{
int ret = 0;
unsigned long spin_flags;
pr_info("%s()\n", __func__);
spin_lock_irqsave(&adsp_clock_spinlock, spin_flags);
if (++adsp_clock_count == 1)
/* unable to access adsp sram before set way_en to 1 */
adsp_way_en_ctrl(1);
spin_unlock_irqrestore(&adsp_clock_spinlock, spin_flags);
ret = clk_prepare_enable(adsp_clks[CLK_ADSP_INFRA].clock);
if (IS_ERR(&ret)) {
pr_err("%s(), clk_prepare_enable %s fail, ret %d\n",
__func__, adsp_clks[CLK_ADSP_INFRA].name, ret);
adsp_clock_count--;
return -EINVAL;
}
return 0;
}
void adsp_disable_clock(void)
{
unsigned long spin_flags;
pr_info("%s()\n", __func__);
clk_disable_unprepare(adsp_clks[CLK_ADSP_INFRA].clock);
spin_lock_irqsave(&adsp_clock_spinlock, spin_flags);
if (--adsp_clock_count == 0)
/* unable to access adsp sram before set way_en to 1 */
adsp_way_en_ctrl(0);
spin_unlock_irqrestore(&adsp_clock_spinlock, spin_flags);
}
@@ -0,0 +1,31 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef ADSP_CLK_H
#define ADSP_CLK_H
#include <linux/platform_device.h>
#define CLK_DEFAULT_INIT_CK CLK_TOP_ADSPPLL_D6
#define CLK_DEFAULT_26M_CK CLK_TOP_CLK26M
enum adsp_clk {
CLK_ADSP_INFRA,
CLK_TOP_ADSP_SEL,
CLK_TOP_CLK26M,
CLK_TOP_MMPLL_D4,
CLK_TOP_ADSPPLL_D4,
CLK_TOP_ADSPPLL_D6,
ADSP_CLK_NUM
};
void adsp_set_clock_freq(enum adsp_clk clk);
int adsp_set_top_mux(enum adsp_clk clk);
int adsp_enable_clock(void);
void adsp_disable_clock(void);
int adsp_clk_device_probe(struct platform_device *pdev);
void adsp_clk_device_remove(void *dev);
#endif /* ADSP_CLK_H */
@@ -0,0 +1,122 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __ADSP_DVFS_H__
#define __ADSP_DVFS_H__
#include <adsp_ipi.h>
#include <adsp_clk.h>
#define ADSP_ITCM_MONITOR (1)
#define ADSP_DTCM_MONITOR (1)
#define ADSP_CFG_MONITOR (0)
#define ADSP_DVFS_PROFILE (1)
#define ADSP_FREQ_METER_ID (43) //hf_fadsp_ck
#define ADSP_DVFS_USE_PLL 1
#define PLL_ENABLE (1)
#define PLL_DISABLE (0)
#define DVFS_STATUS_OK (0)
#define DVFS_STATUS_BUSY (-1)
#define DVFS_REQUEST_SAME_CLOCK (-2)
#define DVFS_STATUS_ERR (-3)
#define DVFS_STATUS_TIMEOUT (-4)
#define DVFS_CLK_ERROR (-5)
#define DVFS_STATUS_CMD_FIX (-6)
#define DVFS_STATUS_CMD_LIMITED (-7)
#define DVFS_STATUS_CMD_DISABLE (-8)
enum adsp_cur_status_enum {
ADSP_STATUS_RESET = 0x00,
ADSP_STATUS_SUSPEND = 0x01,
ADSP_STATUS_SLEEP = 0x10,
ADSP_STATUS_ACTIVE = 0x11,
};
enum adsp_state_enum {
IN_DEBUG_IDLE = 1,
ENTERING_SLEEP = 2,
IN_SLEEP = 4,
ENTERING_ACTIVE = 8,
IN_ACTIVE = 16,
};
enum {
CLK_SYS_EN_BIT = 0,
CLK_HIGH_EN_BIT = 1,
CLK_HIGH_CG_BIT = 2,
CLK_SYS_IRQ_EN_BIT = 16,
CLK_HIGH_IRQ_EN_BIT = 17,
};
/*#ifdef CONFIG_PINCTRL_MT6797*/
enum clk_opp_enum {
CLK_OPP0 = 125,
CLK_OPP1 = 330,
CLK_OPP2 = 416,
CLK_INVALID_OPP,
};
enum clk_div_enum {
CLK_DIV_1 = 0,
CLK_DIV_2 = 1,
CLK_DIV_4 = 2,
CLK_DIV_8 = 3,
CLK_DIV_UNKNOWN,
};
enum voltage_enum {
SPM_VOLTAGE_800_D = 0,
SPM_VOLTAGE_800,
SPM_VOLTAGE_900,
SPM_VOLTAGE_1000,
SPM_VOLTAGE_TYPE_NUM,
};
struct mt_adsp_pll_t {
/* main clock for mfg setting */
struct clk *clk_mux;
/* substitution clock for adsp transient parent setting */
struct clk *clk_pll0;
struct clk *clk_pll1;
struct clk *clk_pll2;
struct clk *clk_pll3;
struct clk *clk_pll4;
struct clk *clk_pll5;
struct clk *clk_pll6;
struct clk *clk_pll7;
};
extern int adsp_pll_ctrl_set(unsigned int pll_ctrl_flag, unsigned int pll_sel);
extern int adsp_set_pmic_vcore(unsigned int cur_freq);
extern unsigned int adsp_get_dvfs_opp(void);
extern uint32_t adsp_get_freq(void);
extern int adsp_request_freq(void);
extern void adsp_pll_mux_set(unsigned int pll_ctrl_flag);
extern void wait_adsp_dvfs_init_done(void);
extern int __init adsp_dvfs_init(void);
extern void __exit adsp_dvfs_exit(void);
/* adsp dvfs variable*/
extern struct mutex adsp_feature_mutex;
extern struct mutex adsp_suspend_mutex;
extern struct completion adsp_suspend_cp;
extern struct completion adsp_resume_cp;
extern int adsp_is_suspend;
/* adsp new implement */
void adsp_A_send_spm_request(uint32_t enable);
extern void adsp_reset(void);
void adsp_sw_reset(enum adsp_core_id core_id);
extern void adsp_release_runstall(enum adsp_core_id, uint32_t release);
extern int adsp_suspend_init(void);
void adsp_start_suspend_timer(void);
void adsp_stop_suspend_timer(void);
int adsp_resume(void);
void adsp_suspend(enum adsp_core_id core_id);
/***************************/
#endif /* __ADSP_DVFS_H__ */
@@ -0,0 +1,565 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#include <linux/vmalloc.h> /* needed by vmalloc */
#include <linux/slab.h> /* needed by kmalloc */
#include <linux/sysfs.h>
#include <linux/device.h> /* needed by device_* */
#include <linux/workqueue.h>
#include <linux/mutex.h>
#include <linux/delay.h>
#include <linux/io.h>
#if IS_ENABLED(CONFIG_PM_WAKELOCKS)
#include <linux/pm_wakeup.h>
#endif
#include <mt-plat/aee.h>
#include "adsp_reg.h"
#include "adsp_core.h"
#include "adsp_clk.h"
#include "adsp_platform_driver.h"
#include "adsp_excep.h"
#include "adsp_logger.h"
#define ADSP_MISC_EXTRA_SIZE 0x400 //1KB
#define ADSP_MISC_BUF_SIZE 0x10000 //64KB
#define ADSP_TEST_EE_PATTERN "Assert-Test"
static char adsp_ke_buffer[ADSP_KE_DUMP_LEN];
static struct adsp_exception_control excep_ctrl;
static bool suppress_test_ee;
static u32 copy_from_buffer(void *dest, size_t destsize, const void *src,
size_t srcsize, u32 offset, size_t request)
{
/* if request == -1, offset == 0, copy full srcsize */
if (offset + request > srcsize)
request = srcsize - offset;
/* if destsize == -1, don't check the request size */
if (!dest || destsize < request) {
pr_warn("%s, buffer null or not enough space", __func__);
return 0;
}
memcpy(dest, src + offset, request);
return request;
}
static inline u32 dump_adsp_shared_memory(void *buf, size_t size, int id)
{
void *mem_addr = adsp_get_reserve_mem_virt(id);
size_t mem_size = adsp_get_reserve_mem_size(id);
if (!mem_addr)
return 0;
return copy_from_buffer(buf, size, mem_addr, mem_size, 0, -1);
}
static inline u32 copy_from_adsp_shared_memory(void *buf, u32 offset,
size_t size, int id)
{
void *mem_addr = adsp_get_reserve_mem_virt(id);
size_t mem_size = adsp_get_reserve_mem_size(id);
if (!mem_addr)
return 0;
return copy_from_buffer(buf, -1, mem_addr, mem_size, offset, size);
}
static u32 dump_adsp_internal_mem(struct adsp_priv *pdata,
void *buf, size_t size)
{
u32 clk_cfg = 0, uart_cfg = 0, n = 0;
u32 clk_mask = ADSP_CLK_UART_EN | ADSP_CLK_CORE_0_EN;
u32 uart_mask = ADSP_UART_RST_N | ADSP_UART_BCLK_CG;
adsp_enable_clock();
mutex_lock(&excep_ctrl.lock);
clk_cfg = switch_adsp_clk_ctrl_cg(true, clk_mask);
uart_cfg = switch_adsp_uart_ctrl_cg(true, uart_mask);
n += copy_from_buffer(buf + n, size - n,
pdata->cfg, pdata->cfg_size, 0, -1);
n += copy_from_buffer(buf + n, size - n,
pdata->itcm, pdata->itcm_size, 0, -1);
n += copy_from_buffer(buf + n, size - n,
pdata->dtcm, pdata->dtcm_size, 0, -1);
switch_adsp_clk_ctrl_cg(false, (~clk_cfg) & clk_mask);
switch_adsp_uart_ctrl_cg(false, (~uart_cfg) & uart_mask);
mutex_unlock(&excep_ctrl.lock);
adsp_disable_clock();
return n;
}
static int dump_buffer(struct adsp_exception_control *ctrl, int coredump_id)
{
u32 total = 0, n = 0;
void *buf = NULL;
int ret = 0;
struct adsp_priv *pdata = NULL;
if (!ctrl || !ctrl->priv_data)
return -1;
pdata = (struct adsp_priv *)ctrl->priv_data;
if (ctrl->buf_backup) {
/* wait last dump done, and release buf_backup */
ret = wait_for_completion_timeout(&ctrl->done, 10 * HZ);
/* if not release buf, return EBUSY */
if (ctrl->buf_backup)
return -EBUSY;
}
total = pdata->cfg_size
+ pdata->itcm_size
+ pdata->dtcm_size
+ pdata->sysram_size
+ adsp_get_reserve_mem_size(coredump_id)
+ adsp_get_reserve_mem_size(ADSP_A_LOGGER_MEM_ID);
buf = vzalloc(total);
if (!buf)
return -ENOMEM;
n += dump_adsp_internal_mem(pdata, buf + n, total - n);
n += copy_from_buffer(buf + n, total - n,
pdata->sysram, pdata->sysram_size, 0, -1);
n += dump_adsp_shared_memory(buf + n, total - n, coredump_id);
n += dump_adsp_shared_memory(buf + n, total - n, ADSP_A_LOGGER_MEM_ID);
mutex_lock(&ctrl->buffer_lock);
reinit_completion(&ctrl->done);
ctrl->buf_backup = buf;
ctrl->buf_size = total;
mutex_unlock(&ctrl->buffer_lock);
pr_debug("%s, vmalloc size %u, buffer %p, dump_size %u",
__func__, total, buf, n);
return n;
}
static void adsp_exception_dump(struct adsp_exception_control *ctrl)
{
char detail[ADSP_AED_STR_LEN];
int db_opt = DB_OPT_DEFAULT;
char *aed_type;
bool dump_flag = true;
int ret = 0, n = 0, coredump_id = 0, coredump_size = 0;
struct adsp_priv *pdata = (struct adsp_priv *)ctrl->priv_data;
struct adsp_coredump *coredump;
/* get adsp title and exception type*/
switch (ctrl->excep_id) {
case EXCEP_BOOTUP:
aed_type = "boot exception";
break;
case EXCEP_RUNTIME:
aed_type = "runtime exception";
db_opt |= DB_OPT_FTRACE;
break;
case EXCEP_KERNEL:
aed_type = "kernel exception";
db_opt |= DB_OPT_FTRACE;
break;
default:
dump_flag = false;
aed_type = "unknown exception";
break;
}
if (pdata->id == ADSP_A_ID)
coredump_id = ADSP_A_CORE_DUMP_MEM_ID;
coredump = adsp_get_reserve_mem_virt(coredump_id);
coredump_size = adsp_get_reserve_mem_size(coredump_id);
if (suppress_test_ee && coredump
&& strstr(coredump->assert_log, ADSP_TEST_EE_PATTERN)) {
pr_info("%s, suppress Test EE dump", __func__);
return;
}
if (dump_flag) {
ret = dump_buffer(ctrl, coredump_id);
if (ret < 0)
pr_info("%s, excep dump fail ret(%d)", __func__, ret);
}
n += snprintf(detail + n, ADSP_AED_STR_LEN - n, "%s %s\n",
pdata->name, aed_type);
if (coredump) {
n += snprintf(detail + n, ADSP_AED_STR_LEN - n,
"adsp pc=0x%08x,exccause=0x%x,excvaddr=0x%x\n",
coredump->pc,
coredump->exccause,
coredump->excvaddr);
n += snprintf(detail + n, ADSP_AED_STR_LEN - n,
"CRDISPATCH_KEY:ADSP exception/%s\n",
coredump->task_name);
n += snprintf(detail + n, ADSP_AED_STR_LEN - n, "%s",
coredump->assert_log);
}
pr_info("%s", detail);
/* adsp aed api, only detail information available*/
aed_common_exception_api("adsp", (const int *)coredump, coredump_size,
NULL, 0, detail, db_opt);
}
void adsp_aed_worker(struct work_struct *ws)
{
struct adsp_exception_control *ctrl = container_of(ws,
struct adsp_exception_control,
aed_work);
struct adsp_priv *pdata = NULL;
int cid = 0, ret = 0, retry = 0;
/* wake lock AP*/
#if IS_ENABLED(CONFIG_PM_WAKELOCKS)
__pm_stay_awake(ctrl->wakeup_lock);
#endif
/* stop adsp, set reset state */
for (cid = 0; cid < ADSP_CORE_TOTAL; cid++) {
pdata = get_adsp_core_by_id(cid);
set_adsp_state(pdata, ADSP_RESET);
complete_all(&pdata->done);
}
/* force wake up if suspend thread wait reset event */
if (ctrl->waitq)
wake_up(ctrl->waitq);
adsp_register_feature(SYSTEM_FEATURE_ID);
adsp_extern_notify_chain(ADSP_EVENT_STOP);
/* exception dump */
adsp_exception_dump(ctrl);
/* reset adsp */
adsp_enable_clock();
for (retry = 0; retry < ADSP_RESET_RETRY_MAXTIME; retry++) {
ret = adsp_reset();
if (ret == 0)
break;
/* reset fail & retry */
pr_info("%s, reset retry.... (%d)", __func__, retry);
msleep(20);
}
adsp_disable_clock();
if (ret) {
pr_info("%s, adsp dead, wait dump dead body", __func__);
aee_kernel_exception_api(__FILE__,
__LINE__,
DB_OPT_DEFAULT,
"[ADSP]",
"ASSERT: ADSP DEAD! Recovery Fail");
/* BUG_ON(1); */
}
adsp_extern_notify_chain(ADSP_EVENT_READY);
adsp_deregister_feature(SYSTEM_FEATURE_ID);
#if IS_ENABLED(CONFIG_PM_WAKELOCKS)
__pm_relax(ctrl->wakeup_lock);
#endif
}
bool adsp_aed_dispatch(enum adsp_excep_id type, void *data)
{
struct adsp_exception_control *ctrl = &excep_ctrl;
if (work_busy(&ctrl->aed_work))
return false;
ctrl->excep_id = type;
ctrl->priv_data = data;
return queue_work(ctrl->workq, &ctrl->aed_work);
}
static void adsp_wdt_counter_reset(struct timer_list *t)
{
excep_ctrl.wdt_counter = 0;
pr_info("[ADSP] %s\n", __func__);
}
/*
* init a work struct
*/
int init_adsp_exception_control(struct device *dev,
struct workqueue_struct *workq,
struct wait_queue_head *waitq)
{
struct adsp_exception_control *ctrl = &excep_ctrl;
ctrl->waitq = waitq;
ctrl->workq = workq;
ctrl->buf_backup = NULL;
ctrl->buf_size = 0;
mutex_init(&ctrl->lock);
mutex_init(&ctrl->buffer_lock);
init_completion(&ctrl->done);
INIT_WORK(&ctrl->aed_work, adsp_aed_worker);
#if IS_ENABLED(CONFIG_PM_WAKELOCKS)
ctrl->wakeup_lock = wakeup_source_register(dev, "adsp wakelock");
#endif
timer_setup(&ctrl->wdt_timer, adsp_wdt_counter_reset, 0);
return 0;
}
void adsp_wdt_handler(int irq, void *data, int cid)
{
struct adsp_priv *pdata = (struct adsp_priv *)data;
if (!adsp_aed_dispatch(EXCEP_RUNTIME, data))
pr_info("%s, already resetting, ignore core%d wdt",
__func__, pdata->id);
}
void get_adsp_misc_buffer(unsigned long *vaddr, unsigned long *size)
{
struct adsp_priv *pdata = NULL;
struct log_info_s *log_info = NULL;
struct buffer_info_s *buf_info = NULL;
void *buf = adsp_ke_buffer;
void *addr = NULL;
unsigned int w_pos, r_pos, buf_size;
unsigned int data_len[2];
unsigned int id = 0, n = 0;
unsigned int part_len = ADSP_MISC_BUF_SIZE / ADSP_CORE_TOTAL;
memset(buf, 0, ADSP_KE_DUMP_LEN);
for (id = 0; id < ADSP_CORE_TOTAL; id++) {
w_pos = 0;
pdata = get_adsp_core_by_id(id);
if (!pdata || !pdata->log_ctrl ||
!pdata->log_ctrl->inited || !pdata->log_ctrl->priv)
goto ERROR;
log_info = (struct log_info_s *)pdata->log_ctrl->priv;
buf_info = (struct buffer_info_s *)(pdata->log_ctrl->priv
+ log_info->info_ofs);
buf_size = log_info->buff_size;
memcpy_fromio(&w_pos, &buf_info->w_pos, sizeof(w_pos));
if (w_pos >= buf_size)
w_pos -= buf_size;
if (w_pos < part_len) {
r_pos = buf_size + w_pos - part_len;
data_len[0] = part_len - w_pos;
data_len[1] = w_pos;
} else {
r_pos = w_pos - part_len;
data_len[0] = part_len;
data_len[1] = 0;
}
addr = pdata->log_ctrl->priv + log_info->buff_ofs;
memcpy(buf + n, addr + r_pos, data_len[0]);
n += data_len[0];
memcpy(buf + n, addr, data_len[1]);
n += data_len[1];
}
/* return value */
*vaddr = (unsigned long)buf;
*size = n;
return;
ERROR:
/* return value */
*vaddr = (unsigned long)buf;
*size = 0;
}
EXPORT_SYMBOL(get_adsp_misc_buffer);
void get_adsp_aee_buffer(unsigned long *vaddr, unsigned long *size)
{
u32 clk_cfg = 0, uart_cfg = 0, n = 0;
u32 clk_mask = ADSP_CLK_UART_EN | ADSP_CLK_CORE_0_EN;
u32 uart_mask = ADSP_UART_RST_N | ADSP_UART_BCLK_CG;
struct adsp_priv *pdata = NULL;
void *buf = adsp_ke_buffer;
u32 len = ADSP_KE_DUMP_LEN;
memset(buf, 0, len);
adsp_enable_clock();
mutex_lock(&excep_ctrl.lock);
read_lock(&access_rwlock);
adsp_mt_clr_sw_reset();
clk_cfg = switch_adsp_clk_ctrl_cg(true, clk_mask);
uart_cfg = switch_adsp_uart_ctrl_cg(true, uart_mask);
pdata = get_adsp_core_by_id(ADSP_A_ID);
n += copy_from_buffer(buf + n, len - n,
pdata->cfg, pdata->cfg_size, 0, -1);
n += copy_from_buffer(buf + n, len - n,
pdata->dtcm, pdata->dtcm_size, 0, -1);
switch_adsp_clk_ctrl_cg(false, (~clk_cfg) & clk_mask);
switch_adsp_uart_ctrl_cg(false, (~uart_cfg) & uart_mask);
read_unlock(&access_rwlock);
mutex_unlock(&excep_ctrl.lock);
adsp_disable_clock();
/* last adsp_log */
//n += dump_adsp_partial_log(buf + n, len - n);
/* return value */
*vaddr = (unsigned long)buf;
*size = len;
}
EXPORT_SYMBOL(get_adsp_aee_buffer);
/*
* sysfs bin_attribute node
*/
static ssize_t adsp_dump_show(struct file *filep, struct kobject *kobj,
struct bin_attribute *attr,
char *buf, loff_t offset, size_t size)
{
ssize_t n = 0;
struct adsp_exception_control *ctrl = &excep_ctrl;
mutex_lock(&ctrl->buffer_lock);
if (ctrl->buf_backup) {
n = copy_from_buffer(buf, -1, ctrl->buf_backup,
ctrl->buf_size, offset, size);
if (n == 0) {
vfree(ctrl->buf_backup);
ctrl->buf_backup = NULL;
ctrl->buf_size = 0;
/* if dump_buffer wait for dump, wake up it */
complete(&ctrl->done);
}
}
mutex_unlock(&ctrl->buffer_lock);
return n;
}
static ssize_t adsp_dump_ke_show(struct file *filep, struct kobject *kobj,
struct bin_attribute *attr,
char *buf, loff_t offset, size_t size)
{
unsigned long tmp[2];
ssize_t n = 0;
ssize_t threshold[2];
if (offset == 0) /* only do ke ramdump once at start */
get_adsp_aee_buffer(&tmp[0], &tmp[1]);
threshold[0] = ADSP_KE_DUMP_LEN;
threshold[1] = threshold[0] +
adsp_get_reserve_mem_size(ADSP_A_LOGGER_MEM_ID);
if (offset >= 0 && offset < threshold[0]) {
n = copy_from_buffer(buf, -1, adsp_ke_buffer,
threshold[0], offset, size);
} else if (offset >= threshold[0] && offset < threshold[1]) {
n = copy_from_adsp_shared_memory(
buf, offset - threshold[0],
size, ADSP_A_LOGGER_MEM_ID);
}
return n;
}
static ssize_t adsp_dump_log_show(struct file *filep, struct kobject *kobj,
struct bin_attribute *attr,
char *buf, loff_t offset, size_t size)
{
ssize_t n = 0;
ssize_t threshold;
threshold = adsp_get_reserve_mem_size(ADSP_A_LOGGER_MEM_ID);
if (offset >= 0 && offset < threshold) {
n = copy_from_adsp_shared_memory(buf, offset,
size, ADSP_A_LOGGER_MEM_ID);
}
return n;
}
static struct bin_attribute bin_attr_adsp_dump = {
.attr = {
.name = "adsp_dump",
.mode = 0444,
},
.size = 0,
.read = adsp_dump_show,
};
static struct bin_attribute bin_attr_adsp_dump_ke = {
.attr = {
.name = "adsp_dump_ke",
.mode = 0444,
},
.size = 0,
.read = adsp_dump_ke_show,
};
struct bin_attribute bin_attr_adsp_dump_log = {
.attr = {
.name = "adsp_last_log",
.mode = 0444,
},
.size = 0,
.read = adsp_dump_log_show,
};
static inline ssize_t suppress_ee_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
unsigned int input = 0;
if (kstrtouint(buf, 0, &input) != 0)
return -EINVAL;
suppress_test_ee = !!input;
return count;
}
DEVICE_ATTR_WO(suppress_ee);
static struct bin_attribute *adsp_excep_bin_attrs[] = {
&bin_attr_adsp_dump,
&bin_attr_adsp_dump_ke,
&bin_attr_adsp_dump_log,
NULL,
};
static struct attribute *adsp_excep_attrs[] = {
&dev_attr_suppress_ee.attr,
NULL,
};
struct attribute_group adsp_excep_attr_group = {
.attrs = adsp_excep_attrs,
.bin_attrs = adsp_excep_bin_attrs,
};
@@ -0,0 +1,61 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __ADSP_EXCEP_H__
#define __ADSP_EXCEP_H__
#include <linux/interrupt.h>
#define ADSP_AED_STR_LEN (512)
#define ADSP_WDT_TIMEOUT (60 * HZ) /* 60 seconds*/
#define ADSP_KE_DUMP_LEN (256 * 1024)
#define ADSP_RESET_RETRY_MAXTIME (7)
enum adsp_excep_id {
EXCEP_LOAD_FIRMWARE = 0,
EXCEP_RESET,
EXCEP_BOOTUP,
EXCEP_RUNTIME,
EXCEP_KERNEL,
ADSP_NR_EXCEP,
};
/* adsp reg dump */
struct adsp_coredump {
u32 reserved_0[67];
u32 pc;
u32 exccause;
u32 excvaddr;
u32 reserved_1[7];
u8 task_name[16];
u32 reserved_2[47];
u8 assert_log[512];
};
struct adsp_exception_control {
int excep_id;
void *priv_data;
void *buf_backup;
size_t buf_size;
struct mutex lock;
struct mutex buffer_lock;
struct workqueue_struct *workq;
struct wait_queue_head *waitq;
struct work_struct aed_work;
struct wakeup_source *wakeup_lock;
struct completion done;
struct timer_list wdt_timer;
unsigned int wdt_counter;
};
void adsp_wdt_handler(int irq, void *data, int cid);
bool adsp_aed_dispatch(enum adsp_excep_id type, void *data);
int init_adsp_exception_control(struct device *dev,
struct workqueue_struct *wq,
struct wait_queue_head *waitq);
#endif
@@ -0,0 +1,95 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __ADSP_FEATURE_DEFINE_H__
#define __ADSP_FEATURE_DEFINE_H__
/* reset recovery feature kernel option*/
#define CFG_RECOVERY_SUPPORT
/* adsp platform configs*/
#define ADSP_EMI_PROTECTION_ENABLE (1)
#define ADSP_BUS_MONITOR_INIT_ENABLE (1)
/* adsp feature PRI list */
/* The higher number, higher priority */
enum adsp_feature_pri {
AUDIO_HAL_FEATURE_PRI = 0,
ADSP_LOGGER_FEATURE_PRI,
SPK_PROTECT_FEATURE_PRI,
A2DP_PLAYBACK_FEATURE_PRI,
AURISYS_FEATURE_PRI,
DEEPBUF_FEATURE_PRI,
OFFLOAD_FEATURE_PRI,
PRIMARY_FEATURE_PRI,
VOIP_FEATURE_PRI,
CAPTURE_UL1_FEATURE_PRI,
AUDIO_DATAPROVIDER_FEATURE_PRI,
AUDIO_PLAYBACK_FEATURE_PRI,
VOICE_CALL_FEATURE_PRI,
AUDIO_CONTROLLER_FEATURE_PRI,
SYSTEM_FEATURE_PRI,
};
/* adsp feature ID list */
enum adsp_feature_id {
SYSTEM_FEATURE_ID = 0,
ADSP_LOGGER_FEATURE_ID = 1,
AURISYS_FEATURE_ID = 2,
AUDIO_CONTROLLER_FEATURE_ID = 3,
PRIMARY_FEATURE_ID = 4,
FAST_FEATURE_ID = 5,
DEEPBUF_FEATURE_ID = 6,
OFFLOAD_FEATURE_ID = 7,
AUDIO_PLAYBACK_FEATURE_ID = 8,
AUDIO_MUSIC_FEATURE_ID = 9,
RESERVED0_FEATURE_ID = 10,
RESERVED1_FEATURE_ID = 11,
CAPTURE_UL1_FEATURE_ID = 12,
AUDIO_DATAPROVIDER_FEATURE_ID = 13,
VOICE_CALL_FEATURE_ID = 14,
VOIP_FEATURE_ID = 15,
SPK_PROTECT_FEATURE_ID = 16,
CALL_FINAL_FEATURE_ID = 17,
A2DP_PLAYBACK_FEATURE_ID = 18,
KTV_FEATURE_ID = 19,
CAPTURE_RAW_FEATURE_ID = 20,
FM_ADSP_FEATURE_ID = 21,
VOICE_CALL_SUB_FEATURE_ID = 22,
BLE_CALL_DL_FEATURE_ID = 27,
BLE_CALL_UL_FEATURE_ID = 28,
ADSP_NUM_FEATURE_ID,
};
enum {
DEREGI_FLAG_NODELAY = 1 << 0,
};
struct adsp_feature_control {
int total;
unsigned int feature_set; /* from dts */
struct mutex lock;
struct workqueue_struct *wq;
struct delayed_work suspend_work;
int delay_ms;
int (*suspend)(void);
int (*resume)(void);
};
ssize_t adsp_dump_feature_state(u32 cid, char *buffer, int size);
int adsp_get_feature_index(const char *str);
bool is_feature_in_set(u32 cid, u32 fid);
bool adsp_feature_is_active(u32 cid);
bool is_adsp_feature_in_active(void);
bool flush_suspend_work(u32 cid);
int _adsp_register_feature(u32 cid, u32 fid, u32 opt);
int _adsp_deregister_feature(u32 cid, u32 fid, u32 opt);
int init_adsp_feature_control(u32 cid, u32 feature_set, int delay_ms,
struct workqueue_struct *wq,
int (*_suspend)(void),
int (*_resume)(void));
#endif
@@ -0,0 +1,103 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __ADSP_HELPER_H__
#define __ADSP_HELPER_H__
#include <linux/notifier.h>
#include "adsp_reserved_mem.h"
#include "adsp_feature_define.h"
enum adsp_ipi_id {
ADSP_IPI_WDT = 0,
ADSP_IPI_TEST1,
ADSP_IPI_LOGGER_ENABLE,
ADSP_IPI_LOGGER_WAKEUP,
ADSP_IPI_LOGGER_INIT,
ADSP_IPI_TRAX_ENABLE,
ADSP_IPI_TRAX_DONE,
ADSP_IPI_TRAX_INIT_A,
ADSP_IPI_VOW,
ADSP_IPI_AUDIO,
ADSP_IPI_DVT_TEST,
ADSP_IPI_TIME_SYNC,
ADSP_IPI_CONSYS,
ADSP_IPI_ADSP_A_READY,
ADSP_IPI_APCCCI,
ADSP_IPI_ADSP_A_RAM_DUMP,
ADSP_IPI_DVFS_DEBUG,
ADSP_IPI_DVFS_FIX_OPP_SET,
ADSP_IPI_DVFS_FIX_OPP_EN,
ADSP_IPI_DVFS_LIMIT_OPP_SET,
ADSP_IPI_DVFS_LIMIT_OPP_EN,
ADSP_IPI_DVFS_SUSPEND,
ADSP_IPI_DVFS_SLEEP,
ADSP_IPI_DVFS_WAKE,
ADSP_IPI_DVFS_SET_FREQ,
ADSP_IPI_ADSP_PLL_CTRL = 27,
ADSP_IPI_MET_ADSP = 30,
ADSP_IPI_ADSP_TIMER = 31,
ADSP_NR_IPI,
};
enum adsp_ipi_status {
ADSP_IPI_ERROR = -1,
ADSP_IPI_DONE,
ADSP_IPI_BUSY,
};
enum adsp_status {
ADSP_ERROR = -1,
ADSP_OK,
ADSP_SEMAPHORE_BUSY,
};
/* adsp notify event */
enum ADSP_NOTIFY_EVENT {
ADSP_EVENT_STOP = 0,
ADSP_EVENT_READY,
};
enum semaphore_2way_flag {
SEMA_2WAY_AUDIOREG = 0,
SEMA_2WAY_NUM = 4,
};
#define SEMA_AUDIO SEMA_2WAY_NUM
#define SEMA_AUDIOREG SEMA_2WAY_AUDIOREG
#define ADSP_OSTIMER_BUFFER (adsp_timesync_ptr)
extern void *adsp_timesync_ptr;
extern enum adsp_ipi_status adsp_ipi_registration(enum adsp_ipi_id id,
void (*ipi_handler)(int id,
void *data, unsigned int len),
const char *name);
extern enum adsp_ipi_status adsp_ipi_unregistration(enum adsp_ipi_id id);
extern enum adsp_ipi_status adsp_push_message(enum adsp_ipi_id id, void *buf,
unsigned int len, unsigned int wait_ms,
unsigned int core_id);
extern enum adsp_ipi_status adsp_send_message(enum adsp_ipi_id id, void *buf,
unsigned int len, unsigned int wait,
unsigned int core_id);
extern int is_adsp_ready(u32 cid);
extern bool is_adsp_feature_in_active(void);
extern int adsp_feature_in_which_core(enum adsp_feature_id fid);
extern int adsp_register_feature(enum adsp_feature_id fid);
extern int adsp_deregister_feature(enum adsp_feature_id fid);
extern void adsp_register_notify(struct notifier_block *nb);
extern void adsp_unregister_notify(struct notifier_block *nb);
extern void reset_hal_feature_table(void);
/* If device interrupt is not connected, return -ENOTCONN. */
extern int adsp_irq_registration(u32 core_id, u32 irq_id, void *handler,
void *data);
/* semaphore */
extern int get_adsp_semaphore(unsigned int flags);
extern int release_adsp_semaphore(unsigned int flags);
#endif
@@ -0,0 +1,282 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#include <linux/mutex.h>
#include <linux/io.h>
#include <linux/ktime.h>
#include "adsp_ipi.h"
#include "adsp_platform.h"
#include "adsp_core.h"
#include "adsp_platform_driver.h"
#include "adsp_excep.h"
#include <adsp_ipi_queue.h>
#include <audio_ipi_platform.h>
#include <audio_messenger_ipi.h>
#include "adsp_reg.h"
/*
* =============================================================================
* log
* =============================================================================
*/
#ifdef pr_fmt
#undef pr_fmt
#endif
#define pr_fmt(fmt) "[IPI][IPC] %s(), " fmt "\n", __func__
char *adsp_core_ids[ADSP_CORE_TOTAL] = {"ADSP A"};
#define PRINT_THRESHOLD 10000
struct adsp_ipi_desc adsp_ipi_desc[ADSP_NR_IPI];
struct ipi_ctrl_s adsp_ipi_ctrl;
/*
* find an ipi handler and invoke it
*/
void adsp_ipi_handler(int irq, void *data, int cid)
{
struct adsp_priv *pdata = (struct adsp_priv *)data;
struct ipi_ctrl_s *ctrl;
struct adsp_share_obj *recv_obj;
enum adsp_ipi_id ipi_id;
struct ipi_msg_t *ipi_msg = NULL;
u8 share_buf[SHARE_BUF_SIZE - 16];
u32 len;
ktime_t start_time;
s64 stop_time;
start_time = ktime_get();
if (!pdata) {
pr_err("%s pdata[%p]\n", __func__, pdata);
return;
}
if (pdata->id >= ADSP_CORE_TOTAL) {
pr_err("%s core_id[%d] is invalid\n", __func__, pdata->id);
return;
}
ctrl = pdata->ipi_ctrl;
recv_obj = ctrl->recv_obj;
ipi_id = recv_obj->id;
len = recv_obj->len;
memcpy_fromio(share_buf,
(void *)recv_obj->share_buf, len);
adsp_mt_clr_sysirq(cid);
if (ipi_id >= ADSP_NR_IPI || ipi_id < 0)
pr_debug("[ADSP] A ipi handler id abnormal, id=%d", ipi_id);
else if (adsp_ipi_desc[ipi_id].handler) {
if (ipi_id == ADSP_IPI_ADSP_A_READY ||
ipi_id == ADSP_IPI_DVFS_SUSPEND ||
ipi_id == ADSP_IPI_LOGGER_INIT) {
/*
* adsp_ready & logger init ipi bypass send to ipi
* queue and do callback directly. (which will in isr)
* Must ensure the callback can do in isr
*/
adsp_ipi_desc[ipi_id].handler(ipi_id, share_buf, len);
} else if (is_scp_ipi_queue_init(AUDIO_OPENDSP_USE_HIFI3_A)) {
scp_dispatch_ipi_hanlder_to_queue(
AUDIO_OPENDSP_USE_HIFI3_A,
ipi_id, share_buf, len,
adsp_ipi_desc[ipi_id].handler);
} else {
ipi_msg = (struct ipi_msg_t *)share_buf;
if (ipi_msg->magic == IPI_MSG_MAGIC_NUMBER)
DUMP_IPI_MSG("ipi queue not ready!", ipi_msg);
else
pr_info("ipi queue not ready!! opendsp_id: %u, ipi_id: %u, buf: %p, len: %u, ipi_handler: %p",
AUDIO_OPENDSP_USE_HIFI3_A,
ipi_id, share_buf, len,
adsp_ipi_desc[ipi_id].handler);
WARN_ON(1);
}
} else {
pr_debug("[ADSP] A ipi handler is null or abnormal, id=%d",
ipi_id);
}
stop_time = ktime_us_delta(ktime_get(), start_time);
if (stop_time > 1000) /* 1 ms */
pr_notice("IPC ISR %lld us too long!!", stop_time);
}
/*
* ipi initialize
*/
void adsp_ipi_init(void)
{
struct adsp_priv *pdata = get_adsp_core_by_id(ADSP_A_ID);
struct ipi_ctrl_s *ctrl = NULL;
void __iomem *base = adsp_get_sharedmem_base(pdata, ADSP_SHAREDMEM_IPCBUF);
pdata->ipi_ctrl = &adsp_ipi_ctrl;
ctrl = pdata->ipi_ctrl;
mutex_init(&ctrl->lock);
ctrl->recv_obj = (struct adsp_share_obj *)base;
ctrl->send_obj = ctrl->recv_obj + 1;
pr_debug("[adsp_ipi]ctrl->recv_obj = 0x%p\n", ctrl->recv_obj);
pr_debug("[adsp_ipi]ctrl->send_obj = 0x%p\n", ctrl->send_obj);
}
/*
* API let apps can register an ipi handler to receive IPI
* @param id: IPI ID
* @param handler: IPI handler
* @param name: IPI name
*/
enum adsp_ipi_status adsp_ipi_registration(
enum adsp_ipi_id id,
void (*ipi_handler)(int id, void *data, unsigned int len),
const char *name)
{
if (id < ADSP_NR_IPI && id >= 0) {
adsp_ipi_desc[id].name = name;
if (ipi_handler == NULL)
return ADSP_IPI_ERROR;
adsp_ipi_desc[id].handler = ipi_handler;
return ADSP_IPI_DONE;
} else
return ADSP_IPI_ERROR;
}
EXPORT_SYMBOL_GPL(adsp_ipi_registration);
/*
* API let apps unregister an ipi handler
* @param id: IPI ID
*/
enum adsp_ipi_status adsp_ipi_unregistration(enum adsp_ipi_id id)
{
if (id < ADSP_NR_IPI && id >= 0) {
adsp_ipi_desc[id].name = "";
adsp_ipi_desc[id].handler = NULL;
return ADSP_IPI_DONE;
} else
return ADSP_IPI_ERROR;
}
EXPORT_SYMBOL_GPL(adsp_ipi_unregistration);
/*
* API for apps to send an IPI to adsp
* @param id: IPI ID
* @param buf: the pointer of data
* @param len: data length
* @param wait: If true, wait (atomically) until data have been gotten by Host
* @param len: data length
*/
enum adsp_ipi_status adsp_ipi_send(enum adsp_ipi_id id, void *buf,
unsigned int len, unsigned int wait,
enum adsp_core_id adsp_id)
{
int retval = 0;
uint32_t wait_ms = (wait) ? ADSP_IPI_QUEUE_DEFAULT_WAIT_MS : 0;
/* wait until IPC done */
retval = scp_send_msg_to_queue(
AUDIO_OPENDSP_USE_HIFI3_A, id, buf, len, wait_ms);
return (retval == 0) ? ADSP_IPI_DONE : ADSP_IPI_ERROR;
}
enum adsp_ipi_status adsp_ipi_send_ipc(enum adsp_ipi_id id, void *buf,
unsigned int len, unsigned int wait,
unsigned int adsp_id)
{
struct adsp_priv *pdata = get_adsp_core_by_id(adsp_id);
struct ipi_ctrl_s *ctrl;
struct adsp_share_obj *send_obj;
struct ipi_msg_t *p_ipi_msg = NULL;
ktime_t start_time;
s64 time_ipc_us;
static bool busy_log_flag;
static u8 share_buf[SHARE_BUF_SIZE - 16];
if (unlikely(!pdata))
return -EACCES;
ctrl = pdata->ipi_ctrl;
send_obj = ctrl->send_obj;
if (in_interrupt() && wait) {
pr_info("adsp_ipi_send: cannot use in isr");
return ADSP_IPI_ERROR;
}
if (len > sizeof(send_obj->share_buf) || buf == NULL) {
pr_info("adsp_ipi_send: %s buffer error",
adsp_core_ids[pdata->id]);
return ADSP_IPI_ERROR;
}
if (mutex_trylock(&ctrl->lock) == 0) {
pr_info("adsp_ipi_send:%s %d mutex_trylock busy,owner=%d",
adsp_core_ids[pdata->id], id,
ctrl->ipi_mutex_owner);
return ADSP_IPI_BUSY;
}
/* get adsp ipi mutex owner */
ctrl->ipi_mutex_owner = id;
if (adsp_mt_check_sw_int(pdata->id) > 0) {
if (busy_log_flag == false) {
busy_log_flag = true;
p_ipi_msg = (struct ipi_msg_t *)share_buf;
if (p_ipi_msg->magic == IPI_MSG_MAGIC_NUMBER)
DUMP_IPI_MSG("busy. ipc owner", p_ipi_msg);
else
pr_info("adsp_ipi_send: %s %d host to adsp busy, ipi last time = %d",
adsp_core_ids[pdata->id], id,
ctrl->ipi_owner);
}
mutex_unlock(&ctrl->lock);
return ADSP_IPI_BUSY;
}
busy_log_flag = false;
/* get adsp ipi send owner */
ctrl->ipi_owner = id;
memcpy(share_buf, buf, len);
memcpy_toio((void *)send_obj->share_buf, buf, len);
send_obj->len = len;
send_obj->id = id;
dsb(SY);
/* send host to adsp ipi */
adsp_mt_set_sw_int(pdata->id);
if (wait) {
start_time = ktime_get();
while (adsp_mt_check_sw_int(pdata->id) > 0) {
time_ipc_us = ktime_us_delta(ktime_get(), start_time);
if (time_ipc_us > 1000) /* 1 ms */
break;
}
}
#ifdef Liang_Check
if (adsp_awake_unlock(pdata->id) == -1)
pr_debug("adsp_ipi_send: awake unlock fail");
#endif
mutex_unlock(&ctrl->lock);
return ADSP_IPI_DONE;
}
EXPORT_SYMBOL_GPL(adsp_ipi_send);
@@ -0,0 +1,42 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __ADSP_IPI_H
#define __ADSP_IPI_H
#include "adsp_helper.h"
#define SHARE_BUF_SIZE 288
/* adsp awake timeout count definition*/
#define ADSP_AWAKE_TIMEOUT 5000
struct adsp_ipi_desc {
void (*handler)(int id, void *data, unsigned int len);
const char *name;
};
struct adsp_share_obj {
enum adsp_ipi_id id;
unsigned int len;
unsigned char reserve[8];
unsigned char share_buf[SHARE_BUF_SIZE - 16];
};
struct ipi_ctrl_s {
enum adsp_ipi_id ipi_mutex_owner;
enum adsp_ipi_id ipi_owner;
struct adsp_share_obj *send_obj;
struct adsp_share_obj *recv_obj;
struct mutex lock; /* ap used */
};
void adsp_ipi_init(void);
void adsp_ipi_handler(int irq, void *data, int cid);
enum adsp_ipi_status adsp_ipi_send_ipc(enum adsp_ipi_id id, void *buf,
unsigned int len, unsigned int wait,
unsigned int adsp_id);
#endif
@@ -0,0 +1,11 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __ADSP_MBOX_H__
#define __ADSP_MBOX_H__
#include "adsp_ipi.h"
#endif /* __ADSP_MBOX_H__ */
@@ -0,0 +1,238 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#include <linux/io.h>
#include <linux/delay.h>
#include <mt-plat/sync_write.h>
#include "adsp_platform.h"
#include "adsp_reg.h"
#include "adsp_reserved_mem.h"
#include "adsp_semaphore.h"
#include "adsp_platform_driver.h"
#ifdef ADSP_BASE
#undef ADSP_BASE
#endif
#define ADSP_BASE mt_base
#define INFRACFG_AO_BASE infracfg_ao
#define PERICFG_BASE pericfg
#define SET_BITS(addr, mask) writel(readl(addr) | (mask), addr)
#define CLR_BITS(addr, mask) writel(readl(addr) & ~(mask), addr)
#ifdef CONFIG_ARM64
#define IOMEM(a) ((void __force __iomem *)((a)))
#endif
#define adsp_reg_read(addr) __raw_readl(IOMEM(addr))
#define adsp_reg_sync_write(addr, val) mt_reg_sync_writel(val, addr)
#define MAGIC_PATTERN (0xfafafafa)
static void __iomem *mt_base;
static void __iomem *infracfg_ao;
static void __iomem *pericfg;
void adsp_mt_sw_reset(u32 cid)
{
unsigned long flags;
if (unlikely(cid >= ADSP_CORE_TOTAL))
return;
write_lock_irqsave(&access_rwlock, flags);
SET_BITS(ADSP_CFGREG_SW_RSTN, ADSP_A_SW_RSTN);
udelay(1);
CLR_BITS(ADSP_CFGREG_SW_RSTN, ADSP_A_SW_RSTN);
write_unlock_irqrestore(&access_rwlock, flags);
}
void adsp_mt_run(u32 cid)
{
int timeout = 1000;
if (unlikely(cid >= ADSP_CORE_TOTAL))
return;
/* request infra/26M/apsrc/v18/ ddr resource */
SET_BITS(ADSP_SPM_REQ, ADSP_SPM_SRC_BITS);
SET_BITS(ADSP_DDREN_REQ, ADSP_DDR_ENABLE);
/* make sure SPM return ack */
while (timeout) {
if (readl(ADSP_SPM_ACK) == ((ADSP_DDR_ENABLE << 4) | ADSP_SPM_SRC_BITS))
break;
udelay(10);
if (--timeout == 0) {
pr_err("[ADSP] timeout: cannot get SPM ack\n");
break;
}
}
CLR_BITS(ADSP_HIFI3_IO_CONFIG, ADSP_A_RUNSTALL);
}
void adsp_mt_stop(u32 cid)
{
if (unlikely(cid >= ADSP_CORE_TOTAL))
return;
SET_BITS(ADSP_HIFI3_IO_CONFIG, ADSP_A_RUNSTALL);
}
void adsp_mt_clear(void)
{
writel(0x0, ADSP_CFGREG_SW_RSTN);
writel(0xC0001002, ADSP_HIFI3_IO_CONFIG);
writel(0, ADSP_CREG_BOOTUP_MARK);
writel(0xdf, ADSP_CLK_CTRL_BASE);
writel(0x0, ADSP_IRQ_EN);
writel(0x0, ADSP_A_WDT_REG);
}
void adsp_mt_clr_spm(u32 cid)
{
if (unlikely(cid >= ADSP_CORE_TOTAL))
return;
CLR_BITS(ADSP_A_SPM_WAKEUPSRC, ADSP_WAKEUP_SPM);
}
void adsp_mt_clr_sysirq(u32 cid)
{
if (unlikely(cid >= ADSP_CORE_TOTAL))
return;
writel(ADSP_A_2HOST_IRQ_BIT, ADSP_GENERAL_IRQ_CLR);
}
bool is_adsp_genirq_idle(u32 cid)
{
if (unlikely(cid >= ADSP_CORE_TOTAL))
return false;
return ((readl(ADSP_GENERAL_IRQ_SET) & ADSP_GENERAL_IRQ_INUSED)
== ADSP_GENERAL_IRQ_INUSED);
}
void adsp_mt_disable_wdt(u32 cid)
{
if (unlikely(cid >= ADSP_CORE_TOTAL))
return;
CLR_BITS(ADSP_A_WDT_REG, WDT_EN_BIT);
}
bool check_hifi_status(u32 mask)
{
return (readl(ADSP_SLEEP_STATUS_REG) & mask);
}
bool is_adsp_axibus_idle(void)
{
/* no pending counter found when ap read this reg in mt6785 */
return (readl(ADSP_DBG_PEND_CNT) == 0x000000);
}
void adsp_mt_set_bootup_mark(u32 cid)
{
if (unlikely(cid >= ADSP_CORE_TOTAL))
return;
writel(MAGIC_PATTERN, ADSP_CREG_BOOTUP_MARK);
}
u32 switch_adsp_clk_ctrl_cg(bool en, u32 mask)
{
u32 retval = readl(ADSP_CLK_CTRL_BASE);
if (en)
SET_BITS(ADSP_CLK_CTRL_BASE, mask);
else
CLR_BITS(ADSP_CLK_CTRL_BASE, mask);
return retval;
}
u32 switch_adsp_uart_ctrl_cg(bool en, u32 mask)
{
u32 retval = readl(ADSP_UART_CTRL);
if (en)
SET_BITS(ADSP_UART_CTRL, mask);
else
CLR_BITS(ADSP_UART_CTRL, mask);
return retval;
}
void adsp_mt_clr_sw_reset(void)
{
CLR_BITS(ADSP_CFGREG_SW_RSTN, ADSP_A_SW_RSTN);
}
void adsp_mt_set_sw_int(u32 cid)
{
if (unlikely(cid >= ADSP_CORE_TOTAL))
return;
adsp_reg_sync_write(ADSP_SW_INT_SET, (1 << cid));
}
u32 adsp_mt_check_sw_int(u32 cid)
{
if (unlikely(cid >= ADSP_CORE_TOTAL))
return 0;
return (adsp_reg_read(ADSP_SW_INT_SET) & (1 << cid));
}
void adsp_platform_init(void)
{
if (unlikely(!adsp_cores[0]))
return;
mt_base = adsp_cores[0]->cfg;
infracfg_ao = adsp_common.infracfg_ao;
pericfg = adsp_common.pericfg;
adsp_init_reserve_memory();
adsp_sem_init(SEMA_WAY_BITS, SEMA_CTRL_BIT,
SEMA_TIMEOUT, ADSP_SEMAPHORE);
}
/* mt6785 only */
static bool is_adsp_bus_protect_ready(void)
{
return ((adsp_reg_read(INFRA_AXI_PROT_STA1) & ADSP_AXI_PROT_READY_MASK)
== ADSP_AXI_PROT_READY_MASK);
}
void adsp_bus_sleep_protect(uint32_t enable)
{
int timeout = 1000;
if (enable) {
/* enable adsp bus protect */
adsp_reg_sync_write(INFRA_AXI_PROT_SET, ADSP_AXI_PROT_MASK);
while (--timeout && !is_adsp_bus_protect_ready())
udelay(1);
if (!is_adsp_bus_protect_ready())
pr_err("%s() ready timeout\n", __func__);
} else {
/* disable adsp bus protect */
adsp_reg_sync_write(INFRA_AXI_PROT_CLR, ADSP_AXI_PROT_MASK);
}
}
void adsp_way_en_ctrl(uint32_t enable)
{
if (enable)
adsp_reg_sync_write(ADSP_WAY_EN_CTRL,
adsp_reg_read(ADSP_WAY_EN_CTRL) | ADSP_WAY_EN_MASK);
else
adsp_reg_sync_write(ADSP_WAY_EN_CTRL,
adsp_reg_read(ADSP_WAY_EN_CTRL) & ~ADSP_WAY_EN_MASK);
}
@@ -0,0 +1,64 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __ADSP_PLATFORM_H__
#define __ADSP_PLATFORM_H__
enum adsp_irq_id {
ADSP_IRQ_WDT_ID = 0,
ADSP_IRQ_IPC_ID,
ADSP_IRQ_NUM, /* id > ADSP_IRQ_NUM: not support */
ADSP_IRQ_AUDIO_ID,
};
enum adsp_core_id {
ADSP_A_ID = 0,
ADSP_CORE_TOTAL,
};
enum adsp_sharedmem_id {
ADSP_SHAREDMEM_MPUINFO,
ADSP_SHAREDMEM_TIMESYNC,
ADSP_SHAREDMEM_IPCBUF,
ADSP_SHAREDMEM_AUDIO_IPIBUF,
ADSP_SHAREDMEM_WAKELOCK,
ADSP_SHAREDMEM_SYS_STATUS,
ADSP_SHAREDMEM_BUS_MON_DUMP,
ADSP_SHAREDMEM_INFRA_BUS_DUMP,
ADSP_SHAREDMEM_NUM,
};
/* semaphore */
#define SEMA_TIMEOUT 5000
#define SEMA_WAY_BITS 2
#define SEMA_CTRL_BIT 1
/* platform method */
void adsp_mt_sw_reset(u32 cid);
void adsp_mt_run(u32 cid);
void adsp_mt_stop(u32 cid);
void adsp_mt_clear(void);
void adsp_mt_clr_sw_reset(void);
void adsp_mt_clr_sysirq(u32 cid);
void adsp_mt_clr_spm(u32 cid);
void adsp_mt_disable_wdt(u32 cid);
void adsp_mt_set_sw_int(u32 cid);
u32 adsp_mt_check_sw_int(u32 cid);
void adsp_mt_set_bootup_mark(u32 cid);
bool check_hifi_status(u32 mask);
bool is_adsp_axibus_idle(void);
bool is_adsp_genirq_idle(u32 cid);
u32 switch_adsp_clk_ctrl_cg(bool en, u32 mask);
u32 switch_adsp_uart_ctrl_cg(bool en, u32 mask);
void adsp_platform_init(void);
/* mt6785 only: system usage */
void adsp_bus_sleep_protect(uint32_t enable);
void adsp_way_en_ctrl(uint32_t enable);
extern rwlock_t access_rwlock;
#endif
@@ -0,0 +1,541 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#include <linux/sysfs.h>
#ifdef CONFIG_DEBUG_FS
#include <linux/debugfs.h>
#endif
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/io.h>
#include <linux/delay.h>
#include <linux/platform_device.h>
#include <linux/kobject.h>
#include <linux/ktime.h>
#include <linux/syscore_ops.h>
#include "adsp_clk.h"
#include "adsp_reserved_mem.h"
#include "adsp_logger.h"
#include "adsp_excep.h"
#include "adsp_reg.h"
#include "adsp_platform.h"
#include "adsp_platform_driver.h"
#include "adsp_core.h"
#include "adsp_ipi.h"
#include "adsp_bus_monitor.h"
#include "adsp_timesync.h"
#include <mtk_spm_sleep.h>
struct wait_queue_head adsp_waitq;
struct workqueue_struct *adsp_wq;
struct adsp_com adsp_common;
struct adsp_priv *adsp_cores[ADSP_CORE_TOTAL];
static u32 adsp_load;
static struct syscore_ops adsp_syscore_ops;
static int adsp_core0_init(struct adsp_priv *pdata);
static int adsp_core0_suspend(void);
static int adsp_core0_resume(void);
static void adsp_logger_init0_cb(struct work_struct *ws);
static int adsp_after_bootup(struct adsp_priv *pdata);
static const struct adsp_description adsp_c0_desc = {
.id = 0,
.name = "adsp_0",
.sharedmems = {
[ADSP_SHAREDMEM_MPUINFO] = {0x0020, 0x0020},
[ADSP_SHAREDMEM_TIMESYNC] = {0x0040, 0x0020},
[ADSP_SHAREDMEM_IPCBUF] = {0x0280, 0x0240},
[ADSP_SHAREDMEM_AUDIO_IPIBUF] = {0x0680, 0x0400},
[ADSP_SHAREDMEM_WAKELOCK] = {0x0684, 0x0004},
[ADSP_SHAREDMEM_SYS_STATUS] = {0x0688, 0x0004},
[ADSP_SHAREDMEM_BUS_MON_DUMP] = {0x0744, 0x00BC},
[ADSP_SHAREDMEM_INFRA_BUS_DUMP] = {0x07E4, 0x00A0},
},
.ops = {
.initialize = adsp_core0_init,
.after_bootup = adsp_after_bootup,
}
};
/*------------------------------------------------------------*/
/* adsp operation */
int adsp_core0_init(struct adsp_priv *pdata)
{
int ret = 0;
#ifdef CONFIG_DEBUG_FS
pdata->debugfs = debugfs_create_file("audiodsp0", S_IFREG | 0644, NULL,
pdata, &adsp_debug_ops);
#endif
adsp_wq = alloc_workqueue("adsp_wq", WORK_CPU_UNBOUND | WQ_HIGHPRI, 0);
pdata->wq = adsp_wq;
init_waitqueue_head(&adsp_waitq);
init_adsp_feature_control(pdata->id, pdata->feature_set, 1000,
adsp_wq,
adsp_core0_suspend,
adsp_core0_resume);
adsp_update_mpu_memory_info(pdata);
/* exception init & irq */
init_adsp_exception_control(pdata->dev, adsp_wq, &adsp_waitq);
adsp_irq_registration(pdata->id, ADSP_IRQ_WDT_ID, adsp_wdt_handler,
pdata);
/* logger */
pdata->log_ctrl = adsp_logger_init(ADSP_A_LOGGER_MEM_ID, adsp_logger_init0_cb);
/* ipi */
adsp_ipi_init();
adsp_irq_registration(pdata->id, ADSP_IRQ_IPC_ID, adsp_ipi_handler,
pdata);
adsp_awake_init(pdata, ADSP_A_SW_INT);
#if ADSP_BUS_MONITOR_INIT_ENABLE
adsp_bus_monitor_init(pdata);
#endif
return ret;
}
bool is_adsp_load(void)
{
return adsp_load;
}
static int adsp_after_bootup(struct adsp_priv *pdata)
{
#ifdef BRINGUP_ADSP
/* disable adsp suspend by registering feature */
_adsp_register_feature(pdata->id, SYSTEM_FEATURE_ID, 0);
#endif
return adsp_awake_unlock(pdata->id);
}
static bool is_adsp_core_suspend(struct adsp_priv *pdata)
{
u32 status = 0;
if (unlikely(!pdata))
return false;
adsp_copy_from_sharedmem(pdata,
ADSP_SHAREDMEM_SYS_STATUS,
&status, sizeof(status));
return check_hifi_status(ADSP_A_IS_WFI) &&
check_hifi_status(ADSP_AXI_BUS_IS_IDLE) &&
(status == ADSP_SUSPEND) &&
is_adsp_genirq_idle(pdata->id);
}
int adsp_core0_suspend(void)
{
int ret = 0, retry = 10;
u32 status = 0;
struct adsp_priv *pdata = adsp_cores[ADSP_A_ID];
ktime_t start = ktime_get();
if (get_adsp_state(pdata) == ADSP_RUNNING) {
reinit_completion(&pdata->done);
adsp_timesync_suspend(APTIME_UNFREEZE);
ret = adsp_push_message(ADSP_IPI_DVFS_SUSPEND, &status,
sizeof(status), 2000, pdata->id);
if (ret != ADSP_IPI_DONE) {
ret = -EPIPE;
goto ERROR;
}
/* wait core suspend ack timeout 2s */
ret = wait_for_completion_timeout(&pdata->done, 2 * HZ);
if (!ret) {
ret = -ETIMEDOUT;
goto ERROR;
}
while (--retry && !is_adsp_core_suspend(pdata))
usleep_range(100, 200);
if (retry == 0 || get_adsp_state(pdata) == ADSP_RESET) {
ret = -ETIME;
goto ERROR;
}
if (get_adsp_state(pdata) == ADSP_RESET) {
ret = -EFAULT;
goto ERROR;
}
adsp_mt_stop(pdata->id);
switch_adsp_power(false);
set_adsp_state(pdata, ADSP_SUSPEND);
}
pr_info("%s(), done elapse %lld us", __func__,
ktime_us_delta(ktime_get(), start));
return 0;
ERROR:
pr_warn("%s(), can't going to suspend, ret(%d)\n", __func__, ret);
adsp_aed_dispatch(EXCEP_KERNEL, pdata);
return ret;
}
int adsp_core0_resume(void)
{
int ret = 0;
struct adsp_priv *pdata = adsp_cores[ADSP_A_ID];
ktime_t start = ktime_get();
if (get_adsp_state(pdata) == ADSP_SUSPEND) {
switch_adsp_power(true);
adsp_mt_sw_reset(pdata->id);
#if ADSP_BUS_MONITOR_INIT_ENABLE
adsp_bus_monitor_init(pdata);
#endif
adsp_mt_set_bootup_mark(pdata->id);
reinit_completion(&pdata->done);
adsp_mt_run(pdata->id);
ret = wait_for_completion_timeout(&pdata->done, 2 * HZ);
if (get_adsp_state(pdata) != ADSP_RUNNING) {
pr_warn("%s, can't going to resume\n", __func__);
adsp_aed_dispatch(EXCEP_KERNEL, pdata);
return -ETIME;
}
adsp_timesync_resume();
}
pr_info("%s(), done elapse %lld us", __func__,
ktime_us_delta(ktime_get(), start));
return 0;
}
void adsp_logger_init0_cb(struct work_struct *ws)
{
int ret;
uint64_t info[6];
info[0] = adsp_get_reserve_mem_phys(ADSP_A_LOGGER_MEM_ID);
info[1] = adsp_get_reserve_mem_size(ADSP_A_LOGGER_MEM_ID);
info[2] = adsp_get_reserve_mem_phys(ADSP_A_CORE_DUMP_MEM_ID);
info[3] = adsp_get_reserve_mem_size(ADSP_A_CORE_DUMP_MEM_ID);
info[4] = adsp_get_reserve_mem_phys(ADSP_A_DEBUG_DUMP_MEM_ID);
info[5] = adsp_get_reserve_mem_size(ADSP_A_DEBUG_DUMP_MEM_ID);
_adsp_register_feature(ADSP_A_ID, ADSP_LOGGER_FEATURE_ID, 0);
ret = adsp_push_message(ADSP_IPI_LOGGER_INIT, (void *)info,
sizeof(info), 20, ADSP_A_ID);
_adsp_deregister_feature(ADSP_A_ID, ADSP_LOGGER_FEATURE_ID, 0);
if (ret != ADSP_IPI_DONE)
pr_err("[ADSP]logger initial fail, ipi ret=%d\n", ret);
}
/*---------------------------------------------------------------------------*/
static const struct of_device_id adsp_of_ids[] = {
{ .compatible = "mediatek,adsp_core_0", .data = &adsp_c0_desc},
{}
};
static const struct of_device_id adsp_common_of_ids[] = {
{ .compatible = "mediatek,adsp_common"},
{}
};
const struct attribute_group *adsp_common_attr_groups[] = {
&adsp_excep_attr_group,
NULL,
};
const struct attribute_group *adsp_core_attr_groups[] = {
&adsp_default_attr_group,
NULL,
};
static struct miscdevice adsp_common_device = {
.minor = MISC_DYNAMIC_MINOR,
.name = "adsp",
.groups = adsp_common_attr_groups,
.fops = &adsp_common_file_ops,
};
/* user-space event notify */
static int adsp_user_event_notify(struct notifier_block *nb,
unsigned long event, void *ptr)
{
struct device *dev = adsp_common_device.this_device;
int ret = 0;
if (!dev)
return NOTIFY_DONE;
switch (event) {
case ADSP_EVENT_STOP:
ret = kobject_uevent(&dev->kobj, KOBJ_OFFLINE);
break;
case ADSP_EVENT_READY:
ret = kobject_uevent(&dev->kobj, KOBJ_ONLINE);
break;
default:
pr_info("%s, ignore event %lu", __func__, event);
break;
}
if (ret)
pr_info("%s, uevnet(%lu) fail, ret %d", __func__, event, ret);
return NOTIFY_OK;
}
struct notifier_block adsp_uevent_notifier = {
.notifier_call = adsp_user_event_notify,
.priority = AUDIO_HAL_FEATURE_PRI,
};
static int adsp_common_drv_probe(struct platform_device *pdev)
{
int ret = 0;
struct device *dev = &pdev->dev;
/* indicate if adsp images is loaded successfully */
of_property_read_u32(dev->of_node, "load", &adsp_load);
if (!adsp_load)
pr_info("%s adsp disable\n", __func__);
adsp_common.infracfg_ao = of_iomap(dev->of_node, 0);
if (IS_ERR(adsp_common.infracfg_ao))
goto ERROR;
adsp_common.pericfg = of_iomap(dev->of_node, 1);
if (IS_ERR(adsp_common.pericfg))
goto ERROR;
ret = adsp_clk_device_probe(pdev);
if (ret) {
pr_warn("%s(), clk probe fail, %d\n", __func__, ret);
goto ERROR;
}
ret = adsp_mem_device_probe(pdev);
if (ret) {
pr_info("%s(), memory probe fail, %d\n", __func__, ret);
goto ERROR;
}
ret = misc_register(&adsp_common_device);
if (ret) {
pr_warn("%s(), misc_register fail, %d\n", __func__, ret);
goto ERROR;
}
/* remove this emimpu setting after emimpu use common kernel struct in mt6785 */
adsp_set_emimpu_shared_region();
adsp_register_notify(&adsp_uevent_notifier);
register_syscore_ops(&adsp_syscore_ops);
pr_info("%s, success\n", __func__);
ERROR:
return ret;
}
static int adsp_common_drv_remove(struct platform_device *pdev)
{
return 0;
}
static int adsp_core_drv_probe(struct platform_device *pdev)
{
int ret = 0;
struct resource *res;
struct device *dev = &pdev->dev;
struct adsp_priv *pdata;
const struct adsp_description *desc;
const struct of_device_id *match;
u32 temp = 0;
/* create private data */
pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
if (!pdata)
return -ENOMEM;
match = of_match_node(adsp_of_ids, dev->of_node);
if (!match)
return -ENODEV;
desc = (struct adsp_description *)match->data;
pdata->id = desc->id;
pdata->name = desc->name;
pdata->ops = &desc->ops;
pdata->mapping_table = desc->sharedmems;
pdata->dev = dev;
init_completion(&pdata->done);
/* get resource from platform_device */
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
pdata->cfg = devm_ioremap_resource(dev, res);
pdata->cfg_size = resource_size(res);
res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
pdata->itcm = devm_ioremap_resource(dev, res);
pdata->itcm_size = resource_size(res);
res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
pdata->dtcm = devm_ioremap_resource(dev, res);
pdata->dtcm_size = resource_size(res);
pdata->irq[ADSP_IRQ_WDT_ID].seq = platform_get_irq(pdev, 0);
pdata->irq[ADSP_IRQ_WDT_ID].clear_irq = adsp_mt_disable_wdt;
pdata->irq[ADSP_IRQ_IPC_ID].seq = platform_get_irq(pdev, 1);
/* adsp_ipi clr irq by itself */
/* pdata->irq[ADSP_IRQ_IPC_ID].clear_irq = adsp_mt_clr_sysirq;*/
of_property_read_u32(dev->of_node, "sysram", &temp);
pdata->sysram_phys = (phys_addr_t)temp;
of_property_read_u32(dev->of_node, "sysram_size", &temp);
pdata->sysram_size = (size_t)temp;
if (pdata->sysram_phys == 0 || pdata->sysram_size == 0) {
ret = -ENODEV;
goto ERROR;
}
pdata->sysram = ioremap_wc(pdata->sysram_phys, pdata->sysram_size);
pdata->feature_set = 0xffffffff; //no need for one core platform
/* register misc device */
pdata->mdev.minor = MISC_DYNAMIC_MINOR;
pdata->mdev.name = desc->name;
pdata->mdev.fops = &adsp_core_file_ops;
pdata->mdev.groups = adsp_core_attr_groups;
ret = misc_register(&pdata->mdev);
if (unlikely(ret != 0))
goto ERROR;
/* add to adsp_core list */
adsp_cores[desc->id] = pdata;
pr_info("%s, id:%d success\n", __func__, pdata->id);
return 0;
ERROR:
pr_err("%s id:%d fail, ret = %d", __func__, pdata->id, ret);
return ret;
}
static int adsp_core_drv_remove(struct platform_device *pdev)
{
return 0;
}
static int adsp_ap_suspend(struct device *dev)
{
int cid = 0, ret = 0;
struct adsp_priv *pdata = NULL;
for (cid = ADSP_CORE_TOTAL - 1; cid >= 0; cid--) {
pdata = adsp_cores[cid];
if (pdata->state == ADSP_RUNNING) {
ret = flush_suspend_work(pdata->id);
pr_info("%s, flush_suspend_work ret %d, cid %d",
__func__, ret, cid);
}
}
if (is_adsp_system_running()) {
adsp_timesync_suspend(APTIME_FREEZE);
pr_info("%s, time sync freeze", __func__);
}
return 0;
}
static int adsp_ap_resume(struct device *dev)
{
if (is_adsp_system_running()) {
adsp_timesync_resume();
pr_info("%s, time sync unfreeze", __func__);
}
return 0;
}
static int adsp_syscore_suspend(void)
{
if (!is_adsp_system_running()) {
adsp_bus_sleep_protect(true);
spm_adsp_mem_protect();
}
return 0;
}
static void adsp_syscore_resume(void)
{
if (!is_adsp_system_running()) {
spm_adsp_mem_unprotect();
adsp_bus_sleep_protect(false);
}
}
static const struct dev_pm_ops adsp_ap_pm_ops = {
SET_SYSTEM_SLEEP_PM_OPS(adsp_ap_suspend,
adsp_ap_resume)
};
static struct syscore_ops adsp_syscore_ops = {
.resume = adsp_syscore_resume,
.suspend = adsp_syscore_suspend,
};
static struct platform_driver adsp_common_driver = {
.probe = adsp_common_drv_probe,
.remove = adsp_common_drv_remove,
.driver = {
.name = "adsp_common",
.owner = THIS_MODULE,
#ifdef CONFIG_OF
.of_match_table = adsp_common_of_ids,
#endif
#ifdef CONFIG_PM
.pm = &adsp_ap_pm_ops,
#endif
},
};
static struct platform_driver adsp_core0_driver = {
.probe = adsp_core_drv_probe,
.remove = adsp_core_drv_remove,
.driver = {
.name = "adsp_core0",
.owner = THIS_MODULE,
#ifdef CONFIG_OF
.of_match_table = adsp_of_ids,
#endif
},
};
static struct platform_driver * const drivers[] = {
&adsp_common_driver,
&adsp_core0_driver,
};
int create_adsp_drivers(void)
{
int ret = 0;
ret = platform_register_drivers(drivers, ARRAY_SIZE(drivers));
return (is_adsp_load() && adsp_cores[0] && ~ret);
}
@@ -0,0 +1,105 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __ADSP_PLATFORM_DRIVER_H__
#define __ADSP_PLATFORM_DRIVER_H__
#include <linux/miscdevice.h> /* needed by miscdevice* */
#include <linux/workqueue.h>
#include <linux/interrupt.h>
#include "adsp_platform.h"
struct adsp_priv;
struct log_ctrl_s;
struct sharedmem_info {
unsigned int offset;
unsigned int size;
};
struct adsp_operations {
int (*initialize)(struct adsp_priv *pdata);
int (*after_bootup)(struct adsp_priv *pdata);
};
struct adsp_description {
u32 id;
const char *name;
const struct sharedmem_info sharedmems[ADSP_SHAREDMEM_NUM];
const struct adsp_operations ops;
};
struct irq_t {
u32 cid;
u32 seq;
void (*irq_cb)(int irq, void *data, int cid);
void (*clear_irq)(u32 cid);
void *data;
};
struct adsp_com {
void __iomem *infracfg_ao;
void __iomem *pericfg;
};
struct adsp_priv {
u32 id;
const char *name;
int state;
unsigned int feature_set;
/* address & size */
void __iomem *cfg;
void __iomem *itcm;
void __iomem *dtcm;
void __iomem *sysram;
size_t cfg_size;
size_t itcm_size;
size_t dtcm_size;
size_t sysram_size;
phys_addr_t sysram_phys;
const struct sharedmem_info *mapping_table;
/* irq */
struct irq_t irq[ADSP_IRQ_NUM];
/* mailbox info: keep for dev_dump_show() in adsp_fs.c */
struct mtk_mbox_pin_send *send_mbox;
struct mtk_mbox_pin_recv *recv_mbox;
/* ipi info */
struct ipi_ctrl_s *ipi_ctrl;
/* logger control */
struct log_ctrl_s *log_ctrl;
struct device *dev;
struct dentry *debugfs;
struct miscdevice mdev;
struct workqueue_struct *wq;
struct completion done;
/* method */
const struct adsp_operations *ops;
/* snapshot for recovery restore */
void *itcm_snapshot;
void *dtcm_snapshot;
};
struct adsp_c2c_share_dram_info_t {
u32 share_dram_addr;
u32 share_dram_size;
};
int create_adsp_drivers(void);
bool is_adsp_load(void);
extern struct attribute_group adsp_default_attr_group;
extern struct attribute_group adsp_excep_attr_group;
extern const struct file_operations adsp_debug_ops;
extern const struct file_operations adsp_common_file_ops;
extern const struct file_operations adsp_core_file_ops;
extern struct adsp_priv *adsp_cores[ADSP_CORE_TOTAL];
extern struct adsp_com adsp_common;
#endif
@@ -0,0 +1,126 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __ADSP_REG_H
#define __ADSP_REG_H
#define ADSP_CFGREG_SW_RSTN (ADSP_BASE + 0x00)
#define ADSP_A_SW_RSTN (0x11)
#define ADSP_HIFI3_IO_CONFIG (ADSP_BASE + 0x0008)
#define ADSP_A_RUNSTALL (1 << 31)
#define ADSP_RUNSTALL (ADSP_A_RUNSTALL)
/* swint register no update naming */
#define ADSP_SW_INT_SET (ADSP_BASE + 0x001C)
#define ADSP_SW_INT_CLR (ADSP_BASE + 0x0020)
#define ADSP_SW_INT0 (0)
#define ADSP_SW_INT1 (1)
#define ADSP_SW_INT2 (2)
#define ADSP_SW_INT3 (3)
#define HOST_TO_ADSP_A (1 << 0)
#define ADSP_A_SW_INT (1 << ADSP_SW_INT1)
#define ADSP_GENERAL_IRQ_SET (ADSP_BASE + 0x0034)
#define ADSP_GENERAL_IRQ_CLR (ADSP_BASE + 0x0038)
#define ADSP_A_2HOST_IRQ_BIT (1 << 0)
#define ADSP_A_2CONN_IRQ_BIT (1 << 4)
#define ADSP_GENERAL_IRQ_INUSED \
(ADSP_A_2HOST_IRQ_BIT)
#define ADSP_DVFSRC_STATE (ADSP_BASE + 0x003C)
#define ADSP_DVFSRC_REQ (ADSP_BASE + 0x0040)
#define ADSP_DDREN_REQ (ADSP_BASE + 0x0044)
#define ADSP_DDR_REQ_SEL (0x3 << 4) // hw auto ddren
#define ADSP_DDR_ENABLE (1 << 0)
#define ADSP_SPM_REQ (ADSP_BASE + 0x0048)
#define ADSP_SPM_ACK (ADSP_BASE + 0x004C)
#define ADSP_SPM_SRC_BITS (0xF << 0)
#define ADSP_IRQ_EN (ADSP_BASE + 0x0050)
#define ADSP_A_SPM_WAKEUPSRC (ADSP_BASE + 0x005C)
#define ADSP_WAKEUP_SPM (0x1 << 0)
#define ADSP_SEMAPHORE (ADSP_BASE + 0x0058)
#define ADSP_A_WDT_REG (ADSP_BASE + 0x007C)
#define ADSP_A_WDT_INIT_VALUE (ADSP_BASE + 0x0080)
#define ADSP_A_WDT_CNT (ADSP_BASE + 0x0084)
#define ADSP_WDT_TRIGGER (ADSP_A_WDT_INIT_VALUE)
#define WDT_EN_BIT (1 << 31)
#define WDT_DIS_BIT (0 << 31)
#define WDT_KICK_BIT 0
#define ADSP_CFGREG_RSV_RW_REG0 (ADSP_BASE + 0x008C)
#define ADSP_CFGREG_RSV_RW_REG1 (ADSP_BASE + 0x0090)
#define ADSP_CREG_BOOTUP_MARK ADSP_CFGREG_RSV_RW_REG0
/* Latch Debug info after WDT */
#define ADSP_A_WDT_DEBUG_PC_REG (ADSP_BASE + 0x0170)
#define ADSP_A_WDT_DEBUG_SP_REG (ADSP_BASE + 0x0174)
/* TODO : add in aee dump */
#define ADSP_A_WDT_EXCVADDR_REG (ADSP_BASE + 0x0178)
/* TODO : add in aee dump */
#define ADSP_A_WDT_EXCCAUSE_REG (ADSP_BASE + 0x017C)
/* Wakeup ADSP interrupt */
#define ADSP_WAKEUPSRC_MASK (ADSP_BASE + 0x00A8)
#define ADSP_WAKEUPSRC_IRQ (ADSP_BASE + 0x00AC)
/*latency monitor*/
#define ADSP_LATMON_DVFS_MODE (ADSP_BASE + 0x0100)
#define ADSP_LATMON_CON1 (ADSP_BASE + 0x0104)
#define ADSP_LATMON_CON2 (ADSP_BASE + 0x0108)
#define ADSP_LATMON_MARGIN (ADSP_BASE + 0x010C)
#define ADSP_LATMON_THRESHOLD (ADSP_BASE + 0x0110)
#define ADSP_LATMON_STATE (ADSP_BASE + 0x0114)
#define ADSP_LATMON_ACCCNT (ADSP_BASE + 0x0118)
/* latency threshold & budget for 0.8V. 0.7V. 0.625V */
#define ADSP_LATMON_CONT0 (ADSP_BASE + 0x012C)
#define ADSP_LATMON_CONT1 (ADSP_BASE + 0x0130)
#define ADSP_LATMON_CONT2 (ADSP_BASE + 0x0134)
#define ADSP_A_DEBUG_PC_REG (ADSP_BASE + 0x013C)
#define ADSP_DBG_PEND_CNT (ADSP_BASE + 0x015C)
#define ADSP_SLEEP_STATUS_REG (ADSP_BASE + 0x0158)
#define ADSP_BUS_MON_BASE (ADSP_BASE + 0x5000)
#define ADSP_A_IS_WFI (1 << 0)
#define ADSP_AXI_BUS_IS_IDLE (1 << 1)
/* clk reg */
#define ADSP_CLK_CTRL_BASE (ADSP_BASE + 0x1000)
#define ADSP_CLK_UART_EN (1 << 5)
#define ADSP_CLK_DMA_EN (1 << 4)
#define ADSP_CLK_TIMER_EN (1 << 3)
#define ADSP_CLK_CORE_0_EN (1 << 0)
#define ADSP_UART_CTRL (ADSP_BASE + 0x1010)
#define ADSP_UART_RST_N (1 << 3)
#define ADSP_UART_CLK_SEL (1 << 1)
#define ADSP_UART_BCLK_CG (1 << 0)
/* INFRA_IRQ (always on register) */
#define INFRA_AXI_PROT (INFRACFG_AO_BASE + 0x0220)
#define INFRA_AXI_PROT_STA1 (INFRACFG_AO_BASE + 0x0228)
#define INFRA_AXI_PROT_SET (INFRACFG_AO_BASE + 0x02A0)
#define INFRA_AXI_PROT_CLR (INFRACFG_AO_BASE + 0x02A4)
#define ADSP_AXI_PROT_MASK (0x1 << 15)
#define ADSP_AXI_PROT_READY_MASK (0x1 << 15)
#define ADSP_WAY_EN_CTRL (INFRACFG_AO_BASE + 0x0240)
#define ADSP_WAY_EN_MASK (0x1 << 13)
#define AP_AWAKE_LOCK_BIT (0)
#define AP_AWAKE_UNLOCK_BIT (1)
#define CONNSYS_AWAKE_LOCK (2)
#define CONNSYS_AWAKE_UNLOCK (3)
#define AP_AWAKE_DUMP_BIT (4)
#define AP_AWAKE_UPDATE_BIT (5)
#define AP_AWAKE_STATE_BIT (6)
#define ADSPPLL_UNLOCK_BIT (8)
#define ADSP_ADSP2SPM_VOL_LV (ADSP_BASE + 0x0094)
#endif
@@ -0,0 +1,197 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#include <linux/io.h>
#ifdef CONFIG_OF_RESERVED_MEM
#include <linux/of.h>
#include <linux/of_reserved_mem.h>
#endif
#include "adsp_reserved_mem.h"
#include "adsp_feature_define.h"
#include "adsp_platform.h"
#include "adsp_core.h"
#if ADSP_EMI_PROTECTION_ENABLE
#include <mt_emi_api.h>
#endif
#define ADSP_RESERVE_MEMORY_BLOCK(xname) \
{.phys_addr = 0x0, .virt_addr = NULL, \
.size = 0, .name = xname}
static struct adsp_reserve_mblock adsp_reserve_mem = {0};
static struct adsp_reserve_mblock adsp_reserve_mblocks[] = {
[ADSP_A_IPI_DMA_MEM_ID]
= ADSP_RESERVE_MEMORY_BLOCK("adsp-rsv-ipidma-a"),
[ADSP_A_LOGGER_MEM_ID]
= ADSP_RESERVE_MEMORY_BLOCK("adsp-rsv-logger-a"),
[ADSP_A_DEBUG_DUMP_MEM_ID]
= ADSP_RESERVE_MEMORY_BLOCK("adsp-rsv-dbg-dump-a"),
[ADSP_A_CORE_DUMP_MEM_ID]
= ADSP_RESERVE_MEMORY_BLOCK("adsp-rsv-core-dump-a"),
#ifndef CONFIG_FPGA_EARLY_PORTING
[ADSP_AUDIO_COMMON_MEM_ID]
= ADSP_RESERVE_MEMORY_BLOCK("adsp-rsv-audio"),
#endif
};
static struct adsp_reserve_mblock *adsp_get_reserve_mblock(
enum adsp_reserve_mem_id_t id)
{
void *va_start = adsp_reserve_mblocks[0].virt_addr;
if (id >= ADSP_NUMS_MEM_ID) {
pr_info("%s no reserve memory for %d\n", __func__, id);
return NULL;
}
if (!va_start) {
pr_info("%s va_start is NULL\n", __func__);
return NULL;
}
return &adsp_reserve_mblocks[id];
}
phys_addr_t adsp_get_reserve_mem_phys(enum adsp_reserve_mem_id_t id)
{
struct adsp_reserve_mblock *mblk = adsp_get_reserve_mblock(id);
return mblk ? mblk->phys_addr : 0;
}
void *adsp_get_reserve_mem_virt(enum adsp_reserve_mem_id_t id)
{
struct adsp_reserve_mblock *mblk = adsp_get_reserve_mblock(id);
return mblk ? mblk->virt_addr : NULL;
}
size_t adsp_get_reserve_mem_size(enum adsp_reserve_mem_id_t id)
{
struct adsp_reserve_mblock *mblk = adsp_get_reserve_mblock(id);
return mblk ? mblk->size : 0;
}
void adsp_set_emimpu_shared_region(void)
{
#if ADSP_EMI_PROTECTION_ENABLE
struct adsp_reserve_mblock *mem = &adsp_reserve_mem;
struct emi_region_info_t region_info;
region_info.start = mem->phys_addr;
region_info.end = mem->phys_addr + mem->size - 0x1;
region_info.region = MPU_PROCT_REGION_ADSP_SHARED;
SET_ACCESS_PERMISSION(region_info.apc, UNLOCK,
FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
FORBIDDEN, NO_PROTECTION, FORBIDDEN, FORBIDDEN,
FORBIDDEN, FORBIDDEN, FORBIDDEN, FORBIDDEN,
FORBIDDEN, FORBIDDEN, FORBIDDEN, NO_PROTECTION);
emi_mpu_set_protection(&region_info);
#endif
}
int adsp_mem_device_probe(struct platform_device *pdev)
{
int ret = 0;
int i = 0;
uint32_t size = 0;
struct device *dev = &pdev->dev;
for (i = 0; i < ADSP_NUMS_MEM_ID; i++) {
ret = of_property_read_u32(dev->of_node,
adsp_reserve_mblocks[i].name, &size);
if (!ret)
adsp_reserve_mblocks[i].size = (size_t)size;
}
return 0;
}
void adsp_init_reserve_memory(void)
{
enum adsp_reserve_mem_id_t id;
struct adsp_reserve_mblock *mem = &adsp_reserve_mem;
size_t acc_size = 0;
if (!mem->phys_addr || !mem->size) {
pr_info("%s() reserve memory illegal addr:%llx, size:%zx\n",
__func__, mem->phys_addr, mem->size);
return;
}
mem->virt_addr = ioremap_wc(mem->phys_addr, mem->size);
if (!mem->virt_addr) {
pr_info("%s() ioremap fail\n", __func__);
return;
}
/* assign to each memory block */
for (id = 0; id < ADSP_NUMS_MEM_ID; id++) {
adsp_reserve_mblocks[id].phys_addr = mem->phys_addr + acc_size;
adsp_reserve_mblocks[id].virt_addr = mem->virt_addr + acc_size;
acc_size += ALIGN(adsp_reserve_mblocks[id].size, RSV_BLOCK_ALIGN);
#ifdef MEM_DEBUG
pr_info("adsp_reserve_mblocks[%d] phys_addr:%llx, size:0x%zx\n",
id,
adsp_reserve_mblocks[id].phys_addr,
adsp_reserve_mblocks[id].size);
#endif
}
WARN_ON(acc_size > mem->size);
}
ssize_t adsp_reserve_memory_dump(char *buffer, int size)
{
int n = 0, i = 0;
struct adsp_reserve_mblock *mem = &adsp_reserve_mem;
n += scnprintf(buffer + n, size - n,
"Reserve-memory-all:0x%llx 0x%p 0x%zx\n",
mem->phys_addr, mem->virt_addr, mem->size);
for (i = 0; i < ADSP_NUMS_MEM_ID; i++) {
mem = &adsp_reserve_mblocks[i];
n += scnprintf(buffer + n, size - n,
"Reserve-memory-Block[%02d]:0x%llx 0x%p 0x%zx\n",
i, mem->phys_addr, mem->virt_addr, mem->size);
}
return n;
}
#ifdef CONFIG_OF_RESERVED_MEM
#define ADSP_MEM_RESERVED_KEY "mediatek,reserve-memory-adsp_share"
static int __init adsp_reserve_mem_of_init(struct reserved_mem *rmem)
{
adsp_reserve_mem.phys_addr = (phys_addr_t) rmem->base;
adsp_reserve_mem.size = (size_t) rmem->size;
return 0;
}
RESERVEDMEM_OF_DECLARE(adsp_reserve_mem_init,
ADSP_MEM_RESERVED_KEY, adsp_reserve_mem_of_init);
#endif /* defined(CONFIG_OF_RESERVED_MEM) */
void adsp_update_mpu_memory_info(struct adsp_priv *pdata)
{
struct adsp_mpu_info_t mpu_info;
memset(&mpu_info, 0, sizeof(struct adsp_mpu_info_t));
adsp_copy_from_sharedmem(pdata, ADSP_SHAREDMEM_MPUINFO,
&mpu_info, sizeof(struct adsp_mpu_info_t));
mpu_info.share_dram_addr = (u32)adsp_reserve_mem.phys_addr;
mpu_info.share_dram_size = (u32)adsp_reserve_mem.size;
pr_info("[ADSP] mpu info=(0x%x, 0x%x)\n",
mpu_info.share_dram_addr, mpu_info.share_dram_size);
adsp_copy_to_sharedmem(pdata, ADSP_SHAREDMEM_MPUINFO,
&mpu_info, sizeof(struct adsp_mpu_info_t));
}
@@ -0,0 +1,62 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __ADSP_RESERVEDMEM_DEFINE_H__
#define __ADSP_RESERVEDMEM_DEFINE_H__
#include <linux/platform_device.h>
//#define MEM_DEBUG
/* emi mpu define */
#define MPU_PROCT_REGION_ADSP_SHARED 30
#define MPU_PROCT_D0_AP 0
#define MPU_PROCT_D10_ADSP 10
/* adsp mpu alignment = 4KB */
#define RSV_BLOCK_ALIGN 0x1000
/* adsp reserve memory ID definition*/
enum adsp_reserve_mem_id_t {
ADSP_A_IPI_DMA_MEM_ID = 0,
ADSP_A_LOGGER_MEM_ID,
ADSP_A_DEBUG_DUMP_MEM_ID,
ADSP_A_CORE_DUMP_MEM_ID,
#ifndef CONFIG_FPGA_EARLY_PORTING
ADSP_AUDIO_COMMON_MEM_ID,
#endif
ADSP_NUMS_MEM_ID,
};
struct adsp_reserve_mblock {
phys_addr_t phys_addr;
void *virt_addr;
size_t size;
char *name;
};
struct adsp_mpu_info_t {
u32 prog_addr;
u32 prog_size;
u32 data_addr;
u32 data_size;
u32 share_dram_addr;
u32 share_dram_size;
};
struct adsp_priv;
/* Reserved Memory Method */
phys_addr_t adsp_get_reserve_mem_phys(enum adsp_reserve_mem_id_t id);
void *adsp_get_reserve_mem_virt(enum adsp_reserve_mem_id_t id);
size_t adsp_get_reserve_mem_size(enum adsp_reserve_mem_id_t id);
int adsp_mem_device_probe(struct platform_device *pdev);
void adsp_init_reserve_memory(void);
ssize_t adsp_reserve_memory_dump(char *buffer, int size);
void adsp_set_emimpu_shared_region(void);
void adsp_update_mpu_memory_info(struct adsp_priv *pdata);
#endif /* __ADSP_RESERVEDMEM_DEFINE_H__ */
@@ -0,0 +1,22 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __ADSP_SERVICE_H__
#define __ADSP_SERVICE_H__
#include <linux/notifier.h>
#include <linux/interrupt.h>
#include "adsp_reg.h"
#include "adsp_feature_define.h"
#include "adsp_ipi.h"
void adsp_read_status_release(const unsigned long dsp_event);
void reset_hal_feature_table(void);
long adsp_driver_ioctl(
struct file *file, unsigned int cmd, unsigned long arg);
long adsp_driver_compat_ioctl(
struct file *file, unsigned int cmd, unsigned long arg);
#endif
@@ -0,0 +1,25 @@
# SPDX-License-Identifier: GPL-2.0
ADSP_VERSION := common_v2
ADSP_VERSION_PATH := ../$(ADSP_VERSION)
obj-y += $(ADSP_VERSION_PATH)/
obj-y += adsp_awake.o
#obj-y += adsp_dvfs.o
#obj-y += adsp_plat.o
obj-y += adsp_clk.o
#obj-y += adsp_bus_monitor.o
obj-y += adsp_reserved_mem.o
obj-y += adsp_platform_driver.o adsp_platform.o
obj-y += adsp_mbox.o
obj-y += adsp_excep.o
ccflags-y += -I$(srctree)/drivers/misc/mediatek/adsp/common_v2
ccflags-y += -I$(srctree)/drivers/misc/mediatek/audio_ipi/common_v2/framework
ccflags-y += -I$(srctree)/drivers/misc/mediatek/include/mt-plat/$(CONFIG_MTK_PLATFORM)/include/mach
ccflags-y += -I$(srctree)/drivers/misc/mediatek/base/power/include
ccflags-y += -I$(srctree)/sound/soc/mediatek/$(CONFIG_MTK_PLATFORM)
ifeq ($(CONFIG_MTK_ENG_BUILD),y)
CFLAGS_adsp_excep.o += -DDEBUG
endif
@@ -0,0 +1,132 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#include <linux/io.h>
#include <linux/mutex.h>
#include <linux/ktime.h>
#include "adsp_core.h"
#include "adsp_platform.h"
#include "adsp_platform_driver.h"
#include "adsp_reg.h"
#ifdef ADSP_BASE
#undef ADSP_BASE
#endif
#define ADSP_BASE (pdata->cfg)
#define AP_AWAKE_LOCK_MASK (0x1 << AP_AWAKE_LOCK_BIT)
#define AP_AWAKE_UNLOCK_MASK (0x1 << AP_AWAKE_UNLOCK_BIT)
struct adsp_sysevent_ctrl {
struct adsp_priv *pdata;
struct mutex lock;
void __iomem *swint;
u32 mask;
};
static struct adsp_sysevent_ctrl sysevent_ctrls[ADSP_CORE_TOTAL];
static int adsp_send_sys_event(struct adsp_sysevent_ctrl *ctrl,
u32 event, bool wait)
{
ktime_t start_time;
s64 time_ipc_us;
if (mutex_trylock(&ctrl->lock) == 0) {
pr_info("%s(), mutex_trylock busy", __func__);
return ADSP_IPI_BUSY;
}
if (readl(ctrl->swint) & ctrl->mask) {
mutex_unlock(&ctrl->lock);
return ADSP_IPI_BUSY;
}
adsp_copy_to_sharedmem(ctrl->pdata, ADSP_SHAREDMEM_WAKELOCK,
&event, sizeof(event));
writel(ctrl->mask, ctrl->swint);
if (wait) {
start_time = ktime_get();
while (readl(ctrl->swint) & ctrl->mask) {
time_ipc_us = ktime_us_delta(ktime_get(), start_time);
if (time_ipc_us > 1000) /* 1 ms */
break;
}
}
mutex_unlock(&ctrl->lock);
return ADSP_IPI_DONE;
}
int adsp_awake_init(struct adsp_priv *pdata, u32 mask)
{
struct adsp_sysevent_ctrl *ctrl;
if (!pdata)
return -EINVAL;
ctrl = &sysevent_ctrls[pdata->id];
ctrl->pdata = pdata;
ctrl->swint = ADSP_SW_INT_SET;
ctrl->mask = mask;
mutex_init(&ctrl->lock);
return 0;
}
/*
* acquire adsp lock flag, keep adsp awake
* @param adsp_id: adsp core id
* return 0 : get lock success
* non-0 : get lock fail
*/
int adsp_awake_lock(u32 cid)
{
int ret = -1;
uint32_t val = 0;
if (cid >= ADSP_CORE_TOTAL)
return -EINVAL;
if (!is_adsp_ready(cid) || !adsp_feature_is_active(cid))
return -ENODEV;
val = AP_AWAKE_LOCK_MASK;
ret = adsp_send_sys_event(&sysevent_ctrls[cid], val, true);
if (ret)
pr_info("%s, lock fail", __func__);
return ret;
}
/*
* release adsp awake lock flag
* @param adsp_id: adsp core id
* return 0 : release lock success
* non-0 : release lock fail
*/
int adsp_awake_unlock(u32 cid)
{
int ret = -1;
uint32_t val = 0;
if (cid >= ADSP_CORE_TOTAL)
return -EINVAL;
if (!is_adsp_ready(cid) || !adsp_feature_is_active(cid))
return -ENODEV;
val = AP_AWAKE_UNLOCK_MASK;
ret = adsp_send_sys_event(&sysevent_ctrls[cid], val, true);
if (ret)
pr_info("%s, unlock fail", __func__);
return ret;
}
@@ -0,0 +1,73 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#include <linux/io.h>
#include "adsp_helper.h"
#include "adsp_bus_monitor.h"
/**
* TIMEOUT_VALUE = value * unit(15 cycle count) / clk_src
*/
#define BUS_MON_STAGE1_TIMEOUT_VALUE (0x01DA0A2B) /* 1.00 sec @ 466MHz */
#define BUS_MON_STAGE2_TIMEOUT_VALUE (0x03B41456) /* 2.00 sec @ 466MHz */
#define ADSP_BUS_MON_STATE (ADSP_BUS_MON_BACKUP_BASE)
#define ADSP_BUS_MON_1ST_STAGE_BASE (ADSP_BUS_MON_BACKUP_BASE + sizeof(u32))
#define ADSP_BUS_MON_2ND_STAGE_BASE (ADSP_BUS_MON_1ST_STAGE_BASE + \
sizeof(struct bus_monitor_cblk))
#define ADSP_BUS_MON_BACKUP_SIZE (sizeof(u32) + \
2 * sizeof(struct bus_monitor_cblk))
int adsp_bus_monitor_init(void)
{
/* Clear bus monitor register backup in DTCM */
memset_io((void *)ADSP_BUS_MON_BACKUP_BASE, 0,
(size_t)ADSP_BUS_MON_BACKUP_SIZE);
/* initialize bus monitor */
writel(BUS_MON_STAGE1_TIMEOUT_VALUE, ADSP_BUS_DBG_TIMER_CON0);
writel(BUS_MON_STAGE2_TIMEOUT_VALUE, ADSP_BUS_DBG_TIMER_CON1);
writel(0x0, ADSP_BUS_DBG_WP);
writel(0x0, ADSP_BUS_DBG_WP_MASK);
writel(0x00002037, ADSP_BUS_DBG_CON); /* timeout control */
writel(STAGE_RUN, ADSP_BUS_MON_STATE);
return 0;
}
bool is_adsp_bus_monitor_alert(void)
{
return readl(ADSP_BUS_MON_STATE) > STAGE_RUN;
}
static void adsp_bus_monitor_stage_info(void *addr)
{
int i = 0;
struct bus_monitor_cblk cblk;
memcpy_fromio(&cblk, addr, sizeof(struct bus_monitor_cblk));
pr_info("BUS_DBG_CON = 0x%08x", cblk.ctrl);
pr_info("TIMER_CON0 = 0x%08x, TIMER_CON01 = 0x%08x",
cblk.timer_ctrl[0], cblk.timer_ctrl[1]);
for (i = 0; i < 8; i++) {
if (!cblk.r_tracks[i] && !cblk.w_tracks[i])
continue;
pr_info("R_TRACK[%d] = 0x%08x, W_TRACK[%d] = 0x%08x",
i, cblk.r_tracks[i],
i, cblk.w_tracks[i]);
}
}
void adsp_bus_monitor_dump(void)
{
pr_info("%s(), BUS_MON_1ST_STAGE BACKUP", __func__);
adsp_bus_monitor_stage_info((void *)ADSP_BUS_MON_1ST_STAGE_BASE);
pr_info("%s(), BUS_MON_2ST_STAGE BACKUP", __func__);
adsp_bus_monitor_stage_info((void *)ADSP_BUS_MON_2ND_STAGE_BASE);
}
@@ -0,0 +1,44 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __ADSP_BUS_MONITOR_H__
#define __ADSP_BUS_MONITOR_H__
#include "adsp_reg.h"
/* bus monitor registers */
#define ADSP_BUS_DBG_CON (ADSP_BUS_MON_BASE + 0x0000)
#define ADSP_BUS_DBG_TIMER_CON0 (ADSP_BUS_MON_BASE + 0x0004)
#define ADSP_BUS_DBG_TIMER_CON1 (ADSP_BUS_MON_BASE + 0x0008)
#define ADSP_BUS_DBG_TIMER0 (ADSP_BUS_MON_BASE + 0x000C)
#define ADSP_BUS_DBG_TIMER1 (ADSP_BUS_MON_BASE + 0x0010)
#define ADSP_BUS_DBG_WP (ADSP_BUS_MON_BASE + 0x0014)
#define ADSP_BUS_DBG_WP_MASK (ADSP_BUS_MON_BASE + 0x0018)
/* bus monitor enum */
enum bus_monitor_stage {
STAGE_OFF = 0,
STAGE_RUN = 1,
STAGE_1ST = 2,
STAGE_2ND = 3,
};
/* bus monitor structure */
struct bus_monitor_cblk { /* hw related */
u32 ctrl;
u32 timer_ctrl[2];
u32 timer_dbg[2];
u32 watch_point_addr;
u32 watch_point_mask;
u32 r_tracks[8]; /* read tracker 8 channel in hw */
u32 w_tracks[8]; /* write tracker 8 channel in hw */
};
/* bus monitor methods, be care all of them need adsp clk on */
int adsp_bus_monitor_init(void);
bool is_adsp_bus_monitor_alert(void);
void adsp_bus_monitor_dump(void);
#endif
@@ -0,0 +1,135 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#include "adsp_clk.h"
#include <linux/clk.h>
static uint32_t adsp_clock_count;
struct adsp_clock_attr {
const char *name;
struct clk *clock;
};
static struct adsp_clock_attr adsp_clks[ADSP_CLK_NUM] = {
[CLK_SCP_SYS_ADSP] = {"scp_sys_adsp", NULL},
[CLK_ADSP_CK_CG] = {"clk_adsp_ck_cg", NULL},
[CLK_TOP_ADSP_SEL] = {"clk_top_adsp_sel", NULL},
[CLK_TOP_CLK26M] = {"clk_top_clk26m", NULL},
[CLK_TOP_ADSPPLL] = {"clk_top_adsppll", NULL},
};
static struct adsp_clock_attr scp_clks[SCP_CLK_NUM] = {
[CLK_TOP_SCP_SEL] = {"clk_top_scp_sel", NULL},
};
int adsp_set_top_mux(enum adsp_clk clk)
{
int ret = 0;
pr_debug("%s(%x)\n", __func__, clk);
if (clk >= ADSP_CLK_NUM || clk < 0)
return -EINVAL;
ret = clk_set_parent(adsp_clks[CLK_TOP_ADSP_SEL].clock,
adsp_clks[clk].clock);
if (IS_ERR(&ret))
pr_err("[ADSP] %s clk_set_parent(clk_top_adsp_sel-%x) fail %d\n",
__func__, clk, ret);
return ret;
}
void adsp_set_clock_freq(enum adsp_clk clk)
{
switch (clk) {
case CLK_TOP_CLK26M:
case CLK_TOP_ADSPPLL:
adsp_set_top_mux(clk);
break;
default:
break;
}
}
/* clock init */
int adsp_clk_device_probe(struct platform_device *pdev)
{
int ret = 0;
size_t i;
struct device *dev = &pdev->dev;
for (i = 0; i < ARRAY_SIZE(adsp_clks); i++) {
adsp_clks[i].clock = devm_clk_get(dev, adsp_clks[i].name);
if (IS_ERR(adsp_clks[i].clock)) {
ret = PTR_ERR(adsp_clks[i].clock);
pr_err("%s devm_clk_get %s fail %d\n", __func__,
adsp_clks[i].name, ret);
}
}
for (i = 0; i < ARRAY_SIZE(scp_clks); i++) {
scp_clks[i].clock = devm_clk_get(dev, scp_clks[i].name);
if (IS_ERR(scp_clks[i].clock)) {
ret = PTR_ERR(scp_clks[i].clock);
pr_info("%s devm_clk_get %s fail %d\n", __func__,
scp_clks[i].name, ret);
}
}
return ret;
}
/* clock deinit */
void adsp_clk_device_remove(void *dev)
{
pr_info("%s\n", __func__);
}
int adsp_enable_clock(void)
{
int ret = 0;
pr_debug("%s()\n", __func__);
/* enable scp clock before access adsp clock cg */
ret = clk_prepare_enable(scp_clks[CLK_TOP_SCP_SEL].clock);
if (IS_ERR(&ret)) {
pr_info("%s(), clk_prepare_enable %s fail, ret %d\n",
__func__, scp_clks[CLK_TOP_SCP_SEL].name, ret);
return -EINVAL;
}
ret = clk_prepare_enable(adsp_clks[CLK_SCP_SYS_ADSP].clock);
if (IS_ERR(&ret)) {
pr_info("%s(), clk_prepare_enable %s fail, ret %d\n",
__func__, adsp_clks[CLK_SCP_SYS_ADSP].name, ret);
return -EINVAL;
}
ret = clk_prepare_enable(adsp_clks[CLK_ADSP_CK_CG].clock);
if (IS_ERR(&ret)) {
pr_err("%s(), clk_prepare_enable %s fail, ret %d\n",
__func__, adsp_clks[CLK_ADSP_CK_CG].name, ret);
clk_disable_unprepare(adsp_clks[CLK_SCP_SYS_ADSP].clock);
return -EINVAL;
}
adsp_clock_count++;
return 0;
}
void adsp_disable_clock(void)
{
pr_debug("%s()\n", __func__);
adsp_clock_count--;
clk_disable_unprepare(adsp_clks[CLK_ADSP_CK_CG].clock);
clk_disable_unprepare(adsp_clks[CLK_SCP_SYS_ADSP].clock);
clk_disable_unprepare(scp_clks[CLK_TOP_SCP_SEL].clock);
}
@@ -0,0 +1,35 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef ADSP_CLK_H
#define ADSP_CLK_H
#include <linux/platform_device.h>
#define CLK_DEFAULT_INIT_CK CLK_TOP_ADSPPLL
#define CLK_DEFAULT_26M_CK CLK_TOP_CLK26M
enum adsp_clk {
CLK_SCP_SYS_ADSP,
CLK_ADSP_CK_CG,
CLK_TOP_ADSP_SEL,
CLK_TOP_CLK26M,
CLK_TOP_ADSPPLL,
ADSP_CLK_NUM
};
enum scp_clk {
CLK_TOP_SCP_SEL,
SCP_CLK_NUM
};
void adsp_set_clock_freq(enum adsp_clk clk);
int adsp_set_top_mux(enum adsp_clk clk);
int adsp_enable_clock(void);
void adsp_disable_clock(void);
int adsp_clk_device_probe(struct platform_device *pdev);
void adsp_clk_device_remove(void *dev);
#endif /* ADSP_CLK_H */
@@ -0,0 +1,723 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/slab.h>
#include <linux/proc_fs.h>
#include <linux/miscdevice.h>
#include <linux/platform_device.h>
#include <linux/spinlock.h>
#include <linux/kthread.h>
#include <linux/hrtimer.h>
#include <linux/ktime.h>
#include <linux/jiffies.h>
#include <linux/fs.h>
#include <linux/seq_file.h>
#include <linux/input.h>
#ifdef wakelock
#include <linux/wakelock.h>
#endif
#include <linux/io.h>
//#include <mt-plat/upmu_common.h>
#include <mt-plat/mtk_secure_api.h>
#ifdef CONFIG_OF
#include <linux/of.h>
#include <linux/of_address.h>
#endif
#ifdef CONFIG_MTK_AEE_FEATURE
#include <mt-plat/aee.h>
#endif
#include <linux/uaccess.h>
#include "adsp_ipi.h"
#include <adsp_ipi_queue.h>
#include <audio_ipi_platform.h>
#include "adsp_helper.h"
#include "adsp_excep.h"
#include "adsp_dvfs.h"
#include "adsp_clk.h"
#include "adsp_reg.h"
#ifdef CONFIG_MTK_CLKMGR
#include <mach/mt_clkmgr.h>
#else
#include <linux/clk.h>
#endif
#ifdef pr_fmt
#undef pr_fmt
#endif
#define pr_fmt(fmt) "[adsp_dvfs]: " fmt
#define ADSP_DBG(fmt, arg...) pr_debug(fmt, ##arg)
#define ADSP_INFO(fmt, arg...) pr_info(fmt, ##arg)
#define DRV_Reg32(addr) readl(addr)
#define DRV_WriteReg32(addr, val) writel(val, addr)
#define DRV_SetReg32(addr, val) DRV_WriteReg32(addr, DRV_Reg32(addr) | (val))
#define DRV_ClrReg32(addr, val) DRV_WriteReg32(addr, DRV_Reg32(addr) & ~(val))
/* new implement for adsp */
static DEFINE_MUTEX(adsp_timer_mutex);
DEFINE_MUTEX(adsp_suspend_mutex);
static struct timer_list adsp_suspend_timer;
static struct adsp_work_t adsp_suspend_work;
struct completion adsp_suspend_cp;
struct completion adsp_resume_cp;
int adsp_is_suspend;
static int adsp_is_force_freq;
static int adsp_is_force_trigger_latmon;
#define ADSP_DELAY_OFF_TIMEOUT (1 * HZ) /* 1 second */
#define ADSP_DELAY_TIMER (0)
#define FORCE_ADSPPLL_BASE (0x10000000)
#define SPM_REQ_BASE (0x20000000)
#define ADSPPLL_ON_BASE (0x30000000)
#define ADD_FREQ_CMD (0x11110000)
#define DEL_FREQ_CMD (0x22220000)
#define QUERY_FREQ_CMD (0xFFFFFFFF)
#define ADSP_FREQ_MAX_VALUE (630) /* 0.725V 70MCPS for sys */
#define TRIGGER_LATMON_IRQ_CMD (0x00010000)
/* Private Macro ---------------------------------------------------------*/
/* The register must sync with ctrl-boards.S in Tinysys */
/* if equal, bypass clear bss and some init */
#define MAGIC_PATTERN (0xfafafafa)
static inline ssize_t adsp_force_adsppll_store(struct device *kobj,
struct device_attribute *attr,
const char *buf, size_t count)
{
uint32_t value = 0, param = 0;
enum adsp_ipi_status ret;
if (kstrtoint(buf, 10, &value))
return -EINVAL;
switch (value) {
case 480:
param = FORCE_ADSPPLL_BASE+0x01E0;
break;
case 694:
param = FORCE_ADSPPLL_BASE+0x02B6;
break;
case 800:
param = FORCE_ADSPPLL_BASE+0x0320;
break;
default:
break;
}
pr_debug("[%s]force in %d(%x)\n", __func__, value, param);
if (is_adsp_ready(ADSP_A_ID) == 1) {
ret = adsp_ipi_send(ADSP_IPI_DVFS_SLEEP, &param,
sizeof(param), 0, ADSP_A_ID);
}
return count;
}
static inline ssize_t adsp_spm_req_store(struct device *kobj,
struct device_attribute *attr,
const char *buf, size_t count)
{
uint32_t value = 0, param;
enum adsp_ipi_status ret;
if (kstrtoint(buf, 10, &value))
return -EINVAL;
param = SPM_REQ_BASE + value;
pr_debug("[%s]set SPM req in %d(%x)\n", __func__, value, param);
if (is_adsp_ready(ADSP_A_ID) == 1) {
ret = adsp_ipi_send(ADSP_IPI_DVFS_SLEEP, &param,
sizeof(param), 0, ADSP_A_ID);
}
return count;
}
static inline ssize_t adsp_keep_adsppll_on_store(struct device *kobj,
struct device_attribute *attr,
const char *buf, size_t count)
{
uint32_t value = 0, param;
enum adsp_ipi_status ret;
if (kstrtoint(buf, 10, &value))
return -EINVAL;
param = ADSPPLL_ON_BASE + value;
pr_debug("[%s] %d(%x)\n", __func__, value, param);
if (is_adsp_ready(ADSP_A_ID) == 1) {
ret = adsp_ipi_send(ADSP_IPI_DVFS_SLEEP, &param,
sizeof(param), 0, ADSP_A_ID);
}
return count;
}
static inline ssize_t adsp_dvfs_force_opp_show(struct device *kobj,
struct device_attribute *attr,
char *buf)
{
return scnprintf(buf, PAGE_SIZE, "force freq status = %d\n",
adsp_is_force_freq);
}
static inline ssize_t adsp_dvfs_force_opp_store(struct device *kobj,
struct device_attribute *attr,
const char *buf, size_t count)
{
unsigned int value = 0;
enum adsp_ipi_status ret = ADSP_IPI_ERROR;
if (kstrtoint(buf, 10, &value))
return -EINVAL;
if (is_adsp_ready(ADSP_A_ID) == 1) {
if (value == 255) {
/* release force freq mode */
adsp_is_force_freq = 0;
ret = adsp_ipi_send(ADSP_IPI_DVFS_FIX_OPP_SET, &value,
sizeof(value), 0, ADSP_A_ID);
} else if (value == 0 || value == 1) {
/* force adsp freq at specific value */
adsp_is_force_freq = 1;
ret = adsp_ipi_send(ADSP_IPI_DVFS_FIX_OPP_SET, &value,
sizeof(value), 0, ADSP_A_ID);
}
}
return count;
}
static inline ssize_t adsp_dvfs_set_freq_show(struct device *kobj,
struct device_attribute *attr,
char *buf)
{
unsigned int value = QUERY_FREQ_CMD;
enum adsp_ipi_status ret;
ret = adsp_ipi_send(ADSP_IPI_DVFS_SET_FREQ, &value,
sizeof(value), 0, ADSP_A_ID);
/* FIXME: ToDo, get MCPS and freq result from ADSP */
return scnprintf(buf, PAGE_SIZE, "Running on level %d, Total MCPS=%d\n",
0xFF, 0xFF);
}
static inline ssize_t adsp_dvfs_set_freq_store(struct device *kobj,
struct device_attribute *attr,
const char *buf, size_t count)
{
char *temp = NULL, *token1 = NULL, *token2 = NULL;
char *pin = NULL;
char delim[] = " ,";
unsigned int value = 0;
enum adsp_ipi_status ret;
temp = kstrdup(buf, GFP_KERNEL);
pin = temp;
token1 = strsep(&pin, delim);
token2 = strsep(&pin, delim);
if (kstrtoint(token2, 10, &value))
return -EINVAL;
if (value >= ADSP_FREQ_MAX_VALUE)
return -EINVAL;
if (strcmp(token1, "add") == 0)
value |= ADD_FREQ_CMD;
if (strcmp(token1, "del") == 0)
value |= DEL_FREQ_CMD;
ret = adsp_ipi_send(ADSP_IPI_DVFS_SET_FREQ, &value,
sizeof(value), 0, ADSP_A_ID);
kfree(temp);
return count;
}
static inline ssize_t adsp_dvfs_trigger_latmon_show(struct device *kobj,
struct device_attribute *attr,
char *buf)
{
return scnprintf(buf, PAGE_SIZE, "force trigger latmon irq = %d\n",
adsp_is_force_trigger_latmon);
}
static inline ssize_t adsp_dvfs_trigger_latmon_store(struct device *kobj,
struct device_attribute *attr,
const char *buf, size_t count)
{
unsigned int value = 0;
enum adsp_ipi_status ret = ADSP_IPI_ERROR;
if (kstrtoint(buf, 10, &value))
return -EINVAL;
value |= TRIGGER_LATMON_IRQ_CMD;
if (is_adsp_ready(ADSP_A_ID) == 1) {
if (value == (TRIGGER_LATMON_IRQ_CMD | 0x0)) {
/* release force freq mode */
adsp_is_force_trigger_latmon = 0;
ret = adsp_ipi_send(ADSP_IPI_DVFS_FIX_OPP_SET, &value,
sizeof(value), 0, ADSP_A_ID);
} else if (value == (TRIGGER_LATMON_IRQ_CMD | 0x1)) {
/* force adsp freq at specific value */
adsp_is_force_trigger_latmon = 1;
ret = adsp_ipi_send(ADSP_IPI_DVFS_FIX_OPP_SET, &value,
sizeof(value), 0, ADSP_A_ID);
}
}
return count;
}
DEVICE_ATTR_WO(adsp_force_adsppll);
DEVICE_ATTR_WO(adsp_spm_req);
DEVICE_ATTR_WO(adsp_keep_adsppll_on);
DEVICE_ATTR_RW(adsp_dvfs_force_opp);
DEVICE_ATTR_RW(adsp_dvfs_set_freq);
DEVICE_ATTR_RW(adsp_dvfs_trigger_latmon);
static struct attribute *adsp_dvfs_attrs[] = {
#if ADSP_SLEEP_ENABLE
&dev_attr_adsp_force_adsppll.attr,
&dev_attr_adsp_spm_req.attr,
&dev_attr_adsp_keep_adsppll_on.attr,
#endif
&dev_attr_adsp_dvfs_force_opp.attr,
&dev_attr_adsp_dvfs_set_freq.attr,
&dev_attr_adsp_dvfs_trigger_latmon.attr,
NULL,
};
struct attribute_group adsp_dvfs_attr_group = {
.attrs = adsp_dvfs_attrs,
};
static bool is_adsp_suspend(void)
{
return (readl(ADSP_A_SYS_STATUS) == ADSP_STATUS_SUSPEND)
&& (readl(ADSP_SLEEP_STATUS_REG) & ADSP_A_IS_WFI)
&& (readl(ADSP_SLEEP_STATUS_REG) & ADSP_A_AXI_BUS_IS_IDLE);
}
DEFINE_MUTEX(adsp_sw_reset_mutex);
static DEFINE_SPINLOCK(adsp_sw_reset_spinlock);
void adsp_sw_reset(enum adsp_core_id core_id)
{
unsigned long flags;
uint32_t reg_value, rstn_bits;
if (core_id == ADSP_A_ID)
rstn_bits = (ADSP_A_SW_RSTN | ADSP_A_SW_DBG_RSTN);
else if (core_id == ADSP_B_ID)
rstn_bits = (ADSP_B_SW_RSTN | ADSP_B_SW_DBG_RSTN);
mutex_lock(&adsp_sw_reset_mutex);
spin_lock_irqsave(&adsp_sw_reset_spinlock, flags);
reg_value = readl(ADSP_CFGREG_SW_RSTN);
writel(reg_value | rstn_bits, ADSP_CFGREG_SW_RSTN);
udelay(1);
writel(reg_value, ADSP_CFGREG_SW_RSTN);
spin_unlock_irqrestore(&adsp_sw_reset_spinlock, flags);
mutex_unlock(&adsp_sw_reset_mutex);
}
void adsp_release_runstall(enum adsp_core_id core_id, uint32_t release)
{
uint32_t reg_value;
uint32_t runstall_bit = (core_id == ADSP_A_ID) ?
ADSP_A_RUNSTALL : ADSP_B_RUNSTALL;
reg_value = readl(ADSP_HIFI3_IO_CONFIG);
if (release) {
writel(reg_value & ~(runstall_bit),
ADSP_HIFI3_IO_CONFIG);
} else {
writel(reg_value | runstall_bit,
ADSP_HIFI3_IO_CONFIG);
}
}
void adsp_A_send_spm_request(uint32_t enable)
{
int timeout = 1000;
pr_debug("req spm source & ddr enable(%d)\n", enable);
if (enable) {
/* request infra/26M/apsrc/v18/ ddr resource */
writel(readl(ADSP_A_DDREN_REQ) | ADSP_SPM_SRC_BITS,
ADSP_A_DDREN_REQ);
/* hw auto on/off ddren, disable now due to latency concern */
// writel(ADSP_A_DDR_REQ_SEL, ADSP_A_DDREN_REQ);
/*make sure SPM return ack*/
while (--timeout) {
/* hw auto on/off ddren */
if (readl(ADSP_SPM_ACK) == ADSP_SPM_SRC_BITS)
break;
udelay(10);
if (timeout == 0)
pr_err("[ADSP] timeout: cannot get SPM ack\n");
}
} else {
writel(readl(ADSP_A_DDREN_REQ) & ~(ADSP_SPM_SRC_BITS),
ADSP_A_DDREN_REQ);
/*make sure SPM return ack*/
while (--timeout) {
if (readl(ADSP_SPM_ACK) == 0x0)
break;
udelay(10);
if (timeout == 0)
pr_err("[ADSP] timeout: cannot get SPM ack\n");
}
}
}
static void adsp_delay_off_handler(unsigned long data)
{
if (!adsp_feature_is_active())
queue_work(adsp_workqueue, &adsp_suspend_work.work);
}
void adsp_start_suspend_timer(void)
{
mutex_lock(&adsp_timer_mutex);
adsp_suspend_timer.function = adsp_delay_off_handler;
adsp_suspend_timer.data = (unsigned long)ADSP_DELAY_TIMER;
adsp_suspend_timer.expires =
jiffies + ADSP_DELAY_OFF_TIMEOUT;
if (timer_pending(&adsp_suspend_timer))
pr_debug("adsp_suspend_timer has set\n");
else
add_timer(&adsp_suspend_timer);
mutex_unlock(&adsp_timer_mutex);
}
void adsp_stop_suspend_timer(void)
{
mutex_lock(&adsp_timer_mutex);
if (timer_pending(&adsp_suspend_timer))
del_timer(&adsp_suspend_timer);
mutex_unlock(&adsp_timer_mutex);
}
/*
* callback function for work struct
* @param ws: work struct
*/
static void adsp_suspend_ws(struct work_struct *ws)
{
struct adsp_work_t *sws = container_of(ws, struct adsp_work_t, work);
enum adsp_core_id core_id = sws->id;
mutex_lock(&adsp_feature_mutex);
if (!adsp_feature_is_active())
adsp_suspend(core_id);
mutex_unlock(&adsp_feature_mutex);
}
#if ADSP_ITCM_MONITOR
static unsigned int adsp_itcm_gtable[9216]; //ADSP_A_ITCM_SIZE/4
#endif
#if ADSP_DTCM_MONITOR
static unsigned int adsp_dtcm_gtable[8192]; //ADPS_A_DTCM_SIZE/4
#endif
#if ADSP_CFG_MONITOR
static unsigned int adsp_cfg_gtable[5312];
#endif
void adsp_sram_reset_init(void)
{
#if ADSP_ITCM_MONITOR
memcpy((void *)(ADSP_A_ITCM),
(void *)adsp_itcm_gtable,
(size_t)ADSP_A_ITCM_SIZE);
#endif
#if ADSP_DTCM_MONITOR
memcpy((void *)(ADSP_A_DTCM),
(void *)adsp_dtcm_gtable,
(size_t)(ADSP_A_DTCM_SIZE - ADSP_A_DTCM_SHARE_SIZE));
#endif
}
void adsp_sram_gtable_init(void)
{
#if ADSP_ITCM_MONITOR
memcpy((void *)adsp_itcm_gtable,
(void *)(ADSP_A_ITCM),
(size_t)ADSP_A_ITCM_SIZE);
#endif
#if ADSP_DTCM_MONITOR
memcpy((void *)adsp_dtcm_gtable,
(void *)(ADSP_A_DTCM),
(size_t)ADSP_A_DTCM_SIZE);
#endif
}
void adsp_sram_gtable_backup(void)
{
#if ADSP_DTCM_MONITOR
memcpy((void *)adsp_dtcm_gtable,
(void *)(ADSP_A_DTCM),
(size_t)ADSP_A_DTCM_SIZE);
#endif
#if ADSP_CFG_MONITOR
/* Enable ADSP CLK and UART to avoid bus hang */
clk_cfg = readl(ADSP_CLK_CTRL_BASE);
uart_cfg = readl(ADSP_UART_CTRL);
writel(readl(ADSP_CLK_CTRL_BASE) | ADSP_CLK_UART_EN,
ADSP_CLK_CTRL_BASE);
writel(readl(ADSP_UART_CTRL) | ADSP_UART_RST_N |
ADSP_UART_BCLK_CG, ADSP_UART_CTRL);
memcpy((void *)adsp_cfg_gtable,
(void *)(ADSP_A_CFG),
(size_t)21248);
/* Restore ADSP CLK and UART setting */
writel(clk_cfg, ADSP_CLK_CTRL_BASE);
writel(uart_cfg, ADSP_UART_CTRL);
#endif
}
int adsp_sram_gtable_check(void)
{
int ret = 0;
int i;
int need_assert = 0;
u32 __iomem *s;
#if ADSP_ITCM_MONITOR
ret = memcmp((void *)adsp_itcm_gtable,
(void *)(ADSP_A_ITCM),
(size_t)ADSP_A_ITCM_SIZE);
if (ret) {
pr_notice("[%s]memcmp adsp_itcm_gtable != ITCM, ret %d\n",
__func__, ret);
s = (void *)(ADSP_A_ITCM);
for (i = 0; i < ADSP_A_ITCM_SIZE / 4; i++) {
if (adsp_itcm_gtable[i] != *s) {
pr_notice("[%s]adsp_itcm_gtable[%d](0x%x) != ITCM(0x%x)\n",
__func__, i, adsp_itcm_gtable[i], *s);
*s = adsp_itcm_gtable[i];
}
s++;
}
need_assert = 1;
}
#endif
#if ADSP_DTCM_MONITOR
ret = memcmp((void *)adsp_dtcm_gtable,
(void *)(ADSP_A_DTCM),
(size_t)ADSP_A_DTCM_SIZE - ADSP_A_DTCM_SHARE_SIZE);
if (ret) {
pr_notice("[%s]memcmp adsp_dtcm_gtable != DTCM, ret %d\n",
__func__, ret);
s = (void *)(ADSP_A_DTCM);
for (i = 0;
i < (ADSP_A_DTCM_SIZE - ADSP_A_DTCM_SHARE_SIZE) / 4;
i++) {
if (adsp_dtcm_gtable[i] != *s) {
pr_notice("[%s]adsp_dtcm_gtable[%d](0x%x) != DTCM(0x%x)\n",
__func__, i, adsp_dtcm_gtable[i], *s);
*s = adsp_dtcm_gtable[i];
}
s++;
}
need_assert = 1;
}
#endif
#if ADSP_CFG_MONITOR
ret = memcmp((void *)adsp_cfg_gtable,
(void *)(ADSP_A_CFG),
(size_t)21248);
if (ret) {
pr_notice("[%s]memcmp adsp_cfg_gtable != CFG, ret %d\n",
__func__, ret);
}
#endif
#ifdef CONFIG_MTK_AEE_FEATURE
if (need_assert)
aee_kernel_exception_api(__FILE__,
__LINE__,
DB_OPT_DEFAULT,
"[ADSP]",
"ASSERT: adsp tcm check fail!!");
#endif
return ret;
}
void adsp_suspend_ipi_handler(int id, void *data, unsigned int len)
{
if (!adsp_is_suspend)
complete(&adsp_suspend_cp);
}
int adsp_suspend_init(void)
{
INIT_WORK(&adsp_suspend_work.work, adsp_suspend_ws);
init_timer(&adsp_suspend_timer);
init_completion(&adsp_suspend_cp);
init_completion(&adsp_resume_cp);
adsp_is_suspend = 0;
adsp_sram_gtable_init();
adsp_sram_gtable_backup();
adsp_ipi_registration(ADSP_IPI_DVFS_SUSPEND, adsp_suspend_ipi_handler,
"adsp_suspend_ack");
return 0;
}
/* actually execute suspend flow, which cannot be disabled.
* retry the resume flow after adsp_ready = 0.
*/
void adsp_suspend(enum adsp_core_id core_id)
{
enum adsp_ipi_status ret;
int value = 0;
#if ADSP_DVFS_PROFILE
ktime_t begin, end;
#endif
mutex_lock(&adsp_suspend_mutex);
if ((is_adsp_ready(core_id) == 1) && !adsp_is_suspend) {
#if ADSP_DVFS_PROFILE
begin = ktime_get();
#endif
ret = scp_send_msg_to_queue(AUDIO_OPENDSP_USE_HIFI3_A,
ADSP_IPI_DVFS_SUSPEND,
&value, sizeof(value), 100);
wait_for_completion_timeout(&adsp_suspend_cp,
msecs_to_jiffies(2000));
if (!is_adsp_suspend()) {
pr_warn("[%s]wait adsp suspend timeout\n", __func__);
#ifdef CFG_RECOVERY_SUPPORT
adsp_send_reset_wq(ADSP_RESET_TYPE_AWAKE, core_id);
#else
adsp_aed(EXCEP_KERNEL, core_id);
#endif
} else {
adsp_release_runstall(ADSP_A_ID, false);
adsp_sram_gtable_backup();
adsp_power_on(false);
adsp_is_suspend = 1;
}
adsp_reset_ready(core_id);
#if ADSP_DVFS_PROFILE
end = ktime_get();
pr_debug("[%s]latency = %lld us, ret(%d)\n",
__func__, ktime_us_delta(end, begin), ret);
#endif
}
mutex_unlock(&adsp_suspend_mutex);
}
int adsp_resume(void)
{
int ret = 0;
int tcm_ret = 0;
#if ADSP_DVFS_PROFILE
ktime_t begin, end;
#endif
mutex_lock(&adsp_suspend_mutex);
if ((is_adsp_ready(ADSP_A_ID) == 0) && adsp_is_suspend) {
#if ADSP_DVFS_PROFILE
begin = ktime_get();
#endif
adsp_power_on(true);
tcm_ret = adsp_sram_gtable_check();
writel(MAGIC_PATTERN, ADSP_A_BOOTUP_MARK);
writel(MAGIC_PATTERN, ADSP_B_BOOTUP_MARK);
DRV_ClrReg32(ADSP_A_WDT_REG, WDT_EN_BIT);
adsp_release_runstall(ADSP_A_ID, true);
adsp_release_runstall(ADSP_B_ID, true);
/* busy waiting until adsp is ready */
wait_for_completion_timeout(&adsp_resume_cp,
msecs_to_jiffies(2000));
if (is_adsp_ready(ADSP_A_ID) != 1) {
pr_warn("[%s]wait for adsp ready timeout\n", __func__);
/* something wrong , dump adsp */
#ifdef CFG_RECOVERY_SUPPORT
adsp_send_reset_wq(ADSP_RESET_TYPE_AWAKE, ADSP_A_ID);
#else
adsp_aed(EXCEP_KERNEL, ADSP_A_ID);
#endif
ret = -ETIME;
}
adsp_is_suspend = 0;
#if ADSP_DVFS_PROFILE
end = ktime_get();
pr_debug("[%s]latency = %lld us, tcm_check(%d), ret(%d)\n",
__func__, ktime_us_delta(end, begin), tcm_ret, ret);
#endif
}
mutex_unlock(&adsp_suspend_mutex);
return ret;
}
void adsp_reset(void)
{
int itcm_ret = 0;
#if ADSP_DVFS_PROFILE
ktime_t begin, end;
#endif
#if ADSP_DVFS_PROFILE
begin = ktime_get();
#endif
adsp_reset_ready(ADSP_A_ID);
adsp_reset_ready(ADSP_B_ID);
adsp_release_runstall(ADSP_A_ID, false);
adsp_release_runstall(ADSP_B_ID, false);
adsp_power_on(false);
adsp_power_on(true);
writel(0, ADSP_A_BOOTUP_MARK);
writel(0x0, ADSP_A_IRQ_EN);
writel(0x0, ADSP_B_IRQ_EN);
DRV_ClrReg32(ADSP_A_WDT_REG, WDT_EN_BIT);
/** TCM back to initial state **/
adsp_sram_reset_init();
dsb(SY);
adsp_release_runstall(ADSP_A_ID, true);
adsp_is_suspend = 0;
#if ADSP_DVFS_PROFILE
end = ktime_get();
pr_debug("[%s]latency = %lld us, itcm_check(%d)\n",
__func__, ktime_us_delta(end, begin),
itcm_ret);
#endif
}
void mt_adsp_dvfs_ipi_init(void)
{
}
int __init adsp_dvfs_init(void)
{
adsp_is_force_freq = 0;
adsp_is_force_trigger_latmon = 0;
return 0;
}
void __exit adsp_dvfs_exit(void)
{
}
@@ -0,0 +1,122 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __ADSP_DVFS_H__
#define __ADSP_DVFS_H__
#include <adsp_ipi.h>
#include <adsp_clk.h>
#define ADSP_ITCM_MONITOR (1)
#define ADSP_DTCM_MONITOR (1)
#define ADSP_CFG_MONITOR (0)
#define ADSP_DVFS_PROFILE (1)
#define ADSP_FREQ_METER_ID (43) //hf_fadsp_ck
#define ADSP_DVFS_USE_PLL 1
#define PLL_ENABLE (1)
#define PLL_DISABLE (0)
#define DVFS_STATUS_OK (0)
#define DVFS_STATUS_BUSY (-1)
#define DVFS_REQUEST_SAME_CLOCK (-2)
#define DVFS_STATUS_ERR (-3)
#define DVFS_STATUS_TIMEOUT (-4)
#define DVFS_CLK_ERROR (-5)
#define DVFS_STATUS_CMD_FIX (-6)
#define DVFS_STATUS_CMD_LIMITED (-7)
#define DVFS_STATUS_CMD_DISABLE (-8)
enum adsp_cur_status_enum {
ADSP_STATUS_RESET = 0x00,
ADSP_STATUS_SUSPEND = 0x01,
ADSP_STATUS_SLEEP = 0x10,
ADSP_STATUS_ACTIVE = 0x11,
};
enum adsp_state_enum {
IN_DEBUG_IDLE = 1,
ENTERING_SLEEP = 2,
IN_SLEEP = 4,
ENTERING_ACTIVE = 8,
IN_ACTIVE = 16,
};
enum {
CLK_SYS_EN_BIT = 0,
CLK_HIGH_EN_BIT = 1,
CLK_HIGH_CG_BIT = 2,
CLK_SYS_IRQ_EN_BIT = 16,
CLK_HIGH_IRQ_EN_BIT = 17,
};
/*#ifdef CONFIG_PINCTRL_MT6797*/
enum clk_opp_enum {
CLK_OPP0 = 125,
CLK_OPP1 = 330,
CLK_OPP2 = 416,
CLK_INVALID_OPP,
};
enum clk_div_enum {
CLK_DIV_1 = 0,
CLK_DIV_2 = 1,
CLK_DIV_4 = 2,
CLK_DIV_8 = 3,
CLK_DIV_UNKNOWN,
};
enum voltage_enum {
SPM_VOLTAGE_800_D = 0,
SPM_VOLTAGE_800,
SPM_VOLTAGE_900,
SPM_VOLTAGE_1000,
SPM_VOLTAGE_TYPE_NUM,
};
struct mt_adsp_pll_t {
/* main clock for mfg setting */
struct clk *clk_mux;
/* substitution clock for adsp transient parent setting */
struct clk *clk_pll0;
struct clk *clk_pll1;
struct clk *clk_pll2;
struct clk *clk_pll3;
struct clk *clk_pll4;
struct clk *clk_pll5;
struct clk *clk_pll6;
struct clk *clk_pll7;
};
extern int adsp_pll_ctrl_set(unsigned int pll_ctrl_flag, unsigned int pll_sel);
extern int adsp_set_pmic_vcore(unsigned int cur_freq);
extern unsigned int adsp_get_dvfs_opp(void);
extern uint32_t adsp_get_freq(void);
extern int adsp_request_freq(void);
extern void adsp_pll_mux_set(unsigned int pll_ctrl_flag);
extern void wait_adsp_dvfs_init_done(void);
extern int __init adsp_dvfs_init(void);
extern void __exit adsp_dvfs_exit(void);
/* adsp dvfs variable*/
extern struct mutex adsp_feature_mutex;
extern struct mutex adsp_suspend_mutex;
extern struct completion adsp_suspend_cp;
extern struct completion adsp_resume_cp;
extern int adsp_is_suspend;
/* adsp new implement */
void adsp_A_send_spm_request(uint32_t enable);
extern void adsp_reset(void);
void adsp_sw_reset(enum adsp_core_id core_id);
extern void adsp_release_runstall(enum adsp_core_id, uint32_t release);
extern int adsp_suspend_init(void);
void adsp_start_suspend_timer(void);
void adsp_stop_suspend_timer(void);
int adsp_resume(void);
void adsp_suspend(enum adsp_core_id core_id);
/***************************/
#endif /* __ADSP_DVFS_H__ */
@@ -0,0 +1,567 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#include <linux/vmalloc.h> /* needed by vmalloc */
#include <linux/slab.h> /* needed by kmalloc */
#include <linux/sysfs.h>
#include <linux/device.h> /* needed by device_* */
#include <linux/workqueue.h>
#include <linux/mutex.h>
#include <linux/delay.h>
#include <linux/io.h>
#if IS_ENABLED(CONFIG_PM_WAKELOCKS)
#include <linux/pm_wakeup.h>
#endif
#include <mt-plat/aee.h>
#include "adsp_reg.h"
#include "adsp_core.h"
#include "adsp_clk.h"
#include "adsp_platform_driver.h"
#include "adsp_excep.h"
#include "adsp_logger.h"
#define ADSP_MISC_EXTRA_SIZE 0x400 //1KB
#define ADSP_MISC_BUF_SIZE 0x10000 //64KB
#define ADSP_TEST_EE_PATTERN "Assert-Test"
static char adsp_ke_buffer[ADSP_KE_DUMP_LEN];
static struct adsp_exception_control excep_ctrl;
static bool suppress_test_ee;
static u32 copy_from_buffer(void *dest, size_t destsize, const void *src,
size_t srcsize, u32 offset, size_t request)
{
/* if request == -1, offset == 0, copy full srcsize */
if (offset + request > srcsize)
request = srcsize - offset;
/* if destsize == -1, don't check the request size */
if (!dest || destsize < request) {
pr_warn("%s, buffer null or not enough space", __func__);
return 0;
}
memcpy(dest, src + offset, request);
return request;
}
static inline u32 dump_adsp_shared_memory(void *buf, size_t size, int id)
{
void *mem_addr = adsp_get_reserve_mem_virt(id);
size_t mem_size = adsp_get_reserve_mem_size(id);
if (!mem_addr)
return 0;
return copy_from_buffer(buf, size, mem_addr, mem_size, 0, -1);
}
static inline u32 copy_from_adsp_shared_memory(void *buf, u32 offset,
size_t size, int id)
{
void *mem_addr = adsp_get_reserve_mem_virt(id);
size_t mem_size = adsp_get_reserve_mem_size(id);
if (!mem_addr)
return 0;
return copy_from_buffer(buf, -1, mem_addr, mem_size, offset, size);
}
static u32 dump_adsp_internal_mem(struct adsp_priv *pdata,
void *buf, size_t size)
{
u32 clk_cfg = 0, uart_cfg = 0, n = 0;
u32 clk_mask = ADSP_CLK_UART_EN | ADSP_CLK_CORE_0_EN |
ADSP_CLK_CORE_1_EN;
u32 uart_mask = ADSP_UART_RST_N | ADSP_UART_BCLK_CG;
adsp_enable_clock();
mutex_lock(&excep_ctrl.lock);
clk_cfg = switch_adsp_clk_ctrl_cg(true, clk_mask);
uart_cfg = switch_adsp_uart_ctrl_cg(true, uart_mask);
n += copy_from_buffer(buf + n, size - n,
pdata->cfg, pdata->cfg_size, 0, -1);
n += copy_from_buffer(buf + n, size - n,
pdata->itcm, pdata->itcm_size, 0, -1);
n += copy_from_buffer(buf + n, size - n,
pdata->dtcm, pdata->dtcm_size, 0, -1);
switch_adsp_clk_ctrl_cg(false, (~clk_cfg) & clk_mask);
switch_adsp_uart_ctrl_cg(false, (~uart_cfg) & uart_mask);
mutex_unlock(&excep_ctrl.lock);
adsp_disable_clock();
return n;
}
static int dump_buffer(struct adsp_exception_control *ctrl, int coredump_id)
{
u32 total = 0, n = 0;
void *buf = NULL;
int ret = 0;
struct adsp_priv *pdata = NULL;
if (!ctrl || !ctrl->priv_data)
return -1;
pdata = (struct adsp_priv *)ctrl->priv_data;
if (ctrl->buf_backup) {
/* wait last dump done, and release buf_backup */
ret = wait_for_completion_timeout(&ctrl->done, 10 * HZ);
/* if not release buf, return EBUSY */
if (ctrl->buf_backup)
return -EBUSY;
}
total = pdata->cfg_size
+ pdata->itcm_size
+ pdata->dtcm_size
+ pdata->sysram_size
+ adsp_get_reserve_mem_size(coredump_id)
+ adsp_get_reserve_mem_size(ADSP_A_LOGGER_MEM_ID);
buf = vzalloc(total);
if (!buf)
return -ENOMEM;
n += dump_adsp_internal_mem(pdata, buf + n, total - n);
n += copy_from_buffer(buf + n, total - n,
pdata->sysram, pdata->sysram_size, 0, -1);
n += dump_adsp_shared_memory(buf + n, total - n, coredump_id);
n += dump_adsp_shared_memory(buf + n, total - n, ADSP_A_LOGGER_MEM_ID);
mutex_lock(&ctrl->buffer_lock);
reinit_completion(&ctrl->done);
ctrl->buf_backup = buf;
ctrl->buf_size = total;
mutex_unlock(&ctrl->buffer_lock);
pr_debug("%s, vmalloc size %u, buffer %p, dump_size %u",
__func__, total, buf, n);
return n;
}
static void adsp_exception_dump(struct adsp_exception_control *ctrl)
{
char detail[ADSP_AED_STR_LEN];
int db_opt = DB_OPT_DEFAULT;
char *aed_type;
bool dump_flag = true;
int ret = 0, n = 0, coredump_id = 0, coredump_size = 0;
struct adsp_priv *pdata = (struct adsp_priv *)ctrl->priv_data;
struct adsp_coredump *coredump;
/* get adsp title and exception type*/
switch (ctrl->excep_id) {
case EXCEP_BOOTUP:
aed_type = "boot exception";
break;
case EXCEP_RUNTIME:
aed_type = "runtime exception";
db_opt |= DB_OPT_FTRACE;
break;
case EXCEP_KERNEL:
aed_type = "kernel exception";
db_opt |= DB_OPT_FTRACE;
break;
default:
dump_flag = false;
aed_type = "unknown exception";
break;
}
if (pdata->id == ADSP_A_ID)
coredump_id = ADSP_A_CORE_DUMP_MEM_ID;
coredump = adsp_get_reserve_mem_virt(coredump_id);
coredump_size = adsp_get_reserve_mem_size(coredump_id);
if (suppress_test_ee && coredump
&& strstr(coredump->assert_log, ADSP_TEST_EE_PATTERN)) {
pr_info("%s, suppress Test EE dump", __func__);
return;
}
if (dump_flag) {
ret = dump_buffer(ctrl, coredump_id);
if (ret < 0)
pr_info("%s, excep dump fail ret(%d)", __func__, ret);
}
n += snprintf(detail + n, ADSP_AED_STR_LEN - n, "%s %s\n",
pdata->name, aed_type);
if (coredump) {
n += snprintf(detail + n, ADSP_AED_STR_LEN - n,
"adsp pc=0x%08x,exccause=0x%x,excvaddr=0x%x\n",
coredump->pc,
coredump->exccause,
coredump->excvaddr);
n += snprintf(detail + n, ADSP_AED_STR_LEN - n,
"CRDISPATCH_KEY:ADSP exception/%s\n",
coredump->task_name);
n += snprintf(detail + n, ADSP_AED_STR_LEN - n, "%s",
coredump->assert_log);
}
pr_info("%s", detail);
/* adsp aed api, only detail information available*/
aed_common_exception_api("adsp", (const int *)coredump, coredump_size,
NULL, 0, detail, db_opt);
}
void adsp_aed_worker(struct work_struct *ws)
{
struct adsp_exception_control *ctrl = container_of(ws,
struct adsp_exception_control,
aed_work);
struct adsp_priv *pdata = NULL;
int cid = 0, ret = 0, retry = 0;
/* wake lock AP*/
#if IS_ENABLED(CONFIG_PM_WAKELOCKS)
__pm_stay_awake(ctrl->wakeup_lock);
#endif
/* stop adsp, set reset state */
for (cid = 0; cid < ADSP_CORE_TOTAL; cid++) {
pdata = get_adsp_core_by_id(cid);
set_adsp_state(pdata, ADSP_RESET);
complete_all(&pdata->done);
}
/* force wake up if suspend thread wait reset event */
if (ctrl->waitq)
wake_up(ctrl->waitq);
adsp_register_feature(SYSTEM_FEATURE_ID);
adsp_extern_notify_chain(ADSP_EVENT_STOP);
/* exception dump */
adsp_exception_dump(ctrl);
/* reset adsp */
adsp_enable_clock();
for (retry = 0; retry < ADSP_RESET_RETRY_MAXTIME; retry++) {
ret = adsp_reset();
if (ret == 0)
break;
/* reset fail & retry */
pr_info("%s, reset retry.... (%d)", __func__, retry);
msleep(20);
}
adsp_disable_clock();
if (ret) {
pr_info("%s, adsp dead, wait dump dead body", __func__);
aee_kernel_exception_api(__FILE__,
__LINE__,
DB_OPT_DEFAULT,
"[ADSP]",
"ASSERT: ADSP DEAD! Recovery Fail");
/* BUG_ON(1); */
}
adsp_extern_notify_chain(ADSP_EVENT_READY);
adsp_deregister_feature(SYSTEM_FEATURE_ID);
#if IS_ENABLED(CONFIG_PM_WAKELOCKS)
__pm_relax(ctrl->wakeup_lock);
#endif
}
bool adsp_aed_dispatch(enum adsp_excep_id type, void *data)
{
struct adsp_exception_control *ctrl = &excep_ctrl;
if (work_busy(&ctrl->aed_work))
return false;
ctrl->excep_id = type;
ctrl->priv_data = data;
return queue_work(ctrl->workq, &ctrl->aed_work);
}
static void adsp_wdt_counter_reset(struct timer_list *t)
{
excep_ctrl.wdt_counter = 0;
pr_info("[ADSP] %s\n", __func__);
}
/*
* init a work struct
*/
int init_adsp_exception_control(struct device *dev,
struct workqueue_struct *workq,
struct wait_queue_head *waitq)
{
struct adsp_exception_control *ctrl = &excep_ctrl;
ctrl->waitq = waitq;
ctrl->workq = workq;
ctrl->buf_backup = NULL;
ctrl->buf_size = 0;
mutex_init(&ctrl->lock);
mutex_init(&ctrl->buffer_lock);
init_completion(&ctrl->done);
INIT_WORK(&ctrl->aed_work, adsp_aed_worker);
#if IS_ENABLED(CONFIG_PM_WAKELOCKS)
ctrl->wakeup_lock = wakeup_source_register(dev, "adsp wakelock");
#endif
timer_setup(&ctrl->wdt_timer, adsp_wdt_counter_reset, 0);
return 0;
}
void adsp_wdt_handler(int irq, void *data, int cid)
{
struct adsp_priv *pdata = (struct adsp_priv *)data;
if (!adsp_aed_dispatch(EXCEP_RUNTIME, data))
pr_info("%s, already resetting, ignore core%d wdt",
__func__, pdata->id);
}
void get_adsp_misc_buffer(unsigned long *vaddr, unsigned long *size)
{
struct adsp_priv *pdata = NULL;
struct log_info_s *log_info = NULL;
struct buffer_info_s *buf_info = NULL;
void *buf = adsp_ke_buffer;
void *addr = NULL;
unsigned int w_pos, r_pos, buf_size;
unsigned int data_len[2];
unsigned int id = 0, n = 0;
unsigned int part_len = ADSP_MISC_BUF_SIZE / ADSP_CORE_TOTAL;
memset(buf, 0, ADSP_KE_DUMP_LEN);
for (id = 0; id < ADSP_CORE_TOTAL; id++) {
w_pos = 0;
pdata = get_adsp_core_by_id(id);
if (!pdata || !pdata->log_ctrl ||
!pdata->log_ctrl->inited || !pdata->log_ctrl->priv)
goto ERROR;
log_info = (struct log_info_s *)pdata->log_ctrl->priv;
buf_info = (struct buffer_info_s *)(pdata->log_ctrl->priv
+ log_info->info_ofs);
buf_size = log_info->buff_size;
memcpy_fromio(&w_pos, &buf_info->w_pos, sizeof(w_pos));
if (w_pos >= buf_size)
w_pos -= buf_size;
if (w_pos < part_len) {
r_pos = buf_size + w_pos - part_len;
data_len[0] = part_len - w_pos;
data_len[1] = w_pos;
} else {
r_pos = w_pos - part_len;
data_len[0] = part_len;
data_len[1] = 0;
}
addr = pdata->log_ctrl->priv + log_info->buff_ofs;
memcpy(buf + n, addr + r_pos, data_len[0]);
n += data_len[0];
memcpy(buf + n, addr, data_len[1]);
n += data_len[1];
}
/* return value */
*vaddr = (unsigned long)buf;
*size = n;
return;
ERROR:
/* return value */
*vaddr = (unsigned long)buf;
*size = 0;
}
EXPORT_SYMBOL(get_adsp_misc_buffer);
void get_adsp_aee_buffer(unsigned long *vaddr, unsigned long *size)
{
u32 clk_cfg = 0, uart_cfg = 0, n = 0;
u32 clk_mask = ADSP_CLK_UART_EN | ADSP_CLK_CORE_0_EN |
ADSP_CLK_CORE_1_EN;
u32 uart_mask = ADSP_UART_RST_N | ADSP_UART_BCLK_CG;
struct adsp_priv *pdata = NULL;
void *buf = adsp_ke_buffer;
u32 len = ADSP_KE_DUMP_LEN;
memset(buf, 0, len);
adsp_enable_clock();
mutex_lock(&excep_ctrl.lock);
read_lock(&access_rwlock);
adsp_mt_clr_sw_reset();
clk_cfg = switch_adsp_clk_ctrl_cg(true, clk_mask);
uart_cfg = switch_adsp_uart_ctrl_cg(true, uart_mask);
pdata = get_adsp_core_by_id(ADSP_A_ID);
n += copy_from_buffer(buf + n, len - n,
pdata->cfg, pdata->cfg_size, 0, -1);
n += copy_from_buffer(buf + n, len - n,
pdata->dtcm, pdata->dtcm_size, 0, -1);
switch_adsp_clk_ctrl_cg(false, (~clk_cfg) & clk_mask);
switch_adsp_uart_ctrl_cg(false, (~uart_cfg) & uart_mask);
read_unlock(&access_rwlock);
mutex_unlock(&excep_ctrl.lock);
adsp_disable_clock();
/* last adsp_log */
//n += dump_adsp_partial_log(buf + n, len - n);
/* return value */
*vaddr = (unsigned long)buf;
*size = len;
}
EXPORT_SYMBOL(get_adsp_aee_buffer);
/*
* sysfs bin_attribute node
*/
static ssize_t adsp_dump_show(struct file *filep, struct kobject *kobj,
struct bin_attribute *attr,
char *buf, loff_t offset, size_t size)
{
ssize_t n = 0;
struct adsp_exception_control *ctrl = &excep_ctrl;
mutex_lock(&ctrl->buffer_lock);
if (ctrl->buf_backup) {
n = copy_from_buffer(buf, -1, ctrl->buf_backup,
ctrl->buf_size, offset, size);
if (n == 0) {
vfree(ctrl->buf_backup);
ctrl->buf_backup = NULL;
ctrl->buf_size = 0;
/* if dump_buffer wait for dump, wake up it */
complete(&ctrl->done);
}
}
mutex_unlock(&ctrl->buffer_lock);
return n;
}
static ssize_t adsp_dump_ke_show(struct file *filep, struct kobject *kobj,
struct bin_attribute *attr,
char *buf, loff_t offset, size_t size)
{
unsigned long tmp[2];
ssize_t n = 0;
ssize_t threshold[2];
if (offset == 0) /* only do ke ramdump once at start */
get_adsp_aee_buffer(&tmp[0], &tmp[1]);
threshold[0] = ADSP_KE_DUMP_LEN;
threshold[1] = threshold[0] +
adsp_get_reserve_mem_size(ADSP_A_LOGGER_MEM_ID);
if (offset >= 0 && offset < threshold[0]) {
n = copy_from_buffer(buf, -1, adsp_ke_buffer,
threshold[0], offset, size);
} else if (offset >= threshold[0] && offset < threshold[1]) {
n = copy_from_adsp_shared_memory(
buf, offset - threshold[0],
size, ADSP_A_LOGGER_MEM_ID);
}
return n;
}
static ssize_t adsp_dump_log_show(struct file *filep, struct kobject *kobj,
struct bin_attribute *attr,
char *buf, loff_t offset, size_t size)
{
ssize_t n = 0;
ssize_t threshold;
threshold = adsp_get_reserve_mem_size(ADSP_A_LOGGER_MEM_ID);
if (offset >= 0 && offset < threshold) {
n = copy_from_adsp_shared_memory(buf, offset,
size, ADSP_A_LOGGER_MEM_ID);
}
return n;
}
static struct bin_attribute bin_attr_adsp_dump = {
.attr = {
.name = "adsp_dump",
.mode = 0444,
},
.size = 0,
.read = adsp_dump_show,
};
static struct bin_attribute bin_attr_adsp_dump_ke = {
.attr = {
.name = "adsp_dump_ke",
.mode = 0444,
},
.size = 0,
.read = adsp_dump_ke_show,
};
struct bin_attribute bin_attr_adsp_dump_log = {
.attr = {
.name = "adsp_last_log",
.mode = 0444,
},
.size = 0,
.read = adsp_dump_log_show,
};
static inline ssize_t suppress_ee_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
unsigned int input = 0;
if (kstrtouint(buf, 0, &input) != 0)
return -EINVAL;
suppress_test_ee = !!input;
return count;
}
DEVICE_ATTR_WO(suppress_ee);
static struct bin_attribute *adsp_excep_bin_attrs[] = {
&bin_attr_adsp_dump,
&bin_attr_adsp_dump_ke,
&bin_attr_adsp_dump_log,
NULL,
};
static struct attribute *adsp_excep_attrs[] = {
&dev_attr_suppress_ee.attr,
NULL,
};
struct attribute_group adsp_excep_attr_group = {
.attrs = adsp_excep_attrs,
.bin_attrs = adsp_excep_bin_attrs,
};
@@ -0,0 +1,61 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __ADSP_EXCEP_H__
#define __ADSP_EXCEP_H__
#include <linux/interrupt.h>
#define ADSP_AED_STR_LEN (512)
#define ADSP_WDT_TIMEOUT (60 * HZ) /* 60 seconds*/
#define ADSP_KE_DUMP_LEN (256 * 1024)
#define ADSP_RESET_RETRY_MAXTIME (7)
enum adsp_excep_id {
EXCEP_LOAD_FIRMWARE = 0,
EXCEP_RESET,
EXCEP_BOOTUP,
EXCEP_RUNTIME,
EXCEP_KERNEL,
ADSP_NR_EXCEP,
};
/* adsp reg dump */
struct adsp_coredump {
u32 reserved_0[67];
u32 pc;
u32 exccause;
u32 excvaddr;
u32 reserved_1[7];
u8 task_name[16];
u32 reserved_2[47];
u8 assert_log[512];
};
struct adsp_exception_control {
int excep_id;
void *priv_data;
void *buf_backup;
size_t buf_size;
struct mutex lock;
struct mutex buffer_lock;
struct workqueue_struct *workq;
struct wait_queue_head *waitq;
struct work_struct aed_work;
struct wakeup_source *wakeup_lock;
struct completion done;
struct timer_list wdt_timer;
unsigned int wdt_counter;
};
void adsp_wdt_handler(int irq, void *data, int cid);
bool adsp_aed_dispatch(enum adsp_excep_id type, void *data);
int init_adsp_exception_control(struct device *dev,
struct workqueue_struct *wq,
struct wait_queue_head *waitq);
#endif
@@ -0,0 +1,91 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __ADSP_FEATURE_DEFINE_H__
#define __ADSP_FEATURE_DEFINE_H__
/* reset recovery feature kernel option*/
#define CFG_RECOVERY_SUPPORT
/* adsp feature PRI list */
/* The higher number, higher priority */
enum adsp_feature_pri {
AUDIO_HAL_FEATURE_PRI = 0,
ADSP_LOGGER_FEATURE_PRI,
SPK_PROTECT_FEATURE_PRI,
A2DP_PLAYBACK_FEATURE_PRI,
AURISYS_FEATURE_PRI,
DEEPBUF_FEATURE_PRI,
OFFLOAD_FEATURE_PRI,
PRIMARY_FEATURE_PRI,
VOIP_FEATURE_PRI,
CAPTURE_UL1_FEATURE_PRI,
AUDIO_DATAPROVIDER_FEATURE_PRI,
AUDIO_PLAYBACK_FEATURE_PRI,
VOICE_CALL_FEATURE_PRI,
AUDIO_CONTROLLER_FEATURE_PRI,
SYSTEM_FEATURE_PRI,
};
/* adsp feature ID list */
enum adsp_feature_id {
SYSTEM_FEATURE_ID = 0,
ADSP_LOGGER_FEATURE_ID = 1,
AURISYS_FEATURE_ID = 2,
AUDIO_CONTROLLER_FEATURE_ID = 3,
PRIMARY_FEATURE_ID = 4,
FAST_FEATURE_ID = 5,
DEEPBUF_FEATURE_ID = 6,
OFFLOAD_FEATURE_ID = 7,
AUDIO_PLAYBACK_FEATURE_ID = 8,
AUDIO_MUSIC_FEATURE_ID = 9,
RESERVED0_FEATURE_ID = 10,
RESERVED1_FEATURE_ID = 11,
CAPTURE_UL1_FEATURE_ID = 12,
AUDIO_DATAPROVIDER_FEATURE_ID = 13,
VOICE_CALL_FEATURE_ID = 14,
VOIP_FEATURE_ID = 15,
SPK_PROTECT_FEATURE_ID = 16,
CALL_FINAL_FEATURE_ID = 17,
A2DP_PLAYBACK_FEATURE_ID = 18,
KTV_FEATURE_ID = 19,
CAPTURE_RAW_FEATURE_ID = 20,
FM_ADSP_FEATURE_ID = 21,
VOICE_CALL_SUB_FEATURE_ID = 22,
BLE_CALL_DL_FEATURE_ID = 27,
BLE_CALL_UL_FEATURE_ID = 28,
ADSP_NUM_FEATURE_ID,
};
enum {
DEREGI_FLAG_NODELAY = 1 << 0,
};
struct adsp_feature_control {
int total;
unsigned int feature_set; /* from dts */
struct mutex lock;
struct workqueue_struct *wq;
struct delayed_work suspend_work;
int delay_ms;
int (*suspend)(void);
int (*resume)(void);
};
ssize_t adsp_dump_feature_state(u32 cid, char *buffer, int size);
int adsp_get_feature_index(const char *str);
bool is_feature_in_set(u32 cid, u32 fid);
bool adsp_feature_is_active(u32 cid);
bool is_adsp_feature_in_active(void);
bool flush_suspend_work(u32 cid);
int _adsp_register_feature(u32 cid, u32 fid, u32 opt);
int _adsp_deregister_feature(u32 cid, u32 fid, u32 opt);
int init_adsp_feature_control(u32 cid, u32 feature_set, int delay_ms,
struct workqueue_struct *wq,
int (*_suspend)(void),
int (*_resume)(void));
#endif
@@ -0,0 +1,108 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __ADSP_HELPER_H__
#define __ADSP_HELPER_H__
#include <linux/notifier.h>
#include "adsp_reserved_mem.h"
#include "adsp_feature_define.h"
enum adsp_ipi_id {
ADSP_IPI_WDT = 0,
ADSP_IPI_TEST1,
ADSP_IPI_LOGGER_ENABLE,
ADSP_IPI_LOGGER_WAKEUP,
ADSP_IPI_LOGGER_INIT,
ADSP_IPI_TRAX_ENABLE,
ADSP_IPI_TRAX_DONE,
ADSP_IPI_TRAX_INIT_A,
ADSP_IPI_VOW,
ADSP_IPI_AUDIO,
ADSP_IPI_DVT_TEST,
ADSP_IPI_TIME_SYNC,
ADSP_IPI_CONSYS,
ADSP_IPI_ADSP_A_READY,
ADSP_IPI_APCCCI,
ADSP_IPI_ADSP_A_RAM_DUMP,
ADSP_IPI_DVFS_DEBUG,
ADSP_IPI_DVFS_FIX_OPP_SET,
ADSP_IPI_DVFS_FIX_OPP_EN,
ADSP_IPI_DVFS_LIMIT_OPP_SET,
ADSP_IPI_DVFS_LIMIT_OPP_EN,
ADSP_IPI_DVFS_SUSPEND,
ADSP_IPI_DVFS_SLEEP,
ADSP_IPI_DVFS_WAKE,
ADSP_IPI_DVFS_SET_FREQ,
ADSP_IPI_ADSP_PLL_CTRL = 27,
ADSP_IPI_MET_ADSP = 30,
ADSP_IPI_ADSP_TIMER = 31,
ADSP_NR_IPI,
};
enum adsp_ipi_status {
ADSP_IPI_ERROR = -1,
ADSP_IPI_DONE,
ADSP_IPI_BUSY,
};
enum adsp_status {
ADSP_ERROR = -1,
ADSP_OK,
ADSP_SEMAPHORE_BUSY,
};
/* adsp notify event */
enum ADSP_NOTIFY_EVENT {
ADSP_EVENT_STOP = 0,
ADSP_EVENT_READY,
};
enum semaphore_3way_flag {
SEMA_3WAY_UART = 0,
SEMA_3WAY_C2C_A = 1,
SEMA_3WAY_C2C_B = 2,
SEMA_3WAY_DVFS = 3,
SEMA_3WAY_AUDIO = 4,
SEMA_3WAY_AUDIOREG = 5,
SEMA_3WAY_NUM = 7,
};
#define SEMA_AUDIO SEMA_3WAY_AUDIO
#define SEMA_AUDIOREG SEMA_3WAY_AUDIOREG
#define ADSP_OSTIMER_BUFFER (adsp_timesync_ptr)
extern void *adsp_timesync_ptr;
extern enum adsp_ipi_status adsp_ipi_registration(enum adsp_ipi_id id,
void (*ipi_handler)(int id,
void *data, unsigned int len),
const char *name);
extern enum adsp_ipi_status adsp_ipi_unregistration(enum adsp_ipi_id id);
extern enum adsp_ipi_status adsp_push_message(enum adsp_ipi_id id, void *buf,
unsigned int len, unsigned int wait_ms,
unsigned int core_id);
extern enum adsp_ipi_status adsp_send_message(enum adsp_ipi_id id, void *buf,
unsigned int len, unsigned int wait,
unsigned int core_id);
extern int is_adsp_ready(u32 cid);
extern bool is_adsp_feature_in_active(void);
extern int adsp_feature_in_which_core(enum adsp_feature_id fid);
extern int adsp_register_feature(enum adsp_feature_id fid);
extern int adsp_deregister_feature(enum adsp_feature_id fid);
extern void adsp_register_notify(struct notifier_block *nb);
extern void adsp_unregister_notify(struct notifier_block *nb);
extern void reset_hal_feature_table(void);
/* If device interrupt is not connected, return -ENOTCONN. */
extern int adsp_irq_registration(u32 core_id, u32 irq_id, void *handler,
void *data);
/* semaphore */
extern int get_adsp_semaphore(unsigned int flags);
extern int release_adsp_semaphore(unsigned int flags);
#endif
@@ -0,0 +1,11 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __ADSP_IPI_H
#define __ADSP_IPI_H
#include "adsp_mbox.h"
#endif
@@ -0,0 +1,264 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#include <linux/soc/mediatek/mtk-mbox.h>
#include <linux/vmalloc.h> /* needed by vmalloc */
#include "adsp_core.h"
#include "adsp_platform.h"
#include "adsp_mbox.h"
#include "audio_ipi_platform.h"
#include "adsp_ipi_queue.h"
struct adsp_ipi_desc {
void (*handler)(int id, void *data, unsigned int len);
const char *name;
} adsp_ipi_descs[ADSP_NR_IPI];
static int adsp_mbox_pin_cb(unsigned int id, void *prdata, void *buf,
unsigned int len);
struct mtk_mbox_info adsp_mbox_table[ADSP_IPI_CH_CNT] = {
{ .opt = MBOX_OPT_QUEUE_DIR, .is64d = true},
{ .opt = MBOX_OPT_QUEUE_DIR, .is64d = true},
{ .opt = MBOX_OPT_QUEUE_DIR, .is64d = true},
{ .opt = MBOX_OPT_QUEUE_DIR, .is64d = true},
};
struct mtk_mbox_pin_send adsp_mbox_pin_send[ADSP_TOTAL_SEND_PIN] = {
{
.mbox = ADSP_MBOX0_CH_ID,
.offset = ADSP_MBOX_SEND_SLOT_OFFSET,
.msg_size = ADSP_MBOX_SLOT_COUNT,
.pin_index = 0,
},
{
.mbox = ADSP_MBOX2_CH_ID,
.offset = ADSP_MBOX_SEND_SLOT_OFFSET,
.msg_size = ADSP_MBOX_SLOT_COUNT,
.pin_index = 0,
}
};
struct mtk_mbox_pin_recv adsp_mbox_pin_recv[ADSP_TOTAL_RECV_PIN] = {
{
.mbox = ADSP_MBOX1_CH_ID,
.offset = ADSP_MBOX_RECV_SLOT_OFFSET,
.msg_size = ADSP_MBOX_SLOT_COUNT,
.pin_index = 0,
.mbox_pin_cb = adsp_mbox_pin_cb,
},
{
.mbox = ADSP_MBOX3_CH_ID,
.offset = ADSP_MBOX_RECV_SLOT_OFFSET,
.msg_size = ADSP_MBOX_SLOT_COUNT,
.pin_index = 0,
.mbox_pin_cb = adsp_mbox_pin_cb,
}
};
struct mtk_mbox_device adsp_mboxdev = {
.name = "adsp_mailbox",
.pin_recv_table = adsp_mbox_pin_recv,
.pin_send_table = adsp_mbox_pin_send,
.info_table = adsp_mbox_table,
.count = ADSP_IPI_CH_CNT,
.recv_count = ADSP_TOTAL_RECV_PIN,
.send_count = ADSP_TOTAL_SEND_PIN,
/*.post_cb = adsp_post_cb, */
};
int adsp_mbox_send(struct mtk_mbox_pin_send *pin_send, void *msg,
unsigned int wait)
{
int result;
struct mtk_mbox_device *mbdev = &adsp_mboxdev;
ktime_t start_time;
s64 time_ipc_us;
if (mutex_trylock(&pin_send->mutex_send) == 0) {
pr_info("%s, mbox %d mutex_trylock busy",
__func__, pin_send->mbox);
return MBOX_PIN_BUSY;
}
if (mtk_mbox_check_send_irq(mbdev, pin_send->mbox,
pin_send->pin_index)) {
mutex_unlock(&pin_send->mutex_send);
return MBOX_PIN_BUSY;
}
result = mtk_mbox_write_hd(mbdev, pin_send->mbox,
pin_send->offset, msg);
if (result != MBOX_DONE) {
pr_err("%s() error mbox%d write, result %d\n",
__func__, pin_send->mbox, result);
return result;
}
dsb(SY);
result = mtk_mbox_trigger_irq(mbdev, pin_send->mbox,
0x1 << pin_send->pin_index);
if (result != MBOX_DONE) {
pr_err("%s() error mbox%d trigger, result %d\n",
__func__, pin_send->mbox, result);
return result;
}
if (wait) {
start_time = ktime_get();
while (mtk_mbox_check_send_irq(mbdev, pin_send->mbox,
pin_send->pin_index)) {
time_ipc_us = ktime_us_delta(ktime_get(), start_time);
if (time_ipc_us > 1000) {/* 1 ms */
pr_warn("%s, time_ipc_us > 1000", __func__);
break;
}
}
}
mutex_unlock(&pin_send->mutex_send);
return MBOX_DONE;
}
static int adsp_mbox_pin_cb(unsigned int id, void *prdata, void *buf,
unsigned int len)
{
u32 opendsp_id = *(u32 *)prdata ?
AUDIO_OPENDSP_USE_HIFI3_B : AUDIO_OPENDSP_USE_HIFI3_A;
adsp_mt_clr_spm(*(u32 *)prdata);
if (id >= ADSP_NR_IPI) {
pr_err("%s() invalid ipi_id %d\n", __func__, id);
return ADSP_IPI_ERROR;
}
if (!adsp_ipi_descs[id].handler) {
pr_err("%s() invalid ipi handler %d\n", __func__, id);
return ADSP_IPI_ERROR;
}
if (id == ADSP_IPI_ADSP_A_READY ||
id == ADSP_IPI_DVFS_SUSPEND ||
id == ADSP_IPI_LOGGER_INIT)
adsp_ipi_descs[id].handler(id, buf, len);
else if (is_scp_ipi_queue_init(opendsp_id))
scp_dispatch_ipi_hanlder_to_queue(
opendsp_id, id, buf, len, adsp_ipi_descs[id].handler);
else {
pr_info("ipi queue not ready!! core: %u, ipi_id: %u, buf: %p, len: %u, ipi_handler: %p",
opendsp_id, id, buf, len, adsp_ipi_descs[id].handler);
WARN_ON(1);
}
return ADSP_IPI_DONE;
}
int adsp_mbox_probe(struct platform_device *pdev)
{
int ret;
int idx = 0;
struct mtk_mbox_device *mbdev = &adsp_mboxdev;
for (idx = 0; idx < ADSP_IPI_CH_CNT; idx++) {
ret = mtk_mbox_probe(pdev, mbdev, idx);
if (ret)
break;
}
for (idx = 0; idx < mbdev->send_count; idx++)
mutex_init(&mbdev->pin_send_table[idx].mutex_send);
return ret;
}
struct mtk_mbox_pin_send *get_adsp_mbox_pin_send(int index)
{
int i;
struct mtk_mbox_info *mbox;
struct mtk_mbox_pin_send *pin_send;
if (index >= ADSP_IPI_CH_CNT)
return ERR_PTR(-EINVAL);
mbox = adsp_mboxdev.info_table + index;
if (!mbox->enable) {
pr_info("the channel %d not enable", index);
return ERR_PTR(-ENODEV);
}
for (i = 0; i < ADSP_TOTAL_SEND_PIN; i++) {
pin_send = &adsp_mbox_pin_send[i];
if (pin_send->mbox == index)
return pin_send;
}
pr_info("the channel %d is not send pin", index);
return ERR_PTR(-ENODEV);
}
struct mtk_mbox_pin_recv *get_adsp_mbox_pin_recv(int index)
{
int i;
struct mtk_mbox_info *mbox;
struct mtk_mbox_pin_recv *pin_recv;
if (index >= ADSP_IPI_CH_CNT)
return ERR_PTR(-EINVAL);
mbox = adsp_mboxdev.info_table + index;
if (!mbox->enable) {
pr_info("the channel %d not enable", index);
return ERR_PTR(-ENODEV);
}
for (i = 0; i < ADSP_TOTAL_RECV_PIN; i++) {
pin_recv = &adsp_mbox_pin_recv[i];
if (pin_recv->mbox == index)
return pin_recv;
}
pr_info("the channel %d is not recv pin", index);
return ERR_PTR(-ENODEV);
}
enum adsp_ipi_status adsp_ipi_registration(
enum adsp_ipi_id id,
void (*ipi_handler)(int id, void *data, unsigned int len),
const char *name)
{
if (id < ADSP_NR_IPI && id >= 0) {
adsp_ipi_descs[id].name = name;
if (ipi_handler == NULL)
return ADSP_IPI_ERROR;
adsp_ipi_descs[id].handler = ipi_handler;
return ADSP_IPI_DONE;
} else
return ADSP_IPI_ERROR;
}
EXPORT_SYMBOL_GPL(adsp_ipi_registration);
/*
* API let apps unregister an ipi handler
* @param id: IPI ID
*/
enum adsp_ipi_status adsp_ipi_unregistration(enum adsp_ipi_id id)
{
if (id < ADSP_NR_IPI && id >= 0) {
adsp_ipi_descs[id].name = "";
adsp_ipi_descs[id].handler = NULL;
return ADSP_IPI_DONE;
} else
return ADSP_IPI_ERROR;
}
EXPORT_SYMBOL_GPL(adsp_ipi_unregistration);
@@ -0,0 +1,37 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 MediaTek Inc.
*/
#ifndef __ADSP_MBOX_H__
#define __ADSP_MBOX_H__
#include <linux/soc/mediatek/mtk_tinysys_ipi.h>
#include <linux/soc/mediatek/mtk-mbox.h>
#define ADSP_MBOX_TOTAL (5)
#define ADSP_MBOX0_CH_ID 0
#define ADSP_MBOX1_CH_ID 1
#define ADSP_MBOX2_CH_ID 2
#define ADSP_MBOX3_CH_ID 3
#define ADSP_MBOX4_CH_ID 4
#define ADSP_MBOX_SEND_IDX 0
#define ADSP_MBOX_RECV_IDX 1
#define ADSP_TOTAL_SEND_PIN 2
#define ADSP_TOTAL_RECV_PIN 2
#define ADSP_IPI_CH_CNT (ADSP_TOTAL_SEND_PIN + ADSP_TOTAL_RECV_PIN)
#define ADSP_MBOX_SLOT_COUNT 64
#define ADSP_MBOX_SEND_SLOT_OFFSET 0
#define ADSP_MBOX_RECV_SLOT_OFFSET 0
#define SHARE_BUF_SIZE (ADSP_MBOX_SLOT_COUNT * MBOX_SLOT_SIZE)
int adsp_mbox_send(struct mtk_mbox_pin_send *pin_send, void *msg,
unsigned int wait);
int adsp_mbox_probe(struct platform_device *pdev);
struct mtk_mbox_pin_send *get_adsp_mbox_pin_send(int index);
struct mtk_mbox_pin_recv *get_adsp_mbox_pin_recv(int index);
#endif /* __ADSP_MBOX_H__ */
Loaded 100 of 80519 files, more files were not shown because too many files have changed in this diff. Show more