Skip to content

Commit 4cc62be

Browse files
author
Tavish Naruka
committed
drivers: gpio: add TMS570 gpio driver
Adds TI TMS570 SoC GPIO driver. Signed-off-by: Tavish Naruka <[email protected]>
1 parent 7aa24b9 commit 4cc62be

File tree

6 files changed

+211
-0
lines changed

6 files changed

+211
-0
lines changed

drivers/gpio/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ zephyr_library_sources_ifdef(CONFIG_GPIO_TCA6424A gpio_tca6424a.c)
110110
zephyr_library_sources_ifdef(CONFIG_GPIO_TELINK_B91 gpio_b91.c)
111111
zephyr_library_sources_ifdef(CONFIG_GPIO_TEST gpio_test.c)
112112
zephyr_library_sources_ifdef(CONFIG_GPIO_TLE9104 gpio_tle9104.c)
113+
zephyr_library_sources_ifdef(CONFIG_GPIO_TMS570 gpio_tms570.c)
113114
zephyr_library_sources_ifdef(CONFIG_GPIO_WCH_GPIO wch_gpio_ch32v00x.c)
114115
zephyr_library_sources_ifdef(CONFIG_GPIO_XEC gpio_mchp_xec.c)
115116
zephyr_library_sources_ifdef(CONFIG_GPIO_XEC_V2 gpio_mchp_xec_v2.c)

drivers/gpio/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ source "drivers/gpio/Kconfig.sy1xx"
192192
source "drivers/gpio/Kconfig.tca6424a"
193193
source "drivers/gpio/Kconfig.test"
194194
source "drivers/gpio/Kconfig.tle9104"
195+
source "drivers/gpio/Kconfig.tms570"
195196
source "drivers/gpio/Kconfig.wch_ch32v00x"
196197
source "drivers/gpio/Kconfig.xec"
197198
source "drivers/gpio/Kconfig.xlnx"

drivers/gpio/Kconfig.tms570

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) 2025 ispace, inc.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config GPIO_TMS570
5+
bool "TMS570 GPIO driver"
6+
default y
7+
depends on DT_HAS_TI_TMS570_GPIO_ENABLED
8+
help
9+
Enable driver for the TI TMS570 GPIO controller.

