OpenBIC
OpenSource Bridge-IC
hal_i2c_target.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef HAL_I2C_TARGET_H
18#define HAL_I2C_TARGET_H
19
20#include <drivers/i2c.h>
21#include "hal_i2c.h"
22
23#define MAX_I2C_TARGET_BUFF 256
24#define MAX_TARGET_NUM 16
25#define I2C_DEVICE_PREFIX "I2C_"
26#define I2C_CONTROLLER_NAME_GET(inst) I2C_DEVICE_PREFIX #inst
27
28struct __attribute__((__packed__)) i2c_msg_package {
29 uint16_t msg_length;
30 uint8_t msg[MAX_I2C_TARGET_BUFF];
31};
32
34 uint8_t i2c_bus; // i2c bus number
35 const struct device *i2c_controller; // i2c controller for one target bus
36 struct i2c_slave_config config; // i2c target relative config
37 struct i2c_slave_config config_sec; // i2c target relative config for 2nd address
38 struct i2c_slave_config config_thd; // i2c target relative config for 3rd address
39 uint8_t req_address; // current request address
40
41 /* TARGET WRITE - Support message queue for massive pending messages storage */
42 uint16_t wr_buffer_idx; // message buffer index
43 struct i2c_msg_package target_wr_msg; // message's buffer and length
44 struct k_msgq target_wr_msgq_id; // target write message queue of Zephyr api
45 uint16_t max_msg_count; // max message count for target write message queue
46 bool skip_msg_wr; // skip message write while target stop
47 void (*post_wr_rcv_func)(void *); // do something after wr received
48
49 /* TARGET READ - Not support pending messages storage */
50 uint32_t rd_buffer_idx; // message buffer index
51 struct i2c_msg_package target_rd_msg; // message's buffer and length
52 bool (*rd_data_collect_func)(void *); // do something before read first byte
53};
54
56 uint8_t address;
57 uint32_t i2c_msg_count;
58 bool (*rd_data_collect_func)(void *);
59 void (*post_wr_rcv_func)(void *);
60 uint8_t address_sec;
62 uint8_t address_thd;
64};
65
68 bool is_init;
72};
73
74/* Retern value set for i2c target status */
81 0x08, /* Might heapen if bus controler is not enable in device tree */
82};
83
84/* Retern value set for i2c target api status */
93};
94
95/* Mode of "i2c_target_control" */
99 I2C_CONTROL_MAX = 0xFF
101
102extern const bool I2C_TARGET_ENABLE_TABLE[MAX_TARGET_NUM];
104
105uint8_t i2c_target_status_get(uint8_t bus_num);
106uint8_t i2c_target_status_print(uint8_t bus_num);
107uint8_t i2c_target_cfg_get(uint8_t bus_num, struct _i2c_target_config *cfg);
108uint8_t i2c_target_read(uint8_t bus_num, uint8_t *buff, uint16_t buff_len, uint16_t *msg_len);
109uint8_t i2c_target_write(uint8_t bus_num, uint8_t *buff, uint16_t buff_len);
110int i2c_target_control(uint8_t bus_num, struct _i2c_target_config *cfg,
112
114
115#endif
int i2c_target_control(uint8_t bus_num, struct _i2c_target_config *cfg, enum i2c_target_api_control_mode mode)
Definition: hal_i2c_target.c:436
void util_init_I2C_target(void)
i2c_target_api_error_status
Definition: hal_i2c_target.h:85
@ I2C_TARGET_API_MSGQ_ERR
Definition: hal_i2c_target.h:90
@ I2C_TARGET_API_INPUT_ERR
Definition: hal_i2c_target.h:87
@ I2C_TARGET_API_LOCK_ERR
Definition: hal_i2c_target.h:88
@ I2C_TARGET_API_BUS_GET_FAIL
Definition: hal_i2c_target.h:91
@ I2C_TARGET_API_MEMORY_ERR
Definition: hal_i2c_target.h:89
@ I2C_TARGET_API_UNKNOWN_ERR
Definition: hal_i2c_target.h:92
@ I2C_TARGET_API_NO_ERR
Definition: hal_i2c_target.h:86
i2c_target_api_control_mode
Definition: hal_i2c_target.h:96
@ I2C_CONTROL_REGISTER
Definition: hal_i2c_target.h:98
@ I2C_CONTROL_UNREGISTER
Definition: hal_i2c_target.h:97
@ I2C_CONTROL_MAX
Definition: hal_i2c_target.h:99
uint8_t i2c_target_status_get(uint8_t bus_num)
Definition: hal_i2c_target.c:228
const struct _i2c_target_config I2C_TARGET_CONFIG_TABLE[MAX_TARGET_NUM]
Definition: plat_i2c_target.c:41
uint8_t i2c_target_status_print(uint8_t bus_num)
Definition: hal_i2c_target.c:303
#define MAX_TARGET_NUM
Definition: hal_i2c_target.h:24
const bool I2C_TARGET_ENABLE_TABLE[MAX_TARGET_NUM]
Definition: plat_i2c_target.c:33
uint8_t i2c_target_read(uint8_t bus_num, uint8_t *buff, uint16_t buff_len, uint16_t *msg_len)
Definition: hal_i2c_target.c:339
#define MAX_I2C_TARGET_BUFF
Definition: hal_i2c_target.h:23
i2c_target_error_status
Definition: hal_i2c_target.h:75
@ I2C_TARGET_CONTROLLER_ERR
Definition: hal_i2c_target.h:80
@ I2C_TARGET_NOT_INIT
Definition: hal_i2c_target.h:78
@ I2C_TARGET_BUS_INVALID
Definition: hal_i2c_target.h:77
@ I2C_TARGET_NOT_REGISTER
Definition: hal_i2c_target.h:79
@ I2C_TARGET_HAS_NO_ERR
Definition: hal_i2c_target.h:76
uint8_t i2c_target_cfg_get(uint8_t bus_num, struct _i2c_target_config *cfg)
Definition: hal_i2c_target.c:273
uint8_t i2c_target_write(uint8_t bus_num, uint8_t *buff, uint16_t buff_len)
Definition: hal_i2c_target.c:399
uint8_t mode
Definition: plat_ncsi.h:5
Definition: pldm_smbios.h:61
Definition: hal_i2c_target.h:55
void(* post_wr_rcv_func)(void *)
Definition: hal_i2c_target.h:59
uint32_t i2c_msg_count
Definition: hal_i2c_target.h:57
uint8_t address_thd
Definition: hal_i2c_target.h:62
bool is_enable_thd
Definition: hal_i2c_target.h:63
bool(* rd_data_collect_func)(void *)
Definition: hal_i2c_target.h:58
uint8_t address_sec
Definition: hal_i2c_target.h:60
uint8_t address
Definition: hal_i2c_target.h:56
bool is_enable_sec
Definition: hal_i2c_target.h:61
Definition: hal_i2c_target.h:33
struct i2c_slave_config config
Definition: hal_i2c_target.h:36
struct i2c_msg_package target_wr_msg
Definition: hal_i2c_target.h:43
void(* post_wr_rcv_func)(void *)
Definition: hal_i2c_target.h:47
struct i2c_slave_config config_sec
Definition: hal_i2c_target.h:37
uint8_t req_address
Definition: hal_i2c_target.h:39
bool skip_msg_wr
Definition: hal_i2c_target.h:46
struct i2c_msg_package target_rd_msg
Definition: hal_i2c_target.h:51
uint16_t wr_buffer_idx
Definition: hal_i2c_target.h:42
struct k_msgq target_wr_msgq_id
Definition: hal_i2c_target.h:44
uint8_t i2c_bus
Definition: hal_i2c_target.h:34
uint16_t max_msg_count
Definition: hal_i2c_target.h:45
const struct device * i2c_controller
Definition: hal_i2c_target.h:35
uint32_t rd_buffer_idx
Definition: hal_i2c_target.h:50
struct i2c_slave_config config_thd
Definition: hal_i2c_target.h:38
bool(* rd_data_collect_func)(void *)
Definition: hal_i2c_target.h:52
Definition: hal_i2c_target.h:66
bool is_init
Definition: hal_i2c_target.h:68
bool is_enable_sec
Definition: hal_i2c_target.h:70
bool is_enable_thd
Definition: hal_i2c_target.h:71
struct i2c_target_data data
Definition: hal_i2c_target.h:67
bool is_register
Definition: hal_i2c_target.h:69