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

Commit c6af29b2 authored by Junjie Wu's avatar Junjie Wu
Browse files

msm: gdsc: Use regulator framework to enforce HW trigger support



For GDSC that does not support hardware trigger, we do not allow mode
change to happen. Even though we enforce this through an internal
flag, we still set REGULATOR_CHANGE_MODE when registering with
regulator framework. This results in probe messages that indicate
change mode support incorrectly.

We should simply use regulator framework to enforce the behavior
instead of using an internal flag. The resulting behavior is same as
our internal flag, except when GDSC does not have hardware trigger
support but get_mode is called. Previously we return MODE_NORMAL
without querying register state. Now we will read the register and
return the actual state hardware is in. It's safe because the register
bit is always there no matter hardware trigger support is present or
not. The resulting value is same MODE_NORMAL because regulator
framework rejects all set_mode calls on that GDSC, leaving that bit
at default value, MODE_NORMAL.

Change-Id: I3f3f278ac19c6034bfe46dcdfd14ed78fb9129dd
Signed-off-by: default avatarJunjie Wu <junjiew@codeaurora.org>
parent 0f8fb3e5
Loading
Loading
Loading
Loading
+8 −14
Original line number Diff line number Diff line
@@ -51,7 +51,6 @@ struct gdsc {
	bool			toggle_periph;
	bool			toggle_logic;
	bool			resets_asserted;
	bool			support_hw_trigger;
};

static int gdsc_is_enabled(struct regulator_dev *rdev)
@@ -156,9 +155,6 @@ static unsigned int gdsc_get_mode(struct regulator_dev *rdev)
	struct gdsc *sc = rdev_get_drvdata(rdev);
	uint32_t regval;

	if (!sc->support_hw_trigger)
		return REGULATOR_MODE_NORMAL;

	regval = readl_relaxed(sc->gdscr);
	if (regval & HW_CONTROL_MASK)
		return REGULATOR_MODE_FAST;
@@ -171,11 +167,6 @@ static int gdsc_set_mode(struct regulator_dev *rdev, unsigned int mode)
	uint32_t regval;
	int ret;

	if (!sc->support_hw_trigger) {
		dev_err(&rdev->dev, "hw collapse not available\n");
		return -ENODEV;
	}

	regval = readl_relaxed(sc->gdscr);

	/*
@@ -249,7 +240,7 @@ static int gdsc_probe(struct platform_device *pdev)
	struct resource *res;
	struct gdsc *sc;
	uint32_t regval;
	bool retain_mem, retain_periph;
	bool retain_mem, retain_periph, support_hw_trigger;
	int i, ret;

	sc = devm_kzalloc(&pdev->dev, sizeof(struct gdsc), GFP_KERNEL);
@@ -263,9 +254,6 @@ static int gdsc_probe(struct platform_device *pdev)
	if (of_get_property(pdev->dev.of_node, "parent-supply", NULL))
		init_data->supply_regulator = "parent";

	init_data->constraints.valid_ops_mask |= REGULATOR_CHANGE_MODE;
	init_data->constraints.valid_modes_mask |= REGULATOR_MODE_NORMAL
						| REGULATOR_MODE_FAST;
	ret = of_property_read_string(pdev->dev.of_node, "regulator-name",
				      &sc->rdesc.name);
	if (ret)
@@ -332,8 +320,14 @@ static int gdsc_probe(struct platform_device *pdev)
	sc->toggle_periph = !retain_periph;
	sc->toggle_logic = !of_property_read_bool(pdev->dev.of_node,
						"qcom,skip-logic-collapse");
	sc->support_hw_trigger = of_property_read_bool(pdev->dev.of_node,
	support_hw_trigger = of_property_read_bool(pdev->dev.of_node,
						    "qcom,support-hw-trigger");
	if (support_hw_trigger) {
		init_data->constraints.valid_ops_mask |= REGULATOR_CHANGE_MODE;
		init_data->constraints.valid_modes_mask |=
				REGULATOR_MODE_NORMAL | REGULATOR_MODE_FAST;
	}

	if (!sc->toggle_logic) {
		regval &= ~SW_COLLAPSE_MASK;
		writel_relaxed(regval, sc->gdscr);