From patchwork Sun Feb 28 15:37:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sperl X-Patchwork-Id: 8447441 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D1FAAC0553 for ; Sun, 28 Feb 2016 15:48:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EA6E22011B for ; Sun, 28 Feb 2016 15:48:02 +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 00F602010F for ; Sun, 28 Feb 2016 15:48:02 +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 1aa3Y4-0005rz-EH; Sun, 28 Feb 2016 15:46:20 +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 1aa3QO-0005Pu-Pc; Sun, 28 Feb 2016 15:38:27 +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 6394911; Sun, 28 Feb 2016 15:37:22 +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 v5 13/20] clk: bcm2835: expose current divider, parent and mash via debugfs Date: Sun, 28 Feb 2016 15:37:04 +0000 Message-Id: <1456673831-2408-14-git-send-email-kernel@martin.sperl.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1456673831-2408-1-git-send-email-kernel@martin.sperl.org> References: <1456673831-2408-1-git-send-email-kernel@martin.sperl.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160228_073825_460334_C6B8FF06 X-CRM114-Status: UNSURE ( 7.23 ) 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 | 101 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/drivers/clk/bcm/clk-bcm2835.c b/drivers/clk/bcm/clk-bcm2835.c index 366f975..b67147b 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 @@ -1045,6 +1049,90 @@ 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); + + file->private_data = kstrdup(parent, GFP_KERNEL); + 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", @@ -1063,6 +1151,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,