Skip to content

Commit 2c5c832

Browse files
committed
Add seesaw gpio
Signed-off-by: Titouan Christophe <[email protected]>
1 parent 5af7550 commit 2c5c832

File tree

5 files changed

+156
-0
lines changed

5 files changed

+156
-0
lines changed

drivers/gpio/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ zephyr_library_sources_ifdef(CONFIG_GPIO_SAM gpio_sam.c)
9595
zephyr_library_sources_ifdef(CONFIG_GPIO_SAM0 gpio_sam0.c)
9696
zephyr_library_sources_ifdef(CONFIG_GPIO_SAM4L gpio_sam4l.c)
9797
zephyr_library_sources_ifdef(CONFIG_GPIO_SEDI gpio_sedi.c)
98+
zephyr_library_sources_ifdef(CONFIG_GPIO_SEESAW gpio_seesaw.c)
9899
zephyr_library_sources_ifdef(CONFIG_GPIO_SI32 gpio_si32.c)
99100
zephyr_library_sources_ifdef(CONFIG_GPIO_SIFIVE gpio_sifive.c)
100101
zephyr_library_sources_ifdef(CONFIG_GPIO_SILABS_SIWX91X gpio_silabs_siwx91x.c)

drivers/gpio/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ source "drivers/gpio/Kconfig.sam"
180180
source "drivers/gpio/Kconfig.sam0"
181181
source "drivers/gpio/Kconfig.sc18im704"
182182
source "drivers/gpio/Kconfig.sedi"
183+
source "drivers/gpio/Kconfig.seesaw"
183184
source "drivers/gpio/Kconfig.si32"
184185
source "drivers/gpio/Kconfig.sifive"
185186
source "drivers/gpio/Kconfig.siwx91x"

drivers/gpio/Kconfig.seesaw

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright 2025 Titouan Chrisotphe
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config GPIO_SEESAW
5+
bool "Adafruit Seesaw GPIO over I2C"
6+
default y
7+
depends on MFD_SEESAW
8+
depends on DT_HAS_ADAFRUIT_SEESAW_GPIO_ENABLED
9+
help
10+
Enable support for Adafruit Seesaw gpio

