Skip to content

Commit 6400e3f

Browse files
jbylickihenrikbrixandersen
authored andcommitted
drivers: pinctrl: Add ZynqMP / Mercury XU pinctrl support
Add a pinctrl driver for the ZynqMP SoC and the Mercury XU board powered by it. Signed-off-by: Jan Bylicki <[email protected]>
1 parent c6f21b2 commit 6400e3f

File tree

8 files changed

+151
-0
lines changed

8 files changed

+151
-0
lines changed

drivers/pinctrl/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ zephyr_library_sources_ifdef(CONFIG_PINCTRL_ESP32 pinctrl_esp32.c)
2626
zephyr_library_sources_ifdef(CONFIG_PINCTRL_RV32M1 pinctrl_rv32m1.c)
2727
zephyr_library_sources_ifdef(CONFIG_PINCTRL_INFINEON_CAT1 pinctrl_ifx_cat1.c)
2828
zephyr_library_sources_ifdef(CONFIG_PINCTRL_XLNX_ZYNQ pinctrl_xlnx_zynq.c)
29+
zephyr_library_sources_ifdef(CONFIG_PINCTRL_XLNX_ZYNQMP pinctrl_xlnx_zynqmp.c)
2930
zephyr_library_sources_ifdef(CONFIG_PINCTRL_SMARTBOND pinctrl_smartbond.c)
3031
zephyr_library_sources_ifdef(CONFIG_PINCTRL_XMC4XXX pinctrl_xmc4xxx.c)
3132
zephyr_library_sources_ifdef(CONFIG_PINCTRL_NXP_S32 pinctrl_nxp_s32.c)

drivers/pinctrl/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,6 @@ source "drivers/pinctrl/Kconfig.numaker"
6666
source "drivers/pinctrl/Kconfig.eos_s3"
6767
source "drivers/pinctrl/Kconfig.ra"
6868
source "drivers/pinctrl/Kconfig.rzt2m"
69+
source "drivers/pinctrl/Kconfig.zynqmp"
6970

7071
endif # PINCTRL

drivers/pinctrl/Kconfig.zynqmp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) 2024 Antmicro <www.antmicro.com>
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config PINCTRL_XLNX_ZYNQMP
5+
bool "Xilinx ZynqMP pin controller driver"
6+
default y
7+
depends on DT_HAS_XLNX_PINCTRL_ZYNQMP_ENABLED
8+
help
9+
Enable the Xilinx ZynqMP processor system MIO pin controller driver.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (c) 2024 Antmicro <www.antmicro.com>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/dt-bindings/pinctrl/pinctrl-zynqmp.h>
8+
#include <zephyr/logging/log.h>
9+
#include "pinctrl_soc.h"
10+
11+
LOG_MODULE_REGISTER(pinctrl_xlnx_zynqmp, CONFIG_PINCTRL_LOG_LEVEL);
12+
13+
#define DT_DRV_COMPAT xlnx_pinctrl_zynqmp
14+
15+
static mm_reg_t base = DT_INST_REG_ADDR(0);
16+
static uint8_t mio_pin_offset = 0x04;
17+
18+
int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt, uintptr_t reg)
19+
{
20+
for (uint8_t i = 0U; i < pin_cnt; i++) {
21+
uint32_t sel = 0;
22+
23+
switch (pins[i].func) {
24+
case UART_FUNCTION: {
25+
sel = UARTX_SEL;
26+
break;
27+
}
28+
29+
default: {
30+
LOG_ERR("Unsupported function enum was selected");
31+
break;
32+
}
33+
}
34+
sys_write32(sel, base + mio_pin_offset * pins[i].pin);
35+
}
36+
37+
return 0;
38+
}

dts/arm/xilinx/zynqmp.dtsi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111

