Skip to content

Commit afd1274

Browse files
wearyzennordicjm
authored andcommitted
[nrf fromtree] pinctrl: add support for mps4
Add MPS4 pinctrl support by referring to `mps4/common/partition/platform_base_address.h` from TF-M's main branch. Signed-off-by: Sudan Landge <[email protected]> (cherry picked from commit 5a3c494)
1 parent d8a80b8 commit afd1274

File tree

10 files changed

+299
-0
lines changed

10 files changed

+299
-0
lines changed

boards/arm/mps4/mps4-pinctrl.dtsi

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright 2025 Arm Limited and/or its affiliates <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/dt-bindings/pinctrl/arm-mps4-pinctrl.h>
8+
9+
&pinctrl {
10+
/omit-if-no-ref/ uart3_default: uart3_default {
11+
group1 {
12+
pinmux = <UART3_TXD_EXP>;
13+
};
14+
15+
group2 {
16+
pinmux = <UART3_RXD_EXP>;
17+
input-enable;
18+
};
19+
};
20+
21+
/omit-if-no-ref/ uart4_default: uart4_default {
22+
group1 {
23+
pinmux = <UART4_TXD_EXP>;
24+
};
25+
26+
group2 {
27+
pinmux = <UART4_RXD_EXP>;
28+
input-enable;
29+
};
30+
};
31+
32+
/omit-if-no-ref/ spi3_default: spi3_default {
33+
group1 {
34+
pinmux = <SPI3_SS_EXP>, <SPI3_MOSI_EXP>,
35+
<SPI3_SCK_EXP>;
36+
};
37+
38+
group2 {
39+
pinmux = <SPI3_MISO_EXP>;
40+
input-enable;
41+
};
42+
};
43+
44+
/omit-if-no-ref/ spi4_default: spi4_default {
45+
group1 {
46+
pinmux = <SPI4_SS_EXP>, <SPI4_MOSI_EXP>, <SPI4_SCK_EXP>;
47+
};
48+
49+
group2 {
50+
pinmux = <SPI4_MISO_EXP>;
51+
input-enable;
52+
};
53+
};
54+
55+
/omit-if-no-ref/ sbcon2_default: sbcon2_default {
56+
group1 {
57+
pinmux = <SBCON2_SDA_EXP>, <SBCON2_SCL_EXP>;
58+
input-enable;
59+
};
60+
};
61+
62+
/omit-if-no-ref/ sbcon3_default: sbcon3_default {
63+
group1 {
64+
pinmux = <SBCON3_SDA_EXP>, <SBCON3_SCL_EXP>;
65+
input-enable;
66+
};
67+
};
68+
};

boards/arm/mps4/mps4_common.dtsi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,5 @@
117117
&nvic {
118118
arm,num-irq-priority-bits = <3>;
119119
};
120+
121+
#include "mps4-pinctrl.dtsi"

boards/arm/mps4/mps4_common_soc_peripheral.dtsi

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ uart3: uart@8206000 {
187187
interrupt-names = "tx", "rx";
188188
clocks = <&sysclk>;
189189
current-speed = <115200>;
190+
pinctrl-0 = <&uart3_default>;
191+
pinctrl-names = "default";
190192
};
191193

