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