Merge "NFC: Add error handling to i2c access"
diff --git a/drivers/nfc/nfc-nci.c b/drivers/nfc/nfc-nci.c
index e51da7f..b1681f1 100644
--- a/drivers/nfc/nfc-nci.c
+++ b/drivers/nfc/nfc-nci.c
@@ -61,7 +61,7 @@
#define CORE_RESET_RSP_GID (0x60)
#define CORE_RESET_OID (0x00)
#define CORE_RST_NTF_LENGTH (0x02)
-#define WAKE_TIMEOUT (10)
+#define WAKE_TIMEOUT (1000)
#define WAKE_REG (0x10)
#define EFUSE_REG (0xA0)
#define WAKEUP_SRC_TIMEOUT (2000)
@@ -101,6 +101,8 @@
struct workqueue_struct *my_wq;
};
+static int nfcc_reboot(struct notifier_block *notifier, unsigned long val,
+ void *v);
static int nfc_i2c_write(struct i2c_client *client, u8 *buf, int len);
static int nfcc_hw_check(struct i2c_client *client, unsigned short curr_addr);
static int nfcc_initialise(struct i2c_client *client, unsigned short curr_addr,
@@ -124,7 +126,7 @@
unsigned int disable_ctrl;
-bool region2_sent;
+bool region2_sent;
static void qca199x_init_stat(struct qca199x_dev *qca199x_dev)
{
@@ -163,15 +165,16 @@
if (device_may_wakeup(&qca199x_dev->client->dev) &&
(qca199x_dev->client->dev.power.is_suspended == true)) {
dev_dbg(&qca199x_dev->client->dev,
- "NFC:Processor in suspend state device_may_wakeup\n");
+ "%s: NFC:Processor in suspend state device_may_wakeup\n",
+ __func__);
/*
- * Keep system awake long enough to allow userspace
- * to process the packet.
- */
+ * Keep system awake long enough to allow userspace
+ * to process the packet.
+ */
pm_wakeup_event(&qca199x_dev->client->dev, WAKEUP_SRC_TIMEOUT);
} else {
dev_dbg(&qca199x_dev->client->dev,
- "NFC:Processor not in suspend state\n");
+ "%s: NFC:Processor not in suspend state\n", __func__);
}
spin_lock_irqsave(&qca199x_dev->irq_enabled_lock, flags);
@@ -329,7 +332,12 @@
/* READ */
if ((ftm_raw_write_mode == 0) && (ftm_werr_code == 0)) {
ftm_rerr_code = i2c_master_recv(qca199x_dev->client,
- &rd_byte, 1);
+ &rd_byte, sizeof(rd_byte));
+
+ if (ftm_rerr_code != sizeof(rd_byte)) {
+ total = -EMSGSIZE;
+ goto err;
+ }
if (ftm_rerr_code == 0x1)
ftm_rerr_code = 0;
tmp[0] = (unsigned char)ftm_rerr_code;
@@ -388,8 +396,8 @@
if (total > 0) {
if ((total > count) || copy_to_user(buf, tmp, total)) {
dev_err(&qca199x_dev->client->dev,
- "failed to copy to user space, total = %d\n",
- total);
+ "%s: failed to copy to user space, total = %d\n",
+ __func__, total);
total = -EFAULT;
}
}
@@ -438,6 +446,9 @@
ret = i2c_master_recv(qca199x_dev->client, tmp, (length +
PAYLOAD_HEADER_LENGTH));
total = ret;
+ if (ret != (length + PAYLOAD_HEADER_LENGTH))
+ goto leave;
+
}
dev_dbg(&qca199x_dev->client->dev, "%s : NfcNciRx %x %x %x\n",
__func__, tmp[0], tmp[1], tmp[2]);
@@ -456,12 +467,13 @@
int nfcc_buffer = 0;
if (count > MAX_BUFFER_SIZE) {
- dev_err(&qca199x_dev->client->dev, "out of memory\n");
+ dev_err(&qca199x_dev->client->dev, "%s: out of memory\n",
+ __func__);
return -ENOMEM;
}
if (copy_from_user(tmp, buf, count)) {
dev_err(&qca199x_dev->client->dev,
- "nfc-nci write: failed to copy from user space\n");
+ "%s: failed to copy from user space\n", __func__);
return -EFAULT;
}
/*
@@ -477,7 +489,8 @@
/* There has been an error while reading from nfcc */
if (nfcc_buffer < 0) {
dev_err(&qca199x_dev->client->dev,
- "nfc-nci write: error while servicing nfcc read buffer\n");
+ "%s: error while servicing nfcc read buffer\n"
+ , __func__);
}
qca199x_dev->sent_first_nci_write = true;
qca199x_enable_irq(qca199x_dev);
@@ -492,7 +505,7 @@
if (count == 1) {
ftm_raw_write_mode = 0;
ret = i2c_master_send(qca199x_dev->client, tmp, count);
- if (ret == 1)
+ if (ret == count)
ftm_werr_code = 0;
else
ftm_werr_code = ret;
@@ -502,7 +515,7 @@
if (count == 2) {
ftm_raw_write_mode = 1;
ret = i2c_master_send(qca199x_dev->client, tmp, count);
- if (ret == 2)
+ if (ret == count)
ftm_werr_code = 0;
else
ftm_werr_code = ret;
@@ -515,7 +528,7 @@
}
if (ret != count) {
dev_err(&qca199x_dev->client->dev,
- "NFC: failed to write %d\n", ret);
+ "%s: failed to write %d\n", __func__, ret);
ret = -EIO;
}
mutex_unlock(&qca199x_dev->read_mutex);
@@ -549,7 +562,7 @@
qca199x_enable_irq_clk_req(qca199x_dev);
}
dev_dbg(&qca199x_dev->client->dev,
- "%d,%d\n", imajor(inode), iminor(inode));
+ "%s: %d,%d\n", __func__, imajor(inode), iminor(inode));
return ret;
}
@@ -561,17 +574,21 @@
int r = 0;
int time_taken = 0;
unsigned char raw_nci_sleep[] = {0x2F, 0x03, 0x00};
- /* Change slave address to 0xE */
unsigned char raw_nci_wake[] = {0x10, 0x0F};
- unsigned short slave_addr = 0xE;
+ /* Change slave address to 0xE */
+ unsigned short slave_addr = 0xE;
unsigned short curr_addr;
- unsigned char wake_status = WAKE_REG;
+ unsigned char wake_status = WAKE_REG;
struct qca199x_dev *qca199x_dev = filp->private_data;
- dev_dbg(&qca199x_dev->client->dev, "nfcc_wake: %s: info: %p\n",
+ dev_dbg(&qca199x_dev->client->dev, "%s: info: %p\n",
__func__, qca199x_dev);
+ curr_addr = qca199x_dev->client->addr;
if (level == NFCC_SLEEP) {
+ /*
+ * Normal NCI write
+ */
r = i2c_master_send(qca199x_dev->client, &raw_nci_sleep[0],
sizeof(raw_nci_sleep));
@@ -579,57 +596,79 @@
return -EMSGSIZE;
qca199x_dev->state = NFCC_STATE_NORMAL_SLEEP;
} else {
- curr_addr = qca199x_dev->client->addr;
qca199x_dev->client->addr = slave_addr;
r = nfc_i2c_write(qca199x_dev->client, &raw_nci_wake[0],
sizeof(raw_nci_wake));
+ if (r != sizeof(raw_nci_wake)) {
+ r = -EMSGSIZE;
+ dev_err(&qca199x_dev->client->dev,
+ "%s: nci wake write failed. Check hardware\n",
+ __func__);
+ goto leave;
+ }
do {
wake_status = WAKE_REG;
- r = nfc_i2c_write(qca199x_dev->client, &wake_status, 1);
+ r = nfc_i2c_write(qca199x_dev->client, &wake_status,
+ sizeof(wake_status));
+ if (r != sizeof(wake_status)) {
+ r = -EMSGSIZE;
+ dev_err(&qca199x_dev->client->dev,
+ "%s: wake status write fail.Check hardware\n",
+ __func__);
+ goto leave;
+ }
/*
- * NFCC chip needs to be at least
- * 10usec high before make it low
+ * I2C line is low after ~10 usec
*/
usleep_range(10, 15);
r = i2c_master_recv(qca199x_dev->client, &wake_status,
sizeof(wake_status));
+ if (r != sizeof(wake_status)) {
+ r = -EMSGSIZE;
+ dev_err(&qca199x_dev->client->dev,
+ "%s: wake status read fail.Check hardware\n",
+ __func__);
+ goto leave;
+ }
time_taken++;
+ /*
+ * Each NFCC wakeup cycle
+ * takes about 0.5 ms
+ */
if ((wake_status & NCI_WAKE) != 0)
/* NFCC wakeup time is between 0.5 and .52 ms */
- usleep_range(500, 520);
+ usleep_range(500, 550);
} while ((wake_status & NCI_WAKE)
&& (time_taken < WAKE_TIMEOUT));
- /* Restore original NFCC slave I2C address */
-
- qca199x_dev->client->addr = curr_addr;
- if (r != sizeof(wake_status))
- return -EMSGSIZE;
-
if (time_taken >= WAKE_TIMEOUT) {
dev_err(&qca199x_dev->client->dev,
- " %s : TIMED OUT to get WAKEUP bit\n", __func__);
+ "%s: timed out to get wakeup bit\n", __func__);
r = -EIO;
+ goto leave;
}
+ r = 0;
qca199x_dev->state = NFCC_STATE_NORMAL_WAKE;
}
-
+leave:
+ /* Restore original NFCC slave I2C address */
+ qca199x_dev->client->addr = curr_addr;
return r;
}
/*
* Inside nfc_ioctl_power_states
*
- * @brief ioctl functions
+ * @brief ioctl functions
*
*
* Device control
* remove control via ioctl
- * (arg = 0): NFC_DISABLE GPIO = 0
- * (arg = 1): NFC_DISABLE GPIO = 1
- * NOT USED (arg = 2): FW_DL GPIO = 0
- * NOT USED (arg = 3): FW_DL GPIO = 1
+ * (arg = 0): NFC_DISABLE GPIO = 0
+ * (arg = 1): NFC_DISABLE GPIO = 1
+ * NOT USED (arg = 2): FW_DL GPIO = 0
+ * NOT USED (arg = 3): FW_DL GPIO = 1
* (arg = 4): NFCC_WAKE = 1
* (arg = 5): NFCC_WAKE = 0
*
@@ -648,7 +687,7 @@
dev_dbg(&qca199x_dev->client->dev, "gpio_set_value disable: %s: info: %p\n",
__func__, qca199x_dev);
gpio_set_value(qca199x_dev->dis_gpio, 0);
- usleep(1000);
+ usleep_range(1000, 1100);
} else if (arg == 1) {
/*
* We are attempting a hardware reset so let us disable
@@ -670,7 +709,7 @@
dev_dbg(&qca199x_dev->client->dev, "gpio_set_value enable: %s: info: %p\n",
__func__, qca199x_dev);
gpio_set_value(qca199x_dev->dis_gpio, 1);
- /*nfcc needs atleast 100ms for the chip to power cycle*/
+ /* NFCC needs at least 100 ms to power cycle*/
msleep(100);
} else if (arg == 2) {
mutex_lock(&qca199x_dev->read_mutex);
@@ -708,14 +747,14 @@
/*
* Inside nfc_ioctl_nfcc_mode
*
- * @brief nfc_ioctl_nfcc_mode
+ * @brief nfc_ioctl_nfcc_mode
*
* (arg = 0) ; NORMAL_MODE - Standard mode, unsolicited read behaviour
* (arg = 1) ; SOLICITED_MODE - As above but reads are solicited from User Land
* (arg = 2) ; UNSOLICITED_FTM_RAW MODE - NORMAL_MODE but messages from FTM and
- * not NCI Host.
+ * not NCI Host.
* (arg = 2) ; SOLICITED_FTM_RAW_MODE - As SOLICITED_MODE but messages from FTM
- * and not NCI Host.
+ * and not NCI Host.
*
*
*
@@ -766,6 +805,7 @@
*
* @brief nfc_ioctl_nfcc_efuse
*
+ *
*/
int nfc_ioctl_nfcc_efuse(struct file *filp, unsigned int cmd,
unsigned long arg)
@@ -826,11 +866,8 @@
unsigned long arg)
{
int r = 0;
- int time_taken = 0;
- unsigned short slave_addr = 0xE;
+ unsigned short slave_addr = 0xE;
unsigned short curr_addr;
- unsigned char raw_nci_wake[] = {0x10, 0x0F};
- unsigned char raw_nci_read;
unsigned char raw_chip_version_addr = 0x00;
unsigned char raw_chip_rev_id_addr = 0x9C;
unsigned char raw_chip_version = 0xFF;
@@ -844,88 +881,56 @@
* Always wake up chip when reading 0x9C, otherwise this
* register is not updated
*/
+ r = nfcc_wake(NFCC_WAKE, filp);
curr_addr = qca199x_dev->client->addr;
qca199x_dev->client->addr = slave_addr;
- r = nfc_i2c_write(qca199x_dev->client, &raw_nci_wake[0],
- sizeof(raw_nci_wake));
- if (r != sizeof(raw_nci_wake))
+
+ if (r) {
dev_err(&qca199x_dev->client->dev,
- "nfc_ioctl_nfcc_version : failed to send wake command\n");
-
- /*
- * After placing the NFCC to sleep by a PROP
- * SLEEP NCI msg (2F 03) and we need to wake
- * it back up to obtain some information (by
- * setting the wake bit).We need to determine
- * when it has in actual fact woken before we
- * can read the required data. We do that by
- * reading back & testing if that wake bit has
- * been cleared.
- */
- do {
- raw_nci_read = 0x10;
- r = nfc_i2c_write(qca199x_dev->client, &raw_nci_read, 1);
- /*
- * NFCC chip needs to be at least
- * 10usec high before make it low
- */
- usleep_range(10, 15);
-
- r = i2c_master_recv(qca199x_dev->client, &raw_nci_read,
- sizeof(raw_nci_read));
-
- if ((raw_nci_read & NCI_WAKE) != 0)
- /* NFCC wakeup time is between 0.5 and .52 ms */
- usleep_range(500, 520);
-
- time_taken++;
-
- } while ((raw_nci_read & NCI_WAKE)
- && (time_taken < WAKE_TIMEOUT));
-
- if (time_taken < WAKE_TIMEOUT)
- qca199x_dev->state = NFCC_STATE_NORMAL_WAKE;
- else
- dev_err(&qca199x_dev->client->dev,
- "nfc_ioctl_nfcc_version : TIMED OUT to get WAKEUP bit\n");
-
-
- if (r != 1) {
- /*
- * r < 0 indicates an error, maybe chip isn't
- * up yet.What should we do??? r = 0 indicates
- * nothing read, maybe chip isn't up yet. (should
- * not happen) r > 1 indicates too many bytes read,
- * maybe ?(should not happen)
- */
- dev_err(&qca199x_dev->client->dev,
- "nfc_ioctl_nfcc_version : i2c error %d\n", r);
+ "%s: nfcc wake failed: %d\n", __func__, r);
+ r = -EIO;
+ goto leave;
}
if (arg == 0) {
r = nfc_i2c_write(qca199x_dev->client,
- &raw_chip_version_addr, 1);
+ &raw_chip_version_addr, sizeof(raw_chip_version_addr));
+ if (r != sizeof(raw_chip_version_addr)) {
+ r = -EMSGSIZE;
+ goto err;
+ }
} else if (arg == 1) {
r = nfc_i2c_write(qca199x_dev->client,
- &raw_chip_rev_id_addr, 1);
+ &raw_chip_rev_id_addr, sizeof(raw_chip_rev_id_addr));
+ if (r != sizeof(raw_chip_version_addr)) {
+ r = -EMSGSIZE;
+ goto err;
+ }
} else {
- /* Restore original NFCC slave I2C address */
- qca199x_dev->client->addr = curr_addr;
- return -EINVAL;
+ r = -EINVAL;
+ goto err;
}
if (r < 0) {
- /* Restore original NFCC slave I2C address */
- qca199x_dev->client->addr = curr_addr;
- dev_err(&qca199x_dev->client->dev,
- "NFCC_INVALID_CHIP_VERSION : i2c write fail\n");
- return -EIO;
+ r = -EIO;
+ goto err;
}
-
- usleep(10);
- r = i2c_master_recv(qca199x_dev->client, &raw_chip_version, 1);
-
+ /*
+ * I2C line is low after ~10 usec
+ */
+ usleep_range(10, 15);
+ r = i2c_master_recv(qca199x_dev->client, &raw_chip_version,
+ sizeof(raw_chip_version));
+ if (r != sizeof(raw_chip_version)) {
+ r = -EMSGSIZE;
+ goto err;
+ }
+ goto leave;
+err:
+ dev_err(&qca199x_dev->client->dev,
+ "%s: i2c access failed\n", __func__);
+leave:
/* Restore original NFCC slave I2C address */
qca199x_dev->client->addr = curr_addr;
return raw_chip_version;
@@ -934,12 +939,12 @@
/*
* Inside nfc_ioctl_kernel_logging
*
- * @brief nfc_ioctl_kernel_logging
+ * @brief nfc_ioctl_kernel_logging
*
* (arg = 0) ; NO_LOGGING
* (arg = 1) ; COMMS_LOGGING - BASIC LOGGING - Mainly just comms over I2C
* (arg = 2) ; FULL_LOGGING - ENABLE ALL - DBG messages for handlers etc.
- * ; ! Be aware as amount of logging could impact behaviour !
+ * ; ! Be aware as amount of logging could impact behaviour !
*
*
*/
@@ -947,19 +952,19 @@
{
int retval = 0;
struct qca199x_dev *qca199x_dev = container_of(filp->private_data,
- struct qca199x_dev,
- qca199x_device);
+ struct qca199x_dev,
+ qca199x_device);
if (arg == 0) {
dev_dbg(&qca199x_dev->client->dev,
- "nfc_ioctl_kernel_logging : level = NO_LOGGING\n");
+ "%s : level = NO_LOGGING\n", __func__);
logging_level = 0;
} else if (arg == 1) {
dev_dbg(&qca199x_dev->client->dev,
- "nfc_ioctl_kernel_logging: level = COMMS_LOGGING only\n");
+ "%s: level = COMMS_LOGGING only\n", __func__);
logging_level = 1;
} else if (arg == 2) {
dev_dbg(&qca199x_dev->client->dev,
- "nfc_ioctl_kernel_logging: level = FULL_LOGGING\n");
+ "%s: level = FULL_LOGGING\n", __func__);
logging_level = 2;
}
return retval;
@@ -968,7 +973,7 @@
/*
* Inside nfc_ioctl_core_reset_ntf
*
- * @brief nfc_ioctl_core_reset_ntf
+ * @brief nfc_ioctl_core_reset_ntf
*
* Allows callers to determine if a CORE_RESET_NTF has arrived
*
@@ -980,22 +985,23 @@
{
struct qca199x_dev *qca199x_dev = filp->private_data;
dev_dbg(&qca199x_dev->client->dev,
- "nfc_ioctl_core_reset_ntf: returning = %d\n",
+ "%s: returning = %d\n",
+ __func__,
qca199x_dev->core_reset_ntf);
return qca199x_dev->core_reset_ntf;
}
-static long nfc_ioctl(struct file *pfile, unsigned int cmd, unsigned long arg)
+static long nfc_ioctl(struct file *pfile, unsigned int cmd,
+ unsigned long arg)
{
int r = 0;
struct qca199x_dev *qca199x_dev = pfile->private_data;
switch (cmd) {
-
case NFC_SET_PWR:
r = nfc_ioctl_power_states(pfile, cmd, arg);
break;
case NFCC_MODE:
- nfc_ioctl_nfcc_mode(pfile, cmd, arg);
+ r = nfc_ioctl_nfcc_mode(pfile, cmd, arg);
break;
case NFCC_VERSION:
r = nfc_ioctl_nfcc_version(pfile, cmd, arg);
@@ -1050,9 +1056,15 @@
((i > 0xF) && (i < 0x12)) || ((i > 0x39) && (i < 0x4d)) ||
((i > 0x69) && (i < 0x74)) || (i == 0x18) || (i == 0x30) ||
(i == 0x58)) {
- r = nfc_i2c_write(client, &raw_reg_rd, 1);
+ r = nfc_i2c_write(client, &raw_reg_rd,
+ sizeof(raw_reg_rd));
+ if (r != sizeof(raw_reg_rd))
+ break;
msleep(20);
- r = i2c_master_recv(client, &raw_reg_rd, 1);
+ r = i2c_master_recv(client, &raw_reg_rd,
+ sizeof(raw_reg_rd));
+ if (r != sizeof(raw_reg_rd))
+ break;
}
}
client->addr = temp_addr;
@@ -1063,11 +1075,11 @@
int r;
r = i2c_master_send(client, buf, len);
- dev_dbg(&client->dev, "send: %d\n", r);
+ dev_dbg(&client->dev, "%s: send: %d\n", __func__, r);
if (r == -EREMOTEIO) { /* Retry, chip was in standby */
usleep_range(6000, 10000);
r = i2c_master_send(client, buf, len);
- dev_dbg(&client->dev, "send2: %d\n", r);
+ dev_dbg(&client->dev, "%s: send attempt 2: %d\n", __func__, r);
}
if (r != len)
return -EREMOTEIO;
@@ -1083,22 +1095,23 @@
client->addr = curr_addr;
/* Set-up Addr 0. No data written */
- r = i2c_master_send(client, &buf, 1);
+ r = i2c_master_send(client, &buf, sizeof(buf));
if (r < 0)
goto err_presence_check;
buf = 0;
/* Read back from Addr 0 */
- r = i2c_master_recv(client, &buf, 1);
+ r = i2c_master_recv(client, &buf, sizeof(buf));
if (r < 0)
goto err_presence_check;
r = 0;
- return r;
+ goto leave;
err_presence_check:
r = -ENXIO;
dev_err(&client->dev,
- "nfc-nci nfcc_presence check - no NFCC available\n");
+ "%s: - no NFCC available\n", __func__);
+leave:
return r;
}
/* Initialise qca199x_ NFC controller hardware */
@@ -1106,7 +1119,7 @@
struct qca199x_dev *qca199x_dev)
{
int r = 0;
- unsigned char raw_1p8_CONTROL_011[] = {0x11, XTAL_CLOCK};
+ unsigned char raw_1P8_CONTROL_011[] = {0x11, XTAL_CLOCK};
unsigned char raw_1P8_CONTROL_010[] = {0x10, PWR_EN};
unsigned char raw_1P8_X0_0B0[] = {0xB0, (FREQ_SEL)};
unsigned char raw_slave1[] = {0x09, NCI_I2C_SLAVE};
@@ -1123,12 +1136,17 @@
client->addr = curr_addr;
qca199x_dev->core_reset_ntf = DEFAULT_INITIAL_CORE_RESET_NTF;
- r = i2c_master_send(client, &buf, 1);
+ r = i2c_master_send(client, &buf, sizeof(buf));
if (r < 0)
goto err_init;
+ /*
+ * I2C line is low after ~10 usec
+ */
+ usleep_range(10, 15);
+
buf = 0;
- r = i2c_master_recv(client, &buf, 1);
+ r = i2c_master_recv(client, &buf, sizeof(buf));
if (r < 0)
goto err_init;
@@ -1138,36 +1156,37 @@
if (r < 0)
goto err_init;
- usleep(1000);
- RAW(1p8_CONTROL_011, XTAL_CLOCK | 0x01);
+ usleep_range(1000, 1100);
- r = nfc_i2c_write(client, &raw_1p8_CONTROL_011[0],
- sizeof(raw_1p8_CONTROL_011));
+ RAW(1P8_CONTROL_011, XTAL_CLOCK | 0x01);
+
+ r = nfc_i2c_write(client, &raw_1P8_CONTROL_011[0],
+ sizeof(raw_1P8_CONTROL_011));
if (r < 0)
goto err_init;
- usleep(1000);
+ usleep_range(1000, 1100); /* 1 ms wait */
RAW(1P8_CONTROL_010, (0x8));
r = nfc_i2c_write(client, &raw_1P8_CONTROL_010[0],
sizeof(raw_1P8_CONTROL_010));
if (r < 0)
goto err_init;
- usleep(10000); /* 10ms wait */
+ usleep_range(10000, 11000); /* 10 ms wait */
RAW(1P8_CONTROL_010, (0xC));
r = nfc_i2c_write(client, &raw_1P8_CONTROL_010[0],
sizeof(raw_1P8_CONTROL_010));
if (r < 0)
goto err_init;
- usleep(100); /* 100uS wait */
+ usleep_range(100, 110); /* 100 us wait */
RAW(1P8_X0_0B0, (FREQ_SEL_19));
r = nfc_i2c_write(client, &raw_1P8_X0_0B0[0],
sizeof(raw_1P8_X0_0B0));
if (r < 0)
goto err_init;
- usleep(1000);
+ usleep_range(1000, 1100); /* 1 ms wait */
/* PWR_EN = 1 */
RAW(1P8_CONTROL_010, (0xd));
@@ -1177,7 +1196,7 @@
goto err_init;
- usleep(20000); /* 20ms wait */
+ msleep(20); /* 20ms wait */
/* LS_EN = 1 */
RAW(1P8_CONTROL_010, 0xF);
r = nfc_i2c_write(client, &raw_1P8_CONTROL_010[0],
@@ -1185,41 +1204,43 @@
if (r < 0)
goto err_init;
- usleep(20000); /* 20ms wait */
+ msleep(20); /* 20ms wait */
/* Enable the PMIC clock */
RAW(1P8_PAD_CFG_CLK_REQ, (0x1));
r = nfc_i2c_write(client, &raw_1P8_PAD_CFG_CLK_REQ[0],
- sizeof(raw_1P8_PAD_CFG_CLK_REQ));
+ sizeof(raw_1P8_PAD_CFG_CLK_REQ));
if (r < 0)
goto err_init;
- usleep(1000);
+ usleep_range(1000, 1100); /* 1 ms wait */
RAW(1P8_PAD_CFG_PWR_REQ, (0x1));
r = nfc_i2c_write(client, &raw_1P8_PAD_CFG_PWR_REQ[0],
- sizeof(raw_1P8_PAD_CFG_PWR_REQ));
+ sizeof(raw_1P8_PAD_CFG_PWR_REQ));
if (r < 0)
goto err_init;
- usleep(1000);
+ usleep_range(1000, 1100); /* 1 ms wait */
RAW(slave2, 0x10);
r = nfc_i2c_write(client, &raw_slave2[0], sizeof(raw_slave2));
if (r < 0)
goto err_init;
- usleep(1000);
+ usleep_range(1000, 1100); /* 1 ms wait */
RAW(slave1, NCI_I2C_SLAVE);
r = nfc_i2c_write(client, &raw_slave1[0], sizeof(raw_slave1));
if (r < 0)
goto err_init;
- usleep(1000);
+ usleep_range(1000, 1100); /* 1 ms wait */
/* QCA199x NFCC CPU should now boot... */
- r = i2c_master_recv(client, &raw_slave1_rd, 1);
+ r = i2c_master_recv(client, &raw_slave1_rd, sizeof(raw_slave1_rd));
+ if (r < 0)
+ goto err_init;
/* Talk on NCI slave address NCI_I2C_SLAVE 0x2C*/
client->addr = NCI_I2C_SLAVE;
@@ -1228,35 +1249,37 @@
* get a core reset notification - This is time for chip
* & NFCC controller to come-up.
*/
- usleep(15000); /* 15 ms */
+ usleep_range(15000, 16500); /* 15 ms */
do {
- ret = i2c_master_recv(client, rsp, 5);
+ ret = i2c_master_recv(client, rsp, sizeof(rsp));
+ if (ret < 0)
+ goto err_init;
/* Found core reset notification */
- if (((rsp[0] == CORE_RESET_RSP_GID) &&
+ if ((rsp[0] == CORE_RESET_RSP_GID) &&
(rsp[1] == CORE_RESET_OID) &&
- (rsp[2] == CORE_RST_NTF_LENGTH))
- || time_taken == NTF_TIMEOUT) {
+ (rsp[2] == CORE_RST_NTF_LENGTH)) {
dev_dbg(&client->dev,
- "NFC core reset recevd: %s: info: %p\n",
+ "NFC core reset recvd: %s: info: %p\n",
__func__, client);
core_reset_completed = true;
} else {
- usleep(2000); /* 2ms sleep before retry */
+ usleep_range(2000, 2200); /* 2 ms wait before retry */
}
time_taken++;
- } while (!core_reset_completed);
- if (time_taken == NTF_TIMEOUT)
+ } while (!core_reset_completed && (time_taken < NTF_TIMEOUT));
+ if (time_taken >= NTF_TIMEOUT) {
qca199x_dev->core_reset_ntf = TIMEDOUT_INITIAL_CORE_RESET_NTF;
- else
- qca199x_dev->core_reset_ntf = ARRIVED_INITIAL_CORE_RESET_NTF;
+ goto err_init;
+ }
+ qca199x_dev->core_reset_ntf = ARRIVED_INITIAL_CORE_RESET_NTF;
r = 0;
return r;
err_init:
r = 1;
dev_err(&client->dev,
- "nfc-nci nfcc_initialise: failed. Check Hardware\n");
+ "%s: failed. Check Hardware\n", __func__);
return r;
}
/*
@@ -1267,19 +1290,20 @@
int r = 0;
if (!strcmp(qca199x_dev->clk_src_name, "BBCLK2")) {
- qca199x_dev->s_clk =
+ qca199x_dev->s_clk =
clk_get(&qca199x_dev->client->dev, "ref_clk");
if (qca199x_dev->s_clk == NULL)
goto err_invalid_dis_gpio;
} else if (!strcmp(qca199x_dev->clk_src_name, "RFCLK3")) {
- qca199x_dev->s_clk =
+ qca199x_dev->s_clk =
clk_get(&qca199x_dev->client->dev, "ref_clk_rf");
if (qca199x_dev->s_clk == NULL)
goto err_invalid_dis_gpio;
} else if (!strcmp(qca199x_dev->clk_src_name, "GPCLK")) {
if (gpio_is_valid(qca199x_dev->clk_src_gpio)) {
- qca199x_dev->s_clk =
- clk_get(&qca199x_dev->client->dev, "core_clk");
+ qca199x_dev->s_clk =
+ clk_get(&qca199x_dev->client->dev,
+ "core_clk");
if (qca199x_dev->s_clk == NULL)
goto err_invalid_dis_gpio;
} else {
@@ -1287,8 +1311,9 @@
}
} else if (!strcmp(qca199x_dev->clk_src_name, "GPCLK2")) {
if (gpio_is_valid(qca199x_dev->clk_src_gpio)) {
- qca199x_dev->s_clk =
- clk_get(&qca199x_dev->client->dev, "core_clk_pvt");
+ qca199x_dev->s_clk =
+ clk_get(&qca199x_dev->client->dev,
+ "core_clk_pvt");
if (qca199x_dev->s_clk == NULL)
goto err_invalid_dis_gpio;
} else {
@@ -1364,7 +1389,7 @@
}
if ((!strcmp(pdata->clk_src_name, "GPCLK")) ||
- (!strcmp(pdata->clk_src_name, "GPCLK2"))) {
+ (!strcmp(pdata->clk_src_name, "GPCLK2"))) {
pdata->clk_src_gpio = of_get_named_gpio(np,
"qcom,clk-src-gpio", 0);
if ((!gpio_is_valid(pdata->clk_src_gpio)))
@@ -1393,7 +1418,7 @@
sizeof(struct qca199x_platform_data), GFP_KERNEL);
if (!platform_data) {
dev_err(&client->dev,
- "nfc-nci probe: Failed to allocate memory\n");
+ "%s: Failed to allocate memory\n", __func__);
return -ENOMEM;
}
r = nfc_parse_dt(&client->dev, platform_data);
@@ -1405,20 +1430,20 @@
if (!platform_data)
return -EINVAL;
dev_dbg(&client->dev,
- "nfc-nci probe: %s, inside nfc-nci flags = %x\n",
+ "%s, inside nfc-nci flags = %x\n",
__func__, client->flags);
if (platform_data == NULL) {
- dev_err(&client->dev, "nfc-nci probe: failed\n");
+ dev_err(&client->dev, "%s: failed\n", __func__);
return -ENODEV;
}
if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
- dev_err(&client->dev, "nfc-nci probe: need I2C_FUNC_I2C\n");
+ dev_err(&client->dev, "%s: need I2C_FUNC_I2C\n", __func__);
return -ENODEV;
}
qca199x_dev = kzalloc(sizeof(*qca199x_dev), GFP_KERNEL);
if (qca199x_dev == NULL) {
dev_err(&client->dev,
- "nfc-nci probe: failed to allocate memory for module data\n");
+ "%s: failed to allocate memory for module data\n", __func__);
return -ENOMEM;
}
qca199x_dev->client = client;
@@ -1436,27 +1461,29 @@
r = gpio_request(platform_data->dis_gpio, "nfc_reset_gpio");
if (r) {
dev_err(&client->dev,
- "NFC: unable to request gpio [%d]\n",
+ "%s: unable to request gpio [%d]\n",
+ __func__,
platform_data->dis_gpio);
goto err_free_dev;
}
r = gpio_direction_output(platform_data->dis_gpio, 1);
if (r) {
dev_err(&client->dev,
- "NFC: unable to set direction for gpio [%d]\n",
+ "%s: unable to set direction for gpio [%d]\n",
+ __func__,
platform_data->dis_gpio);
goto err_dis_gpio;
}
} else {
- dev_err(&client->dev, "dis gpio not provided\n");
+ dev_err(&client->dev, "%s: dis gpio not provided\n", __func__);
goto err_free_dev;
}
/* Guarantee that the NFCC starts in a clean state. */
gpio_set_value(platform_data->dis_gpio, 1);/* HPD */
- usleep(200);
+ usleep_range(200, 220);
gpio_set_value(platform_data->dis_gpio, 0);/* ULPM */
- usleep(200);
+ usleep_range(200, 220);
r = nfcc_hw_check(client, platform_data->reg);
if (r) {
@@ -1468,7 +1495,8 @@
if (gpio_is_valid(platform_data->irq_gpio)) {
r = gpio_request(platform_data->irq_gpio, "nfc_irq_gpio");
if (r) {
- dev_err(&client->dev, "unable to request gpio [%d]\n",
+ dev_err(&client->dev, "%s: unable to request gpio [%d]\n",
+ __func__,
platform_data->irq_gpio);
goto err_dis_gpio;
}
@@ -1476,7 +1504,8 @@
if (r) {
dev_err(&client->dev,
- "unable to set direction for gpio [%d]\n",
+ "%s: unable to set direction for gpio [%d]\n",
+ __func__,
platform_data->irq_gpio);
goto err_irq;
}
@@ -1488,7 +1517,7 @@
client->irq = irqn;
} else {
- dev_err(&client->dev, "irq gpio not provided\n");
+ dev_err(&client->dev, "%s: irq gpio not provided\n", __func__);
goto err_dis_gpio;
}
/* Interrupt from NFCC CLK_REQ to handle REF_CLK
@@ -1499,7 +1528,9 @@
r = gpio_request(platform_data->irq_gpio_clk_req,
"nfc_irq_gpio_clk_en");
if (r) {
- dev_err(&client->dev, "unable to request CLK_EN gpio [%d]\n",
+ dev_err(&client->dev,
+ "%s: unable to request CLK_EN gpio [%d]\n",
+ __func__,
platform_data->irq_gpio_clk_req);
goto err_irq;
}
@@ -1507,8 +1538,8 @@
platform_data->irq_gpio_clk_req);
if (r) {
dev_err(&client->dev,
- "unable to set direction for CLK_EN gpio [%d]\n",
- platform_data->irq_gpio_clk_req);
+ "%s: cannot set direction CLK_EN gpio [%d]\n",
+ __func__, platform_data->irq_gpio_clk_req);
goto err_irq_clk;
}
gpio_to_irq(0);
@@ -1519,7 +1550,8 @@
}
platform_data->clk_req_irq_num = irqn;
} else {
- dev_err(&client->dev, "irq CLK_EN gpio not provided\n");
+ dev_err(&client->dev,
+ "%s: irq CLK_EN gpio not provided\n", __func__);
goto err_irq;
}
}
@@ -1540,19 +1572,21 @@
r = gpio_request(platform_data->clkreq_gpio,
"nfc_clkreq_gpio");
if (r) {
- dev_err(&client->dev, "unable to request gpio [%d]\n",
- platform_data->clkreq_gpio);
+ dev_err(&client->dev,
+ "%s: unable to request gpio [%d]\n",
+ __func__, platform_data->clkreq_gpio);
goto err_clkreq_gpio;
}
r = gpio_direction_input(platform_data->clkreq_gpio);
if (r) {
dev_err(&client->dev,
- "unable to set direction for gpio [%d]\n",
- platform_data->clkreq_gpio);
+ "%s: cannot set direction for gpio [%d]\n",
+ __func__, platform_data->clkreq_gpio);
goto err_clkreq_gpio;
}
} else {
- dev_err(&client->dev, "clkreq gpio not provided\n");
+ dev_err(&client->dev,
+ "%s: clkreq gpio not provided\n", __func__);
goto err_clk;
}
qca199x_dev->clkreq_gpio = platform_data->clkreq_gpio;
@@ -1579,7 +1613,7 @@
r = misc_register(&qca199x_dev->qca199x_device);
if (r) {
- dev_err(&client->dev, "misc_register failed\n");
+ dev_err(&client->dev, "%s: misc_register failed\n", __func__);
goto err_misc_register;
}
@@ -1616,7 +1650,7 @@
r = request_irq(client->irq, qca199x_dev_irq_handler,
IRQF_TRIGGER_RISING, client->name, qca199x_dev);
if (r) {
- dev_err(&client->dev, "nfc-nci probe: request_irq failed\n");
+ dev_err(&client->dev, "%s: request_irq failed\n", __func__);
goto err_request_irq_failed;
}
qca199x_disable_irq(qca199x_dev);
@@ -1629,7 +1663,8 @@
client->name, qca199x_dev);
if (r) {
dev_err(&client->dev,
- "nfc-nci probe: request_irq failed. irq no = %d\n, main irq = %d",
+ "%s: request_irq failed. irq no = %d\n, main irq = %d",
+ __func__,
qca199x_dev->clk_req_irq_num, client->irq);
goto err_request_irq_failed;
}
@@ -1654,13 +1689,13 @@
region2_sent = false;
dev_dbg(&client->dev,
- "nfc-nci probe: %s, probing qca1990 exited successfully\n",
+ "%s: probing qca1990 exited successfully\n",
__func__);
return 0;
err_create_workq:
dev_err(&client->dev,
- "nfc-nci probe: %s, work_queue creation failure\n",
+ "%s: work_queue creation failure\n",
__func__);
free_irq(client->irq, qca199x_dev);
err_nfcc_not_present:
@@ -1678,7 +1713,8 @@
(!strcmp(platform_data->clk_src_name, "GPCLK2"))) {
r = gpio_direction_input(platform_data->irq_gpio_clk_req);
if (r)
- dev_err(&client->dev, "nfc-nci probe: Unable to set direction\n");
+ dev_err(&client->dev,
+ "%s: Unable to set direction\n", __func__);
gpio_free(platform_data->irq_gpio_clk_req);
}
err_irq:
@@ -1752,7 +1788,7 @@
static int nfcc_reboot(struct notifier_block *notifier, unsigned long val,
- void *v)
+ void *v)
{
/*
* Set DISABLE=1 *ONLY* if the NFC service has been disabled.