/*
 * Copyright (C) 2010-2014 NXP Semiconductors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * TML I2C port implementation for linux
 */

/* Basic type definitions */
#include <phEseTypes.h>
#include "tz_log.h"
//#define LOG_TAG "NxpEse"

#define P61_MAGIC 0xEB
#define P61_SET_PWR _IOW(P61_MAGIC, 0x01, unsigned long)
#define P61_SET_DBG _IOW(P61_MAGIC, 0x02, unsigned long)
#define P61_SET_POLL _IOW(P61_MAGIC, 0x03, unsigned long)

/* To set SPI configurations like gpio, clks */
#define P61_SET_SPI_CONFIG _IO(P61_MAGIC, 0x04)
/* Set the baud rate of SPI master clock nonTZ */
#define P61_ENABLE_SPI_CLK _IO(P61_MAGIC, 0x05)
/* To disable spi core clock */
#define P61_DISABLE_SPI_CLK _IO(P61_MAGIC, 0x06)
/* Transmit data to the device and retrieve data from it simultaneously.*/
#define P61_RW_SPI_DATA _IOWR(P61_MAGIC, 0x07, unsigned long)

struct p61_ioctl_transfer 
{    
    unsigned char *rx_buffer;    
    unsigned char *tx_buffer;
    unsigned int len;
};
/*
 * Enum definition contains  supported ioctl control codes.
 *
 * phTmlEse_IoCtl
 */
typedef enum
{
    phTmlEse_e_Invalid = 0,
    phTmlEse_e_ResetDevice,
    phTmlEse_e_EnableLog, /* Enable the spi driver logs */
    phTmlEse_e_EnablePollMode, /* Enable the polling for SPI */
    phTmlEse_e_SetSpiMode, /* To set SPI configurations like gpio, clks */
    phTmlEse_e_EnableSpiClock, /* Set the baud rate of SPI master clock nonTZ */
    phTmlEse_e_DisableSpiClock, /* To disable spi core clock */
    phTmlEse_e_ExchangeSpiData /* Transmit data to the device and retrieve data from it simultaneously.*/

} phTmlEse_ControlCode_t ;  /* Control code for IOCTL call */

/* Function declarations */
void phTmlEse_spi_close(int DevHandle);
ESESTATUS phTmlEse_spi_open_and_configure(int *pLinkHandle, const char *pDevName);
int phTmlEse_spi_read(uint8_t * pBuffer, int nNbBytesToRead);
int phTmlEse_spi_write(uint8_t * pBuffer, int nNbBytesToWrite);
