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) {
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);
}