drivers/gpio/gpio_tms570.c

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
/*
2+
* Copyright (c) 2025 ispace, inc.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#define DT_DRV_COMPAT ti_tms570_gpio
8+
9+
#include <zephyr/drivers/gpio.h>
10+
#include <zephyr/kernel.h>
11+
#include <zephyr/sys/sys_io.h>
12+
#include <zephyr/drivers/gpio/gpio_utils.h>
13+
#include <zephyr/irq.h>
14+
15+
/* port registers */
16+
#define REG_DIR 0x0000 /* Data Direction Register */
17+
#define REG_DIN 0x0004 /* Data Input Register */
18+
#define REG_DOUT 0x0008 /* Data Output Register */
19+
#define REG_DSET 0x000C /* Data Output Set Register */
20+
#define REG_DCLR 0x0010 /* Data Output Clear Register */
21+
#define REG_PDR 0x0014 /* Open Drain Register */
22+
#define REG_PULDIS 0x0018 /* Pullup Disable Register */
23+
#define REG_PSL 0x001C /* Pull Up/Down Selection Register */
24+
25+
/* GIO base registers */
26+
#define REG_GCR0 0x0000 /* Global Control Register */
27+
#define REG_INTDET 0x0008 /* Interrupt Detect Register*/
28+
#define REG_POL 0x000C /* Interrupt Polarity Register */
29+
#define REG_ENASET 0x0010 /* Interrupt Enable Set Register */
30+
#define REG_ENACLR 0x0014 /* Interrupt Enable Clear Register */
31+
#define REG_LVLSET 0x0018 /* Interrupt Priority Set Register */
32+
#define REG_LVLCLR 0x001C /* Interrupt Priority Clear Register */
33+
#define REG_FLG 0x0020 /* Interrupt Flag Register */
34+
#define REG_OFF1 0x0024 /* Interrupt Offset A Register */
35+
#define REG_OFF2 0x0028 /* Interrupt Offset B Register */
36+
#define REG_EMU1 0x002C /* Emulation 1 Register */
37+
#define REG_EMU2 0x0030 /* Emulation 2 Register */
38+
39+
struct gpio_tms570_config {
40+
/* gpio_driver_config needs to be first */
41+
struct gpio_driver_config common;
42+
uint32_t reg_gio;
43+
uint32_t reg_port;
44+
};
45+
46+
struct gpio_tms570_data {
47+
/* gpio_driver_data needs to be first */
48+
struct gpio_driver_data common;
49+
};
50+
51+
static int gpio_tms570_set_bits(const struct device *dev, gpio_port_pins_t pin)
52+
{
53+
const struct gpio_tms570_config *config = dev->config;
54+
55+
sys_write32(pin, config->reg_port + REG_DOUT);
56+
57+
return 0;
58+
}
59+
60+
static int gpio_tms570_clear_bits(const struct device *dev, gpio_port_pins_t pin)
61+
{
62+
const struct gpio_tms570_config *config = dev->config;
63+
64+
uint32_t val = sys_read32(config->reg_port + REG_DIN);
65+
sys_write32(val & (uint32_t)~pin, config->reg_port + REG_DOUT);
66+
67+
return 0;
68+
}
69+
70+
static int gpio_tms570_get(const struct device *dev, gpio_port_value_t *value)
71+
{
72+
const struct gpio_tms570_config *config = dev->config;
73+
74+
*value = sys_read32(config->reg_port + REG_DIN);
75+
76+
return 0;
77+
}
78+
79+
static int gpio_tms570_configure(const struct device *dev, gpio_pin_t pin, gpio_flags_t flags)
80+
{
81+
const struct gpio_tms570_config *config = dev->config;
82+
uint32_t current_config;
83+
84+
/* Read the current configuration of the pins */
85+
current_config = sys_read32(config->reg_port + REG_DIR);
86+
87+
/* We only support changes in the direction of the pins */
88+
if (flags == GPIO_INPUT) {
89+
/* Pins specified as input will have their DIR register's bit set to 0 */
90+
sys_write32(current_config & ~BIT(pin), config->reg_port + REG_DIR);
91+
} else if (flags == GPIO_OUTPUT) {
92+
/* Pins specified as input will have their DIR register's bit set to 1 */
93+
sys_write32(current_config | BIT(pin), config->reg_port + REG_DIR);
94+
} else {
95+
return -EINVAL;
96+
}
97+
98+
return 0;
99+
}
100+
101+
static int gpio_tms570_pin_interrupt_configure(const struct device *dev, gpio_pin_t pin,
102+
enum gpio_int_mode mode, enum gpio_int_trig trig)
103+
{
104+
return -ENOSYS;
105+
}
106+
107+
static int gpio_tms570_manage_callback(const struct device *dev, struct gpio_callback *callback, bool set)
108+
{
109+
return -ENOSYS;
110+
}
111+
112+
static const struct gpio_driver_api gpio_tms570_api = {
113+
.port_set_bits_raw = gpio_tms570_set_bits,
114+
.port_clear_bits_raw = gpio_tms570_clear_bits,
115+
.port_get_raw = gpio_tms570_get,
116+
.pin_configure = gpio_tms570_configure,
117+
.pin_interrupt_configure = gpio_tms570_pin_interrupt_configure,
118+
.manage_callback = gpio_tms570_manage_callback,
119+
};
120+
121+
static int gpio_tms570_init(const struct device *dev)
122+
{
123+
const struct gpio_tms570_config *config = dev->config;
124+
static int gpio_tms570_init_done;
125+
126+
if (gpio_tms570_init_done == 0) {
127+
gpio_tms570_init_done = 1;
128+
sys_write32(1, config->reg_gio + REG_GCR0);
129+
sys_write32(0xFFU, config->reg_gio + REG_ENACLR);
130+
sys_write32(0xFFU, config->reg_gio + REG_LVLCLR);
131+
}
132+
133+
return 0;
134+
}
135+
136+
#define TMS570_GPIO_INIT(n) \
137+
static struct gpio_tms570_data gpio_tms570_data_##n = { \
138+
}; \
139+
static struct gpio_tms570_config gpio_tms570_config_##n = { \
140+
.common = { \
141+
.port_pin_mask = GPIO_PORT_PIN_MASK_FROM_DT_INST(n), \
142+
}, \
143+
.reg_port = DT_INST_REG_ADDR_BY_IDX(n, 0), \
144+
.reg_gio = DT_INST_REG_ADDR_BY_IDX(n, 1), \
145+
}; \
146+
DEVICE_DT_INST_DEFINE(n, gpio_tms570_init, NULL, \
147+
&gpio_tms570_data_##n, &gpio_tms570_config_##n, \
148+
POST_KERNEL, CONFIG_GPIO_INIT_PRIORITY, \
149+
&gpio_tms570_api);
150+
151+
DT_INST_FOREACH_STATUS_OKAY(TMS570_GPIO_INIT)

dts/arm/ti/tms570.dtsi

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,29 @@
115115
reg = <0xfff7e500 256>;
116116
status = "disabled";
117117
};
118+
119+
gpio_a: gpio@fff7bc34 {
120+
compatible = "ti,tms570-gpio";
121+
reg = <0xfff7bc34 0x34 /* GIO port base */
122+
0xfff7bc00 0x20>; /* GIO base */
123+
interrupts = <13 0>;
124+
interrupt-parent = <&vim>;
125+
gpio-controller;
126+
#gpio-cells = <2>;
127+
ngpios = <8>;
128+
status = "okay";
129+
};
130+
131+
gpio_b: gpio@fff7bc54 {
132+
compatible = "ti,tms570-gpio";
133+
reg = <0xfff7bc54 0x34 /* GIO port base */
134+
0xfff7bc00 0x20>; /* GIO base */
135+
interrupts = <13 0>;
136+
interrupt-parent = <&vim>;
137+
gpio-controller;
138+
#gpio-cells = <2>;
139+
ngpios = <8>;
140+
status = "okay";
141+
};
118142
};
119143
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright (c) 2025 ispace, inc.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: TMS570 GPIO
5+
6+
compatible: "ti,tms570-gpio"
7+
8+
include: [gpio-controller.yaml, base.yaml]
9+
10+
properties:
11+
# NOTE: Register ranges:
12+
# - 0 : GIO port registers
13+
# - 1 : GIO base registers
14+
reg:
15+
required: true
16+
17+
interrupt-parent:
18+
required: true
19+
20+
ngpios:
21+
required: true
22+
23+
gpio-cells:
24+
- pin
25+
- flags

0 commit comments

Comments
 (0)