From 6618a673e57c3bc9fe83687626507e98d9a3fa3d Mon Sep 17 00:00:00 2001 From: Hao Luo Date: Wed, 12 Feb 2025 11:38:05 +0800 Subject: [PATCH] drivers: gpio: Add support for Apollo510 GPIO This commit adds support for Apollo510 SoC in ambiq gpio driver Signed-off-by: Hao Luo --- drivers/gpio/gpio_ambiq.c | 18 ++++++++++++++ include/zephyr/drivers/gpio/gpio_ambiq.h | 31 ++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 include/zephyr/drivers/gpio/gpio_ambiq.h diff --git a/drivers/gpio/gpio_ambiq.c b/drivers/gpio/gpio_ambiq.c index 7026640dfff..c4effe03d15 100644 --- a/drivers/gpio/gpio_ambiq.c +++ b/drivers/gpio/gpio_ambiq.c @@ -13,6 +13,7 @@ #include #include #include +#include #include @@ -488,7 +489,12 @@ static int ambiq_gpio_pin_interrupt_configure(const struct device *dev, gpio_pin * GPIO_INT_TRIG_BOTH is not supported on Ambiq Apollo4 Plus Platform * ERR008: GPIO: Dual-edge interrupts are not vectoring */ +#if defined(CONFIG_SOC_SERIES_APOLLO4X) return -ENOTSUP; +#elif defined(CONFIG_SOC_SERIES_APOLLO5X) + pincfg.GP.cfg_b.eIntDir = AM_HAL_GPIO_PIN_INTDIR_BOTH; + break; +#endif default: return -EINVAL; } @@ -567,6 +573,18 @@ static DEVICE_API(gpio, ambiq_gpio_drv_api) = { #endif }; +gpio_pin_t ambiq_gpio_get_pinnum(const struct device *dev, gpio_pin_t pin) +{ + const struct ambiq_gpio_config *const dev_cfg = dev->config; + +#if defined(CONFIG_SOC_SERIES_APOLLO3X) + pin += dev_cfg->offset; +#else + pin += (dev_cfg->offset >> 2); +#endif + return pin; +} + #if defined(CONFIG_SOC_SERIES_APOLLO3X) /* Apollo3 GPIO banks share the same irq number, connect irq here will cause build error, so we * leave this function blank here and do it in ambiq_gpio_cfg_func diff --git a/include/zephyr/drivers/gpio/gpio_ambiq.h b/include/zephyr/drivers/gpio/gpio_ambiq.h new file mode 100644 index 00000000000..eec0e34fe0c --- /dev/null +++ b/include/zephyr/drivers/gpio/gpio_ambiq.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 Ambiq Micro Inc. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_DRIVERS_GPIO_GPIO_AMBIQ_H_ +#define ZEPHYR_DRIVERS_GPIO_GPIO_AMBIQ_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Get the actual gpio pin number. + * + * @param dev Pointer to the device structure for the driver instance. + * @param pin Pin number of the select gpio group. + * + * @retval pin number. + */ +gpio_pin_t ambiq_gpio_get_pinnum(const struct device *dev, gpio_pin_t pin); + +#ifdef __cplusplus +} +#endif + +#endif /* ZEPHYR_DRIVERS_GPIO_GPIO_AMBIQ_H_ */