Skip to content

Commit 75f1f7e

Browse files
duynguyenxanashif
authored andcommitted
drivers: pinctrl: Add pinctrl driver for RA8 series
This is the initial commit to support minimum pinctrl driver for Renesas MCU RA8M1. Signed-off-by: Duy Nguyen <[email protected]>
1 parent 7195f0d commit 75f1f7e

File tree

8 files changed

+274
-0
lines changed

8 files changed

+274
-0
lines changed

drivers/pinctrl/renesas/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Copyright (c) 2024 EPAM Systems
2+
# Copyright (c) 2024 Renesas Electronics Corporation
23
# SPDX-License-Identifier: Apache-2.0
34

45
zephyr_library_sources_ifdef(CONFIG_PINCTRL_RENESAS_RA ra/pinctrl_renesas_ra.c)
6+
zephyr_library_sources_ifdef(CONFIG_PINCTRL_RENESAS_RA8 ra/pinctrl_renesas_ra8.c)
57
zephyr_library_sources_ifdef(CONFIG_PINCTRL_RZT2M rz/pinctrl_rzt2m.c)
68
zephyr_library_sources_ifdef(CONFIG_PINCTRL_SMARTBOND smartbond/pinctrl_smartbond.c)
79

drivers/pinctrl/renesas/ra/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Copyright (c) 2023 TOKITA Hiroshi <[email protected]>
2+
# Copyright (c) 2024 Renesas Electronics Corporation
23
# SPDX-License-Identifier: Apache-2.0
34

45
config PINCTRL_RENESAS_RA
@@ -7,3 +8,10 @@ config PINCTRL_RENESAS_RA
78
depends on DT_HAS_RENESAS_RA_PINCTRL_ENABLED
89
help
910
Enable Renesas RA series pin controller driver.
11+
12+
config PINCTRL_RENESAS_RA8
13+
bool "Renesas RA8 pinctrl driver"
14+
default y
15+
depends on DT_HAS_RENESAS_RA8_PINCTRL_ENABLED
16+
help
17+
Enable the Renesas RA8 pinctrl driver.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
#define PORT_POS (8)
11+
12+
int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt, uintptr_t reg)
13+
{
14+
bsp_io_port_pin_t port_pin;
15+
16+
R_BSP_PinAccessEnable();
17+
18+
for (uint8_t i = 0U; i < pin_cnt; i++) {
19+
const pinctrl_soc_pin_t *pin = &pins[i];
20+
21+
port_pin = (pin->port_num << PORT_POS) | pin->pin_num;
22+
R_BSP_PinCfg(port_pin, pin->cfg);
23+
}
24+
25+
R_BSP_PinAccessDisable();
26+
27+
return 0;
28+
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <mem.h>
88
#include <arm/armv8.1-m.dtsi>
99
#include <freq.h>
10+
#include <zephyr/dt-bindings/pinctrl/renesas/ra-pinctrl.h>
1011

1112

1213
/ {
@@ -61,6 +62,12 @@
6162
status = "okay";
6263
};
6364
};
65+
66+
pinctrl: pin-controller@40400800 {
67+
compatible = "renesas,ra8-pinctrl";
68+
reg = <0x40400800 0x3c0>;
69+
status = "okay";
70+
};
6471
};
6572

