xref: /dflybsd-src/sys/dev/drm/amd/display/dc/i2caux/dce112/i2caux_dce112.c (revision b843c749addef9340ee7d4e250b09fdd492602a1)
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 #include "include/i2caux_interface.h"
29*b843c749SSergey Zigachev #include "../i2caux.h"
30*b843c749SSergey Zigachev #include "../engine.h"
31*b843c749SSergey Zigachev #include "../i2c_engine.h"
32*b843c749SSergey Zigachev #include "../i2c_sw_engine.h"
33*b843c749SSergey Zigachev #include "../i2c_hw_engine.h"
34*b843c749SSergey Zigachev 
35*b843c749SSergey Zigachev #include "../dce110/i2caux_dce110.h"
36*b843c749SSergey Zigachev #include "i2caux_dce112.h"
37*b843c749SSergey Zigachev 
38*b843c749SSergey Zigachev #include "../dce110/aux_engine_dce110.h"
39*b843c749SSergey Zigachev 
40*b843c749SSergey Zigachev #include "../dce110/i2c_hw_engine_dce110.h"
41*b843c749SSergey Zigachev 
42*b843c749SSergey Zigachev #include "dce/dce_11_2_d.h"
43*b843c749SSergey Zigachev #include "dce/dce_11_2_sh_mask.h"
44*b843c749SSergey Zigachev 
45*b843c749SSergey Zigachev /* set register offset */
46*b843c749SSergey Zigachev #define SR(reg_name)\
47*b843c749SSergey Zigachev 	.reg_name = mm ## reg_name
48*b843c749SSergey Zigachev 
49*b843c749SSergey Zigachev /* set register offset with instance */
50*b843c749SSergey Zigachev #define SRI(reg_name, block, id)\
51*b843c749SSergey Zigachev 	.reg_name = mm ## block ## id ## _ ## reg_name
52*b843c749SSergey Zigachev 
53*b843c749SSergey Zigachev #define aux_regs(id)\
54*b843c749SSergey Zigachev [id] = {\
55*b843c749SSergey Zigachev 	AUX_COMMON_REG_LIST(id), \
56*b843c749SSergey Zigachev 	.AUX_RESET_MASK = AUX_CONTROL__AUX_RESET_MASK \
57*b843c749SSergey Zigachev }
58*b843c749SSergey Zigachev 
59*b843c749SSergey Zigachev #define hw_engine_regs(id)\
60*b843c749SSergey Zigachev {\
61*b843c749SSergey Zigachev 		I2C_HW_ENGINE_COMMON_REG_LIST(id) \
62*b843c749SSergey Zigachev }
63*b843c749SSergey Zigachev 
64*b843c749SSergey Zigachev static const struct dce110_aux_registers dce112_aux_regs[] = {
65*b843c749SSergey Zigachev 		aux_regs(0),
66*b843c749SSergey Zigachev 		aux_regs(1),
67*b843c749SSergey Zigachev 		aux_regs(2),
68*b843c749SSergey Zigachev 		aux_regs(3),
69*b843c749SSergey Zigachev 		aux_regs(4),
70*b843c749SSergey Zigachev 		aux_regs(5),
71*b843c749SSergey Zigachev };
72*b843c749SSergey Zigachev 
73*b843c749SSergey Zigachev static const struct dce110_i2c_hw_engine_registers dce112_hw_engine_regs[] = {
74*b843c749SSergey Zigachev 		hw_engine_regs(1),
75*b843c749SSergey Zigachev 		hw_engine_regs(2),
76*b843c749SSergey Zigachev 		hw_engine_regs(3),
77*b843c749SSergey Zigachev 		hw_engine_regs(4),
78*b843c749SSergey Zigachev 		hw_engine_regs(5),
79*b843c749SSergey Zigachev 		hw_engine_regs(6)
80*b843c749SSergey Zigachev };
81*b843c749SSergey Zigachev 
82*b843c749SSergey Zigachev static const struct dce110_i2c_hw_engine_shift i2c_shift = {
83*b843c749SSergey Zigachev 		I2C_COMMON_MASK_SH_LIST_DCE110(__SHIFT)
84*b843c749SSergey Zigachev };
85*b843c749SSergey Zigachev 
86*b843c749SSergey Zigachev static const struct dce110_i2c_hw_engine_mask i2c_mask = {
87*b843c749SSergey Zigachev 		I2C_COMMON_MASK_SH_LIST_DCE110(_MASK)
88*b843c749SSergey Zigachev };
89*b843c749SSergey Zigachev 
construct(struct i2caux_dce110 * i2caux_dce110,struct dc_context * ctx)90*b843c749SSergey Zigachev static void construct(
91*b843c749SSergey Zigachev 	struct i2caux_dce110 *i2caux_dce110,
92*b843c749SSergey Zigachev 	struct dc_context *ctx)
93*b843c749SSergey Zigachev {
94*b843c749SSergey Zigachev 	dal_i2caux_dce110_construct(i2caux_dce110,
95*b843c749SSergey Zigachev 				    ctx,
96*b843c749SSergey Zigachev 				    ARRAY_SIZE(dce112_aux_regs),
97*b843c749SSergey Zigachev 				    dce112_aux_regs,
98*b843c749SSergey Zigachev 				    dce112_hw_engine_regs,
99*b843c749SSergey Zigachev 				    &i2c_shift,
100*b843c749SSergey Zigachev 				    &i2c_mask);
101*b843c749SSergey Zigachev }
102*b843c749SSergey Zigachev 
103*b843c749SSergey Zigachev /*
104*b843c749SSergey Zigachev  * dal_i2caux_dce110_create
105*b843c749SSergey Zigachev  *
106*b843c749SSergey Zigachev  * @brief
107*b843c749SSergey Zigachev  * public interface to allocate memory for DCE11 I2CAUX
108*b843c749SSergey Zigachev  *
109*b843c749SSergey Zigachev  * @param
110*b843c749SSergey Zigachev  * struct adapter_service *as - [in]
111*b843c749SSergey Zigachev  * struct dc_context *ctx - [in]
112*b843c749SSergey Zigachev  *
113*b843c749SSergey Zigachev  * @return
114*b843c749SSergey Zigachev  * pointer to the base struct of DCE11 I2CAUX
115*b843c749SSergey Zigachev  */
dal_i2caux_dce112_create(struct dc_context * ctx)116*b843c749SSergey Zigachev struct i2caux *dal_i2caux_dce112_create(
117*b843c749SSergey Zigachev 	struct dc_context *ctx)
118*b843c749SSergey Zigachev {
119*b843c749SSergey Zigachev 	struct i2caux_dce110 *i2caux_dce110 =
120*b843c749SSergey Zigachev 		kzalloc(sizeof(struct i2caux_dce110), GFP_KERNEL);
121*b843c749SSergey Zigachev 
122*b843c749SSergey Zigachev 	if (!i2caux_dce110) {
123*b843c749SSergey Zigachev 		ASSERT_CRITICAL(false);
124*b843c749SSergey Zigachev 		return NULL;
125*b843c749SSergey Zigachev 	}
126*b843c749SSergey Zigachev 
127*b843c749SSergey Zigachev 	construct(i2caux_dce110, ctx);
128*b843c749SSergey Zigachev 	return &i2caux_dce110->base;
129*b843c749SSergey Zigachev }
130