Skip to content

Commit 04b723e

Browse files
soburifabiobaltieri
authored andcommitted
drivers: pinctrl: Add pinctrl driver for Renesas RA series
To avoid complicating the initial code for supporting the SoC, I have implemented only the bare minimum for now. Signed-off-by: TOKITA Hiroshi <[email protected]>
1 parent 1741b3a commit 04b723e

File tree

11 files changed

+714
-0
lines changed

11 files changed

+714
-0
lines changed

drivers/pinctrl/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ zephyr_library_sources_ifdef(CONFIG_PINCTRL_EMSDP pinctrl_emsdp.c)
3535
zephyr_library_sources_ifdef(CONFIG_PINCTRL_TI_CC32XX pinctrl_ti_cc32xx.c)
3636
zephyr_library_sources_ifdef(CONFIG_PINCTRL_NUMAKER pinctrl_numaker.c)
3737
zephyr_library_sources_ifdef(CONFIG_PINCTRL_QUICKLOGIC_EOS_S3 pinctrl_eos_s3.c)
38+
zephyr_library_sources_ifdef(CONFIG_PINCTRL_RA pinctrl_ra.c)

drivers/pinctrl/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,6 @@ source "drivers/pinctrl/Kconfig.emsdp"
6464
source "drivers/pinctrl/Kconfig.ti_cc32xx"
6565
source "drivers/pinctrl/Kconfig.numaker"
6666
source "drivers/pinctrl/Kconfig.eos_s3"
67+
source "drivers/pinctrl/Kconfig.ra"
6768

6869
endif # PINCTRL

drivers/pinctrl/Kconfig.ra

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) 2023 TOKITA Hiroshi <[email protected]>
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config PINCTRL_RA
5+
bool "Renesas RA series pin controller driver"
6+
default y
7+
depends on DT_HAS_RENESAS_RA_PINCTRL_ENABLED
8+
help
9+
Enable Renesas RA series pin controller driver.

drivers/pinctrl/pinctrl_ra.c

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Copyright (c) 2023 TOKITA Hiroshi <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/drivers/pinctrl.h>
8+
#include <zephyr/kernel.h>
9+
#include <string.h>
10+
11+
#define DT_DRV_COMPAT renesas_ra_pinctrl
12+
13+
#define PORT_NUM 15
14+
#define PIN_NUM 16
15+
16+
enum {
17+
PWPR_PFSWE_POS = 6,
18+
PWPR_B0WI_POS = 7,
19+
};
20+
21+
static inline uint32_t pinctrl_ra_read_PmnFPS(size_t port, size_t pin)
22+
{
23+
return sys_read32(DT_INST_REG_ADDR_BY_NAME(0, pfs) + (port * PIN_NUM + pin) * 4);
24+
}
25+
26+
static inline void pinctrl_ra_write_PmnFPS(size_t port, size_t pin, uint32_t value)
27+
{
28+
sys_write32(value, DT_INST_REG_ADDR_BY_NAME(0, pfs) + (port * PIN_NUM + pin) * 4);
29+
}
30+
31+
static inline uint32_t pinctrl_ra_read_PMISC_PWPR(size_t port, size_t pin)
32+
{
33+
return sys_read32(DT_INST_REG_ADDR_BY_NAME(0, pmisc_pwpr));
34+
}
35+
36+
static inline void pinctrl_ra_write_PMISC_PWPR(uint32_t value)
37+
{
38+
sys_write32(value, DT_INST_REG_ADDR_BY_NAME(0, pmisc_pwpr));
39+
}
40+
41+
static void pinctrl_ra_configure_pfs(const pinctrl_soc_pin_t *pinc)
42+
{
43+
pinctrl_soc_pin_t pincfg;
44+
45+
memcpy(&pincfg, pinc, sizeof(pinctrl_soc_pin_t));
46+
pincfg.pin = 0;
47+
pincfg.port = 0;
48+
49+
/* Clear PMR bits before configuring */
50+
if ((pincfg.config & PmnPFS_PMR_POS)) {
51+
uint32_t val = pinctrl_ra_read_PmnFPS(pinc->port, pinc->pin);
52+
53+
pinctrl_ra_write_PmnFPS(pinc->port, pinc->pin, val & ~(BIT(PmnPFS_PMR_POS)));
54+
pinctrl_ra_write_PmnFPS(pinc->port, pinc->pin, pincfg.config & ~PmnPFS_PMR_POS);
55+
}
56+
57+
pinctrl_ra_write_PmnFPS(pinc->port, pinc->pin, pincfg.config);
58+
}
59+
60+
int pinctrl_ra_query_config(uint32_t port, uint32_t pin, struct pinctrl_ra_pin *const pincfg)
61+
{
62+
if (port >= PORT_NUM || pin >= PIN_NUM) {
63+
return -EINVAL;
64+
}
65+
66+
pincfg->config = pinctrl_ra_read_PmnFPS(port, pin);
67+
return 0;
68+
}
69+
70+
int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt, uintptr_t reg)
71+
{
72+
pinctrl_ra_write_PMISC_PWPR(0);
73+
pinctrl_ra_write_PMISC_PWPR(BIT(PWPR_PFSWE_POS));
74+
75+
for (int i = 0; i < pin_cnt; i++) {
76+
pinctrl_ra_configure_pfs(&pins[i]);
77+
}
78+
79+
pinctrl_ra_write_PMISC_PWPR(0);
80+
pinctrl_ra_write_PMISC_PWPR(BIT(PWPR_B0WI_POS));
81+
82+
return 0;
83+
}

