Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for timeout during read operations #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions i2c_devicetree.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ i2c0: i2c@ffd71000 {
nxp,nxpnfc-irq = <&gpio26 0 0>;
nxp,nxpnfc-ven = <&gpio26 2 0>;
nxp,nxpnfc-fw-dwnld = <&gpio26 4 0>;
nxp,nxpnfc-read-timeout = <1000>;
};
};
9 changes: 7 additions & 2 deletions nfc/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ int nfc_parse_dt(struct device *dev, struct platform_configs *nfc_configs,
{
struct device_node *np = dev->of_node;
struct platform_gpio *nfc_gpio = &nfc_configs->gpio;
u32 timeout;

if (!np) {
pr_err("%s: nfc of_node NULL\n", __func__);
Expand All @@ -37,6 +38,7 @@ int nfc_parse_dt(struct device *dev, struct platform_configs *nfc_configs,
nfc_gpio->irq = -EINVAL;
nfc_gpio->dwl_req = -EINVAL;
nfc_gpio->ven = -EINVAL;
nfc_configs->timeout = 0;

/* irq required for i2c based chips only */
if (interface == PLATFORM_IF_I2C || interface == PLATFORM_IF_SPI) {
Expand All @@ -58,9 +60,12 @@ int nfc_parse_dt(struct device *dev, struct platform_configs *nfc_configs,
if ((!gpio_is_valid(nfc_gpio->dwl_req)))
pr_warn("%s: dwl_req gpio invalid %d\n", __func__,
nfc_gpio->dwl_req);
/* timeout during read operations */
if( 0 == of_property_read_u32(np, DTS_TIMEOUT_STR, &timeout) )
nfc_configs->timeout = (int)timeout;

pr_info("%s: %d, %d, %d\n", __func__, nfc_gpio->irq, nfc_gpio->ven,
nfc_gpio->dwl_req);
pr_info("%s: %d, %d, %d, %d\n", __func__, nfc_gpio->irq, nfc_gpio->ven,
nfc_gpio->dwl_req, nfc_configs->timeout);
return 0;
}

Expand Down
2 changes: 2 additions & 0 deletions nfc/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
#define DTS_IRQ_GPIO_STR "nxp,nxpnfc-irq"
#define DTS_VEN_GPIO_STR "nxp,nxpnfc-ven"
#define DTS_FWDN_GPIO_STR "nxp,nxpnfc-fw-dwnld"
#define DTS_TIMEOUT_STR "nxp,nxpnfc-read-timeout"

enum nfcc_ioctl_request {
/* NFC disable request with VEN LOW */
Expand Down Expand Up @@ -152,6 +153,7 @@ struct platform_gpio {
/* NFC Struct to get all the required configs from DTS */
struct platform_configs {
struct platform_gpio gpio;
int timeout;
};

/* Device specific structure */
Expand Down
6 changes: 3 additions & 3 deletions nfc/i2c_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ int i2c_read(struct nfc_dev *nfc_dev, char *buf, size_t count, int timeout)
msecs_to_jiffies(timeout));

if (ret <= 0) {
pr_err("%s: timeout error\n",
__func__);
// pr_err("%s: timeout error\n",
// __func__);
goto err;
}
} else {
Expand Down Expand Up @@ -226,7 +226,7 @@ ssize_t nfc_i2c_dev_read(struct file *filp, char __user *buf, size_t count,
return -EAGAIN;
}
mutex_lock(&nfc_dev->read_mutex);
ret = i2c_read(nfc_dev, nfc_dev->read_kbuf, count, 0);
ret = i2c_read(nfc_dev, nfc_dev->read_kbuf, count, nfc_dev->configs.timeout);
if (ret > 0) {
if (copy_to_user(buf, nfc_dev->read_kbuf, ret)) {
pr_warn("%s: failed to copy to user space\n", __func__);
Expand Down
7 changes: 3 additions & 4 deletions nfc/spi_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ static irqreturn_t spi_irq_handler(int irq, void *dev_id)
int nfc_spi_read(struct nfc_dev *nfc_dev, char *buf, size_t count, int timeout)
{
int ret;
int cmd_length = 0;
struct spi_dev *spi_dev = &nfc_dev->spi_dev;
struct platform_gpio *nfc_gpio = &nfc_dev->configs.gpio;

Expand All @@ -171,8 +170,8 @@ int nfc_spi_read(struct nfc_dev *nfc_dev, char *buf, size_t count, int timeout)
msecs_to_jiffies(timeout));

if (ret <= 0) {
pr_err("%s: timeout error\n",
__func__);
// pr_err("%s: timeout error\n",
// __func__);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was the timeout error message commented out?
There should be feedback to the user when a read timeout occurs.

goto err;
}
} else {
Expand Down Expand Up @@ -293,7 +292,7 @@ ssize_t nfc_spi_dev_read(struct file *filp, char __user *buf, size_t count,
return -EAGAIN;
}
mutex_lock(&nfc_dev->read_mutex);
ret = nfc_spi_read(nfc_dev, nfc_dev->read_kbuf, count, 0);
ret = nfc_spi_read(nfc_dev, nfc_dev->read_kbuf, count, nfc_dev->configs.timeout);
if (ret > 0) {
if (copy_to_user(buf, nfc_dev->read_kbuf, ret)) {
pr_warn("%s: failed to copy to user space\n", __func__);
Expand Down
1 change: 1 addition & 0 deletions spi_devicetree.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ spi2: spi@ffd68000 {
nxp,nxpnfc-irq = <&gpio26 0 0>;
nxp,nxpnfc-ven = <&gpio26 2 0>;
nxp,nxpnfc-fw-dwnld = <&gpio26 4 0>;
nxp,nxpnfc-read-timeout = <1000>;
spi-max-frequency = <7000000>;
};
};