1 /******************************************************************************
2  *
3  *  Copyright 2018-2019 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 /**
20  * \addtogroup SPI_Power_Management
21  *
22  * @{ */
23 
24 #ifndef _PHNXPESE_SPM_H
25 #define _PHNXPESE_SPM_H
26 
27 #include <phEseStatus.h>
28 #include <phNxpEseFeatures.h>
29 /*! SPI Power Manager (SPM) possible error codes */
30 typedef enum spm_power {
31   SPM_POWER_DISABLE = 0,
32   SPM_POWER_ENABLE,       /*!< SPM power disable */
33   SPM_POWER_RESET,        /*!< SPM Reset pwer */
34   SPM_POWER_PRIO_ENABLE,  /*!< SPM prio mode enable */
35   SPM_POWER_PRIO_DISABLE, /*!< SPM prio mode disable */
36   SPM_RECOVERY_RESET
37 } spm_power_t;
38 
39 /*! SPI Power Manager (SPM) possible states */
40 typedef enum spm_state {
41   SPM_STATE_INVALID = 0x0000,      /*!< Nfc i2c driver misbehaving */
42   SPM_STATE_IDLE = 0x0100,         /*!< ESE is free to use */
43   SPM_STATE_WIRED = 0x0200,        /*!< p61 is being accessed by DWP (NFCC)*/
44   SPM_STATE_SPI = 0x0400,          /*!< ESE is being accessed by SPI */
45   SPM_STATE_DWNLD = 0x0800,        /*!< NFCC fw download is in progress */
46   SPM_STATE_SPI_PRIO = 0x1000,     /*!< Start of p61 access by SPI on priority*/
47   SPM_STATE_SPI_PRIO_END = 0x2000, /*!< End of p61 access by SPI on priority*/
48   SPM_STATE_SPI_FAILED = 0x0010,   /*SPI open/close failed*/
49   SPM_STATE_JCOP_DWNLD = 0x8000    /*!< P73 state JCOP Download*/
50 } spm_state_t;
51 
52 /**
53  * \ingroup SPI_Power_Management
54  * \brief This function opens the nfc i2c driver to manage power
55  *                  and synchronization for ese secure element.
56  *
57  * \param[in]    pDevHandle       - Device handle to open.
58  *
59  * \retval       -On Success ESESTATUS_SUCCESS else proper error code
60  */
61 ESESTATUS phNxpEse_SPM_Init(void* pDevHandle);
62 
63 /**
64  * \ingroup SPI_Power_Management
65  * \brief TThis function closes the nfc i2c driver node.
66  *
67  *
68  * \retval       -On Success ESESTATUS_SUCCESS else proper error code
69  */
70 ESESTATUS phNxpEse_SPM_DeInit(void);
71 
72 /**
73  * \ingroup SPI_Power_Management
74  * \brief This function request to the nfc i2c driver
75  * to enable/disable power to ese. This api should be called
76  *before sending any apdu to ese/once apdu exchange is done.
77  *
78  * \param[in]    arg       -input can be of  type spm_power_t.
79  *
80  * \retval       -On Success ESESTATUS_SUCCESS else proper error code
81  */
82 ESESTATUS phNxpEse_SPM_ConfigPwr(spm_power_t arg);
83 
84 /**
85  * \ingroup SPI_Power_Management
86  * \brief This function request to the nfc i2c driver
87  *                  to enable power to ese. This api should be called before
88  *                  sending any apdu to ese.
89  *
90  *
91  * \retval       -On Success ESESTATUS_SUCCESS else proper error code
92  */
93 ESESTATUS phNxpEse_SPM_EnablePwr(void);
94 
95 /**
96  * \ingroup SPI_Power_Management
97  * \brief This function request to the nfc i2c driver
98  *                  to disable power to ese. This api should be called
99  *                  once apdu exchange is done.
100  *
101  *
102  * \retval       -On Success ESESTATUS_SUCCESS else proper error code
103  */
104 ESESTATUS phNxpEse_SPM_DisablePwr(void);
105 
106 /**
107  * \ingroup SPI_Power_Management
108  * \brief This function gets the current power state of ESE
109  * \param[in]    current_state       -input is of type spm_state_t.
110  *
111  * \retval       -On Success ESESTATUS_SUCCESS else proper error code
112  */
113 ESESTATUS phNxpEse_SPM_GetState(spm_state_t* current_state);
114 
115 /**
116  * \ingroup SPI_Power_Management
117  * \brief  This function request to the nfc i2c driver
118  *                  to reset ese.
119  *
120  * \retval       -On Success ESESTATUS_SUCCESS else proper error code
121  */
122 ESESTATUS phNxpEse_SPM_ResetPwr(void);
123 
124 /**
125  * \ingroup SPI_Power_Management
126  * \brief  This function request to get access to eSE
127  *
128  * \param[in]    timeout - timeout to wait for ese access.
129  *
130  * \retval       -On Success ESESTATUS_SUCCESS else proper error code
131  */
132 ESESTATUS phNxpEse_SPM_GetAccess(long timeout);
133 
134 /**
135  * \ingroup SPI_Power_Management
136  * \brief  This function set the SPM power state
137  *
138  * \param[in]    arg - state value.
139  *
140  * \retval       -On Success ESESTATUS_SUCCESS else proper error code
141  */
142 ESESTATUS phNxpEse_SPM_SetState(long arg);
143 
144 /**
145  * \ingroup SPI_Power_Management
146  * \brief  phNxpEse_SPM_RelAccess
147  *
148  *
149  * \retval       -On Success ESESTATUS_SUCCESS else proper error code
150  */
151 ESESTATUS phNxpEse_SPM_RelAccess(void);
152 
153 /**
154  * \ingroup SPI_Power_Management
155  * \brief   This function request to the nfc i2c driver
156  *                  to set the chip type and power scheme.
157  *
158  * \param[in]    arg - set power scheme from config.
159  *
160  * \retval       -On Success ESESTATUS_SUCCESS else proper error code
161  */
162 ESESTATUS phNxpEse_SPM_SetPwrScheme(long arg);
163 
164 /**
165  * \ingroup SPI_Power_Management
166  * \brief    This function request to the nfc i2c driver
167  *                  to set the chip type and power scheme.
168  *
169  * \param[in]    arg - arg.
170  *
171  * \retval       -On Success ESESTATUS_SUCCESS else proper error code
172  */
173 ESESTATUS phNxpEse_SPM_DisablePwrControl(unsigned long arg);
174 /**
175  * \ingroup SPI_Power_Management
176  * \brief   This function is used to set the ese Update state.
177  *
178  * \param[in]    arg - eSE update status started/completed.
179  *
180  * \retval       -On Success ESESTATUS_SUCCESS else proper error code
181  */
182 ESESTATUS phNxpEse_SPM_SetEseClientUpdateState(long arg);
183 
184 /**
185  * \ingroup SPI_Power_Management
186  * \brief   This function is used to set the ese Update state.
187  *
188  * \param[in]    arg -  JCOP update status started/completed..
189  *
190  * \retval       -On Success ESESTATUS_SUCCESS else proper error code
191  */
192 ESESTATUS phNxpEse_SPM_SetJcopDwnldState(long arg);
193 
194 #endif /*  _PHNXPESE_SPM_H    */
195 /** @} */
196