Skip to content

Commit

Permalink
gpio: implement pin_get_config in npcx driver
Browse files Browse the repository at this point in the history
This commit adds support for pin_get_config function in npcx driver.

Signed-off-by: Michał Barnaś <[email protected]>
  • Loading branch information
barnas-michal authored and carlescufi committed Jul 12, 2022
1 parent f9c9d53 commit 0f60d5a
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions drivers/gpio/gpio_npcx.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,49 @@ static int gpio_npcx_config(const struct device *dev,
return 0;
}

#ifdef CONFIG_GPIO_GET_CONFIG
static int gpio_npcx_pin_get_config(const struct device *port, gpio_pin_t pin,
gpio_flags_t *out_flags)
{
struct gpio_reg *const inst = HAL_INSTANCE(port);
uint32_t mask = BIT(pin);
gpio_flags_t flags = 0;

/* 0:input 1:output */
if (inst->PDIR & mask) {
flags |= GPIO_OUTPUT;

/* 0:push-pull 1:open-drain */
if (inst->PTYPE & mask) {
flags |= GPIO_OPEN_DRAIN;
}

/* 0:low 1:high */
if (inst->PDOUT & mask) {
flags |= GPIO_OUTPUT_HIGH;
} else {
flags |= GPIO_OUTPUT_LOW;
}
} else {
flags |= GPIO_INPUT;

/* 0:disabled 1:enabled pull */
if (inst->PPULL & mask) {
/* 0:pull-up 1:pull-down */
if (inst->PPUD & mask) {
flags |= GPIO_PULL_DOWN;
} else {
flags |= GPIO_PULL_UP;
}
}
}

*out_flags = flags;

return 0;
}
#endif

static int gpio_npcx_port_get_raw(const struct device *dev,
gpio_port_value_t *value)
{
Expand Down Expand Up @@ -311,6 +354,9 @@ static int gpio_npcx_manage_callback(const struct device *dev,
/* GPIO driver registration */
static const struct gpio_driver_api gpio_npcx_driver = {
.pin_configure = gpio_npcx_config,
#ifdef CONFIG_GPIO_GET_CONFIG
.pin_get_config = gpio_npcx_pin_get_config,
#endif
.port_get_raw = gpio_npcx_port_get_raw,
.port_set_masked_raw = gpio_npcx_port_set_masked_raw,
.port_set_bits_raw = gpio_npcx_port_set_bits_raw,
Expand Down

0 comments on commit 0f60d5a

Please sign in to comment.