1 /*
2  * Copyright (C) 2016 The Android Open Source Project
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 __HOSTINTF_PRIV_H
18 #define __HOSTINTF_PRIV_H
19 
20 #include <i2c.h>
21 #include <stdint.h>
22 #include <stddef.h>
23 
24 
25 /**
26  * hostIntf communication abstraction layer
27  */
28 
29 typedef void (*HostIntfCommCallbackF)(size_t bytesTransferred, int err);
30 struct HostIntfComm {
31     int (*request)(void);
32 
33     int (*rxPacket)(void *rxBuf, size_t rxSize, HostIntfCommCallbackF callback);
34     int (*txPacket)(const void *txBuf, size_t txSize,
35             HostIntfCommCallbackF callback);
36 
37     int (*release)(void);
38 };
39 
40 /**
41  * Returns a HostIntfOps backed by I2C
42  */
43 const struct HostIntfComm *hostIntfI2cInit(uint32_t busId);
44 
45 /**
46  * Returns a HostIntfOps backed by SPI
47  */
48 const struct HostIntfComm *hostIntfSpiInit(uint8_t busId);
49 
50 
51 /**
52  * Platform-internal hostIntf API
53  */
54 
55 /**
56  * Returns the platform's communication implementation.  The platform should
57  * delegate this to hostIntfI2cInit() or hostIntfSpiInit() as appropriate.
58  */
59 const struct HostIntfComm *platHostIntfInit();
60 
61 /**
62  * Returns the platform's hardware type (16-bit, host byte order)
63  */
64 uint16_t platHwType(void);
65 
66 /**
67  * Returns the platform's hardware version (16-bit, host byte order)
68  */
69 uint16_t platHwVer(void);
70 
71 /**
72  * Returns the platform's bootloader version (16-bit, host byte order)
73  */
74 uint16_t platBlVer(void);
75 
76 #endif /* __HOSTINTF_PRIV_H */
77