api: gpio: Align GPIO dt-bindings flags with Linux DTS

This commit makes following changes to GPIO dt-bindings flags:
- Added GPIO_ACTIVE_LOW, GPIO_ACTIVE_HIGH to indicate pin active state.
- Added GPIO_OPEN_DRAIN, GPIO_OPEN_SOURCE to configure single ended pin
  driving mode.
- Added GPIO_PULL_UP, GPIO_PULL_DOWN flags.
- GPIO_INPUT, GPIO_OUTPUT to configure pin as input or output.
- Added GPIO_OUTPUT_LOW, GPIO_OUTPUT_HIGH flags to initialize output
  in low or high state.
- reworked GPIO_INT_* flags to configure pin interrupts.
- following flags were deprecated: GPIO_DIR_*, GPIO_DS_DISCONNECT_*,
  GPIO_PUD_*, GPIO_INT_ACTIVE_*, GPIO_INT_DOUBLE_EDGE, GPIO_POL_*.

To be aligned with Linux DTS standard any GPIO flags that should not be
used in DTS files are moved from include/dt-bindings/gpio/gpio.h file to
include/drivers/gpio.h with an exception of several old flags which
removal would cause DTS compilation errors. Those remaining old flags
will be removed from include/dt-bindings/gpio/gpio.h at a later stage.

Signed-off-by: Piotr Mienkowski <piotr.mienkowski@gmail.com>
This commit is contained in:
Piotr Mienkowski 2019-01-22 10:13:02 +01:00 committed by Carles Cufí
commit af972c2c47
2 changed files with 398 additions and 140 deletions

View file

