Skip to content

Commit 258cc7e

Browse files
ssekar15kartben
authored andcommitted
drivers: pinctrl: mspm0: Add a pinctrl driver for TI MSPM0
Added a pinctrl driver support for MSPM0 Family. Signed-off-by: Saravanan Sekar <[email protected]> Signed-off-by: Jackson Farley <[email protected]>
1 parent 2aebc07 commit 258cc7e

File tree

7 files changed

+251
-0
lines changed

7 files changed

+251
-0
lines changed

drivers/pinctrl/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ zephyr_library_sources_ifdef(CONFIG_PINCTRL_ITE_IT8XXX2 pinctrl_ite_it8xxx2.c)
1616
zephyr_library_sources_ifdef(CONFIG_PINCTRL_NPCX pinctrl_npcx.c)
1717
zephyr_library_sources_ifdef(CONFIG_PINCTRL_NUMICRO pinctrl_numicro.c)
1818
zephyr_library_sources_ifdef(CONFIG_PINCTRL_NRF pinctrl_nrf.c)
19+
zephyr_library_sources_ifdef(CONFIG_PINCTRL_MSPM0 pinctrl_mspm0.c)
1920
zephyr_library_sources_ifdef(CONFIG_PINCTRL_RPI_PICO pinctrl_rpi_pico.c)
2021
zephyr_library_sources_ifdef(CONFIG_PINCTRL_SAM pinctrl_sam.c)
2122
zephyr_library_sources_ifdef(CONFIG_PINCTRL_SAM0 pinctrl_sam0.c)

drivers/pinctrl/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ source "drivers/pinctrl/Kconfig.it8xxx2"
4545
source "drivers/pinctrl/Kconfig.npcx"
4646
source "drivers/pinctrl/Kconfig.numicro"
4747
source "drivers/pinctrl/Kconfig.nrf"
48+
source "drivers/pinctrl/Kconfig.mspm0"
4849
source "drivers/pinctrl/Kconfig.rpi_pico"
4950
source "drivers/pinctrl/Kconfig.sam"
5051
source "drivers/pinctrl/Kconfig.sam0"

drivers/pinctrl/Kconfig.mspm0

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# Copyright (c) 2025 Texas Instruments
3+
4+
config PINCTRL_MSPM0
5+
bool "TI pinctrl MSPM0 driver"
6+
default y
7+
depends on DT_HAS_TI_MSPM0_PINCTRL_ENABLED
8+
help
9+
Enable support for the PINCTRL on TI MSPM0 series.

