diff options
Diffstat (limited to 'chip/mt_scp/mt8183')
-rw-r--r-- | chip/mt_scp/mt8183/audio_codec_wov.c | 106 | ||||
-rw-r--r-- | chip/mt_scp/mt8183/build.mk | 35 | ||||
-rw-r--r-- | chip/mt_scp/mt8183/clock.c | 374 | ||||
-rw-r--r-- | chip/mt_scp/mt8183/clock_chip.h | 34 | ||||
-rw-r--r-- | chip/mt_scp/mt8183/config_chip.h | 64 | ||||
-rw-r--r-- | chip/mt_scp/mt8183/gpio.c | 180 | ||||
-rw-r--r-- | chip/mt_scp/mt8183/hrtimer.c | 253 | ||||
-rw-r--r-- | chip/mt_scp/mt8183/ipi.c | 394 | ||||
-rw-r--r-- | chip/mt_scp/mt8183/ipi_chip.h | 116 | ||||
-rw-r--r-- | chip/mt_scp/mt8183/ipi_table.c | 67 | ||||
-rw-r--r-- | chip/mt_scp/mt8183/memmap.c | 322 | ||||
-rw-r--r-- | chip/mt_scp/mt8183/memmap.h | 49 | ||||
-rw-r--r-- | chip/mt_scp/mt8183/registers.h | 645 | ||||
-rw-r--r-- | chip/mt_scp/mt8183/serial_reg.h | 90 | ||||
-rw-r--r-- | chip/mt_scp/mt8183/system.c | 176 | ||||
-rw-r--r-- | chip/mt_scp/mt8183/uart.c | 179 | ||||
-rw-r--r-- | chip/mt_scp/mt8183/watchdog.c | 33 |
17 files changed, 0 insertions, 3117 deletions
diff --git a/chip/mt_scp/mt8183/audio_codec_wov.c b/chip/mt_scp/mt8183/audio_codec_wov.c deleted file mode 100644 index 0a4684f909..0000000000 --- a/chip/mt_scp/mt8183/audio_codec_wov.c +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright 2019 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "audio_codec.h" -#include "hooks.h" -#include "memmap.h" -#include "registers.h" -#include "task.h" -#include "util.h" - -/* VIF FIFO irq is triggered above this level */ -#define WOV_TRIGGER_LEVEL 160 - -int audio_codec_wov_enable_notifier(void) -{ - SCP_VIF_FIFO_DATA_THRE = WOV_TRIGGER_LEVEL + 1; - SCP_VIF_FIFO_EN |= VIF_FIFO_IRQ_EN; - - task_enable_irq(SCP_IRQ_MAD_FIFO); - - return EC_SUCCESS; -} - -int audio_codec_wov_disable_notifier(void) -{ - SCP_VIF_FIFO_EN &= ~VIF_FIFO_IRQ_EN; - - task_disable_irq(SCP_IRQ_MAD_FIFO); - - return EC_SUCCESS; -} - -int audio_codec_wov_enable(void) -{ - SCP_VIF_FIFO_EN = 0; - - SCP_RXIF_CFG0 = (RXIF_CFG0_RESET_VAL & ~RXIF_RGDL2_MASK) | - RXIF_RGDL2_DMIC_16K; - SCP_RXIF_CFG1 = RXIF_CFG1_RESET_VAL; - - SCP_VIF_FIFO_EN |= VIF_FIFO_RSTN; - - return EC_SUCCESS; -} - -int audio_codec_wov_disable(void) -{ - SCP_VIF_FIFO_EN = 0; - - return EC_SUCCESS; -} - -static size_t wov_fifo_level(void) -{ - uint32_t fifo_status = SCP_VIF_FIFO_STATUS; - - if (!(fifo_status & VIF_FIFO_VALID)) - return 0; - - if (fifo_status & VIF_FIFO_FULL) - return VIF_FIFO_MAX; - - return VIF_FIFO_LEVEL(fifo_status); -} - -int32_t audio_codec_wov_read(void *buf, uint32_t count) -{ - int16_t *out = buf; - uint8_t gain = 1; - - if (IS_ENABLED(CONFIG_AUDIO_CODEC_DMIC_SOFTWARE_GAIN)) - audio_codec_dmic_get_gain_idx(0, &gain); - - count >>= 1; - - while (count-- && wov_fifo_level()) { - if (IS_ENABLED(CONFIG_AUDIO_CODEC_DMIC_SOFTWARE_GAIN)) - *out++ = audio_codec_s16_scale_and_clip( - SCP_VIF_FIFO_DATA, gain); - else - *out++ = SCP_VIF_FIFO_DATA; - } - - return (void *)out - buf; -} - -static void wov_fifo_interrupt_handler(void) -{ -#ifdef HAS_TASK_WOV - task_wake(TASK_ID_WOV); -#endif - - audio_codec_wov_disable_notifier(); - - /* Read to clear */ - SCP_VIF_FIFO_IRQ_STATUS; -} -DECLARE_IRQ(SCP_IRQ_MAD_FIFO, wov_fifo_interrupt_handler, 2); - -int audio_codec_memmap_ap_to_ec(uintptr_t ap_addr, uintptr_t *ec_addr) -{ - return memmap_ap_to_scp(ap_addr, ec_addr); -} diff --git a/chip/mt_scp/mt8183/build.mk b/chip/mt_scp/mt8183/build.mk deleted file mode 100644 index 206563a7c5..0000000000 --- a/chip/mt_scp/mt8183/build.mk +++ /dev/null @@ -1,35 +0,0 @@ -# -*- makefile -*- -# Copyright 2021 The Chromium OS Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -CORE:=cortex-m -CFLAGS_CPU+=-march=armv7e-m -mcpu=cortex-m4 - -# Required chip modules -chip-y+=$(CHIP_VARIANT)/clock.o -chip-y+=$(CHIP_VARIANT)/gpio.o -chip-y+=$(CHIP_VARIANT)/memmap.o -chip-y+=$(CHIP_VARIANT)/system.o -chip-y+=$(CHIP_VARIANT)/uart.o - -# Optional chip modules -chip-$(CONFIG_AUDIO_CODEC_WOV)+=$(CHIP_VARIANT)/audio_codec_wov.o -chip-$(CONFIG_COMMON_TIMER)+=$(CHIP_VARIANT)/hrtimer.o -chip-$(CONFIG_I2C)+=$(CHIP_VARIANT)/i2c.o -chip-$(CONFIG_IPI)+=$(CHIP_VARIANT)/ipi.o $(CHIP_VARIANT)/ipi_table.o -chip-$(CONFIG_SPI)+=$(CHIP_VARIANT)/spi.o -chip-$(CONFIG_WATCHDOG)+=$(CHIP_VARIANT)/watchdog.o - -ifeq ($(CONFIG_IPI),y) -$(out)/RO/chip/$(CHIP)/$(CHIP_VARIANT)/ipi_table.o: $(out)/ipi_table_gen.inc -$(out)/RW/chip/$(CHIP)/$(CHIP_VARIANT)/ipi_table.o: $(out)/ipi_table_gen.inc -endif - -ifeq ($(CONFIG_AUDIO_CODEC_WOV),y) -HOTWORD_PRIVATE_LIB:=private/libkukui_scp_google_hotword_dsp_api.a -ifneq ($(wildcard $(HOTWORD_PRIVATE_LIB)),) -LDFLAGS_EXTRA+=$(HOTWORD_PRIVATE_LIB) -HAVE_PRIVATE_AUDIO_CODEC_WOV_LIBS:=y -endif -endif diff --git a/chip/mt_scp/mt8183/clock.c b/chip/mt_scp/mt8183/clock.c deleted file mode 100644 index 3029a00a01..0000000000 --- a/chip/mt_scp/mt8183/clock.c +++ /dev/null @@ -1,374 +0,0 @@ -/* Copyright 2018 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -/* Clocks, PLL and power settings */ - -#include "clock.h" -#include "clock_chip.h" -#include "common.h" -#include "console.h" -#include "registers.h" -#include "task.h" -#include "timer.h" -#include "util.h" - -#define CPRINTF(format, args...) cprintf(CC_CLOCK, format, ## args) - -#define ULPOSC_DIV_MAX (1 << OSC_DIV_BITS) -#define ULPOSC_CALI_MAX (1 << OSC_CALI_BITS) - -void clock_init(void) -{ - /* Set VREQ to HW mode */ - SCP_CPU_VREQ = CPU_VREQ_HW_MODE; - SCP_SECURE_CTRL &= ~ENABLE_SPM_MASK_VREQ; - - /* Set DDREN auto mode */ - SCP_SYS_CTRL |= AUTO_DDREN; - - /* Initialize 26MHz system clock counter reset value to 1. */ - SCP_CLK_SYS_VAL = - (SCP_CLK_SYS_VAL & ~CLK_SYS_VAL_MASK) | CLK_SYS_VAL(1); - /* Initialize high frequency ULPOSC counter reset value to 1. */ - SCP_CLK_HIGH_VAL = - (SCP_CLK_HIGH_VAL & ~CLK_HIGH_VAL_MASK) | CLK_HIGH_VAL(1); - /* Initialize sleep mode control VREQ counter. */ - SCP_CLK_SLEEP_CTRL = - (SCP_CLK_SLEEP_CTRL & ~VREQ_COUNTER_MASK) | VREQ_COUNTER_VAL(1); - - /* Set normal wake clock */ - SCP_WAKE_CKSW &= ~WAKE_CKSW_SEL_NORMAL_MASK; - - /* Enable fast wakeup support */ - SCP_CLK_SLEEP = 0; - SCP_CLK_ON_CTRL = (SCP_CLK_ON_CTRL & ~HIGH_FINAL_VAL_MASK) | - HIGH_FINAL_VAL_DEFAULT; - SCP_FAST_WAKE_CNT_END = - (SCP_FAST_WAKE_CNT_END & ~FAST_WAKE_CNT_END_MASK) | - FAST_WAKE_CNT_END_DEFAULT; - - /* Set slow wake clock */ - SCP_WAKE_CKSW = (SCP_WAKE_CKSW & ~WAKE_CKSW_SEL_SLOW_MASK) | - WAKE_CKSW_SEL_SLOW_DEFAULT; - - /* Select CLK_HIGH as wakeup clock */ - SCP_CLK_SLOW_SEL = (SCP_CLK_SLOW_SEL & - ~(CKSW_SEL_SLOW_MASK | CKSW_SEL_SLOW_DIV_MASK)) | - CKSW_SEL_SLOW_ULPOSC2_CLK; - - /* - * Set legacy wakeup - * - disable SPM sleep control - * - disable SCP sleep mode - */ - SCP_CLK_SLEEP_CTRL &= ~(EN_SLEEP_CTRL | SPM_SLEEP_MODE); - - task_enable_irq(SCP_IRQ_CLOCK); - task_enable_irq(SCP_IRQ_CLOCK2); -} - -static void scp_ulposc_config(int osc, uint32_t osc_div, uint32_t osc_cali) -{ - uint32_t val; - - /* Clear all bits */ - val = 0; - /* Enable CP */ - val |= OSC_CP_EN; - /* Set div */ - val |= osc_div << 17; - /* F-band = 0, I-band = 4 */ - val |= 4 << 6; - /* Set calibration */ - val |= osc_cali; - /* Set control register 1 */ - AP_ULPOSC_CON02(osc) = val; - /* Set control register 2, enable div2 */ - AP_ULPOSC_CON13(osc) |= OSC_DIV2_EN; -} - -static inline void busy_udelay(int usec) -{ - /* - * Delaying by busy-looping, for place that can't use udelay because of - * the clock not configured yet. The value 28 is chosen approximately - * from experiment. - */ - volatile int i = usec * 28; - - while (i--) - ; -} - -static unsigned int scp_measure_ulposc_freq(int osc) -{ - unsigned int result = 0; - int cnt; - - /* Before select meter clock input, bit[1:0] = b00 */ - AP_CLK_DBG_CFG = (AP_CLK_DBG_CFG & ~DBG_MODE_MASK) | - DBG_MODE_SET_CLOCK; - - /* Select source, bit[21:16] = clk_src */ - AP_CLK_DBG_CFG = (AP_CLK_DBG_CFG & ~DBG_BIST_SOURCE_MASK) | - (osc == 0 ? DBG_BIST_SOURCE_ULPOSC1 : - DBG_BIST_SOURCE_ULPOSC2); - - /* Set meter divisor to 1, bit[31:24] = b00000000 */ - AP_CLK_MISC_CFG_0 = (AP_CLK_MISC_CFG_0 & ~MISC_METER_DIVISOR_MASK) | - MISC_METER_DIV_1; - - /* Enable frequency meter, without start */ - AP_SCP_CFG_0 |= CFG_FREQ_METER_ENABLE; - - /* Trigger frequency meter start */ - AP_SCP_CFG_0 |= CFG_FREQ_METER_RUN; - - /* - * Frequency meter counts cycles in 1 / (26 * 1024) second period. - * freq_in_hz = freq_counter * 26 * 1024 - * - * The hardware takes 38us to count cycles. Delay up to 100us, - * as busy_udelay may not be accurate when sysclk is not 26Mhz - * (e.g. when recalibrating/measuring after boot). - */ - for (cnt = 100; cnt; cnt--) { - busy_udelay(1); - if (!(AP_SCP_CFG_0 & CFG_FREQ_METER_RUN)) { - result = CFG_FREQ_COUNTER(AP_SCP_CFG_1); - break; - } - } - - /* Disable freq meter */ - AP_SCP_CFG_0 &= ~CFG_FREQ_METER_ENABLE; - return result; -} - -static inline int signum(int v) -{ - return (v > 0) - (v < 0); -} - -static inline int abs(int v) -{ - return (v >= 0) ? v : -v; -} - -static int scp_ulposc_config_measure(int osc, int div, int cali) -{ - int freq; - - scp_ulposc_config(osc, div, cali); - freq = scp_measure_ulposc_freq(osc); - CPRINTF("ULPOSC%d: %d %d %d (%dkHz)\n", - osc + 1, div, cali, freq, - freq * 26 * 1000 / 1024); - - return freq; -} - -/** - * Calibrate ULPOSC to target frequency. - * - * @param osc 0:ULPOSC1, 1:ULPOSC2 - * @param target_mhz Target frequency to set - * @return Frequency counter output - * - */ -static int scp_calibrate_ulposc(int osc, int target_mhz) -{ - int target_freq = DIV_ROUND_NEAREST(target_mhz * 1024, 26); - struct ulposc { - int div; /* frequency divisor/multiplier */ - int cali; /* variable resistor calibrator */ - int freq; /* frequency counter measure result */ - } curr, prev = {0}; - enum { STAGE_DIV, STAGE_CALI } stage = STAGE_DIV; - int param, param_max; - - curr.div = ULPOSC_DIV_MAX / 2; - curr.cali = ULPOSC_CALI_MAX / 2; - - param = curr.div; - param_max = ULPOSC_DIV_MAX; - - /* - * In the loop below, linear search closest div value to get desired - * frequency counter value. Then adjust cali to get a better result. - * Note that this doesn't give optimal output frequency, but it's - * usually close enough. - * TODO(b:120176040): See if we can efficiently calibrate the clock with - * more precision by exploring more of the cali/div space. - * - * The frequency function follows. Note that f is positively correlated - * with both div and cali: - * f(div, cali) = k1 * (div + k2) / R(cali) * C - * Where: - * R(cali) = k3 / (1 + k4 * (cali - k4)) - */ - while (1) { - curr.freq = scp_ulposc_config_measure(osc, curr.div, curr.cali); - - if (!curr.freq) - return 0; - - /* - * If previous and current are on either side of the desired - * frequency, pick the closest one. - */ - if (prev.freq && signum(target_freq - curr.freq) != - signum(target_freq - prev.freq)) { - if (abs(target_freq - prev.freq) < - abs(target_freq - curr.freq)) - curr = prev; - - if (stage == STAGE_CALI) - break; - - /* Switch to optimizing cali */ - stage = STAGE_CALI; - param = curr.cali; - param_max = ULPOSC_CALI_MAX; - } - - prev = curr; - param += signum(target_freq - curr.freq); - - if (param < 0 || param >= param_max) - return 0; - - if (stage == STAGE_DIV) - curr.div = param; - else - curr.cali = param; - } - - /* - * It's possible we end up using prev, so reset the configuration and - * measure again. - */ - return scp_ulposc_config_measure(osc, curr.div, curr.cali); -} - -static void scp_clock_high_enable(int osc) -{ - /* Enable high speed clock */ - SCP_CLK_EN |= EN_CLK_HIGH; - - switch (osc) { - case 0: - /* After 25ms, enable ULPOSC */ - busy_udelay(25 * MSEC); - SCP_CLK_EN |= CG_CLK_HIGH; - break; - case 1: - /* Turn off ULPOSC2 high-core-disable switch */ - SCP_CLK_ON_CTRL &= ~HIGH_CORE_DIS_SUB; - /* After 25ms, turn on ULPOSC2 high core clock gate */ - busy_udelay(25 * MSEC); - SCP_CLK_HIGH_CORE |= CLK_HIGH_CORE_CG; - break; - default: - break; - } -} - -void scp_use_clock(enum scp_clock_source src) -{ - /* - * DIV2 divider takes precedence over clock selection to prevent - * over-clocking. - */ - if (src == SCP_CLK_ULPOSC1) - SCP_CLK_DIV_SEL = CLK_DIV2; - - SCP_CLK_SEL = src; - - if (src != SCP_CLK_ULPOSC1) - SCP_CLK_DIV_SEL = CLK_DIV1; -} - -void scp_enable_clock(void) -{ - /* Select default CPU clock */ - scp_use_clock(SCP_CLK_26M); - - /* VREQ */ - SCP_CPU_VREQ = 0x10001; - SCP_SECURE_CTRL &= ~ENABLE_SPM_MASK_VREQ; - - /* DDREN auto mode */ - SCP_SYS_CTRL |= AUTO_DDREN; - - /* Set settle time */ - SCP_CLK_SYS_VAL = 1; /* System clock */ - SCP_CLK_HIGH_VAL = 1; /* ULPOSC */ - SCP_CLK_SLEEP_CTRL = (SCP_CLK_SLEEP_CTRL & ~VREQ_COUNTER_MASK) | 2; - - /* Disable slow wake */ - SCP_CLK_SLEEP = SLOW_WAKE_DISABLE; - /* Disable SPM sleep control, disable sleep mode */ - SCP_CLK_SLEEP_CTRL &= ~(SPM_SLEEP_MODE | EN_SLEEP_CTRL); - - /* Turn off ULPOSC2 */ - SCP_CLK_ON_CTRL |= HIGH_CORE_DIS_SUB; - scp_ulposc_config(0, 12, 32); - scp_clock_high_enable(0); /* Turn on ULPOSC1 */ - scp_ulposc_config(1, 16, 32); - scp_clock_high_enable(1); /* Turn on ULPOSC2 */ - - /* Calibrate ULPOSC */ - scp_calibrate_ulposc(0, ULPOSC1_CLOCK_MHZ); - scp_calibrate_ulposc(1, ULPOSC2_CLOCK_MHZ); - - /* Select ULPOSC2 high speed CPU clock */ - scp_use_clock(SCP_CLK_ULPOSC2); - - /* Enable default clock gate */ - SCP_CLK_GATE |= CG_DMA_CH3 | CG_DMA_CH2 | CG_DMA_CH1 | CG_DMA_CH0 | - CG_I2C_M | CG_MAD_M | CG_AP2P_M; - - /* Select pwrap_ulposc */ - AP_CLK_CFG_5 = (AP_CLK_CFG_5 & ~PWRAP_ULPOSC_MASK) | OSC_D16; - - /* Enable pwrap_ulposc clock gate */ - AP_CLK_CFG_5_CLR = PWRAP_ULPOSC_CG; -} - -DECLARE_IRQ(SCP_IRQ_CLOCK, clock_control_irq, 3); -void clock_control_irq(void) -{ - /* Read ack CLK_IRQ */ - (SCP_CLK_IRQ_ACK); - task_clear_pending_irq(SCP_IRQ_CLOCK); -} - -DECLARE_IRQ(SCP_IRQ_CLOCK2, clock_fast_wakeup_irq, 3); -void clock_fast_wakeup_irq(void) -{ - /* Ack fast wakeup */ - SCP_SLEEP_IRQ2 = 1; - task_clear_pending_irq(SCP_IRQ_CLOCK2); -} - -/* Console command */ -int command_ulposc(int argc, char *argv[]) -{ - if (argc > 1 && !strncmp(argv[1], "cal", 3)) { - scp_calibrate_ulposc(0, ULPOSC1_CLOCK_MHZ); - scp_calibrate_ulposc(1, ULPOSC2_CLOCK_MHZ); - } - - /* SCP clock meter counts every (26MHz / 1024) tick */ - ccprintf("ULPOSC1 frequency: %u kHz\n", - scp_measure_ulposc_freq(0) * 26 * 1000 / 1024); - ccprintf("ULPOSC2 frequency: %u kHz\n", - scp_measure_ulposc_freq(1) * 26 * 1000 / 1024); - - return EC_SUCCESS; -} -DECLARE_CONSOLE_COMMAND(ulposc, command_ulposc, "[calibrate]", - "Calibrate ULPOSC frequency"); diff --git a/chip/mt_scp/mt8183/clock_chip.h b/chip/mt_scp/mt8183/clock_chip.h deleted file mode 100644 index a16bf2e54e..0000000000 --- a/chip/mt_scp/mt8183/clock_chip.h +++ /dev/null @@ -1,34 +0,0 @@ -/* Copyright 2019 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -/* Clocks, PLL and power settings */ - -#ifndef __CROS_EC_CLOCK_CHIP_H -#define __CROS_EC_CLOCK_CHIP_H - -#include "common.h" -#include "registers.h" - -/* Default ULPOSC clock speed in MHz */ -#ifndef ULPOSC1_CLOCK_MHZ -#define ULPOSC1_CLOCK_MHZ 240 -#endif -#ifndef ULPOSC2_CLOCK_MHZ -#define ULPOSC2_CLOCK_MHZ 330 -#endif - -void scp_enable_clock(void); - -enum scp_clock_source { - SCP_CLK_26M = CLK_SEL_SYS_26M, - SCP_CLK_32K = CLK_SEL_32K, - SCP_CLK_ULPOSC2 = CLK_SEL_ULPOSC_2, - SCP_CLK_ULPOSC1 = CLK_SEL_ULPOSC_1, -}; - -/* Switches to use 'src' clock */ -void scp_use_clock(enum scp_clock_source src); - -#endif /* __CROS_EC_CLOCK_CHIP_H */ diff --git a/chip/mt_scp/mt8183/config_chip.h b/chip/mt_scp/mt8183/config_chip.h deleted file mode 100644 index e0710a908b..0000000000 --- a/chip/mt_scp/mt8183/config_chip.h +++ /dev/null @@ -1,64 +0,0 @@ -/* Copyright 2018 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef __CROS_EC_CONFIG_CHIP_H -#define __CROS_EC_CONFIG_CHIP_H - -#include "core/cortex-m/config_core.h" - -/* Interval between HOOK_TICK notifications */ -#define HOOK_TICK_INTERVAL_MS 500 -#define HOOK_TICK_INTERVAL (HOOK_TICK_INTERVAL_MS * MSEC) - -/* Default to UART 2 (AP UART) for EC console */ -#define CONFIG_UART_CONSOLE 2 - -/* Number of IRQ vectors */ -#define CONFIG_IRQ_COUNT 56 - -/* - * Number of EINT can be 0 ~ 160. Change this to conditional macro - * on adding other variants. - */ -#define MAX_NUM_EINT 8 -#define MAX_EINT_PORT (MAX_NUM_EINT / 32) - -/* RW only, no flash */ -#undef CONFIG_FW_INCLUDE_RO -#define CONFIG_RO_MEM_OFF 0 -#define CONFIG_RO_SIZE 0 -#define CONFIG_RW_MEM_OFF 0 -#define CONFIG_RW_SIZE 0x40000 /* 256KB */ -#define CONFIG_EC_WRITABLE_STORAGE_OFF 0 -#define CONFIG_EC_PROTECTED_STORAGE_OFF 0 -#define CONFIG_RO_STORAGE_OFF 0 -#define CONFIG_RW_STORAGE_OFF 0 -#define CONFIG_PROGRAM_MEMORY_BASE 0 -#define CONFIG_MAPPED_STORAGE_BASE 0 -/* Enable MPU to protect code RAM from writing, and data RAM from execution.*/ -#define CONFIG_MPU - -/* Unsupported features/commands */ -#undef CONFIG_CMD_FLASHINFO -#undef CONFIG_CMD_POWER_AP -#undef CONFIG_FLASH_CROS -#undef CONFIG_FLASH_PHYSICAL -#undef CONFIG_FMAP -#undef CONFIG_HIBERNATE - -/* Task stack size */ -#define CONFIG_STACK_SIZE 1024 -#define IDLE_TASK_STACK_SIZE 256 -#define SMALLER_TASK_STACK_SIZE 384 -#define TASK_STACK_SIZE 512 -#define LARGER_TASK_STACK_SIZE 640 -#define VENTI_TASK_STACK_SIZE 768 - -#define CONFIG_CHIP_PRE_INIT - -#define GPIO_PIN(num) ((num) / 32), ((num) % 32) -#define GPIO_PIN_MASK(p, m) .port = (p), .mask = (m) - -#endif /* __CROS_EC_CONFIG_CHIP_H */ diff --git a/chip/mt_scp/mt8183/gpio.c b/chip/mt_scp/mt8183/gpio.c deleted file mode 100644 index a4896aae72..0000000000 --- a/chip/mt_scp/mt8183/gpio.c +++ /dev/null @@ -1,180 +0,0 @@ -/* Copyright 2018 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -/* GPIO module */ - -#include "gpio.h" -#include "hooks.h" -#include "registers.h" -#include "system.h" -#include "task.h" -#include "util.h" - -void gpio_set_alternate_function(uint32_t port, uint32_t mask, - enum gpio_alternate_func func) -{ - int bit, mode_reg_index, shift; - uint32_t mode_bits, mode_mask; - - /* Up to 8 alt functions per port */ - if (func > GPIO_ALT_FUNC_7) - return; - - if (func == GPIO_ALT_FUNC_NONE) - func = GPIO_ALT_FUNC_DEFAULT; - - while (mask) { - /* 32 gpio per port */ - bit = get_next_bit(&mask); - /* 8 gpio per mode reg */ - mode_reg_index = (port << 2) | (bit >> 3); - /* - * b[3] - write enable(?) - * b[2:0] - mode - */ - shift = (bit & 7) << 2; - mode_bits = func << shift; - mode_mask = ~(0xf << shift); - AP_GPIO_MODE(mode_reg_index) = (AP_GPIO_MODE(mode_reg_index) & - mode_mask) | mode_bits; - } -} - -test_mockable int gpio_get_level(enum gpio_signal signal) -{ - return !!(AP_GPIO_DIN(gpio_list[signal].port) & - gpio_list[signal].mask); -} - - -void gpio_set_level(enum gpio_signal signal, int value) -{ - if (value) - AP_GPIO_DOUT(gpio_list[signal].port) |= gpio_list[signal].mask; - else - AP_GPIO_DOUT(gpio_list[signal].port) &= ~gpio_list[signal].mask; -} - -void gpio_set_flags_by_mask(uint32_t port, uint32_t mask, uint32_t flags) -{ - /* Set input/output mode */ - if (flags & GPIO_OUTPUT) { - /* Set level before changing to output mode */ - if (flags & GPIO_HIGH) - AP_GPIO_DOUT(port) |= mask; - if (flags & GPIO_LOW) - AP_GPIO_DOUT(port) &= ~mask; - AP_GPIO_DIR(port) |= mask; - } else { - AP_GPIO_DIR(port) &= ~mask; - } - - if (flags & (GPIO_INT_F_RISING | GPIO_INT_F_HIGH)) - SCP_EINT_POLARITY_SET[port] = mask; - - if (flags & (GPIO_INT_F_FALLING | GPIO_INT_F_LOW)) - SCP_EINT_POLARITY_CLR[port] = mask; - else - SCP_EINT_POLARITY_SET[port] = mask; - - /* Set sensitivity register on edge trigger */ - if (flags & (GPIO_INT_F_RISING | GPIO_INT_F_FALLING)) - SCP_EINT_SENS_SET[port] = mask; - else - SCP_EINT_SENS_CLR[port] = mask; -} - -int gpio_get_flags_by_mask(uint32_t port, uint32_t mask) -{ - /* TODO(b/120167145): implement get flags */ - return 0; -} - -int gpio_enable_interrupt(enum gpio_signal signal) -{ - const struct gpio_info *g = gpio_list + signal; - - if (signal >= GPIO_IH_COUNT || !g->mask) - return EC_ERROR_INVAL; - - SCP_EINT_MASK_CLR[g->port] = g->mask; - - return EC_SUCCESS; -} - -int gpio_disable_interrupt(enum gpio_signal signal) -{ - const struct gpio_info *g = gpio_list + signal; - - if (signal >= GPIO_IH_COUNT || !g->mask) - return EC_ERROR_INVAL; - - SCP_EINT_MASK_SET[g->port] = g->mask; - - return EC_SUCCESS; -} - -int gpio_clear_pending_interrupt(enum gpio_signal signal) -{ - const struct gpio_info *g = gpio_list + signal; - - if (signal >= GPIO_IH_COUNT || !g->mask) - return EC_ERROR_INVAL; - - SCP_EINT_ACK[g->port] = g->mask; - - return EC_SUCCESS; -} - -void gpio_pre_init(void) -{ - const struct gpio_info *g = gpio_list; - int i; - int is_warm = system_is_reboot_warm(); - - for (i = 0; i < GPIO_COUNT; i++, g++) { - int flags = g->flags; - - if (flags & GPIO_DEFAULT) - continue; - - if (is_warm) - flags &= ~(GPIO_LOW | GPIO_HIGH); - - gpio_set_flags_by_mask(g->port, g->mask, flags); - } -} - -void gpio_init(void) -{ - /* Enable EINT IRQ */ - task_enable_irq(SCP_IRQ_EINT); -} -DECLARE_HOOK(HOOK_INIT, gpio_init, HOOK_PRIO_DEFAULT); - -/* Interrupt handler */ -void __keep gpio_interrupt(void) -{ - int bit, port; - uint32_t pending; - enum gpio_signal signal; - - for (port = 0; port <= MAX_EINT_PORT; port++) { - pending = SCP_EINT_STATUS[port]; - - while (pending) { - bit = get_next_bit(&pending); - SCP_EINT_ACK[port] = BIT(bit); - /* Skip masked gpio */ - if (SCP_EINT_MASK_GET[port] & BIT(bit)) - continue; - /* Call handler */ - signal = port * 32 + bit; - if (signal < GPIO_IH_COUNT) - gpio_irq_handlers[signal](signal); - } - } -} -DECLARE_IRQ(SCP_IRQ_EINT, gpio_interrupt, 1); diff --git a/chip/mt_scp/mt8183/hrtimer.c b/chip/mt_scp/mt8183/hrtimer.c deleted file mode 100644 index 92887af2a7..0000000000 --- a/chip/mt_scp/mt8183/hrtimer.c +++ /dev/null @@ -1,253 +0,0 @@ -/* Copyright 2018 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -/* - * High-res hardware timer - * - * SCP hardware 32bit count down timer can be configured to source clock from - * 32KHz, 26MHz, BCLK or PCLK. This implementation selects BCLK (ULPOSC1/8) as a - * source, countdown mode and converts to micro second value matching common - * timer. - */ - -#include "clock.h" -#include "clock_chip.h" -#include "common.h" -#include "console.h" -#include "hooks.h" -#include "hwtimer.h" -#include "panic.h" -#include "registers.h" -#include "task.h" -#include "timer.h" -#include "watchdog.h" - -#define IRQ_TIMER(n) CONCAT2(SCP_IRQ_TIMER, n) - -#define TIMER_SYSTEM 5 -#define TIMER_EVENT 3 - -/* ULPOSC1 should be a multiple of 8. */ -BUILD_ASSERT((ULPOSC1_CLOCK_MHZ % 8) == 0); -#define TIMER_CLOCK_MHZ (ULPOSC1_CLOCK_MHZ / 8) - -/* Common timer overflows at 0x100000000 micro seconds */ -#define OVERFLOW_TICKS (TIMER_CLOCK_MHZ * 0x100000000 - 1) - -static uint8_t sys_high; -static uint8_t event_high; - -/* Convert hardware countdown timer to 64bit countup ticks */ -static inline uint64_t timer_read_raw_system(void) -{ - uint32_t timer_ctrl = SCP_TIMER_IRQ_CTRL(TIMER_SYSTEM); - uint32_t sys_high_adj = sys_high; - - /* - * If an IRQ is pending, but has not been serviced yet, adjust the - * sys_high value. - */ - if (timer_ctrl & TIMER_IRQ_STATUS) - sys_high_adj = sys_high ? (sys_high - 1) : (TIMER_CLOCK_MHZ-1); - - return OVERFLOW_TICKS - (((uint64_t)sys_high_adj << 32) | - SCP_TIMER_VAL(TIMER_SYSTEM)); -} - -static inline uint64_t timer_read_raw_event(void) -{ - return OVERFLOW_TICKS - (((uint64_t)event_high << 32) | - SCP_TIMER_VAL(TIMER_EVENT)); -} - -static inline void timer_set_clock(int n, uint32_t clock_source) -{ - SCP_TIMER_EN(n) = (SCP_TIMER_EN(n) & ~TIMER_CLK_MASK) | - clock_source; -} - -static inline void timer_ack_irq(int n) -{ - SCP_TIMER_IRQ_CTRL(n) |= TIMER_IRQ_CLEAR; -} - -/* Set hardware countdown value */ -static inline void timer_set_reset_value(int n, uint32_t reset_value) -{ - SCP_TIMER_RESET_VAL(n) = reset_value; -} - -static void timer_reset(int n) -{ - __hw_timer_enable_clock(n, 0); - timer_ack_irq(n); - timer_set_reset_value(n, 0xffffffff); - timer_set_clock(n, TIMER_CLK_32K); -} - -/* Reload a new 32bit countdown value */ -static void timer_reload(int n, uint32_t value) -{ - __hw_timer_enable_clock(n, 0); - timer_set_reset_value(n, value); - __hw_timer_enable_clock(n, 1); -} - -static int timer_reload_event_high(void) -{ - if (event_high) { - if (SCP_TIMER_RESET_VAL(TIMER_EVENT) == 0xffffffff) - __hw_timer_enable_clock(TIMER_EVENT, 1); - else - timer_reload(TIMER_EVENT, 0xffffffff); - event_high--; - return 1; - } - - /* Disable event timer clock when done. */ - __hw_timer_enable_clock(TIMER_EVENT, 0); - return 0; -} - -void __hw_clock_event_clear(void) -{ - __hw_timer_enable_clock(TIMER_EVENT, 0); - timer_set_reset_value(TIMER_EVENT, 0x0000c1ea4); - event_high = 0; -} - -void __hw_clock_event_set(uint32_t deadline) -{ - uint64_t deadline_raw = (uint64_t)deadline * TIMER_CLOCK_MHZ; - uint64_t now_raw = timer_read_raw_system(); - uint32_t event_deadline; - - if (deadline_raw > now_raw) { - deadline_raw -= now_raw; - event_deadline = (uint32_t)deadline_raw; - event_high = deadline_raw >> 32; - } else { - event_deadline = 1; - event_high = 0; - } - - if (event_deadline) - timer_reload(TIMER_EVENT, event_deadline); - else - timer_reload_event_high(); -} - -void __hw_timer_enable_clock(int n, int enable) -{ - if (enable) { - SCP_TIMER_IRQ_CTRL(n) |= 1; - SCP_TIMER_EN(n) |= 1; - } else { - SCP_TIMER_EN(n) &= ~1; - SCP_TIMER_IRQ_CTRL(n) &= ~1; - } -} - -int __hw_clock_source_init(uint32_t start_t) -{ - int t; - - /* - * TODO(b/120169529): check clock tree to see if we need to turn on - * MCLK and BCLK gate. - */ - SCP_CLK_GATE |= (CG_TIMER_M | CG_TIMER_B); - - /* Reset all timer, select 32768Hz clock source */ - for (t = 0; t < NUM_TIMERS; t++) - timer_reset(t); - - /* Enable timer IRQ wake source */ - SCP_INTC_IRQ_WAKEUP |= (1 << IRQ_TIMER(0)) | (1 << IRQ_TIMER(1)) | - (1 << IRQ_TIMER(2)) | (1 << IRQ_TIMER(3)) | - (1 << IRQ_TIMER(4)) | (1 << IRQ_TIMER(5)); - /* - * Timer configuration: - * OS TIMER - count up @ 13MHz, 64bit value with latch. - * SYS TICK - count down @ 26MHz - * EVENT TICK - count down @ 26MHz - */ - - /* Turn on OS TIMER, tick at 13MHz */ - SCP_OSTIMER_CON |= 1; - - /* System timestamp timer from BCLK (sourced from ULPOSC) */ - SCP_CLK_BCLK = CLK_BCLK_SEL_ULPOSC1_DIV8; - - timer_set_clock(TIMER_SYSTEM, TIMER_CLK_BCLK); - sys_high = TIMER_CLOCK_MHZ-1; - timer_set_reset_value(TIMER_SYSTEM, 0xffffffff); - __hw_timer_enable_clock(TIMER_SYSTEM, 1); - task_enable_irq(IRQ_TIMER(TIMER_SYSTEM)); - /* Event tick timer */ - timer_set_clock(TIMER_EVENT, TIMER_CLK_BCLK); - task_enable_irq(IRQ_TIMER(TIMER_EVENT)); - - return IRQ_TIMER(TIMER_SYSTEM); -} - -uint32_t __hw_clock_source_read(void) -{ - return timer_read_raw_system() / TIMER_CLOCK_MHZ; -} - -uint32_t __hw_clock_event_get(void) -{ - return (timer_read_raw_event() + timer_read_raw_system()) - / TIMER_CLOCK_MHZ; -} - -static void __hw_clock_source_irq(int n) -{ - uint32_t timer_ctrl = SCP_TIMER_IRQ_CTRL(n); - - /* Ack if we're hardware interrupt */ - if (timer_ctrl & TIMER_IRQ_STATUS) - timer_ack_irq(n); - - switch (n) { - case TIMER_EVENT: - if (timer_ctrl & TIMER_IRQ_STATUS) { - if (timer_reload_event_high()) - return; - } - process_timers(0); - break; - case TIMER_SYSTEM: - /* If this is a hardware irq, check overflow */ - if (timer_ctrl & TIMER_IRQ_STATUS) { - if (sys_high) { - sys_high--; - process_timers(0); - } else { - /* Overflow, reload system timer */ - sys_high = TIMER_CLOCK_MHZ-1; - process_timers(1); - } - } else { - process_timers(0); - } - break; - default: - return; - } - -} - -#define DECLARE_TIMER_IRQ(n) \ - DECLARE_IRQ(IRQ_TIMER(n), __hw_clock_source_irq_##n, 2); \ - void __hw_clock_source_irq_##n(void) { __hw_clock_source_irq(n); } - -DECLARE_TIMER_IRQ(0); -DECLARE_TIMER_IRQ(1); -DECLARE_TIMER_IRQ(2); -DECLARE_TIMER_IRQ(3); -DECLARE_TIMER_IRQ(4); -DECLARE_TIMER_IRQ(5); diff --git a/chip/mt_scp/mt8183/ipi.c b/chip/mt_scp/mt8183/ipi.c deleted file mode 100644 index 8e13781db3..0000000000 --- a/chip/mt_scp/mt8183/ipi.c +++ /dev/null @@ -1,394 +0,0 @@ -/* Copyright 2018 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - * - * Inter-Processor Communication (IPC) and Inter-Processor Interrupt (IPI) - * - * IPC is a communication bridge between AP and SCP. AP/SCP sends an IPC - * interrupt to SCP/AP to inform to collect the commmunication mesesages in the - * shared buffer. - * - * There are 4 IPCs in the current architecture, from IPC0 to IPC3. The - * priority of IPC is proportional to its IPC index. IPC3 has the highest - * priority and IPC0 has the lowest one. - * - * IPC0 may contain zero or more IPIs. Each IPI represents a task or a service, - * e.g. host command, or video encoding. IPIs are recognized by IPI ID, which - * should sync across AP and SCP. Shared buffer should designated which IPI - * ID it talks to. - * - * Currently, we don't have IPC handlers for IPC1, IPC2, and IPC3. - */ - -#include "clock_chip.h" -#include "console.h" -#include "hooks.h" -#include "host_command.h" -#include "ipi_chip.h" -#include "mkbp_event.h" -#include "power.h" -#include "system.h" -#include "task.h" -#include "util.h" -#include "hwtimer.h" - -#define CPRINTF(format, args...) cprintf(CC_IPI, format, ##args) -#define CPRINTS(format, args...) cprints(CC_IPI, format, ##args) - -#define IPI_MAX_REQUEST_SIZE CONFIG_IPC_SHARED_OBJ_BUF_SIZE -/* Reserve 1 extra byte for HOSTCMD_TYPE and 3 bytes for padding. */ -#define IPI_MAX_RESPONSE_SIZE (CONFIG_IPC_SHARED_OBJ_BUF_SIZE - 4) -#define HOSTCMD_TYPE_HOSTCMD 1 -#define HOSTCMD_TYPE_HOSTEVENT 2 - -static volatile int16_t ipc0_enabled_count; -static struct mutex ipc0_lock; -static struct mutex ipi_lock; -/* IPC0 shared objects, including send object and receive object. */ -static struct ipc_shared_obj *const scp_send_obj = - (struct ipc_shared_obj *)CONFIG_IPC_SHARED_OBJ_ADDR; -static struct ipc_shared_obj *const scp_recv_obj = - (struct ipc_shared_obj *)(CONFIG_IPC_SHARED_OBJ_ADDR + - sizeof(struct ipc_shared_obj)); -static char ipi_ready; - -#ifdef HAS_TASK_HOSTCMD -/* - * hostcmd and hostevent share the same IPI ID, and use first byte type to - * indicate its type. - */ -static struct hostcmd_data { - const uint8_t type; - /* To be compatible with CONFIG_HOSTCMD_ALIGNED */ - uint8_t response[IPI_MAX_RESPONSE_SIZE] __aligned(4); -} hc_cmd_obj = { .type = HOSTCMD_TYPE_HOSTCMD }; -BUILD_ASSERT(sizeof(struct hostcmd_data) == CONFIG_IPC_SHARED_OBJ_BUF_SIZE); - -static struct host_packet ipi_packet; -#endif - -/* Check if SCP to AP IPI is in use. */ -static inline int is_ipi_busy(void) -{ - return SCP_HOST_INT & IPC_SCP2HOST_BIT; -} - -/* If IPI is declared as a wake-up source, wake AP up. */ -static inline void try_to_wakeup_ap(int32_t id) -{ -#ifdef CONFIG_RPMSG_NAME_SERVICE - if (id == IPI_NS_SERVICE) - return; -#endif - - if (*ipi_wakeup_table[id]) - SCP_SPM_INT = SPM_INT_A2SPM; -} - -void ipi_disable_irq(int irq) -{ - /* Only support SCP_IRQ_IPC0 for now. */ - if (irq != SCP_IRQ_IPC0) - return; - - mutex_lock(&ipc0_lock); - - if ((--ipc0_enabled_count) == 0) - task_disable_irq(irq); - - mutex_unlock(&ipc0_lock); -} - -void ipi_enable_irq(int irq) -{ - /* Only support SCP_IRQ_IPC0 for now. */ - if (irq != SCP_IRQ_IPC0) - return; - - mutex_lock(&ipc0_lock); - - if ((++ipc0_enabled_count) == 1) { - int pending_ipc = SCP_GIPC_IN & SCP_GPIC_IN_CLEAR_ALL; - - task_enable_irq(irq); - - if (ipi_ready && pending_ipc) - /* - * IPC may be triggered while SCP_IRQ_IPC0 was disabled. - * AP will still updates SCP_GIPC_IN. - * Trigger the IRQ handler if it has a - * pending IPC. - */ - task_trigger_irq(irq); - } - - mutex_unlock(&ipc0_lock); -} - -__override void -power_chipset_handle_host_sleep_event(enum host_sleep_event state, - struct host_sleep_event_context *ctx) -{ - int i; - const task_id_t s3_suspend_tasks[] = { -#ifndef S3_SUSPEND_TASK_LIST -#define S3_SUSPEND_TASK_LIST -#endif -#define TASK(n, ...) TASK_ID_##n, - S3_SUSPEND_TASK_LIST - }; - - if (state == HOST_SLEEP_EVENT_S3_SUSPEND) { - ccprints("AP suspend"); - /* - * On AP suspend, Vcore is 0.6V, and we should not use ULPOSC2, - * which needs at least 0.7V. Switch to ULPOSC1 instead. - */ - scp_use_clock(SCP_CLK_ULPOSC1); - - for (i = 0; i < ARRAY_SIZE(s3_suspend_tasks); ++i) - task_disable_task(s3_suspend_tasks[i]); - } else if (state == HOST_SLEEP_EVENT_S3_RESUME) { - ccprints("AP resume"); - /* Vcore is raised to >=0.7V, switch back to ULPSOC2 */ - scp_use_clock(SCP_CLK_ULPOSC2); - - for (i = 0; i < ARRAY_SIZE(s3_suspend_tasks); ++i) - task_enable_task(s3_suspend_tasks[i]); - } -} - -/* Send data from SCP to AP. */ -int ipi_send(int32_t id, const void *buf, uint32_t len, int wait) -{ - if (!ipi_ready) - return EC_ERROR_BUSY; - - /* TODO(b:117917141): Remove this check completely. */ - if (in_interrupt_context()) { - CPRINTS("Err: invoke %s() in ISR CTX", __func__); - return EC_ERROR_BUSY; - } - - if (len > sizeof(scp_send_obj->buffer)) - return EC_ERROR_INVAL; - - ipi_disable_irq(SCP_IRQ_IPC0); - mutex_lock(&ipi_lock); - - /* Check if there is already an IPI pending in AP. */ - if (is_ipi_busy()) { - /* - * If the following conditions meet, - * 1) There is an IPI pending in AP. - * 2) The incoming IPI is a wakeup IPI. - * then it assumes that AP is in suspend state. - * Send a AP wakeup request to SPM. - * - * The incoming IPI will be checked if it's a wakeup source. - */ - try_to_wakeup_ap(id); - - mutex_unlock(&ipi_lock); - ipi_enable_irq(SCP_IRQ_IPC0); - CPRINTS("Err: IPI Busy, %d", id); - - return EC_ERROR_BUSY; - } - - - scp_send_obj->id = id; - scp_send_obj->len = len; - memcpy(scp_send_obj->buffer, buf, len); - - /* Send IPI to AP: interrutp AP to receive IPI messages. */ - try_to_wakeup_ap(id); - SCP_HOST_INT = IPC_SCP2HOST_BIT; - - while (wait && is_ipi_busy()) - ; - - mutex_unlock(&ipi_lock); - ipi_enable_irq(SCP_IRQ_IPC0); - - return EC_SUCCESS; -} - -static void ipi_handler(void) -{ - if (scp_recv_obj->id >= IPI_COUNT) { - CPRINTS("#ERR IPI %d", scp_recv_obj->id); - return; - } - - /* - * Only print IPI that is not host command channel, which will - * be printed by host command driver. - */ - if (scp_recv_obj->id != IPI_HOST_COMMAND) - CPRINTS("IPI %d", scp_recv_obj->id); - - /* - * Pass the buffer to handler. Each handler should be in charge of - * the buffer copying/reading before returning from handler. - */ - ipi_handler_table[scp_recv_obj->id]( - scp_recv_obj->id, scp_recv_obj->buffer, scp_recv_obj->len); -} - -void ipi_inform_ap(void) -{ - struct scp_run_t scp_run; - int ret; -#ifdef CONFIG_RPMSG_NAME_SERVICE - struct rpmsg_ns_msg ns_msg; -#endif - - scp_run.signaled = 1; - strncpy(scp_run.fw_ver, system_get_version(EC_IMAGE_RW), - SCP_FW_VERSION_LEN); - scp_run.dec_capability = VCODEC_CAPABILITY_4K_DISABLED; - scp_run.enc_capability = 0; - - ret = ipi_send(IPI_SCP_INIT, (void *)&scp_run, sizeof(scp_run), 1); - - if (ret) - ccprintf("Failed to send initialization IPC messages.\n"); - -#ifdef CONFIG_RPMSG_NAME_SERVICE - ns_msg.id = IPI_HOST_COMMAND; - strncpy(ns_msg.name, "cros-ec-rpmsg", RPMSG_NAME_SIZE); - ret = ipi_send(IPI_NS_SERVICE, &ns_msg, sizeof(ns_msg), 1); - if (ret) - ccprintf("Failed to announce host command channel.\n"); -#endif -} - -#ifdef HAS_TASK_HOSTCMD -#if defined(CONFIG_MKBP_USE_CUSTOM) -int mkbp_set_host_active_via_custom(int active, uint32_t *timestamp) -{ - static const uint8_t hc_evt_obj = HOSTCMD_TYPE_HOSTEVENT; - - /* This should be moved into ipi_send for more accuracy */ - if (timestamp) - *timestamp = __hw_clock_source_read(); - - if (active) - return ipi_send(IPI_HOST_COMMAND, &hc_evt_obj, - sizeof(hc_evt_obj), 1); - return EC_SUCCESS; -} -#endif - -static void ipi_send_response_packet(struct host_packet *pkt) -{ - int ret; - - ret = ipi_send(IPI_HOST_COMMAND, &hc_cmd_obj, - pkt->response_size + - offsetof(struct hostcmd_data, response), - 1); - if (ret) - CPRINTS("#ERR IPI HOSTCMD %d", ret); -} - -static void ipi_hostcmd_handler(int32_t id, void *buf, uint32_t len) -{ - uint8_t *in_msg = buf; - struct ec_host_request *r = (struct ec_host_request *)in_msg; - int i; - - if (in_msg[0] != EC_HOST_REQUEST_VERSION) { - CPRINTS("ERROR: Protocol V2 is not supported!"); - CPRINTF("in_msg=["); - for (i = 0; i < len; i++) - CPRINTF("%02x ", in_msg[i]); - CPRINTF("]\n"); - return; - } - - /* Protocol version 3 */ - - ipi_packet.send_response = ipi_send_response_packet; - - /* - * Just assign the buffer to request, host_packet_receive - * handles the buffer copy. - */ - ipi_packet.request = (void *)r; - ipi_packet.request_temp = NULL; - ipi_packet.request_max = IPI_MAX_REQUEST_SIZE; - ipi_packet.request_size = host_request_expected_size(r); - - ipi_packet.response = hc_cmd_obj.response; - /* Reserve space for the preamble and trailing byte */ - ipi_packet.response_max = IPI_MAX_RESPONSE_SIZE; - ipi_packet.response_size = 0; - - ipi_packet.driver_result = EC_RES_SUCCESS; - - host_packet_receive(&ipi_packet); -} -DECLARE_IPI(IPI_HOST_COMMAND, ipi_hostcmd_handler, 0); - -/* - * Get protocol information - */ -static enum ec_status ipi_get_protocol_info(struct host_cmd_handler_args *args) -{ - struct ec_response_get_protocol_info *r = args->response; - - memset(r, 0, sizeof(*r)); - r->protocol_versions |= BIT(3); - r->max_request_packet_size = IPI_MAX_REQUEST_SIZE; - r->max_response_packet_size = IPI_MAX_RESPONSE_SIZE; - - args->response_size = sizeof(*r); - - return EC_RES_SUCCESS; -} -DECLARE_HOST_COMMAND(EC_CMD_GET_PROTOCOL_INFO, ipi_get_protocol_info, - EC_VER_MASK(0)); -#endif - -static void ipi_enable_ipc0_deferred(void) -{ - /* Clear IPC0 IRQs. */ - SCP_GIPC_IN = SCP_GPIC_IN_CLEAR_ALL; - - /* All tasks are up, we can safely enable IPC0 IRQ now. */ - SCP_INTC_IRQ_ENABLE |= IPC0_IRQ_EN; - ipi_enable_irq(SCP_IRQ_IPC0); - - ipi_ready = 1; - - /* Inform AP that SCP is inited. */ - ipi_inform_ap(); - - CPRINTS("ipi init"); -} -DECLARE_DEFERRED(ipi_enable_ipc0_deferred); - -/* Initialize IPI. */ -static void ipi_init(void) -{ - /* Clear send share buffer. */ - memset(scp_send_obj, 0, sizeof(struct ipc_shared_obj)); - - /* Enable IRQ after all tasks are up. */ - hook_call_deferred(&ipi_enable_ipc0_deferred_data, 0); -} -DECLARE_HOOK(HOOK_INIT, ipi_init, HOOK_PRIO_DEFAULT); - -DECLARE_IRQ(SCP_IRQ_IPC0, ipc_handler, 4); -void ipc_handler(void) -{ - /* TODO(b/117917141): We only support IPC_ID(0) for now. */ - if (SCP_GIPC_IN & SCP_GIPC_IN_CLEAR_IPCN(0)) { - ipi_handler(); - SCP_GIPC_IN &= SCP_GIPC_IN_CLEAR_IPCN(0); - } - - SCP_GIPC_IN &= (SCP_GPIC_IN_CLEAR_ALL & ~SCP_GIPC_IN_CLEAR_IPCN(0)); -} diff --git a/chip/mt_scp/mt8183/ipi_chip.h b/chip/mt_scp/mt8183/ipi_chip.h deleted file mode 100644 index 758047951f..0000000000 --- a/chip/mt_scp/mt8183/ipi_chip.h +++ /dev/null @@ -1,116 +0,0 @@ -/* Copyright 2018 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef __CROS_EC_IPI_CHIP_H -#define __CROS_EC_IPI_CHIP_H - -#include "common.h" -#include "registers.h" - -#define IPC_MAX 1 -#define IPC_ID(n) (n) - -/* - * Length of EC version string is at most 32 byte (NULL included), which - * also aligns SCP fw_version length. - */ -#define SCP_FW_VERSION_LEN 32 - -/* - * Video decoder supported capability: - * BIT(4): 0 enable 4K - * 1 disable 4K - */ -#define VCODEC_CAPABILITY_4K_DISABLED BIT(4) - -#ifndef IPI_SCP_INIT -#error If CONFIG_IPI is enabled, IPI_SCP_INIT must be defined. -#endif - -/* - * Share buffer layout for IPI_SCP_INIT response. This structure should sync - * across kernel and EC. - */ -struct scp_run_t { - uint32_t signaled; - int8_t fw_ver[SCP_FW_VERSION_LEN]; - uint32_t dec_capability; - uint32_t enc_capability; -}; - -/* - * The layout of the IPC0 AP/SCP shared buffer. - * This should sync across kernel and EC. - */ -struct ipc_shared_obj { - /* IPI ID */ - int32_t id; - /* Length of the contents in buffer. */ - uint32_t len; - /* Shared buffer contents. */ - uint8_t buffer[CONFIG_IPC_SHARED_OBJ_BUF_SIZE]; -}; - -/* Send a IPI contents to AP. This shouldn't be used in ISR context. */ -int ipi_send(int32_t id, const void *buf, uint32_t len, int wait); - -/* Size of the rpmsg device name, should sync across kernel and EC. */ -#define RPMSG_NAME_SIZE 32 - -/* - * The layout of name service message. - * This should sync across kernel and EC. - */ -struct rpmsg_ns_msg { - /* Name of the corresponding rpmsg_driver. */ - char name[RPMSG_NAME_SIZE]; - /* IPC ID */ - uint32_t id; -}; - -/* - * IPC Handler. - */ -void ipc_handler(void); - -/* - * An IPC IRQ could be shared across many IPI handlers. - * Those handlers would usually operate on disabling or enabling the IPC IRQ. - * This may disorder the actual timing to on/off the IRQ when there are many - * tasks try to operate on it. As a result, any access to the SCP_IRQ_* - * should go through ipi_{en,dis}able_irq(), which support a counter to - * enable/disable the IRQ at correct timeing. - */ -/* Disable IPI IRQ. */ -void ipi_disable_irq(int irq); -/* Enable IPI IRQ. */ -void ipi_enable_irq(int irq); - -/* IPI tables */ -extern void (*ipi_handler_table[])(int32_t, void *, uint32_t); -extern int *ipi_wakeup_table[]; - -/* Helper macros to build the IPI handler and wakeup functions. */ -#define IPI_HANDLER(id) CONCAT3(ipi_, id, _handler) -#define IPI_WAKEUP(id) CONCAT3(ipi_, id, _wakeup) - -/* - * Macro to declare an IPI handler. - * _id: The ID of the IPI - * handler: The IPI handler function - * is_wakeup_src: Declare IPI ID as a wake-up source or not - */ -#define DECLARE_IPI(_id, handler, is_wakeup_src) \ - struct ipi_num_check##_id { \ - int tmp1[_id < IPI_COUNT ? 1 : -1]; \ - int tmp2[is_wakeup_src == 0 || is_wakeup_src == 1 ? 1 : -1]; \ - }; \ - void __keep IPI_HANDLER(_id)(int32_t id, void *buf, uint32_t len) \ - { \ - handler(id, buf, len); \ - } \ - const int __keep IPI_WAKEUP(_id) = is_wakeup_src - -#endif /* __CROS_EC_IPI_CHIP_H */ diff --git a/chip/mt_scp/mt8183/ipi_table.c b/chip/mt_scp/mt8183/ipi_table.c deleted file mode 100644 index 8569ab24a7..0000000000 --- a/chip/mt_scp/mt8183/ipi_table.c +++ /dev/null @@ -1,67 +0,0 @@ -/* Copyright 2018 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - * - * IPI handlers declaration - */ - -#include "common.h" -#include "ipi_chip.h" - -typedef void (*ipi_handler_t)(int32_t id, void *data, uint32_t len); - -#ifndef PASS -#define PASS 1 -#endif - -#define ipi_arguments int32_t id, void *data, uint32_t len - -#if PASS == 1 -void ipi_handler_undefined(ipi_arguments) { } - -const int ipi_wakeup_undefined; - -#define table(type, name, x) x - -#define ipi_x_func(suffix, args, number) \ - extern void __attribute__( \ - (used, weak, alias(STRINGIFY(ipi_##suffix##_undefined)))) \ - ipi_##number##_##suffix(args); - -#define ipi_x_var(suffix, number) \ - extern int __attribute__( \ - (weak, alias(STRINGIFY(ipi_##suffix##_undefined)))) \ - ipi_##number##_##suffix; - -#endif /* PASS == 1 */ - -#if PASS == 2 - -#undef table -#undef ipi_x_func -#undef ipi_x_var - -#define table(type, name, x) \ - type name[] __aligned(4) \ - __attribute__((section(".rodata.ipi, \"a\" @"))) = {x} - -#define ipi_x_var(suffix, number) \ - [number < IPI_COUNT ? number : -1] = &ipi_##number##_##suffix, - -#define ipi_x_func(suffix, args, number) ipi_x_var(suffix, number) - -#endif /* PASS == 2 */ - -/* - * Include generated IPI table (by util/gen_ipi_table). The contents originate - * from IPI_COUNT definition in board.h - */ -#include "ipi_table_gen.inc" - -#if PASS == 1 -#undef PASS -#define PASS 2 -#include "ipi_table.c" -BUILD_ASSERT(ARRAY_SIZE(ipi_handler_table) == IPI_COUNT); -BUILD_ASSERT(ARRAY_SIZE(ipi_wakeup_table) == IPI_COUNT); -#endif diff --git a/chip/mt_scp/mt8183/memmap.c b/chip/mt_scp/mt8183/memmap.c deleted file mode 100644 index 6d8f2b0c87..0000000000 --- a/chip/mt_scp/mt8183/memmap.c +++ /dev/null @@ -1,322 +0,0 @@ -/* Copyright 2018 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - * - * SCP memory map - */ - -#include "common.h" -#include "compile_time_macros.h" -#include "console.h" -#include "hooks.h" -#include "memmap.h" -#include "registers.h" -#include "util.h" - -/* - * Map SCP address (bits 31~28) to AP address - * - * SCP addr : AP addr - * 0x20000000 0x40000000 - * 0x30000000 0x50000000 - * 0x60000000 0x60000000 - * 0x70000000 0x70000000 - * 0x80000000 0x80000000 - * 0x90000000 0x00000000 - * 0xA0000000 0x10000000 - * 0xB0000000 0x20000000 - * 0xC0000000 0x30000000 - * 0xD0000000 0x10000000 - * 0xE0000000 0xA0000000 - * 0xF0000000 0x90000000 - */ - -#define MAP_INVALID 0xff - -static const uint8_t addr_map[16] = { - MAP_INVALID, /* 0x0: SRAM */ - MAP_INVALID, /* 0x1: Cached access (see below) */ - 0x4, 0x5, /* 0x2-0x3 */ - MAP_INVALID, MAP_INVALID, /* 0x4-0x5 (unmapped: registers) */ - 0x6, 0x7, 0x8, /* 0x6-0x8 */ - 0x0, 0x1, 0x2, 0x3, /* 0x9-0xc */ - 0x1, 0xa, 0x9 /* 0xd-0xf */ -}; - -/* - * AP addr : SCP cache addr - * 0x50000000 0x10000000 - */ -#define CACHE_TRANS_AP_ADDR 0x50000000 -#define CACHE_TRANS_SCP_CACHE_ADDR 0x10000000 -/* FIXME: This should be configurable */ -#define CACHE_TRANS_AP_SIZE 0x00400000 - -#ifdef CONFIG_DRAM_BASE -BUILD_ASSERT(CONFIG_DRAM_BASE_LOAD == CACHE_TRANS_AP_ADDR); -BUILD_ASSERT(CONFIG_DRAM_BASE == CACHE_TRANS_SCP_CACHE_ADDR); -#endif - -static void cpu_invalidate_icache(void) -{ - SCP_CACHE_OP(CACHE_ICACHE) &= ~SCP_CACHE_OP_OP_MASK; - SCP_CACHE_OP(CACHE_ICACHE) |= - OP_INVALIDATE_ALL_LINES | SCP_CACHE_OP_EN; - asm volatile("dsb; isb"); -} - -void cpu_invalidate_dcache(void) -{ - SCP_CACHE_OP(CACHE_DCACHE) &= ~SCP_CACHE_OP_OP_MASK; - SCP_CACHE_OP(CACHE_DCACHE) |= - OP_INVALIDATE_ALL_LINES | SCP_CACHE_OP_EN; - /* Read is necessary to confirm the invalidation finish. */ - REG32(CACHE_TRANS_SCP_CACHE_ADDR); - asm volatile("dsb;"); -} - -void cpu_invalidate_dcache_range(uintptr_t base, unsigned int length) -{ - size_t pos; - uintptr_t addr; - - for (pos = 0; pos < length; pos += SCP_CACHE_LINE_SIZE) { - addr = base + pos; - SCP_CACHE_OP(CACHE_DCACHE) = addr & SCP_CACHE_OP_TADDR_MASK; - SCP_CACHE_OP(CACHE_DCACHE) |= - OP_INVALIDATE_ONE_LINE_BY_ADDRESS | SCP_CACHE_OP_EN; - /* Read necessary to confirm the invalidation finish. */ - REG32(addr); - } - asm volatile("dsb;"); -} - -void cpu_clean_invalidate_dcache(void) -{ - SCP_CACHE_OP(CACHE_DCACHE) &= ~SCP_CACHE_OP_OP_MASK; - SCP_CACHE_OP(CACHE_DCACHE) |= - OP_CACHE_FLUSH_ALL_LINES | SCP_CACHE_OP_EN; - SCP_CACHE_OP(CACHE_DCACHE) &= ~SCP_CACHE_OP_OP_MASK; - SCP_CACHE_OP(CACHE_DCACHE) |= - OP_INVALIDATE_ALL_LINES | SCP_CACHE_OP_EN; - /* Read necessary to confirm the invalidation finish. */ - REG32(CACHE_TRANS_SCP_CACHE_ADDR); - asm volatile("dsb;"); -} - -void cpu_clean_invalidate_dcache_range(uintptr_t base, unsigned int length) -{ - size_t pos; - uintptr_t addr; - - for (pos = 0; pos < length; pos += SCP_CACHE_LINE_SIZE) { - addr = base + pos; - SCP_CACHE_OP(CACHE_DCACHE) = addr & SCP_CACHE_OP_TADDR_MASK; - SCP_CACHE_OP(CACHE_DCACHE) |= - OP_CACHE_FLUSH_ONE_LINE_BY_ADDRESS | SCP_CACHE_OP_EN; - SCP_CACHE_OP(CACHE_DCACHE) = addr & SCP_CACHE_OP_TADDR_MASK; - SCP_CACHE_OP(CACHE_DCACHE) |= - OP_INVALIDATE_ONE_LINE_BY_ADDRESS | SCP_CACHE_OP_EN; - /* Read necessary to confirm the invalidation finish. */ - REG32(addr); - } - asm volatile("dsb;"); -} - -static void scp_cache_init(void) -{ - int c; - const int region = 0; - - /* First make sure all caches are disabled, and reset stats. */ - for (c = 0; c < CACHE_COUNT; c++) { - /* - * Changing cache-size config may change the SRAM logical - * address in the mean time. This may break the loaded - * memory layout, and thus break the system. Cache-size - * should only be be configured in kernel driver before - * laoding the firmware. b/137920815#comment18 - */ - SCP_CACHE_CON(c) &= (SCP_CACHE_CON_CACHESIZE_MASK | - SCP_CACHE_CON_WAYEN); - SCP_CACHE_REGION_EN(c) = 0; - SCP_CACHE_ENTRY(c, region) = 0; - SCP_CACHE_END_ENTRY(c, region) = 0; - - /* Reset statistics. */ - SCP_CACHE_HCNT0U(c) = 0; - SCP_CACHE_HCNT0L(c) = 0; - SCP_CACHE_CCNT0U(c) = 0; - SCP_CACHE_CCNT0L(c) = 0; - } - - /* No "normal" remap. */ - SCP_L1_REMAP_CFG0 = 0; - SCP_L1_REMAP_CFG1 = 0; - SCP_L1_REMAP_CFG2 = 0; - SCP_L1_REMAP_CFG3 = 0; - /* - * Setup OTHER1: Remap register for addr msb 31 to 28 equal to 0x1 and - * not overlap with L1C_EXT_ADDR0 to L1C_EXT_ADDR7. - */ - SCP_L1_REMAP_OTHER = - (CACHE_TRANS_AP_ADDR >> SCP_L1_EXT_ADDR_OTHER_SHIFT) << 8; - - /* Disable sleep protect */ - SCP_SLP_PROTECT_CFG = SCP_SLP_PROTECT_CFG & - ~(P_CACHE_SLP_PROT_EN | D_CACHE_SLP_PROT_EN); - - /* Enable region 0 for both I-cache and D-cache. */ - for (c = 0; c < CACHE_COUNT; c++) { - SCP_CACHE_ENTRY(c, region) = CACHE_TRANS_SCP_CACHE_ADDR; - SCP_CACHE_END_ENTRY(c, region) = - CACHE_TRANS_SCP_CACHE_ADDR + CACHE_TRANS_AP_SIZE; - SCP_CACHE_ENTRY(c, region) |= SCP_CACHE_ENTRY_C; - - SCP_CACHE_REGION_EN(c) |= 1 << region; - - /* - * Enable cache. Note that cache size setting should have been - * done in kernel driver. b/137920815#comment18 - */ - SCP_CACHE_CON(c) |= SCP_CACHE_CON_MCEN | SCP_CACHE_CON_CNTEN0; - } - - cpu_invalidate_icache(); - cpu_invalidate_dcache(); -} - -static int command_cacheinfo(int argc, char **argv) -{ - const char cache_name[] = {'I', 'D'}; - int c; - - for (c = 0; c < 2; c++) { - uint64_t hit = ((uint64_t)SCP_CACHE_HCNT0U(c) << 32) | - SCP_CACHE_HCNT0L(c); - uint64_t access = ((uint64_t)SCP_CACHE_CCNT0U(c) << 32) | - SCP_CACHE_CCNT0L(c); - - ccprintf("%ccache hit count: %llu\n", cache_name[c], hit); - ccprintf("%ccache access count: %llu\n", cache_name[c], access); - } - - return EC_SUCCESS; -} -DECLARE_SAFE_CONSOLE_COMMAND(cacheinfo, command_cacheinfo, - NULL, - "Dump cache info"); - -void scp_memmap_init(void) -{ - /* - * Default config, LARGE DRAM not active: - * REG32(0xA0001F00) & 0x2000 != 0 - */ - - /* - * SCP_REMAP_CFG1 - * EXT_ADDR3[29:24] remap register for addr msb 31~28 equal to 0x7 - * EXT_ADDR2[21:16] remap register for addr msb 31~28 equal to 0x6 - * EXT_ADDR1[13:8] remap register for addr msb 31~28 equal to 0x3 - * EXT_ADDR0[5:0] remap register for addr msb 31~28 equal to 0x2 - */ - SCP_REMAP_CFG1 = - (uint32_t)addr_map[0x7] << 24 | - (uint32_t)addr_map[0x6] << 16 | - (uint32_t)addr_map[0x3] << 8 | - (uint32_t)addr_map[0x2]; - - /* - * SCP_REMAP_CFG2 - * EXT_ADDR7[29:24] remap register for addr msb 31~28 equal to 0xb - * EXT_ADDR6[21:16] remap register for addr msb 31~28 equal to 0xa - * EXT_ADDR5[13:8] remap register for addr msb 31~28 equal to 0x9 - * EXT_ADDR4[5:0] remap register for addr msb 31~28 equal to 0x8 - */ - SCP_REMAP_CFG2 = - (uint32_t)addr_map[0xb] << 24 | - (uint32_t)addr_map[0xa] << 16 | - (uint32_t)addr_map[0x9] << 8 | - (uint32_t)addr_map[0x8]; - /* - * SCP_REMAP_CFG3 - * AUD_ADDR[31:28] remap register for addr msb 31~28 equal to 0xd - * EXT_ADDR10[21:16]remap register for addr msb 31~28 equal to 0xf - * EXT_ADDR9[13:8] remap register for addr msb 31~28 equal to 0xe - * EXT_ADDR8[5:0] remap register for addr msb 31~28 equal to 0xc - */ - SCP_REMAP_CFG3 = - (uint32_t)addr_map[0xd] << 28 | - (uint32_t)addr_map[0xf] << 16 | - (uint32_t)addr_map[0xe] << 8 | - (uint32_t)addr_map[0xc]; - - /* Initialize cache remapping. */ - scp_cache_init(); -} - -int memmap_ap_to_scp(uintptr_t ap_addr, uintptr_t *scp_addr) -{ - int i; - uint8_t msb = ap_addr >> SCP_REMAP_ADDR_SHIFT; - - for (i = 0; i < ARRAY_SIZE(addr_map); i++) { - if (addr_map[i] != msb) - continue; - - *scp_addr = (ap_addr & SCP_REMAP_ADDR_LSB_MASK) | - (i << SCP_REMAP_ADDR_SHIFT); - return EC_SUCCESS; - } - - return EC_ERROR_INVAL; -} - -int memmap_scp_to_ap(uintptr_t scp_addr, uintptr_t *ap_addr) -{ - int i = scp_addr >> SCP_REMAP_ADDR_SHIFT; - - if (addr_map[i] == MAP_INVALID) - return EC_ERROR_INVAL; - - *ap_addr = (scp_addr & SCP_REMAP_ADDR_LSB_MASK) | - (addr_map[i] << SCP_REMAP_ADDR_SHIFT); - return EC_SUCCESS; -} - -#ifdef CONFIG_DRAM_BASE -BUILD_ASSERT(CONFIG_DRAM_BASE_LOAD == CACHE_TRANS_AP_ADDR); -BUILD_ASSERT(CONFIG_DRAM_BASE == CACHE_TRANS_SCP_CACHE_ADDR); -#endif - -int memmap_ap_to_scp_cache(uintptr_t ap_addr, uintptr_t *scp_addr) -{ - uintptr_t lsb; - - if ((ap_addr & SCP_L1_EXT_ADDR_OTHER_MSB_MASK) != CACHE_TRANS_AP_ADDR) - return EC_ERROR_INVAL; - - lsb = ap_addr & SCP_L1_EXT_ADDR_OTHER_LSB_MASK; - if (lsb > CACHE_TRANS_AP_SIZE) - return EC_ERROR_INVAL; - - *scp_addr = CACHE_TRANS_SCP_CACHE_ADDR | lsb; - return EC_SUCCESS; -} - -int memmap_scp_cache_to_ap(uintptr_t scp_addr, uintptr_t *ap_addr) -{ - uintptr_t lsb; - - if ((scp_addr & SCP_L1_EXT_ADDR_OTHER_MSB_MASK) != - CACHE_TRANS_SCP_CACHE_ADDR) - return EC_ERROR_INVAL; - - lsb = scp_addr & SCP_L1_EXT_ADDR_OTHER_LSB_MASK; - if (lsb >= CACHE_TRANS_AP_SIZE) - return EC_ERROR_INVAL; - - *ap_addr = CACHE_TRANS_AP_ADDR | lsb; - return EC_SUCCESS; -} diff --git a/chip/mt_scp/mt8183/memmap.h b/chip/mt_scp/mt8183/memmap.h deleted file mode 100644 index fbecb5e8cf..0000000000 --- a/chip/mt_scp/mt8183/memmap.h +++ /dev/null @@ -1,49 +0,0 @@ -/* Copyright 2018 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - * - * SCP memory map - */ - -#ifndef __CROS_EC_MEMMAP_H -#define __CROS_EC_MEMMAP_H - -void scp_memmap_init(void); - -/** - * Translate AP addr to SCP addr. - * - * @param ap_addr AP address to translate - * @param scp_addr Tranlated AP address - * @return EC_SUCCESS or EC_ERROR_INVAL - */ -int memmap_ap_to_scp(uintptr_t ap_addr, uintptr_t *scp_addr); - -/** - * Translate SCP addr to AP addr. - * - * @param scp_addr SCP address to tranlate - * @param ap_addr Translated SCP address - * @return EC_SUCCESS or EC_ERROR_INVAL - */ -int memmap_scp_to_ap(uintptr_t scp_addr, uintptr_t *ap_addr); - -/** - * Translate AP addr to SCP cache addr. - * - * @param ap_addr AP address to translate - * @param scp_addr Tranlated AP cache address - * @return EC_SUCCESS or EC_ERROR_INVAL - */ -int memmap_ap_to_scp_cache(uintptr_t ap_addr, uintptr_t *scp_addr); - -/** - * Translate SCP addr to AP addr. - * - * @param scp_addr SCP cache address to tranlate - * @param ap_addr Translated SCP cache address - * @return EC_SUCCESS or EC_ERROR_INVAL - */ -int memmap_scp_cache_to_ap(uintptr_t scp_addr, uintptr_t *ap_addr); - -#endif /* #ifndef __CROS_EC_MEMMAP_H */ diff --git a/chip/mt_scp/mt8183/registers.h b/chip/mt_scp/mt8183/registers.h deleted file mode 100644 index 21270b452d..0000000000 --- a/chip/mt_scp/mt8183/registers.h +++ /dev/null @@ -1,645 +0,0 @@ -/* Copyright 2018 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - * - * Register map for SCP - */ - -#ifndef __CROS_EC_REGISTERS_H -#define __CROS_EC_REGISTERS_H - -#include "common.h" -#include "compile_time_macros.h" - -/* IRQ numbers */ -#define SCP_IRQ_IPC0 0 -#define SCP_IRQ_IPC1 1 -#define SCP_IRQ_IPC2 2 -#define SCP_IRQ_IPC3 3 -#define SCP_IRQ_SPM 4 -#define SCP_IRQ_CIRQ 5 -#define SCP_IRQ_EINT 6 -#define SCP_IRQ_PMIC 7 -#define SCP_IRQ_UART0 8 -#define SCP_IRQ_UART1 9 -#define SCP_IRQ_I2C0 10 -#define SCP_IRQ_I2C1 11 -#define SCP_IRQ_I2C2 12 -#define SCP_IRQ_CLOCK 13 -#define SCP_IRQ_MAD_FIFO 14 -#define SCP_IRQ_TIMER0 15 -#define SCP_IRQ_TIMER1 16 -#define SCP_IRQ_TIMER2 17 -#define SCP_IRQ_TIMER3 18 -#define SCP_IRQ_TIMER4 19 -#define SCP_IRQ_TIMER5 20 -#define SCP_IRQ_TIMER_STATUS 21 -#define SCP_IRQ_UART0_RX 22 -#define SCP_IRQ_UART1_RX 23 -#define SCP_IRQ_DMA 24 -#define SCP_IRQ_AUDIO 25 -#define SCP_IRQ_MD1_F216 26 -#define SCP_IRQ_MD1 27 -#define SCP_IRQ_C2K 28 -#define SCP_IRQ_SPI0 29 -#define SCP_IRQ_SPI1 30 -#define SCP_IRQ_SPI2 31 -#define SCP_IRQ_AP_EINT 32 -#define SCP_IRQ_DEBUG 33 -#define SCP_CCIF0 34 -#define SCP_CCIF1 35 -#define SCP_CCIF2 36 -#define SCP_IRQ_WDT 37 -#define SCP_IRQ_USB0 38 -#define SCP_IRQ_USB1 39 -#define SCP_IRQ_TWAM 40 -#define SCP_IRQ_INFRA 41 -#define SCP_IRQ_HWDVFS_HIGH 42 -#define SCP_IRQ_HWDVFS_LOW 43 -#define SCP_IRQ_CLOCK2 44 -/* RESERVED 45-52 */ -#define SCP_IRQ_AP_EINT2 53 -#define SCP_IRQ_AP_EINT_EVT 54 -#define SCP_IRQ_MAD_DATA 55 - -#define SCP_CFG_BASE 0x405C0000 - -#define SCP_AP_RESOURCE REG32(SCP_CFG_BASE + 0x04) -#define SCP_BUS_RESOURCE REG32(SCP_CFG_BASE + 0x08) - -/* SCP to host interrupt */ -#define SCP_HOST_INT REG32(SCP_CFG_BASE + 0x1C) -#define IPC_SCP2HOST_SSHUB 0xff0000 -#define WDT_INT 0x100 -#define IPC_SCP2HOST 0xff -#define IPC_SCP2HOST_BIT 0x1 - -/* SCP to SPM interrupt */ -#define SCP_SPM_INT REG32(SCP_CFG_BASE + 0x20) -#define SPM_INT_A2SPM BIT(0) -#define SPM_INT_B2SPM BIT(1) -#define SCP_SPM_INT2 REG32(SCP_CFG_BASE + 0x24) - -/* - * AP side to SCP IPC - * APMCU writes 1 bit to trigger ith IPC to SCP. - * SCP writes 1 bit to ith bit to clear ith IPC. - */ -#define SCP_GIPC_IN REG32(SCP_CFG_BASE + 0x28) - #define SCP_GIPC_IN_CLEAR_IPCN(n) (1 << (n)) - #define SCP_GPIC_IN_CLEAR_ALL 0x7FFFF -#define SCP_CONN_INT REG32(SCP_CFG_BASE + 0x2C) - -/* 8 general purpose registers, 0 ~ 7 */ -#define SCP_GPR REG32_ADDR(SCP_CFG_BASE + 0x50) -/* - * SCP_GPR[0] - * b15-b0 : scratchpad - * b31-b16 : saved flags - * SCP_GPR[1] - * b15-b0 : power on state - */ -#define SCP_PWRON_STATE SCP_GPR[1] -#define PWRON_DEFAULT 0xdee80000 -#define PWRON_WATCHDOG BIT(0) -#define PWRON_RESET BIT(1) -/* AP defined features */ -#define SCP_EXPECTED_FREQ SCP_GPR[3] -#define SCP_CURRENT_FREQ SCP_GPR[4] -#define SCP_REBOOT SCP_GPR[5] -#define READY_TO_REBOOT 0x34 -#define REBOOT_OK 1 - -/* Miscellaneous */ -#define SCP_SEMAPHORE REG32(SCP_CFG_BASE + 0x90) -#define CORE_CONTROL REG32(SCP_CFG_BASE + 0xA0) -#define CORE_FPU_FLAGS REG32(SCP_CFG_BASE + 0xA4) -#define CORE_REG_SP REG32(SCP_CFG_BASE + 0xA8) -#define CORE_REG_LR REG32(SCP_CFG_BASE + 0xAC) -#define CORE_REG_PSP REG32(SCP_CFG_BASE + 0xB0) -#define CORE_REG_PC REG32(SCP_CFG_BASE + 0xB4) -#define SCP_SLP_PROTECT_CFG REG32(SCP_CFG_BASE + 0xC8) -#define P_CACHE_SLP_PROT_EN BIT(3) -#define D_CACHE_SLP_PROT_EN BIT(4) -#define SCP_ONE_TIME_LOCK REG32(SCP_CFG_BASE + 0xDC) -#define SCP_SECURE_CTRL REG32(SCP_CFG_BASE + 0xE0) -#define ENABLE_SPM_MASK_VREQ BIT(28) -#define DISABLE_REMAP BIT(22) -#define DISABLE_JTAG BIT(21) -#define DISABLE_AP_TCM BIT(20) -#define SCP_SYS_CTRL REG32(SCP_CFG_BASE + 0xE4) -#define DDREN_FIX_VALUE BIT(28) -#define AUTO_DDREN BIT(18) - -/* Memory remap control */ -/* - * EXT_ADDR3[29:24] remap register for addr msb 31~28 equal to 0x7 - * EXT_ADDR2[21:16] remap register for addr msb 31~28 equal to 0x6 - * EXT_ADDR1[13:8] remap register for addr msb 31~28 equal to 0x3 - * EXT_ADDR0[5:0] remap register for addr msb 31~28 equal to 0x2 - */ -#define SCP_REMAP_CFG1 REG32(SCP_CFG_BASE + 0x120) -/* - * EXT_ADDR7[29:24] remap register for addr msb 31~28 equal to 0xb - * EXT_ADDR6[21:16] remap register for addr msb 31~28 equal to 0xa - * EXT_ADDR5[13:8] remap register for addr msb 31~28 equal to 0x9 - * EXT_ADDR4[5:0] remap register for addr msb 31~28 equal to 0x8 - */ -#define SCP_REMAP_CFG2 REG32(SCP_CFG_BASE + 0x124) -/* - * AUD_ADDR[31:28] remap register for addr msb 31~28 equal to 0xd - * EXT_ADDR10[21:16]remap register for addr msb 31~28 equal to 0xf - * EXT_ADDR9[13:8] remap register for addr msb 31~28 equal to 0xe - * EXT_ADDR8[5:0] remap register for addr msb 31~28 equal to 0xc - */ -#define SCP_REMAP_CFG3 REG32(SCP_CFG_BASE + 0x128) - -#define SCP_REMAP_ADDR_SHIFT 28 -#define SCP_REMAP_ADDR_LSB_MASK (BIT(SCP_REMAP_ADDR_SHIFT) - 1) -#define SCP_REMAP_ADDR_MSB_MASK ((~0) << SCP_REMAP_ADDR_SHIFT) - -/* Cached memory remap control */ -#define SCP_L1_REMAP_CFG0 REG32(SCP_CFG_BASE + 0x12C) -/* - * L1C_EXT_ADDR1[29:16] remap register for addr msb 31~20 equal to 0x401 - * L1C_EXT_ADDR0[13:0] remap register for addr msb 31~20 equal to 0x400 - */ -#define SCP_L1_REMAP_CFG1 REG32(SCP_CFG_BASE + 0x130) -/* - * L1C_EXT_ADDR3[29:16] remap register for addr msb 31~20 equal to 0x403 - * L1C_EXT_ADDR2[13:0] remap register for addr msb 31~20 equal to 0x402 - */ -#define SCP_L1_REMAP_CFG2 REG32(SCP_CFG_BASE + 0x134) -/* - * L1C_EXT_ADDR5[29:16] remap register for addr msb 31~20 equal to 0x405 - * L1C_EXT_ADDR4[13:0] remap register for addr msb 31~20 equal to 0x404 - */ -#define SCP_L1_REMAP_CFG3 REG32(SCP_CFG_BASE + 0x138) -/* - * L1C_EXT_ADDR_OTHER1[13:8] Remap register for addr msb 31 to 28 equal to 0x1 - * L1C_EXT_ADDR_OTHER0[5:0] Remap register for addr msb 31 to 28 equal to 0x0 - * and not overlap with L1C_EXT_ADDR0 to L1C_EXT_ADDR7 - */ -#define SCP_L1_REMAP_OTHER REG32(SCP_CFG_BASE + 0x13C) - -#define SCP_L1_EXT_ADDR_SHIFT 20 -#define SCP_L1_EXT_ADDR_OTHER_SHIFT 28 -#define SCP_L1_EXT_ADDR_OTHER_LSB_MASK (BIT(SCP_REMAP_ADDR_SHIFT) - 1) -#define SCP_L1_EXT_ADDR_OTHER_MSB_MASK ((~0) << SCP_REMAP_ADDR_SHIFT) - -/* Audio/voice FIFO */ -#define SCP_AUDIO_BASE (SCP_CFG_BASE + 0x1000) -#define SCP_VIF_FIFO_EN REG32(SCP_AUDIO_BASE) -#define VIF_FIFO_RSTN (1 << 0) -#define VIF_FIFO_IRQ_EN (1 << 1) -#define VIF_FIFO_SRAM_PWR (1 << 2) -#define VIF_FIFO_RSTN_STATUS (1 << 4) -#define SCP_VIF_FIFO_STATUS REG32(SCP_AUDIO_BASE + 0x04) -#define VIF_FIFO_VALID (1 << 0) -#define VIF_FIFO_FULL (1 << 4) -#define VIF_FIFO_LEVEL(status) (((status) >> 16) & 0xff) -#define VIF_FIFO_MAX 256 -#define SCP_VIF_FIFO_DATA REG32(SCP_AUDIO_BASE + 0x08) -#define SCP_VIF_FIFO_DATA_THRE REG32(SCP_AUDIO_BASE + 0x0C) -/* VIF IRQ status clears on read! */ -#define SCP_VIF_FIFO_IRQ_STATUS REG32(SCP_AUDIO_BASE + 0x10) -/* Audio/voice serial interface */ -#define SCP_RXIF_CFG0 REG32(SCP_AUDIO_BASE + 0x14) -#define RXIF_CFG0_RESET_VAL 0x2A130001 -#define RXIF_AFE_ON (1 << 0) -#define RXIF_SCKINV (1 << 1) -#define RXIF_RG_DL_2_IN_MODE(mode) (((mode) & 0xf) << 8) -#define RXIF_RGDL2_AMIC_16K (0x1 << 8) -#define RXIF_RGDL2_DMIC_16K (0x2 << 8) -#define RXIF_RGDL2_DMIC_LP_16K (0x3 << 8) -#define RXIF_RGDL2_AMIC_32K (0x5 << 8) -#define RXIF_RGDL2_MASK (0xf << 8) -#define RXIF_UP8X_RSP(p) (((p) & 0x7) << 16) -#define RXIF_RG_RX_READEN (1 << 19) -#define RXIF_MONO (1 << 20) -#define RXIF_RG_CLK_A16P7K_EN(cnt) (((cnt) & 0xff) << 24) -#define SCP_RXIF_CFG1 REG32(SCP_AUDIO_BASE + 0x18) -#define RXIF_CFG1_RESET_VAL 0x33180014 -#define RXIF_RG_SYNC_CNT_TBL(t) ((t) & 0x1ff) -#define RXIF_RG_SYNC_SEARCH_TBL(t) (((t) & 0x1f) << 16) -#define RXIF_RG_SYNC_CHECK_ROUND(r) (((r) & 0xf) << 24) -#define RXIF_RG_INSYNC_CHECK_ROUND(r) (((r) & 0xf) << 28) -#define SCP_RXIF_CFG2 REG32(SCP_AUDIO_BASE + 0x1C) -#define RXIF_SYNC_WORD(w) ((w) & 0xffff) -#define SCP_RXIF_OUT REG32(SCP_AUDIO_BASE + 0x20) -#define SCP_RXIF_STATUS REG32(SCP_AUDIO_BASE + 0x24) -#define SCP_RXIF_IRQ_EN REG32(SCP_AUDIO_BASE + 0x28) - -/* INTC control */ -#define SCP_INTC_BASE (SCP_CFG_BASE + 0x2000) -#define SCP_INTC_IRQ_STATUS REG32(SCP_INTC_BASE) -#define SCP_INTC_IRQ_ENABLE REG32(SCP_INTC_BASE + 0x04) -#define IPC0_IRQ_EN BIT(0) -#define SCP_INTC_IRQ_OUTPUT REG32(SCP_INTC_BASE + 0x08) -#define SCP_INTC_IRQ_WAKEUP REG32(SCP_INTC_BASE + 0x0C) -#define SCP_INTC_NMI REG32(SCP_INTC_BASE + 0x10) -#define SCP_INTC_SPM_WAKEUP REG32(SCP_INTC_BASE + 0x14) -#define SCP_INTC_SPM_WAKEUP_MSB REG32(SCP_INTC_BASE + 0x18) -#define SCP_INTC_UART_RX_IRQ REG32(SCP_INTC_BASE + 0x1C) -#define SCP_INTC_IRQ_STATUS_MSB REG32(SCP_INTC_BASE + 0x80) -#define SCP_INTC_IRQ_ENABLE_MSB REG32(SCP_INTC_BASE + 0x84) -#define SCP_INTC_IRQ_OUTPUT_MSB REG32(SCP_INTC_BASE + 0x88) -#define SCP_INTC_IRQ_WAKEUP_MSB REG32(SCP_INTC_BASE + 0x8C) - -/* Timer */ -#define NUM_TIMERS 6 -#define SCP_TIMER_BASE(n) (SCP_CFG_BASE + 0x3000 + (0x10 * (n))) -#define SCP_TIMER_EN(n) REG32(SCP_TIMER_BASE(n)) -#define SCP_TIMER_RESET_VAL(n) REG32(SCP_TIMER_BASE(n) + 0x04) -#define SCP_TIMER_VAL(n) REG32(SCP_TIMER_BASE(n) + 0x08) -#define SCP_TIMER_IRQ_CTRL(n) REG32(SCP_TIMER_BASE(n) + 0x0C) -#define TIMER_IRQ_ENABLE BIT(0) -#define TIMER_IRQ_STATUS BIT(4) -#define TIMER_IRQ_CLEAR BIT(5) -#define SCP_TIMER_CLK_SEL(n) REG32(SCP_TIMER_BASE(n) + 0x40) -#define TIMER_CLK_32K (0 << 4) -#define TIMER_CLK_26M BIT(4) -#define TIMER_CLK_BCLK (2 << 4) -#define TIMER_CLK_PCLK (3 << 4) -#define TIMER_CLK_MASK (3 << 4) -/* OS timer */ -#define SCP_OSTIMER_BASE (SCP_CFG_BASE + 0x3080) -#define SCP_OSTIMER_CON REG32(SCP_OSTIMER_BASE) -#define SCP_OSTIMER_INIT_L REG32(SCP_OSTIMER_BASE + 0x04) -#define SCP_OSTIMER_INIT_H REG32(SCP_OSTIMER_BASE + 0x08) -#define SCP_OSTIMER_VAL_L REG32(SCP_OSTIMER_BASE + 0x0C) -#define SCP_OSTIMER_VAL_H REG32(SCP_OSTIMER_BASE + 0x10) -#define SCP_OSTIMER_TVAL REG32(SCP_OSTIMER_BASE + 0x14) -#define SCP_OSTIMER_IRQ_ACK REG32(SCP_OSTIMER_BASE + 0x18) -#define OSTIMER_LATCH0_EN BIT(5) -#define OSTIMER_LATCH1_EN BIT(13) -#define OSTIMER_LATCH2_EN BIT(21) -#define SCP_OSTIMER_LATCH_CTRL REG32(SCP_OSTIMER_BASE + 0x20) -#define SCP_OSTIMER_LATCH0_L REG32(SCP_OSTIMER_BASE + 0x24) -#define SCP_OSTIMER_LATCH0_H REG32(SCP_OSTIMER_BASE + 0x28) -#define SCP_OSTIMER_LATCH1_L REG32(SCP_OSTIMER_BASE + 0x2C) -#define SCP_OSTIMER_LATCH1_H REG32(SCP_OSTIMER_BASE + 0x30) -#define SCP_OSTIMER_LATCH2_L REG32(SCP_OSTIMER_BASE + 0x34) -#define SCP_OSTIMER_LATCH2_H REG32(SCP_OSTIMER_BASE + 0x38) - -/* Clock, PMIC wrapper, etc. */ -#define SCP_CLK_BASE (SCP_CFG_BASE + 0x4000) -#define SCP_CLK_SEL REG32(SCP_CLK_BASE) -#define CLK_SEL_SYS_26M 0 -#define CLK_SEL_32K 1 -#define CLK_SEL_ULPOSC_2 2 -#define CLK_SEL_ULPOSC_1 3 - -#define SCP_CLK_EN REG32(SCP_CLK_BASE + 0x04) -#define EN_CLK_SYS BIT(0) /* System clock */ -#define EN_CLK_HIGH BIT(1) /* ULPOSC */ -#define CG_CLK_HIGH BIT(2) -#define EN_SYS_IRQ BIT(16) -#define EN_HIGH_IRQ BIT(17) -#define SCP_CLK_SAFE_ACK REG32(SCP_CLK_BASE + 0x08) -#define SCP_CLK_ACK REG32(SCP_CLK_BASE + 0x0C) -#define SCP_CLK_IRQ_ACK REG32(SCP_CLK_BASE + 0x10) -/* - * System clock counter value. - * CLK_SYS_VAL[9:0] System clock counter initial/reset value. - */ -#define SCP_CLK_SYS_VAL REG32(SCP_CLK_BASE + 0x14) -#define CLK_SYS_VAL_MASK 0x3ff /* 10 bits */ -#define CLK_SYS_VAL(n) ((n) & CLK_SYS_VAL_MASK) -/* - * ULPOSC clock counter value. - * CLK_HIGH_VAL[9:0] ULPOSC clock counter initial/reset value. - */ -#define SCP_CLK_HIGH_VAL REG32(SCP_CLK_BASE + 0x18) -#define CLK_HIGH_VAL_MASK 0x3ff /* 10 bits */ -#define CLK_HIGH_VAL(n) ((n) & CLK_HIGH_VAL_MASK) -#define SCP_CLK_SLOW_SEL REG32(SCP_CLK_BASE + 0x1C) -#define CKSW_SEL_SLOW_MASK 0x3 -#define CKSW_SEL_SLOW_DIV_MASK 0x30 -#define CKSW_SEL_SLOW_SYS_CLK 0 -#define CKSW_SEL_SLOW_32K_CLK 1 -#define CKSW_SEL_SLOW_ULPOSC2_CLK 2 -#define CKSW_SEL_SLOW_ULPOSC1_CLK 3 -/* - * Sleep mode control. - * VREQ_COUNT[7:1] Number of cycles to wait when requesting PMIC to raise the - * voltage after returning from sleep mode. - */ -#define SCP_CLK_SLEEP_CTRL REG32(SCP_CLK_BASE + 0x20) -#define EN_SLEEP_CTRL BIT(0) -#define VREQ_COUNTER_MASK 0xfe -#define VREQ_COUNTER_VAL(v) (((v) << 1) & VREQ_COUNTER_MASK) -#define SPM_SLEEP_MODE BIT(8) -#define SPM_SLEEP_MODE_CLK_AO BIT(9) -#define SCP_CLK_DIV_SEL REG32(SCP_CLK_BASE + 0x24) -#define CLK_DIV1 0 -#define CLK_DIV2 1 -#define CLK_DIV4 2 -#define CLK_DIV8 3 -#define SCP_CLK_DEBUG REG32(SCP_CLK_BASE + 0x28) -#define SCP_CLK_SRAM_POWERDOWN REG32(SCP_CLK_BASE + 0x2C) -#define SCP_CLK_GATE REG32(SCP_CLK_BASE + 0x30) -#define CG_TIMER_M BIT(0) -#define CG_TIMER_B BIT(1) -#define CG_MAD_M BIT(2) -#define CG_I2C_M BIT(3) -#define CG_I2C_B BIT(4) -#define CG_GPIO_M BIT(5) -#define CG_AP2P_M BIT(6) -#define CG_UART_M BIT(7) -#define CG_UART_B BIT(8) -#define CG_UART_RSTN BIT(9) -#define CG_UART1_M BIT(10) -#define CG_UART1_B BIT(11) -#define CG_UART1_RSTN BIT(12) -#define CG_SPI0 BIT(13) -#define CG_SPI1 BIT(14) -#define CG_SPI2 BIT(15) -#define CG_DMA_CH0 BIT(16) -#define CG_DMA_CH1 BIT(17) -#define CG_DMA_CH2 BIT(18) -#define CG_DMA_CH3 BIT(19) -#define CG_TWAM BIT(20) -#define CG_CACHE_I_CTRL BIT(21) -#define CG_CACHE_D_CTRL BIT(22) -#define SCP_PMICW_CTRL REG32(SCP_CLK_BASE + 0x34) -#define PMICW_SLEEP_REQ BIT(0) -#define PMICW_SLEEP_ACK BIT(4) -#define PMICW_CLK_MUX BIT(8) -#define PMICW_DCM BIT(9) -#define SCP_SLEEP_WAKE_DEBUG REG32(SCP_CLK_BASE + 0x38) -#define SCP_DCM_EN REG32(SCP_CLK_BASE + 0x3C) -#define SCP_WAKE_CKSW REG32(SCP_CLK_BASE + 0x40) -#define WAKE_CKSW_SEL_NORMAL_MASK 0x3 -#define WAKE_CKSW_SEL_SLOW_MASK 0x30 -#define WAKE_CKSW_SEL_SLOW_DEFAULT 0x10 -#define SCP_CLK_UART REG32(SCP_CLK_BASE + 0x44) -#define CLK_UART_SEL_MASK 0x3 -#define CLK_UART_SEL_26M 0x0 -#define CLK_UART_SEL_32K 0x1 -/* This is named ulposc_div_to_26m in datasheet */ -#define CLK_UART_SEL_ULPOSC1_DIV10 0x2 -#define CLK_UART1_SEL_MASK (0x3 << 16) -#define CLK_UART1_SEL_26M (0x0 << 16) -#define CLK_UART1_SEL_32K (0x1 << 16) -/* This is named ulposc_div_to_26m in datasheet */ -#define CLK_UART1_SEL_ULPOSC1_DIV10 (0x2 << 16) -#define SCP_CLK_BCLK REG32(SCP_CLK_BASE + 0x48) -#define CLK_BCLK_SEL_MASK 0x3 -#define CLK_BCLK_SEL_SYS_DIV8 0x0 -#define CLK_BCLK_SEL_32K 0x1 -#define CLK_BCLK_SEL_ULPOSC1_DIV8 0x2 -#define SCP_CLK_SPI_BCK REG32(SCP_CLK_BASE + 0x4C) -#define SCP_CLK_DIV_CNT REG32(SCP_CLK_BASE + 0x50) -#define SCP_CPU_VREQ REG32(SCP_CLK_BASE + 0x54) -#define CPU_VREQ_HW_MODE 0x10001 -#define SCP_CLK_CLEAR REG32(SCP_CLK_BASE + 0x58) -#define SCP_CLK_HIGH_CORE REG32(SCP_CLK_BASE + 0x5C) -#define CLK_HIGH_CORE_CG (1 << 1) -#define SCP_SLEEP_IRQ2 REG32(SCP_CLK_BASE + 0x64) -#define SCP_CLK_ON_CTRL REG32(SCP_CLK_BASE + 0x6C) -#define HIGH_AO BIT(0) -#define HIGH_CG_AO BIT(2) -#define HIGH_CORE_AO BIT(4) -#define HIGH_CORE_DIS_SUB BIT(5) -#define HIGH_CORE_CG_AO BIT(6) -#define HIGH_FINAL_VAL_MASK 0x1f00 -#define HIGH_FINAL_VAL_DEFAULT 0x300 -#define SCP_CLK_L1_SRAM_PD REG32(SCP_CLK_BASE + 0x80) -#define SCP_CLK_TCM_TAIL_SRAM_PD REG32(SCP_CLK_BASE + 0x94) -#define SCP_CLK_SLEEP REG32(SCP_CLK_BASE + 0xA0) -#define SLOW_WAKE_DISABLE 1 -#define SCP_FAST_WAKE_CNT_END REG32(SCP_CLK_BASE + 0xA4) -#define FAST_WAKE_CNT_END_MASK 0xfff -#define FAST_WAKE_CNT_END_DEFAULT 0x18 -#define MEM_CK_CS_ISO_CNT_END_MASK 0x7f0000 - -/* Peripherals */ -#define SCP_I2C0_BASE (SCP_CFG_BASE + 0x5000) -#define SCP_I2C1_BASE (SCP_CFG_BASE + 0x6000) -#define SCP_I2C2_BASE (SCP_CFG_BASE + 0x7000) - -#define SCP_GPIO_BASE (SCP_CFG_BASE + 0x8000) -#define SCP_UART0_BASE (SCP_CFG_BASE + 0x9000) -#define SCP_UART1_BASE (SCP_CFG_BASE + 0xE000) -#define SCP_UART_COUNT 2 - -/* External GPIO interrupt */ -#define SCP_EINT_BASE (SCP_CFG_BASE + 0xA000) -#define SCP_EINT_STATUS REG32_ADDR(SCP_EINT_BASE) -#define SCP_EINT_ACK REG32_ADDR(SCP_EINT_BASE + 0x040) -#define SCP_EINT_MASK_GET REG32_ADDR(SCP_EINT_BASE + 0x080) -#define SCP_EINT_MASK_SET REG32_ADDR(SCP_EINT_BASE + 0x0C0) -#define SCP_EINT_MASK_CLR REG32_ADDR(SCP_EINT_BASE + 0x100) -#define SCP_EINT_SENS_GET REG32_ADDR(SCP_EINT_BASE + 0x140) -#define SCP_EINT_SENS_SET REG32_ADDR(SCP_EINT_BASE + 0x180) -#define SCP_EINT_SENS_CLR REG32_ADDR(SCP_EINT_BASE + 0x1C0) -#define SCP_EINT_SOFT_GET REG32_ADDR(SCP_EINT_BASE + 0x200) -#define SCP_EINT_SOFT_SET REG32_ADDR(SCP_EINT_BASE + 0x240) -#define SCP_EINT_SOFT_CLR REG32_ADDR(SCP_EINT_BASE + 0x280) -#define SCP_EINT_POLARITY_GET REG32_ADDR(SCP_EINT_BASE + 0x300) -#define SCP_EINT_POLARITY_SET REG32_ADDR(SCP_EINT_BASE + 0x340) -#define SCP_EINT_POLARITY_CLR REG32_ADDR(SCP_EINT_BASE + 0x380) -#define SCP_EINT_D0_EN REG32_ADDR(SCP_EINT_BASE + 0x400) -#define SCP_EINT_D1_EN REG32_ADDR(SCP_EINT_BASE + 0x420) -#define SCP_EINT_DBNC_GET REG32_ADDR(SCP_EINT_BASE + 0x500) -#define SCP_EINT_DBNC_SET REG32_ADDR(SCP_EINT_BASE + 0x600) -#define SCP_EINT_DBNC_CLR REG32_ADDR(SCP_EINT_BASE + 0x700) - -#define SCP_PMICWP2P_BASE (SCP_CFG_BASE + 0xB000) -#define PMICW_WACS_CMD REG32(SCP_PMICWP2P_BASE + 0x200) -#define PMICW_WACS_RDATA REG32(SCP_PMICWP2P_BASE + 0x204) -#define PMICW_WACS_VLDCLR REG32(SCP_PMICWP2P_BASE + 0x208) -#define SCP_SPMP2P_BASE (SCP_CFG_BASE + 0xC000) -#define SCP_DMA_BASE (SCP_CFG_BASE + 0xD000) -#define DMA_ACKINT_CHX REG32(SCP_DMA_BASE + 0x20) -#define SCP_SPI0_BASE (SCP_CFG_BASE + 0xF000) -#define SCP_SPI1_BASE (SCP_CFG_BASE + 0x10000) -#define SCP_SPI2_BASE (SCP_CFG_BASE + 0x11000) - -#define CACHE_ICACHE 0 -#define CACHE_DCACHE 1 -#define CACHE_COUNT 2 -#define SCP_CACHE_BASE (SCP_CFG_BASE + 0x14000) -#define SCP_CACHE_SEL(x) (SCP_CACHE_BASE + (x)*0x3000) -#define SCP_CACHE_CON(x) REG32(SCP_CACHE_SEL(x)) -#define SCP_CACHE_CON_MCEN BIT(0) -#define SCP_CACHE_CON_CNTEN0 BIT(2) -#define SCP_CACHE_CON_CNTEN1 BIT(3) -#define SCP_CACHE_CON_CACHESIZE_SHIFT 8 -#define SCP_CACHE_CON_CACHESIZE_MASK (0x3 << SCP_CACHE_CON_CACHESIZE_SHIFT) -#define SCP_CACHE_CON_CACHESIZE_0KB (0x0 << SCP_CACHE_CON_CACHESIZE_SHIFT) -#define SCP_CACHE_CON_CACHESIZE_8KB (0x1 << SCP_CACHE_CON_CACHESIZE_SHIFT) -#define SCP_CACHE_CON_CACHESIZE_16KB (0x2 << SCP_CACHE_CON_CACHESIZE_SHIFT) -#define SCP_CACHE_CON_CACHESIZE_32KB (0x3 << SCP_CACHE_CON_CACHESIZE_SHIFT) -#define SCP_CACHE_CON_WAYEN BIT(10) - -#define SCP_CACHE_OP(x) REG32(SCP_CACHE_SEL(x) + 0x04) -#define SCP_CACHE_OP_EN BIT(0) -#define SCP_CACHE_OP_OP_SHIFT 1 -#define SCP_CACHE_OP_OP_MASK (0xf << SCP_CACHE_OP_OP_SHIFT) - -#define OP_INVALIDATE_ALL_LINES (0x1 << SCP_CACHE_OP_OP_SHIFT) -#define OP_INVALIDATE_ONE_LINE_BY_ADDRESS (0x2 << SCP_CACHE_OP_OP_SHIFT) -#define OP_INVALIDATE_ONE_LINE_BY_SET_WAY (0x4 << SCP_CACHE_OP_OP_SHIFT) -#define OP_CACHE_FLUSH_ALL_LINES (0x9 << SCP_CACHE_OP_OP_SHIFT) -#define OP_CACHE_FLUSH_ONE_LINE_BY_ADDRESS (0xa << SCP_CACHE_OP_OP_SHIFT) -#define OP_CACHE_FLUSH_ONE_LINE_BY_SET_WAY (0xc << SCP_CACHE_OP_OP_SHIFT) - -#define SCP_CACHE_OP_TADDR_SHIFT 5 -#define SCP_CACHE_OP_TADDR_MASK (0x7ffffff << SCP_CACHE_OP_TADDR_SHIFT) -#define SCP_CACHE_LINE_SIZE BIT(SCP_CACHE_OP_TADDR_SHIFT) - -/* Cache statistics */ -#define SCP_CACHE_HCNT0L(x) REG32(SCP_CACHE_SEL(x) + 0x08) -#define SCP_CACHE_HCNT0U(x) REG32(SCP_CACHE_SEL(x) + 0x0c) -#define SCP_CACHE_CCNT0L(x) REG32(SCP_CACHE_SEL(x) + 0x10) -#define SCP_CACHE_CCNT0U(x) REG32(SCP_CACHE_SEL(x) + 0x14) -#define SCP_CACHE_HCNT1L(x) REG32(SCP_CACHE_SEL(x) + 0x18) -#define SCP_CACHE_HCNT1U(x) REG32(SCP_CACHE_SEL(x) + 0x1c) -#define SCP_CACHE_CCNT1L(x) REG32(SCP_CACHE_SEL(x) + 0x20) -#define SCP_CACHE_CCNT1U(x) REG32(SCP_CACHE_SEL(x) + 0x24) - -#define SCP_CACHE_REGION_EN(x) REG32(SCP_CACHE_SEL(x) + 0x2c) - -#define SCP_CACHE_ENTRY_BASE(x) (SCP_CACHE_SEL(x) + 0x2000) -#define SCP_CACHE_ENTRY(x, reg) REG32(SCP_CACHE_ENTRY_BASE(x) + (reg)*4) -#define SCP_CACHE_END_ENTRY_BASE(x) (SCP_CACHE_SEL(x) + 0x2040) -#define SCP_CACHE_END_ENTRY(x, reg) REG32(SCP_CACHE_END_ENTRY_BASE(x) + \ - (reg)*4) -#define SCP_CACHE_ENTRY_C BIT(8) -#define SCP_CACHE_ENTRY_BASEADDR_MASK (0xfffff << 12) - -/* ARMV7 regs */ -#define ARM_SCB_SCR REG32(0xE000ED10) -#define SCR_DEEPSLEEP BIT(2) - -/* AP regs */ -#define AP_BASE 0xA0000000 -#define TOPCK_BASE AP_BASE /* Top clock */ -#define SCP_UART2_BASE (AP_BASE + 0x01002000) /* AP UART0 */ - -/* CLK_CFG_5 regs */ -#define AP_CLK_CFG_5 REG32(TOPCK_BASE + 0x0090) -#define PWRAP_ULPOSC_MASK (0x3000000) -#define CLK26M (0 << 24) -#define OSC_D16 (1 << 24) -#define OSC_D4 (2 << 24) -#define OSC_D8 (3 << 24) -#define AP_CLK_CFG_5_CLR REG32(TOPCK_BASE + 0x0098) -#define PWRAP_ULPOSC_CG BIT(31) - -/* OSC meter */ -#define AP_CLK_MISC_CFG_0 REG32(TOPCK_BASE + 0x0104) -#define MISC_METER_DIVISOR_MASK 0xff000000 -#define MISC_METER_DIV_1 0 -#define AP_CLK_DBG_CFG REG32(TOPCK_BASE + 0x010C) -#define DBG_MODE_MASK 3 -#define DBG_MODE_SET_CLOCK 0 -#define DBG_BIST_SOURCE_MASK (0x3f << 16) -#define DBG_BIST_SOURCE_ULPOSC1 (0x26 << 16) -#define DBG_BIST_SOURCE_ULPOSC2 (0x25 << 16) -#define AP_SCP_CFG_0 REG32(TOPCK_BASE + 0x0220) -#define CFG_FREQ_METER_RUN (1 << 4) -#define CFG_FREQ_METER_ENABLE (1 << 12) -#define AP_SCP_CFG_1 REG32(TOPCK_BASE + 0x0224) -#define CFG_FREQ_COUNTER(CFG1) ((CFG1) & 0xFFFF) - -/* GPIO */ -#define AP_GPIO_BASE (AP_BASE + 0x00005000) -/* - * AP_GPIO_DIR - * GPIO input/out direction, 1 bit per pin. - * 0:input 1:output - */ -#define AP_GPIO_DIR(n) REG32(AP_GPIO_BASE + ((n) << 4)) -/* - * AP_GPIO_DOUT, n in [0..5] - * GPIO output level, 1 bit per pin - * 0:low 1:high - */ -#define AP_GPIO_DOUT(n) REG32(AP_GPIO_BASE + 0x100 + ((n) << 4)) -/* - * AP_GPIO_DIN, n in [0..5] - * GPIO input level, 1 bit per pin - * 0:low 1:high - */ -#define AP_GPIO_DIN(n) REG32(AP_GPIO_BASE + 0x200 + ((n) << 4)) -/* - * AP_GPIO_MODE, n in [0..22] - * Pin mode selection, 4 bit per pin - * bit3 - write enable, set to 1 for hw to fetch bit2,1,0. - * bit2-0 - mode 0 ~ 7 - */ -#define AP_GPIO_MODE(n) REG32(AP_GPIO_BASE + 0x300 + ((n) << 4)) -#define AP_GPIO_TRAP REG32(AP_GPIO_BASE + 0x6B0) -#define AP_GPIO_UNIMPLEMENTED REG32(AP_GPIO_BASE + 0x6C0) -#define AP_GPIO_DBG REG32(AP_GPIO_BASE + 0x6D0) -#define AP_GPIO_BANK REG32(AP_GPIO_BASE + 0x6E0) -/* AP_GPIO_SEC, n in [0..5] */ -#define AP_GPIO_SEC(n) REG32(AP_GPIO_BASE + 0xF00 + ((n) << 4)) - -/* - * PLL ULPOSC - * ULPOSC1: AP_ULPOSC_CON[0] AP_ULPOSC_CON[1] - * ULPOSC2: AP_ULPOSC_CON[2] AP_ULPOSC_CON[3] - * osc: 0 for ULPOSC1, 1 for ULPSOC2. - */ -#define AP_ULPOSC_BASE0 (AP_BASE + 0xC700) -#define AP_ULPOSC_BASE1 (AP_BASE + 0xC704) -#define AP_ULPOSC_CON02(osc) REG32(AP_ULPOSC_BASE0 + (osc) * 0x8) -#define AP_ULPOSC_CON13(osc) REG32(AP_ULPOSC_BASE1 + (osc) * 0x8) -/* - * AP_ULPOSC_CON[0,2] - * bit0-5: calibration - * bit6-12: I-band - * bit13-16: F-band - * bit17-22: div - * bit23: CP_EN - * bit24-31: reserved - */ -#define OSC_CALI_MSK (0x3f << 0) -#define OSC_CALI_BITS 6 -#define OSC_IBAND_MASK (0x7f << 6) -#define OSC_FBAND_MASK (0x0f << 13) -#define OSC_DIV_MASK (0x1f << 17) -#define OSC_DIV_BITS 5 -#define OSC_CP_EN BIT(23) -#define OSC_RESERVED_MASK (0xff << 24) -/* AP_ULPOSC_CON[1,3] */ -#define OSC_MOD_MASK (0x03 << 0) -#define OSC_DIV2_EN BIT(2) - -#define UNIMPLEMENTED_GPIO_BANK 0 - -#ifndef __ASSEMBLER__ - -/* - * Cortex-M4 mod - * Available power saving features: - * 1. FPU freeze - freeze FPU operand when FPU is not used - * 2. LSU gating - gate LSU clock when not LSU operation - * 3. Trace clk disable - gate trace clock - * 4. DCM for CPU stall - gate CPU clock when CPU stall - */ -#define CM4_MODIFICATION REG32(0xE00FE000) -#define CM4_DCM_FEATURE REG32(0xE00FE004) -/* UART, 16550 compatible */ -#define SCP_UART_BASE(n) CONCAT3(SCP_UART, n, _BASE) -#define UART_REG(n, offset) REG32_ADDR(SCP_UART_BASE(n))[offset] -#define UART_IRQ(n) CONCAT2(SCP_IRQ_UART, n) -#define UART_RX_IRQ(n) CONCAT3(SCP_IRQ_UART, n, _RX) - -/* Watchdog */ -#define SCP_WDT_BASE (SCP_CFG_BASE + 0x84) -#define SCP_WDT_REG(offset) REG32(SCP_WDT_BASE + offset) -#define SCP_WDT_CFG SCP_WDT_REG(0) -#define SCP_WDT_FREQ 33825 -#define SCP_WDT_MAX_PERIOD 0xFFFFF /* 31 seconds */ -#define SCP_WDT_PERIOD(ms) (SCP_WDT_FREQ * (ms) / 1000) -#define SCP_WDT_ENABLE BIT(31) -#define SCP_WDT_RELOAD SCP_WDT_REG(4) -#define SCP_WDT_RELOAD_VALUE 1 - -#endif /* !__ASSEMBLER__ */ -#endif /* __CROS_EC_REGISTERS_H */ diff --git a/chip/mt_scp/mt8183/serial_reg.h b/chip/mt_scp/mt8183/serial_reg.h deleted file mode 100644 index 5344566272..0000000000 --- a/chip/mt_scp/mt8183/serial_reg.h +++ /dev/null @@ -1,90 +0,0 @@ -/* Copyright 2018 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - * - * UART register map - */ - -#ifndef __CROS_EC_SERIAL_REG_H -#define __CROS_EC_SERIAL_REG_H - -#include "registers.h" - -/* Number of hardware ports */ -#define HW_UART_PORTS 2 - -/* DLAB (Divisor Latch Access Bit) == 0 */ - -/* Data register - * (Read) Rcvr buffer register - * (Write) Xmit holding register - */ -#define UART_DATA(n) UART_REG(n, 0) -/* (Write) Interrupt enable register */ -#define UART_IER(n) UART_REG(n, 1) -#define UART_IER_RDI BIT(0) /* Recv data int */ -#define UART_IER_THRI BIT(1) /* Xmit holding register int */ -#define UART_IER_RLSI BIT(2) /* Rcvr line status int */ -#define UART_IER_MSI BIT(3) /* Modem status int */ -/* (Read) Interrupt ID register */ -#define UART_IIR(n) UART_REG(n, 2) -#define UART_IIR_NO_INT BIT(0) /* No int pending */ -#define UART_IIR_ID_MASK 0x0e /* Interrupt ID mask */ -#define UART_IIR_MSI 0x00 -#define UART_IIR_THRI 0x02 -#define UART_IIR_RDI 0x04 -#define UART_IIR_RLSI 0x06 -#define UART_IIR_BUSY 0x07 /* DW APB busy */ -/* (Write) FIFO control register */ -#define UART_FCR(n) UART_REG(n, 2) -#define UART_FCR_ENABLE_FIFO BIT(0) /* Enable FIFO */ -#define UART_FCR_CLEAR_RCVR BIT(1) /* Clear rcvr FIFO */ -#define UART_FCR_CLEAR_XMIT BIT(2) /* Clear xmit FIFO */ -#define UART_FCR_DMA_SELECT BIT(3) -/* FIFO trigger levels */ -#define UART_FCR_T_TRIG_00 0x00 -#define UART_FCR_T_TRIG_01 0x10 -#define UART_FCR_T_TRIG_10 0x20 -#define UART_FCR_T_TRIG_11 0x30 -#define UART_FCR_R_TRIG_00 0x00 -#define UART_FCR_R_TRIG_01 0x40 -#define UART_FCR_R_TRIG_10 0x80 -#define UART_FCR_R_TRIG_11 0x80 -/* (Write) Line control register */ -#define UART_LCR(n) UART_REG(n, 3) -#define UART_LCR_WLEN5 0 /* Word length 5 bits */ -#define UART_LCR_WLEN6 1 -#define UART_LCR_WLEN7 2 -#define UART_LCR_WLEN8 3 -#define UART_LCR_STOP BIT(2) /* Stop bits: 1bit, 2bits */ -#define UART_LCR_PARITY BIT(3) /* Parity enable */ -#define UART_LCR_EPAR BIT(4) /* Even parity */ -#define UART_LCR_SPAR BIT(5) /* Stick parity */ -#define UART_LCR_SBC BIT(6) /* Set break control */ -#define UART_LCR_DLAB BIT(7) /* Divisor latch access */ -/* (Write) Modem control register */ -#define UART_MCR(n) UART_REG(n, 4) -/* (Read) Line status register */ -#define UART_LSR(n) UART_REG(n, 5) -#define UART_LSR_DR BIT(0) /* Data ready */ -#define UART_LSR_OE BIT(1) /* Overrun error */ -#define UART_LSR_PE BIT(2) /* Parity error */ -#define UART_LSR_FE BIT(3) /* Frame error */ -#define UART_LSR_BI BIT(4) /* Break interrupt */ -#define UART_LSR_THRE BIT(5) /* Xmit-hold-register empty */ -#define UART_LSR_TEMT BIT(6) /* Xmit empty */ -#define UART_LSR_FIFOE BIT(7) /* FIFO error */ - -/* DLAB == 1 */ - -/* (Write) Divisor latch */ -#define UART_DLL(n) UART_REG(n, 0) /* Low */ -#define UART_DLH(n) UART_REG(n, 1) /* High */ - -/* MTK extension */ -#define UART_HIGHSPEED(n) UART_REG(n, 9) -#define UART_SAMPLE_COUNT(n) UART_REG(n, 10) -#define UART_SAMPLE_POINT(n) UART_REG(n, 11) -#define UART_RATE_FIX(n) UART_REG(n, 13) - -#endif /* __CROS_EC_SERIAL_REG_H */ diff --git a/chip/mt_scp/mt8183/system.c b/chip/mt_scp/mt8183/system.c deleted file mode 100644 index 03f39298c9..0000000000 --- a/chip/mt_scp/mt8183/system.c +++ /dev/null @@ -1,176 +0,0 @@ -/* Copyright 2018 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -/* System : hardware specific implementation */ - -#include "clock_chip.h" -#include "console.h" -#include "cpu.h" -#include "cros_version.h" -#include "flash.h" -#include "hooks.h" -#include "host_command.h" -#include "memmap.h" -#include "registers.h" -#include "system.h" -#include "task.h" -#include "util.h" -#include "watchdog.h" - -/* - * SCP_GPR[0] b15-b0 - scratchpad - * SCP_GPR[0] b31-b16 - saved_flags - */ - -int system_set_scratchpad(uint32_t value) -{ - /* Check if value fits in 16 bits */ - if (value & 0xffff0000) - return EC_ERROR_INVAL; - - SCP_GPR[0] = (SCP_GPR[0] & 0xffff0000) | value; - - return EC_SUCCESS; -} - -int system_get_scratchpad(uint32_t *value) -{ - *value = SCP_GPR[0] & 0xffff; - return EC_SUCCESS; -} - -const char *system_get_chip_vendor(void) -{ - return "mtk"; -} - -const char *system_get_chip_name(void) -{ - /* Support only SCP_A for now */ - return "scp_a"; -} - -const char *system_get_chip_revision(void) -{ - return ""; -} - -void chip_pre_init(void) -{ -} - -static void scp_cm4_mod(void) -{ - CM4_MODIFICATION = 3; - CM4_DCM_FEATURE = 3; -} - -static void scp_enable_pirq(void) -{ - /* Enable all peripheral to SCP IRQ, except IPC0. */ - SCP_INTC_IRQ_ENABLE = 0xFFFFFFFE; - SCP_INTC_IRQ_ENABLE_MSB = 0xFFFFFFFF; -} - -void system_pre_init(void) -{ - /* CM4 Modification */ - scp_cm4_mod(); - /* Clock */ - scp_enable_clock(); - /* Peripheral IRQ */ - scp_enable_pirq(); - /* Init dram mapping (and cache) */ - scp_memmap_init(); - /* Disable jump (mt_scp has only RW) and enable MPU. */ - system_disable_jump(); -} - -void system_reset(int flags) -{ - uint32_t save_flags = 0; - - /* Disable interrupts to avoid task swaps during reboot */ - interrupt_disable(); - - /* Save current reset reasons if necessary */ - if (flags & SYSTEM_RESET_PRESERVE_FLAGS) - save_flags = system_get_reset_flags() | EC_RESET_FLAG_PRESERVED; - - if (flags & SYSTEM_RESET_LEAVE_AP_OFF) - save_flags |= EC_RESET_FLAG_AP_OFF; - - /* Remember that the software asked us to hard reboot */ - if (flags & SYSTEM_RESET_HARD) - save_flags |= EC_RESET_FLAG_HARD; - - /* Reset flags are 32-bits, but save only 16 bits. */ - ASSERT(!(save_flags >> 16)); - SCP_GPR[0] = (save_flags << 16) | (SCP_GPR[0] & 0xffff); - - /* SCP can not hard reset itself */ - ASSERT(!(flags & SYSTEM_RESET_HARD)); - - if (flags & SYSTEM_RESET_WAIT_EXT) { - int i; - - /* Wait 10 seconds for external reset */ - for (i = 0; i < 1000; i++) { - watchdog_reload(); - udelay(10000); - } - } - - /* Set watchdog timer to small value, and spin wait for watchdog reset */ - SCP_WDT_CFG = 0; - SCP_WDT_CFG = SCP_WDT_ENABLE | SCP_WDT_PERIOD(1); - watchdog_reload(); - while (1) - ; -} - -static void check_reset_cause(void) -{ - uint32_t flags = 0; - uint32_t raw_reset_cause = SCP_GPR[1]; - - /* Set state to power-on */ - SCP_PWRON_STATE = PWRON_DEFAULT; - - if ((raw_reset_cause & 0xffff0000) == PWRON_DEFAULT) { - /* Reboot */ - if (raw_reset_cause & PWRON_WATCHDOG) - flags |= EC_RESET_FLAG_WATCHDOG; - else if (raw_reset_cause & PWRON_RESET) - flags |= EC_RESET_FLAG_POWER_ON; - else - flags |= EC_RESET_FLAG_OTHER; - } else { - /* Power lost restart */ - flags |= EC_RESET_FLAG_POWER_ON; - } - system_set_reset_flags(SCP_GPR[0] >> 16); - SCP_GPR[0] &= 0xffff; -} - -int system_is_reboot_warm(void) -{ - const uint32_t cold_flags = - EC_RESET_FLAG_RESET_PIN | - EC_RESET_FLAG_POWER_ON | - EC_RESET_FLAG_WATCHDOG | - EC_RESET_FLAG_HARD | - EC_RESET_FLAG_SOFT | - EC_RESET_FLAG_HIBERNATE; - - check_reset_cause(); - - return !(system_get_reset_flags() & cold_flags); -} - -int system_get_bbram(enum system_bbram_idx idx, uint8_t *value) -{ - return EC_ERROR_INVAL; -} diff --git a/chip/mt_scp/mt8183/uart.c b/chip/mt_scp/mt8183/uart.c deleted file mode 100644 index 7907f9537d..0000000000 --- a/chip/mt_scp/mt8183/uart.c +++ /dev/null @@ -1,179 +0,0 @@ -/* Copyright 2018 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -/* SCP UART module */ - -#include "clock_chip.h" -#include "console.h" -#include "registers.h" -#include "serial_reg.h" -#include "system.h" -#include "task.h" -#include "uart.h" -#include "util.h" - -/* Console UART index */ -#define UARTN CONFIG_UART_CONSOLE -#define UART_IDLE_WAIT_US 500 - -static uint8_t uart_done, tx_started; - -int uart_init_done(void) -{ - /* - * TODO: AP UART support - * When access AP UART port, wait for AP peripheral clock - */ - return uart_done; -} - -void uart_tx_start(void) -{ - tx_started = 1; - - /* AP UART mode doesn't support interrupt */ - if (UARTN >= SCP_UART_COUNT) - return; - - if (UART_IER(UARTN) & UART_IER_THRI) - return; - disable_sleep(SLEEP_MASK_UART); - UART_IER(UARTN) |= UART_IER_THRI; -} - -void uart_tx_stop(void) -{ - tx_started = 0; - - /* AP UART mode doesn't support interrupt */ - if (UARTN >= SCP_UART_COUNT) - return; - - UART_IER(UARTN) &= ~UART_IER_THRI; - enable_sleep(SLEEP_MASK_UART); -} - -void uart_tx_flush(void) -{ - while (!(UART_LSR(UARTN) & UART_LSR_TEMT)) - ; -} - -int uart_tx_ready(void) -{ - /* Check xmit FIFO empty */ - return UART_LSR(UARTN) & UART_LSR_THRE; -} - -int uart_rx_available(void) -{ - /* Check rcvr data ready */ - return UART_LSR(UARTN) & UART_LSR_DR; -} - -void uart_write_char(char c) -{ - while (!uart_tx_ready()) - ; - - UART_DATA(UARTN) = c; -} - -int uart_read_char(void) -{ - return UART_DATA(UARTN); -} - -void uart_process(void) -{ - uart_process_input(); - uart_process_output(); -} - -#if (UARTN < SCP_UART_COUNT) -DECLARE_IRQ(UART_IRQ(UARTN), uart_interrupt, 2); -void uart_interrupt(void) -{ - uint8_t ier; - - task_clear_pending_irq(UART_IRQ(UARTN)); - uart_process(); - ier = UART_IER(UARTN); - UART_IER(UARTN) = 0; - UART_IER(UARTN) = ier; -} - -DECLARE_IRQ(UART_RX_IRQ(UARTN), uart_rx_interrupt, 2); -void uart_rx_interrupt(void) -{ - uint8_t ier; - - task_clear_pending_irq(UART_RX_IRQ(UARTN)); - SCP_INTC_UART_RX_IRQ &= ~BIT(UARTN); - uart_process(); - ier = UART_IER(UARTN); - UART_IER(UARTN) = 0; - UART_IER(UARTN) = ier; - SCP_INTC_UART_RX_IRQ |= 1 << UARTN; -} -#endif - -void uart_task(void) -{ -#if (UARTN >= SCP_UART_COUNT) - while (1) { - if (uart_rx_available() || tx_started) - uart_process(); - else - task_wait_event(UART_IDLE_WAIT_US); - } -#endif -} - -void uart_init(void) -{ - const uint32_t baud_rate = CONFIG_UART_BAUD_RATE; - /* - * UART clock source is set to ULPOSC1 / 10 below. - * - * TODO(b:134035444): We could get slightly more precise frequency by - * using the _measured_ ULPOSC1 frequency (instead of the target). - */ - const uint32_t uart_clock = ULPOSC1_CLOCK_MHZ * 1000 / 10 * 1000; - const uint32_t div = DIV_ROUND_NEAREST(uart_clock, baud_rate * 16); - - /* Init clock */ -#if UARTN == 0 - SCP_CLK_UART = CLK_UART_SEL_ULPOSC1_DIV10; - SCP_CLK_GATE |= CG_UART_M | CG_UART_B | CG_UART_RSTN; -#elif UARTN == 1 - SCP_CLK_UART = CLK_UART1_SEL_ULPOSC1_DIV10; - SCP_CLK_GATE |= CG_UART1_M | CG_UART1_B | CG_UART1_RSTN; -#endif - - /* Init and clear FIFO */ - UART_FCR(UARTN) = UART_FCR_ENABLE_FIFO - | UART_FCR_CLEAR_RCVR - | UART_FCR_CLEAR_XMIT; - /* Line control: parity none, 8 bit, 1 stop bit */ - UART_LCR(UARTN) = UART_LCR_WLEN8; - /* For baud rate <= 115200 */ - UART_HIGHSPEED(UARTN) = 0; - /* DLAB = 1 and update DLL DLH */ - UART_LCR(UARTN) |= UART_LCR_DLAB; - UART_DLL(UARTN) = div & 0xff; - UART_DLH(UARTN) = (div >> 8) & 0xff; - UART_LCR(UARTN) &= ~UART_LCR_DLAB; - UART_IER(UARTN) |= UART_IER_RDI; - -#if (UARTN < SCP_UART_COUNT) - task_enable_irq(UART_IRQ(UARTN)); - task_enable_irq(UART_RX_IRQ(UARTN)); - /* UART RX IRQ needs an extra enable */ - SCP_INTC_UART_RX_IRQ |= 1 << UARTN; -#endif - gpio_config_module(MODULE_UART, 1); - uart_done = 1; -} diff --git a/chip/mt_scp/mt8183/watchdog.c b/chip/mt_scp/mt8183/watchdog.c deleted file mode 100644 index 74e2cad8e5..0000000000 --- a/chip/mt_scp/mt8183/watchdog.c +++ /dev/null @@ -1,33 +0,0 @@ -/* Copyright 2018 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -/* Watchdog driver */ - -#include "common.h" -#include "hooks.h" -#include "panic.h" -#include "registers.h" -#include "watchdog.h" - -void watchdog_reload(void) -{ - SCP_WDT_RELOAD = SCP_WDT_RELOAD_VALUE; -} -DECLARE_HOOK(HOOK_TICK, watchdog_reload, HOOK_PRIO_DEFAULT); - -int watchdog_init(void) -{ - const uint32_t watchdog_timeout = - SCP_WDT_PERIOD(CONFIG_WATCHDOG_PERIOD_MS); - - /* Disable watchdog */ - SCP_WDT_CFG = 0; - /* Enable watchdog */ - SCP_WDT_CFG = SCP_WDT_ENABLE | watchdog_timeout; - /* Reload watchdog */ - watchdog_reload(); - - return EC_SUCCESS; -} |