Updated corresponding to - NFC_AR_00_1E800_14.02.00_OpnSrc

This commit is contained in:
nxf24591
2022-12-16 13:44:14 +05:30
parent 072edd2c88
commit da89b09311
2 changed files with 54 additions and 8 deletions

View File

@@ -126,8 +126,7 @@ int configure_gpio(unsigned int gpio, int flag)
} }
if (ret) { if (ret) {
pr_err("%s: unable to set direction for nfc gpio [%d]\n", pr_err("%s: unable to set direction for nfc gpio [%d]\n", __func__, gpio);
__func__, gpio);
gpio_free(gpio); gpio_free(gpio);
return ret; return ret;
} }
@@ -215,6 +214,45 @@ int nfc_misc_register(struct nfc_dev *nfc_dev,
} }
return 0; return 0;
} }
/**
* nfc_gpio_info() - gets the status of nfc gpio pins and encodes into a byte.
* @nfc_dev: nfc device data structure
* @arg: userspace buffer
*
* Encoding can be done in following manner
* 1) map the gpio value into INVALID(-2), SET(1), RESET(0).
* 2) mask the first 2 bits of gpio.
* 3) left shift the 2 bits as multiple of 2.
* 4) multiply factor can be defined as position of gpio pin in struct platform_gpio
*
* Return: -EFAULT, if unable to copy the data from kernel space to userspace, 0
* if Success(or no issue)
*/
static int nfc_gpio_info(struct nfc_dev *nfc_dev, unsigned long arg)
{
unsigned int gpios_status = 0;
int value = 0;
int gpio_no = 0;
int i;
int ret = 0;
struct platform_gpio *nfc_gpio = &nfc_dev->configs.gpio;
for (i = 0; i < sizeof(struct platform_gpio) / sizeof(unsigned int);
i++) {
gpio_no = *((unsigned int *)nfc_gpio + i);
value = get_valid_gpio(gpio_no);
if (value < 0)
value = -2;
gpios_status |= (value & GPIO_STATUS_MASK_BITS)<<(GPIO_POS_SHIFT_VAL*i);
}
ret = copy_to_user((uint32_t *) arg, &gpios_status, sizeof(value));
if (ret < 0) {
pr_err("%s : Unable to copy data from kernel space to user space");
return -EFAULT;
}
return 0;
}
/** /**
* nfc_ioctl_power_states() - power control * nfc_ioctl_power_states() - power control
@@ -242,12 +280,14 @@ static int nfc_ioctl_power_states(struct nfc_dev *nfc_dev, unsigned long arg)
set_valid_gpio(nfc_gpio->dwl_req, 0); set_valid_gpio(nfc_gpio->dwl_req, 0);
gpio_set_ven(nfc_dev, 0); gpio_set_ven(nfc_dev, 0);
nfc_dev->nfc_ven_enabled = false; nfc_dev->nfc_ven_enabled = false;
nfc_dev->nfc_state = NFC_STATE_NCI;
} else if (arg == NFC_POWER_ON) { } else if (arg == NFC_POWER_ON) {
nfc_dev->nfc_enable_intr(nfc_dev); nfc_dev->nfc_enable_intr(nfc_dev);
set_valid_gpio(nfc_gpio->dwl_req, 0); set_valid_gpio(nfc_gpio->dwl_req, 0);
gpio_set_ven(nfc_dev, 1); gpio_set_ven(nfc_dev, 1);
nfc_dev->nfc_ven_enabled = true; nfc_dev->nfc_ven_enabled = true;
nfc_dev->nfc_state = NFC_STATE_NCI;
} else if (arg == NFC_FW_DWL_VEN_TOGGLE) { } else if (arg == NFC_FW_DWL_VEN_TOGGLE) {
/* /*
* We are switching to download Mode, toggle the enable pin * We are switching to download Mode, toggle the enable pin
@@ -341,13 +381,11 @@ long nfc_dev_ioctl(struct file *pfile, unsigned int cmd, unsigned long arg)
case NFC_SET_RESET_READ_PENDING: case NFC_SET_RESET_READ_PENDING:
if (arg == NFC_SET_READ_PENDING) { if (arg == NFC_SET_READ_PENDING) {
nfc_dev->cold_reset.is_nfc_read_pending = true; nfc_dev->cold_reset.is_nfc_read_pending = true;
/* Set default NFC state as NCI for Nfc read pending request */ /* Set default NFC state as NCI for Nfc read pending request */
nfc_dev->nfc_state = NFC_STATE_NCI; nfc_dev->nfc_state = NFC_STATE_NCI;
} } else if (arg == NFC_RESET_READ_PENDING) {
else if (arg == NFC_RESET_READ_PENDING){
nfc_dev->cold_reset.is_nfc_read_pending = false; nfc_dev->cold_reset.is_nfc_read_pending = false;
} } else {
else {
ret = -EINVAL; ret = -EINVAL;
} }
break; break;
@@ -357,6 +395,9 @@ long nfc_dev_ioctl(struct file *pfile, unsigned int cmd, unsigned long arg)
case ESE_GET_PWR: case ESE_GET_PWR:
ret = nfc_ese_pwr(nfc_dev, ESE_POWER_STATE); ret = nfc_ese_pwr(nfc_dev, ESE_POWER_STATE);
break; break;
case NFC_GET_GPIO_STATUS:
ret = nfc_gpio_info(nfc_dev, arg);
break;
default: default:
pr_err("%s: bad cmd %lu\n", __func__, arg); pr_err("%s: bad cmd %lu\n", __func__, arg);
ret = -ENOIOCTLCMD; ret = -ENOIOCTLCMD;
@@ -431,7 +472,7 @@ int nfc_dev_close(struct inode *inode, struct file *filp)
* if eSE calls flow is via NFC driver * if eSE calls flow is via NFC driver
* i.e. direct calls from SPI HAL to NFC driver * i.e. direct calls from SPI HAL to NFC driver
*/ */
mutex_unlock(&nfc_dev->dev_ref_mutex); mutex_unlock(&nfc_dev->dev_ref_mutex);
nfc_ese_pwr(nfc_dev, ESE_RST_PROT_DIS_NFC); nfc_ese_pwr(nfc_dev, ESE_RST_PROT_DIS_NFC);
mutex_lock(&nfc_dev->dev_ref_mutex); mutex_lock(&nfc_dev->dev_ref_mutex);
} }

View File

@@ -75,10 +75,15 @@
#define ESE_SET_PWR _IOW(NFC_MAGIC, 0x02, uint32_t) #define ESE_SET_PWR _IOW(NFC_MAGIC, 0x02, uint32_t)
#define ESE_GET_PWR _IOR(NFC_MAGIC, 0x03, uint32_t) #define ESE_GET_PWR _IOR(NFC_MAGIC, 0x03, uint32_t)
#define NFC_SET_RESET_READ_PENDING _IOW(NFC_MAGIC, 0x04, uint32_t) #define NFC_SET_RESET_READ_PENDING _IOW(NFC_MAGIC, 0x04, uint32_t)
#define NFC_GET_GPIO_STATUS _IOR(NFC_MAGIC, 0x05, uint32_t)
#define DTS_IRQ_GPIO_STR "nxp,sn-irq" #define DTS_IRQ_GPIO_STR "nxp,sn-irq"
#define DTS_VEN_GPIO_STR "nxp,sn-ven-rstn" #define DTS_VEN_GPIO_STR "nxp,sn-ven-rstn"
#define DTS_FWDN_GPIO_STR "nxp,sn-dwl-req" #define DTS_FWDN_GPIO_STR "nxp,sn-dwl-req"
/* Each GPIO occupies consecutive two bits */
#define GPIO_POS_SHIFT_VAL 2
/* Two bits to indicate GPIO status (Invalid(-2), Set(1) or Reset(0)) */
#define GPIO_STATUS_MASK_BITS 3
enum nfcc_ioctl_request { enum nfcc_ioctl_request {
/* NFC disable request with VEN LOW */ /* NFC disable request with VEN LOW */