Skip to content

Commit f978c69

Browse files
duynguyenxanashif
authored andcommitted
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 75f1f7e commit f978c69

File tree

7 files changed

+401
-0
lines changed

7 files changed

+401
-0
lines changed

drivers/gpio/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ zephyr_library_sources_ifdef(CONFIG_GPIO_PCA95XX gpio_pca95xx.c)
6666
zephyr_library_sources_ifdef(CONFIG_GPIO_PCAL64XXA gpio_pcal64xxa.c)
6767
zephyr_library_sources_ifdef(CONFIG_GPIO_PCF857X gpio_pcf857x.c)
6868
zephyr_library_sources_ifdef(CONFIG_GPIO_PSOC6 gpio_psoc6.c)
69+
zephyr_library_sources_ifdef(CONFIG_GPIO_RA8 gpio_renesas_ra8.c)
6970
zephyr_library_sources_ifdef(CONFIG_GPIO_RCAR gpio_rcar.c)
7071
zephyr_library_sources_ifdef(CONFIG_GPIO_RENESAS_RA gpio_renesas_ra.c)
7172
zephyr_library_sources_ifdef(CONFIG_GPIO_RPI_PICO gpio_rpi_pico.c)

drivers/gpio/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ source "drivers/gpio/Kconfig.pcf857x"
155155
source "drivers/gpio/Kconfig.psoc6"
156156
source "drivers/gpio/Kconfig.rcar"
157157
source "drivers/gpio/Kconfig.renesas_ra"
158+
source "drivers/gpio/Kconfig.renesas_ra8"
158159
source "drivers/gpio/Kconfig.rpi_pico"
159160
source "drivers/gpio/Kconfig.rt1718s"
160161
source "drivers/gpio/Kconfig.rv32m1"

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: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
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/dt-bindings/gpio/renesas-ra8-gpio.h>
12+
#include <zephyr/drivers/gpio/gpio_utils.h>
13+
#include <zephyr/irq.h>
14+
#include <soc.h>
15+
16+
struct gpio_ra8_config {
17+
struct gpio_driver_config common;
18+
uint8_t port_num;
19+
R_PORT0_Type *port;
20+
gpio_pin_t vbatt_pins[];
21+
};
22+
23+
struct gpio_ra8_data {
24+
struct gpio_driver_data common;
25+
};
26+
27+
static int gpio_ra8_pin_configure(const struct device *dev, gpio_pin_t pin, gpio_flags_t flags)
28+
{
29+
const struct gpio_ra8_config *config = dev->config;
30+
31+
struct ra_pinctrl_soc_pin pincfg = {0};
32+
33+
if (((flags & GPIO_INPUT) != 0U) && ((flags & GPIO_OUTPUT) != 0U)) {
34+
return -ENOTSUP;
35+
}
36+
37+
if ((flags & GPIO_PULL_DOWN) != 0U) {
38+
return -ENOTSUP;
39+
}
40+
41+
if ((flags & GPIO_INT_ENABLE) != 0) {
42+
return -ENOTSUP;
43+
}
44+
45+
if (config->vbatt_pins[0] != 0xFF) {
46+
uint32_t clear = 0;
47+
48+
for (int i = 0; config->vbatt_pins[i] != '\0'; i++) {
49+
if (config->vbatt_pins[i] == pin) {
50+
WRITE_BIT(clear, i, 1);
51+
}
52+
}
53+
54+
R_BSP_RegisterProtectDisable(BSP_REG_PROTECT_OM_LPC_BATT);
55+
56+
R_SYSTEM->VBTICTLR &= (uint8_t)~clear;
57+
58+
R_BSP_RegisterProtectEnable(BSP_REG_PROTECT_OM_LPC_BATT);
59+
}
60+
61+
pincfg.port_num = config->port_num;
62+
pincfg.pin_num = pin;
63+
64+
/* Change mode to general IO mode and disable IRQ and Analog input */
65+
WRITE_BIT(pincfg.cfg, R_PFS_PORT_PIN_PmnPFS_PMR_Pos, 0);
66+
WRITE_BIT(pincfg.cfg, R_PFS_PORT_PIN_PmnPFS_ASEL_Pos, 0);
67+
WRITE_BIT(pincfg.cfg, R_PFS_PORT_PIN_PmnPFS_ISEL_Pos, 0);
68+
69+
if ((flags & GPIO_OUTPUT) != 0U) {
70+
/* Set output pin initial value */
71+
if ((flags & GPIO_OUTPUT_INIT_LOW) != 0U) {
72+
WRITE_BIT(pincfg.cfg, R_PFS_PORT_PIN_PmnPFS_PODR_Pos, 0);
73+
} else if ((flags & GPIO_OUTPUT_INIT_HIGH) != 0U) {
74+
WRITE_BIT(pincfg.cfg, R_PFS_PORT_PIN_PmnPFS_PODR_Pos, 1);
75+
}
76+
77+
WRITE_BIT(pincfg.cfg, R_PFS_PORT_PIN_PmnPFS_PDR_Pos, 1);
78+
} else {
79+
WRITE_BIT(pincfg.cfg, R_PFS_PORT_PIN_PmnPFS_PDR_Pos, 0);
80+
}
81+
82+
if ((flags & GPIO_LINE_OPEN_DRAIN) != 0) {
83+
WRITE_BIT(pincfg.cfg, R_PFS_PORT_PIN_PmnPFS_NCODR_Pos, 1);
84+
}
85+
86+
if ((flags & GPIO_PULL_UP) != 0) {
87+
WRITE_BIT(pincfg.cfg, R_PFS_PORT_PIN_PmnPFS_PCR_Pos, 1);
88+
}
89+
90+
pincfg.cfg = pincfg.cfg |
91+
(((flags & RENESAS_GPIO_DS_MSK) >> 8) << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
92+
93+
return pinctrl_configure_pins(&pincfg, 1, PINCTRL_REG_NONE);
94+
}
95+
96+
static int gpio_ra8_port_get_raw(const struct device *dev, uint32_t *value)
97+
{
98+
const struct gpio_ra8_config *config = dev->config;
99+
R_PORT0_Type *port = config->port;
100+
101+
*value = port->PIDR;
102+
103+
return 0;
104+
}
105+
106+
static int gpio_ra8_port_set_masked_raw(const struct device *dev, gpio_port_pins_t mask,
107+
gpio_port_value_t value)
108+
{
109+
const struct gpio_ra8_config *config = dev->config;
110+
R_PORT0_Type *port = config->port;
111+
112+
port->PODR = ((port->PODR & ~mask) | (value & mask));
113+
114+
return 0;
115+
}
116+
117+
static int gpio_ra8_port_set_bits_raw(const struct device *dev, gpio_port_pins_t pins)
118+
{
119+
const struct gpio_ra8_config *config = dev->config;
120+
R_PORT0_Type *port = config->port;
121+
122+
port->PODR = (port->PODR | pins);
123+
124+
return 0;
125+
}
126+
127+
static int gpio_ra8_port_clear_bits_raw(const struct device *dev, gpio_port_pins_t pins)
128+
{
129+
const struct gpio_ra8_config *config = dev->config;
130+
R_PORT0_Type *port = config->port;
131+
132+
port->PODR = (port->PODR & ~pins);
133+
134+
return 0;
135+
}
136+
137+
static int gpio_ra8_port_toggle_bits(const struct device *dev, gpio_port_pins_t pins)
138+
{
139+
const struct gpio_ra8_config *config = dev->config;
140+
R_PORT0_Type *port = config->port;
141+
142+
port->PODR = (port->PODR ^ pins);
143+
144+
return 0;
145+
}
146+
147+
static const struct gpio_driver_api gpio_ra8_drv_api_funcs = {
148+
.pin_configure = gpio_ra8_pin_configure,
149+
.port_get_raw = gpio_ra8_port_get_raw,
150+
.port_set_masked_raw = gpio_ra8_port_set_masked_raw,
151+
.port_set_bits_raw = gpio_ra8_port_set_bits_raw,
152+
.port_clear_bits_raw = gpio_ra8_port_clear_bits_raw,
153+
.port_toggle_bits = gpio_ra8_port_toggle_bits,
154+
.pin_interrupt_configure = NULL,
155+
.manage_callback = NULL,
156+
};
157+
158+
#define GPIO_DEVICE_INIT(node, port_number, suffix, addr) \
159+
static const struct gpio_ra8_config gpio_ra8_config_##suffix = { \
160+
.common = \
161+
{ \
162+
.port_pin_mask = GPIO_PORT_PIN_MASK_FROM_NGPIOS(16U), \
163+
}, \
164+
.port_num = port_number, \
165+
.port = (R_PORT0_Type *)addr, \
166+
.vbatt_pins = DT_PROP_OR(DT_NODELABEL(ioport##suffix), vbatts_pins, {0xFF}), \
167+
}; \
168+
static struct gpio_ra8_data gpio_ra8_data_##suffix; \
169+
DEVICE_DT_DEFINE(node, NULL, NULL, &gpio_ra8_data_##suffix, \
170+
&gpio_ra8_config_##suffix, PRE_KERNEL_1, CONFIG_GPIO_INIT_PRIORITY, \
171+
&gpio_ra8_drv_api_funcs)
172+
173+
#define GPIO_DEVICE_INIT_RA8(suffix) \
174+
GPIO_DEVICE_INIT(DT_NODELABEL(ioport##suffix), \
175+
DT_PROP(DT_NODELABEL(ioport##suffix), port), suffix, \
176+
DT_REG_ADDR(DT_NODELABEL(ioport##suffix)))
177+
178+
#if DT_NODE_HAS_STATUS(DT_NODELABEL(ioport0), okay)
179+
GPIO_DEVICE_INIT_RA8(0);
180+
#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(ioport0), okay) */
181+
182+
#if DT_NODE_HAS_STATUS(DT_NODELABEL(ioport1), okay)
183+
GPIO_DEVICE_INIT_RA8(1);
184+
#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(ioport1), okay) */
185+
186+
#if DT_NODE_HAS_STATUS(DT_NODELABEL(ioport2), okay)
187+
GPIO_DEVICE_INIT_RA8(2);
188+
#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(ioport2), okay) */
189+
190+
#if DT_NODE_HAS_STATUS(DT_NODELABEL(ioport3), okay)
191+
GPIO_DEVICE_INIT_RA8(3);
192+
#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(ioport3), okay) */
193+
194+
#if DT_NODE_HAS_STATUS(DT_NODELABEL(ioport4), okay)
195+
GPIO_DEVICE_INIT_RA8(4);
196+
#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(ioport4), okay) */
197+
198+
#if DT_NODE_HAS_STATUS(DT_NODELABEL(ioport5), okay)
199+
GPIO_DEVICE_INIT_RA8(5);
200+
#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(ioport5), okay) */
201+
202+
#if DT_NODE_HAS_STATUS(DT_NODELABEL(ioport6), okay)
203+
GPIO_DEVICE_INIT_RA8(6);
204+
#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(ioport6), okay) */
205+
206+
#if DT_NODE_HAS_STATUS(DT_NODELABEL(ioport7), okay)
207+
GPIO_DEVICE_INIT_RA8(7);
208+
#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(ioport7), okay) */
209+
210+
#if DT_NODE_HAS_STATUS(DT_NODELABEL(ioport8), okay)
211+
GPIO_DEVICE_INIT_RA8(8);
212+
#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(ioport8), okay) */
213+
214+
#if DT_NODE_HAS_STATUS(DT_NODELABEL(ioport9), okay)
215+
GPIO_DEVICE_INIT_RA8(9);
216+
#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(ioport9), okay) */
217+
218+
#if DT_NODE_HAS_STATUS(DT_NODELABEL(ioporta), okay)
219+
GPIO_DEVICE_INIT_RA8(a);
220+
#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(ioporta), okay) */
221+
222+
#if DT_NODE_HAS_STATUS(DT_NODELABEL(ioportb), okay)
223+
GPIO_DEVICE_INIT_RA8(b);
224+
#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(ioportb), okay) */

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

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,127 @@
6868
reg = <0x40400800 0x3c0>;
6969
status = "okay";
7070
};
71+
72+
ioport0: gpio@40400000 {
73+
compatible = "renesas,ra8-gpio";
74+
reg = <0x40400000 0x20>;
75+
port = <0>;
76+
gpio-controller;
77+
#gpio-cells = <2>;
78+
ngpios = <16>;
79+
status = "disabled";
80+
};
81+
82+
ioport1: gpio@40400020 {
83+
compatible = "renesas,ra8-gpio";
84+
reg = <0x40400020 0x20>;
85+
port = <1>;
86+
gpio-controller;
87+
#gpio-cells = <2>;
88+
ngpios = <16>;
89+
status = "disabled";
90+
};
91+
92+
ioport2: gpio@40400040 {
93+
compatible = "renesas,ra8-gpio";
94+
reg = <0x40400040 0x20>;
95+
port = <2>;
96+
gpio-controller;
97+
#gpio-cells = <2>;
98+
ngpios = <16>;
99+
status = "disabled";
100+
};
101+
102+
ioport3: gpio@40400060 {
103+
compatible = "renesas,ra8-gpio";
104+
reg = <0x40400060 0x20>;
105+
port = <3>;
106+
gpio-controller;
107+
#gpio-cells = <2>;
108+
ngpios = <16>;
109+
status = "disabled";
110+
};
111+
112+
ioport4: gpio@40400080 {
113+
compatible = "renesas,ra8-gpio";
114+
reg = <0x40400080 0x20>;
115+
port = <4>;
116+
gpio-controller;
117+
#gpio-cells = <2>;
118+
ngpios = <16>;
119+
vbatts_pins = <2 3 4>;
120+
status = "disabled";
121+
};
122+
123+
ioport5: gpio@404000a0 {
124+
compatible = "renesas,ra8-gpio";
125+
reg = <0x404000a0 0x20>;
126+
port = <5>;
127+
gpio-controller;
128+
#gpio-cells = <2>;
129+
ngpios = <16>;
130+
status = "disabled";
131+
};
132+
133+
ioport6: gpio@404000c0 {
134+
compatible = "renesas,ra8-gpio";
135+
reg = <0x404000c0 0x20>;
136+
port = <6>;
137+
gpio-controller;
138+
#gpio-cells = <2>;
139+
ngpios = <16>;
140+
status = "disabled";
141+
};
142+
143+
ioport7: gpio@404000e0 {
144+
compatible = "renesas,ra8-gpio";
145+
reg = <0x404000e0 0x20>;
146+
port = <7>;
147+
gpio-controller;
148+
#gpio-cells = <2>;
149+
ngpios = <16>;
150+
status = "disabled";
151+
};
152+
153+
ioport8: gpio@40400100 {
154+
compatible = "renesas,ra8-gpio";
155+
reg = <0x40400100 0x20>;
156+
port = <8>;
157+
gpio-controller;
158+
#gpio-cells = <2>;
159+
ngpios = <16>;
160+
status = "disabled";
161+
};
162+
163+
ioport9: gpio@40400120 {
164+
compatible = "renesas,ra8-gpio";
165+
reg = <0x40400120 0x20>;
166+
port = <9>;
167+
gpio-controller;
168+
#gpio-cells = <2>;
169+
ngpios = <16>;
170+
status = "disabled";
171+
};
172+
173+
ioporta: gpio@40400140 {
174+
compatible = "renesas,ra8-gpio";
175+
reg = <0x40400140 0x20>;
176+
port = <10>;
177+
gpio-controller;
178+
#gpio-cells = <2>;
179+
ngpios = <16>;
180+
status = "disabled";
181+
};
182+
183+
ioportb: gpio@40400160 {
184+
compatible = "renesas,ra8-gpio";
185+
reg = <0x40400160 0x20>;
186+
port = <11>;
187+
gpio-controller;
188+
#gpio-cells = <2>;
189+
ngpios = <16>;
190+
status = "disabled";
191+
};
71192
};
72193

73194
&nvic {

0 commit comments

Comments
 (0)