1 /******************************************************************************
2  *
3  *  Copyright (C) 2018-2020 NXP Semiconductors
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 #ifndef ANDROID_HARDWARE_HAL_NXPESE_V1_0_H
19 #define ANDROID_HARDWARE_HAL_NXPESE_V1_0_H
20 
21 #define ESE_NXPNFC_HARDWARE_MODULE_ID "ese_nxp.pn54x"
22 
23 #define MAX_IOCTL_TRANSCEIVE_CMD_LEN 256
24 #define MAX_IOCTL_TRANSCEIVE_RESP_LEN 256
25 #define MAX_ATR_INFO_LEN 128
26 #define HAL_NFC_IOCTL_FIRST_EVT 0xA0
27 enum {
28   HAL_ESE_IOCTL_P61_IDLE_MODE = 0,
29   HAL_ESE_IOCTL_P61_WIRED_MODE,
30   HAL_ESE_IOCTL_P61_PWR_MODE,
31   HAL_ESE_IOCTL_P61_DISABLE_MODE,
32   HAL_ESE_IOCTL_P61_ENABLE_MODE,
33   HAL_ESE_IOCTL_SET_BOOT_MODE,
34   HAL_ESE_IOCTL_GET_CONFIG_INFO,
35   HAL_ESE_IOCTL_CHECK_FLASH_REQ,
36   HAL_ESE_IOCTL_FW_DWNLD,
37   HAL_ESE_IOCTL_FW_MW_VER_CHECK,
38   HAL_ESE_IOCTL_DISABLE_HAL_LOG,
39   HAL_ESE_IOCTL_NXP_TRANSCEIVE,
40   HAL_ESE_IOCTL_P61_GET_ACCESS,
41   HAL_ESE_IOCTL_P61_REL_ACCESS,
42   HAL_ESE_IOCTL_ESE_CHIP_RST,
43   HAL_ESE_IOCTL_REL_SVDD_WAIT,
44   HAL_ESE_IOCTL_SET_JCP_DWNLD_ENABLE,
45   HAL_ESE_IOCTL_SET_JCP_DWNLD_DISABLE,
46   HAL_ESE_IOCTL_SET_ESE_SERVICE_PID,
47   HAL_ESE_IOCTL_REL_DWP_WAIT,
48   HAL_ESE_IOCTL_GET_FEATURE_LIST,
49   HAL_ESE_IOCTL_RF_STATUS_UPDATE,
50   HAL_ESE_IOCTL_NFC_JCOP_DWNLD,
51 #if (NXP_EXTNS == TRUE)
52   HAL_ESE_IOCTL_GET_ESE_UPDATE_STATE,
53 #endif
54 };
55 
56 /*
57  * Data structures provided below are used of Hal Ioctl calls
58  */
59 /*
60  * ese_nxp_ExtnCmd_t shall contain data for commands used for transceive command
61  * in ioctl
62  */
63 typedef struct {
64   uint16_t cmd_len;
65   uint8_t p_cmd[MAX_IOCTL_TRANSCEIVE_CMD_LEN];
66 } ese_nxp_ExtnCmd_t;
67 
68 /*
69  * ese_nxp_ExtnRsp_t shall contain response for command sent in transceive
70  * command
71  */
72 typedef struct {
73   uint16_t rsp_len;
74   uint8_t p_rsp[MAX_IOCTL_TRANSCEIVE_RESP_LEN];
75 } ese_nxp_ExtnRsp_t;
76 /*
77  * InputData_t :ioctl has multiple subcommands
78  * Each command has corresponding input data which needs to be populated in this
79  */
80 typedef union {
81   uint16_t bootMode;
82   uint8_t halType;
83   ese_nxp_ExtnCmd_t nxpCmd;
84   uint32_t timeoutMilliSec;
85   long eseServicePid;
86 } eseInputData_t;
87 /*
88  * ese_nxp_ExtnInputData_t :Apart from InputData_t, there are context data
89  * which is required during callback from stub to proxy.
90  * To avoid additional copy of data while propagating from libese to Adaptation
91  * and Esestub to nxphal, common structure is used. As a sideeffect, context
92  * data is exposed to libese (Not encapsulated).
93  */
94 typedef struct {
95   /*context to be used/updated only by users of proxy & stub of Ese.hal
96    * i.e., EseAdaptation & hardware/interface/Ese.
97    */
98   eseInputData_t data;
99   uint8_t data_source;
100   long level;
101 } ese_nxp_ExtnInputData_t;
102 
103 /*
104  * outputData_t :ioctl has multiple commands/responses
105  * This contains the output types for each ioctl.
106  */
107 typedef union {
108   uint32_t status;
109   ese_nxp_ExtnRsp_t nxpRsp;
110   uint8_t nxpNciAtrInfo[MAX_ATR_INFO_LEN];
111   uint32_t p61CurrentState;
112   uint16_t fwUpdateInf;
113   uint16_t fwDwnldStatus;
114   uint16_t fwMwVerStatus;
115   uint8_t chipType;
116 } eseOutputData_t;
117 
118 typedef union {
119   uint8_t nfc_jcop_download_state;
120 } eseIoctlData_t;
121 extern eseIoctlData_t eseioctldata;
122 
123 /*
124  * ese_nxp_ExtnOutputData_t :Apart from outputData_t, there are other
125  * information which is required during callback from stub to proxy. For ex
126  * (context, result of the operation , type of ioctl which was completed). To
127  * avoid additional copy of data while propagating from libese to Adaptation and
128  * Esestub to nxphal, common structure is used. As a sideeffect, these data is
129  * exposed(Not encapsulated).
130  */
131 typedef struct {
132   /*ioctlType, result & context to be used/updated only by users of
133    * proxy & stub of Ese.hal.
134    * i.e., EseAdaptation & hardware/interface/Ese
135    * These fields shall not be used by libese or halimplementation*/
136   uint64_t ioctlType;
137   uint32_t result;
138   eseOutputData_t data;
139 } ese_nxp_ExtnOutputData_t;
140 
141 /*
142  * ese_nxp_IoctlInOutData_t :data structure for input & output
143  * to be sent for ioctl command. input is populated by client/proxy side
144  * output is provided from server/stub to client/proxy
145  */
146 typedef struct {
147   ese_nxp_ExtnInputData_t inp;
148   ese_nxp_ExtnOutputData_t out;
149 } ese_nxp_IoctlInOutData_t;
150 
151 /*
152  * nxpese_nxp_device_t :data structure for nxp's extended ese_nxp_device
153  * Extra features added are
154  * -ioctl(manage sync between  and DWP & SPI)
155  * -check request for fw download
156  */
157 typedef struct nxpese_nxp_device {
158   // ese_nxp_device_t nxp_device;
159   /*
160    * (*ioctl)() For P61 power management synchronization
161    * between ESE Wired and SPI.
162    */
163   int (*ioctl)(const struct nxpese_nxp_device* p_dev, long arg, void* p_data);
164   /*
165    * (*check_fw_dwnld_flag)() Is called to get FW downlaod request.
166    */
167 } nxpese_nxp_device_t;
168 
169 #endif  // ANDROID_HARDWARE_HAL_NXPESE_V1_0_H
170