Skip to content

Commit 53ec07e

Browse files
committed
driver: gpio: Add initial gpio drirver support for RA8M1
This is the initial commit to support for gpio driver for RA8M1 MCU, the coding is base on renesas fsp hal Signed-off-by: Duy Nguyen <[email protected]>
1 parent 546cfe4 commit 53ec07e

File tree

6 files changed

+399
-0
lines changed

6 files changed

+399
-0
lines changed

drivers/gpio/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ zephyr_library_sources_ifdef(CONFIG_GPIO_ALTERA_PIO gpio_altera_pio.c)
9090
zephyr_library_sources_ifdef(CONFIG_GPIO_BCM2711 gpio_bcm2711.c)
9191
zephyr_library_sources_ifdef(CONFIG_GPIO_RENESAS_RA gpio_renesas_ra.c)
9292
zephyr_library_sources_ifdef(CONFIG_GPIO_ENE_KB1200 gpio_ene_kb1200.c)
93+
zephyr_library_sources_ifdef(CONFIG_GPIO_RA8 gpio_renesas_ra8.c)
9394
zephyr_library_sources_ifdef(CONFIG_GPIO_RZT2M gpio_rzt2m.c)
9495
zephyr_library_sources_ifdef(CONFIG_GPIO_AMBIQ gpio_ambiq.c)
9596
zephyr_library_sources_ifdef(CONFIG_GPIO_BRCMSTB gpio_brcmstb.c)

drivers/gpio/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@ source "drivers/gpio/Kconfig.renesas_ra"
238238

239239
source "drivers/gpio/Kconfig.ene"
240240

241+
source "drivers/gpio/Kconfig.renesas_ra8"
242+
241243
source "drivers/gpio/Kconfig.rzt2m"
242244

243245
source "drivers/gpio/Kconfig.ambiq"

drivers/gpio/Kconfig.renesas_ra8

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