drivers/pinctrl/pinctrl_mspm0.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 2025 Texas Instruments
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/init.h>
8+
#include <zephyr/drivers/pinctrl.h>
9+
#include <ti/driverlib/dl_gpio.h>
10+
11+
#define DT_DRV_COMPAT ti_mspm0_pinctrl
12+
13+
#define MSPM0_PINCM(pinmux) (pinmux >> 0x10)
14+
#define MSPM0_PIN_FUNCTION(pinmux) (pinmux & 0x3F)
15+
16+
int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins,
17+
uint8_t pin_cnt,
18+
uintptr_t reg)
19+
{
20+
ARG_UNUSED(reg);
21+
22+
uint8_t pin_function;
23+
uint32_t pin_cm;
24+
uint32_t iomux;
25+
26+
for (int i = 0; i < pin_cnt; i++) {
27+
pin_cm = MSPM0_PINCM(pins[i].pinmux);
28+
pin_function = MSPM0_PIN_FUNCTION(pins[i].pinmux);
29+
iomux = pins[i].iomux;
30+
if (pin_function == 0x00) {
31+
DL_GPIO_initPeripheralAnalogFunction(pin_cm);
32+
} else {
33+
DL_GPIO_initPeripheralFunction(pin_cm,
34+
(iomux | pin_function));
35+
}
36+
}
37+
38+
return 0;
39+
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# Copyright (c) 2025 Texas Instruments
2+
# Copyright (c) 2025 Linumiz
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
description: |
6+
TI MSPM0 pinctrl node.
7+
8+
Device pin configuration should be placed in the child nodes of this node.
9+
Populate the 'pinmux' field with a pair consisting of a pin number and its
10+
IO functions.
11+
12+
The node has the 'pinctrl' node label set in your SoC's devicetree,
13+
so you can modify it like this:
14+
15+
&pinctrl {
16+
/* your modifications go here */
17+
};
18+
19+
All device pin configurations should be placed in child nodes of the
20+
'pinctrl' node, as in the i2c0 example shown at the end.
21+
22+
Here is a list of
23+
supported standard pin properties:
24+
25+
- bias-disable: Disable pull-up/down.
26+
- bias-pull-down: Enable pull-down resistor.
27+
- bias-pull-up: Enable pull-up resistor.
28+
- drive-open-drain: Output driver is open-drain.
29+
- drive-open-drain: Output driver is open-source.
30+
- drive-strength: Maximum current that can be sourced from the pin.
31+
- input-enable: enable input.
32+
- ti,invert: enable logical inversion of a digital input or output
33+
- ti,hysteresis: enable hysteresis control on open-drain pins
34+
35+
An example for MSPM0 family, include the chip level pinctrl
36+
DTSI file in the board level DTS:
37+
38+
#include <dt-bindings/pinctrl/mspm0-pinctrl.h>
39+
40+
We want to configure the I2C pins to open drain, with pullup enabled
41+
and input enabled.
42+
43+
To change a pin's pinctrl default properties add a reference to the
44+
pin in the board's DTS file or in the project overlay and set the
45+
properties.
46+
47+
&i2c1 {
48+
pinctrl-0 = <&i2c1_scl_pb2_pull_up &i2c1_sda_pb3_pull_up>;
49+
pinctrl-names = "default";
50+
}
51+
52+
The i2c1_scl_pb2_pull_up corresponds to the following pin configuration in
53+
the board dts file:
54+
55+
&pinctrl {
56+
i2c1_scl_pb2_pull_up: i2c1_scl_pb2_pull_up {
57+
pinmux = <MSP_PINMUX(15,MSPM0_PIN_FUNCTION_4)>;
58+
input-enable;
59+
bias-pull-up;
60+
drive-open-drain;
61+
};
62+
};
63+
64+
Pin pb2 refers to the device pin name that one would see printed on the
65+
launchpad, and the number 15 in the pinmux define refers to the PINCMx.
66+
67+
These are obtained from the device-specific datasheet.
68+
69+
compatible: "ti,mspm0-pinctrl"
70+
71+
include: base.yaml
72+
73+
properties:
74+
reg:
75+
required: true
76+
77+
child-binding:
78+
description: |
79+
This binding gives a base representation of the MSPM0
80+
pins configuration.
81+
82+
include:
83+
- name: pincfg-node.yaml
84+
property-allowlist:
85+
- bias-disable
86+
- bias-pull-down
87+
- bias-pull-up
88+
- bias-high-impedance
89+
- drive-open-drain
90+
- drive-open-source
91+
- drive-strength
92+
- input-enable
93+
94+
properties:
95+
pinmux:
96+
required: true
97+
type: int
98+
description: |
99+
MSPM0 pin's configuration (IO pin, IO function).
100+
101+
drive-strength:
102+
enum:
103+
- 6
104+
- 20
105+
default: 6
106+
description: |
107+
The drive strength controls the maximum output drive strength sunk or
108+
sourced by an I/O pin.
109+
6: max 6 mA (SoC default)
110+
20: max 20 mA on high-drive capable IOs only (HDIO).
111+
112+
ti,invert:
113+
type: boolean
114+
description: |
115+
Enables inversion of the input or output using the internal
116+
inversion capability of the GPIO
117+
118+
ti,hysteresis:
119+
type: boolean
120+
description: |
121+
Enables the hysteresis control for access to CMOS logic
122+
(on open-drain capable pins)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) 2025 Texas Instruments
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef _MSPM0_DT_BINDINGS_PINCTRL_H_
8+
#define _MSPM0_DT_BINDINGS_PINCTRL_H_
9+
10+
#define MSP_PORT_INDEX_BY_NAME(x) ((x == "PORTA") ? 0 : 1)
11+
12+
#define MSPM0_PIN_FUNCTION_ANALOG (0x00000000)
13+
#define MSPM0_PIN_FUNCTION_GPIO (0x00000001)
14+
#define MSPM0_PIN_FUNCTION_2 (0x00000002)
15+
#define MSPM0_PIN_FUNCTION_3 (0x00000003)
16+
#define MSPM0_PIN_FUNCTION_4 (0x00000004)
17+
#define MSPM0_PIN_FUNCTION_5 (0x00000005)
18+
#define MSPM0_PIN_FUNCTION_6 (0x00000006)
19+
#define MSPM0_PIN_FUNCTION_7 (0x00000007)
20+
#define MSPM0_PIN_FUNCTION_8 (0x00000008)
21+
#define MSPM0_PIN_FUNCTION_9 (0x00000009)
22+
#define MSPM0_PIN_FUNCTION_10 (0x0000000A)
23+
24+
/* Creates a concatenation of the correct pin function based on the pin control
25+
* management register offset and the function suffix.
26+
*/
27+
#define MSP_PINMUX(pincm, function) (((pincm - 1) << 0x10) | function)
28+
29+
#endif

