i2c_engine.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. /*
  27. * Pre-requisites: headers required by header of this unit
  28. */
  29. #include "include/i2caux_interface.h"
  30. #include "engine.h"
  31. /*
  32. * Header of this unit
  33. */
  34. #include "i2c_engine.h"
  35. /*
  36. * Post-requisites: headers required by this unit
  37. */
  38. /*
  39. * This unit
  40. */
  41. #define FROM_ENGINE(ptr) \
  42. container_of((ptr), struct i2c_engine, base)
  43. bool dal_i2c_engine_acquire(
  44. struct engine *engine,
  45. struct ddc *ddc_handle)
  46. {
  47. struct i2c_engine *i2c_engine = FROM_ENGINE(engine);
  48. uint32_t counter = 0;
  49. bool result;
  50. do {
  51. result = i2c_engine->funcs->acquire_engine(
  52. i2c_engine, ddc_handle);
  53. if (result)
  54. break;
  55. /* i2c_engine is busy by VBios, lets wait and retry */
  56. udelay(10);
  57. ++counter;
  58. } while (counter < 2);
  59. if (result) {
  60. if (!i2c_engine->funcs->setup_engine(i2c_engine)) {
  61. engine->funcs->release_engine(engine);
  62. result = false;
  63. }
  64. }
  65. return result;
  66. }
  67. bool dal_i2c_engine_setup_i2c_engine(
  68. struct i2c_engine *engine)
  69. {
  70. /* Derivative classes do not have to override this */
  71. return true;
  72. }
  73. void dal_i2c_engine_submit_channel_request(
  74. struct i2c_engine *engine,
  75. struct i2c_request_transaction_data *request)
  76. {
  77. }
  78. void dal_i2c_engine_process_channel_reply(
  79. struct i2c_engine *engine,
  80. struct i2c_reply_transaction_data *reply)
  81. {
  82. }
  83. void dal_i2c_engine_construct(
  84. struct i2c_engine *engine,
  85. struct dc_context *ctx)
  86. {
  87. dal_i2caux_construct_engine(&engine->base, ctx);
  88. engine->timeout_delay = 0;
  89. }
  90. void dal_i2c_engine_destruct(
  91. struct i2c_engine *engine)
  92. {
  93. dal_i2caux_destruct_engine(&engine->base);
  94. }