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

Commit 4dc8b708 authored by Anirudh Ghayal's avatar Anirudh Ghayal Committed by Gerrit - the friendly Code Review server
Browse files

input: qpnp-power-on: Add support for TWM config



TWM (traditional watch mode) is a low-power mode
configuration on the BG platform. Add a notification
callback to be notified of an entry into this mode.

Add logic to skip the PS_HOLD reset configuration and
initiate the PBS trigger if TWM mode is enabled.
The PBS trigger configures the PMIC for TWM entry.

Change-Id: I31a48c8d2506a668b18737ec3da827cff27b830d
Signed-off-by: default avatarSundara Vinayagam <sundvi@codeaurora.org>
parent fa0300c5
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -115,6 +115,10 @@ Optional properties:
- qcom,use-legacy-hard-reset-offset	Boolean property to support legacy
				hard-reset offset of the PON_RB_SPARE register for
				some (PON gen2) platforms.
- qcom,support-twm-config       Boolean property to allow the PON module to be
                                configured to support TWM modes.
- qcom,pbs-client               Phandle of the PBS client node. Should be
                                defined if 'qcom,support-twm-config' is present.

All the below properties are in the sub-node section (properties of the child
node).
+65 −0
Original line number Diff line number Diff line
@@ -31,6 +31,8 @@
#include <linux/regulator/machine.h>
#include <linux/regulator/of_regulator.h>
#include <linux/input/qpnp-power-on.h>
#include <linux/qpnp/qpnp-pbs.h>
#include <linux/qpnp/qpnp-misc.h>
#include <linux/power_supply.h>

#define PMIC_VER_8941           0x01
@@ -203,6 +205,7 @@ struct qpnp_pon {
	struct list_head	list;
	struct delayed_work	bark_work;
	struct dentry		*debugfs;
	struct device_node      *pbs_dev_node;
	int			pon_trigger_reason;
	int			pon_power_off_reason;
	int			num_pon_reg;
@@ -220,6 +223,7 @@ struct qpnp_pon {
	u8			pon_ver;
	u8			warm_reset_reason1;
	u8			warm_reset_reason2;
	u8                      twm_state;
	bool			is_spon;
	bool			store_hard_reset_reason;
	bool			resin_hard_reset_disable;
@@ -227,8 +231,10 @@ struct qpnp_pon {
	bool			ps_hold_hard_reset_disable;
	bool			ps_hold_shutdown_disable;
	bool			kpdpwr_dbc_enable;
	bool                    support_twm_config;
	bool			resin_pon_reset;
	ktime_t			kpdpwr_last_release_time;
	struct notifier_block   pon_nb;
	bool			legacy_hard_reset_offset;
};

@@ -483,6 +489,7 @@ static ssize_t qpnp_pon_dbc_store(struct device *dev,

static DEVICE_ATTR(debounce_us, 0664, qpnp_pon_dbc_show, qpnp_pon_dbc_store);

#define PON_TWM_ENTRY_PBS_BIT           BIT(0)
static int qpnp_pon_reset_config(struct qpnp_pon *pon,
		enum pon_power_off_type type)
{
@@ -490,6 +497,19 @@ static int qpnp_pon_reset_config(struct qpnp_pon *pon,
	bool disable = false;
	u16 rst_en_reg;

	/* Ignore the PS_HOLD reset config if TWM ENTRY is enabled */
	if (pon->support_twm_config && pon->twm_state == PMIC_TWM_ENABLE) {
		rc = qpnp_pbs_trigger_event(pon->pbs_dev_node,
					PON_TWM_ENTRY_PBS_BIT);
		if (rc < 0) {
			pr_err("Unable to trigger PBS trigger for TWM entry rc=%d\n",
							rc);
			return rc;
		}
		pr_crit("PMIC configured for TWM entry\n");
		return 0;
	}

	if (pon->pon_ver == QPNP_PON_GEN1_V1)
		rst_en_reg = QPNP_PON_PS_HOLD_RST_CTL(pon);
	else
@@ -2087,6 +2107,35 @@ static int read_gen2_pon_off_reason(struct qpnp_pon *pon, u16 *reason,
	return 0;
}

static int pon_twm_notifier_cb(struct notifier_block *nb,
				unsigned long action, void *data)
{
	struct qpnp_pon *pon = container_of(nb, struct qpnp_pon, pon_nb);

	if (action != PMIC_TWM_CLEAR &&
			action != PMIC_TWM_ENABLE) {
		pr_debug("Unsupported option %lu\n", action);
		return NOTIFY_OK;
	}

	pon->twm_state = (u8)action;
	pr_debug("TWM state = %d\n", pon->twm_state);

	return NOTIFY_OK;
}

static int pon_register_twm_notifier(struct qpnp_pon *pon)
{
	int rc;

	pon->pon_nb.notifier_call = pon_twm_notifier_cb;
	rc = qpnp_misc_twm_notifier_register(&pon->pon_nb);
	if (rc < 0)
		pr_err("Failed to register pon_twm_notifier_cb rc=%d\n", rc);

	return rc;
}

static int qpnp_pon_probe(struct platform_device *pdev)
{
	struct qpnp_pon *pon;
@@ -2364,6 +2413,22 @@ static int qpnp_pon_probe(struct platform_device *pdev)
		goto err_out;
	}

	if (of_property_read_bool(pon->pdev->dev.of_node,
					"qcom,support-twm-config")) {
		pon->support_twm_config = true;
		rc = pon_register_twm_notifier(pon);
		if (rc < 0) {
			pr_err("Failed to register TWM notifier rc=%d\n", rc);
			return rc;
		}
		pon->pbs_dev_node = of_parse_phandle(pon->pdev->dev.of_node,
						"qcom,pbs-client", 0);
		if (!pon->pbs_dev_node) {
			pr_err("Missing qcom,pbs-client property\n");
			return -EINVAL;
		}
	}

	rc = of_property_read_u32(pon->pdev->dev.of_node,
				"qcom,pon-dbc-delay", &delay);
	if (rc) {