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

Commit 7e75d514 authored by Ravindranath Thiyagarajan's avatar Ravindranath Thiyagarajan Committed by Subbaraman Narayanamurthy
Browse files

regulator: qpnp-labibb-regulator: support configuring LAB CURRENT_SENSE



As per the hardware documentation, current sense gain for LAB regulator
should be configured to 1.5 times for AMOLED mode. Add
support for that.

While at it, add support for configuring current sense gain through a
device tree property "qcom,qpnp-lab-current-sense". If the property is
specified, then allow overriding the current sense gain irrespective of
the panel type.

Change-Id: I7567eedb8331c70de715f2b392cbb6e560ec4622
Signed-off-by: default avatarRavindranath Thiyagarajan <rthiyaga@codeaurora.org>
parent 235afb47
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -48,6 +48,10 @@ Sub LAB node optional structure:
- qcom,qpnp-lab-pull-down-enable:	If this property is present, pull down is enabled for LAB regulator. Otherwise, pull down is disabled for LAB regulator.
- qcom,qpnp-lab-pull-down-enable:	If this property is present, pull down is enabled for LAB regulator. Otherwise, pull down is disabled for LAB regulator.
- qcom,qpnp-lab-limit-max-current-enable:	If this property is present, maximum inductor current constraint is put for LAB regulator. Otherwise, There is no maximum current constraint.
- qcom,qpnp-lab-limit-max-current-enable:	If this property is present, maximum inductor current constraint is put for LAB regulator. Otherwise, There is no maximum current constraint.
- qcom,qpnp-lab-use-default-voltage:		When bootloader does not turn on LAB regulator and this property is present, value specified in qcom,qpnp-lab-init-voltage is the default init voltage when the voltage output register is of value 0. Otherwise, we need to enable the output override bit in voltage output register.
- qcom,qpnp-lab-use-default-voltage:		When bootloader does not turn on LAB regulator and this property is present, value specified in qcom,qpnp-lab-init-voltage is the default init voltage when the voltage output register is of value 0. Otherwise, we need to enable the output override bit in voltage output register.
- qpnp,qpnp-lab-current-sense:	If this property is present, the LAB current sense gain will be programmed for LAB regulator.
				Otherwise, LAB current sense gain will be default to "1x". A string uses to specify the LAB current sense gain.
				Could be "0.5x" or "1x" or "1.5x" or "2x". For ex: "0.5x" means current sense gain is 0.5.



Sub IBB node required structure:
Sub IBB node required structure:
- reg:				Specifies the SPMI address and size for this peripheral
- reg:				Specifies the SPMI address and size for this peripheral
+78 −11
Original line number Original line Diff line number Diff line
@@ -46,6 +46,7 @@
#define REG_LAB_CLK_DIV			0x48
#define REG_LAB_CLK_DIV			0x48
#define REG_LAB_IBB_EN_RDY		0x49
#define REG_LAB_IBB_EN_RDY		0x49
#define REG_LAB_CURRENT_LIMIT		0x4B
#define REG_LAB_CURRENT_LIMIT		0x4B
#define REG_LAB_CURRENT_SENSE		0x4C
#define REG_LAB_PS_CTL			0x50
#define REG_LAB_PS_CTL			0x50
#define REG_LAB_RDSON_MNGMNT		0x53
#define REG_LAB_RDSON_MNGMNT		0x53
#define REG_LAB_PRECHARGE_CTL		0x5E
#define REG_LAB_PRECHARGE_CTL		0x5E
@@ -86,6 +87,11 @@
#define LAB_CURRENT_LIMIT_MASK		((1 << LAB_CURRENT_LIMIT_BITS) - 1)
#define LAB_CURRENT_LIMIT_MASK		((1 << LAB_CURRENT_LIMIT_BITS) - 1)
#define LAB_CURRENT_LIMIT_EN		BIT(7)
#define LAB_CURRENT_LIMIT_EN		BIT(7)


/* REG_LAB_CURRENT_SENSE */
#define LAB_CURRENT_SENSE_GAIN_BITS	2
#define LAB_CURRENT_SENSE_GAIN_MASK	((1 << LAB_CURRENT_SENSE_GAIN_BITS) \
					- 1)

/* REG_LAB_PS_CTL */
/* REG_LAB_PS_CTL */
#define LAB_PS_CTL_BITS			2
#define LAB_PS_CTL_BITS			2
#define LAB_PS_CTL_MASK			((1 << LAB_PS_CTL_BITS) - 1)
#define LAB_PS_CTL_MASK			((1 << LAB_PS_CTL_BITS) - 1)
@@ -167,10 +173,12 @@


/* REG_IBB_PWRUP_PWRDN_CTL_1 */
/* REG_IBB_PWRUP_PWRDN_CTL_1 */
#define IBB_PWRUP_PWRDN_CTL_1_DLY1_BITS	2
#define IBB_PWRUP_PWRDN_CTL_1_DLY1_BITS	2
#define IBB_PWRUP_PWRDN_CTL_1_DLY1_MASK	((1<<IBB_PWRUP_PWRDN_CTL_1_DLY1_BITS)-1)
#define IBB_PWRUP_PWRDN_CTL_1_DLY1_MASK	\
	((1 << IBB_PWRUP_PWRDN_CTL_1_DLY1_BITS) - 1)
