Skip to content

Commit 652935b

Browse files
Mani-Sadhasivambjorn-helgaas
authored andcommitted
PCI: qcom: Use devm_clk_bulk_get_all() API
There is no need for the device drivers to validate the clocks defined in Devicetree. The validation should be performed by the DT schema and the drivers should just get all the clocks from DT. Right now the driver hardcodes the clock info and validates them against DT which is redundant. So use devm_clk_bulk_get_all() that just gets all the clocks defined in DT and get rid of all static clocks info from the driver. This simplifies the driver. Link: https://lore.kernel.org/linux-pci/[email protected] Signed-off-by: Manivannan Sadhasivam <[email protected]> Signed-off-by: Krzysztof Wilczyński <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]>
1 parent 1613e60 commit 652935b

File tree

1 file changed

+58
-119
lines changed

1 file changed

+58
-119
lines changed

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

Lines changed: 58 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -154,58 +154,56 @@
154154
#define QCOM_PCIE_LINK_SPEED_TO_BW(speed) \
155155
Mbps_to_icc(PCIE_SPEED2MBS_ENC(pcie_link_speed[speed]))
156156

157-
#define QCOM_PCIE_1_0_0_MAX_CLOCKS 4
158157
struct qcom_pcie_resources_1_0_0 {
159-
struct clk_bulk_data clks[QCOM_PCIE_1_0_0_MAX_CLOCKS];
158+
struct clk_bulk_data *clks;
159+
int num_clks;
160160
struct reset_control *core;
161161
struct regulator *vdda;
162162
};
163163

164-
#define QCOM_PCIE_2_1_0_MAX_CLOCKS 5
165164
#define QCOM_PCIE_2_1_0_MAX_RESETS 6
166165
#define QCOM_PCIE_2_1_0_MAX_SUPPLY 3
167166
struct qcom_pcie_resources_2_1_0 {
168-
struct clk_bulk_data clks[QCOM_PCIE_2_1_0_MAX_CLOCKS];
167+
struct clk_bulk_data *clks;
168+
int num_clks;
169169
struct reset_control_bulk_data resets[QCOM_PCIE_2_1_0_MAX_RESETS];
170170
int num_resets;
171171
struct regulator_bulk_data supplies[QCOM_PCIE_2_1_0_MAX_SUPPLY];
172172
};
173173

174-
#define QCOM_PCIE_2_3_2_MAX_CLOCKS 4
175174
#define QCOM_PCIE_2_3_2_MAX_SUPPLY 2
176175
struct qcom_pcie_resources_2_3_2 {
177-
struct clk_bulk_data clks[QCOM_PCIE_2_3_2_MAX_CLOCKS];
176+
struct clk_bulk_data *clks;
177+
int num_clks;
178178
struct regulator_bulk_data supplies[QCOM_PCIE_2_3_2_MAX_SUPPLY];
179179
};
180180

181-
#define QCOM_PCIE_2_3_3_MAX_CLOCKS 5
182181
#define QCOM_PCIE_2_3_3_MAX_RESETS 7
183182
struct qcom_pcie_resources_2_3_3 {
184-
struct clk_bulk_data clks[QCOM_PCIE_2_3_3_MAX_CLOCKS];
183+
struct clk_bulk_data *clks;
184+
int num_clks;
185185
struct reset_control_bulk_data rst[QCOM_PCIE_2_3_3_MAX_RESETS];
186186
};
187187

188-
#define QCOM_PCIE_2_4_0_MAX_CLOCKS 4
189188
#define QCOM_PCIE_2_4_0_MAX_RESETS 12
190189
struct qcom_pcie_resources_2_4_0 {
191-
struct clk_bulk_data clks[QCOM_PCIE_2_4_0_MAX_CLOCKS];
190+
struct clk_bulk_data *clks;
192191
int num_clks;
193192
struct reset_control_bulk_data resets[QCOM_PCIE_2_4_0_MAX_RESETS];
194193
int num_resets;
195194
};
196195

