Skip to content

Commit 8da2e9a

Browse files
Mani-Sadhasivamkwilczynski
authored andcommitted
PCI: qcom: Use PCIE_SPEED2MBS_ENC() macro for encoding link speed
Instead of hardcoding the link speed in MBps, use existing PCIE_SPEED2MBS_ENC() macro that does the encoding of the link speed for us. Also, let's Wrap it with QCOM_PCIE_LINK_SPEED_TO_BW() macro to do the conversion to ICC speed. This eliminates the need for a switch case in qcom_pcie_icc_update() and also works for future Gen speeds without any code modifications. Suggested-by: Bjorn Helgaas <[email protected]> Link: https://lore.kernel.org/linux-pci/[email protected] Signed-off-by: Manivannan Sadhasivam <[email protected]> Signed-off-by: Krzysztof Wilczyński <[email protected]> Reviewed-by: Konrad Dybcio <[email protected]>
1 parent 0bb80ec commit 8da2e9a

File tree

1 file changed

+6
-18
lines changed

1 file changed

+6
-18
lines changed

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

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@
148148

149149
#define QCOM_PCIE_CRC8_POLYNOMIAL (BIT(2) | BIT(1) | BIT(0))
150150

151+
#define QCOM_PCIE_LINK_SPEED_TO_BW(speed) \
152+
Mbps_to_icc(PCIE_SPEED2MBS_ENC(pcie_link_speed[speed]))
153+
151154
#define QCOM_PCIE_1_0_0_MAX_CLOCKS 4
152155
struct qcom_pcie_resources_1_0_0 {
153156
struct clk_bulk_data clks[QCOM_PCIE_1_0_0_MAX_CLOCKS];
@@ -1347,7 +1350,7 @@ static int qcom_pcie_icc_init(struct qcom_pcie *pcie)
13471350
* Set an initial peak bandwidth corresponding to single-lane Gen 1
13481351
* for the pcie-mem path.
13491352
*/
1350-
ret = icc_set_bw(pcie->icc_mem, 0, MBps_to_icc(250));
1353+
ret = icc_set_bw(pcie->icc_mem, 0, QCOM_PCIE_LINK_SPEED_TO_BW(1));
13511354
if (ret) {
13521355
dev_err(pci->dev, "failed to set interconnect bandwidth: %d\n",
13531356
ret);
@@ -1360,7 +1363,7 @@ static int qcom_pcie_icc_init(struct qcom_pcie *pcie)
13601363
static void qcom_pcie_icc_update(struct qcom_pcie *pcie)
13611364
{
13621365
struct dw_pcie *pci = pcie->pci;
1363-
u32 offset, status, bw;
1366+
u32 offset, status;
13641367
int speed, width;
13651368
int ret;
13661369

@@ -1377,22 +1380,7 @@ static void qcom_pcie_icc_update(struct qcom_pcie *pcie)
13771380
speed = FIELD_GET(PCI_EXP_LNKSTA_CLS, status);
13781381
width = FIELD_GET(PCI_EXP_LNKSTA_NLW, status);
13791382

1380-
switch (speed) {
1381-
case 1:
1382-
bw = MBps_to_icc(250);
1383-
break;
1384-
case 2:
1385-
bw = MBps_to_icc(500);
1386-
break;
1387-
default:
1388-
WARN_ON_ONCE(1);
1389-
fallthrough;
1390-
case 3:
1391-
bw = MBps_to_icc(985);
1392-
break;
1393-
}
1394-
1395-
ret = icc_set_bw(pcie->icc_mem, 0, width * bw);
1383+
ret = icc_set_bw(pcie->icc_mem, 0, width * QCOM_PCIE_LINK_SPEED_TO_BW(speed));
13961384
if (ret) {
13971385
dev_err(pci->dev, "failed to set interconnect bandwidth: %d\n",
13981386
ret);

0 commit comments

Comments
 (0)