mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Geert Uytterhoeven <geert@linux-m68k.org>
To: Jonathan Corbet <corbet@lwn.net>,
	Andrew Morton <akpm@linux-foundation.org>,
	Mike Turquette <mturquette@linaro.org>,
	Stephen Boyd <sboyd@codeaurora.org>
Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	Geert Uytterhoeven <geert+renesas@glider.be>
Subject: [PATCH 3/3] lib/vsprintf: Add %pC{,n,r} format specifiers for clocks
Date: Thu, 26 Feb 2015 12:13:03 +0100	[thread overview]
Message-ID: <1424949183-31425-4-git-send-email-geert@linux-m68k.org> (raw)
In-Reply-To: <1424949183-31425-1-git-send-email-geert@linux-m68k.org>

From: Geert Uytterhoeven <geert+renesas@glider.be>

Add format specifiers for printing struct clk:
  - '%pC' or '%pCn': name (Common Clock Framework) or address (legacy
    clock framework) of the clock,
  - '%pCr': rate of the clock.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
 Documentation/printk-formats.txt | 12 ++++++++++++
 lib/vsprintf.c                   | 37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+)

diff --git a/Documentation/printk-formats.txt b/Documentation/printk-formats.txt
index 11413036a63d1f7a..c287a9cec42cd20b 100644
--- a/Documentation/printk-formats.txt
+++ b/Documentation/printk-formats.txt
@@ -269,6 +269,18 @@ struct va_format:
 
 	Passed by reference.
 
+struct clk:
+
+	%pC	pll1
+	%pCn	pll1
+	%pCr	1560000000
+
+	For printing struct clk structures. '%pC' and '%pCn' print the name
+	(Common Clock Framework) or address (legacy clock framework) of the
+	structure; '%pCr' prints the current clock rate.
+
+	Passed by reference.
+
 
 Thank you for your cooperation and attention.
 
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 86907982a7702331..c0ae8ad034efd2aa 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -17,6 +17,7 @@
  */
 
 #include <stdarg.h>
+#include <linux/clk-provider.h>
 #include <linux/module.h>	/* for KSYM_SYMBOL_LEN */
 #include <linux/types.h>
 #include <linux/string.h>
@@ -1337,6 +1338,30 @@ char *comm_name(char *buf, char *end, struct task_struct *tsk,
 	return string(buf, end, name, spec);
 }
 
+static noinline_for_stack
+char *clock(char *buf, char *end, struct clk *clk, struct printf_spec spec,
+	    const char *fmt)
+{
+	if (!clk)
+		return string(buf, end, NULL, spec);
+
+	switch (fmt[1]) {
+	case 'r':
+		return number(buf, end, clk_get_rate(clk), spec);
+
+	case 'n':
+	default:
+#ifdef CONFIG_COMMON_CLK
+		return string(buf, end, __clk_get_name(clk), spec);
+#else
+		spec.base = 16;
+		spec.field_width = sizeof(unsigned long) * 2 + 2;
+		spec.flags |= SPECIAL | SMALL | ZEROPAD;
+		return number(buf, end, (unsigned long)clk, spec);
+#endif
+	}
+}
+
 int kptr_restrict __read_mostly;
 
 /*
@@ -1420,6 +1445,11 @@ int kptr_restrict __read_mostly;
  * - 'd[234]' For a dentry name (optionally 2-4 last components)
  * - 'D[234]' Same as 'd' but for a struct file
  * - 'T' task_struct->comm
+ * - 'C' For a clock, it prints the name (Common Clock Framework) or address
+ *       (legacy clock framework) of the clock
+ * - 'Cn' For a clock, it prints the name (Common Clock Framework) or address
+ *        (legacy clock framework) of the clock
+ * - 'Cr' For a clock, it prints the current rate of the clock
  *
  * Note: The difference between 'S' and 'F' is that on ia64 and ppc64
  * function pointers are really function descriptors, which contain a
@@ -1570,6 +1600,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
 				   spec, fmt);
 	case 'T':
 		return comm_name(buf, end, ptr, spec, fmt);
+	case 'C':
+		return clock(buf, end, ptr, spec, fmt);
 	}
 	spec.flags |= SMALL;
 	if (spec.field_width == -1) {
@@ -1818,6 +1850,11 @@ qualifier:
  * %*pE[achnops] print an escaped buffer
  * %*ph[CDN] a variable-length hex string with a separator (supports up to 64
  *           bytes of the input)
+ * %pC output the name (Common Clock Framework) or address (legacy clock
+ *     framework) of a clock
+ * %pCn output the name (Common Clock Framework) or address (legacy clock
+ *      framework) of a clock
+ * %pCr output the current rate of a clock
  * %n is ignored
  *
  * ** Please update Documentation/printk-formats.txt when making changes **
-- 
1.9.1


  parent reply	other threads:[~2015-02-26 11:13 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-26 11:13 [PATCH 0/3] lib/vsprintf: Doc improvements and clock support Geert Uytterhoeven
2015-02-26 11:13 ` [PATCH 1/3] lib/vsprintf: Document %p parameters passed by reference Geert Uytterhoeven
2015-02-26 11:13 ` [PATCH 2/3] lib/vsprintf: Move integer format types to the top Geert Uytterhoeven
2015-02-26 11:13 ` Geert Uytterhoeven [this message]
2015-02-27 22:18   ` [PATCH 3/3] lib/vsprintf: Add %pC{,n,r} format specifiers for clocks Andrew Morton
2015-02-27 22:55     ` Joe Perches
2015-02-28  8:53       ` Geert Uytterhoeven
2015-02-28 14:56     ` Geert Uytterhoeven
2015-02-27  0:02 ` [PATCH 0/3] lib/vsprintf: Doc improvements and clock support Stephen Boyd
2015-02-27  7:52   ` Geert Uytterhoeven

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1424949183-31425-4-git-send-email-geert@linux-m68k.org \
    --to=geert@linux-m68k.org \
    --cc=akpm@linux-foundation.org \
    --cc=corbet@lwn.net \
    --cc=geert+renesas@glider.be \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mturquette@linaro.org \
    --cc=penguin-kernel@I-love.SAKURA.ne.jp \
    --cc=sboyd@codeaurora.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome