diff mbox

[RFC] clk: debugfs add clk_rate_fops to debugfs mux

Message ID 1376625809-522-1-git-send-email-zhangfei.gao@linaro.org
State Changes Requested
Headers show

Commit Message

Zhangfei Gao Aug. 16, 2013, 4:03 a.m. UTC
MUX could choose parent accordingly when set_rate.
Add clk_rate_fops to debug whether mux choose correct parent

Example:
cat clk_summary
   clock                        enable_cnt  prepare_cnt  rate
---------------------------------------------------------------------
 osc24mhz                       3           3            24000000
    bpll                        1           1            4294967295
       bpll_fout3               0           0            200000000
          sfc_mux               0           0            200000000
             sfc                0           0            200000000

cat osc24mhz/bpll/bpll_fout3/sfc_mux/sfc/clk_rate
200000000

echo 24000000 >  osc24mhz/bpll/bpll_fout3/sfc_mux/sfc/clk_rate
cat clk_summary
   clock                        enable_cnt  prepare_cnt  rate
---------------------------------------------------------------------
 osc24mhz                       3           3            24000000
    sfc_mux                     0           0            24000000
       sfc                      0           0            24000000
    bpll                        1           1            4294967295
       bpll_fout3               0           0            200000000

cat osc24mhz/sfc_mux/sfc/clk_rate
24000000

Signed-off-by: Zhangfei Gao <zhangfei.gao@linaro.org>
---
 drivers/clk/clk.c |   31 +++++++++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 373cd54..327b698 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -226,6 +226,33 @@  static const struct file_operations clk_dump_fops = {
 	.release	= single_release,
 };
 
+static int clk_rate_fops_get(void *data, u64 *rate)
+{
+	struct clk *clk = data;
+
+	*rate = clk->rate;
+
+	return 0;
+};
+
+static int clk_rate_fops_set(void *data, u64 rate)
+{
+	struct clk *clk = data;
+	int ret = 0;
+
+	ret = clk_prepare_enable(clk);
+	if (ret)
+		goto out;
+	clk_set_rate(clk, rate);
+	clk_disable_unprepare(clk);
+
+out:
+	return ret;
+};
+
+DEFINE_SIMPLE_ATTRIBUTE(clk_rate_fops, clk_rate_fops_get,
+			clk_rate_fops_set, "%llu\n");
+
 /* caller must hold prepare_lock */
 static int clk_debug_create_one(struct clk *clk, struct dentry *pdentry)
 {
@@ -243,8 +270,8 @@  static int clk_debug_create_one(struct clk *clk, struct dentry *pdentry)
 
 	clk->dentry = d;
 
-	d = debugfs_create_u32("clk_rate", S_IRUGO, clk->dentry,
-			(u32 *)&clk->rate);
+	d = debugfs_create_file("clk_rate", S_IWUSR | S_IRUGO, clk->dentry,
+				clk, &clk_rate_fops);
 	if (!d)
 		goto err_out;