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

Commit c203ccdb authored by Bhuvan Varshney's avatar Bhuvan Varshney Committed by Gerrit - the friendly Code Review server
Browse files

NFC: Add support for SN100 eSE power management



Enable support for eSE power management from secure element
HAL service and make sure VEN is not HIGH after boot.

Change-Id: I0740681a62cc879eaf696358592b750332afe992
Signed-off-by: default avatarBhuvan Varshney <bvarshne@codeaurora.org>
parent e9465353
Loading
Loading
Loading
Loading
+63 −3
Original line number Diff line number Diff line
/* Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.
/* Copyright (c) 2015-2019, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
@@ -329,6 +329,52 @@ static int nqx_standby_write(struct nqx_dev *nqx_dev,
	return ret;
}

/*
 * Power management of the SN100 eSE
 * eSE and NFCC both are powered using VEN gpio in SN100,
 * VEN HIGH - eSE and NFCC both are powered on
 * VEN LOW - eSE and NFCC both are power down
 */
static int sn100_ese_pwr(struct nqx_dev *nqx_dev, unsigned long int arg)
{
	int r = -1;

	if (arg == 0) {
		/**
		 * Let's store the NFC VEN pin state
		 * will check stored value in case of eSE power off request,
		 * to find out if NFC MW also sent request to set VEN HIGH
		 * VEN state will remain HIGH if NFC is enabled otherwise
		 * it will be set as LOW
		 */
		nqx_dev->nfc_ven_enabled =
			gpio_get_value(nqx_dev->en_gpio);
		if (!nqx_dev->nfc_ven_enabled) {
			dev_dbg(&nqx_dev->client->dev, "eSE HAL service setting en_gpio HIGH\n");
			gpio_set_value(nqx_dev->en_gpio, 1);
			/* hardware dependent delay */
			usleep_range(1000, 1100);
		} else {
			dev_dbg(&nqx_dev->client->dev, "en_gpio already HIGH\n");
		}
		r = 0;
	} else if (arg == 1) {
		if (!nqx_dev->nfc_ven_enabled) {
			dev_dbg(&nqx_dev->client->dev, "NFC not enabled, disabling en_gpio\n");
			gpio_set_value(nqx_dev->en_gpio, 0);
			/* hardware dependent delay */
			usleep_range(1000, 1100);
		} else {
			dev_dbg(&nqx_dev->client->dev, "keep en_gpio high as NFC is enabled\n");
		}
		r = 0;
	} else if (arg == 3) {
		// eSE power state
		r = gpio_get_value(nqx_dev->en_gpio);
	}
	return r;
}

/*
 * Power management of the eSE
 * NFC & eSE ON : NFC_EN high and eSE_pwr_req high.
@@ -653,16 +699,28 @@ static long nfc_ioctl(struct file *pfile, unsigned int cmd,
			unsigned long arg)
{
	int r = 0;
	struct nqx_dev *nqx_dev = pfile->private_data;

	if (!nqx_dev)
		return -ENODEV;

	switch (cmd) {
	case NFC_SET_PWR:
		r = nfc_ioctl_power_states(pfile, arg);
		break;
	case ESE_SET_PWR:
		r = nqx_ese_pwr(pfile->private_data, arg);
		if ((nqx_dev->nqx_info.info.chip_type == NFCC_SN100_A) ||
			(nqx_dev->nqx_info.info.chip_type == NFCC_SN100_B))
			r = sn100_ese_pwr(nqx_dev, arg);
		else
			r = nqx_ese_pwr(nqx_dev, arg);
		break;
	case ESE_GET_PWR:
		r = nqx_ese_pwr(pfile->private_data, 3);
		if ((nqx_dev->nqx_info.info.chip_type == NFCC_SN100_A) ||
			(nqx_dev->nqx_info.info.chip_type == NFCC_SN100_B))
			r = sn100_ese_pwr(nqx_dev, 3);
		else
			r = nqx_ese_pwr(nqx_dev, 3);
		break;
	case SET_RX_BLOCK:
		break;
@@ -894,6 +952,8 @@ static int nfcc_hw_check(struct i2c_client *client, struct nqx_dev *nqx_dev)
		break;
	}

	/*Disable NFC by default to save power on boot*/
	gpio_set_value(enable_gpio, 0);/* ULPM: Disable */
	ret = 0;
	goto done;

+3 −1
Original line number Diff line number Diff line
/* Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.
/* Copyright (c) 2015-2019, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
@@ -48,6 +48,8 @@ enum nfcc_chip_variant {
	NFCC_NQ_220			= 0x58,	/**< NFCC NQ220 */
	NFCC_NQ_310			= 0x40,	/**< NFCC NQ310 */
	NFCC_NQ_330			= 0x51,	/**< NFCC NQ330 */
	NFCC_SN100_A			= 0xa3,	/**< NFCC SN100_A */
	NFCC_SN100_B			= 0xa4,	/**< NFCC SN100_B */
	NFCC_PN66T			= 0x18,	/**< NFCC PN66T */
	NFCC_NOT_SUPPORTED	        = 0xFF	/**< NFCC is not supported */
};