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: 9025601 X-Patchwork-Delegate: sboyd@codeaurora.org Return-Path: X-Original-To: patchwork-linux-clk@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 0312EBF440 for ; Thu, 5 May 2016 15:53:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2A9CA20222 for ; Thu, 5 May 2016 15:53:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 30FAF203AE for ; Thu, 5 May 2016 15:53:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757643AbcEEPxo (ORCPT ); Thu, 5 May 2016 11:53:44 -0400 Received: from 212-186-180-163.dynamic.surfer.at ([212.186.180.163]:53476 "EHLO cgate.sperl.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757640AbcEEPxo (ORCPT ); Thu, 5 May 2016 11:53:44 -0400 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 Cc: Martin Sperl 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> Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org X-Spam-Status: No, score=-9.0 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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))