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

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

Merge "power: bcl: Support selective core frequency mitigation"

parents 4a7aaa64 56ba8020
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -47,7 +47,8 @@ Optional parameters:
		is reached.
- qcom,bcl-soc-hotplug-list: List of phandles to the cores that are to be hotplugged,
		when battery SOC limit condition is reached.

- qcom,bcl-freq-control-list: List of phandles to the cores that are to be frequency
                mitigated when BCL condition is reached.
- qcom,bcl-no-bms: This is an optional node for BCL IAVAIL monitor mode.
		If this property is defined, BCL IAVAIL monitor gets rbat value
		from power supply battery module instead of bms module.
@@ -120,7 +121,9 @@ For Using BCL peripheral interface:
	qcom,bcl {
		compatible = "qcom,bcl";
		qcom,bcl-framework-interface;
		qcom,bcl-freq-mit-list = <&CPU4 &CPU5 &CPU6 &CPU7>;
		qcom,bcl-hotplug-list = <&CPU5 &CPU6 &CPU7>;
		qcom,bcl-soc-hotplug-list = <&CPU4 &CPU5 &CPU6 &CPU7>;
		qcom,ibat-monitor {
			qcom,high-threshold-uamp = <1500>;
			qcom,low-threshold-uamp = <500>;
+41 −28
Original line number Diff line number Diff line
@@ -189,6 +189,7 @@ static enum bcl_threshold_state bcl_vph_state = BCL_THRESHOLD_DISABLED,
		bcl_ibat_state = BCL_THRESHOLD_DISABLED;
static DEFINE_MUTEX(bcl_notify_mutex);
static uint32_t bcl_hotplug_request, bcl_hotplug_mask, bcl_soc_hotplug_mask;
static uint32_t bcl_frequency_mask;
static struct work_struct bcl_hotplug_work;
static DEFINE_MUTEX(bcl_hotplug_mutex);
static bool bcl_hotplug_enabled;
@@ -280,6 +281,9 @@ static int bcl_cpufreq_callback(struct notifier_block *nfb,
	struct cpufreq_policy *policy = data;
	uint32_t max_freq = UINT_MAX;

	if (!(bcl_frequency_mask & BIT(policy->cpu)))
		return NOTIFY_OK;

	switch (event) {
	case CPUFREQ_INCOMPATIBLE:
		if (bcl_vph_state == BCL_LOW_THRESHOLD
@@ -309,11 +313,14 @@ static void update_cpu_freq(void)

	get_online_cpus();
	for_each_online_cpu(cpu) {
		if (bcl_frequency_mask & BIT(cpu)) {
			ret = cpufreq_update_policy(cpu);
			if (ret)
			pr_err("Error updating policy for CPU%d. ret:%d\n",
				pr_err(
				"Error updating policy for CPU%d. ret:%d\n",
				cpu, ret);
		}
	}
	put_online_cpus();
}

@@ -1621,12 +1628,34 @@ static int bcl_battery_set_property(struct power_supply *psy,
	return 0;
}

static uint32_t get_mask_from_core_handle(struct platform_device *pdev,
						const char *key)
{
	struct device_node *core_phandle = NULL;
	int i = 0, cpu = 0;
	uint32_t mask = 0;

	core_phandle = of_parse_phandle(pdev->dev.of_node,
			key, i++);
	while (core_phandle) {
		for_each_possible_cpu(cpu) {
			if (of_get_cpu_node(cpu, NULL) == core_phandle) {
				mask |= BIT(cpu);
				break;
			}
		}
		core_phandle = of_parse_phandle(pdev->dev.of_node,
			key, i++);
	}

	return mask;
}

static int bcl_probe(struct platform_device *pdev)
{
	struct bcl_context *bcl = NULL;
	int ret = 0, i = 0, cpu = 0;
	int ret = 0;
	enum bcl_device_mode bcl_mode = BCL_DEVICE_DISABLED;
	struct device_node *core_phandle = NULL;

	bcl = devm_kzalloc(&pdev->dev, sizeof(struct bcl_context), GFP_KERNEL);
	if (!bcl) {
@@ -1659,31 +1688,15 @@ static int bcl_probe(struct platform_device *pdev)
	else
		bcl->bcl_no_bms = false;

	core_phandle = of_parse_phandle(pdev->dev.of_node,
			"qcom,bcl-hotplug-list", i++);
	while (core_phandle) {
	bcl_frequency_mask = get_mask_from_core_handle(pdev,
					 "qcom,bcl-freq-control-list");
	bcl_hotplug_mask = get_mask_from_core_handle(pdev,
					 "qcom,bcl-hotplug-list");
	if (bcl_hotplug_mask)
		bcl_hotplug_enabled = true;
		for_each_possible_cpu(cpu) {
			if (of_get_cpu_node(cpu, NULL) == core_phandle)
				bcl_hotplug_mask |= BIT(cpu);
		}
		core_phandle = of_parse_phandle(pdev->dev.of_node,
			"qcom,bcl-hotplug-list", i++);
	}
	if (!bcl_hotplug_mask)
		bcl_hotplug_enabled = false;

	i = 0;
	core_phandle = of_parse_phandle(pdev->dev.of_node,
			"qcom,bcl-soc-hotplug-list", i++);
	while (core_phandle) {
		for_each_possible_cpu(cpu) {
			if (of_get_cpu_node(cpu, NULL) == core_phandle)
				bcl_soc_hotplug_mask |= BIT(cpu);
		}
		core_phandle = of_parse_phandle(pdev->dev.of_node,
			"qcom,bcl-soc-hotplug-list", i++);
	}
	bcl_soc_hotplug_mask = get_mask_from_core_handle(pdev,
					 "qcom,bcl-soc-hotplug-list");

	if (of_property_read_bool(pdev->dev.of_node,
		"qcom,bcl-framework-interface"))