1 /*
2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3 *
4 * HDF is dual licensed: you can use it either under the terms of
5 * the GPL, or the BSD license, at your option.
6 * See the LICENSE file in the root of this repository for complete details.
7 */
8
9 #include "i3c_if.h"
10 #include "i3c_core.h"
11 #include "hdf_log.h"
12
13 #define HDF_LOG_TAG i3c_if_c
14
I3cOpen(int16_t number)15 DevHandle I3cOpen(int16_t number)
16 {
17 return (DevHandle)I3cCntlrGet(number);
18 }
19
I3cClose(DevHandle handle)20 void I3cClose(DevHandle handle)
21 {
22 I3cCntlrPut((struct I3cCntlr *)handle);
23 }
24
I3cTransfer(DevHandle handle,struct I3cMsg * msgs,int16_t count,enum TransMode mode)25 int32_t I3cTransfer(DevHandle handle, struct I3cMsg *msgs, int16_t count, enum TransMode mode)
26 {
27 int32_t ret = HDF_SUCCESS;
28
29 if (handle == NULL) {
30 HDF_LOGE("I3cTransfer: handle is null!");
31 return HDF_ERR_INVALID_OBJECT;
32 }
33
34 if (msgs == NULL || count <= 0) {
35 HDF_LOGE("I3cTransfer: err params! msgs:%s, count:%hd", (msgs == NULL) ? "0" : "x", count);
36 return HDF_ERR_INVALID_PARAM;
37 }
38
39 switch (mode) {
40 case I2C_MODE:
41 ret = I3cCntlrI2cTransfer((struct I3cCntlr *)handle, msgs, count);
42 break;
43 case I3C_MODE:
44 ret = I3cCntlrTransfer((struct I3cCntlr *)handle, msgs, count);
45 break;
46 case CCC_CMD_MODE:
47 ret = I3cCntlrSendCccCmd((struct I3cCntlr *)handle, msgs->ccc);
48 break;
49 default:
50 break;
51 }
52
53 return ret;
54 }
55
I3cSetConfig(DevHandle handle,struct I3cConfig * config)56 int32_t I3cSetConfig(DevHandle handle, struct I3cConfig *config)
57 {
58 return I3cCntlrSetConfig((struct I3cCntlr *)handle, config);
59 }
60
I3cGetConfig(DevHandle handle,struct I3cConfig * config)61 int32_t I3cGetConfig(DevHandle handle, struct I3cConfig *config)
62 {
63 return I3cCntlrGetConfig((struct I3cCntlr *)handle, config);
64 }
65
I3cRequestIbi(DevHandle handle,uint16_t addr,I3cIbiFunc func,uint32_t payload)66 int32_t I3cRequestIbi(DevHandle handle, uint16_t addr, I3cIbiFunc func, uint32_t payload)
67 {
68 return I3cCntlrRequestIbi((struct I3cCntlr *)handle, addr, func, payload);
69 }
70
I3cFreeIbi(DevHandle handle,uint16_t addr)71 int32_t I3cFreeIbi(DevHandle handle, uint16_t addr)
72 {
73 return I3cCntlrFreeIbi((struct I3cCntlr *)handle, addr);
74 }
75