Skip to content

Commit 15d2990

Browse files
dnltzjhedberg
authored andcommitted
drivers: gpio: Add driver for Aesc Silicon
Add basic support for the Aesc Silicon GPIO controller. This IP core has internal tri-states and therefore a read, write and direction registers. Additionally, it has advanced monitoring capabilities for interrupt generation; low or high leve and rising or falling edge. Interrupt support will be added later when ElemRV supports interrupt in Zephyr. Signed-off-by: Daniel Schultz <[email protected]>
1 parent 8cd010b commit 15d2990

File tree

5 files changed

+226
-0
lines changed

5 files changed

+226
-0
lines changed

drivers/gpio/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ zephyr_library()
88
zephyr_library_sources_ifdef(CONFIG_GPIO_AD559X gpio_ad559x.c)
99
zephyr_library_sources_ifdef(CONFIG_GPIO_ADP5585 gpio_adp5585.c)
1010
zephyr_library_sources_ifdef(CONFIG_GPIO_ADS1X4S0X gpio_ads1x4s0x.c)
11+
zephyr_library_sources_ifdef(CONFIG_GPIO_AESC gpio_aesc.c)
1112
zephyr_library_sources_ifdef(CONFIG_GPIO_ALTERA_PIO gpio_altera_pio.c)
1213
zephyr_library_sources_ifdef(CONFIG_GPIO_AMBIQ gpio_ambiq.c)
1314
zephyr_library_sources_ifdef(CONFIG_GPIO_ANDES_ATCGPIO100 gpio_andes_atcgpio100.c)

drivers/gpio/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ config GPIO_ENABLE_DISABLE_INTERRUPT
9797
source "drivers/gpio/Kconfig.ad559x"
9898
source "drivers/gpio/Kconfig.adp5585"
9999
source "drivers/gpio/Kconfig.ads1x4s0x"
100+
source "drivers/gpio/Kconfig.aesc"
100101
source "drivers/gpio/Kconfig.altera"
101102
source "drivers/gpio/Kconfig.ambiq"
102103
source "drivers/gpio/Kconfig.andes_atcgpio100"

drivers/gpio/Kconfig.aesc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) 2025 Aesc Silicon
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config GPIO_AESC
5+
bool "Aesc Silicon GPIO driver"
6+
default y
7+
depends on DT_HAS_AESC_GPIO_ENABLED
8+
help
9+
Enable the Aesc Silicon GPIO driver.

