[PATCH 03/14] staging: clocking-wizard: Split probe function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Split probe function so that we can add more code in future patches
without it becoming too big.

Signed-off-by: James Kelly <jamespeterkelly@xxxxxxxxx>
---
 .../clocking-wizard/clk-xlnx-clock-wizard.c        | 63 +++++++++++++++++-----
 1 file changed, 51 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/clocking-wizard/clk-xlnx-clock-wizard.c b/drivers/staging/clocking-wizard/clk-xlnx-clock-wizard.c
index 1d42eabdd956..4dec1bfc303a 100644
--- a/drivers/staging/clocking-wizard/clk-xlnx-clock-wizard.c
+++ b/drivers/staging/clocking-wizard/clk-xlnx-clock-wizard.c
@@ -180,14 +180,12 @@ static int __maybe_unused clk_wzrd_resume(struct device *dev)
 static SIMPLE_DEV_PM_OPS(clk_wzrd_dev_pm_ops, clk_wzrd_suspend,
 			 clk_wzrd_resume);
 
-static int clk_wzrd_probe(struct platform_device *pdev)
+static int clk_wzrd_get_device_tree_data(struct device *dev)
 {
-	int i, ret;
-	u32 reg;
+	int ret;
 	unsigned long rate;
-	const char *clk_name;
 	struct clk_wzrd *clk_wzrd;
-	struct resource *mem;
+	struct platform_device *pdev = to_platform_device(dev);
 	struct device_node *np = pdev->dev.of_node;
 
 	clk_wzrd = devm_kzalloc(&pdev->dev, sizeof(*clk_wzrd), GFP_KERNEL);
@@ -195,11 +193,6 @@ static int clk_wzrd_probe(struct platform_device *pdev)
 		return -ENOMEM;
 	platform_set_drvdata(pdev, clk_wzrd);
 
-	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	clk_wzrd->base = devm_ioremap_resource(&pdev->dev, mem);
-	if (IS_ERR(clk_wzrd->base))
-		return PTR_ERR(clk_wzrd->base);
-
 	ret = of_property_read_u32(np, "speed-grade", &clk_wzrd->speed_grade);
 	if (!ret) {
 		if (clk_wzrd->speed_grade < 1 || clk_wzrd->speed_grade > 3) {
@@ -231,10 +224,36 @@ static int clk_wzrd_probe(struct platform_device *pdev)
 	if (rate > WZRD_ACLK_MAX_FREQ) {
 		dev_err(&pdev->dev, "s_axi_aclk frequency (%lu) too high\n",
 			rate);
-		ret = -EINVAL;
-		goto err_disable_clk;
+		clk_disable_unprepare(clk_wzrd->axi_clk);
+		return -EINVAL;
 	}
 
+	return 0;
+}
+
+static int clk_wzrd_regmap_alloc(struct device *dev)
+{
+	struct resource *mem;
+	struct clk_wzrd *clk_wzrd = dev_get_drvdata(dev);
+	struct platform_device *pdev = to_platform_device(dev);
+
+	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	clk_wzrd->base = devm_ioremap_resource(&pdev->dev, mem);
+	if (IS_ERR(clk_wzrd->base))
+		return PTR_ERR(clk_wzrd->base);
+
+	return 0;
+}
+
+static int clk_wzrd_register_ccf(struct device *dev)
+{
+	int i, ret;
+	u32 reg;
+	const char *clk_name;
+	struct platform_device *pdev = to_platform_device(dev);
+	struct clk_wzrd *clk_wzrd = dev_get_drvdata(dev);
+	struct device_node *np = pdev->dev.of_node;
+
 	/* we don't support fractional div/mul yet */
 	reg = readl(clk_wzrd->base + WZRD_CLK_CFG_REG(0)) &
 		    WZRD_CLKFBOUT_FRAC_EN;
@@ -342,6 +361,26 @@ static int clk_wzrd_probe(struct platform_device *pdev)
 	return ret;
 }
 
+static int clk_wzrd_probe(struct platform_device *pdev)
+{
+	int ret;
+	struct device *dev = &pdev->dev;
+
+	ret = clk_wzrd_get_device_tree_data(dev);
+	if (ret)
+		return ret;
+
+	ret = clk_wzrd_regmap_alloc(dev);
+	if (ret)
+		return ret;
+
+	ret = clk_wzrd_register_ccf(dev);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
 static int clk_wzrd_remove(struct platform_device *pdev)
 {
 	int i;
-- 
2.15.1 (Apple Git-101)

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel



[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux