Skip to content

Commit ad49cd4

Browse files
committed
Merge branch 'pci/controller/imx6'
- Identify the second controller on i.MX8MQ based on devicetree 'linux,pci-domain' instead of DBI 'reg' address (Richard Zhu) - Use devm_clk_bulk_get_all() to fetch clocks to simplify the code (Richard Zhu) * pci/controller/imx6: PCI: imx6: Use devm_clk_bulk_get_all() to fetch clocks PCI: imx6: Identify controller via 'linux,pci-domain', not address
2 parents 8c6dadf + f6a1fdf commit ad49cd4

File tree

1 file changed

+19
-69
lines changed

1 file changed

+19
-69
lines changed

drivers/pci/controller/dwc/pci-imx6.c

Lines changed: 19 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
#define IMX8MQ_GPR_PCIE_CLK_REQ_OVERRIDE BIT(11)
4242
#define IMX8MQ_GPR_PCIE_VREG_BYPASS BIT(12)
4343
#define IMX8MQ_GPR12_PCIE2_CTRL_DEVICE_TYPE GENMASK(11, 8)
44-
#define IMX8MQ_PCIE2_BASE_ADDR 0x33c00000
4544

4645
#define IMX95_PCIE_PHY_GEN_CTRL 0x0
4746
#define IMX95_PCIE_REF_USE_PAD BIT(17)
@@ -109,7 +108,6 @@ enum imx_pcie_variants {
109108

110109
#define imx_check_flag(pci, val) (pci->drvdata->flags & val)
111110

112-
#define IMX_PCIE_MAX_CLKS 6
113111
#define IMX_PCIE_MAX_INSTANCES 2
114112

115113
struct imx_pcie;
@@ -120,9 +118,6 @@ struct imx_pcie_drvdata {
120118
u32 flags;
121119
int dbi_length;
122120
const char *gpr;
123-
const char * const *clk_names;
124-
const u32 clks_cnt;
125-
const u32 clks_optional_cnt;
126121
const u32 ltssm_off;
127122
const u32 ltssm_mask;
128123
const u32 mode_off[IMX_PCIE_MAX_INSTANCES];
@@ -137,7 +132,8 @@ struct imx_pcie_drvdata {
137132
struct imx_pcie {
138133
struct dw_pcie *pci;
139134
struct gpio_desc *reset_gpiod;
140-
struct clk_bulk_data clks[IMX_PCIE_MAX_CLKS];
135+
struct clk_bulk_data *clks;
136+
int num_clks;
141137
struct regmap *iomuxc_gpr;
142138
u16 msi_ctrl;
143139
u32 controller_id;
@@ -470,13 +466,14 @@ static int imx_setup_phy_mpll(struct imx_pcie *imx_pcie)
470466
int mult, div;
471467
u16 val;
472468
int i;
469+
struct clk_bulk_data *clks = imx_pcie->clks;
473470

474471
if (!(imx_pcie->drvdata->flags & IMX_PCIE_FLAG_IMX_PHY))
475472
return 0;
476473

477-
for (i = 0; i < imx_pcie->drvdata->clks_cnt; i++)
478-
if (strncmp(imx_pcie->clks[i].id, "pcie_phy", 8) == 0)
479-
phy_rate = clk_get_rate(imx_pcie->clks[i].clk);
474+
for (i = 0; i < imx_pcie->num_clks; i++)
475+
if (strncmp(clks[i].id, "pcie_phy", 8) == 0)
476+
phy_rate = clk_get_rate(clks[i].clk);
480477

481478
switch (phy_rate) {
482479
case 125000000:
@@ -668,7 +665,7 @@ static int imx_pcie_clk_enable(struct imx_pcie *imx_pcie)
668665
struct device *dev = pci->dev;
669666
int ret;
670667

671-
ret = clk_bulk_prepare_enable(imx_pcie->drvdata->clks_cnt, imx_pcie->clks);
668+
ret = clk_bulk_prepare_enable(imx_pcie->num_clks, imx_pcie->clks);
672669
if (ret)
673670
return ret;
674671

@@ -685,7 +682,7 @@ static int imx_pcie_clk_enable(struct imx_pcie *imx_pcie)
685682
return 0;
686683

687684
err_ref_clk:
688-
clk_bulk_disable_unprepare(imx_pcie->drvdata->clks_cnt, imx_pcie->clks);
685+
clk_bulk_disable_unprepare(imx_pcie->num_clks, imx_pcie->clks);
689686

690687
return ret;
691688
}
@@ -694,7 +691,7 @@ static void imx_pcie_clk_disable(struct imx_pcie *imx_pcie)
694691
{
695692
if (imx_pcie->drvdata->enable_ref_clk)
696693
imx_pcie->drvdata->enable_ref_clk(imx_pcie, false);
697-
clk_bulk_disable_unprepare(imx_pcie->drvdata->clks_cnt, imx_pcie->clks);
694+
clk_bulk_disable_unprepare(imx_pcie->num_clks, imx_pcie->clks);
698695
}
699696

700697
static int imx6sx_pcie_core_reset(struct imx_pcie *imx_pcie, bool assert)
@@ -1474,9 +1471,8 @@ static int imx_pcie_probe(struct platform_device *pdev)
14741471
struct dw_pcie *pci;
14751472
struct imx_pcie *imx_pcie;
14761473
struct device_node *np;
1477-
struct resource *dbi_base;
14781474
struct device_node *node = dev->of_node;
1479-
int i, ret, req_cnt;
1475+
int ret, domain;
14801476
u16 val;
14811477

14821478
imx_pcie = devm_kzalloc(dev, sizeof(*imx_pcie), GFP_KERNEL);
@@ -1515,31 +1511,18 @@ static int imx_pcie_probe(struct platform_device *pdev)
15151511
return PTR_ERR(imx_pcie->phy_base);
15161512
}
15171513

1518-
pci->dbi_base = devm_platform_get_and_ioremap_resource(pdev, 0, &dbi_base);
1519-
if (IS_ERR(pci->dbi_base))
1520-
return PTR_ERR(pci->dbi_base);
1521-
15221514
/* Fetch GPIOs */
15231515
imx_pcie->reset_gpiod = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
15241516
if (IS_ERR(imx_pcie->reset_gpiod))
15251517
return dev_err_probe(dev, PTR_ERR(imx_pcie->reset_gpiod),
15261518
"unable to get reset gpio\n");
15271519
gpiod_set_consumer_name(imx_pcie->reset_gpiod, "PCIe reset");
15281520

1529-
if (imx_pcie->drvdata->clks_cnt >= IMX_PCIE_MAX_CLKS)
1530-
return dev_err_probe(dev, -ENOMEM, "clks_cnt is too big\n");
1531-
1532-
for (i = 0; i < imx_pcie->drvdata->clks_cnt; i++)
1533-
imx_pcie->clks[i].id = imx_pcie->drvdata->clk_names[i];
1534-
15351521
/* Fetch clocks */
1536-
req_cnt = imx_pcie->drvdata->clks_cnt - imx_pcie->drvdata->clks_optional_cnt;
1537-
ret = devm_clk_bulk_get(dev, req_cnt, imx_pcie->clks);
1538-
if (ret)
1539-
return ret;
1540-
imx_pcie->clks[req_cnt].clk = devm_clk_get_optional(dev, "ref");
1541-
if (IS_ERR(imx_pcie->clks[req_cnt].clk))
1542-
return PTR_ERR(imx_pcie->clks[req_cnt].clk);
1522+
imx_pcie->num_clks = devm_clk_bulk_get_all(dev, &imx_pcie->clks);
1523+
if (imx_pcie->num_clks < 0)
1524+
return dev_err_probe(dev, imx_pcie->num_clks,
1525+
"failed to get clocks\n");
15431526

15441527
if (imx_check_flag(imx_pcie, IMX_PCIE_FLAG_HAS_PHYDRV)) {
15451528
imx_pcie->phy = devm_phy_get(dev, "pcie-phy");
@@ -1565,8 +1548,11 @@ static int imx_pcie_probe(struct platform_device *pdev)
15651548
switch (imx_pcie->drvdata->variant) {
15661549
case IMX8MQ:
15671550
case IMX8MQ_EP:
1568-
if (dbi_base->start == IMX8MQ_PCIE2_BASE_ADDR)
1569-
imx_pcie->controller_id = 1;
1551+
domain = of_get_pci_domain_nr(node);
1552+
if (domain < 0 || domain > 1)
1553+
return dev_err_probe(dev, -ENODEV, "no \"linux,pci-domain\" property in devicetree\n");
1554+
1555+
imx_pcie->controller_id = domain;
15701556
break;
15711557
default:
15721558
break;
@@ -1675,13 +1661,6 @@ static void imx_pcie_shutdown(struct platform_device *pdev)
16751661
imx_pcie_assert_core_reset(imx_pcie);
16761662
}
16771663

1678-
static const char * const imx6q_clks[] = {"pcie_bus", "pcie", "pcie_phy"};
1679-
static const char * const imx8mm_clks[] = {"pcie_bus", "pcie", "pcie_aux"};
1680-
static const char * const imx8mq_clks[] = {"pcie_bus", "pcie", "pcie_phy", "pcie_aux"};
1681-
static const char * const imx6sx_clks[] = {"pcie_bus", "pcie", "pcie_phy", "pcie_inbound_axi"};
1682-
static const char * const imx8q_clks[] = {"mstr", "slv", "dbi"};
1683-
static const char * const imx95_clks[] = {"pcie_bus", "pcie", "pcie_phy", "pcie_aux", "ref"};
1684-
16851664
static const struct imx_pcie_drvdata drvdata[] = {
16861665
[IMX6Q] = {
16871666
.variant = IMX6Q,
@@ -1691,8 +1670,6 @@ static const struct imx_pcie_drvdata drvdata[] = {
16911670
IMX_PCIE_FLAG_SUPPORTS_SUSPEND,
16921671
.dbi_length = 0x200,
16931672
.gpr = "fsl,imx6q-iomuxc-gpr",
1694-
.clk_names = imx6q_clks,
1695-
.clks_cnt = ARRAY_SIZE(imx6q_clks),
16961673
.ltssm_off = IOMUXC_GPR12,
16971674
.ltssm_mask = IMX6Q_GPR12_PCIE_CTL_2,
16981675
.mode_off[0] = IOMUXC_GPR12,
@@ -1707,8 +1684,6 @@ static const struct imx_pcie_drvdata drvdata[] = {
17071684
IMX_PCIE_FLAG_IMX_SPEED_CHANGE |
17081685
IMX_PCIE_FLAG_SUPPORTS_SUSPEND,
17091686
.gpr = "fsl,imx6q-iomuxc-gpr",
1710-
.clk_names = imx6sx_clks,
1711-
.clks_cnt = ARRAY_SIZE(imx6sx_clks),
17121687
.ltssm_off = IOMUXC_GPR12,
17131688
.ltssm_mask = IMX6Q_GPR12_PCIE_CTL_2,
17141689
.mode_off[0] = IOMUXC_GPR12,
@@ -1725,8 +1700,6 @@ static const struct imx_pcie_drvdata drvdata[] = {
17251700
IMX_PCIE_FLAG_SUPPORTS_SUSPEND,
17261701
.dbi_length = 0x200,
17271702
.gpr = "fsl,imx6q-iomuxc-gpr",
1728-
.clk_names = imx6q_clks,
1729-
.clks_cnt = ARRAY_SIZE(imx6q_clks),
17301703
.ltssm_off = IOMUXC_GPR12,
17311704
.ltssm_mask = IMX6Q_GPR12_PCIE_CTL_2,
17321705
.mode_off[0] = IOMUXC_GPR12,
@@ -1742,8 +1715,6 @@ static const struct imx_pcie_drvdata drvdata[] = {
17421715
IMX_PCIE_FLAG_HAS_APP_RESET |
17431716
IMX_PCIE_FLAG_HAS_PHY_RESET,
17441717
.gpr = "fsl,imx7d-iomuxc-gpr",
1745-
.clk_names = imx6q_clks,
1746-
.clks_cnt = ARRAY_SIZE(imx6q_clks),
17471718
.mode_off[0] = IOMUXC_GPR12,
17481719
.mode_mask[0] = IMX6Q_GPR12_DEVICE_TYPE,
17491720
.enable_ref_clk = imx7d_pcie_enable_ref_clk,
@@ -1755,8 +1726,6 @@ static const struct imx_pcie_drvdata drvdata[] = {
17551726
IMX_PCIE_FLAG_HAS_PHY_RESET |
17561727
IMX_PCIE_FLAG_SUPPORTS_SUSPEND,
17571728
.gpr = "fsl,imx8mq-iomuxc-gpr",
1758-
.clk_names = imx8mq_clks,
1759-
.clks_cnt = ARRAY_SIZE(imx8mq_clks),
17601729
.mode_off[0] = IOMUXC_GPR12,
17611730
.mode_mask[0] = IMX6Q_GPR12_DEVICE_TYPE,
17621731
.mode_off[1] = IOMUXC_GPR12,
@@ -1770,8 +1739,6 @@ static const struct imx_pcie_drvdata drvdata[] = {
17701739
IMX_PCIE_FLAG_HAS_PHYDRV |
17711740
IMX_PCIE_FLAG_HAS_APP_RESET,
17721741
.gpr = "fsl,imx8mm-iomuxc-gpr",
1773-
.clk_names = imx8mm_clks,
1774-
.clks_cnt = ARRAY_SIZE(imx8mm_clks),
17751742
.mode_off[0] = IOMUXC_GPR12,
17761743
.mode_mask[0] = IMX6Q_GPR12_DEVICE_TYPE,
17771744
.enable_ref_clk = imx8mm_pcie_enable_ref_clk,
@@ -1782,8 +1749,6 @@ static const struct imx_pcie_drvdata drvdata[] = {
17821749
IMX_PCIE_FLAG_HAS_PHYDRV |
17831750
IMX_PCIE_FLAG_HAS_APP_RESET,
17841751
.gpr = "fsl,imx8mp-iomuxc-gpr",
1785-
.clk_names = imx8mm_clks,
1786-
.clks_cnt = ARRAY_SIZE(imx8mm_clks),
17871752
.mode_off[0] = IOMUXC_GPR12,
17881753
.mode_mask[0] = IMX6Q_GPR12_DEVICE_TYPE,
17891754
.enable_ref_clk = imx8mm_pcie_enable_ref_clk,
@@ -1793,17 +1758,12 @@ static const struct imx_pcie_drvdata drvdata[] = {
17931758
.flags = IMX_PCIE_FLAG_HAS_PHYDRV |
17941759
IMX_PCIE_FLAG_CPU_ADDR_FIXUP |
17951760
IMX_PCIE_FLAG_SUPPORTS_SUSPEND,
1796-
.clk_names = imx8q_clks,
1797-
.clks_cnt = ARRAY_SIZE(imx8q_clks),
17981761
},
17991762
[IMX95] = {
18001763
.variant = IMX95,
18011764
.flags = IMX_PCIE_FLAG_HAS_SERDES |
18021765
IMX_PCIE_FLAG_HAS_LUT |
18031766
IMX_PCIE_FLAG_SUPPORTS_SUSPEND,
1804-
.clk_names = imx95_clks,
1805-
.clks_cnt = ARRAY_SIZE(imx95_clks),
1806-
.clks_optional_cnt = 1,
18071767
.ltssm_off = IMX95_PE0_GEN_CTRL_3,
18081768
.ltssm_mask = IMX95_PCIE_LTSSM_EN,
18091769
.mode_off[0] = IMX95_PE0_GEN_CTRL_1,
@@ -1816,8 +1776,6 @@ static const struct imx_pcie_drvdata drvdata[] = {
18161776
IMX_PCIE_FLAG_HAS_PHY_RESET,
18171777
.mode = DW_PCIE_EP_TYPE,
18181778
.gpr = "fsl,imx8mq-iomuxc-gpr",
1819-
.clk_names = imx8mq_clks,
1820-
.clks_cnt = ARRAY_SIZE(imx8mq_clks),
18211779
.mode_off[0] = IOMUXC_GPR12,
18221780
.mode_mask[0] = IMX6Q_GPR12_DEVICE_TYPE,
18231781
.mode_off[1] = IOMUXC_GPR12,
@@ -1832,8 +1790,6 @@ static const struct imx_pcie_drvdata drvdata[] = {
18321790
IMX_PCIE_FLAG_HAS_PHYDRV,
18331791
.mode = DW_PCIE_EP_TYPE,
18341792
.gpr = "fsl,imx8mm-iomuxc-gpr",
1835-
.clk_names = imx8mm_clks,
1836-
.clks_cnt = ARRAY_SIZE(imx8mm_clks),
18371793
.mode_off[0] = IOMUXC_GPR12,
18381794
.mode_mask[0] = IMX6Q_GPR12_DEVICE_TYPE,
18391795
.epc_features = &imx8m_pcie_epc_features,
@@ -1845,8 +1801,6 @@ static const struct imx_pcie_drvdata drvdata[] = {
18451801
IMX_PCIE_FLAG_HAS_PHYDRV,
18461802
.mode = DW_PCIE_EP_TYPE,
18471803
.gpr = "fsl,imx8mp-iomuxc-gpr",
1848-
.clk_names = imx8mm_clks,
1849-
.clks_cnt = ARRAY_SIZE(imx8mm_clks),
18501804
.mode_off[0] = IOMUXC_GPR12,
18511805
.mode_mask[0] = IMX6Q_GPR12_DEVICE_TYPE,
18521806
.epc_features = &imx8m_pcie_epc_features,
@@ -1857,15 +1811,11 @@ static const struct imx_pcie_drvdata drvdata[] = {
18571811
.flags = IMX_PCIE_FLAG_HAS_PHYDRV,
18581812
.mode = DW_PCIE_EP_TYPE,
18591813
.epc_features = &imx8q_pcie_epc_features,
1860-
.clk_names = imx8q_clks,
1861-
.clks_cnt = ARRAY_SIZE(imx8q_clks),
18621814
},
18631815
[IMX95_EP] = {
18641816
.variant = IMX95_EP,
18651817
.flags = IMX_PCIE_FLAG_HAS_SERDES |
18661818
IMX_PCIE_FLAG_SUPPORT_64BIT,
1867-
.clk_names = imx8mq_clks,
1868-
.clks_cnt = ARRAY_SIZE(imx8mq_clks),
18691819
.ltssm_off = IMX95_PE0_GEN_CTRL_3,
18701820
.ltssm_mask = IMX95_PCIE_LTSSM_EN,
18711821
.mode_off[0] = IMX95_PE0_GEN_CTRL_1,

0 commit comments

Comments
 (0)