Skip to content

Commit af8df70

Browse files
Manivannan SadhasivamMani-Sadhasivam
authored andcommitted
PCI: qcom: Move host bridge 'phy' and 'reset' pointers to struct qcom_pcie_port
DT binding allows specifying 'phy' and 'reset' properties in both host bridge and Root Port nodes, though specifying in the host bridge node is marked as deprecated. Still, the pcie-qcom driver should support both combinations for maintaining the DT backwards compatibility. For this purpose, the driver is holding the relevant pointers of these properties in two structs: struct qcom_pcie_port and struct qcom_pcie. However, this causes confusion and increases the driver complexity. Hence, move the pointers from struct qcom_pcie to struct qcom_pcie_port. As a result, even if these properties are specified in the host bridge node, the pointers will be stored in struct qcom_pcie_port as if the properties are specified in a single Root Port node. This logic simplifies the driver a lot. Suggested-by: Bjorn Helgaas <[email protected]> Signed-off-by: Manivannan Sadhasivam <[email protected]> Reviewed-by: Bjorn Helgaas <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent ea5fbbc commit af8df70

File tree

1 file changed

+36
-51
lines changed

1 file changed

+36
-51
lines changed

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

Lines changed: 36 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,6 @@ struct qcom_pcie {
279279
void __iomem *elbi; /* DT elbi */
280280
void __iomem *mhi;
281281
union qcom_pcie_resources res;
282-
struct phy *phy;
283-
struct gpio_desc *reset;
284282
struct icc_path *icc_mem;
285283
struct icc_path *icc_cpu;
286284
const struct qcom_pcie_cfg *cfg;
@@ -297,11 +295,8 @@ static void qcom_perst_assert(struct qcom_pcie *pcie, bool assert)
297295
struct qcom_pcie_port *port;
298296
int val = assert ? 1 : 0;
299297

300-
if (list_empty(&pcie->ports))
301-
gpiod_set_value_cansleep(pcie->reset, val);
302-
else
303-
list_for_each_entry(port, &pcie->ports, list)
304-
gpiod_set_value_cansleep(port->reset, val);
298+
list_for_each_entry(port, &pcie->ports, list)
299+
gpiod_set_value_cansleep(port->reset, val);
305300

306301
usleep_range(PERST_DELAY_US, PERST_DELAY_US + 500);
307302
}
@@ -1253,57 +1248,32 @@ static bool qcom_pcie_link_up(struct dw_pcie *pci)
12531248
return val & PCI_EXP_LNKSTA_DLLLA;
12541249
}
12551250

1256-
static void qcom_pcie_phy_exit(struct qcom_pcie *pcie)
1257-
{
1258-
struct qcom_pcie_port *port;
1259-
1260-
if (list_empty(&pcie->ports))
1261-
phy_exit(pcie->phy);
1262-
else
1263-
list_for_each_entry(port, &pcie->ports, list)
1264-
phy_exit(port->phy);
1265-
}
1266-
12671251
static void qcom_pcie_phy_power_off(struct qcom_pcie *pcie)
12681252
{
12691253
struct qcom_pcie_port *port;
12701254

1271-
if (list_empty(&pcie->ports)) {
1272-
phy_power_off(pcie->phy);
1273-
} else {
1274-
list_for_each_entry(port, &pcie->ports, list)
1275-
phy_power_off(port->phy);
1276-
}
1255+
list_for_each_entry(port, &pcie->ports, list)
1256+
phy_power_off(port->phy);
12771257
}
12781258