197-
#define QCOM_PCIE_2_7_0_MAX_CLOCKS 15
198196
#define QCOM_PCIE_2_7_0_MAX_SUPPLIES 2
199197
struct qcom_pcie_resources_2_7_0 {
200-
struct clk_bulk_data clks[QCOM_PCIE_2_7_0_MAX_CLOCKS];
198+
struct clk_bulk_data *clks;
201199
int num_clks;
202200
struct regulator_bulk_data supplies[QCOM_PCIE_2_7_0_MAX_SUPPLIES];
203201
struct reset_control *rst;
204202
};
205203

206-
#define QCOM_PCIE_2_9_0_MAX_CLOCKS 5
207204
struct qcom_pcie_resources_2_9_0 {
208-
struct clk_bulk_data clks[QCOM_PCIE_2_9_0_MAX_CLOCKS];
205+
struct clk_bulk_data *clks;
206+
int num_clks;
209207
struct reset_control *rst;
210208
};
211209

@@ -337,21 +335,11 @@ static int qcom_pcie_get_resources_2_1_0(struct qcom_pcie *pcie)
337335
if (ret)
338336
return ret;
339337

340-
res->clks[0].id = "iface";
341-
res->clks[1].id = "core";
342-
res->clks[2].id = "phy";
343-
res->clks[3].id = "aux";
344-
res->clks[4].id = "ref";
345-
346-
/* iface, core, phy are required */
347-
ret = devm_clk_bulk_get(dev, 3, res->clks);
348-
if (ret < 0)
349-
return ret;
350-
351-
/* aux, ref are optional */
352-
ret = devm_clk_bulk_get_optional(dev, 2, res->clks + 3);
353-
if (ret < 0)
354-
return ret;
338+
res->num_clks = devm_clk_bulk_get_all(dev, &res->clks);
339+
if (res->num_clks < 0) {
340+
dev_err(dev, "Failed to get clocks\n");
341+
return res->num_clks;
342+
}
355343

356344
res->resets[0].id = "pci";
357345
res->resets[1].id = "axi";
@@ -373,7 +361,7 @@ static void qcom_pcie_deinit_2_1_0(struct qcom_pcie *pcie)
373361
{
374362
struct qcom_pcie_resources_2_1_0 *res = &pcie->res.v2_1_0;
375363

376-
clk_bulk_disable_unprepare(ARRAY_SIZE(res->clks), res->clks);
364+
clk_bulk_disable_unprepare(res->num_clks, res->clks);
377365
reset_control_bulk_assert(res->num_resets, res->resets);
378366

379367
writel(1, pcie->parf + PARF_PHY_CTRL);
@@ -425,7 +413,7 @@ static int qcom_pcie_post_init_2_1_0(struct qcom_pcie *pcie)
425413
val &= ~PHY_TEST_PWR_DOWN;
426414
writel(val, pcie->parf + PARF_PHY_CTRL);
427415

428-
ret = clk_bulk_prepare_enable(ARRAY_SIZE(res->clks), res->clks);
416+
ret = clk_bulk_prepare_enable(res->num_clks, res->clks);
429417
if (ret)
430418
return ret;
431419

@@ -476,20 +464,16 @@ static int qcom_pcie_get_resources_1_0_0(struct qcom_pcie *pcie)
476464
struct qcom_pcie_resources_1_0_0 *res = &pcie->res.v1_0_0;
477465
struct dw_pcie *pci = pcie->pci;
478466
struct device *dev = pci->dev;
479-
int ret;
480467

481468
res->vdda = devm_regulator_get(dev, "vdda");
482469
if (IS_ERR(res->vdda))
483470
return PTR_ERR(res->vdda);
484471

485-
res->clks[0].id = "iface";
486-
res->clks[1].id = "aux";
487-
res->clks[2].id = "master_bus";
488-
res->clks[3].id = "slave_bus";
489-
490-
ret = devm_clk_bulk_get(dev, ARRAY_SIZE(res->clks), res->clks);
491-
if (ret < 0)
492-
return ret;
472+
res->num_clks = devm_clk_bulk_get_all(dev, &res->clks);
473+
if (res->num_clks < 0) {
474+
dev_err(dev, "Failed to get clocks\n");
475+
return res->num_clks;
476+
}
493477

494478
res->core = devm_reset_control_get_exclusive(dev, "core");
495479
return PTR_ERR_OR_ZERO(res->core);
@@ -500,7 +484,7 @@ static void qcom_pcie_deinit_1_0_0(struct qcom_pcie *pcie)
500484
struct qcom_pcie_resources_1_0_0 *res = &pcie->res.v1_0_0;
501485

502486
reset_control_assert(res->core);
503-
clk_bulk_disable_unprepare(ARRAY_SIZE(res->clks), res->clks);
487+
clk_bulk_disable_unprepare(res->num_clks, res->clks);
504488
regulator_disable(res->vdda);
505489
}
506490

