Skip to content

Commit 2aa071c

Browse files
duynguyenxakartben
authored andcommitted
drivers: pinctrl: Support pinctrl driver for Renesas RX
Intial support of pinctrl driver for Renesas RX MCU family. This support base on using Renesas RX driver package in hal_renesas layer Signed-off-by: Duy Nguyen <[email protected]> Signed-off-by: Phi Tran <[email protected]>
1 parent ad42e4d commit 2aa071c

File tree

9 files changed

+788
-0
lines changed

9 files changed

+788
-0
lines changed

drivers/pinctrl/renesas/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# SPDX-License-Identifier: Apache-2.0
44

55
zephyr_library_sources_ifdef(CONFIG_PINCTRL_RENESAS_RA_PFS ra/pinctrl_ra.c)
6+
zephyr_library_sources_ifdef(CONFIG_PINCTRL_RENESAS_RX rx/pinctrl_renesas_rx.c)
67
zephyr_library_sources_ifdef(CONFIG_PINCTRL_RZT2M rz/pinctrl_rzt2m.c)
78
zephyr_library_sources_ifdef(CONFIG_PINCTRL_SMARTBOND smartbond/pinctrl_smartbond.c)
89
zephyr_library_sources_ifdef(CONFIG_PINCTRL_RENESAS_RZ rz/pinctrl_renesas_rz.c)

