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 #include "dm_services.h" 27 28 /* 29 * Pre-requisites: headers required by header of this unit 30 */ 31 #include "include/i2caux_interface.h" 32 #include "../engine.h" 33 #include "../i2c_engine.h" 34 #include "../i2c_sw_engine.h" 35 36 /* 37 * Header of this unit 38 */ 39 40 #include "i2c_sw_engine_dce80.h" 41 42 /* 43 * Post-requisites: headers required by this unit 44 */ 45 46 #include "dce/dce_8_0_d.h" 47 #include "dce/dce_8_0_sh_mask.h" 48 49 /* 50 * This unit 51 */ 52 53 /* not used 54 static const uint32_t ddc_hw_status_addr[] = { 55 mmDC_I2C_DDC1_HW_STATUS, 56 mmDC_I2C_DDC2_HW_STATUS, 57 mmDC_I2C_DDC3_HW_STATUS, 58 mmDC_I2C_DDC4_HW_STATUS, 59 mmDC_I2C_DDC5_HW_STATUS, 60 mmDC_I2C_DDC6_HW_STATUS, 61 mmDC_I2C_DDCVGA_HW_STATUS 62 }; 63 */ 64 65 /* 66 * @brief 67 * Cast 'struct i2c_sw_engine *' 68 * to 'struct i2c_sw_engine_dce80 *' 69 */ 70 #define FROM_I2C_SW_ENGINE(ptr) \ 71 container_of((ptr), struct i2c_sw_engine_dce80, base) 72 73 /* 74 * @brief 75 * Cast 'struct i2c_engine *' 76 * to 'struct i2c_sw_engine_dce80 *' 77 */ 78 #define FROM_I2C_ENGINE(ptr) \ 79 FROM_I2C_SW_ENGINE(container_of((ptr), struct i2c_sw_engine, base)) 80 81 /* 82 * @brief 83 * Cast 'struct engine *' 84 * to 'struct i2c_sw_engine_dce80 *' 85 */ 86 #define FROM_ENGINE(ptr) \ 87 FROM_I2C_ENGINE(container_of((ptr), struct i2c_engine, base)) 88 89 static void release_engine( 90 struct engine *engine) 91 { 92 93 } 94 95 static void destruct( 96 struct i2c_sw_engine_dce80 *engine) 97 { 98 dal_i2c_sw_engine_destruct(&engine->base); 99 } 100 101 static void destroy( 102 struct i2c_engine **engine) 103 { 104 struct i2c_sw_engine_dce80 *sw_engine = FROM_I2C_ENGINE(*engine); 105 106 destruct(sw_engine); 107 108 kfree(sw_engine); 109 110 *engine = NULL; 111 } 112 113 static bool acquire_engine( 114 struct i2c_engine *engine, 115 struct ddc *ddc_handle) 116 { 117 return dal_i2caux_i2c_sw_engine_acquire_engine(engine, ddc_handle); 118 } 119 120 static const struct i2c_engine_funcs i2c_engine_funcs = { 121 .acquire_engine = acquire_engine, 122 .destroy = destroy, 123 .get_speed = dal_i2c_sw_engine_get_speed, 124 .set_speed = dal_i2c_sw_engine_set_speed, 125 .setup_engine = dal_i2c_engine_setup_i2c_engine, 126 .submit_channel_request = dal_i2c_sw_engine_submit_channel_request, 127 .process_channel_reply = dal_i2c_engine_process_channel_reply, 128 .get_channel_status = dal_i2c_sw_engine_get_channel_status, 129 }; 130 131 static const struct engine_funcs engine_funcs = { 132 .release_engine = release_engine, 133 .get_engine_type = dal_i2c_sw_engine_get_engine_type, 134 .acquire = dal_i2c_engine_acquire, 135 .submit_request = dal_i2c_sw_engine_submit_request, 136 }; 137 138 static void construct( 139 struct i2c_sw_engine_dce80 *engine, 140 const struct i2c_sw_engine_dce80_create_arg *arg) 141 { 142 struct i2c_sw_engine_create_arg arg_base; 143 144 arg_base.ctx = arg->ctx; 145 arg_base.default_speed = arg->default_speed; 146 147 dal_i2c_sw_engine_construct(&engine->base, &arg_base); 148 149 engine->base.base.base.funcs = &engine_funcs; 150 engine->base.base.funcs = &i2c_engine_funcs; 151 engine->base.default_speed = arg->default_speed; 152 engine->engine_id = arg->engine_id; 153 } 154 155 struct i2c_engine *dal_i2c_sw_engine_dce80_create( 156 const struct i2c_sw_engine_dce80_create_arg *arg) 157 { 158 struct i2c_sw_engine_dce80 *engine; 159 160 if (!arg) { 161 BREAK_TO_DEBUGGER(); 162 return NULL; 163 } 164 165 engine = kzalloc(sizeof(struct i2c_sw_engine_dce80), GFP_KERNEL); 166 167 if (!engine) { 168 BREAK_TO_DEBUGGER(); 169 return NULL; 170 } 171 172 construct(engine, arg); 173 return &engine->base.base; 174 } 175 176