From patchwork Thu May 5 15:53:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sperl X-Patchwork-Id: 9025721 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 3FEA2BF29F for ; Thu, 5 May 2016 15:57:17 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 52CC4203B4 for ; Thu, 5 May 2016 15:57:16 +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 098F8203AE for ; Thu, 5 May 2016 15:57:15 +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 1ayLc4-0007uA-Ko; Thu, 05 May 2016 15:54:52 +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 1ayLbW-0007WQ-2E; Thu, 05 May 2016 15:54:19 +0000 Received: from rasp3a.intern.sperl.org (account martin@sperl.org [10.10.10.43] verified) by sperl.org (CommuniGate Pro SMTP 6.1.2) with ESMTPSA id 6448388; Thu, 05 May 2016 15:53:31 +0000 From: kernel@martin.sperl.org To: Rob Herring , Mark Rutland , Stephen Warren , Lee Jones , Eric Anholt , Michael Turquette , Stephen Boyd , devicetree@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-clk@vger.kernel.org Subject: [PATCH 5/5] clk: bcm2835: add support for BCM2835_CLOCK_FLAG_USE_MASH/INTEGER Date: Thu, 5 May 2016 15:53:28 +0000 Message-Id: <1462463608-22940-6-git-send-email-kernel@martin.sperl.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1462463608-22940-1-git-send-email-kernel@martin.sperl.org> References: <1462463608-22940-1-git-send-email-kernel@martin.sperl.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160505_085418_586596_A092EC9C X-CRM114-Status: GOOD ( 11.57 ) 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=-6.3 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 Allow the use of higher order mash fractional divider modes and also allow to force the use of integer dividers. Signed-off-by: Martin Sperl --- drivers/clk/bcm/clk-bcm2835.c | 57 +++++++++++++++++++++++++++++++++++-- include/dt-bindings/clock/bcm2835.h | 7 +++++ 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/drivers/clk/bcm/clk-bcm2835.c b/drivers/clk/bcm/clk-bcm2835.c index c80487e..08140ad 100644 --- a/drivers/clk/bcm/clk-bcm2835.c +++ b/drivers/clk/bcm/clk-bcm2835.c @@ -130,6 +130,7 @@ # define CM_BUSY BIT(7) # define CM_BUSYD BIT(8) # define CM_FRAC BIT(9) +# define CM_MASH BIT(10) # define CM_SRC_SHIFT 0 # define CM_SRC_BITS 4 # define CM_SRC_MASK 0xf @@ -888,6 +889,24 @@ static u32 bcm2835_clock_choose_div(struct clk_hw *hw, CM_DIV_FRAC_BITS - data->frac_bits); } + /* based on flags modify settings */ + switch (clock->flags & BCM2835_CLOCK_FLAG_USE_MASK) { + case BCM2835_CLOCK_FLAG_USE_FRAC: + break; + case BCM2835_CLOCK_FLAG_USE_INTEGER: + div &= GENMASK(data->int_bits + CM_DIV_FRAC_BITS - 1, + CM_DIV_FRAC_BITS); + break; + case BCM2835_CLOCK_FLAG_USE_MASH2: + mindiv += 2 << CM_DIV_FRAC_BITS; + maxdiv -= 1 << CM_DIV_FRAC_BITS; + break; + case BCM2835_CLOCK_FLAG_USE_MASH3: + mindiv += 4 << CM_DIV_FRAC_BITS; + maxdiv -= 3 << CM_DIV_FRAC_BITS; + break; + } + /* apply the clamping limits */ div = max_t(u32, div, mindiv); div = min_t(u32, div, maxdiv); @@ -996,8 +1015,26 @@ static int bcm2835_clock_set_rate(struct clk_hw *hw, * clock this requirement should be take care of by the * clk-framework. */ - ctl = cprman_read(cprman, data->ctl_reg) & ~CM_FRAC; - ctl |= (div & CM_DIV_FRAC_MASK) ? CM_FRAC : 0; + ctl = cprman_read(cprman, data->ctl_reg) & ~(CM_FRAC | CM_MASH); + if (div & CM_DIV_FRAC_MASK) { + /* + * we never get to *MASH* for non-mash clock, + * as it is filtered in bcm2835_register_clock + * USE_INTEGER forces already choose_clock_div + * to apply the mask so that we do not get here + */ + switch (clock->flags & BCM2835_CLOCK_FLAG_USE_MASK) { + case BCM2835_CLOCK_FLAG_USE_FRAC: + ctl |= CM_FRAC; + break; + case BCM2835_CLOCK_FLAG_USE_MASH2: + ctl |= CM_MASH; + break; + case BCM2835_CLOCK_FLAG_USE_MASH3: + ctl |= CM_MASH | CM_FRAC; + break; + } + } cprman_write(cprman, data->ctl_reg, ctl); cprman_write(cprman, data->div_reg, div); @@ -1280,6 +1317,22 @@ bcm2835_register_clock(struct bcm2835_cprman *cprman, clock->flags |= bcm2835_register_clock_default_parents( cprman->dev, data); + /* check for MASH flags when the clock is not a mash clock */ + if (!data->is_mash_clock) { + switch (clock->flags & BCM2835_CLOCK_FLAG_USE_MASK) { + case BCM2835_CLOCK_FLAG_USE_MASH2: + case BCM2835_CLOCK_FLAG_USE_MASH3: + dev_warn(cprman->dev, + "found mash2/mash3 flag for clock %s, which does not support mash\n", + data->name); + clock->flags &= BCM2835_CLOCK_FLAG_USE_MASK; + clock->flags |= BCM2835_CLOCK_FLAG_USE_FRAC; + break; + default: + break; + } + } + return devm_clk_register(cprman->dev, &clock->hw); } diff --git a/include/dt-bindings/clock/bcm2835.h b/include/dt-bindings/clock/bcm2835.h index e5396fe..5591bd1 100644 --- a/include/dt-bindings/clock/bcm2835.h +++ b/include/dt-bindings/clock/bcm2835.h @@ -90,3 +90,10 @@ #define BCM2835_VPU_PARENT_PLLH_AUX 7 #define BCM2835_VPU_PARENT_PLLC_CORE1 8 #define BCM2835_VPU_PARENT_PLLC_CORE2 9 + +/* additional clock flags */ +#define BCM2835_CLOCK_FLAG_USE_FRAC ((0 << 31) | (0 << 30)) +#define BCM2835_CLOCK_FLAG_USE_INTEGER ((0 << 31) | (1 << 30)) +#define BCM2835_CLOCK_FLAG_USE_MASH2 ((1 << 31) | (0 << 30)) +#define BCM2835_CLOCK_FLAG_USE_MASH3 ((1 << 31) | (1 << 30)) +#define BCM2835_CLOCK_FLAG_USE_MASK ((1 << 31) | (1 << 30))