driver: gpio: Add gpio driver initial version of RTS5912.
Add gpio driver for Realtek RTS5912. Signed-off-by: Lin Yu-Cheng <lin_yu_cheng@realtek.com>
This commit is contained in:
parent
cfb2074a5e
commit
2656029c3a
8 changed files with 677 additions and 0 deletions
|
@ -82,6 +82,7 @@ zephyr_library_sources_ifdef(CONFIG_GPIO_RP1 gpio_rp1.c)
|
|||
zephyr_library_sources_ifdef(CONFIG_GPIO_RPI_PICO gpio_rpi_pico.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_GPIO_RT1718S gpio_rt1718s.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_GPIO_RT1718S gpio_rt1718s_port.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_GPIO_RTS5912 gpio_rts5912.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_GPIO_RV32M1 gpio_rv32m1.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_GPIO_RZT2M gpio_rzt2m.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_GPIO_SAM gpio_sam.c)
|
||||
|
|
|
@ -167,6 +167,7 @@ source "drivers/gpio/Kconfig.renesas_rz"
|
|||
source "drivers/gpio/Kconfig.rp1"
|
||||
source "drivers/gpio/Kconfig.rpi_pico"
|
||||
source "drivers/gpio/Kconfig.rt1718s"
|
||||
source "drivers/gpio/Kconfig.rts5912"
|
||||
source "drivers/gpio/Kconfig.rv32m1"
|
||||
source "drivers/gpio/Kconfig.rzt2m"
|
||||
source "drivers/gpio/Kconfig.sam"
|
||||
|
|
10
drivers/gpio/Kconfig.rts5912
Normal file
10
drivers/gpio/Kconfig.rts5912
Normal file
|
@ -0,0 +1,10 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# Copyright (c) 2024 Realtek Semiconductor Corporation, SIBG-SD7
|
||||
#
|
||||
|
||||
config GPIO_RTS5912
|
||||
bool "Realtek embedded controller (EC) gpio driver"
|
||||
default y if DT_HAS_REALTEK_RTS5912_GPIO_ENABLED
|
||||
help
|
||||
Enable support for Realtek GPIO controller.
|
457
drivers/gpio/gpio_rts5912.c
Normal file
457
drivers/gpio/gpio_rts5912.c
Normal file
|
@ -0,0 +1,457 @@
|
|||
/*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Copyright (c) 2024 Realtek Semiconductor Corporation, SIBG-SD7
|
||||
* Author: Lin Yu-Cheng <lin_yu_cheng@realtek.com>
|
||||
*/
|
||||
|
||||
#define DT_DRV_COMPAT realtek_rts5912_gpio
|
||||
|
||||
#include <errno.h>
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/drivers/gpio.h>
|
||||
#include <zephyr/irq.h>
|
||||
#include "zephyr/drivers/gpio/gpio_utils.h"
|
||||
#include <zephyr/logging/log.h>
|
||||
#include <zephyr/dt-bindings/gpio/realtek-gpio.h>
|
||||
|
||||
#include <reg/reg_gpio.h>
|
||||
|
||||
LOG_MODULE_REGISTER(gpio_rts5912, CONFIG_GPIO_LOG_LEVEL);
|
||||
|
||||
#define RTS5912_GPIOA_REG_BASE ((GPIO_Type *)(DT_REG_ADDR(DT_NODELABEL(gpioa))))
|
||||
|
||||
struct gpio_rts5912_config {
|
||||
struct gpio_driver_config common;
|
||||
volatile uint32_t *reg_base;
|
||||
uint8_t num_pins;
|
||||
};
|
||||
|
||||
struct gpio_rts5912_data {
|
||||
struct gpio_driver_data common;
|
||||
sys_slist_t callbacks;
|
||||
};
|
||||
|
||||
static int pin_is_valid(const struct gpio_rts5912_config *config, gpio_pin_t pin)
|
||||
{
|
||||
if (pin >= config->num_pins) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int pin_output_high(const struct device *port, gpio_pin_t pin)
|
||||
{
|
||||
const struct gpio_rts5912_config *config = port->config;
|
||||
volatile uint32_t *gcr = &config->reg_base[pin];
|
||||
|
||||
int err = pin_is_valid(config, pin);
|
||||
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if (*gcr & GPIO_GCR_OUTMD_Msk) {
|
||||
/* Switch I/O mode to input mode when configuration is open-drain with output high
|
||||
*/
|
||||
*gcr = (*gcr & ~GPIO_GCR_DIR_Msk) | GPIO_GCR_OUTCTRL_Msk;
|
||||
} else {
|
||||
*gcr |= GPIO_GCR_OUTCTRL_Msk | GPIO_GCR_DIR_Msk;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int pin_output_low(const struct device *port, gpio_pin_t pin)
|
||||
{
|
||||
const struct gpio_rts5912_config *config = port->config;
|
||||
volatile uint32_t *gcr = &config->reg_base[pin];
|
||||
|
||||
int err = pin_is_valid(config, pin);
|
||||
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
*gcr = (*gcr & ~GPIO_GCR_OUTCTRL_Msk) | GPIO_GCR_DIR_Msk;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int gpio_rts5912_configuration(const struct device *port, gpio_pin_t pin, gpio_flags_t flags)
|
||||
{
|
||||
const struct gpio_rts5912_config *config = port->config;
|
||||
volatile uint32_t *gcr = &config->reg_base[pin];
|
||||
uint32_t cfg_val = *gcr;
|
||||
|
||||
int err = pin_is_valid(config, pin);
|
||||
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if (flags & GPIO_INPUT) {
|
||||
cfg_val &= ~GPIO_GCR_DIR_Msk;
|
||||
cfg_val &= ~GPIO_GCR_OUTCTRL_Msk;
|
||||
cfg_val |= GPIO_GCR_INDETEN_Msk;
|
||||
}
|
||||
|
||||
if (flags & GPIO_OPEN_DRAIN) {
|
||||
cfg_val |= GPIO_GCR_OUTMD_Msk;
|
||||
} else {
|
||||
cfg_val &= ~GPIO_GCR_OUTMD_Msk;
|
||||
}
|
||||
|
||||
switch (flags & (GPIO_PULL_UP | GPIO_PULL_DOWN)) {
|
||||
case GPIO_PULL_UP:
|
||||
cfg_val &= ~GPIO_GCR_PULLDWEN_Msk;
|
||||
cfg_val |= GPIO_GCR_PULLUPEN_Msk;
|
||||
break;
|
||||
case GPIO_PULL_DOWN:
|
||||
cfg_val &= ~GPIO_GCR_PULLUPEN_Msk;
|
||||
cfg_val |= GPIO_GCR_PULLDWEN_Msk;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (flags & RTS5912_GPIO_VOLTAGE_MASK) {
|
||||
case RTS5912_GPIO_VOLTAGE_1V8:
|
||||
cfg_val |= GPIO_GCR_INVOLMD_Msk;
|
||||
break;
|
||||
case RTS5912_GPIO_VOLTAGE_DEFAULT:
|
||||
case RTS5912_GPIO_VOLTAGE_3V3:
|
||||
cfg_val &= ~GPIO_GCR_INVOLMD_Msk;
|
||||
break;
|
||||
case RTS5912_GPIO_VOLTAGE_5V0:
|
||||
return -ENOTSUP;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
*gcr = cfg_val;
|
||||
|
||||
if (flags & GPIO_OUTPUT) {
|
||||
if (flags & GPIO_OUTPUT_INIT_HIGH) {
|
||||
pin_output_high(port, pin);
|
||||
} else {
|
||||
pin_output_low(port, pin);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_GPIO_GET_CONFIG
|
||||
static int gpio_rts5912_get_configuration(const struct device *port, gpio_pin_t pin,
|
||||
gpio_flags_t *flags)
|
||||
{
|
||||
const struct gpio_rts5912_config *config = port->config;
|
||||
volatile uint32_t *gcr = &config->reg_base[pin];
|
||||
gpio_flags_t cfg_flag = 0x0UL;
|
||||
|
||||
int err = pin_is_valid(config, pin);
|
||||
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if (*gcr & GPIO_GCR_OUTCTRL_Msk) {
|
||||
cfg_flag |= GPIO_OUTPUT | GPIO_OUTPUT_INIT_HIGH;
|
||||
} else {
|
||||
if (*gcr & GPIO_GCR_DIR_Msk) {
|
||||
cfg_flag |= GPIO_OUTPUT | GPIO_OUTPUT_INIT_LOW;
|
||||
} else {
|
||||
cfg_flag |= GPIO_INPUT;
|
||||
if (*gcr & GPIO_GCR_INVOLMD_Msk) {
|
||||
cfg_flag |= RTS5912_GPIO_VOLTAGE_1V8;
|
||||
} else {
|
||||
cfg_flag |= RTS5912_GPIO_VOLTAGE_3V3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (*gcr & GPIO_GCR_OUTMD_Msk) {
|
||||
cfg_flag |= GPIO_OPEN_DRAIN;
|
||||
}
|
||||
|
||||
if (*gcr & GPIO_GCR_PULLUPEN_Msk) {
|
||||
cfg_flag |= GPIO_PULL_UP;
|
||||
} else if (*gcr & GPIO_GCR_PULLDWEN_Msk) {
|
||||
cfg_flag |= GPIO_PULL_DOWN;
|
||||
}
|
||||
|
||||
*flags = cfg_flag;
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int gpio_rts5912_port_get_raw(const struct device *port, gpio_port_value_t *value)
|
||||
{
|
||||
const struct gpio_rts5912_config *config = port->config;
|
||||
gpio_port_value_t ret_val = 0;
|
||||
uint16_t mask = 0x1U;
|
||||
|
||||
for (gpio_pin_t i = 0; i < config->num_pins; i++) {
|
||||
if (config->reg_base[i] & GPIO_GCR_PINSTS_Msk) {
|
||||
ret_val |= (gpio_port_value_t)mask;
|
||||
}
|
||||
mask <<= 1;
|
||||
}
|
||||
|
||||
*value = ret_val;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int gpio_rts5912_port_set_masked_raw(const struct device *port, gpio_port_pins_t mask,
|
||||
gpio_port_value_t value)
|
||||
{
|
||||
const struct gpio_rts5912_config *config = port->config;
|
||||
uint32_t pin;
|
||||
|
||||
mask &= 0x0000FFFF;
|
||||
for (; mask; mask &= ~BIT(pin)) {
|
||||
pin = find_lsb_set(mask) - 1;
|
||||
if (pin >= config->num_pins) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (value & BIT(pin)) {
|
||||
pin_output_high(port, pin);
|
||||
} else {
|
||||
pin_output_low(port, pin);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int gpio_rts5912_port_set_bits_raw(const struct device *port, gpio_port_pins_t pins)
|
||||
{
|
||||
const struct gpio_rts5912_config *config = port->config;
|
||||
volatile uint32_t *gcr = config->reg_base;
|
||||
uint32_t pin = 0;
|
||||
|
||||
pins &= 0x0000FFFF;
|
||||
gpio_port_pins_t sel_pin = 1;
|
||||
|
||||
for (; pins;) {
|
||||
if (pins & sel_pin) {
|
||||
pin_output_high(port, pin);
|
||||
}
|
||||
pins &= ~sel_pin;
|
||||
sel_pin <<= 1;
|
||||
gcr++;
|
||||
pin++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int gpio_rts5912_port_clear_bits_raw(const struct device *port, gpio_port_pins_t pins)
|
||||
{
|
||||
const struct gpio_rts5912_config *config = port->config;
|
||||
volatile uint32_t *gcr = config->reg_base;
|
||||
uint32_t pin = 0;
|
||||
|
||||
pins &= 0x0000FFFF;
|
||||
gpio_port_pins_t sel_pin = 1;
|
||||
|
||||
for (; pins;) {
|
||||
if (pins & sel_pin) {
|
||||
pin_output_low(port, pin);
|
||||
}
|
||||
pins &= ~sel_pin;
|
||||
sel_pin <<= 1;
|
||||
gcr++;
|
||||
pin++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int gpio_rts5912_port_toggle_bits(const struct device *port, gpio_port_pins_t pins)
|
||||
{
|
||||
const struct gpio_rts5912_config *config = port->config;
|
||||
volatile uint32_t *gcr = config->reg_base;
|
||||
uint32_t pin = 0;
|
||||
|
||||
pins &= 0x0000FFFF;
|
||||
gpio_port_pins_t sel_pin = 0x1UL;
|
||||
|
||||
for (; pins;) {
|
||||
if (pins & sel_pin) {
|
||||
if (*gcr & GPIO_GCR_OUTCTRL_Msk) {
|
||||
pin_output_low(port, pin);
|
||||
} else {
|
||||
pin_output_high(port, pin);
|
||||
}
|
||||
}
|
||||
|
||||
pins &= ~sel_pin;
|
||||
sel_pin <<= 1;
|
||||
gcr++;
|
||||
pin++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static gpio_pin_t gpio_rts5912_get_intr_pin(volatile uint32_t *reg_base)
|
||||
{
|
||||
gpio_pin_t pin = 0U;
|
||||
|
||||
for (; pin < 16; pin++) {
|
||||
if (reg_base[pin] & GPIO_GCR_INTSTS_Msk) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return pin;
|
||||
}
|
||||
|
||||
static void gpio_rts5912_isr(const void *arg)
|
||||
{
|
||||
const struct device *port = arg;
|
||||
const struct gpio_rts5912_config *config = port->config;
|
||||
struct gpio_rts5912_data *data = port->data;
|
||||
volatile uint32_t *gcr = config->reg_base;
|
||||
unsigned int key = irq_lock();
|
||||
gpio_pin_t pin = gpio_rts5912_get_intr_pin(gcr);
|
||||
|
||||
if (gcr[pin] & GPIO_GCR_INTSTS_Msk) {
|
||||
gcr[pin] |= GPIO_GCR_INTSTS_Msk;
|
||||
|
||||
gpio_fire_callbacks(&data->callbacks, port, BIT(pin));
|
||||
}
|
||||
irq_unlock(key);
|
||||
}
|
||||
|
||||
static int gpio_rts5912_intr_config(const struct device *port, gpio_pin_t pin,
|
||||
enum gpio_int_mode mode, enum gpio_int_trig trig)
|
||||
{
|
||||
const struct gpio_rts5912_config *config = port->config;
|
||||
volatile uint32_t *gcr = &config->reg_base[pin];
|
||||
uint32_t cfg_val = *gcr;
|
||||
uint32_t pin_index =
|
||||
DT_IRQ_BY_IDX(DT_NODELABEL(gpioa), 0, irq) +
|
||||
((uint32_t)(&config->reg_base[pin]) - (uint32_t)(RTS5912_GPIOA_REG_BASE)) / 4;
|
||||
|
||||
int err = pin_is_valid(config, pin);
|
||||
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
switch (mode) {
|
||||
case GPIO_INT_MODE_DISABLED:
|
||||
cfg_val &= ~GPIO_GCR_INTEN_Msk;
|
||||
irq_disable(pin_index);
|
||||
*gcr = cfg_val;
|
||||
return 0;
|
||||
case GPIO_INT_MODE_LEVEL:
|
||||
switch (trig) {
|
||||
case GPIO_INT_TRIG_LOW:
|
||||
cfg_val &= ~GPIO_GCR_INTCTRL_Msk;
|
||||
cfg_val |= 0x03UL << GPIO_GCR_INTCTRL_Pos;
|
||||
break;
|
||||
case GPIO_INT_TRIG_HIGH:
|
||||
cfg_val &= ~GPIO_GCR_INTCTRL_Msk;
|
||||
cfg_val |= 0x04UL << GPIO_GCR_INTCTRL_Pos;
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
break;
|
||||
case GPIO_INT_MODE_EDGE:
|
||||
switch (trig) {
|
||||
case GPIO_INT_TRIG_LOW:
|
||||
cfg_val &= ~GPIO_GCR_INTCTRL_Msk;
|
||||
cfg_val |= 0x01UL << GPIO_GCR_INTCTRL_Pos;
|
||||
break;
|
||||
case GPIO_INT_TRIG_HIGH:
|
||||
cfg_val &= ~GPIO_GCR_INTCTRL_Msk;
|
||||
cfg_val |= 0x00UL << GPIO_GCR_INTCTRL_Pos;
|
||||
break;
|
||||
case GPIO_INT_TRIG_BOTH:
|
||||
cfg_val &= ~GPIO_GCR_INTCTRL_Msk;
|
||||
cfg_val |= 0x2UL << GPIO_GCR_INTCTRL_Pos;
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
cfg_val |= GPIO_GCR_INTEN_Msk;
|
||||
*gcr = cfg_val;
|
||||
|
||||
irq_enable(pin_index);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int gpio_rts5912_manage_cb(const struct device *port, struct gpio_callback *cb, bool set)
|
||||
{
|
||||
struct gpio_rts5912_data *data = port->data;
|
||||
|
||||
return gpio_manage_callback(&data->callbacks, cb, set);
|
||||
}
|
||||
|
||||
static DEVICE_API(gpio, gpio_rts5912_driver_api) = {
|
||||
.pin_configure = gpio_rts5912_configuration,
|
||||
#ifdef CONFIG_GPIO_GET_CONFIG
|
||||
.pin_get_config = gpio_rts5912_get_configuration,
|
||||
#endif
|
||||
.port_get_raw = gpio_rts5912_port_get_raw,
|
||||
.port_set_masked_raw = gpio_rts5912_port_set_masked_raw,
|
||||
.port_set_bits_raw = gpio_rts5912_port_set_bits_raw,
|
||||
.port_clear_bits_raw = gpio_rts5912_port_clear_bits_raw,
|
||||
.port_toggle_bits = gpio_rts5912_port_toggle_bits,
|
||||
.pin_interrupt_configure = gpio_rts5912_intr_config,
|
||||
.manage_callback = gpio_rts5912_manage_cb,
|
||||
};
|
||||
|
||||
#ifdef CONFIG_GEN_ISR_TABLES
|
||||
#define RTS5912_GPIO_DTNAMIC_IRQ(id) \
|
||||
for (int i = 0; i < 16 && (DT_INST_IRQ_BY_IDX(id, 0, irq) + i) < 132; i++) { \
|
||||
irq_connect_dynamic((DT_INST_IRQ_BY_IDX(id, 0, irq) + i), \
|
||||
DT_INST_IRQ(id, priority), gpio_rts5912_isr, \
|
||||
DEVICE_DT_INST_GET(id), 0U); \
|
||||
}
|
||||
#else
|
||||
#define RTS5912_GPIO_DTNAMIC_IRQ(id) \
|
||||
IRQ_CONNECT(DT_INST_IRQN(id), DT_INST_IRQ(id, priority), gpio_rts5912_isr, \
|
||||
DEVICE_DT_INST_GET(id), 0U);
|
||||
#endif
|
||||
|
||||
#define GPIO_RTS5912_INIT(id) \
|
||||
static int gpio_rts5912_init_##id(const struct device *dev) \
|
||||
{ \
|
||||
if (!(DT_INST_IRQ_HAS_CELL(id, irq))) { \
|
||||
return 0; \
|
||||
} \
|
||||
\
|
||||
RTS5912_GPIO_DTNAMIC_IRQ(id) \
|
||||
\
|
||||
return 0; \
|
||||
} \
|
||||
\
|
||||
static struct gpio_rts5912_data gpio_rts5912_data_##id; \
|
||||
\
|
||||
static const struct gpio_rts5912_config gpio_rts5912_config_##id = { \
|
||||
.common = {.port_pin_mask = GPIO_PORT_PIN_MASK_FROM_DT_INST(id)}, \
|
||||
.reg_base = (volatile uint32_t *)DT_INST_REG_ADDR(id), \
|
||||
.num_pins = DT_INST_PROP(id, ngpios), \
|
||||
}; \
|
||||
DEVICE_DT_INST_DEFINE(id, gpio_rts5912_init_##id, NULL, &gpio_rts5912_data_##id, \
|
||||
&gpio_rts5912_config_##id, POST_KERNEL, CONFIG_GPIO_INIT_PRIORITY, \
|
||||
&gpio_rts5912_driver_api);
|
||||
|
||||
DT_INST_FOREACH_STATUS_OKAY(GPIO_RTS5912_INIT)
|
|
@ -97,6 +97,123 @@
|
|||
#address-cells = <1>;
|
||||
#size-cells = <1>;
|
||||
reg = <0x40090000 0x300>;
|
||||
|
||||
/* GPIO0-GPIO15 */
|
||||
gpioa: gpio@40090000 {
|
||||
compatible = "realtek,rts5912-gpio";
|
||||
gpio-controller;
|
||||
#gpio-cells = <2>;
|
||||
reg = <0x40090000 0x40>;
|
||||
ngpios = <16>;
|
||||
interrupts = <0 0 1 0 2 0 3 0
|
||||
4 0 5 0 6 0 7 0
|
||||
8 0 9 0 10 0 11 0
|
||||
12 0 13 0 14 0 15 0>;
|
||||
};
|
||||
|
||||
/* GPIO16-GPIO31 */
|
||||
gpiob: gpio@40090040 {
|
||||
compatible = "realtek,rts5912-gpio";
|
||||
gpio-controller;
|
||||
#gpio-cells = <2>;
|
||||
reg = <0x40090040 0x40>;
|
||||
ngpios = <16>;
|
||||
interrupts = <16 0 17 0 18 0 19 0
|
||||
20 0 21 0 22 0 23 0
|
||||
24 0 25 0 26 0 27 0
|
||||
28 0 29 0 30 0 31 0>;
|
||||
};
|
||||
|
||||
/* GPIO32-GPIO47 */
|
||||
gpioc: gpio@40090080 {
|
||||
compatible = "realtek,rts5912-gpio";
|
||||
gpio-controller;
|
||||
#gpio-cells = <2>;
|
||||
reg = <0x40090080 0x40>;
|
||||
ngpios = <16>;
|
||||
interrupts = <32 0 33 0 34 0 35 0
|
||||
36 0 37 0 38 0 39 0
|
||||
40 0 41 0 42 0 43 0
|
||||
44 0 45 0 46 0 47 0>;
|
||||
};
|
||||
|
||||
/* GPIO48-GPIO63 */
|
||||
gpiod: gpio@400900c0 {
|
||||
compatible = "realtek,rts5912-gpio";
|
||||
gpio-controller;
|
||||
#gpio-cells = <2>;
|
||||
reg = <0x400900c0 0x40>;
|
||||
ngpios = <16>;
|
||||
interrupts = <48 0 49 0 50 0 51 0
|
||||
52 0 53 0 54 0 55 0
|
||||
56 0 57 0 58 0 59 0
|
||||
60 0 61 0 62 0 63 0>;
|
||||
};
|
||||
|
||||
/* GPIO64-GPIO79 */
|
||||
gpioe: gpio@40090100 {
|
||||
compatible = "realtek,rts5912-gpio";
|
||||
gpio-controller;
|
||||
#gpio-cells = <2>;
|
||||
reg = <0x40090100 0x40>;
|
||||
ngpios = <16>;
|
||||
interrupts = <64 0 65 0 66 0 67 0
|
||||
68 0 69 0 70 0 71 0
|
||||
72 0 73 0 74 0 75 0
|
||||
76 0 77 0 78 0 79 0>;
|
||||
};
|
||||
|
||||
/* GPIO80-GPIO95 */
|
||||
gpiof: gpio@40090140 {
|
||||
compatible = "realtek,rts5912-gpio";
|
||||
gpio-controller;
|
||||
#gpio-cells = <2>;
|
||||
reg = <0x40090140 0x40>;
|
||||
ngpios = <16>;
|
||||
interrupts = <80 0 81 0 82 0 83 0
|
||||
84 0 85 0 86 0 87 0
|
||||
88 0 89 0 90 0 91 0
|
||||
92 0 93 0 94 0 95 0>;
|
||||
};
|
||||
|
||||
/* GPIO96-GPIO111 */
|
||||
gpiog: gpio@40090180 {
|
||||
compatible = "realtek,rts5912-gpio";
|
||||
gpio-controller;
|
||||
#gpio-cells = <2>;
|
||||
reg = <0x40090180 0x40>;
|
||||
ngpios = <16>;
|
||||
interrupts = <96 0 97 0 98 0 99 0
|
||||
100 0 101 0 102 0 103 0
|
||||
104 0 105 0 106 0 107 0
|
||||
108 0 109 0 110 0 111 0>;
|
||||
};
|
||||
|
||||
/* GPIO112-GPIO127 */
|
||||
gpioh: gpio@400901c0 {
|
||||
compatible = "realtek,rts5912-gpio";
|
||||
gpio-controller;
|
||||
#gpio-cells = <2>;
|
||||
reg = <0x400901c0 0x40>;
|
||||
ngpios = <16>;
|
||||
interrupts = <112 0 113 0 114 0 115 0
|
||||
116 0 117 0 118 0 119 0
|
||||
120 0 121 0 122 0 123 0
|
||||
124 0 125 0 126 0 127 0>;
|
||||
};
|
||||
|
||||
/* GPIO128-GPIO131 */
|
||||
gpioi: gpio@40090200 {
|
||||
compatible = "realtek,rts5912-gpio";
|
||||
gpio-controller;
|
||||
#gpio-cells = <2>;
|
||||
reg = <0x40090200 0x10>;
|
||||
ngpios = <4>;
|
||||
interrupts = <128 0 129 0 130 0 131 0
|
||||
132 0 133 0 134 0 135 0
|
||||
136 0 137 0 138 0 139 0
|
||||
140 0 141 0 142 0 143 0>;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
|
|
18
dts/bindings/gpio/realtek,rts5912-gpio.yaml
Normal file
18
dts/bindings/gpio/realtek,rts5912-gpio.yaml
Normal file
|
@ -0,0 +1,18 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# Copyright (c) 2024 Realtek Semiconductor Corporation, SIBG-SD7
|
||||
#
|
||||
|
||||
description: Realtek RTS5912 GPIO
|
||||
|
||||
compatible: "realtek,rts5912-gpio"
|
||||
|
||||
include: [gpio-controller.yaml, base.yaml]
|
||||
|
||||
properties:
|
||||
reg:
|
||||
required: true
|
||||
|
||||
gpio-cells:
|
||||
- pin
|
||||
- flags
|
23
include/zephyr/dt-bindings/gpio/realtek-gpio.h
Normal file
23
include/zephyr/dt-bindings/gpio/realtek-gpio.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Copyright (c) 2024 Realtek Semiconductor Corporation, SIBG-SD7
|
||||
* Author: Lin Yu-Cheng <lin_yu_cheng@realtek.com>
|
||||
*/
|
||||
|
||||
#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_GPIO_REALTEK_GPIO_H_
|
||||
#define ZEPHYR_INCLUDE_DT_BINDINGS_GPIO_REALTEK_GPIO_H_
|
||||
|
||||
#define RTS5912_GPIO_VOLTAGE_POS 11
|
||||
#define RTS5912_GPIO_VOLTAGE_MASK (3U << RTS5912_GPIO_VOLTAGE_POS)
|
||||
|
||||
/** Set pin at the default voltage level */
|
||||
#define RTS5912_GPIO_VOLTAGE_DEFAULT (0U << RTS5912_GPIO_VOLTAGE_POS)
|
||||
/** Set pin voltage level at 1.8 V */
|
||||
#define RTS5912_GPIO_VOLTAGE_1V8 (1U << RTS5912_GPIO_VOLTAGE_POS)
|
||||
/** Set pin voltage level at 3.3 V */
|
||||
#define RTS5912_GPIO_VOLTAGE_3V3 (2U << RTS5912_GPIO_VOLTAGE_POS)
|
||||
/** Set pin voltage level at 5.0 V */
|
||||
#define RTS5912_GPIO_VOLTAGE_5V0 (3U << RTS5912_GPIO_VOLTAGE_POS)
|
||||
|
||||
#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_GPIO_REALTEK_GPIO_H_ */
|
50
soc/realtek/ec/rts5912/reg/reg_gpio.h
Normal file
50
soc/realtek/ec/rts5912/reg/reg_gpio.h
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright (c) 2023 Realtek, SIBG-SD7
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef ZEPHYR_SOC_REALTEK_RTS5912_REG_GPIO_H
|
||||
#define ZEPHYR_SOC_REALTEK_RTS5912_REG_GPIO_H
|
||||
|
||||
/*
|
||||
* @brief GPIO Controller (GPIO)
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
volatile uint32_t GCR[132];
|
||||
} GPIO_Type;
|
||||
|
||||
/* GCR */
|
||||
#define GPIO_GCR_DIR_Pos (0UL)
|
||||
#define GPIO_GCR_DIR_Msk BIT(GPIO_GCR_DIR_Pos)
|
||||
#define GPIO_GCR_INDETEN_Pos (1UL)
|
||||
#define GPIO_GCR_INDETEN_Msk BIT(GPIO_GCR_INDETEN_Pos)
|
||||
#define GPIO_GCR_INVOLMD_Pos (2UL)
|
||||
#define GPIO_GCR_INVOLMD_Msk BIT(GPIO_GCR_INVOLMD_Pos)
|
||||
#define GPIO_GCR_PINSTS_Pos (3UL)
|
||||
#define GPIO_GCR_PINSTS_Msk BIT(GPIO_GCR_PINSTS_Pos)
|
||||
#define GPIO_GCR_MFCTRL_Pos (8UL)
|
||||
#define GPIO_GCR_MFCTRL_Msk GENMASK(10, 8)
|
||||
#define GPIO_GCR_OUTDRV_Pos (11UL)
|
||||
#define GPIO_GCR_OUTDRV_Msk BIT(GPIO_GCR_OUTDRV_Pos)
|
||||
#define GPIO_GCR_SLEWRATE_Pos (12UL)
|
||||
#define GPIO_GCR_SLEWRATE_Msk BIT(GPIO_GCR_SLEWRATE_Pos)
|
||||
#define GPIO_GCR_PULLDWEN_Pos (13UL)
|
||||
#define GPIO_GCR_PULLDWEN_Msk BIT(GPIO_GCR_PULLDWEN_Pos)
|
||||
#define GPIO_GCR_PULLUPEN_Pos (14UL)
|
||||
#define GPIO_GCR_PULLUPEN_Msk BIT(GPIO_GCR_PULLUPEN_Pos)
|
||||
#define GPIO_GCR_SCHEN_Pos (15UL)
|
||||
#define GPIO_GCR_SCHEN_Msk BIT(GPIO_GCR_SCHEN_Pos)
|
||||
#define GPIO_GCR_OUTMD_Pos (16UL)
|
||||
#define GPIO_GCR_OUTMD_Msk BIT(GPIO_GCR_OUTMD_Pos)
|
||||
#define GPIO_GCR_OUTCTRL_Pos (17UL)
|
||||
#define GPIO_GCR_OUTCTRL_Msk BIT(GPIO_GCR_OUTCTRL_Pos)
|
||||
#define GPIO_GCR_INTCTRL_Pos (24UL)
|
||||
#define GPIO_GCR_INTCTRL_Msk GENMASK(26, 24)
|
||||
#define GPIO_GCR_INTEN_Pos (28UL)
|
||||
#define GPIO_GCR_INTEN_Msk BIT(GPIO_GCR_INTEN_Pos)
|
||||
#define GPIO_GCR_INTSTS_Pos (31UL)
|
||||
#define GPIO_GCR_INTSTS_Msk BIT(GPIO_GCR_INTSTS_Pos)
|
||||
|
||||
#endif /* ZEPHYR_SOC_REALTEK_RTS5912_REG_GPIO_H */
|
Loading…
Add table
Add a link
Reference in a new issue