Skip to content

Commit 49a0925

Browse files
floatiousbjorn-helgaas
authored andcommitted
PCI: dw-rockchip: Refactor the driver to prepare for EP mode
Refactor the driver to prepare for EP mode. Add of-match data to the existing compatible, and explicitly define it as DW_PCIE_RC_TYPE. This way, we will be able to add EP mode in a follow-up commit in a much less intrusive way, which makes the follow-up commit much easier to review. No functional change intended. Link: https://lore.kernel.org/linux-pci/[email protected] Signed-off-by: Niklas Cassel <[email protected]> Signed-off-by: Krzysztof Wilczyński <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Reviewed-by: Manivannan Sadhasivam <[email protected]>
1 parent d8b864c commit 49a0925

File tree

1 file changed

+60
-24
lines changed

1 file changed

+60
-24
lines changed

drivers/pci/controller/dwc/pcie-dw-rockchip.c

Lines changed: 60 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,20 @@
4949
#define PCIE_LTSSM_STATUS_MASK GENMASK(5, 0)
5050

5151
struct rockchip_pcie {
52-
struct dw_pcie pci;
53-
void __iomem *apb_base;
54-
struct phy *phy;
55-
struct clk_bulk_data *clks;
56-
unsigned int clk_cnt;
57-
struct reset_control *rst;
58-
struct gpio_desc *rst_gpio;
59-
struct regulator *vpcie3v3;
60-
struct irq_domain *irq_domain;
52+
struct dw_pcie pci;
53+
void __iomem *apb_base;
54+
struct phy *phy;
55+
struct clk_bulk_data *clks;
56+
unsigned int clk_cnt;
57+
struct reset_control *rst;
58+
struct gpio_desc *rst_gpio;
59+
struct regulator *vpcie3v3;
60+
struct irq_domain *irq_domain;
61+
const struct rockchip_pcie_of_data *data;
62+
};
63+
64+
struct rockchip_pcie_of_data {
65+
enum dw_pcie_device_mode mode;
6166
};
6267

6368
static int rockchip_pcie_readl_apb(struct rockchip_pcie *rockchip, u32 reg)
@@ -195,7 +200,6 @@ static int rockchip_pcie_host_init(struct dw_pcie_rp *pp)
195200
struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
196201
struct rockchip_pcie *rockchip = to_rockchip_pcie(pci);
197202
struct device *dev = rockchip->pci.dev;
198-
u32 val = HIWORD_UPDATE_BIT(PCIE_LTSSM_ENABLE_ENHANCE);
199203
int irq, ret;
200204

201205
irq = of_irq_get_byname(dev->of_node, "legacy");
@@ -209,12 +213,6 @@ static int rockchip_pcie_host_init(struct dw_pcie_rp *pp)
209213
irq_set_chained_handler_and_data(irq, rockchip_pcie_intx_handler,
210214
rockchip);
211215

212-
/* LTSSM enable control mode */
213-
rockchip_pcie_writel_apb(rockchip, val, PCIE_CLIENT_HOT_RESET_CTRL);
214-
215-
rockchip_pcie_writel_apb(rockchip, PCIE_CLIENT_RC_MODE,
216-
PCIE_CLIENT_GENERAL_CONTROL);
217-
218216
return 0;
219217
}
220218

@@ -294,13 +292,35 @@ static const struct dw_pcie_ops dw_pcie_ops = {
294292
.start_link = rockchip_pcie_start_link,
295293
};
296294

295+
static int rockchip_pcie_configure_rc(struct rockchip_pcie *rockchip)
296+
{
297+
struct dw_pcie_rp *pp;
298+
u32 val;
299+
300+
/* LTSSM enable control mode */
301+
val = HIWORD_UPDATE_BIT(PCIE_LTSSM_ENABLE_ENHANCE);
302+
rockchip_pcie_writel_apb(rockchip, val, PCIE_CLIENT_HOT_RESET_CTRL);
303+
304+
rockchip_pcie_writel_apb(rockchip, PCIE_CLIENT_RC_MODE,
305+
PCIE_CLIENT_GENERAL_CONTROL);
306+
307+
pp = &rockchip->pci.pp;
308+
pp->ops = &rockchip_pcie_host_ops;
309+
310+
return dw_pcie_host_init(pp);
311+
}
312+
297313
static int rockchip_pcie_probe(struct platform_device *pdev)
298314
{
299315
struct device *dev = &pdev->dev;
300316
struct rockchip_pcie *rockchip;
301-
struct dw_pcie_rp *pp;
317+
const struct rockchip_pcie_of_data *data;
302318
int ret;
303319

320+
data = of_device_get_match_data(dev);
321+
if (!data)
322+
return -EINVAL;
323+
304324
rockchip = devm_kzalloc(dev, sizeof(*rockchip), GFP_KERNEL);
305325
if (!rockchip)
306326
return -ENOMEM;
@@ -309,9 +329,7 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
309329

310330
rockchip->pci.dev = dev;
311331
rockchip->pci.ops = &dw_pcie_ops;
312-
313-
pp = &rockchip->pci.pp;
314-
pp->ops = &rockchip_pcie_host_ops;
332+
rockchip->data = data;
315333

316334
ret = rockchip_pcie_resource_get(pdev, rockchip);
317335
if (ret)
@@ -347,10 +365,21 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
347365
if (ret)
348366
goto deinit_phy;
349367

350-
ret = dw_pcie_host_init(pp);
351-
if (!ret)
352-
return 0;
368+
switch (data->mode) {
369+
case DW_PCIE_RC_TYPE:
370+
ret = rockchip_pcie_configure_rc(rockchip);
371+
if (ret)
372+
goto deinit_clk;
373+
break;
374+
default:
375+
dev_err(dev, "INVALID device type %d\n", data->mode);
376+
ret = -EINVAL;
377+
goto deinit_clk;
378+
}
379+
380+
return 0;
353381

382+
deinit_clk:
354383
clk_bulk_disable_unprepare(rockchip->clk_cnt, rockchip->clks);
355384
deinit_phy:
356385
rockchip_pcie_phy_deinit(rockchip);
@@ -361,8 +390,15 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
361390
return ret;
362391
}
363392

393+
static const struct rockchip_pcie_of_data rockchip_pcie_rc_of_data_rk3568 = {
394+
.mode = DW_PCIE_RC_TYPE,
395+
};
396+
364397
static const struct of_device_id rockchip_pcie_of_match[] = {
365-
{ .compatible = "rockchip,rk3568-pcie", },
398+
{
399+
.compatible = "rockchip,rk3568-pcie",
400+
.data = &rockchip_pcie_rc_of_data_rk3568,
401+
},
366402
{},
367403
};
368404

0 commit comments

Comments
 (0)