From: kernel@martin.sperl.org (kernel at martin.sperl.org)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 2/2] clk: bcm2835: expose current divider, parent and mash via debugfs
Date: Mon, 29 Feb 2016 14:20:16 +0000 [thread overview]
Message-ID: <1456755616-2472-3-git-send-email-kernel@martin.sperl.org> (raw)
In-Reply-To: <1456755616-2472-1-git-send-email-kernel@martin.sperl.org>
From: Martin Sperl <kernel@martin.sperl.org>
For each clock expose the following values via debugfs:
* current_parent - the currently selected parent
* current_divi - the integer portion of the currently set divider
* current_divf - the fractional portion of the currently set divider
* current_frac - the current frac/mash settings for the divider
Signed-off-by: Martin Sperl <kernel@martin.sperl.org>
---
drivers/clk/bcm/clk-bcm2835.c | 110 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 110 insertions(+)
diff --git a/drivers/clk/bcm/clk-bcm2835.c b/drivers/clk/bcm/clk-bcm2835.c
index 89de3d6..01a48cb 100644
--- a/drivers/clk/bcm/clk-bcm2835.c
+++ b/drivers/clk/bcm/clk-bcm2835.c
@@ -129,6 +129,10 @@
# define CM_BUSY BIT(7)
# define CM_BUSYD BIT(8)
# define CM_FRAC BIT(9)
+# define CM_MASH0 BIT(9)
+# define CM_MASH1 BIT(10)
+# define CM_MASH_MASK (CM_MASH0 | CM_MASH1)
+# define CM_MASH_SHIFT 9
# define CM_SRC_SHIFT 0
# define CM_SRC_BITS 4
# define CM_SRC_MASK 0xf
@@ -1063,6 +1067,99 @@ static u8 bcm2835_clock_get_parent(struct clk_hw *hw)
return (src & CM_SRC_MASK) >> CM_SRC_SHIFT;
}
+static const char *bcm2835_clock_get_parent_name(struct clk_hw *hw)
+{
+ struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
+ const struct bcm2835_clock_data *data = clock->data;
+ u8 id = bcm2835_clock_get_parent(hw);
+
+ return (id < data->num_mux_parents) ?
+ data->parents[id] : "unknown";
+}
+
+static int bcm2835_clock_debug_current_parent_open(struct inode *inode,
+ struct file *file)
+{
+ const char *parent = bcm2835_clock_get_parent_name(inode->i_private);
+ size_t len = strlen(parent);
+ char *buf;
+
+ /* create string with trailing newline */
+ buf = kmalloc(len + 2, GFP_KERNEL);
+ memcpy(buf, parent, len);
+ buf[len] = '\n';
+ buf[len + 1] = 0;
+
+ file->private_data = buf;
+
+ return 0;
+}
+
+static ssize_t bcm2835_clock_debug_current_parent_read(struct file *file,
+ char __user *buf,
+ size_t len,
+ loff_t *ppos)
+{
+ const char *parent = file->private_data;
+ size_t size = strlen(parent);
+
+ return simple_read_from_buffer(buf, len, ppos, parent, size);
+}
+
+static const struct file_operations bcm2835_clock_debug_current_parent_fops = {
+ .owner = THIS_MODULE,
+ .open = bcm2835_clock_debug_current_parent_open,
+ .release = simple_attr_release,
+ .read = bcm2835_clock_debug_current_parent_read,
+ .llseek = generic_file_llseek,
+};
+
+static int bcm2835_clock_debug_current_divi_get(void *hw, u64 *val)
+{
+ struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
+ struct bcm2835_cprman *cprman = clock->cprman;
+ const struct bcm2835_clock_data *data = clock->data;
+ u32 div = cprman_read(cprman, data->div_reg);
+
+ *val = div >> CM_DIV_FRAC_BITS;
+ return 0;
+}
+DEFINE_SIMPLE_ATTRIBUTE(bcm2835_clock_debug_current_divi_fops,
+ bcm2835_clock_debug_current_divi_get,
+ NULL, "%llu\n");
+
+static int bcm2835_clock_debug_current_divf_get(void *hw, u64 *val)
+{
+ struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
+ struct bcm2835_cprman *cprman = clock->cprman;
+ const struct bcm2835_clock_data *data = clock->data;
+ u32 div = cprman_read(cprman, data->div_reg);
+
+ *val = div & CM_DIV_FRAC_MASK;
+ return 0;
+}
+DEFINE_SIMPLE_ATTRIBUTE(bcm2835_clock_debug_current_divf_fops,
+ bcm2835_clock_debug_current_divf_get,
+ NULL, "%llu\n");
+
+static int bcm2835_clock_debug_current_frac_get(void *hw, u64 *val)
+{
+ struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
+ struct bcm2835_cprman *cprman = clock->cprman;
+ const struct bcm2835_clock_data *data = clock->data;
+ u32 ctl = cprman_read(cprman, data->ctl_reg);
+
+ if (data->is_mash_clock)
+ *val = (ctl & CM_MASH_MASK) >> CM_MASH_SHIFT;
+ else
+ *val = ctl & CM_FRAC ? 1 : 0;
+
+ return 0;
+}
+DEFINE_SIMPLE_ATTRIBUTE(bcm2835_clock_debug_current_frac_fops,
+ bcm2835_clock_debug_current_frac_get,
+ NULL, "%llu\n");
+
static struct debugfs_reg32 bcm2835_debugfs_clock_reg32[] = {
{
.name = "ctl",
@@ -1081,6 +1178,19 @@ static int bcm2835_clock_debug_init(struct clk_hw *hw,
struct bcm2835_cprman *cprman = clock->cprman;
const struct bcm2835_clock_data *data = clock->data;
+ /* expose the current parrent */
+ debugfs_create_file("current_parent", S_IRUGO, dentry, hw,
+ &bcm2835_clock_debug_current_parent_fops);
+
+ /* expose the current divider components */
+ debugfs_create_file("current_divi", S_IRUGO, dentry, hw,
+ &bcm2835_clock_debug_current_divi_fops);
+ debugfs_create_file("current_divf", S_IRUGO, dentry, hw,
+ &bcm2835_clock_debug_current_divf_fops);
+ debugfs_create_file("current_frac", S_IRUGO, dentry, hw,
+ &bcm2835_clock_debug_current_frac_fops);
+
+ /* add the regset */
return bcm2835_debugfs_regset(
cprman, data->ctl_reg,
bcm2835_debugfs_clock_reg32,
--
1.7.10.4
next prev parent reply other threads:[~2016-02-29 14:20 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-29 14:20 [PATCH 0/2] clk: bcm2835 expose current settings and registers kernel at martin.sperl.org
2016-02-29 14:20 ` [PATCH 1/2] clk: bcm2835: expose raw clock-registers via debugfs kernel at martin.sperl.org
2016-02-29 20:39 ` Eric Anholt
2016-03-01 13:31 ` Martin Sperl
2016-03-01 18:41 ` Eric Anholt
2016-02-29 14:20 ` kernel at martin.sperl.org [this message]
2016-02-29 20:43 ` [PATCH 2/2] clk: bcm2835: expose current divider, parent and mash " Eric Anholt
2016-02-29 21:11 ` Martin Sperl
2016-02-29 23:13 ` Eric Anholt
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=1456755616-2472-3-git-send-email-kernel@martin.sperl.org \
--to=kernel@martin.sperl.org \
--cc=linux-arm-kernel@lists.infradead.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;
as well as URLs for NNTP newsgroup(s).