Skip to content

Commit da0c8e5

Browse files
Hoang Nguyenkartben
authored andcommitted
drivers: pinctrl: Add support for RZ/N2L
This is the initial commit to support pinctrl driver for Renesas RZ/N2L Signed-off-by: Hoang Nguyen <[email protected]> Signed-off-by: Nhut Nguyen <[email protected]>
1 parent 954e80a commit da0c8e5

File tree

7 files changed

+255
-1
lines changed

7 files changed

+255
-1
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (c) 2025 Renesas Electronics Corporation
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include <zephyr/dt-bindings/gpio/gpio.h>
7+
#include <zephyr/dt-bindings/pinctrl/renesas/pinctrl-rzn-common.h>
8+
9+
&pinctrl {
10+
/omit-if-no-ref/ sci0_default: sci0_default {
11+
sci0-pinmux {
12+
pinmux = <RZN_PINMUX(PORT_16, 5, 1)>, /* TXD */
13+
<RZN_PINMUX(PORT_16, 6, 2)>; /* RXD */
14+
};
15+
};
16+
17+
/omit-if-no-ref/ sci3_default: sci3_default {
18+
sci3-pinmux {
19+
pinmux = <RZN_PINMUX(PORT_18, 0, 4)>, /* TXD */
20+
<RZN_PINMUX(PORT_17, 7, 4)>; /* RXD */
21+
};
22+
};
23+
24+
/omit-if-no-ref/ irq7_default: irq7_default {
25+
irq7-pinmux {
26+
pinmux = <RZN_PINMUX(PORT_16, 3, 0)>;
27+
input-enable;
28+
};
29+
};
30+
};

drivers/pinctrl/renesas/rz/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ config PINCTRL_RZT2M
1212
config PINCTRL_RENESAS_RZ
1313
bool "Renesas RZ pin controller driver"
1414
default y
15-
depends on DT_HAS_RENESAS_RZG_PINCTRL_ENABLED
15+
depends on DT_HAS_RENESAS_RZG_PINCTRL_ENABLED || DT_HAS_RENESAS_RZN_PINCTRL_ENABLED
1616
select USE_RZ_FSP_IOPORT
1717
help
1818
Enable Renesas RZ pinctrl driver.

dts/arm/renesas/rz/rzn/r9a07g084.dtsi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,10 @@
8787
};
8888
};
8989
};
90+
91+
pinctrl: pinctrl@800a0000 {
92+
compatible = "renesas,rzn-pinctrl";
93+
reg = <0x800a0000 0x1000 0x81030c00 0x1000>;
94+
};
9095
};
9196
};
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Copyright (c) 2025 Renesas Electronics Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
5+
description: |
6+
The Renesas RZ/N2L pin controller is a node responsible for controlling
7+
pin function selection and pin properties, such as routing the TX and RX of UART0
8+
to pin 5 and pin 6 of port 16.
9+
10+
The node has the 'pinctrl' node label set in your SoC's devicetree,
11+
so you can modify it like this:
12+
13+
&pinctrl {
14+
/* your modifications go here */
15+
};
16+
17+
All device pin configurations should be placed in child nodes of the
18+
'pinctrl' node, as shown in this example:
19+
20+
/* You can put this in places like a board-pinctrl.dtsi file in
21+
* your board directory, or a devicetree overlay in your application.
22+
*/
23+
24+
/* include pre-defined combinations for the SoC variant used by the board */
25+
#include <zephyr/dt-bindings/pinctrl/renesas/pinctrl-rzn-common.h>
26+
27+
&pinctrl {
28+
uart0_pins: uart0 {
29+
group1 {
30+
pinmux = <RZN_PINMUX(PORT_16, 5, 1)>; /* TXD */
31+
};
32+
group2 {
33+
pinmux = <RZN_PINMUX(PORT_16, 6, 2)>; /* RXD */
34+
input-enable;
35+
};
36+
};
37+
};
38+
39+
The 'uart0_pins' 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 'pinmux'
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.
49+
50+
compatible: "renesas,rzn-pinctrl"
51+
52+
include: base.yaml
53+
54+
child-binding:
55+
description: |
56+
Definitions for a pinctrl state.
57+
child-binding:
58+
59+
include:
60+
- name: pincfg-node.yaml
61+
property-allowlist:
62+
- input-enable
63+
- output-enable
64+
- output-high
65+
- bias-pull-up
66+
- bias-pull-down
67+
- input-schmitt-enable
68+
69+
properties:
70+
pinmux:
71+
required: true
72+
type: array
73+
description: |
74+
An array of pins sharing the same group properties. Each
75+
element of the array is an integer constructed from the
76+
pin number and the alternative function of the pin.
77+
drive-strength:
78+
type: string
79+
enum:
80+
- "low"
81+
- "middle"
82+
- "high"
83+
- "ultrahigh"
84+
default: "low"
85+
description: |
86+
The drive strength of a pin, relative to full-driver strength.
87+
The default value is "low", which is the reset value.
88+
slew-rate:
89+
type: string
90+
enum:
91+
- "slow"
92+
- "fast"
93+
default: "slow"
94+
description: |
95+
Select slew rate for a pin. The default is slow, which is the reset value.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (c) 2025 Renesas Electronics Corporation
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_PINCTRL_RENESAS_PINCTRL_RZN_COMMON_H_
7+
#define ZEPHYR_INCLUDE_DT_BINDINGS_PINCTRL_RENESAS_PINCTRL_RZN_COMMON_H_
8+
9+
/* Superset list of all possible IO ports. */
10+
#define PORT_00 0x0000 /* IO port 0 */
11+
#define PORT_01 0x0100 /* IO port 1 */
12+
#define PORT_02 0x0200 /* IO port 2 */
13+
#define PORT_03 0x0300 /* IO port 3 */
14+
#define PORT_04 0x0400 /* IO port 4 */
15+
#define PORT_05 0x0500 /* IO port 5 */
16+
#define PORT_06 0x0600 /* IO port 6 */
17+
#define PORT_07 0x0700 /* IO port 7 */
18+
#define PORT_08 0x0800 /* IO port 8 */
19+
#define PORT_09 0x0900 /* IO port 9 */
20+
#define PORT_10 0x0A00 /* IO port 10 */
21+
#define PORT_11 0x0B00 /* IO port 11 */
22+
#define PORT_12 0x0C00 /* IO port 12 */
23+
#define PORT_13 0x0D00 /* IO port 13 */
24+
#define PORT_14 0x0E00 /* IO port 14 */
25+
#define PORT_15 0x0F00 /* IO port 15 */
26+
#define PORT_16 0x1000 /* IO port 16 */
27+
#define PORT_17 0x1100 /* IO port 17 */
28+
#define PORT_18 0x1200 /* IO port 18 */
29+
#define PORT_19 0x1300 /* IO port 19 */
30+
#define PORT_20 0x1400 /* IO port 20 */
31+
#define PORT_21 0x1500 /* IO port 21 */
32+
#define PORT_22 0x1600 /* IO port 22 */
33+
#define PORT_23 0x1700 /* IO port 23 */
34+
#define PORT_24 0x1800 /* IO port 24 */
35+
36+
/*
37+
* Create the value contain port/pin/function information
38+
*
39+
* port: port number BSP_IO_PORT_00..BSP_IO_PORT_34
40+
* pin: pin number
41+
* func: pin function
42+
*/
43+
#define RZN_PINMUX(port, pin, func) (port | pin | (func << 4))
44+
45+
#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_PINCTRL_RENESAS_PINCTRL_RZN_COMMON_H_ */

