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 <unistd.h>
18 #include <sys/types.h>
19 #include <sys/stat.h>
20 #include <log/log.h>
21
22 #include <sys/ioctl.h>
23 #include <fcntl.h>
24 #include <errno.h>
25 #include "spi_spm.h"
26 #include "phNxpLog.h"
27 #include "phTmlNfc_i2c.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, long level)
43 {
44 int ret;
45 NXPLOG_TML_D("phPalEse_spi_ioctl(), ioctl %x , level %lx", eControlCode, level);
46
47 if (NULL == pDevHandle) {
48 return -1;
49 }
50 switch (eControlCode) {
51 case phPalEse_e_ChipRst:
52 if(level == 1 || level == 0)
53 ret = ioctl((intptr_t)pDevHandle, P61_SET_SPI_PWR, level);
54 else
55 ret=0;
56 break;
57
58 case phPalEse_e_GetSPMStatus:
59 ret = ioctl((intptr_t)pDevHandle, P61_GET_PWR_STATUS, level);
60 break;
61
62 case phPalEse_e_SetPowerScheme:
63 ret=0;
64 break;
65 case phPalEse_e_GetEseAccess:
66 ret=0;
67 break;
68 #if(NXP_ESE_JCOP_DWNLD_PROTECTION == TRUE)
69 case phPalEse_e_SetJcopDwnldState:
70 ret=0;
71 break;
72 #endif
73 case phPalEse_e_DisablePwrCntrl:
74 ret = ioctl((intptr_t)pDevHandle, P61_SET_SPI_PWR, 1);
75 break;
76 default:
77 ret=-1;
78 break;
79 }
80 return ret;
81 }
82