soc/ti/mspm0/mspm0g/pinctrl_soc.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 2025 Texas Instruments
3+
* Copyright (c) 2025 Linumiz
4+
*
5+
* SPDX-License-Identifier: Apache-2.0
6+
*/
7+
8+
#ifndef __ZEPHYR_SOC_ARM_TI_MSPM0_M0G_PINCTRL_SOC_H__
9+
#define __ZEPHYR_SOC_ARM_TI_MSPM0_M0G_PINCTRL_SOC_H__
10+
11+
#include <zephyr/devicetree.h>
12+
#include <zephyr/types.h>
13+
#include <zephyr/dt-bindings/pinctrl/mspm0-pinctrl.h>
14+
15+
#define MSP_GPIO_RESISTOR_PULL_DOWN (16)
16+
#define MSP_GPIO_RESISTOR_PULL_UP (17)
17+
#define MSP_GPIO_INPUT_ENABLE (18)
18+
#define MSP_GPIO_HYSTERESIS_ENABLED (19)
19+
#define MSP_GPIO_HIGH_DRIVE (20)
20+
#define MSP_GPIO_OPEN_DRAIN_OUTPUT (25)
21+
#define MSP_GPIO_INVERSION_ENABLED (26)
22+
23+
#define MSP_PINMUX_INIT(node_id) DT_PROP(node_id, pinmux)
24+
25+
#define MSP_PIN_CONTROL_IOMUX_INIT(node_id) \
26+
((DT_PROP(node_id, bias_pull_up) << MSP_GPIO_RESISTOR_PULL_UP) | \
27+
(DT_PROP(node_id, bias_pull_down) << MSP_GPIO_RESISTOR_PULL_DOWN) | \
28+
(DT_PROP(node_id, drive_open_drain) << MSP_GPIO_OPEN_DRAIN_OUTPUT) | \
29+
(DT_ENUM_IDX(node_id, drive_strength) << MSP_GPIO_HIGH_DRIVE) | \
30+
(DT_PROP(node_id, ti_hysteresis) << MSP_GPIO_HYSTERESIS_ENABLED) | \
31+
(DT_PROP(node_id, ti_invert) << MSP_GPIO_INVERSION_ENABLED) | \
32+
(DT_PROP(node_id, input_enable) << MSP_GPIO_INPUT_ENABLE))
33+
34+
typedef struct pinctrl_soc_pin {
35+
/* PINCM register index and pin function */
36+
uint32_t pinmux;
37+
/* IOMUX Pin Control Management (direction, inversion, pullups) */
38+
uint32_t iomux;
39+
} pinctrl_soc_pin_t;
40+
41+
#define Z_PINCTRL_STATE_PIN_INIT(node_id, prop, idx) \
42+
{.pinmux = MSP_PINMUX_INIT(DT_PROP_BY_IDX(node_id, prop, idx)), \
43+
.iomux = MSP_PIN_CONTROL_IOMUX_INIT(DT_PROP_BY_IDX(node_id, prop, idx))},
44+
45+
#define Z_PINCTRL_STATE_PINS_INIT(node_id, prop) \
46+
{ \
47+
DT_FOREACH_PROP_ELEM(node_id, prop, Z_PINCTRL_STATE_PIN_INIT) \
48+
}
49+
50+
#endif /* __ZEPHYR_SOC_ARM_TI_MSPM0_M0G_PINCTRL_SOC_H__ */

0 commit comments

Comments
 (0)