Skip to content

Commit 1f583d8

Browse files
committed
drivers: gpio: mspm0: Add a gpio support for MSPM0 family
Add a GPIO driver support for TI MSPM0 SoC family. Signed-off-by: Saravanan Sekar <[email protected]> Signed-off-by: Jackson Farley <[email protected]>
1 parent e3e0142 commit 1f583d8

File tree

5 files changed

+347
-0
lines changed

5 files changed

+347
-0
lines changed

drivers/gpio/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ zephyr_library_sources_ifdef(CONFIG_GPIO_MCUX_LPC gpio_mcux_lpc.c)
6161
zephyr_library_sources_ifdef(CONFIG_GPIO_MCUX_RGPIO gpio_mcux_rgpio.c)
6262
zephyr_library_sources_ifdef(CONFIG_GPIO_MFXSTM32L152 gpio_mfxstm32l152.c)
6363
zephyr_library_sources_ifdef(CONFIG_GPIO_MMIO32 gpio_mmio32.c)
64+
zephyr_library_sources_ifdef(CONFIG_GPIO_MSPM0 gpio_mspm0.c)
6465
zephyr_library_sources_ifdef(CONFIG_GPIO_NCT38XX gpio_nct38xx.c)
6566
zephyr_library_sources_ifdef(CONFIG_GPIO_NCT38XX gpio_nct38xx_port.c)
6667
zephyr_library_sources_ifdef(CONFIG_GPIO_NCT38XX_ALERT gpio_nct38xx_alert.c)

drivers/gpio/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ source "drivers/gpio/Kconfig.mcux_rgpio"
149149
source "drivers/gpio/Kconfig.mec5"
150150
source "drivers/gpio/Kconfig.mfxstm32l152"
151151
source "drivers/gpio/Kconfig.mmio32"
152+
source "drivers/gpio/Kconfig.mspm0"
152153
source "drivers/gpio/Kconfig.nct38xx"
153154
source "drivers/gpio/Kconfig.neorv32"
154155
source "drivers/gpio/Kconfig.npcx"

drivers/gpio/Kconfig.mspm0

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# TI MSPM0 GPIO configuration options
2+
3+
# Copyright (c) 2025 Texas Instruments
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
config GPIO_MSPM0
7+
bool "TI MSPM0 GPIO driver"
8+
default y
9+
depends on DT_HAS_TI_MSPM0_GPIO_ENABLED
10+
select USE_MSPM0_DL_GPIO
11+
help
12+
Enable the TI MSPM0 GPIO driver.

drivers/gpio/gpio_mspm0.c