drivers/pinctrl/renesas/rx/Kconfig

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Copyright (c) 2024 Renesas Electronics Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config PINCTRL_RENESAS_RX
5+
bool "Renesas RX series pin controller driver"
6+
default y
7+
depends on DT_HAS_RENESAS_RX_PINCTRL_ENABLED
8+
select USE_RX_RDP_MPC
9+
select USE_RX_RDP_GPIO
10+
help
11+
Enable Renesas RX series pin controller driver.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
/*
2+
* Copyright (c) 2024 Renesas Electronics Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/drivers/pinctrl.h>
8+
#include <soc.h>
9+
10+
/* Renesas FIT module for iodefine.h data structures */
11+
#include "platform.h"
12+
#include "r_gpio_rx_if.h"
13+
#include "r_mpc_rx_if.h"
14+
15+
#define PORT_POS (8)
16+
17+
extern const uint8_t g_gpio_open_drain_n_support[];
18+
extern const uint8_t g_gpio_pull_up_support[];
19+
extern const uint8_t g_gpio_dscr_support[];
20+
21+
static bool gpio_pin_function_check(uint8_t const *check_array, uint8_t port_number,
22+
uint8_t pin_number)
23+
{
24+
if ((check_array[port_number] & (1 << pin_number)) != 0) {
25+
return true;
26+
} else {
27+
return false;
28+
}
29+
}
30+
31+
static int pinctrl_configure_pullup(const pinctrl_soc_pin_t *pin, uint32_t value)
32+
{
33+
gpio_port_pin_t port_pin;
34+
bool pin_check;
35+
int ret = 0;
36+
37+
port_pin = (pin->port_num << PORT_POS) | pin->pin_num;
38+
pin_check = gpio_pin_function_check(g_gpio_pull_up_support, pin->port_num, pin->pin_num);
39+
40+
if (pin_check) {
41+
ret = R_GPIO_PinControl(port_pin, (value ? GPIO_CMD_IN_PULL_UP_ENABLE
42+
: GPIO_CMD_IN_PULL_UP_DISABLE));
43+
}
44+
45+
return ret;
46+
}
47+
48+
static int pinctrl_configure_dscr(const pinctrl_soc_pin_t *pin, uint32_t value)
49+
{
50+
gpio_port_pin_t port_pin;
51+
bool pin_check;
52+
int ret = 0;
53+
54+
port_pin = (pin->port_num << PORT_POS) | pin->pin_num;
55+
pin_check = gpio_pin_function_check(g_gpio_dscr_support, pin->port_num, pin->pin_num);
56+
57+
if (pin_check) {
58+
ret = R_GPIO_PinControl(port_pin,
59+
(value ? GPIO_CMD_DSCR_ENABLE : GPIO_CMD_DSCR_DISABLE));
60+
}
61+
62+
return ret;
63+
}
64+
65+
static int pinctrl_configure_opendrain(const pinctrl_soc_pin_t *pin, uint32_t value)
66+
{
67+
gpio_port_pin_t port_pin;
68+
bool pin_check;
69+
int ret = 0;
70+
71+
port_pin = (pin->port_num << PORT_POS) | pin->pin_num;
72+
pin_check =
73+
gpio_pin_function_check(g_gpio_open_drain_n_support, pin->port_num, pin->pin_num);
74+
75+
if (pin_check) {
76+
ret = R_GPIO_PinControl(
77+
port_pin, (value ? GPIO_CMD_OUT_OPEN_DRAIN_N_CHAN : GPIO_CMD_OUT_CMOS));
78+
}
79+
80+
return ret;
81+
}
82+
83+
int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt, uintptr_t reg)
84+
{
85+
gpio_port_pin_t port_pin;
86+
mpc_config_t pconfig = {
87+
.pin_function = 0x0,
88+
.irq_enable = false,
89+
.analog_enable = false,
90+
};
91+
int ret;
92+
93+
for (uint8_t i = 0U; i < pin_cnt; i++) {
94+
const pinctrl_soc_pin_t *pin = &pins[i];
95+
96+
port_pin = (pin->port_num << PORT_POS) | pin->pin_num;
97+
98+
/* Set PMR register to 0 before setting pin control register */
99+
ret = R_GPIO_PinControl(port_pin, GPIO_CMD_ASSIGN_TO_GPIO);
100+
if (ret != 0) {
101+
return -EINVAL;
102+
}
103+
104+
/* Set output high */
105+
if (pin->cfg.output_high) {
106+
R_GPIO_PinWrite(port_pin, GPIO_LEVEL_HIGH);
107+
}
108+
109+
/* Set port direction */
110+
if (pin->cfg.output_enable) {
111+
R_GPIO_PinDirectionSet(port_pin, GPIO_DIRECTION_OUTPUT);
112+
}
113+
114+
/* Set pull-up */
115+
ret = pinctrl_configure_pullup(pin, pin->cfg.bias_pull_up);
116+
117+
if (ret != 0) {
118+
return -EINVAL;
119+
}
120+
121+
/* Set open-drain */
122+
ret = pinctrl_configure_opendrain(pin, pin->cfg.drive_open_drain);
123+
124+
if (ret != 0) {
125+
return -EINVAL;
126+
}
127+
128+
/* Set drive-strength */
129+
ret = pinctrl_configure_dscr(pin, pin->cfg.drive_strength);
130+
131+
if (ret != 0) {
132+
return -EINVAL;
133+
}
134+
135+
/* Set pin function */
136+
pconfig.analog_enable = pin->cfg.analog_enable;
137+
pconfig.pin_function = pin->cfg.psels;
138+
ret = R_MPC_Write(port_pin, &pconfig);
139+
if (ret != 0) {
140+
return -EINVAL;
141+
}
142+
143+
/* Set MODE */
144+
if (pin->cfg.pin_mode) {
145+
ret = R_GPIO_PinControl(port_pin, GPIO_CMD_ASSIGN_TO_PERIPHERAL);
146+
if (ret != 0) {
147+
return -EINVAL;
148+
}
149+
}
150+
}
151+
152+
return 0;
153+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Copyright (c) 2024 Renesas Electronics Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: |
5+
description: |
6+
The Renesas RX pin controller is a node responsible for controlling
7+
pin function selection and pin properties
8+
9+
The node has the 'pinctrl' node label set in your SoC's devicetree,
10+
so you can modify it like this:
11+
12+
&pinctrl {
13+
/* your modifications go here */
14+
};
15+
16+
All device pin configurations should be placed in child nodes of the
17+
'pinctrl' node, as shown in this example:
18+
19+
/* You can put this in places like a board-pinctrl.dtsi file in
20+
* your board directory, or a devicetree overlay in your application.
21+
*/
22+
23+
/* include pre-defined combinations for the SoC variant used by the board */
24+
#include <dt-bindings/pinctrl/renesas/rx-pinctrl.h>
25+
26+
&pinctrl {
27+
sci1_default: sci1_default {
28+
group1 {
29+
psels = <RX_PSEL(RX_PSEL_SCI_1, 2, 6)>; /* TX */
30+
drive-strength = "medium";
31+
};
32+
group2 {
33+
psels = <RX_PSEL(RX_PSEL_SCI_1, 3, 0)>; /* RX */
34+
drive-strength = "medium";
35+
};
36+
};
37+
};
38+
39+
The 'sci1_default' child node encodes the pin configurations for a
40+
particular state of a device; in this case, the default (that is, active)
41+
state.
42+
43+
As shown, pin configurations are organized in groups within each child node.
44+
Each group can specify a list of pin function selections in the 'psels'
45+
property.
46+
47+
A group can also specify shared pin properties common to all the specified
48+
pins, such as the 'input-enable' property in group 2. Here is a list of
49+
supported standard pin properties:
50+
51+
- bias-disable: Disable pull-up/down (default, not required).
52+
- bias-pull-up: Enable pull-up resistor.
53+
- input-enable: Enable input from the pin.
54+
- drive-strength: Set the drive strength of the pin. Possible
55+
values are: normal, high.
56+
57+
To link pin configurations with a device, use a pinctrl-N property for some
58+
number N, like this example you could place in your board's DTS file:
59+
60+
#include "board-pinctrl.dtsi"
61+
62+
&sci1 {
63+
pinctrl-0 = <&uart0_default>;
64+
pinctrl-1 = <&uart0_sleep>;
65+
pinctrl-names = "default", "sleep";
66+
};
67+
68+
compatible: "renesas,rx-pinctrl"
69+
70+
include: base.yaml
71+
72+
child-binding:
73+
description: |
74+
Definitions for a pinctrl state.
75+
child-binding:
76+
include:
77+
- name: pincfg-node.yaml
78+
property-allowlist:
79+
- bias-disable
80+
- bias-pull-up
81+
- input-enable
82+
- output-enable
83+
- output-high
84+
- drive-open-drain
85+
86+
properties:
87+
psels:
88+
required: true
89+
type: array
90+
description: |
91+
An array of pins sharing the same group properties. Each
92+
element of the array is an integer constructed from the
93+
pin number and the alternative function of the pin.
94+
drive-strength:
95+
type: string
96+
enum:
97+
- "normal"
98+
- "high"
99+
default: "normal"
100+
description: |
101+
The drive strength of a pin. The default value is normal, as this
102+
is the power on reset value.
103+
renesas,analog-enable:
104+
type: boolean
105+
description: enable analog input
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright (c) 2024 Renesas Electronics Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: Rensas RX Pinmux (Multi Function Pin Controller, MPC)
5+
6+
compatible: "renesas,rx-pinmux"
7+
8+
include: base.yaml
9+
10+
properties:
11+
reg:
12+
required: true
13+
14+
"#pinmux-cells":
15+
type: int
16+
required: true
17+
const: 2
18+
description: number of items in a pinmux specifier
19+
20+
pinmux-cells:
21+
- pin
22+
- function
23+
24+
child-binding:
25+
include: pincfg-node.yaml

dts/rx/renesas/rx130-common.dtsi

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <mem.h>
1212
#include <zephyr/dt-bindings/clock/rx_clock.h>
13+
#include <zephyr/dt-bindings/pinctrl/renesas/pinctrl-rx.h>
1314

1415
/ {
1516
#address-cells = <1>;

0 commit comments

Comments
 (0)