drivers/gpio/gpio_aesc.c

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
/*
2+
* Copyright (c) 2025 Aesc Silicon
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#define DT_DRV_COMPAT aesc_gpio
8+
9+
#include <errno.h>
10+
#include <ip_identification.h>
11+
#include <soc.h>
12+
13+
#include <zephyr/arch/common/sys_bitops.h>
14+
#include <zephyr/device.h>
15+
#include <zephyr/devicetree.h>
16+
#include <zephyr/drivers/gpio.h>
17+
#include <zephyr/drivers/gpio/gpio_utils.h>
18+
#include <zephyr/init.h>
19+
#include <zephyr/kernel.h>
20+
#include <zephyr/sys/sys_io.h>
21+
#include <zephyr/spinlock.h>
22+
23+
24+
#include <zephyr/logging/log.h>
25+
LOG_MODULE_REGISTER(aesc_gpio, CONFIG_GPIO_LOG_LEVEL);
26+
27+
struct gpio_aesc_config {
28+
DEVICE_MMIO_ROM;
29+
};
30+
31+
struct gpio_aesc_regs {
32+
uint32_t info;
33+
uint32_t read;
34+
uint32_t write;
35+
uint32_t direction;
36+
uint32_t high_ip;
37+
uint32_t high_ie;
38+
uint32_t low_ip;
39+
uint32_t low_ie;
40+
uint32_t rise_ip;
41+
uint32_t rise_ie;
42+
uint32_t fall_ip;
43+
uint32_t fall_ie;
44+
} __packed;
45+
46+
struct gpio_aesc_data {
47+
DEVICE_MMIO_RAM;
48+
sys_slist_t cb;
49+
struct k_spinlock lock;
50+
};
51+
52+
#define DEV_CFG(dev) ((struct gpio_aesc_config *)(dev)->config)
53+
#define DEV_DATA(dev) ((struct gpio_aesc_data *)(dev)->data)
54+
#define DEV_GPIO(dev) ((struct gpio_aesc_regs *)DEVICE_MMIO_GET(dev))
55+
56+
static int gpio_aesc_config(const struct device *dev, gpio_pin_t pin,
57+
gpio_flags_t flags)
58+
{
59+
volatile struct gpio_aesc_regs *gpio = DEV_GPIO(dev);
60+
struct gpio_aesc_data *data = DEV_DATA(dev);
61+
k_spinlock_key_t key;
62+
63+
key = k_spin_lock(&data->lock);
64+
/* Configure gpio direction */
65+
if (flags & GPIO_OUTPUT) {
66+
gpio->direction |= BIT(pin);
67+
} else {
68+
gpio->direction &= ~BIT(pin);
69+
}
70+
k_spin_unlock(&data->lock, key);
71+
72+
return 0;
73+
}
74+
75+
static int gpio_aesc_port_get_raw(const struct device *dev,
76+
gpio_port_value_t *value)
77+
{
78+
volatile struct gpio_aesc_regs *gpio = DEV_GPIO(dev);
79+
80+
*value = gpio->read;
81+
82+
return 0;
83+
}
84+
85+
static int gpio_aesc_port_set_masked_raw(const struct device *dev,
86+
gpio_port_pins_t mask,
87+
gpio_port_value_t value)
88+
{
89+
volatile struct gpio_aesc_regs *gpio = DEV_GPIO(dev);
90+
struct gpio_aesc_data *data = DEV_DATA(dev);
91+
k_spinlock_key_t key;
92+
93+
key = k_spin_lock(&data->lock);
94+
gpio->write = (gpio->write & ~mask) | (value & mask);
95+
k_spin_unlock(&data->lock, key);
96+
97+
return 0;
98+
}
99+
100+
static int gpio_aesc_port_set_bits_raw(const struct device *dev,
101+
gpio_port_pins_t mask)
102+
{
103+
volatile struct gpio_aesc_regs *gpio = DEV_GPIO(dev);
104+
struct gpio_aesc_data *data = DEV_DATA(dev);
105+
k_spinlock_key_t key;
106+
107+
key = k_spin_lock(&data->lock);
108+
gpio->write |= mask;
109+
k_spin_unlock(&data->lock, key);
110+
111+
return 0;
112+
}
113+
114+
static int gpio_aesc_port_clear_bits_raw(const struct device *dev,
115+
gpio_port_pins_t mask)
116+
{
117+
volatile struct gpio_aesc_regs *gpio = DEV_GPIO(dev);
118+
struct gpio_aesc_data *data = DEV_DATA(dev);
119+
k_spinlock_key_t key;
120+
121+
key = k_spin_lock(&data->lock);
122+
gpio->write &= ~mask;
123+
k_spin_unlock(&data->lock, key);
124+
125+
return 0;
126+
}
127+
128+
static int gpio_aesc_port_toggle_bits(const struct device *dev,
129+
gpio_port_pins_t mask)
130+
{
131+
volatile struct gpio_aesc_regs *gpio = DEV_GPIO(dev);
132+
struct gpio_aesc_data *data = DEV_DATA(dev);
133+
k_spinlock_key_t key;
134+
135+
key = k_spin_lock(&data->lock);
136+
gpio->write ^= mask;
137+
k_spin_unlock(&data->lock, key);
138+
139+
return 0;
140+
}
141+
142+
static int gpio_aesc_init(const struct device *dev)
143+
{
144+
volatile uintptr_t *base_addr = (volatile uintptr_t *)DEV_GPIO(dev);
145+
volatile struct gpio_aesc_regs *gpio;
146+
147+
DEVICE_MMIO_MAP(dev, K_MEM_CACHE_NONE);
148+
LOG_DBG("IP core version: %i.%i.%i.",
149+
ip_id_get_major_version(base_addr),
150+
ip_id_get_minor_version(base_addr),
151+
ip_id_get_patchlevel(base_addr)
152+
);
153+
DEVICE_MMIO_GET(dev) = ip_id_relocate_driver(base_addr);
154+
LOG_DBG("Relocate driver to address 0x%lx.", DEVICE_MMIO_GET(dev));
155+
gpio = DEV_GPIO(dev);
156+
157+
gpio->high_ie = 0;
158+
gpio->low_ie = 0;
159+
gpio->rise_ie = 0;
160+
gpio->fall_ie = 0;
161+
162+
return 0;
163+
}
164+
165+
static DEVICE_API(gpio, gpio_aesc_driver_api) = {
166+
.pin_configure = gpio_aesc_config,
167+
.port_get_raw = gpio_aesc_port_get_raw,
168+
.port_set_masked_raw = gpio_aesc_port_set_masked_raw,
169+
.port_set_bits_raw = gpio_aesc_port_set_bits_raw,
170+
.port_clear_bits_raw = gpio_aesc_port_clear_bits_raw,
171+
.port_toggle_bits = gpio_aesc_port_toggle_bits,
172+
};
173+
174+
#define AESC_GPIO_INIT(no) \
175+
static struct gpio_aesc_data gpio_aesc_dev_data_##no; \
176+
static struct gpio_aesc_config gpio_aesc_dev_cfg_##no = { \
177+
DEVICE_MMIO_ROM_INIT(DT_DRV_INST(no)), \
178+
}; \
179+
DEVICE_DT_INST_DEFINE(no, \
180+
gpio_aesc_init, \
181+
NULL, \
182+
&gpio_aesc_dev_data_##no, \
183+
&gpio_aesc_dev_cfg_##no, \
184+
PRE_KERNEL_2, \
185+
CONFIG_GPIO_INIT_PRIORITY, \
186+
(void *)&gpio_aesc_driver_api);
187+
188+
DT_INST_FOREACH_STATUS_OKAY(AESC_GPIO_INIT)

dts/bindings/gpio/aesc,gpio.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#
2+
# Copyright (c) 2025 Aesc Silicon
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
7+
title: Aesc Silicon GPIO (General Purpose Input/Output)
8+
9+
description: |
10+
The GPIO (General-Purpose Input/Output) IP Core with tri-state pins is a digital interface
11+
that allows each pin to be configured as either an input or an output, with additional control
12+
for setting the direction of data flow.
13+
14+
compatible: "aesc,gpio"
15+
16+
include: [gpio-controller.yaml, base.yaml]
17+
18+
properties:
19+
reg:
20+
required: true
21+
22+
"#gpio-cells":
23+
const: 2
24+
25+
gpio-cells:
26+
- pin
27+
- flags

0 commit comments

Comments
 (0)