Lines changed: 312 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,312 @@
1+
/*
2+
* Copyright (c) 2025 Texas Instruments
3+
* Copyright (c) 2025 Linumiz
4+
*
5+
* SPDX-License-Identifier: Apache-2.0
6+
*/
7+
8+
#define DT_DRV_COMPAT ti_mspm0_gpio
9+
10+
/* Zephyr includes */
11+
#include <zephyr/drivers/gpio.h>
12+
#include <zephyr/drivers/gpio/gpio_utils.h>
13+
#include <zephyr/irq.h>
14+
15+
/* Driverlib includes */
16+
#include <ti/driverlib/dl_gpio.h>
17+
18+
struct gpio_mspm0_config {
19+
/* gpio_mspm0_config needs to be first (doesn't actually get used) */
20+
struct gpio_driver_config common;
21+
/* port base address */
22+
GPIO_Regs *base;
23+
/* port pincm lookup table */
24+
uint32_t *pincm_lut;
25+
};
26+
27+
struct gpio_mspm0_data {
28+
/* gpio_driver_data needs to be first */
29+
struct gpio_driver_data common;
30+
sys_slist_t callbacks; /* List of interrupt callbacks */
31+
};
32+
33+
/* GPIO defines */
34+
#define GPIOA_NODE DT_NODELABEL(gpioa)
35+
#if DT_NODE_HAS_STATUS(GPIOA_NODE, okay)
36+
#if CONFIG_SOC_SERIES_MSPM0G
37+
#define NUM_GPIOA_PIN 32
38+
#define gpioa_pins NUM_GPIOA_PIN
39+
static uint32_t gpioa_pincm_lut[NUM_GPIOA_PIN] = {
40+
IOMUX_PINCM1, IOMUX_PINCM2, IOMUX_PINCM7, IOMUX_PINCM8, IOMUX_PINCM9, IOMUX_PINCM10,
41+
IOMUX_PINCM11, IOMUX_PINCM14, IOMUX_PINCM19, IOMUX_PINCM20, IOMUX_PINCM21, IOMUX_PINCM22,
42+
IOMUX_PINCM34, IOMUX_PINCM35, IOMUX_PINCM36, IOMUX_PINCM37, IOMUX_PINCM38, IOMUX_PINCM39,
43+
IOMUX_PINCM40, IOMUX_PINCM41, IOMUX_PINCM42, IOMUX_PINCM46, IOMUX_PINCM47, IOMUX_PINCM53,
44+
IOMUX_PINCM54, IOMUX_PINCM55, IOMUX_PINCM59, IOMUX_PINCM60, IOMUX_PINCM3, IOMUX_PINCM4,
45+
IOMUX_PINCM5, IOMUX_PINCM6,
46+
};
47+
#else
48+
#error "Series lookup table not supported"
49+
#endif /* if CONFIG_SOC_SERIES_MSPM0G */
50+
#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(gpioa), okay) */
51+
52+
#define GPIOB_NODE DT_NODELABEL(gpiob)
53+
#if DT_NODE_HAS_STATUS(GPIOB_NODE, okay)
54+
#ifdef CONFIG_SOC_SERIES_MSPM0G
55+
#define NUM_GPIOB_PIN 28
56+
#define gpiob_pins NUM_GPIOB_PIN
57+
static uint32_t gpiob_pincm_lut[NUM_GPIOB_PIN] = {
58+
IOMUX_PINCM12, IOMUX_PINCM13, IOMUX_PINCM15, IOMUX_PINCM16, IOMUX_PINCM17, IOMUX_PINCM18,
59+
IOMUX_PINCM23, IOMUX_PINCM24, IOMUX_PINCM25, IOMUX_PINCM26, IOMUX_PINCM27, IOMUX_PINCM28,
60+
IOMUX_PINCM29, IOMUX_PINCM30, IOMUX_PINCM31, IOMUX_PINCM32, IOMUX_PINCM33, IOMUX_PINCM43,
61+
IOMUX_PINCM44, IOMUX_PINCM45, IOMUX_PINCM48, IOMUX_PINCM49, IOMUX_PINCM50, IOMUX_PINCM51,
62+
IOMUX_PINCM52, IOMUX_PINCM56, IOMUX_PINCM57, IOMUX_PINCM58,
63+
};
64+
#endif /* CONFIG_SOC_SERIES_MSPM0G */
65+
#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(gpiob), okay) */
66+
67+
static int gpio_mspm0_port_get_raw(const struct device *port, uint32_t *value)
68+
{
69+
const struct gpio_mspm0_config *config = port->config;
70+
71+
/* Read entire port */
72+
*value = DL_GPIO_readPins(config->base, UINT32_MAX);
73+
74+
return 0;
75+
}
76+
77+
static int gpio_mspm0_port_set_masked_raw(const struct device *port,
78+
uint32_t mask, uint32_t value)
79+
{
80+
const struct gpio_mspm0_config *config = port->config;
81+
82+
DL_GPIO_writePinsVal(config->base, mask, value);
83+
84+
return 0;
85+
}
86+
87+
static int gpio_mspm0_port_set_bits_raw(const struct device *port,
88+
uint32_t mask)
89+
{
90+
const struct gpio_mspm0_config *config = port->config;
91+
92+
DL_GPIO_setPins(config->base, mask);
93+
94+
return 0;
95+
}
96+
97+
static int gpio_mspm0_port_clear_bits_raw(const struct device *port,
98+
uint32_t mask)
99+
{
100+
const struct gpio_mspm0_config *config = port->config;
101+
102+
DL_GPIO_clearPins(config->base, mask);
103+
104+
return 0;
105+
}
106+
107+
static int gpio_mspm0_port_toggle_bits(const struct device *port,
108+
uint32_t mask)
109+
{
110+
const struct gpio_mspm0_config *config = port->config;
111+
112+
DL_GPIO_togglePins(config->base, mask);
113+
114+
return 0;
115+
}
116+
117+
static int gpio_mspm0_pin_configure(const struct device *port,
118+
gpio_pin_t pin,
119+
gpio_flags_t flags)
120+
{
121+
const struct gpio_mspm0_config *config = port->config;
122+
/* determine pull up resistor value based on flags */
123+
DL_GPIO_RESISTOR pull_res;
124+
125+
if (flags & GPIO_PULL_UP) {
126+
pull_res = DL_GPIO_RESISTOR_PULL_UP;
127+
} else if (flags & GPIO_PULL_DOWN) {
128+
pull_res = DL_GPIO_RESISTOR_PULL_DOWN;
129+
} else {
130+
pull_res = DL_GPIO_RESISTOR_NONE;
131+
}
132+
133+
/* Config pin based on flags */
134+
switch (flags & (GPIO_INPUT | GPIO_OUTPUT)) {
135+
case GPIO_INPUT:
136+
DL_GPIO_initDigitalInputFeatures(config->pincm_lut[pin],
137+
DL_GPIO_INVERSION_DISABLE,
138+
pull_res,
139+
DL_GPIO_HYSTERESIS_DISABLE,
140+
DL_GPIO_WAKEUP_DISABLE);
141+
break;
142+
case GPIO_OUTPUT:
143+
DL_GPIO_initDigitalOutputFeatures(config->pincm_lut[pin],
144+
DL_GPIO_INVERSION_DISABLE,
145+
pull_res,
146+
DL_GPIO_DRIVE_STRENGTH_LOW,
147+
DL_GPIO_HIZ_DISABLE);
148+
149+
/* Set initial state */
150+
if (flags & GPIO_OUTPUT_INIT_HIGH) {
151+
gpio_mspm0_port_set_bits_raw(port, BIT(pin));
152+
} else if (flags & GPIO_OUTPUT_INIT_LOW) {
153+
gpio_mspm0_port_clear_bits_raw(port, BIT(pin));
154+
}
155+
/* Enable output */
156+
DL_GPIO_enableOutput(config->base, BIT(pin));
157+
break;
158+
case GPIO_DISCONNECTED:
159+
DL_GPIO_disableOutput(config->base, BIT(pin));
160+
break;
161+
default:
162+
return -ENOTSUP;
163+
}
164+
165+
return 0;
166+
}
167+
168+
static int gpio_mspm0_pin_interrupt_configure(const struct device *port,
169+
gpio_pin_t pin,
170+
enum gpio_int_mode mode,
171+
enum gpio_int_trig trig)
172+
{
173+
const struct gpio_mspm0_config *config = port->config;
174+
175+
/* Config interrupt */
176+
switch (mode) {
177+
case GPIO_INT_MODE_DISABLED:
178+
DL_GPIO_clearInterruptStatus(config->base, BIT(pin));
179+
DL_GPIO_disableInterrupt(config->base, BIT(pin));
180+
break;
181+
case GPIO_INT_MODE_EDGE:
182+
uint32_t polarity = 0x00;
183+
184+
if (trig & GPIO_INT_TRIG_LOW) {
185+
polarity |= BIT(0);
186+
}
187+
188+
if (trig & GPIO_INT_TRIG_HIGH) {
189+
polarity |= BIT(1);
190+
}
191+
192+
if (pin < 16) {
193+
DL_GPIO_setLowerPinsPolarity(config->base,
194+
polarity << (2 * pin));
195+
} else {
196+
DL_GPIO_setUpperPinsPolarity(config->base,
197+
polarity << (2 * (pin - 16)));
198+
}
199+
200+
DL_GPIO_clearInterruptStatus(config->base, BIT(pin));
201+
DL_GPIO_enableInterrupt(config->base, BIT(pin));
202+
break;
203+
case GPIO_INT_MODE_LEVEL:
204+
return -ENOTSUP;
205+
}
206+
207+
return 0;
208+
}
209+
210+
static int gpio_mspm0_manage_callback(const struct device *port,
211+
struct gpio_callback *callback,
212+
bool set)
213+
{
214+
struct gpio_mspm0_data *data = port->data;
215+
216+
return gpio_manage_callback(&data->callbacks, callback, set);
217+
}
218+
219+
static uint32_t gpio_mspm0_get_pending_int(const struct device *port)
220+
{
221+
const struct gpio_mspm0_config *config = port->config;
222+
223+
return DL_GPIO_getPendingInterrupt(config->base);
224+
}
225+
226+
static void gpio_mspm0_isr(const struct device *port)
227+
{
228+
struct gpio_mspm0_data *data;
229+
const struct gpio_mspm0_config *config;
230+
const struct device *dev_list[] = {
231+
DEVICE_DT_GET_OR_NULL(GPIOA_NODE),
232+
DEVICE_DT_GET_OR_NULL(GPIOB_NODE),
233+
};
234+
235+
for (uint8_t i = 0; i < ARRAY_SIZE(dev_list); i++) {
236+
uint32_t status;
237+
238+
if (dev_list[i] == NULL) {
239+
continue;
240+
}
241+
242+
data = dev_list[i]->data;
243+
config = dev_list[i]->config;
244+
245+
status = DL_GPIO_getRawInterruptStatus(config->base,
246+
0xFFFFFFFF);
247+
248+
DL_GPIO_clearInterruptStatus(config->base, status);
249+
if (status != 0) {
250+
gpio_fire_callbacks(&data->callbacks,
251+
dev_list[i], status);
252+
}
253+
}
254+
}
255+
256+
static int gpio_mspm0_init(const struct device *dev)
257+
{
258+
const struct gpio_mspm0_config *cfg = dev->config;
259+
static bool init_irq = true;
260+
261+
/* Reset and enable GPIO banks */
262+
DL_GPIO_reset(cfg->base);
263+
DL_GPIO_enablePower(cfg->base);
264+
265+
/* All the interrupt port share the same irq number, do it once */
266+
if (init_irq) {
267+
init_irq = false;
268+
269+
IRQ_CONNECT(DT_INST_IRQN(0), DT_INST_IRQ(0, priority),
270+
gpio_mspm0_isr, DEVICE_DT_INST_GET(0), 0);
271+
irq_enable(DT_INST_IRQN(0));
272+
}
273+
274+
return 0;
275+
}
276+
277+
static const struct gpio_driver_api gpio_mspm0_driver_api = {
278+
.pin_configure = gpio_mspm0_pin_configure,
279+
.port_get_raw = gpio_mspm0_port_get_raw,
280+
.port_set_masked_raw = gpio_mspm0_port_set_masked_raw,
281+
.port_set_bits_raw = gpio_mspm0_port_set_bits_raw,
282+
.port_clear_bits_raw = gpio_mspm0_port_clear_bits_raw,
283+
.port_toggle_bits = gpio_mspm0_port_toggle_bits,
284+
.pin_interrupt_configure = gpio_mspm0_pin_interrupt_configure,
285+
.manage_callback = gpio_mspm0_manage_callback,
286+
.get_pending_int = gpio_mspm0_get_pending_int,
287+
};
288+
289+
#define GPIO_DEVICE_INIT(n, __suffix, __base_addr) \
290+
static const struct gpio_mspm0_config gpio_mspm0_cfg_##__suffix = { \
291+
.common = { .port_pin_mask = \
292+
GPIO_PORT_PIN_MASK_FROM_NGPIOS(gpio##__suffix##_pins), \
293+
}, \
294+
.base = (GPIO_Regs *)__base_addr, \
295+
.pincm_lut = gpio##__suffix##_pincm_lut, \
296+
}; \
297+
static struct gpio_mspm0_data gpio_mspm0_data_##__suffix; \
298+
DEVICE_DT_DEFINE(n, gpio_mspm0_init, NULL, &gpio_mspm0_data_##__suffix, \
299+
&gpio_mspm0_cfg_##__suffix, PRE_KERNEL_1, CONFIG_GPIO_INIT_PRIORITY, \
300+
&gpio_mspm0_driver_api)
301+
302+
#define GPIO_DEVICE_INIT_MSPM0(__suffix) \
303+
GPIO_DEVICE_INIT(DT_NODELABEL(gpio##__suffix), __suffix, \
304+
DT_REG_ADDR(DT_NODELABEL(gpio##__suffix)))
305+
306+
#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpioa), okay)
307+
GPIO_DEVICE_INIT_MSPM0(a);
308+
#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(gpioa), okay) */
309+
310+
#if DT_NODE_HAS_STATUS(DT_NODELABEL(gpiob), okay)
311+
GPIO_DEVICE_INIT_MSPM0(b);
312+
#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(gpiob), okay) */
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
description: TI MSPM0 GPIO
4+
5+
compatible: "ti,mspm0-gpio"
6+
7+
include: [gpio-controller.yaml, base.yaml]
8+
9+
properties:
10+
reg:
11+
required: true
12+
13+
interrupts:
14+
required: true
15+
16+
"#gpio-cells":
17+
const: 2
18+
19+
gpio-cells:
20+
- pin
21+
- flags

0 commit comments

Comments
 (0)