Skip to content

Commit ea55fb6

Browse files
committed
soc: arm64: add support of pinctrl for r8a779f
Add support of pinctrl for r8a779f. Signed-off-by: Mykola Kvach <[email protected]>
1 parent 9180790 commit ea55fb6

File tree

6 files changed

+235
-0
lines changed

6 files changed

+235
-0
lines changed

drivers/pinctrl/pfc_rcar.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,20 @@
1616
DEVICE_MMIO_TOPLEVEL_STATIC(pfc, DT_DRV_INST(0));
1717

1818
#define PFC_REG_BASE DEVICE_MMIO_TOPLEVEL_GET(pfc)
19+
20+
#ifdef CONFIG_SOC_R8A779F
21+
/*
22+
* todo: add support of pin groups,the next registers
23+
* offset is for a group 0
24+
*/
25+
#define PFC_RCAR_PMMR 0x0
26+
#define PFC_RCAR_GPSR 0x040
27+
#define PFC_RCAR_IPSR 0x060
28+
#else
1929
#define PFC_RCAR_PMMR 0x0
2030
#define PFC_RCAR_GPSR 0x100
2131
#define PFC_RCAR_IPSR 0x200
32+
#endif
2233

2334
/*
2435
* Each drive step is either encoded in 2 or 3 bits.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (c) 2023 EPAM Systems
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_PINCTRL_RENESAS_PINCTRL_R8A779F_H_
7+
#define ZEPHYR_INCLUDE_DT_BINDINGS_PINCTRL_RENESAS_PINCTRL_R8A779F_H_
8+
9+
#include "pinctrl-rcar-common.h"
10+
11+
/* Pins declaration */
12+
#define PIN_NONE -1
13+
14+
/*
15+
* note: we don't need ipsr configuration for sd/mmc pins,
16+
* they don't have alternative functions.
17+
*/
18+
#define PIN_SD_WP RCAR_GP_PIN(1, 24)
19+
#define PIN_SD_CD RCAR_GP_PIN(1, 23)
20+
#define PIN_MMC_SD_CMD RCAR_GP_PIN(1, 22)
21+
#define PIN_MMC_DS RCAR_GP_PIN(1, 20)
22+
#define PIN_MMC_D7 RCAR_GP_PIN(1, 21)
23+
#define PIN_MMC_D6 RCAR_GP_PIN(1, 19)
24+
#define PIN_MMC_D5 RCAR_GP_PIN(1, 17)
25+
#define PIN_MMC_D4 RCAR_GP_PIN(1, 18)
26+
#define PIN_MMC_SD_D3 RCAR_GP_PIN(1, 16)
27+
#define PIN_MMC_SD_D2 RCAR_GP_PIN(1, 15)
28+
#define PIN_MMC_SD_D1 RCAR_GP_PIN(1, 14)
29+
#define PIN_MMC_SD_D0 RCAR_GP_PIN(1, 13)
30+
#define PIN_MMC_SD_CLK RCAR_GP_PIN(1, 12)
31+
32+
#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_PINCTRL_RENESAS_PINCTRL_R8A779F_H_ */
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Copyright (c) 2023 EPAM Systems
22
# SPDX-License-Identifier: Apache-2.0
33

4+
zephyr_library_sources_ifdef(CONFIG_SOC_R8A779F pfc_r8a779f.c)
45
zephyr_library_sources_ifdef(CONFIG_ARM_MMU mmu_regions.c)

soc/arm64/renesas_rcar/gen4/Kconfig.defconfig.series

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@ config NUM_IRQS
1212
int
1313
default 500
1414

