1 /*
2  * Copyright (C) 2012-2014 NXP Semiconductors
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 #include <log/log.h>
18 #include <sys/stat.h>
19 #include <sys/types.h>
20 #include <unistd.h>
21 
22 #include <errno.h>
23 #include <fcntl.h>
24 #include <sys/ioctl.h>
25 #include "phNxpLog.h"
26 #include "phTmlNfc_i2c.h"
27 #include "spi_spm.h"
28 
29 /*******************************************************************************
30 **
31 ** Function         phPalEse_spi_ioctl
32 **
33 ** Description      Exposed ioctl by p61 spi driver
34 **
35 ** Parameters       pDevHandle     - valid device handle
36 **                  level          - reset level
37 **
38 ** Returns           0   - ioctl operation success
39 **                  -1   - ioctl operation failure
40 **
41 *******************************************************************************/
phPalEse_spi_ioctl(phPalEse_ControlCode_t eControlCode,void * pDevHandle,long level)42 int phPalEse_spi_ioctl(phPalEse_ControlCode_t eControlCode, void* pDevHandle,
43                        long level) {
44   int ret;
45   NXPLOG_TML_D("phPalEse_spi_ioctl(), ioctl %x , level %lx", eControlCode,
46                level);
47 
48   if (NULL == pDevHandle) {
49     return -1;
50   }
51   switch (eControlCode) {
52     case phPalEse_e_ChipRst:
53       if (level == 1 || level == 0)
54         ret = ioctl((intptr_t)pDevHandle, P61_SET_SPI_PWR, level);
55       else
56         ret = 0;
57       break;
58 
59     case phPalEse_e_GetSPMStatus:
60       ret = ioctl((intptr_t)pDevHandle, P61_GET_PWR_STATUS, level);
61       break;
62 
63     case phPalEse_e_SetPowerScheme:
64       ret = 0;
65       break;
66     case phPalEse_e_GetEseAccess:
67       ret = 0;
68       break;
69 #if (NXP_ESE_JCOP_DWNLD_PROTECTION == TRUE)
70     case phPalEse_e_SetJcopDwnldState:
71       ret = 0;
72       break;
73 #endif
74     case phPalEse_e_DisablePwrCntrl:
75       ret = ioctl((intptr_t)pDevHandle, P61_SET_SPI_PWR, 1);
76       break;
77     default:
78       ret = -1;
79       break;
80   }
81   return ret;
82 }
83