soc/renesas/rz/common/pinctrl_rzn.h

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright (c) 2025 Renesas Electronics Corporation
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
#ifndef ZEPHYR_SOC_RENESAS_RZ_COMMON_PINCTRL_RZN_H_
6+
#define ZEPHYR_SOC_RENESAS_RZ_COMMON_PINCTRL_RZN_H_
7+
8+
#include <zephyr/types.h>
9+
#include <zephyr/devicetree.h>
10+
#include "r_ioport.h"
11+
12+
#ifdef __cplusplus
13+
extern "C" {
14+
#endif
15+
16+
#define RZN_GET_PORT_PIN(pinmux) (pinmux & ~(0xF << 4))
17+
#define RZN_GET_FUNC(pinmux) ((pinmux & 0xF0) >> 4)
18+
19+
/* Porting */
20+
typedef struct pinctrl_cfg_data_t {
21+
uint32_t p_reg: 1;
22+
uint32_t pm_reg: 2;
23+
uint32_t pmc_reg: 1;
24+
uint32_t pfc_reg: 4;
25+
uint32_t drct_reg: 6;
26+
uint32_t rsel_reg: 1;
27+
uint32_t reserved: 17;
28+
} pinctrl_cfg_data_t;
29+
30+
typedef struct pinctrl_soc_pin_t {
31+
bsp_io_port_pin_t port_pin;
32+
pinctrl_cfg_data_t config;
33+
} pinctrl_soc_pin_t;
34+
35+
#define Z_PINCTRL_STATE_PIN_INIT(node_id, prop, idx) \
36+
{ \
37+
.port_pin = RZN_GET_PORT_PIN(DT_PROP_BY_IDX(node_id, prop, idx)), \
38+
.config = \
39+
{ \
40+
.p_reg = DT_PROP(node_id, output_high), \
41+
.pm_reg = DT_PROP(node_id, input_enable) == 1 \
42+
? 1U \
43+
: (DT_PROP(node_id, output_enable) == 1 ? 2U \
44+
: 0U), \
45+
.pmc_reg = 1, \
46+
.pfc_reg = RZN_GET_FUNC(DT_PROP_BY_IDX(node_id, prop, idx)), \
47+
.drct_reg = \
48+
(DT_ENUM_IDX(node_id, drive_strength)) | \
49+
((DT_PROP(node_id, bias_pull_up) == 1 \
50+
? 1U \
51+
: (DT_PROP(node_id, bias_pull_down) == 1 ? 2U \
52+
: 0)) \
53+
<< 2) | \
54+
(DT_PROP(node_id, input_schmitt_enable) << 4) | \
55+
(DT_ENUM_IDX(node_id, slew_rate) << 5), \
56+
.rsel_reg = 1, \
57+
.reserved = 0, \
58+
}, \
59+
},
60+
#define Z_PINCTRL_STATE_PINS_INIT(node_id, prop) \
61+
{DT_FOREACH_CHILD_VARGS(DT_PHANDLE(node_id, prop), DT_FOREACH_PROP_ELEM, pinmux, \
62+
Z_PINCTRL_STATE_PIN_INIT)}
63+
64+
#ifdef __cplusplus
65+
}
66+
#endif
67+
68+
#endif /* ZEPHYR_SOC_RENESAS_RZ_COMMON_PINCTRL_RZN_H_ */

soc/renesas/rz/rzn2l/pinctrl_soc.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* Copyright (c) 2025 Renesas Electronics Corporation
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#ifndef ZEPHYR_SOC_RENESAS_RZ_RZN2L_PINCTRL_SOC_H_
7+
#define ZEPHYR_SOC_RENESAS_RZ_RZN2L_PINCTRL_SOC_H_
8+
9+
#include <pinctrl_rzn.h>
10+
11+
#endif /* ZEPHYR_SOC_RENESAS_RZ_RZN2L_PINCTRL_SOC_H_ */

0 commit comments

Comments
 (0)