Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e9593670 authored by Nakul Kadannavar's avatar Nakul Kadannavar
Browse files

NFC: Read NFCC is fused or unfused



Implement kernel ioctl to read if NFCC is fused or not.

CRs-Fixed: 692604
Change-Id: I588c3bcf0fc52e8b857fdeaa1f9f2a343efec744
Signed-off-by: default avatarNakul Kadannavar <nakulk@codeaurora.org>
parent e03ec8b2
Loading
Loading
Loading
Loading
+65 −1
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ MODULE_DEVICE_TABLE(of, msm_match_table);
#define CORE_RST_NTF_LENGTH		(0x02)
#define WAKE_TIMEOUT			(10)
#define WAKE_REG			(0x10)

#define EFUSE_REG			(0xA0)

struct qca199x_dev {
	wait_queue_head_t read_wq;
@@ -707,6 +707,61 @@ int nfc_ioctl_nfcc_mode(struct file *filp, unsigned int cmd, unsigned long arg)
	return retval;
}

/*
 * Inside nfc_ioctl_nfcc_efuse
 *
 * @brief   nfc_ioctl_nfcc_efuse
 *
 *
 */
int nfc_ioctl_nfcc_efuse(struct file *filp, unsigned int cmd,
				unsigned long arg)
{
	int r = 0;
	unsigned short slave_addr = 0xE;
	unsigned short curr_addr;
	unsigned char efuse_addr  = EFUSE_REG;
	unsigned char efuse_value = 0xFF;

	struct qca199x_dev *qca199x_dev = filp->private_data;

	curr_addr = qca199x_dev->client->addr;
	qca199x_dev->client->addr = slave_addr;

	r = nfc_i2c_write(qca199x_dev->client,
				&efuse_addr, 1);
	if (r < 0) {
		/* Restore original NFCC slave I2C address */
		qca199x_dev->client->addr = curr_addr;
		dev_err(&qca199x_dev->client->dev,
		"ERROR_WRITE_FAIL : i2c write fail\n");
		return -EIO;
	}

	/*
	 * NFCC chip needs to be at least
	 * 10usec high before make it low
	 */
	usleep_range(10, 15);

	r = i2c_master_recv(qca199x_dev->client, &efuse_value,
					sizeof(efuse_value));
	if (r < 0) {
		/* Restore original NFCC slave I2C address */
		qca199x_dev->client->addr = curr_addr;
		dev_err(&qca199x_dev->client->dev,
		"ERROR_I2C_RCV_FAIL : i2c recv fail\n");
		return -EIO;
	}

	dev_dbg(&qca199x_dev->client->dev, "%s : EFUSE_VALUE %02x\n",
	__func__, efuse_value);

	/* Restore original NFCC slave I2C address */
	qca199x_dev->client->addr = curr_addr;
	return efuse_value;
}

/*
 * Inside nfc_ioctl_nfcc_version
 *
@@ -891,6 +946,7 @@ 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:
		nfc_ioctl_power_states(pfile, cmd, arg);
@@ -908,6 +964,14 @@ static long nfc_ioctl(struct file *pfile, unsigned int cmd,
		break;
	case SET_EMULATOR_TEST_POINT:
		break;
	case NFC_GET_EFUSE:
		r = nfc_ioctl_nfcc_efuse(pfile, cmd, arg);
		if (r < 0) {
			r = 0xFF;
			dev_err(&qca199x_dev->client->dev,
			"nfc_ioctl : FAILED TO READ EFUSE TYPE\n");
		}
		break;
	default:
		r = -ENOIOCTLCMD;
	}
+1 −0
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ struct devicemode {
#define SET_RX_BLOCK	_IOW(0xE9, 0x04, unsigned int)
#define SET_EMULATOR_TEST_POINT		_IOW(0xE9, 0x05, unsigned int)
#define NFCC_VERSION				_IOW(0xE9, 0x08, unsigned int)
#define NFC_GET_EFUSE				_IOW(0xE9, 0x09, unsigned int)

#define NFC_MAX_I2C_TRANSFER	(0x0400)
#define NFC_MSG_MAX_SIZE	(0x21)