Skip to content

Commit

Permalink
driver: gpio: Add pin_configure api for creg_gpio driver
Browse files Browse the repository at this point in the history
Update pin_configure api for creg_gpio driver

Signed-off-by: Siyuan Cheng <siyuanc@synopsys.com>
  • Loading branch information
Siyuan Cheng authored and cfriedt committed Jan 28, 2023
1 parent d1c0f18 commit 59130b1
Showing 1 changed file with 44 additions and 7 deletions.
51 changes: 44 additions & 7 deletions drivers/gpio/gpio_creg_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,6 @@ struct creg_gpio_config {
uint8_t on_val;
};

static int pin_config(const struct device *dev,
gpio_pin_t pin,
gpio_flags_t flags)
{
return -ENOTSUP;
}

static int port_get(const struct device *dev,
gpio_port_value_t *value)
{
Expand Down Expand Up @@ -119,6 +112,50 @@ static int pin_interrupt_configure(const struct device *dev,
return -ENOTSUP;
}

static int pin_config(const struct device *dev,
gpio_pin_t pin,
gpio_flags_t flags)
{
const struct creg_gpio_config *cfg = dev->config;
uint32_t io_flags;
bool pin_is_output;

/* Check for invalid pin number */
if (pin >= cfg->ngpios) {
return -EINVAL;
}

/* Does not support disconnected pin, and
* not supporting both input/output at same time.
*/
io_flags = flags & (GPIO_INPUT | GPIO_OUTPUT);
if ((io_flags == GPIO_DISCONNECTED)
|| (io_flags == (GPIO_INPUT | GPIO_OUTPUT))) {
return -ENOTSUP;
}

/* No open-drain support */
if ((flags & GPIO_SINGLE_ENDED) != 0U) {
return -ENOTSUP;
}

/* Does not support pull-up/pull-down */
if ((flags & (GPIO_PULL_UP | GPIO_PULL_DOWN)) != 0U) {
return -ENOTSUP;
}

pin_is_output = (flags & GPIO_OUTPUT) != 0U;
if (pin_is_output) {
if ((flags & GPIO_OUTPUT_INIT_HIGH) != 0U) {
return port_set_bits(dev, BIT(pin));
} else if ((flags & GPIO_OUTPUT_INIT_LOW) != 0U) {
return port_clear_bits(dev, BIT(pin));
}
}

return -ENOTSUP;
}

/**
* @brief Initialization function of creg_gpio
*
Expand Down

0 comments on commit 59130b1

Please sign in to comment.