1212
/ {
1313
soc {
14+
pinctrl: pinctrl@ff180000 {
15+
reg = <0xff180000 0xc80>;
16+
compatible = "xlnx,pinctrl-zynqmp";
17+
};
1418
flash0: flash@c0000000 {
1519
compatible = "soc-nv-flash";
1620
reg = <0xc0000000 DT_SIZE_M(32)>;
@@ -271,4 +275,5 @@
271275
};
272276
};
273277
};
278+
274279
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright (c) 2024 Antmicro <www.antmicro.com>
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: |
5+
Xilinx ZynqMP SoC pinctrl node. It allows configuration of pin assignments
6+
for the supported peripherals.
7+
8+
See Zynq UltraScale+ Devices Register Reference (UG1087) for details regarding
9+
valid pin assignments
10+
compatible: "xlnx,pinctrl-zynqmp"
11+
12+
include: base.yaml
13+
14+
child-binding:
15+
description: |
16+
Definitions for a pinctrl state.
17+
child-binding:
18+
19+
include:
20+
- name: pincfg-node.yaml
21+
22+
properties:
23+
pinmux:
24+
required: true
25+
type: array
26+
description: |
27+
Pin assignments for the selected group
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright (c) 2024 Antmicro <www.antmicro.com>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_PINCTRL_ZYNQMP_PINCTRL_H_
8+
#define ZEPHYR_INCLUDE_DT_BINDINGS_PINCTRL_ZYNQMP_PINCTRL_H_
9+
10+
#define UART_FUNCTION 0x1
11+
12+
#define UART0_RX_38 (38U | (UART_FUNCTION << 8))
13+
#define UART0_TX_39 (39U | (UART_FUNCTION << 8))
14+
15+
16+
#endif
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) 2024 Antmicro <www.antmicro.com>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_SOC_ARM_XLNX_ZYNQMP_SOC_PINCTRL_H_
8+
#define ZEPHYR_SOC_ARM_XLNX_ZYNQMP_SOC_PINCTRL_H_
9+
10+
#include <zephyr/devicetree.h>
11+
#include <zephyr/sys/util.h>
12+
#include <zephyr/types.h>
13+
14+
#define MIO_L0_SEL BIT(1)
15+
#define MIO_L1_SEL BIT(2)
16+
#define MIO_L2_SEL GENMASK(4, 3)
17+
#define MIO_L3_SEL GENMASK(7, 5)
18+
19+
/* All other selectors should be zeroed and FIELD_PREP does that */
20+
#define UARTX_SEL FIELD_PREP(MIO_L3_SEL, 6)
21+
22+
/*
23+
* Each peripheral PINCTRL mask is defined as such:
24+
* [7 ... 0] MIO register number
25+
* [15 ... 8] Function, mapped as:
26+
* 1 - UART
27+
*
28+
* The function numbers serve as an enumerator in the pinctrl driver
29+
* and the defines controling those are listed in `pinctrl-zynqmp.h`.
30+
* Currently, one function for UART is specified and subsequent ones
31+
* can be added when the need arises.
32+
*/
33+
34+
typedef struct pinctrl_soc_pin_t {
35+
uint32_t pin;
36+
uint32_t func;
37+
} pinctrl_soc_pin_t;
38+
39+
40+
#define ZYNQMP_GET_PIN(pinctrl) (pinctrl & 0xff)
41+
#define ZYNQMP_GET_FUNC(pinctrl) ((pinctrl >> 8) & 0xff)
42+
43+
#define Z_PINCTRL_STATE_PIN_INIT(node_id, prop, idx) \
44+
{ \
45+
.pin = ZYNQMP_GET_PIN(DT_PROP_BY_IDX(node_id, prop, idx)), \
46+
.func = ZYNQMP_GET_FUNC(DT_PROP_BY_IDX(node_id, prop, idx)), \
47+
},
48+
49+
#define Z_PINCTRL_STATE_PINS_INIT(node_id, prop) { \
50+
DT_FOREACH_CHILD_VARGS(DT_PHANDLE(node_id, prop), \
51+
DT_FOREACH_PROP_ELEM, pinmux, \
52+
Z_PINCTRL_STATE_PIN_INIT)}
53+
54+
#endif

0 commit comments

Comments
 (0)