1*b843c749SSergey Zigachev /*
2*b843c749SSergey Zigachev * Copyright 2012-15 Advanced Micro Devices, Inc.
3*b843c749SSergey Zigachev *
4*b843c749SSergey Zigachev * Permission is hereby granted, free of charge, to any person obtaining a
5*b843c749SSergey Zigachev * copy of this software and associated documentation files (the "Software"),
6*b843c749SSergey Zigachev * to deal in the Software without restriction, including without limitation
7*b843c749SSergey Zigachev * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*b843c749SSergey Zigachev * and/or sell copies of the Software, and to permit persons to whom the
9*b843c749SSergey Zigachev * Software is furnished to do so, subject to the following conditions:
10*b843c749SSergey Zigachev *
11*b843c749SSergey Zigachev * The above copyright notice and this permission notice shall be included in
12*b843c749SSergey Zigachev * all copies or substantial portions of the Software.
13*b843c749SSergey Zigachev *
14*b843c749SSergey Zigachev * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15*b843c749SSergey Zigachev * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16*b843c749SSergey Zigachev * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17*b843c749SSergey Zigachev * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18*b843c749SSergey Zigachev * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19*b843c749SSergey Zigachev * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20*b843c749SSergey Zigachev * OTHER DEALINGS IN THE SOFTWARE.
21*b843c749SSergey Zigachev *
22*b843c749SSergey Zigachev * Authors: AMD
23*b843c749SSergey Zigachev *
24*b843c749SSergey Zigachev */
25*b843c749SSergey Zigachev
26*b843c749SSergey Zigachev #include "dm_services.h"
27*b843c749SSergey Zigachev
28*b843c749SSergey Zigachev /*
29*b843c749SSergey Zigachev * Pre-requisites: headers required by header of this unit
30*b843c749SSergey Zigachev */
31*b843c749SSergey Zigachev #include "include/i2caux_interface.h"
32*b843c749SSergey Zigachev #include "engine.h"
33*b843c749SSergey Zigachev
34*b843c749SSergey Zigachev /*
35*b843c749SSergey Zigachev * Header of this unit
36*b843c749SSergey Zigachev */
37*b843c749SSergey Zigachev
38*b843c749SSergey Zigachev #include "i2c_engine.h"
39*b843c749SSergey Zigachev
40*b843c749SSergey Zigachev /*
41*b843c749SSergey Zigachev * Post-requisites: headers required by this unit
42*b843c749SSergey Zigachev */
43*b843c749SSergey Zigachev
44*b843c749SSergey Zigachev /*
45*b843c749SSergey Zigachev * This unit
46*b843c749SSergey Zigachev */
47*b843c749SSergey Zigachev
48*b843c749SSergey Zigachev #define FROM_ENGINE(ptr) \
49*b843c749SSergey Zigachev container_of((ptr), struct i2c_engine, base)
50*b843c749SSergey Zigachev
dal_i2c_engine_acquire(struct engine * engine,struct ddc * ddc_handle)51*b843c749SSergey Zigachev bool dal_i2c_engine_acquire(
52*b843c749SSergey Zigachev struct engine *engine,
53*b843c749SSergey Zigachev struct ddc *ddc_handle)
54*b843c749SSergey Zigachev {
55*b843c749SSergey Zigachev struct i2c_engine *i2c_engine = FROM_ENGINE(engine);
56*b843c749SSergey Zigachev
57*b843c749SSergey Zigachev uint32_t counter = 0;
58*b843c749SSergey Zigachev bool result;
59*b843c749SSergey Zigachev
60*b843c749SSergey Zigachev do {
61*b843c749SSergey Zigachev result = i2c_engine->funcs->acquire_engine(
62*b843c749SSergey Zigachev i2c_engine, ddc_handle);
63*b843c749SSergey Zigachev
64*b843c749SSergey Zigachev if (result)
65*b843c749SSergey Zigachev break;
66*b843c749SSergey Zigachev
67*b843c749SSergey Zigachev /* i2c_engine is busy by VBios, lets wait and retry */
68*b843c749SSergey Zigachev
69*b843c749SSergey Zigachev udelay(10);
70*b843c749SSergey Zigachev
71*b843c749SSergey Zigachev ++counter;
72*b843c749SSergey Zigachev } while (counter < 2);
73*b843c749SSergey Zigachev
74*b843c749SSergey Zigachev if (result) {
75*b843c749SSergey Zigachev if (!i2c_engine->funcs->setup_engine(i2c_engine)) {
76*b843c749SSergey Zigachev engine->funcs->release_engine(engine);
77*b843c749SSergey Zigachev result = false;
78*b843c749SSergey Zigachev }
79*b843c749SSergey Zigachev }
80*b843c749SSergey Zigachev
81*b843c749SSergey Zigachev return result;
82*b843c749SSergey Zigachev }
83*b843c749SSergey Zigachev
dal_i2c_engine_setup_i2c_engine(struct i2c_engine * engine)84*b843c749SSergey Zigachev bool dal_i2c_engine_setup_i2c_engine(
85*b843c749SSergey Zigachev struct i2c_engine *engine)
86*b843c749SSergey Zigachev {
87*b843c749SSergey Zigachev /* Derivative classes do not have to override this */
88*b843c749SSergey Zigachev
89*b843c749SSergey Zigachev return true;
90*b843c749SSergey Zigachev }
91*b843c749SSergey Zigachev
dal_i2c_engine_submit_channel_request(struct i2c_engine * engine,struct i2c_request_transaction_data * request)92*b843c749SSergey Zigachev void dal_i2c_engine_submit_channel_request(
93*b843c749SSergey Zigachev struct i2c_engine *engine,
94*b843c749SSergey Zigachev struct i2c_request_transaction_data *request)
95*b843c749SSergey Zigachev {
96*b843c749SSergey Zigachev
97*b843c749SSergey Zigachev }
98*b843c749SSergey Zigachev
dal_i2c_engine_process_channel_reply(struct i2c_engine * engine,struct i2c_reply_transaction_data * reply)99*b843c749SSergey Zigachev void dal_i2c_engine_process_channel_reply(
100*b843c749SSergey Zigachev struct i2c_engine *engine,
101*b843c749SSergey Zigachev struct i2c_reply_transaction_data *reply)
102*b843c749SSergey Zigachev {
103*b843c749SSergey Zigachev
104*b843c749SSergey Zigachev }
105*b843c749SSergey Zigachev
dal_i2c_engine_construct(struct i2c_engine * engine,struct dc_context * ctx)106*b843c749SSergey Zigachev void dal_i2c_engine_construct(
107*b843c749SSergey Zigachev struct i2c_engine *engine,
108*b843c749SSergey Zigachev struct dc_context *ctx)
109*b843c749SSergey Zigachev {
110*b843c749SSergey Zigachev dal_i2caux_construct_engine(&engine->base, ctx);
111*b843c749SSergey Zigachev engine->timeout_delay = 0;
112*b843c749SSergey Zigachev }
113*b843c749SSergey Zigachev
dal_i2c_engine_destruct(struct i2c_engine * engine)114*b843c749SSergey Zigachev void dal_i2c_engine_destruct(
115*b843c749SSergey Zigachev struct i2c_engine *engine)
116*b843c749SSergey Zigachev {
117*b843c749SSergey Zigachev dal_i2caux_destruct_engine(&engine->base);
118*b843c749SSergey Zigachev }
119