Linux ARM-MSM sub-architecture
 help / color / mirror / Atom feed
From: Jiri Slaby <jirislaby@kernel.org>
To: Vijaya Krishna Nivarthi <quic_vnivarth@quicinc.com>,
	agross@kernel.org, bjorn.andersson@linaro.org,
	konrad.dybcio@somainline.org, gregkh@linuxfoundation.org,
	linux-arm-msm@vger.kernel.org, linux-serial@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: quic_msavaliy@quicinc.com, dianders@chromium.org,
	mka@chromium.org, swboyd@chromium.org
Subject: Re: [V5] tty: serial: qcom-geni-serial: Fix get_clk_div_rate() which otherwise could return a sub-optimal clock rate.
Date: Thu, 14 Jul 2022 12:46:23 +0200	[thread overview]
Message-ID: <b973cfc2-d9a8-5d62-036f-14671cf56799@kernel.org> (raw)
In-Reply-To: <1657629905-24685-1-git-send-email-quic_vnivarth@quicinc.com>

On 12. 07. 22, 14:45, Vijaya Krishna Nivarthi wrote:
...
> +static unsigned long get_clk_div_rate(struct clk *clk, struct device *dev,
> +		unsigned int baud, unsigned int sampling_rate, unsigned int *clk_div)
> +{
> +	unsigned long ser_clk;
> +	unsigned long desired_clk;
> +
> +	desired_clk = baud * sampling_rate;
> +	if (!desired_clk) {
> +		dev_dbg(dev, "Invalid frequency\n");
> +		return 0;
>   	}
>   
> -	*clk_div = ser_clk / desired_clk;
> -	if (!(*clk_div))
> -		*clk_div = 1;
> +	/*
> +	 * try to find a clock rate within 2% tolerance, then within

"then within" ... "5" is missing, perhaps?

> +	 */
> +	ser_clk = find_clk_rate_in_tol(clk, desired_clk, clk_div, 2);
> +	if (!ser_clk)
> +		ser_clk = find_clk_rate_in_tol(clk, desired_clk, clk_div, 5);
> +
> +	if (!ser_clk)
> +		dev_err(dev, "Couldn't find suitable clock rate for %lu\n", desired_clk);
> +	else
> +		dev_dbg(dev, "desired_clk-%lu, ser_clk-%lu, clk_div-%u\n",
> +				desired_clk, ser_clk, *clk_div);
>   
>   	return ser_clk;
>   }
> @@ -1021,8 +1040,8 @@ static void qcom_geni_serial_set_termios(struct uart_port *uport,
>   	if (ver >= QUP_SE_VERSION_2_5)
>   		sampling_rate /= 2;
>   
> -	clk_rate = get_clk_div_rate(port->se.clk, baud,
> -		sampling_rate, &clk_div);
> +	clk_rate = get_clk_div_rate(port->se.clk, port->se.dev, baud,

Maybe worth passing whole geni_se (port->se) then?

> +					sampling_rate, &clk_div);
>   	if (!clk_rate)
>   		goto out_restart_rx;
>   

thanks,
-- 
js
suse labs

  parent reply	other threads:[~2022-07-14 10:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-12 12:45 [V5] tty: serial: qcom-geni-serial: Fix get_clk_div_rate() which otherwise could return a sub-optimal clock rate Vijaya Krishna Nivarthi
2022-07-12 14:11 ` Doug Anderson
2022-07-14 10:46 ` Jiri Slaby [this message]
2022-07-14 13:05   ` Vijaya Krishna Nivarthi

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=b973cfc2-d9a8-5d62-036f-14671cf56799@kernel.org \
    --to=jirislaby@kernel.org \
    --cc=agross@kernel.org \
    --cc=bjorn.andersson@linaro.org \
    --cc=dianders@chromium.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=konrad.dybcio@somainline.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=mka@chromium.org \
    --cc=quic_msavaliy@quicinc.com \
    --cc=quic_vnivarth@quicinc.com \
    --cc=swboyd@chromium.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