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_dce110.h"
41
42 /*
43 * Post-requisites: headers required by this unit
44 */
45
46 /*
47 * This unit
48 */
49
50 /*
51 * @brief
52 * Cast 'struct i2c_sw_engine *'
53 * to 'struct i2c_sw_engine_dce110 *'
54 */
55 #define FROM_I2C_SW_ENGINE(ptr) \
56 container_of((ptr), struct i2c_sw_engine_dce110, base)
57 /*
58 * @brief
59 * Cast 'struct i2c_engine *'
60 * to 'struct i2c_sw_engine_dce80 *'
61 */
62 #define FROM_I2C_ENGINE(ptr) \
63 FROM_I2C_SW_ENGINE(container_of((ptr), struct i2c_sw_engine, base))
64
65 /*
66 * @brief
67 * Cast 'struct engine *'
68 * to 'struct i2c_sw_engine_dce80 *'
69 */
70 #define FROM_ENGINE(ptr) \
71 FROM_I2C_ENGINE(container_of((ptr), struct i2c_engine, base))
72
release_engine(struct engine * engine)73 static void release_engine(
74 struct engine *engine)
75 {
76 }
77
destruct(struct i2c_sw_engine_dce110 * engine)78 static void destruct(
79 struct i2c_sw_engine_dce110 *engine)
80 {
81 dal_i2c_sw_engine_destruct(&engine->base);
82 }
83
destroy(struct i2c_engine ** engine)84 static void destroy(
85 struct i2c_engine **engine)
86 {
87 struct i2c_sw_engine_dce110 *sw_engine = FROM_I2C_ENGINE(*engine);
88
89 destruct(sw_engine);
90
91 kfree(sw_engine);
92
93 *engine = NULL;
94 }
95
acquire_engine(struct i2c_engine * engine,struct ddc * ddc_handle)96 static bool acquire_engine(
97 struct i2c_engine *engine,
98 struct ddc *ddc_handle)
99 {
100 return dal_i2caux_i2c_sw_engine_acquire_engine(engine, ddc_handle);
101 }
102
103 static const struct i2c_engine_funcs i2c_engine_funcs = {
104 .acquire_engine = acquire_engine,
105 .destroy = destroy,
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,
112 };
113
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,
119 };
120
construct(struct i2c_sw_engine_dce110 * engine_dce110,const struct i2c_sw_engine_dce110_create_arg * arg_dce110)121 static void construct(
122 struct i2c_sw_engine_dce110 *engine_dce110,
123 const struct i2c_sw_engine_dce110_create_arg *arg_dce110)
124 {
125 struct i2c_sw_engine_create_arg arg_base;
126
127 arg_base.ctx = arg_dce110->ctx;
128 arg_base.default_speed = arg_dce110->default_speed;
129
130 dal_i2c_sw_engine_construct(&engine_dce110->base, &arg_base);
131
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;
138 }
139
dal_i2c_sw_engine_dce110_create(const struct i2c_sw_engine_dce110_create_arg * arg)140 struct i2c_engine *dal_i2c_sw_engine_dce110_create(
141 const struct i2c_sw_engine_dce110_create_arg *arg)
142 {
143 struct i2c_sw_engine_dce110 *engine_dce110;
144
145 if (!arg) {
146 ASSERT_CRITICAL(false);
147 return NULL;
148 }
149
150 engine_dce110 = kzalloc(sizeof(struct i2c_sw_engine_dce110),
151 GFP_KERNEL);
152
153 if (!engine_dce110) {
154 ASSERT_CRITICAL(false);
155 return NULL;
156 }
157
158 construct(engine_dce110, arg);
159 return &engine_dce110->base.base;
160 }
161