hw_gpio.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * Copyright 2012-15 Advanced Micro Devices, Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * Authors: AMD
  23. *
  24. */
  25. #ifndef __DAL_HW_GPIO_H__
  26. #define __DAL_HW_GPIO_H__
  27. #include "gpio_regs.h"
  28. #define FROM_HW_GPIO_PIN(ptr) \
  29. container_of((ptr), struct hw_gpio, base)
  30. struct addr_mask {
  31. uint32_t addr;
  32. uint32_t mask;
  33. };
  34. struct hw_gpio_pin {
  35. const struct hw_gpio_pin_funcs *funcs;
  36. enum gpio_id id;
  37. uint32_t en;
  38. enum gpio_mode mode;
  39. bool opened;
  40. struct dc_context *ctx;
  41. };
  42. struct hw_gpio_pin_funcs {
  43. void (*destroy)(
  44. struct hw_gpio_pin **ptr);
  45. bool (*open)(
  46. struct hw_gpio_pin *pin,
  47. enum gpio_mode mode);
  48. enum gpio_result (*get_value)(
  49. const struct hw_gpio_pin *pin,
  50. uint32_t *value);
  51. enum gpio_result (*set_value)(
  52. const struct hw_gpio_pin *pin,
  53. uint32_t value);
  54. enum gpio_result (*set_config)(
  55. struct hw_gpio_pin *pin,
  56. const struct gpio_config_data *config_data);
  57. enum gpio_result (*change_mode)(
  58. struct hw_gpio_pin *pin,
  59. enum gpio_mode mode);
  60. void (*close)(
  61. struct hw_gpio_pin *pin);
  62. };
  63. struct hw_gpio;
  64. /* Register indices are represented by member variables
  65. * and are to be filled in by constructors of derived classes.
  66. * These members permit the use of common code
  67. * for programming registers, where the sequence is the same
  68. * but register sets are different.
  69. * Some GPIOs have HW mux which allows to choose
  70. * what is the source of the signal in HW mode */
  71. struct hw_gpio_pin_reg {
  72. struct addr_mask DC_GPIO_DATA_MASK;
  73. struct addr_mask DC_GPIO_DATA_A;
  74. struct addr_mask DC_GPIO_DATA_EN;
  75. struct addr_mask DC_GPIO_DATA_Y;
  76. };
  77. struct hw_gpio_mux_reg {
  78. struct addr_mask GPIO_MUX_CONTROL;
  79. struct addr_mask GPIO_MUX_STEREO_SEL;
  80. };
  81. struct hw_gpio {
  82. struct hw_gpio_pin base;
  83. /* variables to save register value */
  84. struct {
  85. uint32_t mask;
  86. uint32_t a;
  87. uint32_t en;
  88. uint32_t mux;
  89. } store;
  90. /* GPIO MUX support */
  91. bool mux_supported;
  92. const struct gpio_registers *regs;
  93. };
  94. #define HW_GPIO_FROM_BASE(hw_gpio_pin) \
  95. container_of((hw_gpio_pin), struct hw_gpio, base)
  96. void dal_hw_gpio_construct(
  97. struct hw_gpio *pin,
  98. enum gpio_id id,
  99. uint32_t en,
  100. struct dc_context *ctx);
  101. bool dal_hw_gpio_open(
  102. struct hw_gpio_pin *pin,
  103. enum gpio_mode mode);
  104. enum gpio_result dal_hw_gpio_get_value(
  105. const struct hw_gpio_pin *pin,
  106. uint32_t *value);
  107. enum gpio_result dal_hw_gpio_config_mode(
  108. struct hw_gpio *pin,
  109. enum gpio_mode mode);
  110. void dal_hw_gpio_destruct(
  111. struct hw_gpio *pin);
  112. enum gpio_result dal_hw_gpio_set_value(
  113. const struct hw_gpio_pin *ptr,
  114. uint32_t value);
  115. enum gpio_result dal_hw_gpio_change_mode(
  116. struct hw_gpio_pin *ptr,
  117. enum gpio_mode mode);
  118. void dal_hw_gpio_close(
  119. struct hw_gpio_pin *ptr);
  120. #endif