@@ -517,7 +501,7 @@ static int qcom_pcie_init_1_0_0(struct qcom_pcie *pcie)
517501
return ret;
518502
}
519503

520-
ret = clk_bulk_prepare_enable(ARRAY_SIZE(res->clks), res->clks);
504+
ret = clk_bulk_prepare_enable(res->num_clks, res->clks);
521505
if (ret) {
522506
dev_err(dev, "cannot prepare/enable clocks\n");
523507
goto err_assert_reset;
@@ -532,7 +516,7 @@ static int qcom_pcie_init_1_0_0(struct qcom_pcie *pcie)
532516
return 0;
533517

534518
err_disable_clks:
535-
clk_bulk_disable_unprepare(ARRAY_SIZE(res->clks), res->clks);
519+
clk_bulk_disable_unprepare(res->num_clks, res->clks);
536520
err_assert_reset:
537521
reset_control_assert(res->core);
538522

@@ -580,14 +564,11 @@ static int qcom_pcie_get_resources_2_3_2(struct qcom_pcie *pcie)
580564
if (ret)
581565
return ret;
582566

583-
res->clks[0].id = "aux";
584-
res->clks[1].id = "cfg";
585-
res->clks[2].id = "bus_master";
586-
res->clks[3].id = "bus_slave";
587-
588-
ret = devm_clk_bulk_get(dev, ARRAY_SIZE(res->clks), res->clks);
589-
if (ret < 0)
590-
return ret;
567+
res->num_clks = devm_clk_bulk_get_all(dev, &res->clks);
568+
if (res->num_clks < 0) {
569+
dev_err(dev, "Failed to get clocks\n");
570+
return res->num_clks;
571+
}
591572

592573
return 0;
593574
}
@@ -596,7 +577,7 @@ static void qcom_pcie_deinit_2_3_2(struct qcom_pcie *pcie)
596577
{
597578
struct qcom_pcie_resources_2_3_2 *res = &pcie->res.v2_3_2;
598579

599-
clk_bulk_disable_unprepare(ARRAY_SIZE(res->clks), res->clks);
580+
clk_bulk_disable_unprepare(res->num_clks, res->clks);
600581
regulator_bulk_disable(ARRAY_SIZE(res->supplies), res->supplies);
601582
}
602583

@@ -613,7 +594,7 @@ static int qcom_pcie_init_2_3_2(struct qcom_pcie *pcie)
613594
return ret;
614595
}
615596

