[PATCH] clk: clk-divider: Add a simple test for dividers
From: Sascha Hauer
Date: Tue Feb 17 2015 - 05:24:10 EST
Signed-off-by: Sascha Hauer <s.hauer@xxxxxxxxxxxxxx>
---
drivers/clk/clk-divider.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 86 insertions(+)
diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c
index c0a842b..cd66625 100644
--- a/drivers/clk/clk-divider.c
+++ b/drivers/clk/clk-divider.c
@@ -463,3 +463,89 @@ struct clk *clk_register_divider_table(struct device *dev, const char *name,
width, clk_divider_flags, table, lock);
}
EXPORT_SYMBOL_GPL(clk_register_divider_table);
+
+/*
+ * Simple test of dividers. Try to set rates between 1 and 10000Hz and
+ * - get output of clk_round_rate()
+ * - set the current target rate, get the rate
+ * - set the rate to the rounded rate, get the rate
+ *
+ * Whenever a value changed print the results
+ */
+static void clktest_one(struct clk *clk)
+{
+ int i, ret;
+ unsigned long roundsetrate, last_roundsetrate = 0;
+ unsigned long roundrate, last_roundrate = 0;
+ unsigned long setrate, last_setrate = 0;
+
+ for (i = 1; i < 10000; i++) {
+ roundrate = clk_round_rate(clk, i);
+
+ clk_set_rate(clk, i);
+ setrate = clk_get_rate(clk);
+
+ ret = clk_set_rate(clk, roundrate);
+ if (ret) {
+ printk("clkdivtest: Failed to set rate: %d\n", ret);
+ return;
+ }
+
+ roundsetrate = clk_get_rate(clk);
+
+ if (last_roundsetrate != roundsetrate ||
+ last_roundrate != roundrate ||
+ last_setrate != setrate)
+ printk("target rate: %4d rounded: %4ld set: %4ld round/set: %4ld\n",
+ i, roundrate, setrate, roundsetrate);
+
+ last_roundsetrate = roundsetrate;
+ last_roundrate = roundrate;
+ last_setrate = setrate;
+ }
+}
+
+static int clktest(void)
+{
+ u32 reg_div1 = 0;
+ u32 reg_div2 = 0;
+ u32 reg_div3 = 0;
+ struct clk *clktest_base = ERR_PTR(-ENODEV);
+ struct clk *clktest_div1 = ERR_PTR(-ENODEV);
+ struct clk *clktest_div2 = ERR_PTR(-ENODEV);
+ struct clk *clktest_div3 = ERR_PTR(-ENODEV);
+
+ clktest_base = clk_register_fixed_rate(NULL, "clktest_base", NULL, 0, 10000);
+ clktest_div1 = clk_register_divider(NULL, "clktest_div1", "clktest_base",
+ 0, ®_div1, 0, 4, 0, NULL);
+ clktest_div2 = clk_register_divider(NULL, "clktest_div2", "clktest_div1",
+ CLK_SET_RATE_PARENT, ®_div2, 0, 4, 0, NULL);
+ clktest_div3 = clk_register_divider(NULL, "clktest_div3", "clktest_div2",
+ CLK_SET_RATE_PARENT, ®_div3, 0, 4, 0, NULL);
+
+ if (IS_ERR(clktest_base) || IS_ERR(clktest_div1) ||
+ IS_ERR(clktest_div2) || IS_ERR(clktest_div3)) {
+ printk("clkdivtest: Failed to register clocks\n");
+ goto err_out;
+ }
+
+ printk("------------------ Single divider, fin=10000Hz ------------------\n");
+ clktest_one(clktest_div1);
+ printk("--------------- two cascaded dividers, fin=10000Hz --------------\n");
+ clktest_one(clktest_div2);
+ printk("-------------- three cascaded dividers, fin=10000Hz -------------\n");
+ clktest_one(clktest_div3);
+
+err_out:
+ if (!IS_ERR(clktest_base))
+ clk_unregister(clktest_base);
+ if (!IS_ERR(clktest_div1))
+ clk_unregister(clktest_div1);
+ if (!IS_ERR(clktest_div2))
+ clk_unregister(clktest_div2);
+ if (!IS_ERR(clktest_div3))
+ clk_unregister(clktest_div3);
+
+ return 0;
+}
+late_initcall(clktest);
--
2.1.4
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/