6673
&nvic {
Lines changed: 105 additions & 0 deletions
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+
The Renesas RA pin controller is a node responsible for controlling
6+
pin function selection and pin properties, such as routing a SCI0 RXD
7+
to P610.
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/ra-pinctrl.h>
25+
26+
&pinctrl {
27+
/* configuration for the sci0 "default" state */
28+
sci0_default: sci0_default {
29+
group1 {
30+
/* tx */
31+
psels = <RA_PSEL(RA_PSEL_SCI_0, 6, 9)>;
32+
drive-strength = "medium";
33+
};
34+
group2 {
35+
/* rx */
36+
psels = <RA_PSEL(RA_PSEL_SCI_0, 6, 10)>;
37+
};
38+
};
39+
};
40+
41+
The 'sci0_default' child node encodes the pin configurations for a
42+
particular state of a device; in this case, the default (that is, active)
43+
state.
44+
45+
As shown, pin configurations are organized in groups within each child node.
46+
Each group can specify a list of pin function selections in the 'psels'
47+
property.
48+
49+
A group can also specify shared pin properties common to all the specified
50+
pins, such as the 'input-enable' property in group 2. Here is a list of
51+
supported standard pin properties:
52+
53+
- bias-disable: Disable pull-up/down (default, not required).
54+
- bias-pull-up: Enable pull-up resistor.
55+
- input-enable: Enable input from the pin.
56+
- drive-strength: Set the drive strength of the pin. Possible
57+
values are: low, medium, highspeed-high, high.
58+
59+
To link pin configurations with a device, use a pinctrl-N property for some
60+
number N, like this example you could place in your board's DTS file:
61+
62+
#include "board-pinctrl.dtsi"
63+
64+
&sci0 {
65+
pinctrl-0 = <&uart0_default>;
66+
pinctrl-1 = <&uart0_sleep>;
67+
pinctrl-names = "default", "sleep";
68+
};
69+
70+
compatible: "renesas,ra8-pinctrl"
71+
72+
include: base.yaml
73+
74+
child-binding:
75+
description: |
76+
Definitions for a pinctrl state.
77+
child-binding:
78+
79+
include:
80+
- name: pincfg-node.yaml
81+
property-allowlist:
82+
- bias-disable
83+
- bias-pull-up
84+
- input-enable
85+
- drive-open-drain
86+
87+
properties:
88+
psels:
89+
required: true
90+
type: array
91+
description: |
92+
An array of pins sharing the same group properties. Each
93+
element of the array is an integer constructed from the
94+
pin number and the alternative function of the pin.
95+
drive-strength:
96+
type: string
97+
enum:
98+
- "low"
99+
- "medium"
100+
- "highspeed-high"
101+
- "high"
102+
default: "low"
103+
description: |
104+
The drive strength of a pin. The default value is low, as this
105+
is the power on reset value.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (c) 2024 Renesas Electronics Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef __ZEPHYR_INCLUDE_DT_BINDINGS_PINCTRL_RENESAS_RA_PINCTRL_H__
8+
#define __ZEPHYR_INCLUDE_DT_BINDINGS_PINCTRL_RENESAS_RA_PINCTRL_H__
9+
10+
#define RA_PORT_NUM_POS 0
11+
#define RA_PORT_NUM_MASK 0xf
12+
13+
#define RA_PIN_NUM_POS 4
14+
#define RA_PIN_NUM_MASK 0xf
15+
16+
#define RA_PSEL_HIZ_JTAG_SWD 0x0
17+
#define RA_PSEL_AGT 0x1
18+
#define RA_PSEL_GPT0 0x2
19+
#define RA_PSEL_GPT1 0x3
20+
#define RA_PSEL_SCI_0 0x4
21+
#define RA_PSEL_SCI_2 0x4
22+
#define RA_PSEL_SCI_4 0x4
23+
#define RA_PSEL_SCI_6 0x4
24+
#define RA_PSEL_SCI_8 0x4
25+
#define RA_PSEL_SCI_1 0x5
26+
#define RA_PSEL_SCI_3 0x5
27+
#define RA_PSEL_SCI_5 0x5
28+
#define RA_PSEL_SCI_7 0x5
29+
#define RA_PSEL_SCI_9 0x5
30+
#define RA_PSEL_SPI 0x6
31+
#define RA_PSEL_I2C 0x7
32+
#define RA_PSEL_CLKOUT_RTC 0x9
33+
#define RA_PSEL_CAC_ADC 0xa
34+
#define RA_PSEL_BUS 0xb
35+
#define RA_PSEL_CANFD 0x10
36+
#define RA_PSEL_QSPI 0x11
37+
#define RA_PSEL_SSIE 0x12
38+
#define RA_PSEL_USBFS 0x13
39+
#define RA_PSEL_USBHS 0x14
40+
#define RA_PSEL_SDHI 0x15
41+
#define RA_PSEL_ETH_MII 0x16
42+
#define RA_PSEL_ETH_RMII 0x17
43+
#define RA_PSEL_GLCDC 0x19
44+
#define RA_PSEL_OSPI 0x1c
45+
46+
#define RA_PSEL_POS 8
47+
#define RA_PSEL_MASK 0x1f
48+
49+
#define RA_MODE_POS 13
50+
#define RA_MODE_MASK 0x1
51+
52+
#define RA_PSEL(psel, port_num, pin_num) \
53+
(1 << RA_MODE_POS | psel << RA_PSEL_POS | port_num << RA_PORT_NUM_POS | \
54+
pin_num << RA_PIN_NUM_POS)
55+
56+
#endif /* __ZEPHYR_INCLUDE_DT_BINDINGS_PINCTRL_RENESAS_RA_PINCTRL_H__ */
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright (c) 2024 Renesas Electronics Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_SOC_RENESAS_RA_COMMON_PINCTRL_SOC_H_
8+
#define ZEPHYR_SOC_RENESAS_RA_COMMON_PINCTRL_SOC_H_
9+
10+
#include <zephyr/devicetree.h>
11+
#include <zephyr/types.h>
12+
13+
#include <zephyr/dt-bindings/pinctrl/renesas/ra-pinctrl.h>
14+
15+
/**
16+
* @brief Type to hold a renesas ra pin's pinctrl configuration.
17+
*/
18+
struct ra_pinctrl_soc_pin {
19+
/** Port number 0..9, A, B */
20+
uint32_t port_num: 4;
21+
/** Pin number 0..15 */
22+
uint32_t pin_num: 4;
23+
/** Register PFS cfg */
24+
uint32_t cfg;
25+
};
26+
27+
typedef struct ra_pinctrl_soc_pin pinctrl_soc_pin_t;
28+
29+
/**
30+
* @brief Utility macro to initialize each pin.
31+
*
32+
* @param node_id Node identifier.
33+
* @param prop Property name.
34+
* @param idx Property entry index.
35+
*/
36+
#define Z_PINCTRL_STATE_PIN_INIT(node_id, prop, idx) \
37+
{ \
38+
.port_num = RA_GET_PORT_NUM(DT_PROP_BY_IDX(node_id, prop, idx)), \
39+
.pin_num = RA_GET_PIN_NUM(DT_PROP_BY_IDX(node_id, prop, idx)), \
40+
.cfg = (DT_PROP(node_id, bias_pull_up) << 4) | \
41+
(DT_PROP(node_id, drive_open_drain) << 6) | \
42+
(DT_ENUM_IDX(node_id, drive_strength) << 10) | \
43+
(RA_GET_MODE(DT_PROP_BY_IDX(node_id, prop, idx)) << 16) | \
44+
(RA_GET_PSEL(DT_PROP_BY_IDX(node_id, prop, idx)) << 24), \
45+
},
46+
47+
/**
48+
* @brief Utility macro to initialize state pins contained in a given property.
49+
*
50+
* @param node_id Node identifier.
51+
* @param prop Property name describing state pins.
52+
*/
53+
#define Z_PINCTRL_STATE_PINS_INIT(node_id, prop) \
54+
{ \
55+
DT_FOREACH_CHILD_VARGS(DT_PHANDLE(node_id, prop), DT_FOREACH_PROP_ELEM, psels, \
56+
Z_PINCTRL_STATE_PIN_INIT) \
57+
}
58+
59+
#define RA_GET_PORT_NUM(pinctrl) (((pinctrl) >> RA_PORT_NUM_POS) & RA_PORT_NUM_MASK)
60+
#define RA_GET_PIN_NUM(pinctrl) (((pinctrl) >> RA_PIN_NUM_POS) & RA_PIN_NUM_MASK)
61+
62+
#define RA_GET_MODE(pinctrl) (((pinctrl) >> RA_MODE_POS) & RA_MODE_MASK)
63+
#define RA_GET_PSEL(pinctrl) (((pinctrl) >> RA_PSEL_POS) & RA_PSEL_MASK)
64+
65+
#endif /* ZEPHYR_SOC_RENESAS_RA_COMMON_PINCTRL_SOC_H_ */

soc/renesas/ra/ra8m1/soc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ LOG_MODULE_REGISTER(soc, CONFIG_SOC_LOG_LEVEL);
2323

2424
uint32_t SystemCoreClock BSP_SECTION_EARLY_INIT;
2525

26+
volatile uint32_t g_protect_pfswe_counter BSP_SECTION_EARLY_INIT;
27+
2628
/**
2729
* @brief Perform basic hardware initialization at boot.
2830
*
@@ -34,6 +36,7 @@ uint32_t SystemCoreClock BSP_SECTION_EARLY_INIT;
3436
static int renesas_ra8m1_init(void)
3537
{
3638
SystemCoreClock = BSP_MOCO_HZ;
39+
g_protect_pfswe_counter = 0;
3740
bsp_clock_init();
3841

3942
return 0;

0 commit comments

Comments
 (0)