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

Commit 14e03610 authored by Bhalchandra Gajare's avatar Bhalchandra Gajare Committed by Stephen Boyd
Browse files

mfd: wcd9xxx: Add support to parse new set of regulators



Chargepump supply to the codec can be supplied from multiple
regulators. Add support to maintain list of regulators for
chargepump that can be used by individual codec drivers to
dynamically enable/disable the regulators.

Change-Id: I22e2abac349f099ed60a786e50bc15cffd0a3aa2
Signed-off-by: default avatarBhalchandra Gajare <gajare@codeaurora.org>
parent a597e02b
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -35,6 +35,12 @@ Required properties:
 - qcom,cdc-vddcx-2-voltage: cx-2 supply's voltage level min and max in mV.
 - qcom,cdc-vddcx-2-current: cx-2 supply's max current in mA.

 - cdc-vdd-buckhelper-supply: phandle of helper regulator supply's
				device tree node. This supply is a helper regulator for
				cdc-vdd-buck-supply regulator.
 - cdc-vdd-buckhelper-voltage: helper supply's voltage level min and max in mV.
 - qcom,cdc-vdd-buckhelper-current: helper supply's max current in mA.

 - qcom,cdc-static-supplies: List of supplies to be enabled prior to codec
			     hardware probe.  Supplies in this list will be
			     stay enabled.
@@ -76,6 +82,10 @@ Optional properties:
				dynamically.
				Supplies in this list are off by default.

- qcom,cdc-cp-supplies: List of supplies required for codec chargepump enable
				Supplies in this list can be enabled/disabled dynamically and
				are off by default.

 - qcom,cdc-micbias2-headset-only: Boolean. Allow micbias 2 only to headset mic.

Example:
+62 −33
Original line number Diff line number Diff line
@@ -1195,15 +1195,54 @@ static int wcd9xxx_dt_parse_slim_interface_dev_info(struct device *dev,
	return 0;
}

static int wcd9xxx_process_supplies(struct device *dev,
		struct wcd9xxx_pdata *pdata, const char *supply_list,
		int supply_cnt, bool is_ondemand, int index)
{
	int idx, ret = 0;
	const char *name;

	if (supply_cnt == 0) {
		dev_dbg(dev, "%s: no supplies defined for %s\n", __func__,
				supply_list);
		return 0;
	}

	for (idx = 0; idx < supply_cnt; idx++) {
		ret = of_property_read_string_index(dev->of_node,
						    supply_list, idx,
						    &name);
		if (ret) {
			dev_err(dev, "%s: of read string %s idx %d error %d\n",
				__func__, supply_list, idx, ret);
			goto err;
		}

		dev_dbg(dev, "%s: Found cdc supply %s as part of %s\n",
				__func__, name, supply_list);
		ret = wcd9xxx_dt_parse_vreg_info(dev,
					&pdata->regulator[index + idx],
					name, is_ondemand);
		if (ret)
			goto err;
	}

	return 0;

err:
	return ret;

}

static struct wcd9xxx_pdata *wcd9xxx_populate_dt_pdata(struct device *dev)
{
	struct wcd9xxx_pdata *pdata;
	int ret, static_cnt, ond_cnt, idx, i;
	const char *name = NULL;
	int ret, static_cnt, ond_cnt, cp_supplies_cnt;
	u32 mclk_rate = 0;
	u32 dmic_sample_rate = 0;
	const char *static_prop_name = "qcom,cdc-static-supplies";
	const char *ond_prop_name = "qcom,cdc-on-demand-supplies";
	const char *cp_supplies_name = "qcom,cdc-cp-supplies";

	pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
	if (!pdata) {
@@ -1223,44 +1262,34 @@ static struct wcd9xxx_pdata *wcd9xxx_populate_dt_pdata(struct device *dev)
	if (IS_ERR_VALUE(ond_cnt))
		ond_cnt = 0;

	BUG_ON(static_cnt <= 0 || ond_cnt < 0);
	if ((static_cnt + ond_cnt) > ARRAY_SIZE(pdata->regulator)) {
	/* cp-supplies list is an optional property */
	cp_supplies_cnt = of_property_count_strings(dev->of_node,
							cp_supplies_name);
	if (IS_ERR_VALUE(cp_supplies_cnt))
		cp_supplies_cnt = 0;

	BUG_ON(static_cnt <= 0 || ond_cnt < 0 || cp_supplies_cnt < 0);
	if ((static_cnt + ond_cnt + cp_supplies_cnt)
			> ARRAY_SIZE(pdata->regulator)) {
		dev_err(dev, "%s: Num of supplies %u > max supported %u\n",
			__func__, static_cnt, ARRAY_SIZE(pdata->regulator));
		goto err;
	}

	for (idx = 0; idx < static_cnt; idx++) {
		ret = of_property_read_string_index(dev->of_node,
						    static_prop_name, idx,
						    &name);
		if (ret) {
			dev_err(dev, "%s: of read string %s idx %d error %d\n",
				__func__, static_prop_name, idx, ret);
			goto err;
		}

		dev_dbg(dev, "%s: Found static cdc supply %s\n", __func__,
			name);
		ret = wcd9xxx_dt_parse_vreg_info(dev, &pdata->regulator[idx],
						 name, false);
	ret = wcd9xxx_process_supplies(dev, pdata, static_prop_name,
				static_cnt, false, 0);
	if (ret)
		goto err;
	}

	for (i = 0; i < ond_cnt; i++, idx++) {
		ret = of_property_read_string_index(dev->of_node, ond_prop_name,
						    i, &name);
	ret = wcd9xxx_process_supplies(dev, pdata, ond_prop_name,
				ond_cnt, true, static_cnt);
	if (ret)
		goto err;

		dev_dbg(dev, "%s: Found on-demand cdc supply %s\n", __func__,
			name);
		ret = wcd9xxx_dt_parse_vreg_info(dev, &pdata->regulator[idx],
						 name, true);
	ret = wcd9xxx_process_supplies(dev, pdata, cp_supplies_name,
				cp_supplies_cnt, false, static_cnt + ond_cnt);
	if (ret)
		goto err;
	}

	ret = wcd9xxx_dt_parse_micbias_info(dev, &pdata->micbias);
	if (ret)