drivers/gpio/gpio_seesaw.c

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/*
2+
* Copyright (c) 2025 Titouan Christophe
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#define DT_DRV_COMPAT adafruit_seesaw_gpio
8+
9+
#include <zephyr/drivers/gpio.h>
10+
#include <zephyr/drivers/mfd/mfd_seesaw.h>
11+
12+
enum seesaw_mod_gpio {
13+
GPIO_DIRSET = 0x02,
14+
GPIO_DIRCLR = 0x03,
15+
GPIO_GPIO = 0x04,
16+
GPIO_SET = 0x05,
17+
GPIO_CLR = 0x06,
18+
GPIO_TOGGLE = 0x07,
19+
GPIO_INTENSET = 0x08,
20+
GPIO_INTENCLR = 0x09,
21+
GPIO_INTFLAG = 0x0a,
22+
GPIO_PULLENSET = 0x0b,
23+
GPIO_PULLENCLR = 0x0c,
24+
};
25+
26+
struct seesaw_gpio_config {
27+
const struct device *seesaw;
28+
};
29+
30+
static int seesaw_gpio_configure(const struct device *dev,
31+
gpio_pin_t pin, gpio_flags_t flags)
32+
{
33+
const struct seesaw_gpio_config *const config = dev->config;
34+
35+
if (flags & GPIO_OUTPUT) {
36+
seesaw_write_uint32(config->seesaw, SEESAW_MOD_GPIO, GPIO_DIRSET, BIT(pin));
37+
} else if (flags & GPIO_INPUT) {
38+
seesaw_write_uint32(config->seesaw, SEESAW_MOD_GPIO, GPIO_DIRCLR, BIT(pin));
39+
} else {
40+
return -ENOTSUP;
41+
}
42+
43+
if (flags & GPIO_PULL_UP) {
44+
seesaw_write_uint32(config->seesaw, SEESAW_MOD_GPIO, GPIO_SET, BIT(pin));
45+
seesaw_write_uint32(config->seesaw, SEESAW_MOD_GPIO, GPIO_PULLENSET, BIT(pin));
46+
} else if (flags & GPIO_PULL_DOWN) {
47+
seesaw_write_uint32(config->seesaw, SEESAW_MOD_GPIO, GPIO_CLR, BIT(pin));
48+
seesaw_write_uint32(config->seesaw, SEESAW_MOD_GPIO, GPIO_PULLENSET, BIT(pin));
49+
}
50+
51+
return 0;
52+
}
53+
54+
static int seesaw_gpio_port_get_raw(const struct device *dev, uint32_t *value)
55+
{
56+
uint32_t tmp;
57+
const struct seesaw_gpio_config *const config = dev->config;
58+
int ret = seesaw_read(config->seesaw, SEESAW_MOD_GPIO, GPIO_GPIO, (uint8_t *) &tmp, 4);
59+
60+
if (ret == 0) {
61+
*value = sys_be32_to_cpu(ret);
62+
}
63+
64+
return ret;
65+
}
66+
67+
static int seesaw_gpio_port_set_masked_raw(const struct device *dev, uint32_t mask, uint32_t value)
68+
{
69+
const struct seesaw_gpio_config *const config = dev->config;
70+
71+
seesaw_write_uint32(config->seesaw, SEESAW_MOD_GPIO, GPIO_SET, value & mask);
72+
seesaw_write_uint32(config->seesaw, SEESAW_MOD_GPIO, GPIO_CLR, ~value & mask);
73+
74+
return 0;
75+
}
76+
77+
static int seesaw_gpio_port_set_bits_raw(const struct device *dev, uint32_t mask)
78+
{
79+
const struct seesaw_gpio_config *const config = dev->config;
80+
81+
seesaw_write_uint32(config->seesaw, SEESAW_MOD_GPIO, GPIO_SET, mask);
82+
83+
return 0;
84+
}
85+
86+
static int seesaw_gpio_port_clear_bits_raw(const struct device *dev, uint32_t mask)
87+
{
88+
const struct seesaw_gpio_config *const config = dev->config;
89+
90+
seesaw_write_uint32(config->seesaw, SEESAW_MOD_GPIO, GPIO_CLR, mask);
91+
92+
return 0;
93+
}
94+
95+
static int seesaw_gpio_port_toggle_bits(const struct device *dev, uint32_t mask)
96+
{
97+
const struct seesaw_gpio_config *const config = dev->config;
98+
99+
seesaw_write_uint32(config->seesaw, SEESAW_MOD_GPIO, GPIO_TOGGLE, mask);
100+
101+
return 0;
102+
}
103+
104+
105+
static DEVICE_API(gpio, seesaw_gpio_api) = {
106+
.pin_configure = seesaw_gpio_configure,
107+
.port_get_raw = seesaw_gpio_port_get_raw,
108+
.port_set_masked_raw = seesaw_gpio_port_set_masked_raw,
109+
.port_set_bits_raw = seesaw_gpio_port_set_bits_raw,
110+
.port_clear_bits_raw = seesaw_gpio_port_clear_bits_raw,
111+
.port_toggle_bits = seesaw_gpio_port_toggle_bits,
112+
};
113+
114+
static int seesaw_gpio_init(const struct device *dev)
115+
{
116+
const struct seesaw_gpio_config *config = dev->config;
117+
118+
return seesaw_claim_module(config->seesaw, SEESAW_MOD_GPIO, dev);
119+
}
120+
121+
#define SEESAW_GPIO_INIT(inst) \
122+
static const struct seesaw_gpio_config config_##inst = { \
123+
.seesaw = DEVICE_DT_GET(DT_INST_PARENT(inst)), \
124+
}; \
125+
DEVICE_DT_INST_DEFINE(inst, seesaw_gpio_init, NULL, NULL, &config_##inst, POST_KERNEL, \
126+
CONFIG_MFD_INIT_PRIORITY, &seesaw_gpio_api);
127+
128+
DT_INST_FOREACH_STATUS_OKAY(SEESAW_GPIO_INIT)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright (c) 2025 Titouan Christophe
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: Adafruit Seesaw gpio
5+
6+
compatible: "adafruit,seesaw-gpio"
7+
8+
include: [gpio-controller.yaml]
9+
10+
properties:
11+
"#gpio-cells":
12+
const: 2
13+
14+
gpio-cells:
15+
- pin
16+
- flags

0 commit comments

Comments
 (0)