Do some cosmetic cleanups before we start adding lots of code.

- Shorten clk_wzrd identifier to cw to keep lines short
- Replace &pdev->dev with dev to keep lines short
- Remove convenience variable np as it was only used once in function
- Add some tabs to make clk_wzrd structure definitions easier to read
- Use #define for clock names in case we want to change them later

Signed-off-by: James Kelly <jamespeterke...@gmail.com>
---
 .../clocking-wizard/clk-xlnx-clock-wizard.c        | 210 ++++++++++-----------
 1 file changed, 105 insertions(+), 105 deletions(-)

diff --git a/drivers/staging/clocking-wizard/clk-xlnx-clock-wizard.c 
b/drivers/staging/clocking-wizard/clk-xlnx-clock-wizard.c
index 4dec1bfc303a..3b66ac3b5ed0 100644
--- a/drivers/staging/clocking-wizard/clk-xlnx-clock-wizard.c
+++ b/drivers/staging/clocking-wizard/clk-xlnx-clock-wizard.c
@@ -70,6 +70,8 @@
 
 #define WZRD_NUM_OUTPUTS       7
 #define WZRD_ACLK_MAX_FREQ     250000000UL
+#define WZRD_CLKNAME_AXI       "s_axi_aclk"
+#define WZRD_CLKNAME_IN1       "clk_in1"
 
 #define WZRD_CLK_CFG_REG(n)    (0x200 + 4 * (n))
 
