Updated corresponding to - NFC_AR_00_E000_12.04.01_OpnSrc

Esse commit está contido em:
nxf35421
2021-04-29 20:39:02 +05:30
commit f64dad377c
7 arquivos alterados com 404 adições e 684 exclusões

Ver arquivo

@@ -1,7 +1,7 @@
/******************************************************************************
* Copyright (C) 2015, The Linux Foundation. All rights reserved.
* Copyright (C) 2013-2021 NXP
* *
* Copyright (C) 2015, The Linux Foundation. All rights reserved.
* Copyright (C) 2013-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
@@ -34,15 +34,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <linux/fs.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/of_device.h>
#include <linux/interrupt.h>
#include <linux/delay.h>
#include <linux/uaccess.h>
#include <linux/slab.h>
#include "common.h"
#include <linux/gpio.h>
#include "common_ese.h"
/**
@@ -103,20 +101,19 @@ static irqreturn_t i2c_irq_handler(int irq, void *dev_id)
return IRQ_HANDLED;
}
int i2c_read(struct nfc_dev *nfc_dev, char *buf, size_t count, int timeout)
{
int ret;
struct i2c_dev *i2c_dev = &nfc_dev->i2c_dev;
struct platform_gpio *nfc_gpio = &nfc_dev->configs.gpio;
pr_debug("%s : reading %zu bytes.\n", __func__, count);
pr_debug("%s: reading %zu bytes.\n", __func__, count);
if (timeout > NCI_CMD_RSP_TIMEOUT)
timeout = NCI_CMD_RSP_TIMEOUT;
if (timeout > NCI_CMD_RSP_TIMEOUT_MS)
timeout = NCI_CMD_RSP_TIMEOUT_MS;
if (count > MAX_BUFFER_SIZE)
count = MAX_BUFFER_SIZE;
if (count > MAX_NCI_BUFFER_SIZE)
count = MAX_NCI_BUFFER_SIZE;
if (!gpio_get_value(nfc_gpio->irq)) {
while (1) {
@@ -127,18 +124,23 @@ int i2c_read(struct nfc_dev *nfc_dev, char *buf, size_t count, int timeout)
}
if (!gpio_get_value(nfc_gpio->irq)) {
if (timeout) {
ret = wait_event_interruptible_timeout(nfc_dev->read_wq,
!i2c_dev->irq_enabled, msecs_to_jiffies(timeout));
ret = wait_event_interruptible_timeout(
nfc_dev->read_wq,
!i2c_dev->irq_enabled,
msecs_to_jiffies(timeout));
if (ret <= 0) {
pr_err("%s timeout/error in read\n", __func__);
pr_err("%s: timeout error\n",
__func__);
goto err;
}
} else {
ret = wait_event_interruptible(nfc_dev->read_wq,
ret = wait_event_interruptible(
nfc_dev->read_wq,
!i2c_dev->irq_enabled);
if (ret) {
pr_err("%s error wakeup of read wq\n", __func__);
pr_err("%s: err wakeup of wq\n",
__func__);
goto err;
}
}
@@ -170,10 +172,12 @@ int i2c_read(struct nfc_dev *nfc_dev, char *buf, size_t count, int timeout)
if (nfc_dev->cold_reset.rsp_pending) {
if (IS_PROP_CMD_RSP(buf)) {
/* Read data */
ret = i2c_master_recv(nfc_dev->i2c_dev.client, &buf[NCI_PAYLOAD_IDX],
buf[NCI_PAYLOAD_LEN_IDX]);
ret = i2c_master_recv(nfc_dev->i2c_dev.client,
&buf[NCI_PAYLOAD_IDX],
buf[NCI_PAYLOAD_LEN_IDX]);
if (ret <= 0) {
pr_err("%s: error reading cold reset/prot rsp header\n", __func__);
pr_err("%s: error reading cold rst/prot rsp\n",
__func__);
goto err;
}
wakeup_on_prop_rsp(nfc_dev, buf);
@@ -194,19 +198,38 @@ int i2c_write(struct nfc_dev *nfc_dev, const char *buf, size_t count,
{
int ret = -EINVAL;
int retry_cnt;
struct platform_gpio *nfc_gpio = &nfc_dev->configs.gpio;
if (count > MAX_DL_BUFFER_SIZE)
count = MAX_DL_BUFFER_SIZE;
pr_debug("%s : writing %zu bytes.\n", __func__, count);
pr_debug("%s: writing %zu bytes.\n", __func__, count);
/*
* Wait for any pending read for max 15ms before write
* This is to avoid any packet corruption during read, when
* the host cmds resets NFCC during any parallel read operation
*/
for (retry_cnt = 1; retry_cnt <= MAX_WRITE_IRQ_COUNT; retry_cnt++) {
if (gpio_get_value(nfc_gpio->irq)) {
pr_warn("%s: irq high during write, wait\n", __func__);
usleep_range(NFC_WRITE_IRQ_WAIT_TIME_US,
NFC_WRITE_IRQ_WAIT_TIME_US + 100);
} else {
break;
}
if (retry_cnt == MAX_WRITE_IRQ_COUNT &&
gpio_get_value(nfc_gpio->irq)) {
pr_warn("%s: allow after maximum wait\n", __func__);
}
}
for (retry_cnt = 1; retry_cnt <= max_retry_cnt; retry_cnt++) {
ret = i2c_master_send(nfc_dev->i2c_dev.client, buf, count);
if (ret <= 0) {
pr_warn("%s: failed to write ret(%d), Maybe in Standby Mode - Retry(%d)\n", __func__,
ret, retry_cnt);
usleep_range(WRITE_RETRY_WAIT_TIME_USEC,
WRITE_RETRY_WAIT_TIME_USEC + 100);
pr_warn("%s: write failed ret(%d), maybe in standby\n",
__func__, ret);
usleep_range(WRITE_RETRY_WAIT_TIME_US,
WRITE_RETRY_WAIT_TIME_US + 100);
} else if (ret != count) {
pr_err("%s: failed to write %d\n", __func__, ret);
ret = -EIO;
@@ -216,21 +239,21 @@ int i2c_write(struct nfc_dev *nfc_dev, const char *buf, size_t count,
return ret;
}
ssize_t nfc_i2c_dev_read(struct file *filp, char __user *buf,
size_t count, loff_t *offset)
ssize_t nfc_i2c_dev_read(struct file *filp, char __user *buf, size_t count,
loff_t *offset)
{
int ret = 0;
int ret;
struct nfc_dev *nfc_dev = (struct nfc_dev *)filp->private_data;
if (filp->f_flags & O_NONBLOCK) {
pr_err(":f_falg has O_NONBLOCK. EAGAIN\n");
pr_err("%s: f_flags has nonblock. try again\n", __func__);
return -EAGAIN;
}
mutex_lock(&nfc_dev->read_mutex);
ret = i2c_read(nfc_dev, nfc_dev->read_kbuf, count, 0);
if (ret > 0) {
if (copy_to_user(buf, nfc_dev->read_kbuf, ret)) {
pr_warn("%s : failed to copy to user space\n", __func__);
pr_warn("%s: failed to copy to user space\n", __func__);
ret = -EFAULT;
}
}
@@ -239,9 +262,9 @@ ssize_t nfc_i2c_dev_read(struct file *filp, char __user *buf,
}
ssize_t nfc_i2c_dev_write(struct file *filp, const char __user *buf,
size_t count, loff_t *offset)
size_t count, loff_t *offset)
{
int ret = 0;
int ret;
struct nfc_dev *nfc_dev = (struct nfc_dev *)filp->private_data;
if (count > MAX_DL_BUFFER_SIZE)
@@ -249,7 +272,7 @@ ssize_t nfc_i2c_dev_write(struct file *filp, const char __user *buf,
mutex_lock(&nfc_dev->write_mutex);
if (copy_from_user(nfc_dev->write_kbuf, buf, count)) {
pr_err("%s : failed to copy from user space\n", __func__);
pr_err("%s: failed to copy from user space\n", __func__);
mutex_unlock(&nfc_dev->write_mutex);
return -EFAULT;
}
@@ -277,15 +300,15 @@ int nfc_i2c_dev_probe(struct i2c_client *client, const struct i2c_device_id *id)
struct platform_gpio *nfc_gpio = &nfc_configs.gpio;
pr_debug("%s: enter\n", __func__);
/*retrieve details of gpios from dt */
/* retrieve details of gpios from dt */
ret = nfc_parse_dt(&client->dev, &nfc_configs, PLATFORM_IF_I2C);
if (ret) {
pr_err("%s : failed to parse dt\n", __func__);
pr_err("%s: failed to parse dt\n", __func__);
goto err;
}
if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
pr_err("%s : need I2C_FUNC_I2C\n", __func__);
pr_err("%s: need I2C_FUNC_I2C\n", __func__);
ret = -ENODEV;
goto err;
}
@@ -294,15 +317,15 @@ int nfc_i2c_dev_probe(struct i2c_client *client, const struct i2c_device_id *id)
ret = -ENOMEM;
goto err;
}
nfc_dev->read_kbuf = kzalloc(MAX_BUFFER_SIZE, GFP_DMA | GFP_KERNEL);
nfc_dev->read_kbuf = kzalloc(MAX_NCI_BUFFER_SIZE, GFP_DMA | GFP_KERNEL);
if (!nfc_dev->read_kbuf) {
ret = -ENOMEM;
goto err;
goto err_free_nfc_dev;
}
nfc_dev->write_kbuf = kzalloc(MAX_DL_BUFFER_SIZE, GFP_DMA | GFP_KERNEL);
if (!nfc_dev->write_kbuf) {
ret = -ENOMEM;
goto err;
goto err_free_read_kbuf;
}
nfc_dev->interface = PLATFORM_IF_I2C;
nfc_dev->nfc_state = NFC_STATE_NCI;
@@ -312,26 +335,28 @@ int nfc_i2c_dev_probe(struct i2c_client *client, const struct i2c_device_id *id)
nfc_dev->nfc_write = i2c_write;
nfc_dev->nfc_enable_intr = i2c_enable_irq;
nfc_dev->nfc_disable_intr = i2c_disable_irq;
nfc_dev->fw_major_version = 0;
ret = configure_gpio(nfc_gpio->ven, GPIO_OUTPUT);
if (ret) {
pr_err("%s: unable to request nfc reset gpio [%d]\n", __func__, nfc_gpio->ven);
goto err;
pr_err("%s: unable to request nfc reset gpio [%d]\n", __func__,
nfc_gpio->ven);
goto err_free_write_kbuf;
}
ret = configure_gpio(nfc_gpio->irq, GPIO_IRQ);
if (ret <= 0) {
pr_err("%s: unable to request nfc irq gpio [%d]\n", __func__, nfc_gpio->irq);
goto err;
pr_err("%s: unable to request nfc irq gpio [%d]\n", __func__,
nfc_gpio->irq);
goto err_free_gpio;
}
client->irq = ret;
ret = configure_gpio(nfc_gpio->dwl_req, GPIO_OUTPUT);
if (ret) {
pr_err("%s: unable to request nfc firm downl gpio [%d]\n", __func__,
nfc_gpio->dwl_req);
pr_err("%s: unable to request nfc firm downl gpio [%d]\n",
__func__, nfc_gpio->dwl_req);
}
/*copy the retrieved gpio details from DT */
memcpy(&nfc_dev->configs, &nfc_configs, sizeof(struct platform_configs));
/* copy the retrieved gpio details from DT */
memcpy(&nfc_dev->configs, &nfc_configs,
sizeof(struct platform_configs));
/* init mutex and queues */
init_waitqueue_head(&nfc_dev->read_wq);
@@ -347,28 +372,23 @@ int nfc_i2c_dev_probe(struct i2c_client *client, const struct i2c_device_id *id)
goto err_mutex_destroy;
}
/* interrupt initializations */
pr_info("%s : requesting IRQ %d\n", __func__, client->irq);
pr_info("%s: requesting IRQ %d\n", __func__, client->irq);
i2c_dev->irq_enabled = true;
ret = request_irq(client->irq, i2c_irq_handler,
IRQF_TRIGGER_HIGH, client->name, nfc_dev);
ret = request_irq(client->irq, i2c_irq_handler, IRQF_TRIGGER_HIGH,
client->name, nfc_dev);
if (ret) {
pr_err("%s: request_irq failed\n", __func__);
goto err_nfc_misc_unregister;
}
i2c_disable_irq(nfc_dev);
ret = nfcc_hw_check(nfc_dev);
if (ret != 0) {
pr_err("nfc hw check failed ret %d\n", ret);
goto err_nfc_misc_unregister;
}
gpio_set_ven(nfc_dev, 1);
gpio_set_ven(nfc_dev, 0);
gpio_set_ven(nfc_dev, 1);
device_init_wakeup(&client->dev, true);
device_set_wakeup_capable(&client->dev, true);
i2c_set_clientdata(client, nfc_dev);
i2c_dev->irq_wake_up = false;
pr_info("%s probing nfc i2c successfully", __func__);
pr_info("%s: probing nfc i2c successfully\n", __func__);
return 0;
err_nfc_misc_unregister:
nfc_misc_unregister(nfc_dev, DEV_COUNT);
@@ -376,11 +396,15 @@ err_mutex_destroy:
mutex_destroy(&nfc_dev->dev_ref_mutex);
mutex_destroy(&nfc_dev->read_mutex);
mutex_destroy(&nfc_dev->write_mutex);
err:
err_free_gpio:
gpio_free_all(nfc_dev);
kfree(nfc_dev->read_kbuf);
err_free_write_kbuf:
kfree(nfc_dev->write_kbuf);
err_free_read_kbuf:
kfree(nfc_dev->read_kbuf);
err_free_nfc_dev:
kfree(nfc_dev);
err:
pr_err("%s: probing not successful, check hardware\n", __func__);
return ret;
}
@@ -439,19 +463,18 @@ int nfc_i2c_dev_resume(struct device *device)
return 0;
}
static const struct i2c_device_id nfc_i2c_dev_id[] = {
{NFC_I2C_DEV_ID, 0},
{}
};
static const struct i2c_device_id nfc_i2c_dev_id[] = { { NFC_I2C_DEV_ID, 0 },
{} };
static const struct of_device_id nfc_i2c_dev_match_table[] = {
{.compatible = NFC_I2C_DRV_STR,},
{
.compatible = NFC_I2C_DRV_STR,
},
{}
};
static const struct dev_pm_ops nfc_i2c_dev_pm_ops = {
SET_SYSTEM_SLEEP_PM_OPS(nfc_i2c_dev_suspend, nfc_i2c_dev_resume)
};
static const struct dev_pm_ops nfc_i2c_dev_pm_ops = { SET_SYSTEM_SLEEP_PM_OPS(
nfc_i2c_dev_suspend, nfc_i2c_dev_resume) };
static struct i2c_driver nfc_i2c_dev_driver = {
.id_table = nfc_i2c_dev_id,
@@ -471,10 +494,10 @@ static int __init nfc_i2c_dev_init(void)
{
int ret = 0;
pr_info("Loading NXP NFC I2C driver\n");
pr_info("%s: Loading NXP NFC I2C driver\n", __func__);
ret = i2c_add_driver(&nfc_i2c_dev_driver);
if (ret != 0)
pr_err("NFC I2C add driver error ret %d\n", ret);
pr_err("%s: NFC I2C add driver error ret %d\n", __func__, ret);
return ret;
}
@@ -482,7 +505,7 @@ module_init(nfc_i2c_dev_init);
static void __exit nfc_i2c_dev_exit(void)
{
pr_info("Unloading NXP NFC I2C driver\n");
pr_info("%s: Unloading NXP NFC I2C driver\n", __func__);
i2c_del_driver(&nfc_i2c_dev_driver);
}