public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Joonyoung Shim <jy0922.shim@samsung.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v6 7/7] Exynos: Clock: Cleanup soc_get_periph_rate
Date: Thu, 05 Feb 2015 13:40:09 +0900	[thread overview]
Message-ID: <54D2F429.90702@samsung.com> (raw)
In-Reply-To: <1423045805-14487-8-git-send-email-akshay.s@samsung.com>

Hi Akshay,

On 02/04/2015 07:30 PM, Akshay Saraswat wrote:
> Since we have src, div and pre-div mask bits defined corresponding
> to peripherals, calculation of clock specific to I2C appears
> redundant and confusing. Using clk_bit_info struct we can write
> calculations generic to all peripherals which makes code easy to
> understand and free from peripheral specific exceptions.
> 
> Signed-off-by: Akshay Saraswat <akshay.s@samsung.com>
> ---
> Changes since v5:
> 	- Elaborated Commit message and fixed a nit.
> 
> Changes since v4:
> 	- New patch.
> 
>  arch/arm/cpu/armv7/exynos/clock.c | 74 ++++++++++++++++++---------------------
>  1 file changed, 35 insertions(+), 39 deletions(-)
> 
> diff --git a/arch/arm/cpu/armv7/exynos/clock.c b/arch/arm/cpu/armv7/exynos/clock.c
> index 3884d4b..5777490 100644
> --- a/arch/arm/cpu/armv7/exynos/clock.c
> +++ b/arch/arm/cpu/armv7/exynos/clock.c
> @@ -366,8 +366,8 @@ static struct clk_bit_info *get_clk_bit_info(int peripheral)
>  static unsigned long exynos5_get_periph_rate(int peripheral)
>  {
>  	struct clk_bit_info *bit_info = get_clk_bit_info(peripheral);
> -	unsigned long sclk, sub_clk = 0;
> -	unsigned int src, div, sub_div = 0;
> +	unsigned long sclk = 0;
> +	unsigned int src = 0, div = 0, sub_div = 0;
>  	struct exynos5_clock *clk =
>  			(struct exynos5_clock *)samsung_get_base_clock();
>  
> @@ -389,30 +389,30 @@ static unsigned long exynos5_get_periph_rate(int peripheral)
>  		break;
>  	case PERIPH_ID_I2S0:
>  		src = readl(&clk->src_mau);
> -		div = readl(&clk->div_mau);
> +		div = sub_div = readl(&clk->div_mau);

I just do scripts/checkpatch.pl and get follow results.

CHECK: multiple assignments should be avoided
#37: FILE: arch/arm/cpu/armv7/exynos/clock.c:392:
+		div = sub_div = readl(&clk->div_mau);

CHECK: multiple assignments should be avoided
#42: FILE: arch/arm/cpu/armv7/exynos/clock.c:396:
+		div = sub_div = readl(&clk->div_peric1);

CHECK: multiple assignments should be avoided
#47: FILE: arch/arm/cpu/armv7/exynos/clock.c:400:
+		div = sub_div = readl(&clk->div_peric2);

CHECK: multiple assignments should be avoided
#53: FILE: arch/arm/cpu/armv7/exynos/clock.c:405:
+		div = sub_div = readl(&clk->sclk_div_isp);

CHECK: multiple assignments should be avoided
#59: FILE: arch/arm/cpu/armv7/exynos/clock.c:410:
+		div = sub_div = readl(&clk->div_fsys1);

CHECK: multiple assignments should be avoided
#65: FILE: arch/arm/cpu/armv7/exynos/clock.c:415:
+		div = sub_div = readl(&clk->div_fsys2);

total: 0 errors, 0 warnings, 6 checks, 145 lines checked

Thanks.

>  	case PERIPH_ID_SPI0:
>  	case PERIPH_ID_SPI1:
>  		src = readl(&clk->src_peric1);
> -		div = readl(&clk->div_peric1);
> +		div = sub_div = readl(&clk->div_peric1);
>  		break;
>  	case PERIPH_ID_SPI2:
>  		src = readl(&clk->src_peric1);
> -		div = readl(&clk->div_peric2);
> +		div = sub_div = readl(&clk->div_peric2);
>  		break;
>  	case PERIPH_ID_SPI3:
>  	case PERIPH_ID_SPI4:
>  		src = readl(&clk->sclk_src_isp);
> -		div = readl(&clk->sclk_div_isp);
> +		div = sub_div = readl(&clk->sclk_div_isp);
>  		break;
>  	case PERIPH_ID_SDMMC0:
>  	case PERIPH_ID_SDMMC1:
>  		src = readl(&clk->src_fsys);
> -		div = readl(&clk->div_fsys1);
> +		div = sub_div = readl(&clk->div_fsys1);
>  		break;
>  	case PERIPH_ID_SDMMC2:
>  	case PERIPH_ID_SDMMC3:
>  		src = readl(&clk->src_fsys);
> -		div = readl(&clk->div_fsys2);
> +		div = sub_div = readl(&clk->div_fsys2);
>  		break;
>  	case PERIPH_ID_I2C0:
>  	case PERIPH_ID_I2C1:
> @@ -422,12 +422,10 @@ static unsigned long exynos5_get_periph_rate(int peripheral)
>  	case PERIPH_ID_I2C5:
>  	case PERIPH_ID_I2C6:
>  	case PERIPH_ID_I2C7:
> -		sclk = exynos5_get_pll_clk(MPLL);
> -		sub_div = ((readl(&clk->div_top1) >> bit_info->div_bit)
> -			    & bit_info->div_mask) + 1;
> -		div = ((readl(&clk->div_top0) >> bit_info->prediv_bit)
> -			& bit_info->prediv_mask) + 1;
> -		return (sclk / sub_div) / div;
> +		src = EXYNOS_SRC_MPLL;
> +		div = readl(&clk->div_top0);
> +		sub_div = readl(&clk->div_top1);
> +		break;
>  	default:
>  		debug("%s: invalid peripheral %d", __func__, peripheral);
>  		return -1;
> @@ -447,28 +445,28 @@ static unsigned long exynos5_get_periph_rate(int peripheral)
>  		sclk = exynos5_get_pll_clk(VPLL);
>  		break;
>  	default:
> +		debug("%s: EXYNOS_SRC %d not supported\n", __func__, src);
>  		return 0;
>  	}
>  
> -	/* Ratio clock division for this peripheral */
> -	if (bit_info->div_bit >= 0) {
> -		sub_div = (div >> bit_info->div_bit) & bit_info->div_mask;
> -		sub_clk = sclk / (sub_div + 1);
> -	}
> +	/* Clock divider ratio for this peripheral */
> +	if (bit_info->div_bit >= 0)
> +		div = (div >> bit_info->div_bit) & bit_info->div_mask;
>  
> -	if (bit_info->prediv_bit >= 0) {
> -		div = (div >> bit_info->prediv_bit) & bit_info->prediv_mask;
> -		return sub_clk / (div + 1);
> -	}
> +	/* Clock pre-divider ratio for this peripheral */
> +	if (bit_info->prediv_bit >= 0)
> +		sub_div = (sub_div >> bit_info->prediv_bit)
> +			  & bit_info->prediv_mask;
>  
> -	return sub_clk;
> +	/* Calculate and return required clock rate */
> +	return (sclk / (div + 1)) / (sub_div + 1);
>  }
>  
>  static unsigned long exynos542x_get_periph_rate(int peripheral)
>  {
>  	struct clk_bit_info *bit_info = get_clk_bit_info(peripheral);
> -	unsigned long sclk, sub_clk = 0;
> -	unsigned int src, div, sub_div = 0;
> +	unsigned long sclk = 0;
> +	unsigned int src = 0, div = 0, sub_div = 0;
>  	struct exynos5420_clock *clk =
>  			(struct exynos5420_clock *)samsung_get_base_clock();
>  
> @@ -516,10 +514,9 @@ static unsigned long exynos542x_get_periph_rate(int peripheral)
>  	case PERIPH_ID_I2C8:
>  	case PERIPH_ID_I2C9:
>  	case PERIPH_ID_I2C10:
> -		sclk = exynos542x_get_pll_clk(MPLL);
> -		sub_div = ((readl(&clk->div_top1) >> bit_info->div_bit)
> -			    & bit_info->div_mask) + 1;
> -		return sclk / sub_div;
> +		src = EXYNOS542X_SRC_MPLL;
> +		div = readl(&clk->div_top1);
> +		break;
>  	default:
>  		debug("%s: invalid peripheral %d", __func__, peripheral);
>  		return -1;
> @@ -542,22 +539,21 @@ static unsigned long exynos542x_get_periph_rate(int peripheral)
>  		sclk = exynos542x_get_pll_clk(RPLL);
>  		break;
>  	default:
> +		debug("%s: EXYNOS542X_SRC %d not supported", __func__, src);
>  		return 0;
>  	}
>  
> -	/* Ratio clock division for this peripheral */
> -	if (bit_info->div_bit >= 0) {
> +	/* Clock divider ratio for this peripheral */
> +	if (bit_info->div_bit >= 0)
>  		div = (div >> bit_info->div_bit) & bit_info->div_mask;
> -		sub_clk = sclk / (div + 1);
> -	}
>  
> -	if (bit_info->prediv_bit >= 0) {
> +	/* Clock pre-divider ratio for this peripheral */
> +	if (bit_info->prediv_bit >= 0)
>  		sub_div = (sub_div >> bit_info->prediv_bit)
> -						& bit_info->prediv_mask;
> -		return sub_clk / (sub_div + 1);
> -	}
> +			  & bit_info->prediv_mask;
>  
> -	return sub_clk;
> +	/* Calculate and return required clock rate */
> +	return (sclk / (div + 1)) / (sub_div + 1);
>  }
>  
>  unsigned long clock_get_periph_rate(int peripheral)
> 

  reply	other threads:[~2015-02-05  4:40 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-04 10:29 [U-Boot] [PATCH v6 0/7] Exynos5: Fix warnings and enrich clock_get_periph_rate Akshay Saraswat
2015-02-04 10:29 ` [U-Boot] [PATCH v6 1/7] Exynos5: Fix compiler warnings due to clock_get_periph_rate Akshay Saraswat
2015-02-04 10:30 ` [U-Boot] [PATCH v6 2/7] Exynos542x: Move exynos5420_get_pll_clk up and rename Akshay Saraswat
2015-02-04 10:30 ` [U-Boot] [PATCH v6 3/7] Exynos542x: Add and enable get_periph_rate support Akshay Saraswat
2015-02-04 10:30 ` [U-Boot] [PATCH v6 4/7] Exynos5: Fix exynos5_get_periph_rate calculations Akshay Saraswat
2015-02-04 10:30 ` [U-Boot] [PATCH v6 5/7] Exynos5: Use clock_get_periph_rate generic API Akshay Saraswat
2015-02-04 10:30 ` [U-Boot] [PATCH v6 6/7] Exynos: clock: change mask bits as per peripheral Akshay Saraswat
2015-02-04 10:30 ` [U-Boot] [PATCH v6 7/7] Exynos: Clock: Cleanup soc_get_periph_rate Akshay Saraswat
2015-02-05  4:40   ` Joonyoung Shim [this message]
2015-02-05  4:41 ` [U-Boot] [PATCH v6 0/7] Exynos5: Fix warnings and enrich clock_get_periph_rate Joonyoung Shim
2015-02-13  8:25 ` Minkyu Kang

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=54D2F429.90702@samsung.com \
    --to=jy0922.shim@samsung.com \
    --cc=u-boot@lists.denx.de \
    /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