From d45497e4c8cc5a994ef99afaa3ebcab33eb5944b Mon Sep 17 00:00:00 2001 From: Chekhov Ma Date: Wed, 28 Aug 2024 17:55:59 +0800 Subject: [PATCH] drivers: gpio: pca_series: add api to get per-port register size This commit add get per-port reg size api to make it more clear to understand the design. Signed-off-by: Chekhov Ma --- drivers/gpio/gpio_pca_series.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/drivers/gpio/gpio_pca_series.c b/drivers/gpio/gpio_pca_series.c index 23f9505b0c5..78e3d1e4b65 100644 --- a/drivers/gpio/gpio_pca_series.c +++ b/drivers/gpio/gpio_pca_series.c @@ -211,18 +211,16 @@ static inline uint8_t gpio_pca_series_reg_get_addr(const struct device *dev, } /** - * @brief get read size for register + * @brief get per-port size for register * * @param dev device struct * @param reg_type value from enum gpio_pca_series_reg_type * @return uint32_t size in bytes * 0 if fail */ -static inline uint32_t gpio_pca_series_reg_size(const struct device *dev, - enum gpio_pca_series_reg_type reg_type) +static inline uint32_t gpio_pca_series_reg_size_per_port(const struct device *dev, + enum gpio_pca_series_reg_type reg_type) { - const struct gpio_pca_series_config *cfg = dev->config; - #ifdef GPIO_NXP_PCA_SERIES_DEBUG if (reg_type >= PCA_REG_TYPE_COUNT) { LOG_ERR("reg_type %d out of range", reg_type); @@ -250,18 +248,34 @@ static inline uint32_t gpio_pca_series_reg_size(const struct device *dev, case PCA_REG_TYPE_1B_INTERRUPT_FALL: #endif /* CONFIG_GPIO_PCA_SERIES_CACHE_ALL */ #endif /* CONFIG_GPIO_PCA_SERIES_INTERRUPT */ - return cfg->part_cfg->port_no; + return 1; case PCA_REG_TYPE_2B_OUTPUT_DRIVE_STRENGTH: #ifdef CONFIG_GPIO_PCA_SERIES_INTERRUPT case PCA_REG_TYPE_2B_INTERRUPT_EDGE: #endif /* CONFIG_GPIO_PCA_SERIES_INTERRUPT */ - return (cfg->part_cfg->port_no * 2U); + return 2; default: LOG_ERR("unsupported reg type %d", reg_type); return 0; /** should never happen */ } } +/** + * @brief get read size for register + * + * @param dev device struct + * @param reg_type value from enum gpio_pca_series_reg_type + * @return uint32_t size in bytes + * 0 if fail + */ +static inline uint32_t gpio_pca_series_reg_size(const struct device *dev, + enum gpio_pca_series_reg_type reg_type) +{ + const struct gpio_pca_series_config *cfg = dev->config; + + return gpio_pca_series_reg_size_per_port(dev, reg_type) * cfg->part_cfg->port_no; +} + #ifdef CONFIG_GPIO_PCA_SERIES_CACHE_ALL /** forward declarations */ static inline uint8_t gpio_pca_series_reg_cache_offset(const struct device *dev,