dts/arm/renesas/ra/r7fa4m1ab3cfm.dtsi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,9 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
#define RA_SOC_PINS 64
8+
#define RA_SOC_HAS_MSTPCRE 1
9+
#define RA_SOC_MSTPD5_CHANNELS 1
10+
711
#include <zephyr/dt-bindings/clock/r7fa4m1xxxxxx-clock.h>
812
#include <renesas/ra/ra4-cm4-common.dtsi>

dts/arm/renesas/ra/ra-cm4-common.dtsi

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@
105105
reg = <0x40100000 DT_SIZE_K(8)>;
106106
};
107107
};
108+
109+
pinctrl: pinctrl@40040800 {
110+
compatible = "renesas,ra-pinctrl";
111+
reg = <0x40040800 0x500 0x40040d03 0x1>;
112+
reg-names = "pfs", "pmisc_pwpr";
113+
status = "okay";
114+
};
108115
};
109116
};
110117

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright (c) 2023 TOKITA Hiroshi <[email protected]>
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: |
5+
Renesas RA series pin controller
6+
7+
compatible: "renesas,ra-pinctrl"
8+
9+
include: base.yaml
10+
11+
child-binding:
12+
description: |
13+
Definitions for a pinctrl state.
14+
child-binding:
15+
16+
include:
17+
- name: pincfg-node.yaml
18+
19+
properties:
20+
pinmux:
21+
required: true
22+
type: array
23+
description: |
24+
An array of pins sharing the same group properties. Each
25+
element of the array is an integer constructed from the
26+
pin number and the alternative function of the pin.

include/zephyr/dt-bindings/pinctrl/renesas/pinctrl-r7fa4m1xxxxxx.h

