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 "../engine.h"
33 #include "../i2c_engine.h"
34 #include "../i2c_sw_engine.h"
40 #include "i2c_sw_engine_dce110.h"
43 * Post-requisites: headers required by this unit
52 * Cast 'struct i2c_sw_engine *'
53 * to 'struct i2c_sw_engine_dce110 *'
55 #define FROM_I2C_SW_ENGINE(ptr) \
56 container_of((ptr), struct i2c_sw_engine_dce110, base)
59 * Cast 'struct i2c_engine *'
60 * to 'struct i2c_sw_engine_dce80 *'
62 #define FROM_I2C_ENGINE(ptr) \
63 FROM_I2C_SW_ENGINE(container_of((ptr), struct i2c_sw_engine, base))
67 * Cast 'struct engine *'
68 * to 'struct i2c_sw_engine_dce80 *'
70 #define FROM_ENGINE(ptr) \
71 FROM_I2C_ENGINE(container_of((ptr), struct i2c_engine, base))
73 static void release_engine(
74 struct engine *engine)
79 struct i2c_sw_engine_dce110 *engine)
81 dal_i2c_sw_engine_destruct(&engine->base);
85 struct i2c_engine **engine)
87 struct i2c_sw_engine_dce110 *sw_engine = FROM_I2C_ENGINE(*engine);
96 static bool acquire_engine(
97 struct i2c_engine *engine,
98 struct ddc *ddc_handle)
100 return dal_i2caux_i2c_sw_engine_acquire_engine(engine, ddc_handle);
103 static const struct i2c_engine_funcs i2c_engine_funcs = {
104 .acquire_engine = acquire_engine,
106 .get_speed = dal_i2c_sw_engine_get_speed,
107 .set_speed = dal_i2c_sw_engine_set_speed,
108 .setup_engine = dal_i2c_engine_setup_i2c_engine,
109 .submit_channel_request = dal_i2c_sw_engine_submit_channel_request,
110 .process_channel_reply = dal_i2c_engine_process_channel_reply,
111 .get_channel_status = dal_i2c_sw_engine_get_channel_status,
114 static const struct engine_funcs engine_funcs = {
115 .release_engine = release_engine,
116 .get_engine_type = dal_i2c_sw_engine_get_engine_type,
117 .acquire = dal_i2c_engine_acquire,
118 .submit_request = dal_i2c_sw_engine_submit_request,
121 static void construct(
122 struct i2c_sw_engine_dce110 *engine_dce110,
123 const struct i2c_sw_engine_dce110_create_arg *arg_dce110)
125 struct i2c_sw_engine_create_arg arg_base;
127 arg_base.ctx = arg_dce110->ctx;
128 arg_base.default_speed = arg_dce110->default_speed;
130 dal_i2c_sw_engine_construct(&engine_dce110->base, &arg_base);
132 /*struct engine struct engine_funcs*/
133 engine_dce110->base.base.base.funcs = &engine_funcs;
134 /*struct i2c_engine struct i2c_engine_funcs*/
135 engine_dce110->base.base.funcs = &i2c_engine_funcs;
136 engine_dce110->base.default_speed = arg_dce110->default_speed;
137 engine_dce110->engine_id = arg_dce110->engine_id;
140 struct i2c_engine *dal_i2c_sw_engine_dce110_create(
141 const struct i2c_sw_engine_dce110_create_arg *arg)
143 struct i2c_sw_engine_dce110 *engine_dce110;
146 ASSERT_CRITICAL(false);
150 engine_dce110 = kzalloc(sizeof(struct i2c_sw_engine_dce110),
153 if (!engine_dce110) {
154 ASSERT_CRITICAL(false);
158 construct(engine_dce110, arg);
159 return &engine_dce110->base.base;