• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright 2020-2023 NXP
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 
19 #pragma once
20 #include <NfccTransport.h>
21 
22 #define NFC_MAGIC 0xE9
23 /*
24  * NFCC power control via ioctl
25  * NFC_SET_PWR(0): power off
26  * NFC_SET_PWR(1): power on
27  * NFC_SET_PWR(2): reset and power on with firmware download enabled
28  */
29 #define NFC_SET_PWR _IOW(NFC_MAGIC, 0x01, uint32_t)
30 /*
31  * 1. SPI Request NFCC to enable ESE power, only in param
32  *   Only for SPI
33  *   level 1 = Enable power
34  *   level 0 = Disable power
35  * 2. NFC Request the eSE cold reset, only with MODE_ESE_COLD_RESET
36  */
37 #define ESE_SET_PWR _IOW(NFC_MAGIC, 0x02, uint32_t)
38 
39 /*
40  * SPI or DWP can call this ioctl to get the current
41  * power state of ESE
42  */
43 #define ESE_GET_PWR _IOR(NFC_MAGIC, 0x03, uint32_t)
44 /*
45  *  NFC_SET_RESET_READ_PENDING(1): set read pending flag of NFC
46  *  NFC_SET_RESET_READ_PENDING(0): reset read pending flag of NFC
47  */
48 #define NFC_SET_RESET_READ_PENDING _IOW(NFC_MAGIC, 0x04, uint32_t)
49 
50 /*
51  * read the gpios status flag encoded byte from kernel space
52  */
53 #define NFC_GET_GPIO_STATUS _IOR(NFC_MAGIC, 0x05, uint32_t)
54 
55 extern phTmlNfc_i2cfragmentation_t fragmentation_enabled;
56 
57 class NfccI2cTransport : public NfccTransport {
58  private:
59   bool_t bFwDnldFlag = false;
60   sem_t mTxRxSemaphore;
61 
62  public:
63   /*****************************************************************************
64   **
65   ** Function         Close
66   **
67   ** Description      Closes NFCC device
68   **
69   ** Parameters       pDevHandle - device handle
70   **
71   ** Returns          None
72   **
73   *****************************************************************************/
74   void Close(void* pDevHandle);
75 
76   /*****************************************************************************
77    **
78    ** Function         OpenAndConfigure
79    **
80    ** Description      Open and configure NFCC device
81    **
82    ** Parameters       pConfig     - hardware information
83    **                  pLinkHandle - device handle
84    **
85    ** Returns          NFC status:
86    **                  NFCSTATUS_SUCCESS - open_and_configure operation success
87    **                  NFCSTATUS_INVALID_DEVICE - device open operation failure
88    **
89    ****************************************************************************/
90   NFCSTATUS OpenAndConfigure(pphTmlNfc_Config_t pConfig, void** pLinkHandle);
91 
92   /*****************************************************************************
93    **
94    ** Function         Read
95    **
96    ** Description      Reads requested number of bytes from NFCC device into
97    *given
98    **                  buffer
99    **
100    ** Parameters       pDevHandle       - valid device handle
101    **                  pBuffer          - buffer for read data
102    **                  nNbBytesToRead   - number of bytes requested to be read
103    **
104    ** Returns          numRead   - number of successfully read bytes
105    **                  -1        - read operation failure
106    **
107    ****************************************************************************/
108   int Read(void* pDevHandle, uint8_t* pBuffer, int nNbBytesToRead);
109 
110   /*****************************************************************************
111   **
112   ** Function         Write
113   **
114   ** Description      Writes requested number of bytes from given buffer into
115   **                  NFCC device
116   **
117   ** Parameters       pDevHandle       - valid device handle
118   **                  pBuffer          - buffer for read data
119   **                  nNbBytesToWrite  - number of bytes requested to be written
120   **
121   ** Returns          numWrote   - number of successfully written bytes
122   **                  -1         - write operation failure
123   **
124   *****************************************************************************/
125   int Write(void* pDevHandle, uint8_t* pBuffer, int nNbBytesToWrite);
126 
127   /*****************************************************************************
128    **
129    ** Function         Reset
130    **
131    ** Description      Reset NFCC device, using VEN pin
132    **
133    ** Parameters       pDevHandle     - valid device handle
134    **                  level          - reset level
135    **
136    ** Returns           0   - reset operation success
137    **                  -1   - reset operation failure
138    **
139    ****************************************************************************/
140   int NfccReset(void* pDevHandle, NfccResetType eType);
141 
142   /*****************************************************************************
143    **
144    ** Function         UpdateReadPending
145    **
146    ** Description      Set/Reset Read Pending of NFC
147    **
148    ** Parameters       pDevHandle     - valid device handle
149    **                  eType          - set or clear the flag
150    **
151    ** Returns           0   - operation success
152    **                  -1   - operation failure
153    **
154    ****************************************************************************/
155   int UpdateReadPending(void* pDevHandle, NfcReadPending eType);
156 
157   /*****************************************************************************
158    **
159    ** Function         NfcGetGpioStatus
160    **
161    ** Description      Get the gpio status flag byte from kernel space
162    **
163    ** Parameters       pDevHandle     - valid device handle
164    **
165    **
166    ** Returns           0   - operation success
167    **                  -1   - operation failure
168    **
169    ****************************************************************************/
170   int NfcGetGpioStatus(void* pDevHandle, uint32_t* status);
171 
172   /*****************************************************************************
173    **
174    ** Function         EseReset
175    **
176    ** Description      Request NFCC to reset the eSE
177    **
178    ** Parameters       pDevHandle     - valid device handle
179    **                  eType          - EseResetType
180    **
181    ** Returns           0   - reset operation success
182    **                  else - reset operation failure
183    **
184    ****************************************************************************/
185   int EseReset(void* pDevHandle, EseResetType eType);
186 
187   /*****************************************************************************
188    **
189    ** Function         EnableFwDnldMode
190    **
191    ** Description      updates the state to Download mode
192    **
193    ** Parameters       True/False
194    **
195    ** Returns          None
196    ****************************************************************************/
197   void EnableFwDnldMode(bool mode);
198 
199   /*****************************************************************************
200    **
201    ** Function         IsFwDnldModeEnabled
202    **
203    ** Description      Returns the current mode
204    **
205    ** Parameters       none
206    **
207    ** Returns           Current mode download/NCI
208    ****************************************************************************/
209   bool_t IsFwDnldModeEnabled(void);
210 
211   /*******************************************************************************
212   **
213   ** Function         Flushdata
214   **
215   ** Description      Reads payload of FW rsp from NFCC device into given buffer
216   **
217   ** Parameters       pConfig     - hardware information
218   **
219   ** Returns          True(Success)/False(Fail)
220   **
221   *******************************************************************************/
222   bool Flushdata(pphTmlNfc_Config_t pConfig);
223 };
224