Skip to content

Commit f8c45ac

Browse files
committed
drivers: added pinctrl driver for MSPM0
added pinctrl driver support for MSPM0 Family Signed-off-by: Jackson Farley <[email protected]>
1 parent 64c7cf7 commit f8c45ac

File tree

6 files changed

+181
-13
lines changed

6 files changed

+181
-13
lines changed

drivers/pinctrl/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ zephyr_library_sources_ifdef(CONFIG_PINCTRL_SILABS_DBUS pinctrl_silabs_dbus.c)
3333
zephyr_library_sources_ifdef(CONFIG_PINCTRL_TI_K3 pinctrl_ti_k3.c)
3434
zephyr_library_sources_ifdef(CONFIG_PINCTRL_EMSDP pinctrl_emsdp.c)
3535
zephyr_library_sources_ifdef(CONFIG_PINCTRL_TI_CC32XX pinctrl_ti_cc32xx.c)
36+
zephyr_library_sources_ifdef(CONFIG_PINCTRL_MSPM0 pinctrl_mspm0.c)
3637
zephyr_library_sources_ifdef(CONFIG_PINCTRL_NUMAKER pinctrl_numaker.c)
3738
zephyr_library_sources_ifdef(CONFIG_PINCTRL_QUICKLOGIC_EOS_S3 pinctrl_eos_s3.c)
3839
zephyr_library_sources_ifdef(CONFIG_PINCTRL_MCI_IO_MUX pinctrl_mci_io_mux.c)

drivers/pinctrl/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ source "drivers/pinctrl/Kconfig.nxp_s32"
5959
source "drivers/pinctrl/Kconfig.gecko"
6060
source "drivers/pinctrl/Kconfig.silabs_dbus"
6161
source "drivers/pinctrl/Kconfig.ti_k3"
62+
source "drivers/pinctrl/Kconfig.mspm0"
6263
source "drivers/pinctrl/Kconfig.emsdp"
6364
source "drivers/pinctrl/Kconfig.ti_cc32xx"
6465
source "drivers/pinctrl/Kconfig.numaker"

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

soc/ti/mspm0/mspm0g1x0x_g3x0x/pinctrl_soc.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@
1414
#define MSP_GPIO_RESISTOR_PULL_DOWN (16)
1515
#define MSP_GPIO_RESISTOR_PULL_UP (17)
1616
#define MSP_GPIO_INPUT_ENABLE (18)
17+
#define MSP_GPIO_HIGH_DRIVE (20)
1718
#define MSP_GPIO_HYSTERESIS_ENABLED (19)
1819
#define MSP_GPIO_OPEN_DRAIN_OUTPUT (25)
1920
#define MSP_GPIO_INVERSION_ENABLED (26)
2021

21-
#define MSP_GPIO_HIGH_DRIVE (20)
22-
2322
#define MSP_PINMUX_INIT(node_id) DT_PROP(node_id, pinmux)
2423

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_PROP(node_id, ti_hysteresis) << MSP_GPIO_HYSTERESIS_ENABLED) | \
30-
(DT_PROP(node_id, ti_invert) << MSP_GPIO_INVERSION_ENABLED) | \
24+
#define MSP_PIN_CONTROL_IOMUX_INIT(node_id) \
25+
((DT_PROP(node_id, bias_pull_up) << MSP_GPIO_RESISTOR_PULL_UP) | \
26+
(DT_PROP(node_id, bias_pull_down) << MSP_GPIO_RESISTOR_PULL_DOWN) | \
27+
(DT_PROP(node_id, drive_open_drain) << MSP_GPIO_OPEN_DRAIN_OUTPUT) | \
28+
(DT_ENUM_IDX(node_id, drive_strength) << MSP_GPIO_HIGH_DRIVE) | \
29+
(DT_PROP(node_id, ti_hysteresis) << MSP_GPIO_HYSTERESIS_ENABLED) | \
30+
(DT_PROP(node_id, ti_invert) << MSP_GPIO_INVERSION_ENABLED) | \
3131
(DT_PROP(node_id, input_enable) << MSP_GPIO_INPUT_ENABLE))
3232

3333
typedef struct pinctrl_soc_pin {
@@ -37,13 +37,13 @@ typedef struct pinctrl_soc_pin {
3737
uint32_t iomux;
3838
} pinctrl_soc_pin_t;
3939

40-
#define Z_PINCTRL_STATE_PIN_INIT(node_id, prop, idx) \
41-
{.pinmux = MSP_PINMUX_INIT(DT_PROP_BY_IDX(node_id, prop, idx)), \
40+
#define Z_PINCTRL_STATE_PIN_INIT(node_id, prop, idx) \
41+
{.pinmux = MSP_PINMUX_INIT(DT_PROP_BY_IDX(node_id, prop, idx)), \
4242
.iomux = MSP_PIN_CONTROL_IOMUX_INIT(DT_PROP_BY_IDX(node_id, prop, idx))},
4343

44-
#define Z_PINCTRL_STATE_PINS_INIT(node_id, prop) \
45-
{ \
46-
DT_FOREACH_PROP_ELEM(node_id, prop, Z_PINCTRL_STATE_PIN_INIT) \
44+
#define Z_PINCTRL_STATE_PINS_INIT(node_id, prop) \
45+
{ \
46+
DT_FOREACH_PROP_ELEM(node_id, prop, Z_PINCTRL_STATE_PIN_INIT) \
4747
}
4848

4949
#endif /* __ZEPHYR_SOC_ARM_TI_MSPM0_M0G_PINCTRL_SOC_H__ */

0 commit comments

Comments
 (0)