#define IBB_PWRUP_PWRDN_CTL_1_DLY1_SHIFT	3
#define IBB_PWRUP_PWRDN_CTL_1_DLY1_SHIFT	3
#define IBB_PWRUP_PWRDN_CTL_1_DLY2_BITS	2
#define IBB_PWRUP_PWRDN_CTL_1_DLY2_BITS	2
#define IBB_PWRUP_PWRDN_CTL_1_DLY2_MASK	((1<<IBB_PWRUP_PWRDN_CTL_1_DLY2_BITS)-1)
#define IBB_PWRUP_PWRDN_CTL_1_DLY2_MASK	\
	((1 << IBB_PWRUP_PWRDN_CTL_1_DLY2_BITS) - 1)
#define IBB_PWRUP_PWRDN_CTL_1_LAB_VREG_OK	BIT(7)
#define IBB_PWRUP_PWRDN_CTL_1_LAB_VREG_OK	BIT(7)
#define IBB_PWRUP_PWRDN_CTL_1_EN_DLY1	BIT(6)
#define IBB_PWRUP_PWRDN_CTL_1_EN_DLY1	BIT(6)
#define PWRUP_PWRDN_CTL_1_DISCHARGE_EN	BIT(2)
#define PWRUP_PWRDN_CTL_1_DISCHARGE_EN	BIT(2)
@@ -259,6 +267,13 @@ static const int lab_current_limit_plan[] = {
	800,
	800,
};
};


static const char * const lab_current_sense_plan[] = {
	"0.5x",
	"1x",
	"1.5x",
	"2x"
};

static const int ibb_current_limit_plan[] = {
static const int ibb_current_limit_plan[] = {
	0,
	0,
	50,
	50,
@@ -480,6 +495,17 @@ static int qpnp_ibb_unlock_sec_access(struct qpnp_labibb *labibb)
	return rc;
	return rc;
}
}


static int qpnp_labibb_get_matching_idx(const char *val)
{
	int i;

	for (i = 0; i < ARRAY_SIZE(lab_current_sense_plan); i++)
		if (!strcmp(lab_current_sense_plan[i], val))
			return i;

	return -EINVAL;
}

static int qpnp_lab_dt_init(struct qpnp_labibb *labibb,
static int qpnp_lab_dt_init(struct qpnp_labibb *labibb,
				struct device_node *of_node)
				struct device_node *of_node)
{
{
@@ -1033,6 +1059,8 @@ static int register_qpnp_lab_regulator(struct qpnp_labibb *labibb,
	struct regulator_desc *rdesc;
	struct regulator_desc *rdesc;
	struct regulator_config cfg = {};
	struct regulator_config cfg = {};
	u8 ibb_en_rdy_val, val;
	u8 ibb_en_rdy_val, val;
	const char *current_sense_str;
	bool config_current_sense = false;


	if (!of_node) {
	if (!of_node) {
		dev_err(labibb->dev, "qpnp lab regulator device tree node is missing\n");
		dev_err(labibb->dev, "qpnp lab regulator device tree node is missing\n");
@@ -1151,6 +1179,45 @@ static int register_qpnp_lab_regulator(struct qpnp_labibb *labibb,


		}
		}


		if (labibb->mode == QPNP_LABIBB_AMOLED_MODE) {
			/*
			 * default to 1.5 times current gain if
			 * user doesn't specify the current-sense
			 * dt parameter
			 */
			current_sense_str = "1.5x";
			val = qpnp_labibb_get_matching_idx(current_sense_str);
			config_current_sense = true;
		}

		if (of_find_property(of_node,
			"qpnp,qpnp-lab-current-sense", NULL)) {
			config_current_sense = true;
			rc = of_property_read_string(of_node,
				"qpnp,qpnp-lab-current-sense",
				&current_sense_str);
			if (!rc) {
				val = qpnp_labibb_get_matching_idx(
						current_sense_str);
			} else {
				pr_err("qpnp,qpnp-lab-current-sense configured incorrectly rc = %d\n",
					rc);
				return rc;
			}
		}

		if (config_current_sense) {
			rc = qpnp_labibb_masked_write(labibb, labibb->lab_base +
				REG_LAB_CURRENT_SENSE,
				LAB_CURRENT_SENSE_GAIN_MASK,
				val, 1);
			if (rc) {
				pr_err("qpnp_labibb_write register %x failed rc = %d\n",
					REG_LAB_CURRENT_SENSE, rc);
				return rc;
			}
		}

		labibb->lab_vreg.vreg_enabled = 1;
		labibb->lab_vreg.vreg_enabled = 1;
	} else {
	} else {
		rc = qpnp_lab_dt_init(labibb, of_node);
		rc = qpnp_lab_dt_init(labibb, of_node);