@@ -102,15 +104,15 @@ enum clk_wzrd_int_clks {
  * @suspended:         Flag indicating power state of the device
  */
 struct clk_wzrd {
-       struct clk_onecell_data clk_data;
-       struct notifier_block nb;
-       void __iomem *base;
-       struct clk *clk_in1;
-       struct clk *axi_clk;
-       struct clk *clks_internal[wzrd_clk_int_max];
-       struct clk *clkout[WZRD_NUM_OUTPUTS];
-       unsigned int speed_grade;
-       bool suspended;
+       struct clk_onecell_data         clk_data;
+       struct notifier_block           nb;
+       void __iomem                    *base;
+       struct clk                      *clk_in1;
+       struct clk                      *axi_clk;
+       struct clk                      *clks_internal[wzrd_clk_int_max];
+       struct clk                      *clkout[WZRD_NUM_OUTPUTS];
+       unsigned int                    speed_grade;
+       bool                            suspended;
 };
 
 #define to_clk_wzrd(_nb) container_of(_nb, struct clk_wzrd, nb)
@@ -127,14 +129,14 @@ static int clk_wzrd_clk_notifier(struct notifier_block 
*nb, unsigned long event,
 {
        unsigned long max;
        struct clk_notifier_data *ndata = data;
-       struct clk_wzrd *clk_wzrd = to_clk_wzrd(nb);
+       struct clk_wzrd *cw = to_clk_wzrd(nb);
 
-       if (clk_wzrd->suspended)
+       if (cw->suspended)
                return NOTIFY_OK;
 
-       if (ndata->clk == clk_wzrd->clk_in1)
-               max = clk_wzrd_max_freq[clk_wzrd->speed_grade - 1];
-       else if (ndata->clk == clk_wzrd->axi_clk)
+       if (ndata->clk == cw->clk_in1)
+               max = clk_wzrd_max_freq[cw->speed_grade - 1];
+       else if (ndata->clk == cw->axi_clk)
                max = WZRD_ACLK_MAX_FREQ;
        else
                return NOTIFY_DONE;     /* should never happen */
@@ -153,10 +155,10 @@ static int clk_wzrd_clk_notifier(struct notifier_block 
*nb, unsigned long event,
 
 static int __maybe_unused clk_wzrd_suspend(struct device *dev)
 {
-       struct clk_wzrd *clk_wzrd = dev_get_drvdata(dev);
+       struct clk_wzrd *cw = dev_get_drvdata(dev);
 
-       clk_disable_unprepare(clk_wzrd->axi_clk);
-       clk_wzrd->suspended = true;
+       clk_disable_unprepare(cw->axi_clk);
+       cw->suspended = true;
 
        return 0;
 }
@@ -164,15 +166,15 @@ static int __maybe_unused clk_wzrd_suspend(struct device 
*dev)
 static int __maybe_unused clk_wzrd_resume(struct device *dev)
 {
        int ret;
-       struct clk_wzrd *clk_wzrd = dev_get_drvdata(dev);
+       struct clk_wzrd *cw = dev_get_drvdata(dev);
 
-       ret = clk_prepare_enable(clk_wzrd->axi_clk);
+       ret = clk_prepare_enable(cw->axi_clk);
        if (ret) {
                dev_err(dev, "unable to enable s_axi_aclk\n");
                return ret;
        }
 
-       clk_wzrd->suspended = false;
+       cw->suspended = false;
 
        return 0;
 }
@@ -184,47 +186,46 @@ static int clk_wzrd_get_device_tree_data(struct device 
*dev)
 {
        int ret;
        unsigned long rate;
-       struct clk_wzrd *clk_wzrd;
-       struct platform_device *pdev = to_platform_device(dev);
-       struct device_node *np = pdev->dev.of_node;
+       struct clk_wzrd *cw;
 
-       clk_wzrd = devm_kzalloc(&pdev->dev, sizeof(*clk_wzrd), GFP_KERNEL);
-       if (!clk_wzrd)
+       cw = devm_kzalloc(dev, sizeof(*cw), GFP_KERNEL);
+       if (!cw)
                return -ENOMEM;
-       platform_set_drvdata(pdev, clk_wzrd);
+       dev_set_drvdata(dev, cw);
 
-       ret = of_property_read_u32(np, "speed-grade", &clk_wzrd->speed_grade);
+       ret = of_property_read_u32(dev->of_node, "speed-grade",
+                                  &cw->speed_grade);
        if (!ret) {
-               if (clk_wzrd->speed_grade < 1 || clk_wzrd->speed_grade > 3) {
-                       dev_warn(&pdev->dev, "invalid speed grade '%d'\n",
-                                clk_wzrd->speed_grade);
-                       clk_wzrd->speed_grade = 0;
+               if (cw->speed_grade < 1 || cw->speed_grade > 3) {
+                       dev_warn(dev, "invalid speed grade '%d'\n",
+                                cw->speed_grade);
+                       cw->speed_grade = 0;
                }
        }
 
-       clk_wzrd->clk_in1 = devm_clk_get(&pdev->dev, "clk_in1");
-       if (IS_ERR(clk_wzrd->clk_in1)) {
-               if (clk_wzrd->clk_in1 != ERR_PTR(-EPROBE_DEFER))
-                       dev_err(&pdev->dev, "clk_in1 not found\n");
-               return PTR_ERR(clk_wzrd->clk_in1);
+       cw->clk_in1 = devm_clk_get(dev, WZRD_CLKNAME_IN1);
+       if (IS_ERR(cw->clk_in1)) {
+               if (cw->clk_in1 != ERR_PTR(-EPROBE_DEFER))
+                       dev_err(dev, "Clock %s not found\n", WZRD_CLKNAME_IN1);
+               return PTR_ERR(cw->clk_in1);
        }
 
-       clk_wzrd->axi_clk = devm_clk_get(&pdev->dev, "s_axi_aclk");
-       if (IS_ERR(clk_wzrd->axi_clk)) {
-               if (clk_wzrd->axi_clk != ERR_PTR(-EPROBE_DEFER))
-                       dev_err(&pdev->dev, "s_axi_aclk not found\n");
-               return PTR_ERR(clk_wzrd->axi_clk);
+       cw->axi_clk = devm_clk_get(dev, WZRD_CLKNAME_AXI);
+       if (IS_ERR(cw->axi_clk)) {
+               if (cw->axi_clk != ERR_PTR(-EPROBE_DEFER))
+                       dev_err(dev, "Clock %s not found\n", WZRD_CLKNAME_AXI);
+               return PTR_ERR(cw->axi_clk);
        }
-       ret = clk_prepare_enable(clk_wzrd->axi_clk);
+       ret = clk_prepare_enable(cw->axi_clk);
        if (ret) {
-               dev_err(&pdev->dev, "enabling s_axi_aclk failed\n");
+               dev_err(dev, "enabling %s failed\n", WZRD_CLKNAME_AXI);
                return ret;
        }
-       rate = clk_get_rate(clk_wzrd->axi_clk);
+       rate = clk_get_rate(cw->axi_clk);
        if (rate > WZRD_ACLK_MAX_FREQ) {
-               dev_err(&pdev->dev, "s_axi_aclk frequency (%lu) too high\n",
+               dev_err(dev, "%s frequency (%lu) too high\n", WZRD_CLKNAME_AXI,
                        rate);
-               clk_disable_unprepare(clk_wzrd->axi_clk);
+               clk_disable_unprepare(cw->axi_clk);
                return -EINVAL;
        }
 
@@ -234,13 +235,12 @@ static int clk_wzrd_get_device_tree_data(struct device 
*dev)
 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);
+       struct clk_wzrd *cw = dev_get_drvdata(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);
+       mem = platform_get_resource(to_platform_device(dev), IORESOURCE_MEM, 0);
+       cw->base = devm_ioremap_resource(dev, mem);
+       if (IS_ERR(cw->base))
+               return PTR_ERR(cw->base);
 
        return 0;
 }
@@ -250,52 +250,50 @@ 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;
+       struct clk_wzrd *cw = dev_get_drvdata(dev);
 
        /* we don't support fractional div/mul yet */
-       reg = readl(clk_wzrd->base + WZRD_CLK_CFG_REG(0)) &
+       reg = readl(cw->base + WZRD_CLK_CFG_REG(0)) &
                    WZRD_CLKFBOUT_FRAC_EN;
-       reg |= readl(clk_wzrd->base + WZRD_CLK_CFG_REG(2)) &
+       reg |= readl(cw->base + WZRD_CLK_CFG_REG(2)) &
                     WZRD_CLKOUT0_FRAC_EN;
        if (reg)
-               dev_warn(&pdev->dev, "fractional div/mul not supported\n");
+               dev_warn(dev, "fractional div/mul not supported\n");
 
        /* register div */
-       reg = (readl(clk_wzrd->base + WZRD_CLK_CFG_REG(0)) &
-                       WZRD_DIVCLK_DIVIDE_MASK) >> WZRD_DIVCLK_DIVIDE_SHIFT;
-       clk_name = kasprintf(GFP_KERNEL, "%s_mul_div", dev_name(&pdev->dev));
+       reg = (readl(cw->base + WZRD_CLK_CFG_REG(0)) &
+              WZRD_DIVCLK_DIVIDE_MASK) >> WZRD_DIVCLK_DIVIDE_SHIFT;
+       clk_name = kasprintf(GFP_KERNEL, "%s_mul_div", dev_name(dev));
        if (!clk_name) {
                ret = -ENOMEM;
                goto err_disable_clk;
        }
-       clk_wzrd->clks_internal[wzrd_clk_mul_div] = clk_register_fixed_factor(
-                       &pdev->dev, clk_name,
-                       __clk_get_name(clk_wzrd->clk_in1),
+       cw->clks_internal[wzrd_clk_mul_div] = clk_register_fixed_factor(
+                       dev, clk_name,
+                       __clk_get_name(cw->clk_in1),
                        0, 1, reg);
        kfree(clk_name);
-       if (IS_ERR(clk_wzrd->clks_internal[wzrd_clk_mul_div])) {
-               dev_err(&pdev->dev, "unable to register divider clock\n");
-               ret = PTR_ERR(clk_wzrd->clks_internal[wzrd_clk_mul_div]);
+       if (IS_ERR(cw->clks_internal[wzrd_clk_mul_div])) {
+               dev_err(dev, "unable to register divider clock\n");
+               ret = PTR_ERR(cw->clks_internal[wzrd_clk_mul_div]);
                goto err_disable_clk;
        }
 
        /* register multiplier */
-       reg = (readl(clk_wzrd->base + WZRD_CLK_CFG_REG(0)) &
-                    WZRD_CLKFBOUT_MULT_MASK) >> WZRD_CLKFBOUT_MULT_SHIFT;
-       clk_name = kasprintf(GFP_KERNEL, "%s_mul", dev_name(&pdev->dev));
+       reg = (readl(cw->base + WZRD_CLK_CFG_REG(0)) &
+              WZRD_CLKFBOUT_MULT_MASK) >> WZRD_CLKFBOUT_MULT_SHIFT;
+       clk_name = kasprintf(GFP_KERNEL, "%s_mul", dev_name(dev));
        if (!clk_name) {
                ret = -ENOMEM;
                goto err_rm_int_clk;
        }
-       clk_wzrd->clks_internal[wzrd_clk_mul] = clk_register_fixed_factor(
-                       &pdev->dev, clk_name,
-                       
__clk_get_name(clk_wzrd->clks_internal[wzrd_clk_mul_div]),
+       cw->clks_internal[wzrd_clk_mul] = clk_register_fixed_factor(
+                       dev, clk_name,
+                       __clk_get_name(cw->clks_internal[wzrd_clk_mul_div]),
                        0, reg, 1);
-       if (IS_ERR(clk_wzrd->clks_internal[wzrd_clk_mul])) {
-               dev_err(&pdev->dev, "unable to register fixed-factor clock\n");
-               ret = PTR_ERR(clk_wzrd->clks_internal[wzrd_clk_mul]);
+       if (IS_ERR(cw->clks_internal[wzrd_clk_mul])) {
+               dev_err(dev, "unable to register fixed-factor clock\n");
+               ret = PTR_ERR(cw->clks_internal[wzrd_clk_mul]);
                goto err_rm_int_clk;
        }
 
@@ -303,60 +301,62 @@ static int clk_wzrd_register_ccf(struct device *dev)
        for (i = WZRD_NUM_OUTPUTS - 1; i >= 0 ; i--) {
                const char *clkout_name;
 
-               if (of_property_read_string_index(np, "clock-output-names", i,
+               if (of_property_read_string_index(dev->of_node,
+                                                 "clock-output-names", i,
                                                  &clkout_name)) {
-                       dev_err(&pdev->dev,
+                       dev_err(dev,
                                "clock output name not specified\n");
                        ret = -EINVAL;
                        goto err_rm_int_clks;
                }
-               reg = readl(clk_wzrd->base + WZRD_CLK_CFG_REG(2) + i * 12);
+               reg = readl(cw->base + WZRD_CLK_CFG_REG(2) + i * 12);
                reg &= WZRD_CLKOUT_DIVIDE_MASK;
                reg >>= WZRD_CLKOUT_DIVIDE_SHIFT;
-               clk_wzrd->clkout[i] = clk_register_fixed_factor(&pdev->dev,
-                               clkout_name, clk_name, 0, 1, reg);
-               if (IS_ERR(clk_wzrd->clkout[i])) {
+               cw->clkout[i] = clk_register_fixed_factor(dev, clkout_name,
+                                                         clk_name, 0, 1, reg);
+               if (IS_ERR(cw->clkout[i])) {
                        int j;
 
                        for (j = i + 1; j < WZRD_NUM_OUTPUTS; j++)
-                               clk_unregister(clk_wzrd->clkout[j]);
-                       dev_err(&pdev->dev,
+                               clk_unregister(cw->clkout[j]);
+                       dev_err(dev,
                                "unable to register divider clock\n");
-                       ret = PTR_ERR(clk_wzrd->clkout[i]);
+                       ret = PTR_ERR(cw->clkout[i]);
                        goto err_rm_int_clks;
                }
        }
 
        kfree(clk_name);
 
-       clk_wzrd->clk_data.clks = clk_wzrd->clkout;
-       clk_wzrd->clk_data.clk_num = ARRAY_SIZE(clk_wzrd->clkout);
-       of_clk_add_provider(np, of_clk_src_onecell_get, &clk_wzrd->clk_data);
+       cw->clk_data.clks = cw->clkout;
+       cw->clk_data.clk_num = ARRAY_SIZE(cw->clkout);
+       of_clk_add_provider(dev->of_node, of_clk_src_onecell_get,
+                           &cw->clk_data);
 
-       if (clk_wzrd->speed_grade) {
-               clk_wzrd->nb.notifier_call = clk_wzrd_clk_notifier;
+       if (cw->speed_grade) {
+               cw->nb.notifier_call = clk_wzrd_clk_notifier;
 
-               ret = clk_notifier_register(clk_wzrd->clk_in1,
-                                           &clk_wzrd->nb);
+               ret = clk_notifier_register(cw->clk_in1,
+                                           &cw->nb);
                if (ret)
-                       dev_warn(&pdev->dev,
+                       dev_warn(dev,
                                 "unable to register clock notifier\n");
 
-               ret = clk_notifier_register(clk_wzrd->axi_clk, &clk_wzrd->nb);
+               ret = clk_notifier_register(cw->axi_clk, &cw->nb);
                if (ret)
-                       dev_warn(&pdev->dev,
+                       dev_warn(dev,
                                 "unable to register clock notifier\n");
        }
 
        return 0;
 
 err_rm_int_clks:
-       clk_unregister(clk_wzrd->clks_internal[1]);
+       clk_unregister(cw->clks_internal[1]);
 err_rm_int_clk:
        kfree(clk_name);
-       clk_unregister(clk_wzrd->clks_internal[0]);
+       clk_unregister(cw->clks_internal[0]);
 err_disable_clk:
-       clk_disable_unprepare(clk_wzrd->axi_clk);
+       clk_disable_unprepare(cw->axi_clk);
 
        return ret;
 }
@@ -384,21 +384,21 @@ static int clk_wzrd_probe(struct platform_device *pdev)
 static int clk_wzrd_remove(struct platform_device *pdev)
 {
        int i;
-       struct clk_wzrd *clk_wzrd = platform_get_drvdata(pdev);
+       struct clk_wzrd *cw = platform_get_drvdata(pdev);
 
        of_clk_del_provider(pdev->dev.of_node);
 
        for (i = 0; i < WZRD_NUM_OUTPUTS; i++)
-               clk_unregister(clk_wzrd->clkout[i]);
+               clk_unregister(cw->clkout[i]);
        for (i = 0; i < wzrd_clk_int_max; i++)
-               clk_unregister(clk_wzrd->clks_internal[i]);
+               clk_unregister(cw->clks_internal[i]);
 
-       if (clk_wzrd->speed_grade) {
-               clk_notifier_unregister(clk_wzrd->axi_clk, &clk_wzrd->nb);
-               clk_notifier_unregister(clk_wzrd->clk_in1, &clk_wzrd->nb);
+       if (cw->speed_grade) {
+               clk_notifier_unregister(cw->axi_clk, &cw->nb);
+               clk_notifier_unregister(cw->clk_in1, &cw->nb);
        }
 
-       clk_disable_unprepare(clk_wzrd->axi_clk);
+       clk_disable_unprepare(cw->axi_clk);
 
        return 0;
 }
-- 
2.15.1 (Apple Git-101)

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

Reply via email to