Skip to content

Commit 6618a67

Browse files
AlessandroLuokartben
authored andcommitted
drivers: gpio: Add support for Apollo510 GPIO
This commit adds support for Apollo510 SoC in ambiq gpio driver Signed-off-by: Hao Luo <hluo@ambiq.com>
1 parent b9f0507 commit 6618a67

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

drivers/gpio/gpio_ambiq.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <zephyr/drivers/gpio/gpio_utils.h>
1414
#include <zephyr/irq.h>
1515
#include <zephyr/spinlock.h>
16+
#include <zephyr/drivers/gpio/gpio_ambiq.h>
1617

1718
#include <soc.h>
1819

@@ -488,7 +489,12 @@ static int ambiq_gpio_pin_interrupt_configure(const struct device *dev, gpio_pin
488489
* GPIO_INT_TRIG_BOTH is not supported on Ambiq Apollo4 Plus Platform
489490
* ERR008: GPIO: Dual-edge interrupts are not vectoring
490491
*/
492+
#if defined(CONFIG_SOC_SERIES_APOLLO4X)
491493
return -ENOTSUP;
494+
#elif defined(CONFIG_SOC_SERIES_APOLLO5X)
495+
pincfg.GP.cfg_b.eIntDir = AM_HAL_GPIO_PIN_INTDIR_BOTH;
496+
break;
497+
#endif
492498
default:
493499
return -EINVAL;
494500
}
@@ -567,6 +573,18 @@ static DEVICE_API(gpio, ambiq_gpio_drv_api) = {
567573
#endif
568574
};
569575

576+
gpio_pin_t ambiq_gpio_get_pinnum(const struct device *dev, gpio_pin_t pin)
577+
{
578+
const struct ambiq_gpio_config *const dev_cfg = dev->config;
579+
580+
#if defined(CONFIG_SOC_SERIES_APOLLO3X)
581+
pin += dev_cfg->offset;
582+
#else
583+
pin += (dev_cfg->offset >> 2);
584+
#endif
585+
return pin;
586+
}
587+
570588
#if defined(CONFIG_SOC_SERIES_APOLLO3X)
571589
/* Apollo3 GPIO banks share the same irq number, connect irq here will cause build error, so we
572590
* leave this function blank here and do it in ambiq_gpio_cfg_func
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (c) 2025 Ambiq Micro Inc. <www.ambiq.com>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_DRIVERS_GPIO_GPIO_AMBIQ_H_
8+
#define ZEPHYR_DRIVERS_GPIO_GPIO_AMBIQ_H_
9+
10+
#include <zephyr/device.h>
11+
#include <zephyr/drivers/gpio.h>
12+
13+
#ifdef __cplusplus
14+
extern "C" {
15+
#endif
16+
17+
/**
18+
* @brief Get the actual gpio pin number.
19+
*
20+
* @param dev Pointer to the device structure for the driver instance.
21+
* @param pin Pin number of the select gpio group.
22+
*
23+
* @retval pin number.
24+
*/
25+
gpio_pin_t ambiq_gpio_get_pinnum(const struct device *dev, gpio_pin_t pin);
26+
27+
#ifdef __cplusplus
28+
}
29+
#endif
30+
31+
#endif /* ZEPHYR_DRIVERS_GPIO_GPIO_AMBIQ_H_ */

0 commit comments

Comments
 (0)