Skip to content

Commit abdd4c8

Browse files
moonlinuxbjorn-helgaas
authored andcommitted
PCI: rockchip: Simplify clock handling by using clk_bulk*() functions
Currently, the driver acquires clocks and prepare/enable/disable/unprepare the clocks individually thereby making the driver complex to read. The driver can be simplified by using the clk_bulk*() APIs. Use: - devm_clk_bulk_get_all() API to acquire all the clocks - clk_bulk_prepare_enable() to prepare/enable clocks - clk_bulk_disable_unprepare() APIs to disable/unprepare them in bulk Link: https://lore.kernel.org/r/20241202151150.7393-2-linux.amoon@gmail.com Signed-off-by: Anand Moon <linux.amoon@gmail.com> Signed-off-by: Lorenzo Pieralisi <lpieralisi@kernel.org> [bhelgaas: squash error handling fix from https://lore.kernel.org/r/20250106153041.55267-1-linux.amoon@gmail.com] Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
1 parent fd46bc0 commit abdd4c8

File tree

2 files changed

+11
-62
lines changed

2 files changed

+11
-62
lines changed

drivers/pci/controller/pcie-rockchip.c

Lines changed: 8 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -129,29 +129,10 @@ int rockchip_pcie_parse_dt(struct rockchip_pcie *rockchip)
129129
return dev_err_probe(dev, PTR_ERR(rockchip->perst_gpio),
130130
"failed to get PERST# GPIO\n");
131131

132-
rockchip->aclk_pcie = devm_clk_get(dev, "aclk");
133-
if (IS_ERR(rockchip->aclk_pcie)) {
134-
dev_err(dev, "aclk clock not found\n");
135-
return PTR_ERR(rockchip->aclk_pcie);
136-
}
137-
138-
rockchip->aclk_perf_pcie = devm_clk_get(dev, "aclk-perf");
139-
if (IS_ERR(rockchip->aclk_perf_pcie)) {
140-
dev_err(dev, "aclk_perf clock not found\n");
141-
return PTR_ERR(rockchip->aclk_perf_pcie);
142-
}
143-
144-
rockchip->hclk_pcie = devm_clk_get(dev, "hclk");
145-
if (IS_ERR(rockchip->hclk_pcie)) {
146-
dev_err(dev, "hclk clock not found\n");
147-
return PTR_ERR(rockchip->hclk_pcie);
148-
}
149-
150-
rockchip->clk_pcie_pm = devm_clk_get(dev, "pm");
151-
if (IS_ERR(rockchip->clk_pcie_pm)) {
152-
dev_err(dev, "pm clock not found\n");
153-
return PTR_ERR(rockchip->clk_pcie_pm);
154-
}
132+
rockchip->num_clks = devm_clk_bulk_get_all(dev, &rockchip->clks);
133+
if (rockchip->num_clks < 0)
134+
return dev_err_probe(dev, rockchip->num_clks,
135+
"failed to get clocks\n");
155136

156137
return 0;
157138
}
@@ -375,50 +356,19 @@ int rockchip_pcie_enable_clocks(struct rockchip_pcie *rockchip)
375356
struct device *dev = rockchip->dev;
376357
int err;
377358

378-
err = clk_prepare_enable(rockchip->aclk_pcie);
379-
if (err) {
380-
dev_err(dev, "unable to enable aclk_pcie clock\n");
381-
return err;
382-
}
383-
384-
err = clk_prepare_enable(rockchip->aclk_perf_pcie);
385-
if (err) {
386-
dev_err(dev, "unable to enable aclk_perf_pcie clock\n");
387-
goto err_aclk_perf_pcie;
388-
}
389-
390-
err = clk_prepare_enable(rockchip->hclk_pcie);
391-
if (err) {
392-
dev_err(dev, "unable to enable hclk_pcie clock\n");
393-
goto err_hclk_pcie;
394-
}
395-
396-
err = clk_prepare_enable(rockchip->clk_pcie_pm);
397-
if (err) {
398-
dev_err(dev, "unable to enable clk_pcie_pm clock\n");
399-
goto err_clk_pcie_pm;
400-
}
359+
err = clk_bulk_prepare_enable(rockchip->num_clks, rockchip->clks);
360+
if (err)
361+
return dev_err_probe(dev, err, "failed to enable clocks\n");
401362

402363
return 0;
403-
404-
err_clk_pcie_pm:
405-
clk_disable_unprepare(rockchip->hclk_pcie);
406-
err_hclk_pcie:
407-
clk_disable_unprepare(rockchip->aclk_perf_pcie);
408-
err_aclk_perf_pcie:
409-
clk_disable_unprepare(rockchip->aclk_pcie);
410-
return err;
411364
}
412365
EXPORT_SYMBOL_GPL(rockchip_pcie_enable_clocks);
413366

414367
void rockchip_pcie_disable_clocks(void *data)
415368
{
416369
struct rockchip_pcie *rockchip = data;
417370

418-
clk_disable_unprepare(rockchip->clk_pcie_pm);
419-
clk_disable_unprepare(rockchip->hclk_pcie);
420-
clk_disable_unprepare(rockchip->aclk_perf_pcie);
421-
clk_disable_unprepare(rockchip->aclk_pcie);
371+
clk_bulk_disable_unprepare(rockchip->num_clks, rockchip->clks);
422372
}
423373
EXPORT_SYMBOL_GPL(rockchip_pcie_disable_clocks);
424374

drivers/pci/controller/pcie-rockchip.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#ifndef _PCIE_ROCKCHIP_H
1212
#define _PCIE_ROCKCHIP_H
1313

14+
#include <linux/clk.h>
1415
#include <linux/kernel.h>
1516
#include <linux/pci.h>
1617
#include <linux/pci-ecam.h>
@@ -321,10 +322,8 @@ struct rockchip_pcie {
321322
struct reset_control *pm_rst;
322323
struct reset_control *aclk_rst;
323324
struct reset_control *pclk_rst;
324-
struct clk *aclk_pcie;
325-
struct clk *aclk_perf_pcie;
326-
struct clk *hclk_pcie;
327-
struct clk *clk_pcie_pm;
325+
struct clk_bulk_data *clks;
326+
int num_clks;
328327
struct regulator *vpcie12v; /* 12V power supply */
329328
struct regulator *vpcie3v3; /* 3.3V power supply */
330329
struct regulator *vpcie1v8; /* 1.8V power supply */

0 commit comments

Comments
 (0)