xref: /dflybsd-src/sys/dev/drm/amd/display/dc/i2caux/engine.h (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 #ifndef __DAL_ENGINE_H__
27*b843c749SSergey Zigachev #define __DAL_ENGINE_H__
28*b843c749SSergey Zigachev 
29*b843c749SSergey Zigachev #include "dc_ddc_types.h"
30*b843c749SSergey Zigachev 
31*b843c749SSergey Zigachev enum i2caux_transaction_operation {
32*b843c749SSergey Zigachev 	I2CAUX_TRANSACTION_READ,
33*b843c749SSergey Zigachev 	I2CAUX_TRANSACTION_WRITE
34*b843c749SSergey Zigachev };
35*b843c749SSergey Zigachev 
36*b843c749SSergey Zigachev enum i2caux_transaction_address_space {
37*b843c749SSergey Zigachev 	I2CAUX_TRANSACTION_ADDRESS_SPACE_I2C = 1,
38*b843c749SSergey Zigachev 	I2CAUX_TRANSACTION_ADDRESS_SPACE_DPCD
39*b843c749SSergey Zigachev };
40*b843c749SSergey Zigachev 
41*b843c749SSergey Zigachev struct i2caux_transaction_payload {
42*b843c749SSergey Zigachev 	enum i2caux_transaction_address_space address_space;
43*b843c749SSergey Zigachev 	uint32_t address;
44*b843c749SSergey Zigachev 	uint32_t length;
45*b843c749SSergey Zigachev 	uint8_t *data;
46*b843c749SSergey Zigachev };
47*b843c749SSergey Zigachev 
48*b843c749SSergey Zigachev enum i2caux_transaction_status {
49*b843c749SSergey Zigachev 	I2CAUX_TRANSACTION_STATUS_UNKNOWN = (-1L),
50*b843c749SSergey Zigachev 	I2CAUX_TRANSACTION_STATUS_SUCCEEDED,
51*b843c749SSergey Zigachev 	I2CAUX_TRANSACTION_STATUS_FAILED_CHANNEL_BUSY,
52*b843c749SSergey Zigachev 	I2CAUX_TRANSACTION_STATUS_FAILED_TIMEOUT,
53*b843c749SSergey Zigachev 	I2CAUX_TRANSACTION_STATUS_FAILED_PROTOCOL_ERROR,
54*b843c749SSergey Zigachev 	I2CAUX_TRANSACTION_STATUS_FAILED_NACK,
55*b843c749SSergey Zigachev 	I2CAUX_TRANSACTION_STATUS_FAILED_INCOMPLETE,
56*b843c749SSergey Zigachev 	I2CAUX_TRANSACTION_STATUS_FAILED_OPERATION,
57*b843c749SSergey Zigachev 	I2CAUX_TRANSACTION_STATUS_FAILED_INVALID_OPERATION,
58*b843c749SSergey Zigachev 	I2CAUX_TRANSACTION_STATUS_FAILED_BUFFER_OVERFLOW,
59*b843c749SSergey Zigachev 	I2CAUX_TRANSACTION_STATUS_FAILED_HPD_DISCON
60*b843c749SSergey Zigachev };
61*b843c749SSergey Zigachev 
62*b843c749SSergey Zigachev struct i2caux_transaction_request {
63*b843c749SSergey Zigachev 	enum i2caux_transaction_operation operation;
64*b843c749SSergey Zigachev 	struct i2caux_transaction_payload payload;
65*b843c749SSergey Zigachev 	enum i2caux_transaction_status status;
66*b843c749SSergey Zigachev };
67*b843c749SSergey Zigachev 
68*b843c749SSergey Zigachev enum i2caux_engine_type {
69*b843c749SSergey Zigachev 	I2CAUX_ENGINE_TYPE_UNKNOWN = (-1L),
70*b843c749SSergey Zigachev 	I2CAUX_ENGINE_TYPE_AUX,
71*b843c749SSergey Zigachev 	I2CAUX_ENGINE_TYPE_I2C_DDC_HW,
72*b843c749SSergey Zigachev 	I2CAUX_ENGINE_TYPE_I2C_GENERIC_HW,
73*b843c749SSergey Zigachev 	I2CAUX_ENGINE_TYPE_I2C_SW
74*b843c749SSergey Zigachev };
75*b843c749SSergey Zigachev 
76*b843c749SSergey Zigachev enum i2c_default_speed {
77*b843c749SSergey Zigachev 	I2CAUX_DEFAULT_I2C_HW_SPEED = 50,
78*b843c749SSergey Zigachev 	I2CAUX_DEFAULT_I2C_SW_SPEED = 50
79*b843c749SSergey Zigachev };
80*b843c749SSergey Zigachev 
81*b843c749SSergey Zigachev struct engine;
82*b843c749SSergey Zigachev 
83*b843c749SSergey Zigachev struct engine_funcs {
84*b843c749SSergey Zigachev 	enum i2caux_engine_type (*get_engine_type)(
85*b843c749SSergey Zigachev 		const struct engine *engine);
86*b843c749SSergey Zigachev 	bool (*acquire)(
87*b843c749SSergey Zigachev 		struct engine *engine,
88*b843c749SSergey Zigachev 		struct ddc *ddc);
89*b843c749SSergey Zigachev 	bool (*submit_request)(
90*b843c749SSergey Zigachev 		struct engine *engine,
91*b843c749SSergey Zigachev 		struct i2caux_transaction_request *request,
92*b843c749SSergey Zigachev 		bool middle_of_transaction);
93*b843c749SSergey Zigachev 	void (*release_engine)(
94*b843c749SSergey Zigachev 		struct engine *engine);
95*b843c749SSergey Zigachev };
96*b843c749SSergey Zigachev 
97*b843c749SSergey Zigachev struct engine {
98*b843c749SSergey Zigachev 	const struct engine_funcs *funcs;
99*b843c749SSergey Zigachev 	uint32_t inst;
100*b843c749SSergey Zigachev 	struct ddc *ddc;
101*b843c749SSergey Zigachev 	struct dc_context *ctx;
102*b843c749SSergey Zigachev };
103*b843c749SSergey Zigachev 
104*b843c749SSergey Zigachev void dal_i2caux_construct_engine(
105*b843c749SSergey Zigachev 	struct engine *engine,
106*b843c749SSergey Zigachev 	struct dc_context *ctx);
107*b843c749SSergey Zigachev 
108*b843c749SSergey Zigachev void dal_i2caux_destruct_engine(
109*b843c749SSergey Zigachev 	struct engine *engine);
110*b843c749SSergey Zigachev 
111*b843c749SSergey Zigachev #endif
112