Skip to content

Commit

Permalink
drivers: gpio: gpio_pca953x: Support TCA9536
Browse files Browse the repository at this point in the history
The PCA953x driver supports the TCA953x family

To properly support TCA953x, we need to allow ngpios!=8

This change allows this posibility in the driver

Signed-off-by: Rafael Laya <[email protected]>
  • Loading branch information
RafaelLaya committed Jan 26, 2025
1 parent f0d0264 commit 41e78d4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
13 changes: 5 additions & 8 deletions drivers/gpio/gpio_pca953x.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ LOG_MODULE_REGISTER(pca953x, CONFIG_GPIO_LOG_LEVEL);
#define REG_INPUT_LATCH_PORT0 0x42
#define REG_INT_MASK_PORT0 0x45

/* Number of pins supported by the device */
#define NUM_PINS 8

/* Max to select all pins supported on the device. */
#define ALL_PINS ((uint8_t)BIT_MASK(NUM_PINS))

/** Cache of the output configuration and data of the pins. */
struct pca953x_pin_state {
uint8_t dir;
Expand Down Expand Up @@ -478,7 +472,10 @@ static DEVICE_API(gpio, api_table) = {
.manage_callback = gpio_pca953x_manage_callback,
};

#define GET_NGPIOS(n) DT_INST_PROP(n, ngpios)

#define GPIO_PCA953X_INIT(n) \
BUILD_ASSERT((GET_NGPIOS(n) == 4) || (GET_NGPIOS(n) == 8)); \
static const struct pca953x_config pca953x_cfg_##n = { \
.i2c = I2C_DT_SPEC_INST_GET(n), \
.common = { \
Expand All @@ -492,8 +489,8 @@ static DEVICE_API(gpio, api_table) = {
\
static struct pca953x_drv_data pca953x_drvdata_##n = { \
.lock = Z_SEM_INITIALIZER(pca953x_drvdata_##n.lock, 1, 1), \
.pin_state.dir = ALL_PINS, \
.pin_state.output = ALL_PINS, \
.pin_state.dir = GPIO_PORT_PIN_MASK_FROM_DT_INST(n), \
.pin_state.output = GPIO_PORT_PIN_MASK_FROM_DT_INST(n), \
}; \
DEVICE_DT_INST_DEFINE(n, \
gpio_pca953x_init, \
Expand Down
3 changes: 1 addition & 2 deletions dts/bindings/gpio/ti,tca9538.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright (c) 2021, Laird Connectivity
# SPDX-License-Identifier: Apache-2.0

description: TCA9538 GPIO node
description: TCA9538 GPIO node. Supports variants such as TCA9536 which have 8 or less outputs

compatible: "ti,tca9538"

Expand All @@ -14,7 +14,6 @@ properties:

ngpios:
required: true
const: 8
description: |
Number of GPIOs available on port expander.
Expand Down

0 comments on commit 41e78d4

Please sign in to comment.