From patchwork Mon Feb 29 14:20:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sperl X-Patchwork-Id: 8454701 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 97D149F38C for ; Mon, 29 Feb 2016 14:23:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id ABB0B202B8 for ; Mon, 29 Feb 2016 14:23:26 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B80C9202AE for ; Mon, 29 Feb 2016 14:23:24 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aaOhz-0006JM-9G; Mon, 29 Feb 2016 14:21:59 +0000 Received: from 212-186-180-163.dynamic.surfer.at ([212.186.180.163] helo=cgate.sperl.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aaOhO-00068U-3O; Mon, 29 Feb 2016 14:21:24 +0000 Received: from raspcm.intern.sperl.org (account martin@sperl.org [10.10.10.41] verified) by sperl.org (CommuniGate Pro SMTP 6.1.2) with ESMTPSA id 6394991; Mon, 29 Feb 2016 14:20:53 +0000 From: kernel@martin.sperl.org To: Michael Turquette , Stephen Boyd , Stephen Warren , Lee Jones , Eric Anholt , linux-clk@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, 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 Message-Id: <1456755616-2472-3-git-send-email-kernel@martin.sperl.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1456755616-2472-1-git-send-email-kernel@martin.sperl.org> References: <1456755616-2472-1-git-send-email-kernel@martin.sperl.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160229_062122_693798_BA67338E X-CRM114-Status: UNSURE ( 8.26 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.9 (/) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Martin Sperl MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Martin Sperl 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 --- 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,