Skip to content

Commit 5b6272e

Browse files
Krishna chaitanya chundrubjorn-helgaas
authored andcommitted
PCI: qcom: Add OPP support to scale performance
QCOM Resource Power Manager-hardened (RPMh) is a hardware block which maintains hardware state of a regulator by performing max aggregation of the requests made by all of the clients. PCIe controller can operate on different RPMh performance state of power domain based on the speed of the link. And this performance state varies from target to target, like some controllers support GEN3 in NOM (Nominal) voltage corner, while some other supports GEN3 in low SVS (static voltage scaling). The SoC can be more power efficient if we scale the performance state based on the aggregate PCIe link bandwidth. Add Operating Performance Points (OPP) support to vote for RPMh state based on the aggregate link bandwidth. OPP can handle ICC bw voting also, so move ICC bw voting through OPP framework if OPP entries are present. As we are moving ICC voting as part of OPP, don't initialize ICC if OPP is supported. Before PCIe link is initialized vote for highest OPP in the OPP table, so that we are voting for maximum voltage corner for the link to come up in maximum supported speed. Link: https://lore.kernel.org/linux-pci/[email protected] Signed-off-by: Krishna chaitanya chundru <[email protected]> Signed-off-by: Krzysztof Wilczyński <[email protected]> [bhelgaas: wrap comments to fit in 80 columns] Signed-off-by: Bjorn Helgaas <[email protected]> Reviewed-by: Manivannan Sadhasivam <[email protected]>
1 parent 100ae5d commit 5b6272e

File tree

1 file changed

+80
-19
lines changed

1 file changed

+80
-19
lines changed

drivers/pci/controller/dwc/pcie-qcom.c

Lines changed: 80 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
#include <linux/io.h>
1919
#include <linux/iopoll.h>
2020
#include <linux/kernel.h>
21+
#include <linux/limits.h>
2122
#include <linux/init.h>
2223
#include <linux/of.h>
2324
#include <linux/of_gpio.h>
2425
#include <linux/pci.h>
26+
#include <linux/pm_opp.h>
2527
#include <linux/pm_runtime.h>
2628
#include <linux/platform_device.h>
2729
#include <linux/phy/pcie.h>
@@ -30,6 +32,7 @@
3032
#include <linux/reset.h>
3133
#include <linux/slab.h>
3234
#include <linux/types.h>
35+
#include <linux/units.h>
3336

3437
#include "../../pci.h"
3538
#include "pcie-designware.h"
@@ -1406,15 +1409,13 @@ static int qcom_pcie_icc_init(struct qcom_pcie *pcie)
14061409
return 0;
14071410
}
14081411

