Skip to content

Commit 5bca309

Browse files
JasonLin-RealTekjhedberg
authored andcommitted
gpio: rts5912: implement power management
support gpio wake up function. change init stage from POST_KERNEL to PRE_KERNEL_1 because uart wrap init need to use the gpio functions. Signed-off-by: Lin Yu-Cheng <[email protected]>
1 parent 75c4be1 commit 5bca309

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

drivers/gpio/gpio_rts5912.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,25 @@ static int gpio_rts5912_port_toggle_bits(const struct device *port, gpio_port_pi
412412
return 0;
413413
}
414414

415-
static gpio_pin_t gpio_rts5912_get_intr_pin(volatile uint32_t *reg_base)
415+
int gpio_rts5912_get_pin_num(const struct gpio_dt_spec *gpio)
416+
{
417+
const struct device *dev = gpio->port;
418+
const struct gpio_rts5912_config *config = dev->config;
419+
uint32_t gcr = (uint32_t)config->reg_base;
420+
421+
return (gcr - (uint32_t)(RTS5912_GPIOA_REG_BASE)) / 4 + gpio->pin;
422+
}
423+
424+
volatile uint32_t *gpio_rts5912_get_port_address(const struct gpio_dt_spec *gpio)
425+
{
426+
const struct device *dev = gpio->port;
427+
const struct gpio_rts5912_config *config = dev->config;
428+
volatile uint32_t *gcr = config->reg_base;
429+
430+
return gcr;
431+
}
432+
433+
gpio_pin_t gpio_rts5912_get_intr_pin(volatile uint32_t *reg_base)
416434
{
417435
gpio_pin_t pin = 0U;
418436

@@ -564,7 +582,7 @@ static DEVICE_API(gpio, gpio_rts5912_driver_api) = {
564582
.num_pins = DT_INST_PROP(id, ngpios), \
565583
}; \
566584
DEVICE_DT_INST_DEFINE(id, gpio_rts5912_init_##id, NULL, &gpio_rts5912_data_##id, \
567-
&gpio_rts5912_config_##id, POST_KERNEL, CONFIG_GPIO_INIT_PRIORITY, \
585+
&gpio_rts5912_config_##id, PRE_KERNEL_1, CONFIG_GPIO_INIT_PRIORITY, \
568586
&gpio_rts5912_driver_api);
569587

570588
DT_INST_FOREACH_STATUS_OKAY(GPIO_RTS5912_INIT)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* Copyright (c) 2024 Realtek Semiconductor Corporation, SIBG-SD7
5+
* Author: Lin Yu-Cheng <[email protected]>
6+
*/
7+
8+
#ifndef ZEPHYR_DRIVERS_GPIO_GPIO_RTS5912_H_
9+
#define ZEPHYR_DRIVERS_GPIO_GPIO_RTS5912_H_
10+
11+
#include <zephyr/device.h>
12+
#include <zephyr/drivers/gpio.h>
13+
#include <reg/reg_gpio.h>
14+
15+
#ifdef __cplusplus
16+
extern "C" {
17+
#endif
18+
19+
gpio_pin_t gpio_rts5912_get_intr_pin(volatile uint32_t *reg_base);
20+
21+
static ALWAYS_INLINE void gpio_rts5912_set_wakeup_pin(uint32_t pin_num)
22+
{
23+
volatile uint32_t *gcr =
24+
(volatile uint32_t *)(((uint32_t *)(DT_REG_ADDR(DT_NODELABEL(gpioa)))) + pin_num);
25+
26+
*gcr &= ~(GPIO_GCR_MFCTRL_Msk | GPIO_GCR_DIR_Msk);
27+
*gcr |= BIT(GPIO_GCR_INTCTRL_Pos) | GPIO_GCR_INTSTS_Msk | GPIO_GCR_INTEN_Msk |
28+
GPIO_GCR_INDETEN_Msk;
29+
}
30+
31+
int gpio_rts5912_get_pin_num(const struct gpio_dt_spec *gpio);
32+
33+
uint32_t gpio_rts5912_get_port_address(const struct gpio_dt_spec *gpio);
34+
35+
#ifdef __cplusplus
36+
}
37+
#endif
38+
39+
#endif /* ZEPHYR_DRIVERS_GPIO_GPIO_RTS5912_H_ */

0 commit comments

Comments
 (0)