i2c_engine.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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_I2C_ENGINE_H__
  26. #define __DAL_I2C_ENGINE_H__
  27. enum i2c_channel_operation_result {
  28. I2C_CHANNEL_OPERATION_SUCCEEDED,
  29. I2C_CHANNEL_OPERATION_FAILED,
  30. I2C_CHANNEL_OPERATION_NOT_GRANTED,
  31. I2C_CHANNEL_OPERATION_IS_BUSY,
  32. I2C_CHANNEL_OPERATION_NO_HANDLE_PROVIDED,
  33. I2C_CHANNEL_OPERATION_CHANNEL_IN_USE,
  34. I2C_CHANNEL_OPERATION_CHANNEL_CLIENT_MAX_ALLOWED,
  35. I2C_CHANNEL_OPERATION_ENGINE_BUSY,
  36. I2C_CHANNEL_OPERATION_TIMEOUT,
  37. I2C_CHANNEL_OPERATION_NO_RESPONSE,
  38. I2C_CHANNEL_OPERATION_HW_REQUEST_I2C_BUS,
  39. I2C_CHANNEL_OPERATION_WRONG_PARAMETER,
  40. I2C_CHANNEL_OPERATION_OUT_NB_OF_RETRIES,
  41. I2C_CHANNEL_OPERATION_NOT_STARTED
  42. };
  43. struct i2c_request_transaction_data {
  44. enum i2caux_transaction_action action;
  45. enum i2c_channel_operation_result status;
  46. uint8_t address;
  47. uint32_t length;
  48. uint8_t *data;
  49. };
  50. struct i2c_reply_transaction_data {
  51. uint32_t length;
  52. uint8_t *data;
  53. };
  54. struct i2c_engine;
  55. struct i2c_engine_funcs {
  56. void (*destroy)(
  57. struct i2c_engine **ptr);
  58. uint32_t (*get_speed)(
  59. const struct i2c_engine *engine);
  60. void (*set_speed)(
  61. struct i2c_engine *engine,
  62. uint32_t speed);
  63. bool (*acquire_engine)(
  64. struct i2c_engine *engine,
  65. struct ddc *ddc);
  66. bool (*setup_engine)(
  67. struct i2c_engine *engine);
  68. void (*submit_channel_request)(
  69. struct i2c_engine *engine,
  70. struct i2c_request_transaction_data *request);
  71. void (*process_channel_reply)(
  72. struct i2c_engine *engine,
  73. struct i2c_reply_transaction_data *reply);
  74. enum i2c_channel_operation_result (*get_channel_status)(
  75. struct i2c_engine *engine,
  76. uint8_t *returned_bytes);
  77. };
  78. struct i2c_engine {
  79. struct engine base;
  80. const struct i2c_engine_funcs *funcs;
  81. uint32_t timeout_delay;
  82. };
  83. void dal_i2c_engine_construct(
  84. struct i2c_engine *engine,
  85. struct dc_context *ctx);
  86. void dal_i2c_engine_destruct(
  87. struct i2c_engine *engine);
  88. bool dal_i2c_engine_setup_i2c_engine(
  89. struct i2c_engine *engine);
  90. void dal_i2c_engine_submit_channel_request(
  91. struct i2c_engine *engine,
  92. struct i2c_request_transaction_data *request);
  93. void dal_i2c_engine_process_channel_reply(
  94. struct i2c_engine *engine,
  95. struct i2c_reply_transaction_data *reply);
  96. bool dal_i2c_engine_acquire(
  97. struct engine *ptr,
  98. struct ddc *ddc_handle);
  99. #endif