Updated corresponding to - NFC_AR_00_E000_12.04.01_OpnSrc
Esse commit está contido em:
188
nfc/common.h
188
nfc/common.h
@@ -1,7 +1,7 @@
|
||||
/******************************************************************************
|
||||
* Copyright (C) 2015, The Linux Foundation. All rights reserved.
|
||||
* Copyright (C) 2019-2021 NXP
|
||||
* *
|
||||
* Copyright (C) 2015, The Linux Foundation. All rights reserved.
|
||||
* Copyright (C) 2019-2021 NXP
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
@@ -19,96 +19,68 @@
|
||||
******************************************************************************/
|
||||
#ifndef _COMMON_H_
|
||||
#define _COMMON_H_
|
||||
#include <linux/types.h>
|
||||
#include <linux/version.h>
|
||||
#include <linux/semaphore.h>
|
||||
#include <linux/completion.h>
|
||||
#include <linux/ioctl.h>
|
||||
|
||||
#include <linux/cdev.h>
|
||||
#include <linux/spinlock.h>
|
||||
#include <linux/gpio.h>
|
||||
|
||||
#include "i2c_drv.h"
|
||||
|
||||
#define DEV_COUNT 1 /* Max device count for this driver */
|
||||
#define CLASS_NAME "nfc" /* i2c device class */
|
||||
/* Max device count for this driver */
|
||||
#define DEV_COUNT 1
|
||||
/* i2c device class */
|
||||
#define CLASS_NAME "nfc"
|
||||
|
||||
// NFC character device name, this will be in /dev/
|
||||
#define NFC_CHAR_DEV_NAME "pn553"
|
||||
/* NFC character device name, this will be in /dev/ */
|
||||
#define NFC_CHAR_DEV_NAME "pn553"
|
||||
|
||||
// NCI packet details
|
||||
#define NCI_MSG_CMD 0x20
|
||||
#define NCI_MSG_RSP 0x40
|
||||
#define NCI_MSG_NTF 0x60
|
||||
#define NCI_HDR_LEN 3
|
||||
#define NCI_PAYLOAD_IDX 3
|
||||
#define NCI_PAYLOAD_LEN_IDX 2
|
||||
/*Time to wait for first NCI rest response*/
|
||||
#define NCI_RESET_RESP_READ_DELAY (10000) // 10ms
|
||||
#define NCI_RESET_RESP_TIMEOUT (500) // 500ms
|
||||
/* NCI packet details */
|
||||
#define NCI_CMD (0x20)
|
||||
#define NCI_RSP (0x40)
|
||||
#define NCI_HDR_LEN (3)
|
||||
#define NCI_HDR_IDX (0)
|
||||
#define NCI_HDR_OID_IDX (1)
|
||||
#define NCI_PAYLOAD_IDX (3)
|
||||
#define NCI_PAYLOAD_LEN_IDX (2)
|
||||
|
||||
// FW DNLD packet details
|
||||
#define FW_MSG_CMD_RSP 0x00
|
||||
#define FW_HDR_LEN 2
|
||||
#define FW_PAYLOAD_LEN_IDX 1
|
||||
#define FW_CRC_LEN 2
|
||||
#define FW_MIN_PAYLOAD_LEN 4
|
||||
#define MIN_NFC_DL_FRAME_SIZE 3
|
||||
/* FW DNLD packet details */
|
||||
#define DL_HDR_LEN (2)
|
||||
#define DL_CRC_LEN (2)
|
||||
|
||||
#define NCI_RESET_CMD_LEN (4)
|
||||
#define NCI_RESET_RSP_LEN (4)
|
||||
#define NCI_RESET_NTF_LEN (13)
|
||||
#define MAX_NCI_PAYLOAD_LEN (255)
|
||||
#define MAX_NCI_BUFFER_SIZE (NCI_HDR_LEN + MAX_NCI_PAYLOAD_LEN)
|
||||
#define MAX_DL_PAYLOAD_LEN (550)
|
||||
#define MAX_DL_BUFFER_SIZE (DL_HDR_LEN + DL_CRC_LEN + \
|
||||
MAX_DL_PAYLOAD_LEN)
|
||||
|
||||
#define SN1XX_ROM_VER 0x01
|
||||
#define SN1xx_MAJOR_VER 0x10
|
||||
#define SN220_ROM_VER 0x01
|
||||
#define SN220_MAJOR_VER 0x01
|
||||
#define FW_ROM_CODE_VER_OFFSET 4
|
||||
#define FW_MAJOR_VER_OFFSET 7
|
||||
|
||||
#define DL_GET_VERSION_CMD_LEN (8)
|
||||
#define DL_GET_VERSION_RSP_LEN_1 (12)
|
||||
#define DL_GET_VERSION_RSP_LEN_2 (20)
|
||||
/* Retry count for normal write */
|
||||
#define NO_RETRY (1)
|
||||
/* Maximum retry count for standby writes */
|
||||
#define MAX_RETRY_COUNT (3)
|
||||
#define MAX_WRITE_IRQ_COUNT (5)
|
||||
#define MAX_IRQ_WAIT_TIME (90)
|
||||
#define WAKEUP_SRC_TIMEOUT (2000)
|
||||
|
||||
#define DL_RESET_CMD_LEN (8)
|
||||
#define DL_GET_SESSION_STATE_CMD_LEN (8)
|
||||
#define DL_GET_SESSION_STATE_RSP_LEN (8)
|
||||
#define GET_SESSION_STS_OFF (3)
|
||||
#define NFCC_SESSION_STS_CLOSED (0x0)
|
||||
#define MAX_NCI_PAYLOAD_LEN (255)
|
||||
#define MAX_BUFFER_SIZE (NCI_HDR_LEN + MAX_NCI_PAYLOAD_LEN)
|
||||
#define MAX_DL_PAYLOAD_LEN (550)
|
||||
#define MAX_DL_BUFFER_SIZE (FW_HDR_LEN + FW_CRC_LEN + MAX_DL_PAYLOAD_LEN)
|
||||
// Maximum retry count for standby writes
|
||||
#define MAX_RETRY_COUNT (3)
|
||||
// Retry count for normal write
|
||||
#define NO_RETRY (1)
|
||||
#define MAX_IRQ_WAIT_TIME (90)
|
||||
#define WAKEUP_SRC_TIMEOUT (2000)
|
||||
/* command response timeout */
|
||||
#define NCI_CMD_RSP_TIMEOUT_MS (2000)
|
||||
/* Time to wait for NFCC to be ready again after any change in the GPIO */
|
||||
#define NFC_GPIO_SET_WAIT_TIME_US (10000)
|
||||
/* Time to wait for IRQ low during write 5*3ms */
|
||||
#define NFC_WRITE_IRQ_WAIT_TIME_US (3000)
|
||||
/* Time to wait before retrying i2c/I3C writes */
|
||||
#define WRITE_RETRY_WAIT_TIME_US (1000)
|
||||
/* Time to wait before retrying read for some specific usecases */
|
||||
#define READ_RETRY_WAIT_TIME_US (3500)
|
||||
#define NFC_MAGIC (0xE9)
|
||||
|
||||
/*command response timeout*/
|
||||
#define NCI_CMD_RSP_TIMEOUT (2000) //2s
|
||||
/*Time to wait for NFCC to be ready again after any change in the GPIO*/
|
||||
#define NFC_GPIO_SET_WAIT_TIME_USEC (10000)
|
||||
/*Time to wait after soft reset via any NCI/DL cmd*/
|
||||
#define NFC_SOFT_RESET_WAIT_TIME_USEC (5000)
|
||||
/*Time to wait before retrying i2c/I3C writes*/
|
||||
#define WRITE_RETRY_WAIT_TIME_USEC (1000)
|
||||
/*Time to wait before retrying read for some specific usecases*/
|
||||
#define READ_RETRY_WAIT_TIME_USEC (3500)
|
||||
#define NFC_MAGIC 0xE9
|
||||
/* Ioctls */
|
||||
/* The type should be aligned with MW HAL definitions */
|
||||
#define NFC_SET_PWR _IOW(NFC_MAGIC, 0x01, long)
|
||||
#define ESE_SET_PWR _IOW(NFC_MAGIC, 0x02, long)
|
||||
#define ESE_GET_PWR _IOR(NFC_MAGIC, 0x03, long)
|
||||
|
||||
/*Ioctls*/
|
||||
// The type should be aligned with MW HAL definitions
|
||||
#define NFC_SET_PWR _IOW(NFC_MAGIC, 0x01, long)
|
||||
#define ESE_SET_PWR _IOW(NFC_MAGIC, 0x02, long)
|
||||
#define ESE_GET_PWR _IOR(NFC_MAGIC, 0x03, long)
|
||||
/* NFC HAL can call this ioctl to get the current IRQ state */
|
||||
#define NFC_GET_IRQ_STATE _IO(NFC_MAGIC, 0x06)
|
||||
|
||||
#define DTS_IRQ_GPIO_STR "nxp,pn544-irq"
|
||||
#define DTS_VEN_GPIO_STR "nxp,pn544-ven"
|
||||
#define DTS_FWDN_GPIO_STR "nxp,pn544-fw-dwnld"
|
||||
#define DTS_IRQ_GPIO_STR "nxp,pn544-irq"
|
||||
#define DTS_VEN_GPIO_STR "nxp,pn544-ven"
|
||||
#define DTS_FWDN_GPIO_STR "nxp,pn544-fw-dwnld"
|
||||
|
||||
enum nfcc_ioctl_request {
|
||||
/* NFC disable request with VEN LOW */
|
||||
@@ -127,21 +99,21 @@ enum nfcc_ioctl_request {
|
||||
NFC_FW_DWL_LOW,
|
||||
};
|
||||
|
||||
/*nfc platform interface type*/
|
||||
/* nfc platform interface type */
|
||||
enum interface_flags {
|
||||
/*I2C physical IF for NFCC */
|
||||
/* I2C physical IF for NFCC */
|
||||
PLATFORM_IF_I2C = 0,
|
||||
};
|
||||
|
||||
/*nfc state flags*/
|
||||
/* nfc state flags */
|
||||
enum nfc_state_flags {
|
||||
/*nfc in unknown state */
|
||||
/* nfc in unknown state */
|
||||
NFC_STATE_UNKNOWN = 0,
|
||||
/*nfc in download mode */
|
||||
/* nfc in download mode */
|
||||
NFC_STATE_FW_DWL = 0x1,
|
||||
/*nfc booted in NCI mode */
|
||||
/* nfc booted in NCI mode */
|
||||
NFC_STATE_NCI = 0x2,
|
||||
/*nfc booted in Fw teared mode */
|
||||
/* nfc booted in Fw teared mode */
|
||||
NFC_STATE_FW_TEARED = 0x4,
|
||||
};
|
||||
/*
|
||||
@@ -154,7 +126,7 @@ enum pm_state_flags {
|
||||
PM_STATE_IBI_BEFORE_RESUME,
|
||||
};
|
||||
|
||||
/* Enum for GPIO values*/
|
||||
/* Enum for GPIO values */
|
||||
enum gpio_values {
|
||||
GPIO_INPUT = 0x0,
|
||||
GPIO_OUTPUT = 0x1,
|
||||
@@ -163,35 +135,29 @@ enum gpio_values {
|
||||
GPIO_IRQ = 0x4,
|
||||
};
|
||||
|
||||
// NFC GPIO variables
|
||||
/* NFC GPIO variables */
|
||||
struct platform_gpio {
|
||||
unsigned int irq;
|
||||
unsigned int ven;
|
||||
unsigned int dwl_req;
|
||||
};
|
||||
|
||||
// NFC Struct to get all the required configs from DTS
|
||||
/* NFC Struct to get all the required configs from DTS */
|
||||
struct platform_configs {
|
||||
struct platform_gpio gpio;
|
||||
};
|
||||
|
||||
//cold reset Features specific Parameters
|
||||
/* cold reset Features specific Parameters */
|
||||
struct cold_reset {
|
||||
bool rsp_pending; /*cmd rsp pending status */
|
||||
bool in_progress; /*for cold reset when gurad timer in progress */
|
||||
bool reset_protection; /*reset protection enabled/disabled */
|
||||
uint8_t status; /*status from response buffer */
|
||||
uint8_t rst_prot_src; /*reset protection source (SPI, NFC) */
|
||||
bool rsp_pending; /* cmd rsp pending status */
|
||||
bool in_progress; /* for cold reset when gurad timer in progress */
|
||||
bool reset_protection; /* reset protection enabled/disabled */
|
||||
uint8_t status; /* status from response buffer */
|
||||
uint8_t rst_prot_src; /* reset protection source (SPI, NFC) */
|
||||
struct timer_list timer;
|
||||
wait_queue_head_t read_wq;
|
||||
};
|
||||
|
||||
enum chip_types {
|
||||
CHIP_SN1XX = 0x01,
|
||||
CHIP_SN220 = 0x02,
|
||||
CHIP_UNKNOWN = 0xFF,
|
||||
};
|
||||
|
||||
/* Device specific structure */
|
||||
struct nfc_dev {
|
||||
wait_queue_head_t read_wq;
|
||||
@@ -211,18 +177,17 @@ struct nfc_dev {
|
||||
uint8_t nfc_state;
|
||||
/* NFC VEN pin state */
|
||||
bool nfc_ven_enabled;
|
||||
/* current firmware major version */
|
||||
uint8_t fw_major_version;
|
||||
union {
|
||||
struct i2c_dev i2c_dev;
|
||||
};
|
||||
struct platform_configs configs;
|
||||
struct cold_reset cold_reset;
|
||||
|
||||
/*function pointers for the common i2c functionality */
|
||||
int (*nfc_read)(struct nfc_dev *dev, char *buf, size_t count, int timeout);
|
||||
int (*nfc_write)(struct nfc_dev *dev, const char *buf, const size_t count,
|
||||
int max_retry_cnt);
|
||||
/* function pointers for the common i2c functionality */
|
||||
int (*nfc_read)(struct nfc_dev *dev, char *buf, size_t count,
|
||||
int timeout);
|
||||
int (*nfc_write)(struct nfc_dev *dev, const char *buf,
|
||||
const size_t count, int max_retry_cnt);
|
||||
int (*nfc_enable_intr)(struct nfc_dev *dev);
|
||||
int (*nfc_disable_intr)(struct nfc_dev *dev);
|
||||
};
|
||||
@@ -233,12 +198,11 @@ long nfc_dev_ioctl(struct file *pfile, unsigned int cmd, unsigned long arg);
|
||||
int nfc_parse_dt(struct device *dev, struct platform_configs *nfc_configs,
|
||||
uint8_t interface);
|
||||
int nfc_misc_register(struct nfc_dev *nfc_dev,
|
||||
const struct file_operations *nfc_fops, int count, char *devname,
|
||||
char *classname);
|
||||
const struct file_operations *nfc_fops, int count,
|
||||
char *devname, char *classname);
|
||||
void nfc_misc_unregister(struct nfc_dev *nfc_dev, int count);
|
||||
int configure_gpio(unsigned int gpio, int flag);
|
||||
void gpio_set_ven(struct nfc_dev *nfc_dev, int value);
|
||||
void gpio_free_all(struct nfc_dev *nfc_dev);
|
||||
int validate_nfc_state_nci(struct nfc_dev *nfc_dev);
|
||||
int nfcc_hw_check(struct nfc_dev *nfc_dev);
|
||||
#endif //_COMMON_H_
|
||||
#endif /* _COMMON_H_ */
|
||||
|
Referência em uma nova issue
Block a user