Lines changed: 437 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (c) 2023 TOKITA Hiroshi <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_PINCTRL_RENESAS_PINCTRL_RA_COMMON_H_
8+
#define ZEPHYR_INCLUDE_DT_BINDINGS_PINCTRL_RENESAS_PINCTRL_RA_COMMON_H_
9+
10+
#define PORT4_POS 29
11+
#define PORT4_MASK 0x1
12+
#define PSEL_POS 24
13+
#define PSEL_MASK 0x5
14+
#define PORT_POS 21
15+
#define PORT_MASK 0x3
16+
#define PIN_POS 17
17+
#define PIN_MASK 0xF
18+
#define OPT_POS 0
19+
#define OPT_MASK 0x1B000
20+
21+
#define RA_PINCFG_GPIO 0x00000
22+
#define RA_PINCFG_FUNC 0x10000
23+
#define RA_PINCFG_ANALOG 0x08000
24+
25+
#define RA_PINCFG(port, pin, psel, opt) \
26+
((((psel)&PSEL_MASK) << PSEL_POS) | (((pin)&PIN_MASK) << PIN_POS) | \
27+
(((port)&PORT_MASK) << PORT_POS) | ((((port) >> 3) & PORT4_MASK) << PORT4_POS) | \
28+
(((opt)&OPT_MASK) << OPT_POS))
29+
30+
#if RA_SOC_PINS >= 40
31+
#define RA_PINCFG__40(port, pin, psel, opt) RA_PINCFG(port, pin, psel, opt)
32+
#endif
33+
34+
#if RA_SOC_PINS >= 48
35+
#define RA_PINCFG__48(port, pin, psel, opt) RA_PINCFG(port, pin, psel, opt)
36+
#endif
37+
38+
#if RA_SOC_PINS >= 64
39+
#define RA_PINCFG__64(port, pin, psel, opt) RA_PINCFG(port, pin, psel, opt)
40+
#endif
41+
42+
#if RA_SOC_PINS >= 100
43+
#define RA_PINCFG_100(port, pin, psel, opt) RA_PINCFG(port, pin, psel, opt)
44+
#endif
45+
46+
#endif
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Copyright (c) 2023 TOKITA Hiroshi <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_SOC_ARM_RENESAS_RA_COMMON_RA_PINCTRL_SOC_H_
8+
#define ZEPHYR_SOC_ARM_RENESAS_RA_COMMON_RA_PINCTRL_SOC_H_
9+
10+
enum {
11+
PmnPFS_PODR_POS,
12+
PmnPFS_PIDR_POS,
13+
PmnPFS_PDR_POS,
14+
PmnPFS_RSV3_POS,
15+
PmnPFS_PCR_POS,
16+
PmnPFS_RSV5_POS,
17+
PmnPFS_NCODR_POS,
18+
PmnPFS_RSV7_POS,
19+
PmnPFS_RSV8_POS,
20+
PmnPFS_RSV9_POS,
21+
PmnPFS_DSCR_POS,
22+
PmnPFS_DSCR1_POS,
23+
PmnPFS_EOR_POS,
24+
PmnPFS_EOF_POS,
25+
PmnPFS_ISEL_POS,
26+
PmnPFS_ASEL_POS,
27+
PmnPFS_PMR_POS,
28+
};
29+
30+
struct pinctrl_ra_pin {
31+
union {
32+
uint32_t config;
33+
struct {
34+
uint8_t PODR: 1;
35+
uint8_t PIDR: 1;
36+
uint8_t PDR: 1;
37+
uint8_t RESERVED3: 1;
38+
uint8_t PCR: 1;
39+
uint8_t RESERVED5: 1;
40+
uint8_t NCODR: 1;
41+
uint8_t RESERVED7: 1;
42+
uint8_t RESERVED8: 1;
43+
uint8_t RESERVED9: 1;
44+
uint8_t DSCR: 2;
45+
uint8_t EOFR: 2;
46+
uint8_t ISEL: 1;
47+
uint8_t ASEL: 1;
48+
uint8_t PMR: 1;
49+
uint8_t RESERVED17: 7;
50+
uint8_t PSEL: 5;
51+
uint8_t RESERVED29: 3;
52+
};
53+
/* Using RESERVED fields for store pin and port info. */
54+
struct {
55+
uint32_t UNUSED0: 17;
56+
uint8_t pin: 4;
57+
uint8_t port: 3;
58+
uint32_t UNUSED24: 5;
59+
uint8_t port4: 3;
60+
};
61+
};
62+
};
63+
64+
typedef struct pinctrl_ra_pin pinctrl_soc_pin_t;
65+
66+
extern int pinctrl_ra_query_config(uint32_t port, uint32_t pin,
67+
struct pinctrl_ra_pin *const pincfg);
68+
69+
/**
70+
* @brief Utility macro to initialize each pin.
71+
*
72+
* @param node_id Node identifier.
73+
* @param prop Property name.
74+
* @param idx Property entry index.
75+
*/
76+
#define Z_PINCTRL_STATE_PIN_INIT(node_id, prop, idx) \
77+
{ \
78+
.config = DT_PROP_BY_IDX(node_id, prop, idx), \
79+
},
80+
81+
/**
82+
* @brief Utility macro to initialize state pins contained in a given property.
83+
*
84+
* @param node_id Node identifier.
85+
* @param prop Property name describing state pins.
86+
*/
87+
#define Z_PINCTRL_STATE_PINS_INIT(node_id, prop) \
88+
{ \
89+
DT_FOREACH_CHILD_VARGS(DT_PHANDLE(node_id, prop), DT_FOREACH_PROP_ELEM, pinmux, \
90+
Z_PINCTRL_STATE_PIN_INIT) \
91+
}
92+
93+
#endif /* ZEPHYR_SOC_ARM_RENESAS_RA_RA6E1_PINCTRL_SOC_H_ */

0 commit comments

Comments
 (0)