15+
config PINCTRL
16+
default y
17+
1518
endif # SOC_SERIES_RCAR_GEN4
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright (c) 2023 EPAM Systems
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
*/
7+
8+
#include "pinctrl_soc.h"
9+
#include <zephyr/dt-bindings/pinctrl/renesas/pinctrl-r8a779f.h>
10+
11+
const struct pfc_drive_reg pfc_drive_regs[] = {
12+
/* DRV1CTRL1 */
13+
{ 0x884, {
14+
{ PIN_MMC_SD_D2, 28, 3 },
15+
{ PIN_MMC_SD_D1, 24, 3 },
16+
{ PIN_MMC_SD_D0, 20, 3 },
17+
{ PIN_MMC_SD_CLK, 16, 3 },
18+
} },
19+
/* DRV2CTRL1 */
20+
{ 0x888, {
21+
{ PIN_SD_CD, 28, 3 },
22+
{ PIN_MMC_SD_CMD, 24, 3 },
23+
{ PIN_MMC_D7, 20, 3 },
24+
{ PIN_MMC_DS, 16, 3 },
25+
{ PIN_MMC_D6, 12, 3 },
26+
{ PIN_MMC_D4, 8, 3 },
27+
{ PIN_MMC_D5, 4, 3 },
28+
{ PIN_MMC_SD_D3, 0, 3 },
29+
} },
30+
/* DRV3CTRL1 */
31+
{ 0x88c, {
32+
{ PIN_SD_WP, 0, 3 },
33+
} },
34+
{ },
35+
};
36+
37+
#define PFC_BIAS_REG(r1, r2) \
38+
.puen = r1, \
39+
.pud = r2, \
40+
.pins =
41+
42+
const struct pfc_bias_reg pfc_bias_regs[] = {
43+
/* PUEN1, PUD1 */
44+
{ PFC_BIAS_REG(0x8c0, 0x8e0) {
45+
[0 ... 11] = PIN_NONE,
46+
[12] = PIN_MMC_SD_CLK,
47+
[13] = PIN_MMC_SD_D0,
48+
[14] = PIN_MMC_SD_D1,
49+
[15] = PIN_MMC_SD_D2,
50+
[16] = PIN_MMC_SD_D3,
51+
[17] = PIN_MMC_D5,
52+
[18] = PIN_MMC_D4,
53+
[19] = PIN_MMC_D6,
54+
[20] = PIN_MMC_DS,
55+
[21] = PIN_MMC_D7,
56+
[22] = PIN_MMC_SD_CMD,
57+
[23] = PIN_SD_CD,
58+
[24] = PIN_SD_WP,
59+
[25 ... 31] = PIN_NONE,
60+
} },
61+
{ /* sentinel */ },
62+
};
63+
64+
const struct pfc_bias_reg *pfc_rcar_get_bias_regs(void)
65+
{
66+
return pfc_bias_regs;
67+
}
68+
const struct pfc_drive_reg *pfc_rcar_get_drive_regs(void)
69+
{
70+
return pfc_drive_regs;
71+
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* Copyright (c) 2023 EPAM Systems
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
*/
7+
8+
#ifndef ZEPHYR_SOC_ARM_RENESAS_RCAR_GEN4_PINCTRL_SOC_H_
9+
#define ZEPHYR_SOC_ARM_RENESAS_RCAR_GEN4_PINCTRL_SOC_H_
10+
11+
#include <zephyr/devicetree.h>
12+
#include <zephyr/dt-bindings/pinctrl/renesas/pinctrl-rcar-common.h>
13+
#include <stdint.h>
14+
#include <zephyr/sys/util_macro.h>
15+
16+
struct rcar_pin_func {
17+
uint8_t bank:5; /* bank number 0 - 18 */
18+
uint8_t shift:5; /* bit shift 0 - 28 */
19+
uint8_t func:4; /* choice from 0x0 to 0xF */
20+
};
21+
/** Pull-up, pull-down, or bias disable is requested */
22+
#define RCAR_PIN_FLAGS_PULL_SET BIT(0)
23+
/** Performs on/off control of the pull resistors */
24+
#define RCAR_PIN_FLAGS_PUEN BIT(1)
25+
/** Select pull-up resistor if set pull-down otherwise */
26+
#define RCAR_PIN_FLAGS_PUD BIT(2)
27+
/** Alternate function for the pin is requested */
28+
#define RCAR_PIN_FLAGS_FUNC_SET BIT(3)
29+
30+
#define RCAR_PIN_PULL_UP (RCAR_PIN_FLAGS_PULL_SET | RCAR_PIN_FLAGS_PUEN | RCAR_PIN_FLAGS_PUD)
31+
#define RCAR_PIN_PULL_DOWN (RCAR_PIN_FLAGS_PULL_SET | RCAR_PIN_FLAGS_PUEN)
32+
#define RCAR_PIN_PULL_DISABLE RCAR_PIN_FLAGS_PULL_SET
33+
34+
/** Type for R-Car pin. */
35+
typedef struct pinctrl_soc_pin {
36+
uint16_t pin;
37+
struct rcar_pin_func func;
38+
uint8_t flags;
39+
uint8_t drive_strength;
40+
} pinctrl_soc_pin_t;
41+
42+
#define RCAR_IPSR(node_id) DT_PROP_BY_IDX(node_id, pin, 1)
43+
#define RCAR_HAS_IPSR(node_id) DT_PROP_HAS_IDX(node_id, pin, 1)
44+
45+
/* Offsets are defined in dt-bindings pinctrl-rcar-common.h */
46+
#define RCAR_PIN_FUNC(node_id) \
47+
{ \
48+
((RCAR_IPSR(node_id) >> 10U) & 0x1FU), \
49+
((RCAR_IPSR(node_id) >> 4U) & 0x1FU), \
50+
((RCAR_IPSR(node_id) & 0xFU)) \
51+
}
52+
53+
#define RCAR_PIN_FLAGS(node_id) \
54+
DT_PROP(node_id, bias_pull_up) * RCAR_PIN_PULL_UP | \
55+
DT_PROP(node_id, bias_pull_down) * RCAR_PIN_PULL_DOWN | \
56+
DT_PROP(node_id, bias_disable) * RCAR_PIN_PULL_DISABLE | \
57+
RCAR_HAS_IPSR(node_id) * RCAR_PIN_FLAGS_FUNC_SET
58+
59+
#define RCAR_DT_PIN(node_id) \
60+
{ \
61+
.pin = DT_PROP_BY_IDX(node_id, pin, 0), \
62+
.func = COND_CODE_1(RCAR_HAS_IPSR(node_id), \
63+
(RCAR_PIN_FUNC(node_id)), ({0})), \
64+
.flags = RCAR_PIN_FLAGS(node_id), \
65+
.drive_strength = \
66+
COND_CODE_1(DT_NODE_HAS_PROP(node_id, drive_strength), \
67+
(DT_PROP(node_id, drive_strength)), (0)), \
68+
},
69+
70+
/**
71+
* @brief Utility macro to initialize each pin.
72+
*
73+
* @param node_id Node identifier.
74+
* @param state_prop State property name.
75+
* @param idx State property entry index.
76+
*/
77+
#define Z_PINCTRL_STATE_PIN_INIT(node_id, state_prop, idx) \
78+
RCAR_DT_PIN(DT_PROP_BY_IDX(node_id, state_prop, idx))
79+
80+
/**
81+
* @brief Utility macro to initialize state pins contained in a given property.
82+
*
83+
* @param node_id Node identifier.
84+
* @param prop Property name describing state pins.
85+
*/
86+
#define Z_PINCTRL_STATE_PINS_INIT(node_id, prop) \
87+
{ DT_FOREACH_PROP_ELEM(node_id, prop, Z_PINCTRL_STATE_PIN_INIT) }
88+
89+
struct pfc_drive_reg_field {
90+
uint16_t pin;
91+
uint8_t offset;
92+
uint8_t size;
93+
};
94+
95+
struct pfc_drive_reg {
96+
uint32_t reg;
97+
const struct pfc_drive_reg_field fields[8];
98+
};
99+
100+
struct pfc_bias_reg {
101+
uint32_t puen; /** Pull-enable or pull-up control register */
102+
uint32_t pud; /** Pull-up/down or pull-down control register */
103+
const uint16_t pins[32];
104+
};
105+
106+
const struct pfc_bias_reg *pfc_rcar_get_bias_regs(void);
107+
const struct pfc_drive_reg *pfc_rcar_get_drive_regs(void);
108+
109+
/**
110+
* @brief Utility macro to check if a pin is GPIO capable
111+
*
112+
* @param pin
113+
* @return true if pin is GPIO capable false otherwise
114+
*/
115+
#define RCAR_IS_GP_PIN(pin) (pin < PIN_NOGPSR_START)
116+
117+
#endif /* ZEPHYR_SOC_ARM_RENESAS_RCAR_GEN4_PINCTRL_SOC_H_ */

0 commit comments

Comments
 (0)