1409-
static void qcom_pcie_icc_update(struct qcom_pcie *pcie)
1412+
static void qcom_pcie_icc_opp_update(struct qcom_pcie *pcie)
14101413
{
1414+
u32 offset, status, width, speed;
14111415
struct dw_pcie *pci = pcie->pci;
1412-
u32 offset, status;
1413-
int speed, width;
1414-
int ret;
1415-
1416-
if (!pcie->icc_mem)
1417-
return;
1416+
unsigned long freq_kbps;
1417+
struct dev_pm_opp *opp;
1418+
int ret, freq_mbps;
14181419

14191420
offset = dw_pcie_find_capability(pci, PCI_CAP_ID_EXP);
14201421
status = readw(pci->dbi_base + offset + PCI_EXP_LNKSTA);
@@ -1426,10 +1427,28 @@ static void qcom_pcie_icc_update(struct qcom_pcie *pcie)
14261427
speed = FIELD_GET(PCI_EXP_LNKSTA_CLS, status);
14271428
width = FIELD_GET(PCI_EXP_LNKSTA_NLW, status);
14281429

1429-
ret = icc_set_bw(pcie->icc_mem, 0, width * QCOM_PCIE_LINK_SPEED_TO_BW(speed));
1430-
if (ret) {
1431-
dev_err(pci->dev, "Failed to set bandwidth for PCIe-MEM interconnect path: %d\n",
1432-
ret);
1430+
if (pcie->icc_mem) {
1431+
ret = icc_set_bw(pcie->icc_mem, 0,
1432+
width * QCOM_PCIE_LINK_SPEED_TO_BW(speed));
1433+
if (ret) {
1434+
dev_err(pci->dev, "Failed to set bandwidth for PCIe-MEM interconnect path: %d\n",
1435+
ret);
1436+
}
1437+
} else {
1438+
freq_mbps = pcie_dev_speed_mbps(pcie_link_speed[speed]);
1439+
if (freq_mbps < 0)
1440+
return;
1441+
1442+
freq_kbps = freq_mbps * KILO;
1443+
opp = dev_pm_opp_find_freq_exact(pci->dev, freq_kbps * width,
1444+
true);
1445+
if (!IS_ERR(opp)) {
1446+
ret = dev_pm_opp_set_opp(pci->dev, opp);
1447+
if (ret)
1448+
dev_err(pci->dev, "Failed to set OPP for freq (%lu): %d\n",
1449+
freq_kbps * width, ret);
1450+
}
1451+
dev_pm_opp_put(opp);
14331452
}
14341453
}
14351454

@@ -1473,7 +1492,9 @@ static void qcom_pcie_init_debugfs(struct qcom_pcie *pcie)
14731492
static int qcom_pcie_probe(struct platform_device *pdev)
14741493
{
14751494
const struct qcom_pcie_cfg *pcie_cfg;
1495+
unsigned long max_freq = ULONG_MAX;
14761496
struct device *dev = &pdev->dev;
1497+
struct dev_pm_opp *opp;
14771498
struct qcom_pcie *pcie;
14781499
struct dw_pcie_rp *pp;
14791500
struct resource *res;
@@ -1541,9 +1562,42 @@ static int qcom_pcie_probe(struct platform_device *pdev)
15411562
goto err_pm_runtime_put;
15421563
}
15431564

1544-
ret = qcom_pcie_icc_init(pcie);
1545-
if (ret)
1565+
/* OPP table is optional */
1566+
ret = devm_pm_opp_of_add_table(dev);
1567+
if (ret && ret != -ENODEV) {
1568+
dev_err_probe(dev, ret, "Failed to add OPP table\n");
15461569
goto err_pm_runtime_put;
1570+
}
1571+
1572+
/*
1573+
* Before the PCIe link is initialized, vote for highest OPP in the OPP
1574+
* table, so that we are voting for maximum voltage corner for the
1575+
* link to come up in maximum supported speed. At the end of the
1576+
* probe(), OPP will be updated using qcom_pcie_icc_opp_update().
1577+
*/
1578+
if (!ret) {
1579+
opp = dev_pm_opp_find_freq_floor(dev, &max_freq);
1580+
if (IS_ERR(opp)) {
1581+
dev_err_probe(pci->dev, PTR_ERR(opp),
1582+
"Unable to find max freq OPP\n");
1583+
goto err_pm_runtime_put;
1584+
} else {
1585+
ret = dev_pm_opp_set_opp(dev, opp);
1586+
}
1587+
1588+
dev_pm_opp_put(opp);
1589+
if (ret) {
1590+
dev_err_probe(pci->dev, ret,
1591+
"Failed to set OPP for freq %lu\n",
1592+
max_freq);
1593+
goto err_pm_runtime_put;
1594+
}
1595+
} else {
1596+
/* Skip ICC init if OPP is supported as it is handled by OPP */
1597+
ret = qcom_pcie_icc_init(pcie);
1598+
if (ret)
1599+
goto err_pm_runtime_put;
1600+
}
15471601

15481602
ret = pcie->cfg->ops->get_resources(pcie);
15491603
if (ret)
@@ -1563,7 +1617,7 @@ static int qcom_pcie_probe(struct platform_device *pdev)
15631617
goto err_phy_exit;
15641618
}
15651619

1566-
qcom_pcie_icc_update(pcie);
1620+
qcom_pcie_icc_opp_update(pcie);
15671621

15681622
if (pcie->mhi)
15691623
qcom_pcie_init_debugfs(pcie);
@@ -1588,10 +1642,14 @@ static int qcom_pcie_suspend_noirq(struct device *dev)
15881642
* Set minimum bandwidth required to keep data path functional during
15891643
* suspend.
15901644
*/
1591-
ret = icc_set_bw(pcie->icc_mem, 0, kBps_to_icc(1));
1592-
if (ret) {
1593-
dev_err(dev, "Failed to set bandwidth for PCIe-MEM interconnect path: %d\n", ret);
1594-
return ret;
1645+
if (pcie->icc_mem) {
1646+
ret = icc_set_bw(pcie->icc_mem, 0, kBps_to_icc(1));
1647+
if (ret) {
1648+
dev_err(dev,
1649+
"Failed to set bandwidth for PCIe-MEM interconnect path: %d\n",
1650+
ret);
1651+
return ret;
1652+
}
15951653
}
15961654

15971655
/*
@@ -1624,6 +1682,9 @@ static int qcom_pcie_suspend_noirq(struct device *dev)
16241682
ret = icc_disable(pcie->icc_cpu);
16251683
if (ret)
16261684
dev_err(dev, "Failed to disable CPU-PCIe interconnect path: %d\n", ret);
1685+
1686+
if (!pcie->icc_mem)
1687+
dev_pm_opp_set_opp(pcie->pci->dev, NULL);
16271688
}
16281689
return ret;
16291690
}
@@ -1649,7 +1710,7 @@ static int qcom_pcie_resume_noirq(struct device *dev)
16491710
pcie->suspended = false;
16501711
}
16511712

1652-
qcom_pcie_icc_update(pcie);
1713+
qcom_pcie_icc_opp_update(pcie);
16531714

16541715
return 0;
16551716
}

0 commit comments

Comments
 (0)