From da89b093114cbce525056ec4068f7b1d7d83d69b Mon Sep 17 00:00:00 2001 From: nxf24591 Date: Fri, 16 Dec 2022 13:44:14 +0530 Subject: [PATCH] Updated corresponding to - NFC_AR_00_1E800_14.02.00_OpnSrc --- nfc/common.c | 57 ++++++++++++++++++++++++++++++++++++++++++++-------- nfc/common.h | 5 +++++ 2 files changed, 54 insertions(+), 8 deletions(-) diff --git a/nfc/common.c b/nfc/common.c index 5425efa6d3..f34baa9a5b 100644 --- a/nfc/common.c +++ b/nfc/common.c @@ -126,8 +126,7 @@ int configure_gpio(unsigned int gpio, int flag) } if (ret) { - pr_err("%s: unable to set direction for nfc gpio [%d]\n", - __func__, gpio); + pr_err("%s: unable to set direction for nfc gpio [%d]\n", __func__, gpio); gpio_free(gpio); return ret; } @@ -215,6 +214,45 @@ int nfc_misc_register(struct nfc_dev *nfc_dev, } 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 @@ -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); gpio_set_ven(nfc_dev, 0); nfc_dev->nfc_ven_enabled = false; + nfc_dev->nfc_state = NFC_STATE_NCI; } else if (arg == NFC_POWER_ON) { nfc_dev->nfc_enable_intr(nfc_dev); set_valid_gpio(nfc_gpio->dwl_req, 0); gpio_set_ven(nfc_dev, 1); nfc_dev->nfc_ven_enabled = true; + nfc_dev->nfc_state = NFC_STATE_NCI; } else if (arg == NFC_FW_DWL_VEN_TOGGLE) { /* * 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: if (arg == NFC_SET_READ_PENDING) { 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; - } - else if (arg == NFC_RESET_READ_PENDING){ + } else if (arg == NFC_RESET_READ_PENDING) { nfc_dev->cold_reset.is_nfc_read_pending = false; - } - else { + } else { ret = -EINVAL; } break; @@ -357,6 +395,9 @@ long nfc_dev_ioctl(struct file *pfile, unsigned int cmd, unsigned long arg) case ESE_GET_PWR: ret = nfc_ese_pwr(nfc_dev, ESE_POWER_STATE); break; + case NFC_GET_GPIO_STATUS: + ret = nfc_gpio_info(nfc_dev, arg); + break; default: pr_err("%s: bad cmd %lu\n", __func__, arg); ret = -ENOIOCTLCMD; @@ -431,7 +472,7 @@ int nfc_dev_close(struct inode *inode, struct file *filp) * if eSE calls flow is via 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); mutex_lock(&nfc_dev->dev_ref_mutex); } diff --git a/nfc/common.h b/nfc/common.h index 2c82394cc0..91c043b313 100644 --- a/nfc/common.h +++ b/nfc/common.h @@ -75,10 +75,15 @@ #define ESE_SET_PWR _IOW(NFC_MAGIC, 0x02, 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_GET_GPIO_STATUS _IOR(NFC_MAGIC, 0x05, uint32_t) #define DTS_IRQ_GPIO_STR "nxp,sn-irq" #define DTS_VEN_GPIO_STR "nxp,sn-ven-rstn" #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 { /* NFC disable request with VEN LOW */