Skip to content

Commit

Permalink
driver: intc: add MIWU driver support in NPCM series.
Browse files Browse the repository at this point in the history
The device Multi-Input Wake-Up Unit (MIWU) supports the embedded
controller (EC) to exit 'Sleep' or 'Deep Sleep' power state which allows
chip has better power consumption. Also, it provides signal conditioning
such as 'Level' and 'Edge' trigger type and grouping of external
interrupt sources of NVIC. The NPCM series has three identical MIWU
modules: MIWU0, MIWU1, MIWU2. Together, they support a total of 143
internal and/or external wake-up sources.

In this CL, we use device tree files to present the relationship bewteen
MIWU and the other devices in different npcm series. For npcm4 series,
it include:
1. npcm4-miwus-int-map.dtsi: it presents relationship between MIWU group
   and NVIC interrupt in npcm4. Please notice it isn't 1-to-1 mapping.
2. npcm4-miwus-wui-map.dtsi: it presents relationship between input of
   MIWU and its source device such as gpio, timer, eSPI VWs and so on.

This CL also includes:
1. Add MIWU device tree declarations.
2. MIWU api function declarations and implementation to configure signal
   conditions and callback function mechanism. They can be be classified
   into two types. One is for GPIO which connects original gpio callback
   implemetation and the other is for generic devices such as timer,
   eSPI, and so on.
3. Update the npcm gpio driver for the interaction with npcm MIWU
   driver.

Signed-off-by: Tyrone Ting <[email protected]>
  • Loading branch information
warp5tw committed Jun 13, 2024
1 parent 35e72e2 commit 3cd1644
Show file tree
Hide file tree
Showing 11 changed files with 616 additions and 74 deletions.
3 changes: 3 additions & 0 deletions boards/nuvoton/npcm400f_evb/npcm400f_evb_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ CONFIG_UART_CONSOLE=y
# GPIO Driver
CONFIG_GPIO=y
CONFIG_GPIO_NPCM=y

# MIWU Driver
CONFIG_NPCM_MIWU=y
32 changes: 2 additions & 30 deletions drivers/gpio/gpio_npcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ const struct device *npcm_get_gpio_dev(int port)
return gpio_devs[port];
}

#ifdef CONFIG_NPCM_MIWU
void npcm_gpio_enable_io_pads(const struct device *dev, int pin)
{
const struct gpio_npcm_config *const config = dev->config;
Expand Down Expand Up @@ -104,14 +103,6 @@ void npcm_gpio_disable_io_pads(const struct device *dev, int pin)
npcm_miwu_io_disable(io_wui);
}
}
#else
void npcm_gpio_enable_io_pads(const struct device *dev, int pin)
{
}
void npcm_gpio_disable_io_pads(const struct device *dev, int pin)
{
}
#endif

/* GPIO api functions */
static int gpio_npcm_config(const struct device *dev,
Expand Down Expand Up @@ -277,7 +268,6 @@ static int gpio_npcm_port_toggle_bits(const struct device *dev,
return 0;
}

#ifdef CONFIG_NPCM_MIWU
static int gpio_npcm_pin_interrupt_configure(const struct device *dev,
gpio_pin_t pin,
enum gpio_int_mode mode,
Expand Down Expand Up @@ -337,23 +327,12 @@ static int gpio_npcm_pin_interrupt_configure(const struct device *dev,

return 0;
}
#else
static int gpio_npcm_pin_interrupt_configure(const struct device *dev,
gpio_pin_t pin,
enum gpio_int_mode mode,
enum gpio_int_trig trig)
{
return -EINVAL;
}
#endif


#ifdef CONFIG_NPCM_MIWU
static int gpio_npcm_manage_callback(const struct device *dev,
struct gpio_callback *callback, bool set)
{
const struct gpio_npcm_config *const config = dev->config;
struct miwu_io_callback *miwu_cb = (struct miwu_io_callback *)callback;
struct miwu_callback *miwu_cb = (struct miwu_callback *)callback;
int pin = find_lsb_set(callback->pin_mask) - 1;

/* pin_mask should not be zero */
Expand All @@ -373,15 +352,8 @@ static int gpio_npcm_manage_callback(const struct device *dev,
config->port);

/* Insert or remove a IO callback which being called in MIWU ISRs */
return npcm_miwu_manage_gpio_callback(miwu_cb, set);
return npcm_miwu_manage_callback(miwu_cb, set);
}
#else
static int gpio_npcm_manage_callback(const struct device *dev,
struct gpio_callback *callback, bool set)
{
return -EINVAL;
}
#endif

/* GPIO driver registration */
static const struct gpio_driver_api gpio_npcm_driver = {
Expand Down
1 change: 1 addition & 0 deletions drivers/interrupt_controller/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ zephyr_library_sources_ifdef(CONFIG_LEON_IRQMP intc_irqmp.c)
zephyr_library_sources_ifdef(CONFIG_LOAPIC intc_loapic.c intc_system_apic.c)
zephyr_library_sources_ifdef(CONFIG_LOAPIC_SPURIOUS_VECTOR intc_loapic_spurious.S)
zephyr_library_sources_ifdef(CONFIG_MCHP_ECIA_XEC intc_mchp_ecia_xec.c)
zephyr_library_sources_ifdef(CONFIG_NPCM_MIWU intc_npcm_miwu.c)
zephyr_library_sources_ifdef(CONFIG_NPCX_MIWU intc_miwu.c)
zephyr_library_sources_ifdef(CONFIG_PLIC intc_plic.c)
zephyr_library_sources_ifdef(CONFIG_RV32M1_INTMUX intc_rv32m1_intmux.c)
Expand Down
2 changes: 2 additions & 0 deletions drivers/interrupt_controller/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ source "drivers/interrupt_controller/Kconfig.sam0"

source "drivers/interrupt_controller/Kconfig.gic"

source "drivers/interrupt_controller/Kconfig.npcm"

source "drivers/interrupt_controller/Kconfig.npcx"

source "drivers/interrupt_controller/Kconfig.intel_vtd"
Expand Down
13 changes: 13 additions & 0 deletions drivers/interrupt_controller/Kconfig.npcm
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# NPCM GPIO driver configuration options

# Copyright (c) 2024 Nuvoton Technology Corporation.
# SPDX-License-Identifier: Apache-2.0

config NPCM_MIWU
bool "Nuvoton NPCM embedded controller (EC) miwu driver"
default y
depends on SOC_FAMILY_NPCM
help
This option enables the Multi-Input Wake-Up Unit (MIWU) driver
for NPCM family ofprocessors.
This is required for GPIO, RTC, LPC/eSPI interrupt support.
Loading

0 comments on commit 3cd1644

Please sign in to comment.