Commit 694a5b57 authored by Arnd Bergmann's avatar Arnd Bergmann

Merge tag 'memory-controller-drv-tegra-5.11-3' of...

Merge tag 'memory-controller-drv-tegra-5.11-3' of git://git.kernel.org/pub/scm/linux/kernel/git/krzk/linux-mem-ctrl into arm/drivers

Memory controller drivers for v5.11 - Tegra SoC, part two

Continuation of work on Tegra SoC memory controllers towards adding
interconnect support and integration with devfreq.

This brings few more patches including one which removes/fixes annoying
warning if the DTS patches get applied.  This is expected and only
informs that new features of Tegra memory controller drivers will not be
enabled however the warning itself could look worrying.

* tag 'memory-controller-drv-tegra-5.11-3' of git://git.kernel.org/pub/scm/linux/kernel/git/krzk/linux-mem-ctrl:
  memory: tegra30: Support interconnect framework
  memory: tegra20: Support hardware versioning and clean up OPP table initialization
  dt-bindings: memory: tegra20-emc: Document opp-supported-hw property

Link: https://lore.kernel.org/r/20201207075758.5501-2-krzk@kernel.orgSigned-off-by: default avatarArnd Bergmann <arnd@arndb.de>
parents c35ffce8 d76fa3f2
......@@ -16,6 +16,12 @@ Properties:
- #interconnect-cells : Should be 0.
- operating-points-v2: See ../bindings/opp/opp.txt for details.
For each opp entry in 'operating-points-v2' table:
- opp-supported-hw: One bitfield indicating SoC process ID mask
A bitwise AND is performed against this value and if any bit
matches, the OPP gets enabled.
Optional properties:
- core-supply: Phandle of voltage regulator of the SoC "core" power domain.
......
......@@ -24,6 +24,7 @@ config TEGRA30_EMC
tristate "NVIDIA Tegra30 External Memory Controller driver"
default y
depends on TEGRA_MC && ARCH_TEGRA_3x_SOC
select PM_OPP
help
This driver is for the External Memory Controller (EMC) found on
Tegra30 chips. The EMC controls the external DRAM on the board.
......
......@@ -910,43 +910,36 @@ static int tegra_emc_interconnect_init(struct tegra_emc *emc)
static int tegra_emc_opp_table_init(struct tegra_emc *emc)
{
struct opp_table *reg_opp_table = NULL, *clk_opp_table;
const char *rname = "core";
u32 hw_version = BIT(tegra_sku_info.soc_process_id);
struct opp_table *clk_opp_table, *hw_opp_table;
int err;
/*
* Legacy device-trees don't have OPP table and EMC driver isn't
* useful in this case.
*/
if (!device_property_present(emc->dev, "operating-points-v2")) {
dev_err(emc->dev,
"OPP table not found, please update your device tree\n");
return -ENODEV;
}
/* voltage scaling is optional */
if (device_property_present(emc->dev, "core-supply")) {
reg_opp_table = dev_pm_opp_set_regulators(emc->dev, &rname, 1);
if (IS_ERR(reg_opp_table))
return dev_err_probe(emc->dev, PTR_ERR(reg_opp_table),
"failed to set OPP regulator\n");
}
clk_opp_table = dev_pm_opp_set_clkname(emc->dev, NULL);
err = PTR_ERR_OR_ZERO(clk_opp_table);
if (err) {
dev_err(emc->dev, "failed to set OPP clk: %d\n", err);
goto put_reg_table;
return err;
}
err = dev_pm_opp_of_add_table(emc->dev);
hw_opp_table = dev_pm_opp_set_supported_hw(emc->dev, &hw_version, 1);
err = PTR_ERR_OR_ZERO(hw_opp_table);
if (err) {
dev_err(emc->dev, "failed to add OPP table: %d\n", err);
dev_err(emc->dev, "failed to set OPP supported HW: %d\n", err);
goto put_clk_table;
}
dev_info(emc->dev, "current clock rate %lu MHz\n",
clk_get_rate(emc->clk) / 1000000);
err = dev_pm_opp_of_add_table(emc->dev);
if (err) {
if (err == -ENODEV)
dev_err(emc->dev, "OPP table not found, please update your device tree\n");
else
dev_err(emc->dev, "failed to add OPP table: %d\n", err);
goto put_hw_table;
}
dev_info(emc->dev, "OPP HW ver. 0x%x, current clock rate %lu MHz\n",
hw_version, clk_get_rate(emc->clk) / 1000000);
/* first dummy rate-set initializes voltage state */
err = dev_pm_opp_set_rate(emc->dev, clk_get_rate(emc->clk));
......@@ -959,11 +952,10 @@ static int tegra_emc_opp_table_init(struct tegra_emc *emc)
remove_table:
dev_pm_opp_of_remove_table(emc->dev);
put_hw_table:
dev_pm_opp_put_supported_hw(hw_opp_table);
put_clk_table:
dev_pm_opp_put_clkname(clk_opp_table);
put_reg_table:
if (reg_opp_table)
dev_pm_opp_put_regulators(reg_opp_table);
return err;
}
......
This diff is collapsed.
......@@ -4,7 +4,8 @@
*/
#include <linux/of.h>
#include <linux/mm.h>
#include <linux/of_device.h>
#include <linux/slab.h>
#include <dt-bindings/memory/tegra30-mc.h>
......@@ -1083,6 +1084,175 @@ static const struct tegra_mc_reset tegra30_mc_resets[] = {
TEGRA30_MC_RESET(VI, 0x200, 0x204, 17),
};
static void tegra30_mc_tune_client_latency(struct tegra_mc *mc,
const struct tegra_mc_client *client,
unsigned int bandwidth_mbytes_sec)
{
u32 arb_tolerance_compensation_nsec, arb_tolerance_compensation_div;
const struct tegra_mc_la *la = &client->la;
unsigned int fifo_size = client->fifo_size;
u32 arb_nsec, la_ticks, value;
/* see 18.4.1 Client Configuration in Tegra3 TRM v03p */
if (bandwidth_mbytes_sec)
arb_nsec = fifo_size * NSEC_PER_USEC / bandwidth_mbytes_sec;
else
arb_nsec = U32_MAX;
/*
* Latency allowness should be set with consideration for the module's
* latency tolerance and internal buffering capabilities.
*
* Display memory clients use isochronous transfers and have very low
* tolerance to a belated transfers. Hence we need to compensate the
* memory arbitration imperfection for them in order to prevent FIFO
* underflow condition when memory bus is busy.
*
* VI clients also need a stronger compensation.
*/
switch (client->swgroup) {
case TEGRA_SWGROUP_MPCORE:
case TEGRA_SWGROUP_PTC:
/*
* We always want lower latency for these clients, hence
* don't touch them.
*/
return;
case TEGRA_SWGROUP_DC:
case TEGRA_SWGROUP_DCB:
arb_tolerance_compensation_nsec = 1050;
arb_tolerance_compensation_div = 2;
break;
case TEGRA_SWGROUP_VI:
arb_tolerance_compensation_nsec = 1050;
arb_tolerance_compensation_div = 1;
break;
default:
arb_tolerance_compensation_nsec = 150;
arb_tolerance_compensation_div = 1;
break;
}
if (arb_nsec > arb_tolerance_compensation_nsec)
arb_nsec -= arb_tolerance_compensation_nsec;
else
arb_nsec = 0;
arb_nsec /= arb_tolerance_compensation_div;
/*
* Latency allowance is a number of ticks a request from a particular
* client may wait in the EMEM arbiter before it becomes a high-priority
* request.
*/
la_ticks = arb_nsec / mc->tick;
la_ticks = min(la_ticks, la->mask);
value = mc_readl(mc, la->reg);
value &= ~(la->mask << la->shift);
value |= la_ticks << la->shift;
mc_writel(mc, value, la->reg);
}
static int tegra30_mc_icc_set(struct icc_node *src, struct icc_node *dst)
{
struct tegra_mc *mc = icc_provider_to_tegra_mc(src->provider);
const struct tegra_mc_client *client = &mc->soc->clients[src->id];
u64 peak_bandwidth = icc_units_to_bps(src->peak_bw);
/*
* Skip pre-initialization that is done by icc_node_add(), which sets
* bandwidth to maximum for all clients before drivers are loaded.
*
* This doesn't make sense for us because we don't have drivers for all
* clients and it's okay to keep configuration left from bootloader
* during boot, at least for today.
*/
if (src == dst)
return 0;
/* convert bytes/sec to megabytes/sec */
do_div(peak_bandwidth, 1000000);
tegra30_mc_tune_client_latency(mc, client, peak_bandwidth);
return 0;
}
static int tegra30_mc_icc_aggreate(struct icc_node *node, u32 tag, u32 avg_bw,
u32 peak_bw, u32 *agg_avg, u32 *agg_peak)
{
/*
* ISO clients need to reserve extra bandwidth up-front because
* there could be high bandwidth pressure during initial filling
* of the client's FIFO buffers. Secondly, we need to take into
* account impurities of the memory subsystem.
*/
if (tag & TEGRA_MC_ICC_TAG_ISO)
peak_bw = tegra_mc_scale_percents(peak_bw, 400);
*agg_avg += avg_bw;
*agg_peak = max(*agg_peak, peak_bw);
return 0;
}
static struct icc_node_data *
tegra30_mc_of_icc_xlate_extended(struct of_phandle_args *spec, void *data)
{
struct tegra_mc *mc = icc_provider_to_tegra_mc(data);
const struct tegra_mc_client *client;
unsigned int i, idx = spec->args[0];
struct icc_node_data *ndata;
struct icc_node *node;
list_for_each_entry(node, &mc->provider.nodes, node_list) {
if (node->id != idx)
continue;
ndata = kzalloc(sizeof(*ndata), GFP_KERNEL);
if (!ndata)
return ERR_PTR(-ENOMEM);
client = &mc->soc->clients[idx];
ndata->node = node;
switch (client->swgroup) {
case TEGRA_SWGROUP_DC:
case TEGRA_SWGROUP_DCB:
case TEGRA_SWGROUP_PTC:
case TEGRA_SWGROUP_VI:
/* these clients are isochronous by default */
ndata->tag = TEGRA_MC_ICC_TAG_ISO;
break;
default:
ndata->tag = TEGRA_MC_ICC_TAG_DEFAULT;
break;
}
return ndata;
}
for (i = 0; i < mc->soc->num_clients; i++) {
if (mc->soc->clients[i].id == idx)
return ERR_PTR(-EPROBE_DEFER);
}
dev_err(mc->dev, "invalid ICC client ID %u\n", idx);
return ERR_PTR(-EINVAL);
}
static const struct tegra_mc_icc_ops tegra30_mc_icc_ops = {
.xlate_extended = tegra30_mc_of_icc_xlate_extended,
.aggregate = tegra30_mc_icc_aggreate,
.set = tegra30_mc_icc_set,
};
const struct tegra_mc_soc tegra30_mc_soc = {
.clients = tegra30_mc_clients,
.num_clients = ARRAY_SIZE(tegra30_mc_clients),
......@@ -1097,4 +1267,5 @@ const struct tegra_mc_soc tegra30_mc_soc = {
.reset_ops = &tegra_mc_reset_ops_common,
.resets = tegra30_mc_resets,
.num_resets = ARRAY_SIZE(tegra30_mc_resets),
.icc_ops = &tegra30_mc_icc_ops,
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment