Steve Chen <[email protected]> writes:

> From: Steve Chen <[email protected]>
>
> Simplify code to calculate MMC/SD memory clock divide.

This looks good to me.

Purushotam, Vipin, any comments?  If looks good, please pull into your
driver for upstream submission, then ack this patch and I'll pull it
into davinci git.

Kevin

> In the original code, much of the logic were dedicated to rounding
> up the memory clock divide (mmc_push_pull).  The code can be simplified
> by rounding up in the algorithm itself.
>
> Original code has
>
>                  cpu_arm_clk
> mmc_push_pull = ------------------- - 1
>                  2 * mmc_req_freq
>
> We can round up by doing
>
>                  cpu_arm_clk + 2 * mmc_req_freq - 1
> mmc_push_pull = ------------------------------------ - 1
>                          2 * mmc_req_freq
>
> Since
>
>       2 * mmc_req_freq
> 1 = -------------------
>       2 * mmc_req_freq
>
> The algorithm becomes
>
>                  cpu_arm_clk + 2 * mmc_req_freq - 1 - 2 * mmc_req_freq
> mmc_push_pull = ------------------------------------------------------
>                          2 * mmc_req_freq
>
> or simply
>
>                  cpu_arm_clk - 1
> mmc_push_pull = ------------------
>                  2 * mmc_req_freq
>
> Signed-off-by: Steve Chen <[email protected]>

> ---
>
>  drivers/mmc/host/davinci_mmc.c |   21 ++++-----------------
>  1 files changed, 4 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/mmc/host/davinci_mmc.c b/drivers/mmc/host/davinci_mmc.c
> index 9b23802..dab8db1 100644
> --- a/drivers/mmc/host/davinci_mmc.c
> +++ b/drivers/mmc/host/davinci_mmc.c
> @@ -719,24 +719,11 @@ static void mmc_davinci_request(struct mmc_host *mmc, 
> struct mmc_request *req)
>       mmc_davinci_start_command(host, req->cmd);
>  }
>  
> -static unsigned int calculate_freq_for_card(struct mmc_davinci_host *host,
> -     unsigned int mmc_req_freq)
> +static inline
> +unsigned int calculate_freq_for_card(struct mmc_davinci_host *host,
> +                                  unsigned int mmc_req_freq)
>  {
> -     unsigned int mmc_freq = 0, cpu_arm_clk = 0, mmc_push_pull = 0;
> -
> -     cpu_arm_clk = host->mmc_input_clk;
> -     if (cpu_arm_clk > (2 * mmc_req_freq))
> -             mmc_push_pull = ((unsigned int)cpu_arm_clk
> -                             / (2 * mmc_req_freq)) - 1;
> -     else
> -             mmc_push_pull = 0;
> -
> -     mmc_freq = (unsigned int)cpu_arm_clk / (2 * (mmc_push_pull + 1));
> -
> -     if (mmc_freq > mmc_req_freq)
> -             mmc_push_pull = mmc_push_pull + 1;
> -
> -     return mmc_push_pull;
> +     return (host->mmc_input_clk - 1) / (mmc_req_freq * 2);
>  }
>  
>  static void mmc_davinci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
>
>
>
> _______________________________________________
> Davinci-linux-open-source mailing list
> [email protected]
> http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source

_______________________________________________
Davinci-linux-open-source mailing list
[email protected]
http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source

Reply via email to