1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26#ifndef __DAL_I2C_ENGINE_H__
27#define __DAL_I2C_ENGINE_H__
28
29enum i2c_channel_operation_result {
30 I2C_CHANNEL_OPERATION_SUCCEEDED,
31 I2C_CHANNEL_OPERATION_FAILED,
32 I2C_CHANNEL_OPERATION_NOT_GRANTED,
33 I2C_CHANNEL_OPERATION_IS_BUSY,
34 I2C_CHANNEL_OPERATION_NO_HANDLE_PROVIDED,
35 I2C_CHANNEL_OPERATION_CHANNEL_IN_USE,
36 I2C_CHANNEL_OPERATION_CHANNEL_CLIENT_MAX_ALLOWED,
37 I2C_CHANNEL_OPERATION_ENGINE_BUSY,
38 I2C_CHANNEL_OPERATION_TIMEOUT,
39 I2C_CHANNEL_OPERATION_NO_RESPONSE,
40 I2C_CHANNEL_OPERATION_HW_REQUEST_I2C_BUS,
41 I2C_CHANNEL_OPERATION_WRONG_PARAMETER,
42 I2C_CHANNEL_OPERATION_OUT_NB_OF_RETRIES,
43 I2C_CHANNEL_OPERATION_NOT_STARTED
44};
45
46struct i2c_request_transaction_data {
47 enum i2caux_transaction_action action;
48 enum i2c_channel_operation_result status;
49 uint8_t address;
50 uint32_t length;
51 uint8_t *data;
52};
53
54struct i2c_reply_transaction_data {
55 uint32_t length;
56 uint8_t *data;
57};
58
59struct i2c_engine;
60
61struct i2c_engine_funcs {
62 void (*destroy)(
63 struct i2c_engine **ptr);
64 uint32_t (*get_speed)(
65 const struct i2c_engine *engine);
66 void (*set_speed)(
67 struct i2c_engine *engine,
68 uint32_t speed);
69 bool (*acquire_engine)(
70 struct i2c_engine *engine,
71 struct ddc *ddc);
72 bool (*setup_engine)(
73 struct i2c_engine *engine);
74 void (*submit_channel_request)(
75 struct i2c_engine *engine,
76 struct i2c_request_transaction_data *request);
77 void (*process_channel_reply)(
78 struct i2c_engine *engine,
79 struct i2c_reply_transaction_data *reply);
80 enum i2c_channel_operation_result (*get_channel_status)(
81 struct i2c_engine *engine,
82 uint8_t *returned_bytes);
83};
84
85struct i2c_engine {
86 struct engine base;
87 const struct i2c_engine_funcs *funcs;
88 uint32_t timeout_delay;
89 uint32_t setup_limit;
90 uint32_t send_reset_length;
91};
92
93void dal_i2c_engine_construct(
94 struct i2c_engine *engine,
95 struct dc_context *ctx);
96
97void dal_i2c_engine_destruct(
98 struct i2c_engine *engine);
99
100bool dal_i2c_engine_setup_i2c_engine(
101 struct i2c_engine *engine);
102
103void dal_i2c_engine_submit_channel_request(
104 struct i2c_engine *engine,
105 struct i2c_request_transaction_data *request);
106
107void dal_i2c_engine_process_channel_reply(
108 struct i2c_engine *engine,
109 struct i2c_reply_transaction_data *reply);
110
111bool dal_i2c_engine_acquire(
112 struct engine *ptr,
113 struct ddc *ddc_handle);
114
115#endif
116