616-
ret = clk_bulk_prepare_enable(ARRAY_SIZE(res->clks), res->clks);
597+
ret = clk_bulk_prepare_enable(res->num_clks, res->clks);
617598
if (ret) {
618599
dev_err(dev, "cannot prepare/enable clocks\n");
619600
regulator_bulk_disable(ARRAY_SIZE(res->supplies), res->supplies);
@@ -661,17 +642,11 @@ static int qcom_pcie_get_resources_2_4_0(struct qcom_pcie *pcie)
661642
bool is_ipq = of_device_is_compatible(dev->of_node, "qcom,pcie-ipq4019");
662643
int ret;
663644

664-
res->clks[0].id = "aux";
665-
res->clks[1].id = "master_bus";
666-
res->clks[2].id = "slave_bus";
667-
res->clks[3].id = "iface";
668-
669-
/* qcom,pcie-ipq4019 is defined without "iface" */
670-
res->num_clks = is_ipq ? 3 : 4;
671-
672-
ret = devm_clk_bulk_get(dev, res->num_clks, res->clks);
673-
if (ret < 0)
674-
return ret;
645+
res->num_clks = devm_clk_bulk_get_all(dev, &res->clks);
646+
if (res->num_clks < 0) {
647+
dev_err(dev, "Failed to get clocks\n");
648+
return res->num_clks;
649+
}
675650

676651
res->resets[0].id = "axi_m";
677652
res->resets[1].id = "axi_s";
@@ -742,15 +717,11 @@ static int qcom_pcie_get_resources_2_3_3(struct qcom_pcie *pcie)
742717
struct device *dev = pci->dev;
743718
int ret;
744719

745-
res->clks[0].id = "iface";
746-
res->clks[1].id = "axi_m";
747-
res->clks[2].id = "axi_s";
748-
res->clks[3].id = "ahb";
749-
res->clks[4].id = "aux";
750-
751-
ret = devm_clk_bulk_get(dev, ARRAY_SIZE(res->clks), res->clks);
752-
if (ret < 0)
753-
return ret;
720+
res->num_clks = devm_clk_bulk_get_all(dev, &res->clks);
721+
if (res->num_clks < 0) {
722+
dev_err(dev, "Failed to get clocks\n");
723+
return res->num_clks;
724+
}
754725

755726
res->rst[0].id = "axi_m";
756727
res->rst[1].id = "axi_s";
@@ -771,7 +742,7 @@ static void qcom_pcie_deinit_2_3_3(struct qcom_pcie *pcie)
771742
{
772743
struct qcom_pcie_resources_2_3_3 *res = &pcie->res.v2_3_3;
773744

774-
clk_bulk_disable_unprepare(ARRAY_SIZE(res->clks), res->clks);
745+
clk_bulk_disable_unprepare(res->num_clks, res->clks);
775746
}
776747

777748
static int qcom_pcie_init_2_3_3(struct qcom_pcie *pcie)
@@ -801,7 +772,7 @@ static int qcom_pcie_init_2_3_3(struct qcom_pcie *pcie)
801772
*/
802773
usleep_range(2000, 2500);
803774

804-
ret = clk_bulk_prepare_enable(ARRAY_SIZE(res->clks), res->clks);
775+
ret = clk_bulk_prepare_enable(res->num_clks, res->clks);
805776
if (ret) {
806777
dev_err(dev, "cannot prepare/enable clocks\n");
807778
goto err_assert_resets;
@@ -862,8 +833,6 @@ static int qcom_pcie_get_resources_2_7_0(struct qcom_pcie *pcie)
862833
struct qcom_pcie_resources_2_7_0 *res = &pcie->res.v2_7_0;
863834
struct dw_pcie *pci = pcie->pci;
864835
struct device *dev = pci->dev;
865-
unsigned int num_clks, num_opt_clks;
866-
unsigned int idx;
867836
int ret;
868837

869838
res->rst = devm_reset_control_array_get_exclusive(dev);
@@ -877,36 +846,11 @@ static int qcom_pcie_get_resources_2_7_0(struct qcom_pcie *pcie)
877846
if (ret)
878847
return ret;
879848

880-
idx = 0;
881-
res->clks[idx++].id = "aux";
882-
res->clks[idx++].id = "cfg";
883-
res->clks[idx++].id = "bus_master";
884-
res->clks[idx++].id = "bus_slave";
885-
res->clks[idx++].id = "slave_q2a";
886-
887-
num_clks = idx;
888-
889-
ret = devm_clk_bulk_get(dev, num_clks, res->clks);
890-
if (ret < 0)
891-
return ret;
892-
893-
res->clks[idx++].id = "tbu";
894-
res->clks[idx++].id = "ddrss_sf_tbu";
895-
res->clks[idx++].id = "aggre0";
896-
res->clks[idx++].id = "aggre1";
897-
res->clks[idx++].id = "noc_aggr";
898-
res->clks[idx++].id = "noc_aggr_4";
899-
res->clks[idx++].id = "noc_aggr_south_sf";
900-
res->clks[idx++].id = "cnoc_qx";
901-
res->clks[idx++].id = "sleep";
902-
res->clks[idx++].id = "cnoc_sf_axi";
903-
904-
num_opt_clks = idx - num_clks;
905-
res->num_clks = idx;
906-
907-
ret = devm_clk_bulk_get_optional(dev, num_opt_clks, res->clks + num_clks);
908-
if (ret < 0)
909-
return ret;
849+
res->num_clks = devm_clk_bulk_get_all(dev, &res->clks);
850+
if (res->num_clks < 0) {
851+
dev_err(dev, "Failed to get clocks\n");
852+
return res->num_clks;
853+
}
910854

911855
return 0;
912856
}
@@ -1101,17 +1045,12 @@ static int qcom_pcie_get_resources_2_9_0(struct qcom_pcie *pcie)
11011045
struct qcom_pcie_resources_2_9_0 *res = &pcie->res.v2_9_0;
11021046
struct dw_pcie *pci = pcie->pci;
11031047
struct device *dev = pci->dev;
1104-
int ret;
1105-
1106-
res->clks[0].id = "iface";
1107-
res->clks[1].id = "axi_m";
1108-
res->clks[2].id = "axi_s";
1109-
res->clks[3].id = "axi_bridge";
1110-
res->clks[4].id = "rchng";
11111048

1112-
ret = devm_clk_bulk_get(dev, ARRAY_SIZE(res->clks), res->clks);
1113-
if (ret < 0)
1114-
return ret;
1049+
res->num_clks = devm_clk_bulk_get_all(dev, &res->clks);
1050+
if (res->num_clks < 0) {
1051+
dev_err(dev, "Failed to get clocks\n");
1052+
return res->num_clks;
1053+
}
11151054

11161055
res->rst = devm_reset_control_array_get_exclusive(dev);
11171056
if (IS_ERR(res->rst))
@@ -1124,7 +1063,7 @@ static void qcom_pcie_deinit_2_9_0(struct qcom_pcie *pcie)
11241063
{
11251064
struct qcom_pcie_resources_2_9_0 *res = &pcie->res.v2_9_0;
11261065

1127-
clk_bulk_disable_unprepare(ARRAY_SIZE(res->clks), res->clks);
1066+
clk_bulk_disable_unprepare(res->num_clks, res->clks);
11281067
}
11291068

11301069
static int qcom_pcie_init_2_9_0(struct qcom_pcie *pcie)
@@ -1153,7 +1092,7 @@ static int qcom_pcie_init_2_9_0(struct qcom_pcie *pcie)
11531092

11541093
usleep_range(2000, 2500);
11551094

1156-
return clk_bulk_prepare_enable(ARRAY_SIZE(res->clks), res->clks);
1095+
return clk_bulk_prepare_enable(res->num_clks, res->clks);
11571096
}
11581097

11591098
static int qcom_pcie_post_init_2_9_0(struct qcom_pcie *pcie)

0 commit comments

Comments
 (0)