linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: kernel@martin.sperl.org (kernel at martin.sperl.org)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v5 10/20] clk: bcm2835: implement correct clamping for mash clocks
Date: Sun, 28 Feb 2016 15:37:01 +0000	[thread overview]
Message-ID: <1456673831-2408-11-git-send-email-kernel@martin.sperl.org> (raw)
In-Reply-To: <1456673831-2408-1-git-send-email-kernel@martin.sperl.org>

From: Martin Sperl <kernel@martin.sperl.org>

The bcm2835-soc has 2 kindes of clocks:
* normal clocks
* mash-enabled clocks that can spread frequency noise better
  into non-audiable frequency ranges

The mash clocks have distinct clock-divider requirements
and if the requested divider is not in range, then there will
no clock output.

This patch implements the clamping limits for first order
fractual mash dividers.

Only dividers that are impacted by this patch are: pcm and pwm

Signed-off-by: Martin Sperl <kernel@martin.sperl.org>
---
 drivers/clk/bcm/clk-bcm2835.c |   24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/drivers/clk/bcm/clk-bcm2835.c b/drivers/clk/bcm/clk-bcm2835.c
index 3df17a5..2fb9923 100644
--- a/drivers/clk/bcm/clk-bcm2835.c
+++ b/drivers/clk/bcm/clk-bcm2835.c
@@ -407,6 +407,7 @@ struct bcm2835_clock_data {
 	/* Number of fractional bits in the divider */
 	u32 frac_bits;
 
+	bool is_mash_clock;
 	bool is_vpu_clock;
 };
 
@@ -780,10 +781,19 @@ static u32 bcm2835_clock_choose_div(struct clk_hw *hw,
 		div += unused_frac_mask + 1;
 	div &= ~unused_frac_mask;
 
-	/* Clamp to the limits. */
-	div = max(div, unused_frac_mask + 1);
-	div = min_t(u32, div, GENMASK(data->int_bits + CM_DIV_FRAC_BITS - 1,
-				      CM_DIV_FRAC_BITS - data->frac_bits));
+	/* Clamp to the limits for the clock type */
+	if (data->is_mash_clock) {
+		/* clamp to min divider 2 */
+		div = max_t(u32, div, 2 << CM_DIV_FRAC_BITS);
+		/* clamp to max int divider */
+		div = min_t(u32, div,
+			    (BIT(data->int_bits) - 1) << CM_DIV_FRAC_BITS);
+	} else {
+		div = max(div, unused_frac_mask + 1);
+		div = min_t(u32, div,
+			    GENMASK(data->int_bits + CM_DIV_FRAC_BITS - 1,
+				    CM_DIV_FRAC_BITS - data->frac_bits));
+	}
 
 	return div;
 }
@@ -1512,13 +1522,15 @@ static const struct bcm2835_clk_desc clk_desc_array[] = {
 		.ctl_reg = CM_PCMCTL,
 		.div_reg = CM_PCMDIV,
 		.int_bits = 12,
-		.frac_bits = 12),
+		.frac_bits = 12,
+		.is_mash_clock = true),
 	[BCM2835_CLOCK_PWM]	= REGISTER_PER_CLK(
 		.name = "pwm",
 		.ctl_reg = CM_PWMCTL,
 		.div_reg = CM_PWMDIV,
 		.int_bits = 12,
-		.frac_bits = 12),
+		.frac_bits = 12,
+		.is_mash_clock = true),
 	[BCM2835_CLOCK_UART]	= REGISTER_PER_CLK(
 		.name = "uart",
 		.ctl_reg = CM_UARTCTL,
-- 
1.7.10.4

  parent reply	other threads:[~2016-02-28 15:37 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-28 15:36 [PATCH v5 00/20] add additional clocks and frac/mash support kernel at martin.sperl.org
2016-02-28 15:36 ` [PATCH v5 01/20] clk: bcm2835: pll_off should only set CM_PLL_ANARST kernel at martin.sperl.org
2016-02-28 17:58   ` Stefan Wahren
2016-02-28 15:36 ` [PATCH v5 02/20] clk: bcm2835: clean up coding style issues kernel at martin.sperl.org
2016-02-28 15:36 ` [PATCH v5 03/20] clk: bcm2835: add locking to pll*_on/off methods kernel at martin.sperl.org
2016-02-28 18:04   ` Stefan Wahren
2016-02-28 15:36 ` [PATCH v5 04/20] clk: bcm2835: remove uart0/1_pclk fixed clocks kernel at martin.sperl.org
2016-02-28 15:36 ` [PATCH v5 05/20] clk: bcm2835: enable clocks that have been enabled by firmware kernel at martin.sperl.org
2016-02-28 15:36 ` [PATCH v5 06/20] clk: bcm2835: remove use of BCM2835_CLOCK_COUNT in driver kernel at martin.sperl.org
2016-02-28 15:36 ` [PATCH v5 07/20] clk: bcm2835: reorganize bcm2835_clock_array assignment kernel at martin.sperl.org
2016-02-28 15:36 ` [PATCH v5 08/20] clk: bcm2835: add fractional support kernel at martin.sperl.org
2016-02-28 15:37 ` [PATCH v5 09/20] clk: bcm2835: enable management of PCM clock kernel at martin.sperl.org
2016-02-28 15:37 ` kernel at martin.sperl.org [this message]
2016-02-28 15:37 ` [PATCH v5 11/20] clk: bcm2835: divider value has to be 1 or more kernel at martin.sperl.org
2016-02-28 15:37 ` [PATCH v5 12/20] clk: bcm2835: expose raw clock-registers via debugfs kernel at martin.sperl.org
2016-02-28 15:37 ` [PATCH v5 13/20] clk: bcm2835: expose current divider, parent and mash " kernel at martin.sperl.org
2016-02-28 15:37 ` [PATCH v5 14/20] clk: bcm2835: added missing PLL clock divider kernel at martin.sperl.org
2016-02-28 15:37 ` [PATCH v5 15/20] clk: bcm2835: add additional clocks kernel at martin.sperl.org
2016-02-28 15:37 ` [PATCH v5 16/20] clk: bcm2835: add the camera related clocks cam0, cam1 and ccp2 kernel at martin.sperl.org
2016-02-28 15:37 ` [PATCH v5 17/20] clk: bcm2835: add the dsi clocks kernel at martin.sperl.org
2016-02-28 15:37 ` [PATCH v5 18/20] clk: bcm2835: add arm clock kernel at martin.sperl.org
2016-02-28 15:37 ` [PATCH v5 19/20] clk: bcm2835: add gates that require PM_DEBUG to be set kernel at martin.sperl.org
2016-02-28 17:48 ` [PATCH v5 00/20] add additional clocks and frac/mash support Stefan Wahren

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=1456673831-2408-11-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).