Skip to content

Commit 791af9a

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 0a33adf commit 791af9a

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 bool init_irq = true;
68+
69+
static int gpio_mspm0_port_get_raw(const struct device *port, uint32_t *value)
70+
{
71+
const struct gpio_mspm0_config *config = port->config;
72+
73+
/* Read entire port */
74+
*value = DL_GPIO_readPins(config->base, UINT32_MAX);
75+
76+
return 0;
77+
}
78+
79+
static int gpio_mspm0_port_set_masked_raw(const struct device *port,
80+
uint32_t mask, uint32_t value)
81+
{
82+
const struct gpio_mspm0_config *config = port->config;
83+
84+
DL_GPIO_writePinsVal(config->base, mask, value);
85+
86+
return 0;
87+
}
88+
89+
static int gpio_mspm0_port_set_bits_raw(const struct device *port,
90+
uint32_t mask)
91+
{
92+
const struct gpio_mspm0_config *config = port->config;
93+
94+
DL_GPIO_setPins(config->base, mask);
95+
96+
return 0;
97+
}
98+
99+
static int gpio_mspm0_port_clear_bits_raw(const struct device *port,
100+
uint32_t mask)
101+
{
102+
const struct gpio_mspm0_config *config = port->config;
103+
104+
DL_GPIO_clearPins(config->base, mask);
105+
106+
return 0;
107+
}
108+
109+
static int gpio_mspm0_port_toggle_bits(const struct device *port,
110+
uint32_t mask)
111+
{
112+
const struct gpio_mspm0_config *config = port->config;
113+
114+
DL_GPIO_togglePins(config->base, mask);
115+
116+
return 0;
117+
}
118+
119+
static int gpio_mspm0_pin_configure(const struct device *port,
120+
gpio_pin_t pin,
121+
gpio_flags_t flags)
122+
{
123+
const struct gpio_mspm0_config *config = port->config;
124+
/* determine pull up resistor value based on flags */
125+
DL_GPIO_RESISTOR pull_res;
126+
127+
if (flags & GPIO_PULL_UP) {
128+
pull_res = DL_GPIO_RESISTOR_PULL_UP;
129+
} else if (flags & GPIO_PULL_DOWN) {
130+
pull_res = DL_GPIO_RESISTOR_PULL_DOWN;
131+
} else {
132+
pull_res = DL_GPIO_RESISTOR_NONE;
133+
}
134+
135+
/* Config pin based on flags */
136+
switch (flags & (GPIO_INPUT | GPIO_OUTPUT)) {
137+
case GPIO_INPUT:
138+
DL_GPIO_initDigitalInputFeatures(config->pincm_lut[pin],
139+
DL_GPIO_INVERSION_DISABLE,
140+
pull_res,
141+
DL_GPIO_HYSTERESIS_DISABLE,
142+
DL_GPIO_WAKEUP_DISABLE);
143+
break;
144+
case GPIO_OUTPUT:
145+
DL_GPIO_initDigitalOutputFeatures(config->pincm_lut[pin],
146+
DL_GPIO_INVERSION_DISABLE,
147+
pull_res,
148+
DL_GPIO_DRIVE_STRENGTH_LOW,
149+
DL_GPIO_HIZ_DISABLE);
150+
151+
/* Set initial state */
152+
if (flags & GPIO_OUTPUT_INIT_HIGH) {
153+
gpio_mspm0_port_set_bits_raw(port, BIT(pin));
154+
} else if (flags & GPIO_OUTPUT_INIT_LOW) {
155+
gpio_mspm0_port_clear_bits_raw(port, BIT(pin));
156+
}
157+
/* Enable output */
158+
DL_GPIO_enableOutput(config->base, BIT(pin));
159+
break;
160+
case GPIO_DISCONNECTED:
161+
DL_GPIO_disableOutput(config->base, BIT(pin));
162+
break;
163+
default:
164+
return -ENOTSUP;
165+
}
166+
167+
return 0;
168+
}
169+
170+
static int gpio_mspm0_pin_interrupt_configure(const struct device *port,
171+
gpio_pin_t pin,
172+
enum gpio_int_mode mode,
173+
enum gpio_int_trig trig)
174+
{
175+
const struct gpio_mspm0_config *config = port->config;
176+
177+
/* Config interrupt */
178+
switch (mode) {
179+
case GPIO_INT_MODE_DISABLED:
180+
DL_GPIO_clearInterruptStatus(config->base, BIT(pin));
181+
DL_GPIO_disableInterrupt(config->base, BIT(pin));
182+
break;
183+
case GPIO_INT_MODE_EDGE:
184+
uint32_t polarity = 0x00;
185+
186+
if (trig & GPIO_INT_TRIG_LOW) {
187+
polarity |= BIT(0);
188+
}
189+
190+
if (trig & GPIO_INT_TRIG_HIGH) {
191+
polarity |= BIT(1);
192+
}
193+
194+
if (pin < 16) {
195+
DL_GPIO_setLowerPinsPolarity(config->base,
196+
polarity << (2 * pin));
197+
} else {
198+
DL_GPIO_setUpperPinsPolarity(config->base,
199+
polarity << (2 * (pin - 16)));
200+
}
201+
202+
DL_GPIO_clearInterruptStatus(config->base, BIT(pin));
203+
DL_GPIO_enableInterrupt(config->base, BIT(pin));
204+
break;
205+
case GPIO_INT_MODE_LEVEL:
206+
return -ENOTSUP;
207+
}
208+
209+
return 0;
210+
}
211+
212+
static int gpio_mspm0_manage_callback(const struct device *port,
213+
struct gpio_callback *callback,
214+
bool set)
215+
{
216+
struct gpio_mspm0_data *data = port->data;
217+
218+
return gpio_manage_callback(&data->callbacks, callback, set);
219+
}
220+
221+
static uint32_t gpio_mspm0_get_pending_int(const struct device *port)
222+
{
223+
const struct gpio_mspm0_config *config = port->config;
224+
225+
return DL_GPIO_getPendingInterrupt(config->base);
226+
}
227+
228+
static void gpio_mspm0_isr(const struct device *port)
229+
{
230+
struct gpio_mspm0_data *data;
231+
const struct gpio_mspm0_config *config;
232+
const struct device *dev_list[] = {
233+
DEVICE_DT_GET_OR_NULL(GPIOA_NODE),
234+
DEVICE_DT_GET_OR_NULL(GPIOB_NODE),
235+
};
236+
237+
for (uint8_t i = 0; i < ARRAY_SIZE(dev_list); i++) {
238+
uint32_t status;
239+
240+
if (dev_list[i] == NULL) {
241+
continue;
242+
}
243+
244+
data = dev_list[i]->data;
245+
config = dev_list[i]->config;
246+
247+
status = DL_GPIO_getRawInterruptStatus(config->base,
248+
0xFFFFFFFF);
249+
250+
DL_GPIO_clearInterruptStatus(config->base, status);
251+
if (status != 0) {
252+
gpio_fire_callbacks(&data->callbacks,
253+
dev_list[i], status);
254+
}
255+
}
256+
}
257+
258+
static int gpio_mspm0_init(const struct device *dev)
259+
{
260+
const struct gpio_mspm0_config *cfg = dev->config;
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)