192194
uart4: uart@8207000 {
@@ -196,6 +198,8 @@ uart4: uart@8207000 {
196198
interrupt-names = "tx", "rx";
197199
clocks = <&sysclk>;
198200
current-speed = <115200>;
201+
pinctrl-0 = <&uart4_default>;
202+
pinctrl-names = "default";
199203
};
200204

201205
uart5: uart@8208000 {
@@ -207,3 +211,8 @@ uart5: uart@8208000 {
207211
clocks = <&sysclk>;
208212
current-speed = <115200>;
209213
};
214+
215+
pinctrl: pinctrl {
216+
compatible = "arm,mps4-pinctrl";
217+
status = "okay";
218+
};

drivers/pinctrl/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ zephyr_library_sources_ifdef(CONFIG_PINCTRL_TELINK_B91 pinctrl_b91.c)
88
zephyr_library_sources_ifdef(CONFIG_PINCTRL_AMBIQ pinctrl_ambiq.c)
99
zephyr_library_sources_ifdef(CONFIG_PINCTRL_ARM_MPS2 pinctrl_arm_mps2.c)
1010
zephyr_library_sources_ifdef(CONFIG_PINCTRL_ARM_MPS3 pinctrl_arm_mps3.c)
11+
zephyr_library_sources_ifdef(CONFIG_PINCTRL_ARM_MPS4 pinctrl_arm_mps4.c)
1112
zephyr_library_sources_ifdef(CONFIG_PINCTRL_ARM_V2M_BEETLE pinctrl_arm_v2m_beetle.c)
1213
zephyr_library_sources_ifdef(CONFIG_PINCTRL_BFLB pinctrl_bflb.c)
1314
zephyr_library_sources_ifdef(CONFIG_PINCTRL_GD32_AF pinctrl_gd32_af.c)

drivers/pinctrl/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ source "drivers/pinctrl/Kconfig.bflb"
3939
source "drivers/pinctrl/Kconfig.ambiq"
4040
source "drivers/pinctrl/Kconfig.arm_mps2"
4141
source "drivers/pinctrl/Kconfig.arm_mps3"
42+
source "drivers/pinctrl/Kconfig.arm_mps4"
4243
source "drivers/pinctrl/Kconfig.arm_v2m_beetle"
4344
source "drivers/pinctrl/Kconfig.gd32"
4445
source "drivers/pinctrl/Kconfig.it8xxx2"

drivers/pinctrl/Kconfig.arm_mps4

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright 2025 Arm Limited and/or its affiliates <[email protected]>
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config PINCTRL_ARM_MPS4
5+
bool "Arm MPS4 pin controller driver"
6+
default y
7+
depends on DT_HAS_ARM_MPS4_PINCTRL_ENABLED
8+
help
9+
Arm MPS4 pinctrl driver

drivers/pinctrl/pinctrl_arm_mps4.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2025 Arm Limited and/or its affiliates <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include "zephyr/device.h"
8+
#include "zephyr/drivers/gpio.h"
9+
#include <zephyr/drivers/pinctrl.h>
10+
#include <zephyr/devicetree/gpio.h>
11+
#include <zephyr/drivers/gpio/gpio_cmsdk_ahb.h>
12+
13+
static const struct device *const gpio_ports[] = {DEVICE_DT_GET_OR_NULL(DT_NODELABEL(gpio0)),
14+
DEVICE_DT_GET_OR_NULL(DT_NODELABEL(gpio1))};
15+
16+
static int pinctrl_configure_pin(const pinctrl_soc_pin_t *pin)
17+
{
18+
uint32_t flags = pin->input_enable ? GPIO_INPUT : GPIO_OUTPUT;
19+
20+
/* Each gpio has 16 pins, so divide by 16 to get specific gpio*/
21+
const struct device *gpio_dev = gpio_ports[pin->pin_num >> 4];
22+
23+
return cmsdk_ahb_gpio_config(gpio_dev, pin->pin_num % 16, flags);
24+
}
25+
26+
int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt, uintptr_t reg)
27+
{
28+
ARG_UNUSED(reg);
29+
for (uint8_t i = 0U; i < pin_cnt; i++) {
30+
if (pinctrl_configure_pin(&pins[i]) == -ENOTSUP) {
31+
return -ENOTSUP;
32+
}
33+
}
34+
35+
return 0;
36+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Copyright 2025 Arm Limited and/or its affiliates <[email protected]>
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: |
5+
The Arm Mps4 pin controller is a node responsible for controlling
6+
pin function selection and pin properties, such as routing a UART3 TX
7+
to pin 1.
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+
&pinctrl {
20+
/* configuration for the usart0 "default" state */
21+
uart3_default: uart3_default {
22+
/* group 1 */
23+
group1 {
24+
/* configure P1 as UART3 TX */
25+
pinmux = <UART3_TXD_EXP>;
26+
};
27+
/* group 2 */
28+
group2 {
29+
/* configure P0 as UART3 RX */
30+
pinmux = <UART3_TXD_EXP>;
31+
/* enable input on pin 1 */
32+
input-enable;
33+
};
34+
};
35+
};
36+
37+
The 'uart3_default' child node encodes the pin configurations for a
38+
particular state of a device; in this case, the default (that is, active)
39+
state.
40+
41+
As shown, pin configurations are organized in groups within each child node.
42+
Each group can specify a list of pin function selections in the 'pinmux'
43+
property. Here is a list of supported standard pin properties:
44+
- input-enable
45+
46+
A group can also specify shared pin properties common to all the specified
47+
pins, such as the 'input-enable' property in group 2.
48+
49+
To link pin configurations with a device, use a pinctrl-N property for some
50+
number N, like this example you could place in your board's DTS file:
51+
52+
#include "board-pinctrl.dtsi"
53+
54+
&uart3 {
55+
pinctrl-0 = <&uart3_default>;
56+
pinctrl-1 = <&uart3_sleep>;
57+
pinctrl-names = "default", "sleep";
58+
};
59+
60+
61+
compatible: "arm,mps4-pinctrl"
62+
63+
include: base.yaml
64+
65+
child-binding:
66+
description: |
67+
Definitions for a pinctrl state.
68+
child-binding:
69+
70+
include:
71+
- name: pincfg-node.yaml
72+
property-allowlist:
73+
- input-enable
74+
75+
properties:
76+
pinmux:
77+
required: true
78+
type: array
79+
description: |
80+
An array of pins sharing the same group properties. Each
81+
element of the array is an integer constructed from the
82+
pin number and the alternative function of the pin.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2025 Arm Limited and/or its affiliates <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#define MPS4_ALT_FUNC_POS 0
8+
#define MPS4_ALT_FUNC_MASK 0x7
9+
10+
#define MPS4_EXP_NUM_POS 3
11+
#define MPS4_EXP_NUM_MASK 0x1F8
12+
13+
#define MPS4_PINCTRL_FUNC_UART 0
14+
#define MPS4_PINCTRL_FUNC_GPIO 1
15+
#define MPS4_PINCTRL_FUNC_I2C 2
16+
#define MPS4_PINCTRL_FUNC_SPI 3
17+
18+
#define MPS4_PINMUX(alt_func, exp_num) (exp_num << MPS4_EXP_NUM_POS | \
19+
alt_func << MPS4_ALT_FUNC_POS)
20+
21+
/* GPIO 0 */
22+
#define UART3_RXD_EXP MPS4_PINMUX(MPS4_PINCTRL_FUNC_UART, 0)
23+
#define UART3_TXD_EXP MPS4_PINMUX(MPS4_PINCTRL_FUNC_UART, 1)
24+
#define SPI3_SS_EXP MPS4_PINMUX(MPS4_PINCTRL_FUNC_SPI, 10)
25+
#define SPI3_MOSI_EXP MPS4_PINMUX(MPS4_PINCTRL_FUNC_SPI, 11)
26+
#define SPI3_MISO_EXP MPS4_PINMUX(MPS4_PINCTRL_FUNC_SPI, 12)
27+
#define SPI3_SCK_EXP MPS4_PINMUX(MPS4_PINCTRL_FUNC_SPI, 13)
28+
#define SBCON2_SDA_EXP MPS4_PINMUX(MPS4_PINCTRL_FUNC_I2C, 14)
29+
#define SBCON2_SCL_EXP MPS4_PINMUX(MPS4_PINCTRL_FUNC_I2C, 15)
30+
31+
32+
/* GPIO 1 */
33+
#define UART4_RXD_EXP MPS4_PINMUX(MPS4_PINCTRL_FUNC_UART, 16)
34+
#define UART4_TXD_EXP MPS4_PINMUX(MPS4_PINCTRL_FUNC_UART, 17)
35+
#define SPI4_SS_EXP MPS4_PINMUX(MPS4_PINCTRL_FUNC_SPI, 26)
36+
#define SPI4_MOSI_EXP MPS4_PINMUX(MPS4_PINCTRL_FUNC_SPI, 27)
37+
#define SPI4_MISO_EXP MPS4_PINMUX(MPS4_PINCTRL_FUNC_SPI, 28)
38+
#define SPI4_SCK_EXP MPS4_PINMUX(MPS4_PINCTRL_FUNC_SPI, 29)
39+
#define SBCON3_SDA_EXP MPS4_PINMUX(MPS4_PINCTRL_FUNC_I2C, 30)
40+
#define SBCON3_SCL_EXP MPS4_PINMUX(MPS4_PINCTRL_FUNC_I2C, 31)

soc/arm/mps4/pinctrl_soc.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2025 Arm Limited and/or its affiliates <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/dt-bindings/pinctrl/arm-mps4-pinctrl.h>
8+
9+
/**
10+
* @brief Type to hold a pin's pinctrl configuration.
11+
*/
12+
struct mps4_pinctrl_soc_pin {
13+
/** Pin number 0..52 */
14+
uint32_t pin_num : 6;
15+
/** Alternative function (UART, SPI, etc.) */
16+
uint32_t alt_func : 3;
17+
/** Enable the pin as an input */
18+
uint32_t input_enable : 1;
19+
};
20+
21+
typedef struct mps4_pinctrl_soc_pin pinctrl_soc_pin_t;
22+
23+
/**
24+
* @brief Utility macro to initialize each pin.
25+
*
26+
* @param node_id Node identifier.
27+
* @param prop Property name.
28+
* @param idx Property entry index.
29+
*/
30+
#define Z_PINCTRL_STATE_PIN_INIT(node_id, prop, idx) \
31+
{ \
32+
MPS4_GET_PIN_NUM(DT_PROP_BY_IDX(node_id, prop, idx)), \
33+
MPS4_GET_PIN_ALT_FUNC(DT_PROP_BY_IDX(node_id, prop, idx)), \
34+
DT_PROP(node_id, input_enable), \
35+
},
36+
37+
/**
38+
* @brief Utility macro to initialize state pins contained in a given property.
39+
*
40+
* @param node_id Node identifier.
41+
* @param prop Property name describing state pins.
42+
*/
43+
#define Z_PINCTRL_STATE_PINS_INIT(node_id, prop) \
44+
{DT_FOREACH_CHILD_VARGS(DT_PHANDLE(node_id, prop), \
45+
DT_FOREACH_PROP_ELEM, pinmux, \
46+
Z_PINCTRL_STATE_PIN_INIT)}
47+
48+
#define MPS4_GET_PIN_NUM(pinctrl) \
49+
(((pinctrl) >> MPS4_EXP_NUM_POS) & MPS4_EXP_NUM_MASK)
50+
#define MPS4_GET_PIN_ALT_FUNC(pinctrl) \
51+
(((pinctrl) >> MPS4_ALT_FUNC_POS) & MPS4_ALT_FUNC_MASK)

0 commit comments

Comments
 (0)