Commit a92b0256 authored by Manish Pandey's avatar Manish Pandey Committed by TrustedFirmware Code Review
Browse files

Merge changes I20c73f6e,I9962263c,I177796e3,I6ff6875c,I21fe9d85, ... into integration

* changes:
  mediatek: mt8195: add rtc power off sequence
  mediatek: mt8195: add power-off support
  mediatek: mt8195: Add reboot function for PSCI
  mediatek: mt8195: Add gpio driver
  mediatek: mt8195: Add SiP service
  mediatek: mt8195: Add CPU hotplug and MCDI support
  mediatek: mt8195: Add MCDI drivers
  mediatek: mt8195: Add SPMC driver
  mediatek: mt8195: Initialize delay_timer
  mediatek: mt8195: initialize systimer
  mediatek: mt8192: move timer driver to common folder
  mediatek: mt8195: add sys_cirq support
  mediatek: mt8195: initialize GIC
  Initialize platform for MediaTek MT8195
parents 7bcb8ad2 c52a10a2
...@@ -20,6 +20,7 @@ Platform Ports ...@@ -20,6 +20,7 @@ Platform Ports
marvell/index marvell/index
mt8183 mt8183
mt8192 mt8192
mt8195
nvidia-tegra nvidia-tegra
warp7 warp7
imx8 imx8
......
MediaTek 8195
=============
MediaTek 8195 (MT8195) is a 64-bit ARM SoC introduced by MediaTek in 2021.
The chip incorporates eight cores - four Cortex-A55 little cores and Cortex-A76.
Cortex-A76 can operate at up to 2.2 GHz.
Cortex-A55 can operate at up to 2.0 GHz.
Boot Sequence
-------------
::
Boot Rom --> Coreboot --> TF-A BL31 --> Depthcharge --> Linux Kernel
How to Build
------------
.. code:: shell
make CROSS_COMPILE=aarch64-linux-gnu- PLAT=mt8195 DEBUG=1 COREBOOT=1
/*
* Copyright (c) 2020, MediaTek Inc. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <assert.h>
#include <common/debug.h>
#include <drivers/delay_timer.h>
#include <drivers/gpio.h>
#include <lib/mmio.h>
#include <mtgpio.h>
#include <platform_def.h>
/******************************************************************************
*Macro Definition
******************************************************************************/
#define GPIO_MODE_BITS 4
#define MAX_GPIO_MODE_PER_REG 8
#define MAX_GPIO_REG_BITS 32
#define DIR_BASE (GPIO_BASE + 0x000)
#define DOUT_BASE (GPIO_BASE + 0x100)
#define DIN_BASE (GPIO_BASE + 0x200)
#define MODE_BASE (GPIO_BASE + 0x300)
#define SET 0x4
#define CLR 0x8
static void mt_set_gpio_dir_chip(uint32_t pin, int dir)
{
uint32_t pos, bit;
assert(pin < MAX_GPIO_PIN);
assert(dir < MT_GPIO_DIR_MAX);
pos = pin / MAX_GPIO_REG_BITS;
bit = pin % MAX_GPIO_REG_BITS;
if (dir == MT_GPIO_DIR_IN) {
mmio_write_32(DIR_BASE + 0x10U * pos + CLR, 1U << bit);
} else {
mmio_write_32(DIR_BASE + 0x10U * pos + SET, 1U << bit);
}
}
static int mt_get_gpio_dir_chip(uint32_t pin)
{
uint32_t pos, bit;
uint32_t reg;
assert(pin < MAX_GPIO_PIN);
pos = pin / MAX_GPIO_REG_BITS;
bit = pin % MAX_GPIO_REG_BITS;
reg = mmio_read_32(DIR_BASE + 0x10U * pos);
return (((reg & (1U << bit)) != 0U) ? MT_GPIO_DIR_OUT : MT_GPIO_DIR_IN);
}
static void mt_set_gpio_out_chip(uint32_t pin, int output)
{
uint32_t pos, bit;
assert(pin < MAX_GPIO_PIN);
assert(output < MT_GPIO_OUT_MAX);
pos = pin / MAX_GPIO_REG_BITS;
bit = pin % MAX_GPIO_REG_BITS;
if (output == MT_GPIO_OUT_ZERO) {
mmio_write_32(DOUT_BASE + 0x10U * pos + CLR, 1U << bit);
} else {
mmio_write_32(DOUT_BASE + 0x10U * pos + SET, 1U << bit);
}
}
static int mt_get_gpio_in_chip(uint32_t pin)
{
uint32_t pos, bit;
uint32_t reg;
assert(pin < MAX_GPIO_PIN);
pos = pin / MAX_GPIO_REG_BITS;
bit = pin % MAX_GPIO_REG_BITS;
reg = mmio_read_32(DIN_BASE + 0x10U * pos);
return (((reg & (1U << bit)) != 0U) ? 1 : 0);
}
static void mt_gpio_set_spec_pull_pupd(uint32_t pin, int enable,
int select)
{
uintptr_t reg1;
uintptr_t reg2;
struct mt_pin_info gpio_info;
gpio_info = mt_pin_infos[pin];
uint32_t bit = gpio_info.bit;
reg1 = mt_gpio_find_reg_addr(pin) + gpio_info.offset;
reg2 = reg1 + (gpio_info.base & 0xf0);
if (enable == MT_GPIO_PULL_ENABLE) {
mmio_write_32(reg2 + SET, (1U << bit));
if (select == MT_GPIO_PULL_DOWN) {
mmio_write_32(reg1 + SET, (1U << bit));
} else {
mmio_write_32(reg1 + CLR, (1U << bit));
}
} else {
mmio_write_32(reg2 + CLR, (1U << bit));
mmio_write_32((reg2 + 0x010U) + CLR, (1U << bit));
}
}
static void mt_gpio_set_pull_pu_pd(uint32_t pin, int enable,
int select)
{
uintptr_t reg1;
uintptr_t reg2;
struct mt_pin_info gpio_info;
gpio_info = mt_pin_infos[pin];
uint32_t bit = gpio_info.bit;
reg1 = mt_gpio_find_reg_addr(pin) + gpio_info.offset;
reg2 = reg1 - (gpio_info.base & 0xf0);
if (enable == MT_GPIO_PULL_ENABLE) {
if (select == MT_GPIO_PULL_DOWN) {
mmio_write_32(reg1 + CLR, (1U << bit));
mmio_write_32(reg2 + SET, (1U << bit));
} else {
mmio_write_32(reg2 + CLR, (1U << bit));
mmio_write_32(reg1 + SET, (1U << bit));
}
} else {
mmio_write_32(reg1 + CLR, (1U << bit));
mmio_write_32(reg2 + CLR, (1U << bit));
}
}
static void mt_gpio_set_pull_chip(uint32_t pin, int enable,
int select)
{
struct mt_pin_info gpio_info;
gpio_info = mt_pin_infos[pin];
if (gpio_info.flag) {
mt_gpio_set_spec_pull_pupd(pin, enable, select);
} else {
mt_gpio_set_pull_pu_pd(pin, enable, select);
}
}
static int mt_gpio_get_spec_pull_pupd(uint32_t pin)
{
uintptr_t reg1;
uintptr_t reg2;
uint32_t r0;
uint32_t r1;
struct mt_pin_info gpio_info;
gpio_info = mt_pin_infos[pin];
uint32_t bit = gpio_info.bit;
reg1 = mt_gpio_find_reg_addr(pin) + gpio_info.offset;
reg2 = reg1 + (gpio_info.base & 0xf0);
r0 = (mmio_read_32(reg2) >> bit) & 1U;
r1 = (mmio_read_32(reg2 + 0x010) >> bit) & 1U;
if (r0 == 0U && r1 == 0U) {
return MT_GPIO_PULL_NONE;
} else {
if (mmio_read_32(reg1) & (1U << bit)) {
return MT_GPIO_PULL_DOWN;
} else {
return MT_GPIO_PULL_UP;
}
}
}
static int mt_gpio_get_pull_pu_pd(uint32_t pin)
{
uintptr_t reg1;
uintptr_t reg2;
uint32_t pu;
uint32_t pd;
struct mt_pin_info gpio_info;
gpio_info = mt_pin_infos[pin];
uint32_t bit = gpio_info.bit;
reg1 = mt_gpio_find_reg_addr(pin) + gpio_info.offset;
reg2 = reg1 - (gpio_info.base & 0xf0);
pu = (mmio_read_32(reg1) >> bit) & 1U;
pd = (mmio_read_32(reg2) >> bit) & 1U;
if (pu == 1U) {
return MT_GPIO_PULL_UP;
} else if (pd == 1U) {
return MT_GPIO_PULL_DOWN;
} else {
return MT_GPIO_PULL_NONE;
}
}
static int mt_gpio_get_pull_chip(uint32_t pin)
{
struct mt_pin_info gpio_info;
gpio_info = mt_pin_infos[pin];
if (gpio_info.flag) {
return mt_gpio_get_spec_pull_pupd(pin);
} else {
return mt_gpio_get_pull_pu_pd(pin);
}
}
static void mt_set_gpio_pull_select_chip(uint32_t pin, int sel)
{
assert(pin < MAX_GPIO_PIN);
if (sel == MT_GPIO_PULL_NONE) {
mt_gpio_set_pull_chip(pin, MT_GPIO_PULL_DISABLE, MT_GPIO_PULL_DOWN);
} else if (sel == MT_GPIO_PULL_UP) {
mt_gpio_set_pull_chip(pin, MT_GPIO_PULL_ENABLE, MT_GPIO_PULL_UP);
} else if (sel == MT_GPIO_PULL_DOWN) {
mt_gpio_set_pull_chip(pin, MT_GPIO_PULL_ENABLE, MT_GPIO_PULL_DOWN);
}
}
/* get pull-up or pull-down, regardless of resistor value */
static int mt_get_gpio_pull_select_chip(uint32_t pin)
{
assert(pin < MAX_GPIO_PIN);
return mt_gpio_get_pull_chip(pin);
}
static void mt_set_gpio_dir(int gpio, int direction)
{
mt_set_gpio_dir_chip((uint32_t)gpio, direction);
}
static int mt_get_gpio_dir(int gpio)
{
uint32_t pin;
pin = (uint32_t)gpio;
return mt_get_gpio_dir_chip(pin);
}
static void mt_set_gpio_pull(int gpio, int pull)
{
uint32_t pin;
pin = (uint32_t)gpio;
mt_set_gpio_pull_select_chip(pin, pull);
}
static int mt_get_gpio_pull(int gpio)
{
uint32_t pin;
pin = (uint32_t)gpio;
return mt_get_gpio_pull_select_chip(pin);
}
static void mt_set_gpio_out(int gpio, int value)
{
uint32_t pin;
pin = (uint32_t)gpio;
mt_set_gpio_out_chip(pin, value);
}
static int mt_get_gpio_in(int gpio)
{
uint32_t pin;
pin = (uint32_t)gpio;
return mt_get_gpio_in_chip(pin);
}
const gpio_ops_t mtgpio_ops = {
.get_direction = mt_get_gpio_dir,
.set_direction = mt_set_gpio_dir,
.get_value = mt_get_gpio_in,
.set_value = mt_set_gpio_out,
.set_pull = mt_set_gpio_pull,
.get_pull = mt_get_gpio_pull,
};
void mt_gpio_init(void)
{
gpio_init(&mtgpio_ops);
}
/*
* Copyright (c) 2020, MediaTek Inc. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef MT_GPIO_COMMON_H
#define MT_GPIO_COMMON_H
#include <stdbool.h>
#include <stdint.h>
#include <plat/common/common_def.h>
/* Error Code No. */
#define RSUCCESS 0
#define ERACCESS 1
#define ERINVAL 2
#define ERWRAPPER 3
#define MAX_GPIO_PIN MT_GPIO_BASE_MAX
/* GPIO MODE CONTROL VALUE*/
typedef enum {
GPIO_MODE_UNSUPPORTED = -1,
GPIO_MODE_GPIO = 0,
GPIO_MODE_00 = 0,
GPIO_MODE_01,
GPIO_MODE_02,
GPIO_MODE_03,
GPIO_MODE_04,
GPIO_MODE_05,
GPIO_MODE_06,
GPIO_MODE_07,
GPIO_MODE_MAX,
GPIO_MODE_DEFAULT = GPIO_MODE_00,
} GPIO_MODE;
/* GPIO DIRECTION */
typedef enum {
MT_GPIO_DIR_UNSUPPORTED = -1,
MT_GPIO_DIR_OUT = 0,
MT_GPIO_DIR_IN = 1,
MT_GPIO_DIR_MAX,
MT_GPIO_DIR_DEFAULT = MT_GPIO_DIR_IN,
} GPIO_DIR;
/* GPIO PULL ENABLE*/
typedef enum {
MT_GPIO_PULL_EN_UNSUPPORTED = -1,
MT_GPIO_PULL_DISABLE = 0,
MT_GPIO_PULL_ENABLE = 1,
MT_GPIO_PULL_ENABLE_R0 = 2,
MT_GPIO_PULL_ENABLE_R1 = 3,
MT_GPIO_PULL_ENABLE_R0R1 = 4,
MT_GPIO_PULL_EN_MAX,
MT_GPIO_PULL_EN_DEFAULT = MT_GPIO_PULL_ENABLE,
} GPIO_PULL_EN;
/* GPIO PULL-UP/PULL-DOWN*/
typedef enum {
MT_GPIO_PULL_UNSUPPORTED = -1,
MT_GPIO_PULL_NONE = 0,
MT_GPIO_PULL_UP = 1,
MT_GPIO_PULL_DOWN = 2,
MT_GPIO_PULL_MAX,
MT_GPIO_PULL_DEFAULT = MT_GPIO_PULL_DOWN
} GPIO_PULL;
/* GPIO OUTPUT */
typedef enum {
MT_GPIO_OUT_UNSUPPORTED = -1,
MT_GPIO_OUT_ZERO = 0,
MT_GPIO_OUT_ONE = 1,
MT_GPIO_OUT_MAX,
MT_GPIO_OUT_DEFAULT = MT_GPIO_OUT_ZERO,
MT_GPIO_DATA_OUT_DEFAULT = MT_GPIO_OUT_ZERO, /*compatible with DCT*/
} GPIO_OUT;
/* GPIO INPUT */
typedef enum {
MT_GPIO_IN_UNSUPPORTED = -1,
MT_GPIO_IN_ZERO = 0,
MT_GPIO_IN_ONE = 1,
MT_GPIO_IN_MAX,
} GPIO_IN;
#define PIN(_id, _flag, _bit, _base, _offset) { \
.id = _id, \
.flag = _flag, \
.bit = _bit, \
.base = _base, \
.offset = _offset, \
}
struct mt_pin_info {
uint8_t id;
uint8_t flag;
uint8_t bit;
uint16_t base;
uint16_t offset;
};
void mt_gpio_init(void);
uintptr_t mt_gpio_find_reg_addr(uint32_t pin);
#endif /* MT_GPIO_COMMON_H */
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
* SPDX-License-Identifier: BSD-3-Clause * SPDX-License-Identifier: BSD-3-Clause
*/ */
#ifndef RTC_H #ifndef RTC_MT6359P_H
#define RTC_H #define RTC_MT6359P_H
/* RTC registers */ /* RTC registers */
enum { enum {
...@@ -194,4 +194,4 @@ int32_t RTC_Write_Trigger(void); ...@@ -194,4 +194,4 @@ int32_t RTC_Write_Trigger(void);
int32_t Writeif_unlock(void); int32_t Writeif_unlock(void);
void rtc_power_off_sequence(void); void rtc_power_off_sequence(void);
#endif /* RTC_H */ #endif /* RTC_MT6359P_H */
...@@ -10,8 +10,7 @@ ...@@ -10,8 +10,7 @@
#include <lib/mmio.h> #include <lib/mmio.h>
#include <mt_gic_v3.h> #include <mt_gic_v3.h>
#include <plat_mt_cirq.h> #include <mtk_cirq.h>
#include <platform_def.h>
static struct cirq_events cirq_all_events = { static struct cirq_events cirq_all_events = {
.spi_start = CIRQ_SPI_START, .spi_start = CIRQ_SPI_START,
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#define PLAT_MT_CIRQ_H #define PLAT_MT_CIRQ_H
#include <stdint.h> #include <stdint.h>
#include <platform_def.h>
enum { enum {
IRQ_MASK_HEADER = 0xF1F1F1F1, IRQ_MASK_HEADER = 0xF1F1F1F1,
...@@ -35,13 +36,6 @@ struct mtk_irq_mask { ...@@ -35,13 +36,6 @@ struct mtk_irq_mask {
/* /*
* Define hardware register * Define hardware register
*/ */
#define SYS_CIRQ_BASE U(0x10204000)
#define CIRQ_REG_NUM U(14)
#define CIRQ_IRQ_NUM U(439)
#define CIRQ_SPI_START U(64)
#define MD_WDT_IRQ_BIT_ID U(110)
#define CIRQ_STA_BASE (SYS_CIRQ_BASE + U(0x000)) #define CIRQ_STA_BASE (SYS_CIRQ_BASE + U(0x000))
#define CIRQ_ACK_BASE (SYS_CIRQ_BASE + U(0x080)) #define CIRQ_ACK_BASE (SYS_CIRQ_BASE + U(0x080))
#define CIRQ_MASK_BASE (SYS_CIRQ_BASE + U(0x100)) #define CIRQ_MASK_BASE (SYS_CIRQ_BASE + U(0x100))
......
...@@ -102,7 +102,7 @@ void bl31_platform_setup(void) ...@@ -102,7 +102,7 @@ void bl31_platform_setup(void)
mt_gic_driver_init(); mt_gic_driver_init();
mt_gic_init(); mt_gic_init();
plat_mt8192_gpio_init(); mt_gpio_init();
mt_systimer_init(); mt_systimer_init();
generic_delay_timer_init(); generic_delay_timer_init();
spm_boot_init(); spm_boot_init();
......
...@@ -5,94 +5,17 @@ ...@@ -5,94 +5,17 @@
*/ */
#include <assert.h> #include <assert.h>
#include <common/debug.h>
#include <drivers/delay_timer.h>
#include <drivers/gpio.h>
#include <lib/mmio.h>
#include <mtgpio.h> #include <mtgpio.h>
#include <platform_def.h> #include <platform_def.h>
/****************************************************************************** uintptr_t mt_gpio_find_reg_addr(uint32_t pin)
*Macro Definition
******************************************************************************/
#define GPIO_MODE_BITS 4
#define MAX_GPIO_MODE_PER_REG 8
#define MAX_GPIO_REG_BITS 32
#define DIR_BASE (GPIO_BASE + 0x000)
#define DOUT_BASE (GPIO_BASE + 0x100)
#define DIN_BASE (GPIO_BASE + 0x200)
#define MODE_BASE (GPIO_BASE + 0x300)
#define SET 0x4
#define CLR 0x8
static void mt_set_gpio_dir_chip(uint32_t pin, int dir)
{
uint32_t pos, bit;
assert(pin < MAX_GPIO_PIN);
assert(dir < MT_GPIO_DIR_MAX);
pos = pin / MAX_GPIO_REG_BITS;
bit = pin % MAX_GPIO_REG_BITS;
if (dir == MT_GPIO_DIR_IN) {
mmio_write_32(DIR_BASE + 0x10U * pos + CLR, 1U << bit);
} else {
mmio_write_32(DIR_BASE + 0x10U * pos + SET, 1U << bit);
}
}
static int mt_get_gpio_dir_chip(uint32_t pin)
{
uint32_t pos, bit;
uint32_t reg;
assert(pin < MAX_GPIO_PIN);
pos = pin / MAX_GPIO_REG_BITS;
bit = pin % MAX_GPIO_REG_BITS;
reg = mmio_read_32(DIR_BASE + 0x10U * pos);
return (((reg & (1U << bit)) != 0U) ? MT_GPIO_DIR_OUT : MT_GPIO_DIR_IN);
}
static void mt_set_gpio_out_chip(uint32_t pin, int output)
{
uint32_t pos, bit;
assert(pin < MAX_GPIO_PIN);
assert(output < MT_GPIO_OUT_MAX);
pos = pin / MAX_GPIO_REG_BITS;
bit = pin % MAX_GPIO_REG_BITS;
if (output == MT_GPIO_OUT_ZERO) {
mmio_write_32(DOUT_BASE + 0x10U * pos + CLR, 1U << bit);
} else {
mmio_write_32(DOUT_BASE + 0x10U * pos + SET, 1U << bit);
}
}
static int mt_get_gpio_in_chip(uint32_t pin)
{
uint32_t pos, bit;
uint32_t reg;
assert(pin < MAX_GPIO_PIN);
pos = pin / MAX_GPIO_REG_BITS;
bit = pin % MAX_GPIO_REG_BITS;
reg = mmio_read_32(DIN_BASE + 0x10U * pos);
return (((reg & (1U << bit)) != 0U) ? 1 : 0);
}
static uintptr_t mt_gpio_find_reg_addr(uint32_t pin)
{ {
uintptr_t reg_addr = 0U; uintptr_t reg_addr = 0U;
struct mt_pin_info gpio_info; struct mt_pin_info gpio_info;
gpio_info = mt8192_pin_infos[pin]; assert(pin < MAX_GPIO_PIN);
gpio_info = mt_pin_infos[pin];
switch (gpio_info.base & 0x0f) { switch (gpio_info.base & 0x0f) {
case 0: case 0:
...@@ -128,213 +51,3 @@ static uintptr_t mt_gpio_find_reg_addr(uint32_t pin) ...@@ -128,213 +51,3 @@ static uintptr_t mt_gpio_find_reg_addr(uint32_t pin)
return reg_addr; return reg_addr;
} }
static void mt_gpio_set_spec_pull_pupd(uint32_t pin, int enable,
int select)
{
uintptr_t reg1;
uintptr_t reg2;
struct mt_pin_info gpio_info;
gpio_info = mt8192_pin_infos[pin];
uint32_t bit = gpio_info.bit;
reg1 = mt_gpio_find_reg_addr(pin) + gpio_info.offset;
reg2 = reg1 + (gpio_info.base & 0xf0);
if (enable == MT_GPIO_PULL_ENABLE) {
mmio_write_32(reg2 + SET, (1U << bit));
if (select == MT_GPIO_PULL_DOWN) {
mmio_write_32(reg1 + SET, (1U << bit));
} else {
mmio_write_32(reg1 + CLR, (1U << bit));
}
} else {
mmio_write_32(reg2 + CLR, (1U << bit));
mmio_write_32((reg2 + 0x010U) + CLR, (1U << bit));
}
}
static void mt_gpio_set_pull_pu_pd(uint32_t pin, int enable,
int select)
{
uintptr_t reg1;
uintptr_t reg2;
struct mt_pin_info gpio_info;
gpio_info = mt8192_pin_infos[pin];
uint32_t bit = gpio_info.bit;
reg1 = mt_gpio_find_reg_addr(pin) + gpio_info.offset;
reg2 = reg1 - (gpio_info.base & 0xf0);
if (enable == MT_GPIO_PULL_ENABLE) {
if (select == MT_GPIO_PULL_DOWN) {
mmio_write_32(reg1 + CLR, (1U << bit));
mmio_write_32(reg2 + SET, (1U << bit));
} else {
mmio_write_32(reg2 + CLR, (1U << bit));
mmio_write_32(reg1 + SET, (1U << bit));
}
} else {
mmio_write_32(reg1 + CLR, (1U << bit));
mmio_write_32(reg2 + CLR, (1U << bit));
}
}
static void mt_gpio_set_pull_chip(uint32_t pin, int enable,
int select)
{
struct mt_pin_info gpio_info;
gpio_info = mt8192_pin_infos[pin];
if (gpio_info.flag) {
mt_gpio_set_spec_pull_pupd(pin, enable, select);
} else {
mt_gpio_set_pull_pu_pd(pin, enable, select);
}
}
static int mt_gpio_get_spec_pull_pupd(uint32_t pin)
{
uintptr_t reg1;
uintptr_t reg2;
uint32_t r0;
uint32_t r1;
struct mt_pin_info gpio_info;
gpio_info = mt8192_pin_infos[pin];
uint32_t bit = gpio_info.bit;
reg1 = mt_gpio_find_reg_addr(pin) + gpio_info.offset;
reg2 = reg1 + (gpio_info.base & 0xf0);
r0 = (mmio_read_32(reg2) >> bit) & 1U;
r1 = (mmio_read_32(reg2 + 0x010) >> bit) & 1U;
if (r0 == 0U && r1 == 0U) {
return MT_GPIO_PULL_NONE;
} else {
if (mmio_read_32(reg1) & (1U << bit)) {
return MT_GPIO_PULL_DOWN;
} else {
return MT_GPIO_PULL_UP;
}
}
}
static int mt_gpio_get_pull_pu_pd(uint32_t pin)
{
uintptr_t reg1;
uintptr_t reg2;
uint32_t pu;
uint32_t pd;
struct mt_pin_info gpio_info;
gpio_info = mt8192_pin_infos[pin];
uint32_t bit = gpio_info.bit;
reg1 = mt_gpio_find_reg_addr(pin) + gpio_info.offset;
reg2 = reg1 - (gpio_info.base & 0xf0);
pu = (mmio_read_32(reg1) >> bit) & 1U;
pd = (mmio_read_32(reg2) >> bit) & 1U;
if (pu == 1U) {
return MT_GPIO_PULL_UP;
} else if (pd == 1U) {
return MT_GPIO_PULL_DOWN;
} else {
return MT_GPIO_PULL_NONE;
}
}
static int mt_gpio_get_pull_chip(uint32_t pin)
{
struct mt_pin_info gpio_info;
gpio_info = mt8192_pin_infos[pin];
if (gpio_info.flag) {
return mt_gpio_get_spec_pull_pupd(pin);
} else {
return mt_gpio_get_pull_pu_pd(pin);
}
}
static void mt_set_gpio_pull_select_chip(uint32_t pin, int sel)
{
assert(pin < MAX_GPIO_PIN);
if (sel == MT_GPIO_PULL_NONE) {
mt_gpio_set_pull_chip(pin, MT_GPIO_PULL_DISABLE, MT_GPIO_PULL_DOWN);
} else if (sel == MT_GPIO_PULL_UP) {
mt_gpio_set_pull_chip(pin, MT_GPIO_PULL_ENABLE, MT_GPIO_PULL_UP);
} else if (sel == MT_GPIO_PULL_DOWN) {
mt_gpio_set_pull_chip(pin, MT_GPIO_PULL_ENABLE, MT_GPIO_PULL_DOWN);
}
}
/* get pull-up or pull-down, regardless of resistor value */
static int mt_get_gpio_pull_select_chip(uint32_t pin)
{
assert(pin < MAX_GPIO_PIN);
return mt_gpio_get_pull_chip(pin);
}
static void mt_set_gpio_dir(int gpio, int direction)
{
mt_set_gpio_dir_chip((uint32_t)gpio, direction);
}
static int mt_get_gpio_dir(int gpio)
{
uint32_t pin;
pin = (uint32_t)gpio;
return mt_get_gpio_dir_chip(pin);
}
static void mt_set_gpio_pull(int gpio, int pull)
{
uint32_t pin;
pin = (uint32_t)gpio;
mt_set_gpio_pull_select_chip(pin, pull);
}
static int mt_get_gpio_pull(int gpio)
{
uint32_t pin;
pin = (uint32_t)gpio;
return mt_get_gpio_pull_select_chip(pin);
}
static void mt_set_gpio_out(int gpio, int value)
{
uint32_t pin;
pin = (uint32_t)gpio;
mt_set_gpio_out_chip(pin, value);
}
static int mt_get_gpio_in(int gpio)
{
uint32_t pin;
pin = (uint32_t)gpio;
return mt_get_gpio_in_chip(pin);
}
const gpio_ops_t mtgpio_ops = {
.get_direction = mt_get_gpio_dir,
.set_direction = mt_set_gpio_dir,
.get_value = mt_get_gpio_in,
.set_value = mt_set_gpio_out,
.set_pull = mt_set_gpio_pull,
.get_pull = mt_get_gpio_pull,
};
void plat_mt8192_gpio_init(void)
{
gpio_init(&mtgpio_ops);
}
...@@ -7,17 +7,7 @@ ...@@ -7,17 +7,7 @@
#ifndef MT_GPIO_H #ifndef MT_GPIO_H
#define MT_GPIO_H #define MT_GPIO_H
#include <stdbool.h> #include <mtgpio_common.h>
#include <stdint.h>
#include <plat/common/common_def.h>
/* Error Code No. */
#define RSUCCESS 0
#define ERACCESS 1
#define ERINVAL 2
#define ERWRAPPER 3
#define MAX_GPIO_PIN MT_GPIO_BASE_MAX
/* Enumeration for GPIO pin */ /* Enumeration for GPIO pin */
typedef enum GPIO_PIN { typedef enum GPIO_PIN {
...@@ -54,110 +44,7 @@ typedef enum GPIO_PIN { ...@@ -54,110 +44,7 @@ typedef enum GPIO_PIN {
MT_GPIO_BASE_MAX MT_GPIO_BASE_MAX
} GPIO_PIN; } GPIO_PIN;
/* GPIO MODE CONTROL VALUE*/ static const struct mt_pin_info mt_pin_infos[] = {
typedef enum {
GPIO_MODE_UNSUPPORTED = -1,
GPIO_MODE_GPIO = 0,
GPIO_MODE_00 = 0,
GPIO_MODE_01,
GPIO_MODE_02,
GPIO_MODE_03,
GPIO_MODE_04,
GPIO_MODE_05,
GPIO_MODE_06,
GPIO_MODE_07,
GPIO_MODE_MAX,
GPIO_MODE_DEFAULT = GPIO_MODE_00,
} GPIO_MODE;
/* GPIO DIRECTION */
typedef enum {
MT_GPIO_DIR_UNSUPPORTED = -1,
MT_GPIO_DIR_OUT = 0,
MT_GPIO_DIR_IN = 1,
MT_GPIO_DIR_MAX,
MT_GPIO_DIR_DEFAULT = MT_GPIO_DIR_IN,
} GPIO_DIR;
/* GPIO PULL ENABLE*/
typedef enum {
MT_GPIO_PULL_EN_UNSUPPORTED = -1,
MT_GPIO_PULL_DISABLE = 0,
MT_GPIO_PULL_ENABLE = 1,
MT_GPIO_PULL_ENABLE_R0 = 2,
MT_GPIO_PULL_ENABLE_R1 = 3,
MT_GPIO_PULL_ENABLE_R0R1 = 4,
MT_GPIO_PULL_EN_MAX,
MT_GPIO_PULL_EN_DEFAULT = MT_GPIO_PULL_ENABLE,
} GPIO_PULL_EN;
/* GPIO PULL-UP/PULL-DOWN*/
typedef enum {
MT_GPIO_PULL_UNSUPPORTED = -1,
MT_GPIO_PULL_NONE = 0,
MT_GPIO_PULL_UP = 1,
MT_GPIO_PULL_DOWN = 2,
MT_GPIO_PULL_MAX,
MT_GPIO_PULL_DEFAULT = MT_GPIO_PULL_DOWN
} GPIO_PULL;
/* GPIO OUTPUT */
typedef enum {
MT_GPIO_OUT_UNSUPPORTED = -1,
MT_GPIO_OUT_ZERO = 0,
MT_GPIO_OUT_ONE = 1,
MT_GPIO_OUT_MAX,
MT_GPIO_OUT_DEFAULT = MT_GPIO_OUT_ZERO,
MT_GPIO_DATA_OUT_DEFAULT = MT_GPIO_OUT_ZERO, /*compatible with DCT*/
} GPIO_OUT;
/* GPIO INPUT */
typedef enum {
MT_GPIO_IN_UNSUPPORTED = -1,
MT_GPIO_IN_ZERO = 0,
MT_GPIO_IN_ONE = 1,
MT_GPIO_IN_MAX,
} GPIO_IN;
typedef struct {
uint32_t val;
uint32_t set;
uint32_t rst;
uint32_t _align1;
} VAL_REGS;
typedef struct {
VAL_REGS dir[7];
uint8_t rsv00[144];
VAL_REGS dout[7];
uint8_t rsv01[144];
VAL_REGS din[7];
uint8_t rsv02[144];
VAL_REGS mode[28];
} GPIO_REGS;
#define PIN(_id, _flag, _bit, _base, _offset) { \
.id = _id, \
.flag = _flag, \
.bit = _bit, \
.base = _base, \
.offset = _offset, \
}
struct mt_pin_info {
uint8_t id;
uint8_t flag;
uint8_t bit;
uint16_t base;
uint16_t offset;
};
static const struct mt_pin_info mt8192_pin_infos[] = {
PIN(0, 0, 9, 0x23, 0xb0), PIN(0, 0, 9, 0x23, 0xb0),
PIN(1, 0, 10, 0x23, 0xb0), PIN(1, 0, 10, 0x23, 0xb0),
PIN(2, 0, 11, 0x23, 0xb0), PIN(2, 0, 11, 0x23, 0xb0),
...@@ -379,6 +266,4 @@ static const struct mt_pin_info mt8192_pin_infos[] = { ...@@ -379,6 +266,4 @@ static const struct mt_pin_info mt8192_pin_infos[] = {
PIN(218, 0, 1, 0x14, 0x50), PIN(218, 0, 1, 0x14, 0x50),
PIN(219, 0, 2, 0x14, 0x50), PIN(219, 0, 2, 0x14, 0x50),
}; };
void plat_mt8192_gpio_init(void);
#endif /* MT_GPIO_H */ #endif /* MT_GPIO_H */
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
#include <mt_lp_rm.h> #include <mt_lp_rm.h>
#include <mt_lp_irqremain.h> #include <mt_lp_irqremain.h>
#include <mtk_cirq.h>
#include <plat_mtk_lpm.h> #include <plat_mtk_lpm.h>
#include <plat_mt_cirq.h>
#define EDMA0_IRQ_ID U(448) #define EDMA0_IRQ_ID U(448)
#define MDLA_IRQ_ID U(446) #define MDLA_IRQ_ID U(446)
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#ifndef ATF_PLAT_CIRQ_UNSUPPORT #ifndef ATF_PLAT_CIRQ_UNSUPPORT
#include <mt_gic_v3.h> #include <mt_gic_v3.h>
#include <plat_mt_cirq.h> #include <mtk_cirq.h>
#endif #endif
#define CONSTRAINT_BUS26M_ALLOW \ #define CONSTRAINT_BUS26M_ALLOW \
......
...@@ -65,13 +65,19 @@ ...@@ -65,13 +65,19 @@
#define SYS_COUNTER_FREQ_IN_MHZ 13 #define SYS_COUNTER_FREQ_IN_MHZ 13
/******************************************************************************* /*******************************************************************************
* GIC-400 & interrupt handling related constants * GIC-600 & interrupt handling related constants
******************************************************************************/ ******************************************************************************/
/* Base MTK_platform compatible GIC memory map */ /* Base MTK_platform compatible GIC memory map */
#define BASE_GICD_BASE MT_GIC_BASE #define BASE_GICD_BASE MT_GIC_BASE
#define MT_GIC_RDIST_BASE (MT_GIC_BASE + 0x40000) #define MT_GIC_RDIST_BASE (MT_GIC_BASE + 0x40000)
#define SYS_CIRQ_BASE (IO_PHYS + 0x204000)
#define CIRQ_REG_NUM 14
#define CIRQ_IRQ_NUM 439
#define CIRQ_SPI_START 64
#define MD_WDT_IRQ_BIT_ID 110
/******************************************************************************* /*******************************************************************************
* Platform binary types for linking * Platform binary types for linking
******************************************************************************/ ******************************************************************************/
......
/*
* Copyright (c) 2021, MediaTek Inc. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef RTC_H
#define RTC_H
#include <rtc_mt6359p.h>
#endif /* RTC_H */
...@@ -8,6 +8,10 @@ MTK_PLAT := plat/mediatek ...@@ -8,6 +8,10 @@ MTK_PLAT := plat/mediatek
MTK_PLAT_SOC := ${MTK_PLAT}/${PLAT} MTK_PLAT_SOC := ${MTK_PLAT}/${PLAT}
PLAT_INCLUDES := -I${MTK_PLAT}/common/ \ PLAT_INCLUDES := -I${MTK_PLAT}/common/ \
-I${MTK_PLAT}/common/drivers/gic600/ \
-I${MTK_PLAT}/common/drivers/gpio/ \
-I${MTK_PLAT}/common/drivers/rtc/ \
-I${MTK_PLAT}/common/drivers/timer/ \
-I${MTK_PLAT}/common/drivers/uart/ \ -I${MTK_PLAT}/common/drivers/uart/ \
-I${MTK_PLAT}/common/lpm/ \ -I${MTK_PLAT}/common/lpm/ \
-I${MTK_PLAT_SOC}/include/ \ -I${MTK_PLAT_SOC}/include/ \
...@@ -19,9 +23,7 @@ PLAT_INCLUDES := -I${MTK_PLAT}/common/ \ ...@@ -19,9 +23,7 @@ PLAT_INCLUDES := -I${MTK_PLAT}/common/ \
-I${MTK_PLAT_SOC}/drivers/mcdi/ \ -I${MTK_PLAT_SOC}/drivers/mcdi/ \
-I${MTK_PLAT_SOC}/drivers/pmic/ \ -I${MTK_PLAT_SOC}/drivers/pmic/ \
-I${MTK_PLAT_SOC}/drivers/ptp3/ \ -I${MTK_PLAT_SOC}/drivers/ptp3/ \
-I${MTK_PLAT_SOC}/drivers/rtc/ \ -I${MTK_PLAT_SOC}/drivers/spmc/
-I${MTK_PLAT_SOC}/drivers/spmc/ \
-I${MTK_PLAT_SOC}/drivers/timer/
GICV3_SUPPORT_GIC600 := 1 GICV3_SUPPORT_GIC600 := 1
include drivers/arm/gic/v3/gicv3.mk include drivers/arm/gic/v3/gicv3.mk
...@@ -41,10 +43,15 @@ BL31_SOURCES += common/desc_image_load.c \ ...@@ -41,10 +43,15 @@ BL31_SOURCES += common/desc_image_load.c \
lib/cpus/aarch64/cortex_a55.S \ lib/cpus/aarch64/cortex_a55.S \
lib/cpus/aarch64/cortex_a76.S \ lib/cpus/aarch64/cortex_a76.S \
plat/common/plat_gicv3.c \ plat/common/plat_gicv3.c \
${MTK_PLAT}/common/drivers/gic600/mt_gic_v3.c \
${MTK_PLAT}/common/drivers/gpio/mtgpio_common.c \
${MTK_PLAT}/common/drivers/pmic_wrap/pmic_wrap_init_v2.c \ ${MTK_PLAT}/common/drivers/pmic_wrap/pmic_wrap_init_v2.c \
${MTK_PLAT}/common/drivers/rtc/rtc_common.c \ ${MTK_PLAT}/common/drivers/rtc/rtc_common.c \
${MTK_PLAT}/common/drivers/rtc/rtc_mt6359p.c \
${MTK_PLAT}/common/drivers/timer/mt_timer.c \
${MTK_PLAT}/common/drivers/uart/uart.c \ ${MTK_PLAT}/common/drivers/uart/uart.c \
${MTK_PLAT}/common/lpm/mt_lp_rm.c \ ${MTK_PLAT}/common/lpm/mt_lp_rm.c \
${MTK_PLAT}/common/mtk_cirq.c \
${MTK_PLAT}/common/mtk_plat_common.c \ ${MTK_PLAT}/common/mtk_plat_common.c \
${MTK_PLAT}/common/mtk_sip_svc.c \ ${MTK_PLAT}/common/mtk_sip_svc.c \
${MTK_PLAT}/common/params_setup.c \ ${MTK_PLAT}/common/params_setup.c \
...@@ -52,11 +59,8 @@ BL31_SOURCES += common/desc_image_load.c \ ...@@ -52,11 +59,8 @@ BL31_SOURCES += common/desc_image_load.c \
${MTK_PLAT_SOC}/aarch64/plat_helpers.S \ ${MTK_PLAT_SOC}/aarch64/plat_helpers.S \
${MTK_PLAT_SOC}/bl31_plat_setup.c \ ${MTK_PLAT_SOC}/bl31_plat_setup.c \
${MTK_PLAT_SOC}/drivers/pmic/pmic.c \ ${MTK_PLAT_SOC}/drivers/pmic/pmic.c \
${MTK_PLAT_SOC}/drivers/rtc/rtc.c \
${MTK_PLAT_SOC}/plat_pm.c \ ${MTK_PLAT_SOC}/plat_pm.c \
${MTK_PLAT_SOC}/plat_topology.c \ ${MTK_PLAT_SOC}/plat_topology.c \
${MTK_PLAT_SOC}/plat_mt_gic.c \
${MTK_PLAT_SOC}/plat_mt_cirq.c \
${MTK_PLAT_SOC}/plat_sip_calls.c \ ${MTK_PLAT_SOC}/plat_sip_calls.c \
${MTK_PLAT_SOC}/drivers/dcm/mtk_dcm.c \ ${MTK_PLAT_SOC}/drivers/dcm/mtk_dcm.c \
${MTK_PLAT_SOC}/drivers/dcm/mtk_dcm_utils.c \ ${MTK_PLAT_SOC}/drivers/dcm/mtk_dcm_utils.c \
...@@ -68,8 +72,7 @@ BL31_SOURCES += common/desc_image_load.c \ ...@@ -68,8 +72,7 @@ BL31_SOURCES += common/desc_image_load.c \
${MTK_PLAT_SOC}/drivers/mcdi/mt_lp_irqremain.c \ ${MTK_PLAT_SOC}/drivers/mcdi/mt_lp_irqremain.c \
${MTK_PLAT_SOC}/drivers/mcdi/mt_mcdi.c \ ${MTK_PLAT_SOC}/drivers/mcdi/mt_mcdi.c \
${MTK_PLAT_SOC}/drivers/ptp3/mtk_ptp3_main.c \ ${MTK_PLAT_SOC}/drivers/ptp3/mtk_ptp3_main.c \
${MTK_PLAT_SOC}/drivers/spmc/mtspmc.c \ ${MTK_PLAT_SOC}/drivers/spmc/mtspmc.c
${MTK_PLAT_SOC}/drivers/timer/mt_timer.c
# Build SPM drivers # Build SPM drivers
include ${MTK_PLAT_SOC}/drivers/spm/build.mk include ${MTK_PLAT_SOC}/drivers/spm/build.mk
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment