hw_hpd.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. #include "dm_services.h"
  26. #include "include/gpio_types.h"
  27. #include "hw_gpio.h"
  28. #include "hw_hpd.h"
  29. #include "reg_helper.h"
  30. #include "hpd_regs.h"
  31. #undef FN
  32. #define FN(reg_name, field_name) \
  33. hpd->shifts->field_name, hpd->masks->field_name
  34. #define CTX \
  35. hpd->base.base.ctx
  36. #define REG(reg)\
  37. (hpd->regs->reg)
  38. static void dal_hw_hpd_construct(
  39. struct hw_hpd *pin,
  40. enum gpio_id id,
  41. uint32_t en,
  42. struct dc_context *ctx)
  43. {
  44. dal_hw_gpio_construct(&pin->base, id, en, ctx);
  45. }
  46. static void dal_hw_hpd_destruct(
  47. struct hw_hpd *pin)
  48. {
  49. dal_hw_gpio_destruct(&pin->base);
  50. }
  51. static void destruct(
  52. struct hw_hpd *hpd)
  53. {
  54. dal_hw_hpd_destruct(hpd);
  55. }
  56. static void destroy(
  57. struct hw_gpio_pin **ptr)
  58. {
  59. struct hw_hpd *hpd = HW_HPD_FROM_BASE(*ptr);
  60. destruct(hpd);
  61. kfree(hpd);
  62. *ptr = NULL;
  63. }
  64. static enum gpio_result get_value(
  65. const struct hw_gpio_pin *ptr,
  66. uint32_t *value)
  67. {
  68. struct hw_hpd *hpd = HW_HPD_FROM_BASE(ptr);
  69. uint32_t hpd_delayed = 0;
  70. /* in Interrupt mode we ask for SENSE bit */
  71. if (ptr->mode == GPIO_MODE_INTERRUPT) {
  72. REG_GET(int_status,
  73. DC_HPD_SENSE_DELAYED, &hpd_delayed);
  74. *value = hpd_delayed;
  75. return GPIO_RESULT_OK;
  76. }
  77. /* in any other modes, operate as normal GPIO */
  78. return dal_hw_gpio_get_value(ptr, value);
  79. }
  80. static enum gpio_result set_config(
  81. struct hw_gpio_pin *ptr,
  82. const struct gpio_config_data *config_data)
  83. {
  84. struct hw_hpd *hpd = HW_HPD_FROM_BASE(ptr);
  85. if (!config_data)
  86. return GPIO_RESULT_INVALID_DATA;
  87. REG_UPDATE_2(toggle_filt_cntl,
  88. DC_HPD_CONNECT_INT_DELAY, config_data->config.hpd.delay_on_connect / 10,
  89. DC_HPD_DISCONNECT_INT_DELAY, config_data->config.hpd.delay_on_disconnect / 10);
  90. return GPIO_RESULT_OK;
  91. }
  92. static const struct hw_gpio_pin_funcs funcs = {
  93. .destroy = destroy,
  94. .open = dal_hw_gpio_open,
  95. .get_value = get_value,
  96. .set_value = dal_hw_gpio_set_value,
  97. .set_config = set_config,
  98. .change_mode = dal_hw_gpio_change_mode,
  99. .close = dal_hw_gpio_close,
  100. };
  101. static void construct(
  102. struct hw_hpd *hpd,
  103. enum gpio_id id,
  104. uint32_t en,
  105. struct dc_context *ctx)
  106. {
  107. dal_hw_hpd_construct(hpd, id, en, ctx);
  108. hpd->base.base.funcs = &funcs;
  109. }
  110. struct hw_gpio_pin *dal_hw_hpd_create(
  111. struct dc_context *ctx,
  112. enum gpio_id id,
  113. uint32_t en)
  114. {
  115. struct hw_hpd *hpd;
  116. if (id != GPIO_ID_HPD) {
  117. ASSERT_CRITICAL(false);
  118. return NULL;
  119. }
  120. if ((en < GPIO_HPD_MIN) || (en > GPIO_HPD_MAX)) {
  121. ASSERT_CRITICAL(false);
  122. return NULL;
  123. }
  124. hpd = kzalloc(sizeof(struct hw_hpd), GFP_KERNEL);
  125. if (!hpd) {
  126. ASSERT_CRITICAL(false);
  127. return NULL;
  128. }
  129. construct(hpd, id, en, ctx);
  130. return &hpd->base.base;
  131. }