drivers/gpio/gpio_renesas_ra8.c

Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
/*
2+
* Copyright (c) 2024 Renesas Electronics Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#define DT_DRV_COMPAT renesas_ra8_gpio
8+
9+
#include <zephyr/drivers/gpio.h>
10+
#include <zephyr/drivers/pinctrl.h>
11+
#include <zephyr/drivers/gpio/gpio_utils.h>
12+
#include <zephyr/irq.h>
13+
#include <soc.h>
14+
15+
#define PRCR_KEY 0xA500U
16+
#define VBATT_PORT 4
17+
18+
static const gpio_pin_t vbatt_pins[] = {
19+
2U,
20+
3U,
21+
4U,
22+
};
23+
24+
#define RA8_INVALID_PORT_ADDR 0UL
25+
26+
#define RA8_GPIO_PORT_ADDR(nodelabel) \
27+
COND_CODE_1(DT_NODE_EXISTS(DT_NODELABEL(nodelabel)), \
28+
(DT_REG_ADDR(DT_NODELABEL(nodelabel))), (RA8_INVALID_PORT_ADDR))
29+
30+
struct gpio_ra8_config {
31+
struct gpio_driver_config common;
32+
uint8_t port_num;
33+
R_PORT0_Type *port;
34+
};
35+
36+
struct gpio_ra8_data {
37+
struct gpio_driver_data common;
38+
};
39+
40+
static int gpio_ra8_pin_configure(const struct device *dev, gpio_pin_t pin, gpio_flags_t flags)
41+
{
42+
const struct gpio_ra8_config *config = dev->config;
43+
44+
if (((flags & GPIO_INPUT) != 0U) && ((flags & GPIO_OUTPUT) != 0U)) {
45+
return -ENOTSUP;
46+
}
47+
48+
if ((flags & GPIO_PULL_DOWN) != 0U) {
49+
return -ENOTSUP;
50+
}
51+
52+
if (config->port_num == VBATT_PORT) {
53+
uint32_t clear = 0;
54+
55+
for (int i = 0; i < ARRAY_SIZE(vbatt_pins); i++) {
56+
if (vbatt_pins[i] == pin) {
57+
WRITE_BIT(clear, i, 1);
58+
}
59+
}
60+
61+
R_SYSTEM->PRCR = ((R_SYSTEM->PRCR | PRCR_KEY) | R_SYSTEM_PRCR_PRC1_Msk);
62+
63+
R_SYSTEM->VBTICTLR &= (uint8_t)~clear;
64+
65+
R_SYSTEM->PRCR = ((R_SYSTEM->PRCR | PRCR_KEY) & (uint16_t)~R_SYSTEM_PRCR_PRC1_Msk);
66+
}
67+
68+
#if BSP_CFG_MCU_PART_SERIES == 8
69+
R_PMISC->PWPRS = 0;
70+
R_PMISC->PWPRS = BIT(R_PMISC_PWPR_PFSWE_Pos);
71+
#else
72+
R_PMISC->PWPR = 0;
73+
R_PMISC->PWPR = BIT(R_PMISC_PWPR_PFSWE_Pos);
74+
#endif
75+
76+
uint32_t value = R_PFS->PORT[config->port_num].PIN[pin].PmnPFS;
77+
78+
/* Change mode to general IO mode and disable IRQ and Analog input */
79+
WRITE_BIT(value, R_PFS_PORT_PIN_PmnPFS_PMR_Pos, 0);
80+
WRITE_BIT(value, R_PFS_PORT_PIN_PmnPFS_ASEL_Pos, 0);
81+
WRITE_BIT(value, R_PFS_PORT_PIN_PmnPFS_ISEL_Pos, 0);
82+
83+
if ((flags & GPIO_OUTPUT) != 0U) {
84+
/* Set output pin initial value */
85+
if ((flags & GPIO_OUTPUT_INIT_LOW) != 0U) {
86+
WRITE_BIT(value, R_PFS_PORT_PIN_PmnPFS_PODR_Pos, 0);
87+
} else if ((flags & GPIO_OUTPUT_INIT_HIGH) != 0U) {
88+
WRITE_BIT(value, R_PFS_PORT_PIN_PmnPFS_PODR_Pos, 1);
89+
}
90+
91+
WRITE_BIT(value, R_PFS_PORT_PIN_PmnPFS_PDR_Pos, 1);
92+
} else {
93+
WRITE_BIT(value, R_PFS_PORT_PIN_PmnPFS_PDR_Pos, 0);
94+
}
95+
96+
R_PFS->PORT[config->port_num].PIN[pin].PmnPFS = value;
97+
98+
#if BSP_CFG_MCU_PART_SERIES == 8
99+
R_PMISC->PWPRS = 0;
100+
R_PMISC->PWPRS = BIT(R_PMISC_PWPR_B0WI_Pos);
101+
#else
102+
R_PMISC->PWPR = 0;
103+
R_PMISC->PWPR = BIT(R_PMISC_PWPR_B0WI_Pos);
104+
#endif
105+
106+
return 0;
107+
}
108+
109+
static int gpio_ra8_port_get_raw(const struct device *dev, uint32_t *value)
110+
{
111+
const struct gpio_ra8_config *config = dev->config;
112+
R_PORT0_Type *port = config->port;
113+
114+
*value = port->PIDR;
115+
116+
return 0;
117+
}
118+
119+
static int gpio_ra8_port_set_masked_raw(const struct device *dev, gpio_port_pins_t mask,
120+
gpio_port_value_t value)
121+
{
122+
const struct gpio_ra8_config *config = dev->config;
123+
R_PORT0_Type *port = config->port;
124+
125+
port->PODR = ((port->PODR & ~mask) | (value & mask));
126+
127+
return 0;
128+
}
129+
130+
static int gpio_ra8_port_set_bits_raw(const struct device *dev, gpio_port_pins_t pins)
131+
{
132+
const struct gpio_ra8_config *config = dev->config;
133+
R_PORT0_Type *port = config->port;
134+
135+
port->PODR = (port->PODR | pins);
136+
137+
return 0;
138+
}
139+
140+
static int gpio_ra8_port_clear_bits_raw(const struct device *dev, gpio_port_pins_t pins)
141+
{
142+
const struct gpio_ra8_config *config = dev->config;
143+
R_PORT0_Type *port = config->port;
144+
145+
port->PODR = (port->PODR & ~pins);
146+
147+
return 0;
148+
}
149+
150+
static int gpio_ra8_port_toggle_bits(const struct device *dev, gpio_port_pins_t pins)
151+
{
152+
const struct gpio_ra8_config *config = dev->config;
153+
R_PORT0_Type *port = config->port;
154+
155+
port->PODR = (port->PODR ^ pins);
156+
157+
return 0;
158+
}
159+
160+
static const struct gpio_driver_api gpio_ra8_drv_api_funcs = {
161+
.pin_configure = gpio_ra8_pin_configure,
162+
.port_get_raw = gpio_ra8_port_get_raw,
163+
.port_set_masked_raw = gpio_ra8_port_set_masked_raw,
164+
.port_set_bits_raw = gpio_ra8_port_set_bits_raw,
165+
.port_clear_bits_raw = gpio_ra8_port_clear_bits_raw,
166+
.port_toggle_bits = gpio_ra8_port_toggle_bits,
167+
.pin_interrupt_configure = NULL,
168+
.manage_callback = NULL,
169+
#ifdef CONFIG_GPIO_GET_DIRECTION
170+
.port_get_direction = gpio_ra8_port_get_direction,
171+
#endif
172+
};
173+
174+
static int gpio_ra8_init(const struct device *dev)
175+
{
176+
return 0;
177+
}
178+
179+
#define GPIO_DEVICE_INIT(__node, __port_num, __suffix, __addr) \
180+
static const struct gpio_ra8_config gpio_ra8_config_##__suffix = { \
181+
.common = \
182+
{ \
183+
.port_pin_mask = GPIO_PORT_PIN_MASK_FROM_NGPIOS(16U), \
184+
}, \
185+
.port_num = __port_num, \
186+
.port = (R_PORT0_Type *)__addr, \
187+
}; \
188+
static struct gpio_ra8_data gpio_ra8_data_##__suffix; \
189+
DEVICE_DT_DEFINE(__node, gpio_ra8_init, PM_DEVICE_DT_GET(__node), \
190+
&gpio_ra8_data_##__suffix, &gpio_ra8_config_##__suffix, PRE_KERNEL_1, \
191+
CONFIG_GPIO_INIT_PRIORITY, &gpio_ra8_drv_api_funcs)
192+
193+
#define GPIO_DEVICE_INIT_RA8(__suffix) \
194+
GPIO_DEVICE_INIT(DT_NODELABEL(gpio##__suffix), \
195+
DT_PROP(DT_NODELABEL(gpio##__suffix), port), __suffix, \
196+
DT_REG_ADDR(DT_NODELABEL(gpio##__suffix)))
197+
198+
#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio0), okay)
199+
GPIO_DEVICE_INIT_RA8(0);
200+
#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(gpio0), okay) */
201+
202+
#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio1), okay)
203+
GPIO_DEVICE_INIT_RA8(1);
204+
#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(gpio1), okay) */
205+
206+
#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio2), okay)
207+
GPIO_DEVICE_INIT_RA8(2);
208+
#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(gpio2), okay) */
209+
210+
#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio3), okay)
211+
GPIO_DEVICE_INIT_RA8(3);
212+
#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(gpio3), okay) */
213+
214+
#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio4), okay)
215+
GPIO_DEVICE_INIT_RA8(4);
216+
#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(gpio4), okay) */
217+
218+
#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio5), okay)
219+
GPIO_DEVICE_INIT_RA8(5);
220+
#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(gpio5), okay) */
221+
222+
#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio6), okay)
223+
GPIO_DEVICE_INIT_RA8(6);
224+
#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(gpio6), okay) */
225+
226+
#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio7), okay)
227+
GPIO_DEVICE_INIT_RA8(7);
228+
#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(gpio7), okay) */
229+
230+
#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio8), okay)
231+
GPIO_DEVICE_INIT_RA8(8);
232+
#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(gpio8), okay) */
233+
234+
#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpio9), okay)
235+
GPIO_DEVICE_INIT_RA8(9);
236+
#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(gpio9), okay) */
237+
238+
#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpioa), okay)
239+
GPIO_DEVICE_INIT_RA8(a);
240+
#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(gpioa), okay) */
241+
242+
#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpiob), okay)
243+
GPIO_DEVICE_INIT_RA8(b);
244+
#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(gpiob), okay) */

dts/arm/renesas/ra/ra8/ra8x1.dtsi

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,126 @@
4747
reg = <0x40400800 0x3c0>;
4848
status = "disabled";
4949
};
50+
51+
gpio0: gpio@40400000 {
52+
compatible = "renesas,ra8-gpio";
53+
reg = <0x40400000 0x20>;
54+
port = <0>;
55+
gpio-controller;
56+
#gpio-cells = <2>;
57+
ngpios = <16>;
58+
status = "disabled";
59+
};
60+
61+
gpio1: gpio@40400020 {
62+
compatible = "renesas,ra8-gpio";
63+
reg = <0x40400020 0x20>;
64+
port = <1>;
65+
gpio-controller;
66+
#gpio-cells = <2>;
67+
ngpios = <16>;
68+
status = "disabled";
69+
};
70+
71+
gpio2: gpio@40400040 {
72+
compatible = "renesas,ra8-gpio";
73+
reg = <0x40400040 0x20>;
74+
port = <2>;
75+
gpio-controller;
76+
#gpio-cells = <2>;
77+
ngpios = <16>;
78+
status = "disabled";
79+
};
80+
81+
gpio3: gpio@40400060 {
82+
compatible = "renesas,ra8-gpio";
83+
reg = <0x40400060 0x20>;
84+
port = <3>;
85+
gpio-controller;
86+
#gpio-cells = <2>;
87+
ngpios = <16>;
88+
status = "disabled";
89+
};
90+
91+
gpio4: gpio@40400080 {
92+
compatible = "renesas,ra8-gpio";
93+
reg = <0x40400080 0x20>;
94+
port = <4>;
95+
gpio-controller;
96+
#gpio-cells = <2>;
97+
ngpios = <16>;
98+
status = "disabled";
99+
};
100+
101+
gpio5: gpio@404000a0 {
102+
compatible = "renesas,ra8-gpio";
103+
reg = <0x404000a0 0x20>;
104+
port = <5>;
105+
gpio-controller;
106+
#gpio-cells = <2>;
107+
ngpios = <16>;
108+
status = "disabled";
109+
};
110+
111+
gpio6: gpio@404000c0 {
112+
compatible = "renesas,ra8-gpio";
113+
reg = <0x404000c0 0x20>;
114+
port = <6>;
115+
gpio-controller;
116+
#gpio-cells = <2>;
117+
ngpios = <16>;
118+
status = "disabled";
119+
};
120+
121+
gpio7: gpio@404000e0 {
122+
compatible = "renesas,ra8-gpio";
123+
reg = <0x404000e0 0x20>;
124+
port = <7>;
125+
gpio-controller;
126+
#gpio-cells = <2>;
127+
ngpios = <16>;
128+
status = "disabled";
129+
};
130+
131+
gpio8: gpio@40400100 {
132+
compatible = "renesas,ra8-gpio";
133+
reg = <0x40400100 0x20>;
134+
port = <8>;
135+
gpio-controller;
136+
#gpio-cells = <2>;
137+
ngpios = <16>;
138+
status = "disabled";
139+
};
140+
141+
gpio9: gpio@40400120 {
142+
compatible = "renesas,ra8-gpio";
143+
reg = <0x40400120 0x20>;
144+
port = <9>;
145+
gpio-controller;
146+
#gpio-cells = <2>;
147+
ngpios = <16>;
148+
status = "disabled";
149+
};
150+
151+
gpioa: gpio@40400140 {
152+
compatible = "renesas,ra8-gpio";
153+
reg = <0x40400140 0x20>;
154+
port = <10>;
155+
gpio-controller;
156+
#gpio-cells = <2>;
157+
ngpios = <16>;
158+
status = "disabled";
159+
};
160+
161+
gpiob: gpio@40400160 {
162+
compatible = "renesas,ra8-gpio";
163+
reg = <0x40400160 0x20>;
164+
port = <11>;
165+
gpio-controller;
166+
#gpio-cells = <2>;
167+
ngpios = <16>;
168+
status = "disabled";
169+
};
50170
};
51171

52172
&nvic {

0 commit comments

Comments
 (0)