@ -1,4 +1,5 @@
/*
* Copyright (c) 2019 Piotr Mienkowski
* Copyright (c) 2018 Linaro Limited
*
* SPDX-License-Identifier: Apache-2.0
@ -6,175 +7,89 @@
#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_GPIO_GPIO_H_
#define ZEPHYR_INCLUDE_DT_BINDINGS_GPIO_GPIO_H_
/**
* @name GPIO direction flags
* The `GPIO_DIR_*` flags are used with `gpio_pin_configure` or `gpio_port_configure`,
* to specify whether a GPIO pin will be used for input or output.
* @brief GPIO Driver APIs
* @defgroup gpio_interface GPIO Driver APIs
* @ingroup io_interfaces
* @{
*/
/** GPIO pin to be input. */
#define GPIO_DIR_IN (0 << 0)
/** GPIO pin to be output. */
#define GPIO_DIR_OUT (1 << 0)
/**
* @name GPIO pin active level flags
* @{
*/
/** GPIO pin is active (has logical value '1') in low state. */
#define GPIO_ACTIVE_LOW (1 << 0)
/** GPIO pin is active (has logical value '1') in high state. */
#define GPIO_ACTIVE_HIGH (0 << 0)
/** @cond INTERNAL_HIDDEN */
#define GPIO_DIR_MASK 0x1
/** @endcond */
/** @} */
/**
* @name GPIO interrupt flags
* The `GPIO_INT_*` flags are used with `gpio_pin_configure` or `gpio_port_configure`,
* to specify how input GPIO pins will trigger interrupts.
* @name GPIO pin drive flags
* @{
*/
/** GPIO pin to trigger interrupt. */
#define GPIO_INT (1 << 1)
/** GPIO pin trigger on level low or falling edge. */
#define GPIO_INT_ACTIVE_LOW (0 << 2)
/** @cond INTERNAL_HIDDEN */
/** GPIO pin trigger on level high or rising edge. */
#define GPIO_INT_ACTIVE_HIGH (1 << 2)
/* Configures GPIO output in single-ended mode (open drain or open source). */
#define GPIO_SINGLE_ENDED (1 << 1)
/* Configures GPIO output in push-pull mode */
#define GPIO_PUSH_PULL (0 << 1)
/** Enable GPIO pin debounce. */
#define GPIO_INT_DEBOUNCE (1 << 4)
/* Indicates single ended open drain mode (wired AND). */
#define GPIO_LINE_OPEN_DRAIN (1 << 2)
/* Indicates single ended open source mode (wired OR). */
#define GPIO_LINE_OPEN_SOURCE (0 << 2)
/** Do Level trigger. */
#define GPIO_INT_LEVEL (0 << 5)
/** @endcond */
/** Do Edge trigger. */
#define GPIO_INT_EDGE (1 << 5)
/** Interrupt triggers on both rising and falling edge.
* Must be combined with GPIO_INT_EDGE.
/** Configures GPIO output in open drain mode (wired AND).
*
* @note 'Open Drain' mode also known as 'Open Collector' is an output
* configuration which behaves like a switch that is either connected to ground
* or disconnected.
*/
#define GPIO_INT_DOUBLE_EDGE (1 << 6)
#define GPIO_OPEN_DRAIN (GPIO_SINGLE_ENDED | GPIO_LINE_OPEN_DRAIN)
/** Configures GPIO output in open source mode (wired OR).
*
* @note 'Open Source' is a term used by software engineers to describe output
* mode opposite to 'Open Drain'. It behaves like a switch that is either
* connected to power supply or disconnected. There exist no corresponding
* hardware schematic and the term is generally unknown to hardware engineers.
*/
#define GPIO_OPEN_SOURCE (GPIO_SINGLE_ENDED | GPIO_LINE_OPEN_SOURCE)
/** @} */
/**
* @name GPIO polarity flags
* The `GPIO_POL_*` flags are used with `gpio_pin_configure` or `gpio_port_configure`,
* to specify the polarity of a GPIO pin.
* @name GPIO pin bias flags
* @{
*/
/** @cond INTERNAL_HIDDEN */
#define GPIO_POL_POS 7
/** @endcond */
/** GPIO pin polarity is normal. */
#define GPIO_POL_NORMAL (0 << GPIO_POL_POS)
/** GPIO pin polarity is inverted. */
#define GPIO_POL_INV (1 << GPIO_POL_POS)
/** @cond INTERNAL_HIDDEN */
#define GPIO_POL_MASK (1 << GPIO_POL_POS)
/** @endcond */
/** @} */
/**
* @name GPIO pull flags
* The `GPIO_PUD_*` flags are used with `gpio_pin_configure` or `gpio_port_configure`,
* to specify the pull-up or pull-down electrical configuration of a GPIO pin.
* @{
*/
/** @cond INTERNAL_HIDDEN */
#define GPIO_PUD_POS 8
/** @endcond */
/** Pin is neither pull-up nor pull-down. */
#define GPIO_PUD_NORMAL (0 << GPIO_PUD_POS)
/** Enable GPIO pin pull-up. */
#define GPIO_PUD_PULL_UP (1 << GPIO_PUD_POS)
/** Enables GPIO pin pull-up. */
#define GPIO_PULL_UP (1 << 4)
/** Enable GPIO pin pull-down. */
#define GPIO_PUD_PULL_DOWN (2 << GPIO_PUD_POS)
#define GPIO_PULL_DOWN (1 << 5)
/** @cond INTERNAL_HIDDEN */
#define GPIO_PUD_MASK (3 << GPIO_PUD_POS)
/** @endcond */
/** @} */
/**
* @name GPIO drive strength flags
* The `GPIO_DS_*` flags are used with `gpio_pin_configure` or `gpio_port_configure`,
* to specify the drive strength configuration of a GPIO pin.
* @cond INTERNAL_HIDDEN
*
* The drive strength of individual pins can be configured
* independently for when the pin output is low and high.
*
* The `GPIO_DS_*_LOW` enumerations define the drive strength of a pin
* when output is low.
* The `GPIO_DS_*_HIGH` enumerations define the drive strength of a pin
* when output is high.
*
* The `DISCONNECT` drive strength indicates that the pin is placed in a
* high impedance state and not driven, this option is used to
* configure hardware that supports a open collector drive mode.
*
* The interface supports two different drive strengths:
* `DFLT` - The lowest drive strength supported by the HW
* `ALT` - The highest drive strength supported by the HW
*
* On hardware that supports only one standard drive strength, both
* `DFLT` and `ALT` have the same behavior.
*
* On hardware that does not support a disconnect mode, `DISCONNECT`
* will behave the same as `DFLT`.
* @{
* Following defines are deprecated and shouldn't be used in DTS files.
*/
/** @cond INTERNAL_HIDDEN */
#define GPIO_DS_LOW_POS 12
#define GPIO_DS_LOW_MASK (0x3 << GPIO_DS_LOW_POS)
#define GPIO_DIR_OUT (1 << 9) /* GPIO_OUTPUT */
#define GPIO_PUD_PULL_UP GPIO_PULL_UP
#define GPIO_PUD_PULL_DOWN GPIO_PULL_DOWN
#define GPIO_INT_ACTIVE_LOW (1 << 15) /* GPIO_INT_LOW_0 */
#define GPIO_INT_ACTIVE_HIGH (1 << 16) /* GPIO_INT_HIGH_1 */
/** @endcond */
/** Default drive strength standard when GPIO pin output is low.
/**
* @}
*/
#define GPIO_DS_DFLT_LOW (0x0 << GPIO_DS_LOW_POS)
/** Alternative drive strength when GPIO pin output is low.
* For hardware that does not support configurable drive strength
* use the default drive strength.
*/
#define GPIO_DS_ALT_LOW (0x1 << GPIO_DS_LOW_POS)
/** Disconnect pin when GPIO pin output is low.
* For hardware that does not support disconnect use the default
* drive strength.
*/
#define GPIO_DS_DISCONNECT_LOW (0x3 << GPIO_DS_LOW_POS)
/** @cond INTERNAL_HIDDEN */
#define GPIO_DS_HIGH_POS 14
#define GPIO_DS_HIGH_MASK (0x3 << GPIO_DS_HIGH_POS)
/** @endcond */
/** Default drive strength when GPIO pin output is high.
*/
#define GPIO_DS_DFLT_HIGH (0x0 << GPIO_DS_HIGH_POS)
/** Alternative drive strength when GPIO pin output is high.
* For hardware that does not support configurable drive strengths
* use the default drive strength.
*/
#define GPIO_DS_ALT_HIGH (0x1 << GPIO_DS_HIGH_POS)
/** Disconnect pin when GPIO pin output is high.
* For hardware that does not support disconnect use the default
* drive strength.
*/
#define GPIO_DS_DISCONNECT_HIGH (0x3 << GPIO_DS_HIGH_POS)
/** @} */
#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_GPIO_GPIO_H_ */