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

Commit 1383baad authored by Rohit Gupta's avatar Rohit Gupta
Browse files

PM / devfreq: devbw: Switch to OPP APIs



OPP framework exposes a set of functions that could be used to fetch
the list of supported bandwidth values from DT and to query the list
for an appropriate value while honoring requests from
governors/clients.
Use OPP table APIs and get rid of frequency table logic to make the
code more concise and upstream friendly.

Change-Id: I120ae7230bdbfaaa9523263c65a8b84470583071
Signed-off-by: default avatarRohit Gupta <rohgup@codeaurora.org>
parent 4cec0cd6
Loading
Loading
Loading
Loading
+33 −14
Original line number Diff line number Diff line
@@ -9,11 +9,11 @@ Required properties:
- compatible:		Must be "qcom,devbw"
- qcom,src-dst-ports:	A list of tuples where each tuple consists of a bus
			master port number and a bus slave port number.
- qcom,bw-tbl:		A list of meaningful instantaneous bandwidth values
			(in MB/s) that can be requested from the device
			master port to the slave port. The list of values
			depend on the supported bus/slave frequencies and the
			bus width.
- operating-points-v2:	A phandle to the OPP v2 table that holds meaningful
			instantaneous bandwidth values (in MB/s) that can be
			requested from the device master port to the slave port.
			The list of values depend on the supported bus/slave
			frequencies and the bus width.

Optional properties:
- qcom,active-only:	Indicates that the bandwidth votes need to be
@@ -23,17 +23,36 @@ Optional properties:

Example:

	bw_opp_table: bw-opp-table {
		compatible = "operating-points-v2";
		opp-75  {
			opp-hz = /bits/ 64 <  572 >; /*  75 MHz */
		};
		opp-150 {
			opp-hz = /bits/ 64 < 1144 >; /* 150 MHz */
		};
		opp-200 {
			opp-hz = /bits/ 64 < 1525 >; /* 200 MHz */
		};
		opp-307 {
			opp-hz = /bits/ 64 < 2342 >; /* 307 MHz */
		};
		opp-460 {
			opp-hz = /bits/ 64 < 3509 >; /* 460 MHz */
		};
		opp-614 {
			opp-hz = /bits/ 64 < 4684 >; /* 614 MHz */
		};
		opp-800 {
			opp-hz = /bits/ 64 < 6103 >; /* 800 MHz */
		};
		opp-931 {
			opp-hz = /bits/ 64 < 7102 >; /* 931 MHz */
		};
	};
	qcom,cpubw {
		compatible = "qcom,devbw";
		qcom,src-dst-ports = <1 512>, <2 512>;
		qcom,active-only;
		qcom,bw-tbl =
			<  572 /*  75 MHz */ >,
			< 1144 /* 150 MHz */ >,
			< 1525 /* 200 MHz */ >,
			< 2342 /* 307 MHz */ >,
			< 3509 /* 460 MHz */ >,
			< 4684 /* 614 MHz */ >,
			< 6103 /* 800 MHz */ >,
			< 7102 /* 931 MHz */ >;
		operating-points-v2 = <&bw_opp_table>;
	};
+10 −47
Original line number Diff line number Diff line
/*
 * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
 * Copyright (c) 2013-2014, 2018, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
@@ -78,33 +78,15 @@ static int set_bw(struct device *dev, int new_ib, int new_ab)
	return ret;
}

static void find_freq(struct devfreq_dev_profile *p, unsigned long *freq,
			u32 flags)
{
	int i;
	unsigned long atmost, atleast, f;

	atmost = p->freq_table[0];
	atleast = p->freq_table[p->max_state-1];
	for (i = 0; i < p->max_state; i++) {
		f = p->freq_table[i];
		if (f <= *freq)
			atmost = max(f, atmost);
		if (f >= *freq)
			atleast = min(f, atleast);
	}

	if (flags & DEVFREQ_FLAG_LEAST_UPPER_BOUND)
		*freq = atmost;
	else
		*freq = atleast;
}

static int devbw_target(struct device *dev, unsigned long *freq, u32 flags)
{
	struct dev_data *d = dev_get_drvdata(dev);
	struct dev_pm_opp *opp;

	opp = devfreq_recommended_opp(dev, freq, flags);
	if (!IS_ERR(opp))
		dev_pm_opp_put(opp);

	find_freq(&d->dp, freq, flags);
	return set_bw(dev, *freq, d->gov_ab);
}

@@ -118,14 +100,13 @@ static int devbw_get_dev_status(struct device *dev,
}

#define PROP_PORTS "qcom,src-dst-ports"
#define PROP_TBL "qcom,bw-tbl"
#define PROP_ACTIVE "qcom,active-only"

int devfreq_add_devbw(struct device *dev)
{
	struct dev_data *d;
	struct devfreq_dev_profile *p;
	u32 *data, ports[MAX_PATHS * 2];
	u32 ports[MAX_PATHS * 2];
	const char *gov_name;
	int ret, len, i, num_paths;

@@ -174,27 +155,9 @@ int devfreq_add_devbw(struct device *dev)
	p->target = devbw_target;
	p->get_dev_status = devbw_get_dev_status;

	if (of_find_property(dev->of_node, PROP_TBL, &len)) {
		len /= sizeof(*data);
		data = devm_kzalloc(dev, len * sizeof(*data), GFP_KERNEL);
		if (!data)
			return -ENOMEM;

		p->freq_table = devm_kzalloc(dev,
					     len * sizeof(*p->freq_table),
					     GFP_KERNEL);
		if (!p->freq_table)
			return -ENOMEM;

		ret = of_property_read_u32_array(dev->of_node, PROP_TBL,
						 data, len);
	ret = dev_pm_opp_of_add_table(dev);
	if (ret)
			return ret;

		for (i = 0; i < len; i++)
			p->freq_table[i] = data[i];
		p->max_state = len;
	}
		dev_err(dev, "Couldn't parse OPP table:%d\n", ret);

	d->bus_client = msm_bus_scale_register_client(&d->bw_data);
	if (!d->bus_client) {