2 * Copyright 2012-15 Advanced Micro Devices, Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
26 #include "dm_services.h"
29 * Pre-requisites: headers required by header of this unit
31 #include "include/i2caux_interface.h"
32 #include "../i2caux.h"
33 #include "../engine.h"
34 #include "../i2c_engine.h"
35 #include "../i2c_sw_engine.h"
36 #include "../i2c_hw_engine.h"
41 #include "i2caux_dce110.h"
43 #include "i2c_sw_engine_dce110.h"
44 #include "i2c_hw_engine_dce110.h"
45 #include "aux_engine_dce110.h"
51 * Post-requisites: headers required by this unit
57 /*cast pointer to struct i2caux TO pointer to struct i2caux_dce110*/
58 #define FROM_I2C_AUX(ptr) \
59 container_of((ptr), struct i2caux_dce110, base)
62 struct i2caux_dce110 *i2caux_dce110)
64 dal_i2caux_destruct(&i2caux_dce110->base);
68 struct i2caux **i2c_engine)
70 struct i2caux_dce110 *i2caux_dce110 = FROM_I2C_AUX(*i2c_engine);
72 destruct(i2caux_dce110);
79 static struct i2c_engine *acquire_i2c_hw_engine(
80 struct i2caux *i2caux,
83 struct i2caux_dce110 *i2caux_dce110 = FROM_I2C_AUX(i2caux);
85 struct i2c_engine *engine = NULL;
86 /* generic hw engine is not used for EDID read
87 * It may be needed for external i2c device, like thermal chip,
88 * TODO will be implemented when needed.
89 * check dce80 bool non_generic for generic hw engine;
95 if (ddc->hw_info.hw_supported) {
96 enum gpio_ddc_line line = dal_ddc_get_line(ddc);
98 if (line < GPIO_DDC_LINE_COUNT)
99 engine = i2caux->i2c_hw_engines[line];
105 if (!i2caux_dce110->i2c_hw_buffer_in_use &&
106 engine->base.funcs->acquire(&engine->base, ddc)) {
107 i2caux_dce110->i2c_hw_buffer_in_use = true;
114 static void release_engine(
115 struct i2caux *i2caux,
116 struct engine *engine)
118 struct i2caux_dce110 *i2caux_dce110 = FROM_I2C_AUX(i2caux);
120 if (engine->funcs->get_engine_type(engine) ==
121 I2CAUX_ENGINE_TYPE_I2C_DDC_HW)
122 i2caux_dce110->i2c_hw_buffer_in_use = false;
124 dal_i2caux_release_engine(i2caux, engine);
127 static const enum gpio_ddc_line hw_ddc_lines[] = {
136 static const enum gpio_ddc_line hw_aux_lines[] = {
146 static const struct i2caux_funcs i2caux_funcs = {
148 .acquire_i2c_hw_engine = acquire_i2c_hw_engine,
149 .release_engine = release_engine,
150 .acquire_i2c_sw_engine = dal_i2caux_acquire_i2c_sw_engine,
151 .acquire_aux_engine = dal_i2caux_acquire_aux_engine,
154 #include "dce/dce_11_0_d.h"
155 #include "dce/dce_11_0_sh_mask.h"
157 /* set register offset */
158 #define SR(reg_name)\
159 .reg_name = mm ## reg_name
161 /* set register offset with instance */
162 #define SRI(reg_name, block, id)\
163 .reg_name = mm ## block ## id ## _ ## reg_name
165 #define aux_regs(id)\
167 AUX_COMMON_REG_LIST(id), \
168 .AUX_RESET_MASK = AUX_CONTROL__AUX_RESET_MASK \
171 #define hw_engine_regs(id)\
173 I2C_HW_ENGINE_COMMON_REG_LIST(id) \
176 static const struct dce110_aux_registers dce110_aux_regs[] = {
185 static const struct dce110_i2c_hw_engine_registers i2c_hw_engine_regs[] = {
194 static const struct dce110_i2c_hw_engine_shift i2c_shift = {
195 I2C_COMMON_MASK_SH_LIST_DCE110(__SHIFT)
198 static const struct dce110_i2c_hw_engine_mask i2c_mask = {
199 I2C_COMMON_MASK_SH_LIST_DCE110(_MASK)
202 void dal_i2caux_dce110_construct(
203 struct i2caux_dce110 *i2caux_dce110,
204 struct dc_context *ctx,
205 unsigned int num_i2caux_inst,
206 const struct dce110_aux_registers aux_regs[],
207 const struct dce110_i2c_hw_engine_registers i2c_hw_engine_regs[],
208 const struct dce110_i2c_hw_engine_shift *i2c_shift,
209 const struct dce110_i2c_hw_engine_mask *i2c_mask)
212 uint32_t reference_frequency = 0;
213 bool use_i2c_sw_engine = false;
214 struct i2caux *base = NULL;
215 /*TODO: For CZ bring up, if dal_i2caux_get_reference_clock
216 * does not return 48KHz, we need hard coded for 48Khz.
217 * Some BIOS setting incorrect cause this
218 * For production, we always get value from BIOS*/
219 reference_frequency =
220 dal_i2caux_get_reference_clock(ctx->dc_bios) >> 1;
222 base = &i2caux_dce110->base;
224 dal_i2caux_construct(base, ctx);
226 i2caux_dce110->base.funcs = &i2caux_funcs;
227 i2caux_dce110->i2c_hw_buffer_in_use = false;
228 /* Create I2C engines (DDC lines per connector)
229 * different I2C/AUX usage cases, DDC, Generic GPIO, AUX.
232 enum gpio_ddc_line line_id = hw_ddc_lines[i];
234 struct i2c_hw_engine_dce110_create_arg hw_arg_dce110;
236 if (use_i2c_sw_engine) {
237 struct i2c_sw_engine_dce110_create_arg sw_arg;
239 sw_arg.engine_id = i;
240 sw_arg.default_speed = base->default_i2c_sw_speed;
242 base->i2c_sw_engines[line_id] =
243 dal_i2c_sw_engine_dce110_create(&sw_arg);
246 hw_arg_dce110.engine_id = i;
247 hw_arg_dce110.reference_frequency = reference_frequency;
248 hw_arg_dce110.default_speed = base->default_i2c_hw_speed;
249 hw_arg_dce110.ctx = ctx;
250 hw_arg_dce110.regs = &i2c_hw_engine_regs[i];
251 hw_arg_dce110.i2c_shift = i2c_shift;
252 hw_arg_dce110.i2c_mask = i2c_mask;
254 base->i2c_hw_engines[line_id] =
255 dal_i2c_hw_engine_dce110_create(&hw_arg_dce110);
256 if (base->i2c_hw_engines[line_id] != NULL) {
257 switch (ctx->dce_version) {
258 case DCN_VERSION_1_0:
259 base->i2c_hw_engines[line_id]->setup_limit =
260 I2C_SETUP_TIME_LIMIT_DCN;
261 base->i2c_hw_engines[line_id]->send_reset_length = 0;
264 base->i2c_hw_engines[line_id]->setup_limit =
265 I2C_SETUP_TIME_LIMIT_DCE;
266 base->i2c_hw_engines[line_id]->send_reset_length = 0;
271 } while (i < num_i2caux_inst);
273 /* Create AUX engines for all lines which has assisted HW AUX
274 * 'i' (loop counter) used as DDC/AUX engine_id */
279 enum gpio_ddc_line line_id = hw_aux_lines[i];
281 struct aux_engine_dce110_init_data aux_init_data;
283 aux_init_data.engine_id = i;
284 aux_init_data.timeout_period = base->aux_timeout_period;
285 aux_init_data.ctx = ctx;
286 aux_init_data.regs = &aux_regs[i];
288 base->aux_engines[line_id] =
289 dal_aux_engine_dce110_create(&aux_init_data);
292 } while (i < num_i2caux_inst);
294 /*TODO Generic I2C SW and HW*/
298 * dal_i2caux_dce110_create
301 * public interface to allocate memory for DCE11 I2CAUX
304 * struct adapter_service *as - [in]
305 * struct dc_context *ctx - [in]
308 * pointer to the base struct of DCE11 I2CAUX
310 struct i2caux *dal_i2caux_dce110_create(
311 struct dc_context *ctx)
313 struct i2caux_dce110 *i2caux_dce110 =
314 kzalloc(sizeof(struct i2caux_dce110), GFP_KERNEL);
316 if (!i2caux_dce110) {
317 ASSERT_CRITICAL(false);
321 dal_i2caux_dce110_construct(i2caux_dce110,
323 ARRAY_SIZE(dce110_aux_regs),
328 return &i2caux_dce110->base;