dw_gpio.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /* ------------------------------------------
  2. * Copyright (c) 2016, Synopsys, Inc. All rights reserved.
  3. * Redistribution and use in source and binary forms, with or without modification,
  4. * are permitted provided that the following conditions are met:
  5. * 1) Redistributions of source code must retain the above copyright notice, this
  6. * list of conditions and the following disclaimer.
  7. * 2) Redistributions in binary form must reproduce the above copyright notice,
  8. * this list of conditions and the following disclaimer in the documentation and/or
  9. * other materials provided with the distribution.
  10. * 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may
  11. * be used to endorse or promote products derived from this software without
  12. * specific prior written permission.
  13. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  14. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  15. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  16. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  17. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  18. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  19. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  20. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  21. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  22. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. *
  24. * \version 2016.05
  25. * \date 2014-07-22
  26. * \author Wayne Ren(Wei.Ren@synopsys.com)
  27. --------------------------------------------- */
  28. /**
  29. * \file
  30. * \brief designware gpio driver
  31. * \ingroup DEVICE_DW_GPIO
  32. * \brief Designware GPIO driver header file
  33. */
  34. #ifndef _DW_GPIO_H_
  35. #define _DW_GPIO_H_
  36. #include "device/device_hal/inc/dev_gpio.h"
  37. #include "inc/arc/arc_exception.h"
  38. #define DW_GPIO_PORT_A (0x00)
  39. #define DW_GPIO_PORT_B (0x01)
  40. #define DW_GPIO_PORT_C (0x02)
  41. #define DW_GPIO_PORT_D (0x03)
  42. #define DW_GPIO_INT_ACT_LOW GPIO_INT_ACTIVE_LOW
  43. #define DW_GPIO_INT_ACT_HIGH GPIO_INT_ACTIVE_HIGH
  44. #define DW_GPIO_INT_LEVEL_TRIG GPIO_INT_LEVEL_TRIG
  45. #define DW_GPIO_INT_EDGE_TRIG GPIO_INT_EDGE_TRIG
  46. #define DW_GPIO_INT_NO_DEBOUNCE GPIO_INT_NO_DEBOUNCE
  47. #define DW_GPIO_INT_DEBOUNCE GPIO_INT_DEBOUNCE
  48. #define DW_GPIO_ALL_ZERO (0x0)
  49. #define DW_GPIO_ALL_ONE (0xffffffff)
  50. #define DW_GPIO_MASK_ALL (0xffffffff)
  51. #define DW_GPIO_INPUT_ALL (0x0)
  52. #define DW_GPIO_OUTPUT_ALL (0xffffffff)
  53. /**
  54. * \name DesignWare GPIO Register Structure
  55. * \brief contains definitions of DesignWare GPIO register structure.
  56. * @{
  57. */
  58. typedef struct port_ctrl {
  59. uint32_t DR;
  60. uint32_t DDR;
  61. uint32_t CTRL;
  62. } PORT_CTRL;
  63. /* DW GPIO PORTS Registers */
  64. typedef volatile struct dw_gpio_reg {
  65. PORT_CTRL SWPORTS[4];
  66. uint32_t INTEN; /*!< (0x30) */
  67. uint32_t INTMASK; /*!< (0x34) */
  68. uint32_t INTTYPE_LEVEL; /*!< (0x38) */
  69. uint32_t INT_POLARITY; /*!< (0x3c) */
  70. uint32_t INTSTATUS; /*!< (0x40) */
  71. uint32_t RAW_INTSTATUS; /*!< (0x44) */
  72. uint32_t DEBOUNCE; /*!< (0x48) */
  73. uint32_t PORTA_EOI; /*!< (0x4c) */
  74. uint32_t EXT_PORTS[4]; /*!< (0x50) -A
  75. (0x54) -B
  76. (0x58) -C
  77. (0x5c) -D */
  78. uint32_t LS_SYNC; /*!< (0x60) */
  79. uint32_t ID_CODE; /*!< (0x64) */
  80. uint32_t RESERVED_3; /*!< (0x68) */
  81. uint32_t VER_ID_CODE; /*!< (0x6c) */
  82. uint32_t CONFIG_REG2; /*!< (0x70) */
  83. uint32_t CONFIG_REG1; /*!< (0x74) */
  84. } DW_GPIO_REG, *DW_GPIO_REG_PTR;
  85. /** @} */
  86. /** interrupt handler for each port bit */
  87. typedef struct dw_gpio_bit_isr {
  88. uint32_t int_bit_max_cnt; /*!< max bit count for each port */
  89. DEV_GPIO_HANDLER *int_bit_handler_ptr; /*!< interrupt handler pointer */
  90. } DW_GPIO_BIT_ISR, * DW_GPIO_BIT_ISR_PTR;
  91. /**
  92. * \brief DesignWare GPIO control structure definition
  93. * \details implement of dev_gpio_info::gpio_ctrl
  94. */
  95. typedef struct dw_gpio_port {
  96. uint32_t no; /*!< gpio port number */
  97. DW_GPIO_REG_PTR regs; /*!< gpio port register */
  98. uint32_t intno; /*!< gpio interrupt vector number */
  99. uint32_t valid_bit_mask; /*!< valid bit mask of gpio port */
  100. INT_HANDLER int_handler; /*!< gpio interrupt handler */
  101. DW_GPIO_BIT_ISR_PTR gpio_bit_isr; /*!< gpio bit handler struct */
  102. } DW_GPIO_PORT, *DW_GPIO_PORT_PTR;
  103. #ifdef __cplusplus
  104. extern "C" {
  105. #endif
  106. /**
  107. * \name DesignWare GPIO Function Declaration
  108. * \brief contains declarations of designware gpio functions.
  109. * \details This are only used in gpio object implementation source file
  110. * @{
  111. */
  112. extern int32_t dw_gpio_open(DEV_GPIO *gpio_obj, uint32_t dir);
  113. extern int32_t dw_gpio_close(DEV_GPIO *gpio_obj);
  114. extern int32_t dw_gpio_read(DEV_GPIO *gpio_obj, uint32_t *val, uint32_t mask);
  115. extern int32_t dw_gpio_write(DEV_GPIO *gpio_obj, uint32_t val, uint32_t mask);
  116. extern int32_t dw_gpio_control(DEV_GPIO *gpio_obj, uint32_t ctrl_cmd, void *param);
  117. extern int32_t dw_gpio_isr_handler(DEV_GPIO *gpio_obj, void *ptr);
  118. #ifdef __cplusplus
  119. }
  120. #endif
  121. /** @} */
  122. #endif /* _DW_GPIO_H_ */