12791259
static int qcom_pcie_phy_power_on(struct qcom_pcie *pcie)
12801260
{
12811261
struct qcom_pcie_port *port;
1282-
int ret = 0;
1262+
int ret;
12831263

1284-
if (list_empty(&pcie->ports)) {
1285-
ret = phy_set_mode_ext(pcie->phy, PHY_MODE_PCIE, PHY_MODE_PCIE_RC);
1264+
list_for_each_entry(port, &pcie->ports, list) {
1265+
ret = phy_set_mode_ext(port->phy, PHY_MODE_PCIE, PHY_MODE_PCIE_RC);
12861266
if (ret)
12871267
return ret;
12881268

1289-
ret = phy_power_on(pcie->phy);
1290-
if (ret)
1269+
ret = phy_power_on(port->phy);
1270+
if (ret) {
1271+
qcom_pcie_phy_power_off(pcie);
12911272
return ret;
1292-
} else {
1293-
list_for_each_entry(port, &pcie->ports, list) {
1294-
ret = phy_set_mode_ext(port->phy, PHY_MODE_PCIE, PHY_MODE_PCIE_RC);
1295-
if (ret)
1296-
return ret;
1297-
1298-
ret = phy_power_on(port->phy);
1299-
if (ret) {
1300-
qcom_pcie_phy_power_off(pcie);
1301-
return ret;
1302-
}
13031273
}
13041274
}
13051275

1306-
return ret;
1276+
return 0;
13071277
}
13081278

13091279
static int qcom_pcie_host_init(struct dw_pcie_rp *pp)
@@ -1750,29 +1720,43 @@ static int qcom_pcie_parse_ports(struct qcom_pcie *pcie)
17501720
return ret;
17511721

17521722
err_port_del:
1753-
list_for_each_entry_safe(port, tmp, &pcie->ports, list)
1723+
list_for_each_entry_safe(port, tmp, &pcie->ports, list) {
1724+
phy_exit(port->phy);
17541725
list_del(&port->list);
1726+
}
17551727

17561728
return ret;
17571729
}
17581730

17591731
static int qcom_pcie_parse_legacy_binding(struct qcom_pcie *pcie)
17601732
{
17611733
struct device *dev = pcie->pci->dev;
1734+
struct qcom_pcie_port *port;
1735+
struct gpio_desc *reset;
1736+
struct phy *phy;
17621737
int ret;
17631738

1764-
pcie->phy = devm_phy_optional_get(dev, "pciephy");
1765-
if (IS_ERR(pcie->phy))
1766-
return PTR_ERR(pcie->phy);
1739+
phy = devm_phy_optional_get(dev, "pciephy");
1740+
if (IS_ERR(phy))
1741+
return PTR_ERR(phy);
17671742

1768-
pcie->reset = devm_gpiod_get_optional(dev, "perst", GPIOD_OUT_HIGH);
1769-
if (IS_ERR(pcie->reset))
1770-
return PTR_ERR(pcie->reset);
1743+
reset = devm_gpiod_get_optional(dev, "perst", GPIOD_OUT_HIGH);
1744+
if (IS_ERR(reset))
1745+
return PTR_ERR(reset);
17711746

1772-
ret = phy_init(pcie->phy);
1747+
ret = phy_init(phy);
17731748
if (ret)
17741749
return ret;
17751750

1751+
port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL);
1752+
if (!port)
1753+
return -ENOMEM;
1754+
1755+
port->reset = reset;
1756+
port->phy = phy;
1757+
INIT_LIST_HEAD(&port->list);
1758+
list_add_tail(&port->list, &pcie->ports);
1759+
17761760
return 0;
17771761
}
17781762

@@ -1986,9 +1970,10 @@ static int qcom_pcie_probe(struct platform_device *pdev)
19861970
err_host_deinit:
19871971
dw_pcie_host_deinit(pp);
19881972
err_phy_exit:
1989-
qcom_pcie_phy_exit(pcie);
1990-
list_for_each_entry_safe(port, tmp, &pcie->ports, list)
1973+
list_for_each_entry_safe(port, tmp, &pcie->ports, list) {
1974+
phy_exit(port->phy);
19911975
list_del(&port->list);
1976+
}
19921977
err_pm_runtime_put:
19931978
pm_runtime_put(dev);
19941979
pm_runtime_disable(dev);

0 commit comments

Comments
 (0)