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

Commit de0fd907 authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

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

parents d852829a 7e75d514
Loading
Loading
Loading
Loading
+4 −0
Original line number 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-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.
- 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:
- reg:				Specifies the SPMI address and size for this peripheral
+78 −11
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@
#define REG_LAB_CLK_DIV			0x48
#define REG_LAB_IBB_EN_RDY		0x49
#define REG_LAB_CURRENT_LIMIT		0x4B
#define REG_LAB_CURRENT_SENSE		0x4C
#define REG_LAB_PS_CTL			0x50
#define REG_LAB_RDSON_MNGMNT		0x53
#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_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 */
#define LAB_PS_CTL_BITS			2
#define LAB_PS_CTL_MASK			((1 << LAB_PS_CTL_BITS) - 1)
@@ -167,10 +173,12 @@

/* REG_IBB_PWRUP_PWRDN_CTL_1 */
#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_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_EN_DLY1	BIT(6)
#define PWRUP_PWRDN_CTL_1_DISCHARGE_EN	BIT(2)
@@ -259,6 +267,13 @@ static const int lab_current_limit_plan[] = {
	800,
};

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

static const int ibb_current_limit_plan[] = {
	0,
	50,
@@ -480,6 +495,17 @@ static int qpnp_ibb_unlock_sec_access(struct qpnp_labibb *labibb)
	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,
				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_config cfg = {};
	u8 ibb_en_rdy_val, val;
	const char *current_sense_str;
	bool config_current_sense = false;

	if (!of_node) {
		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;
	} else {
		rc = qpnp_lab_dt_init(labibb, of_node);