* [PATCH] tty: serial: qcom_geni_serial: Remove the UART frequency table
@ 2020-08-12 5:48 satya priya
2020-08-12 7:42 ` Stephen Boyd
0 siblings, 1 reply; 2+ messages in thread
From: satya priya @ 2020-08-12 5:48 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: swboyd, mgautam, linux-arm-msm, linux-serial, akashast, rojay,
msavaliy, satya priya
Use clk_round_rate() API to find a frequency that will work with the
requested baud rate. With this we can avoid updating the table each time
we add a new frquency to the table. We can just call clk_round_rate() and
make sure it is evenly divisible by the requested rate and then it will be
the same as before.
Signed-off-by: satya priya <skakit@codeaurora.org>
---
drivers/tty/serial/qcom_geni_serial.c | 32 +++++++++-----------------------
1 file changed, 9 insertions(+), 23 deletions(-)
diff --git a/drivers/tty/serial/qcom_geni_serial.c b/drivers/tty/serial/qcom_geni_serial.c
index 3aa29d2..312daa24 100644
--- a/drivers/tty/serial/qcom_geni_serial.c
+++ b/drivers/tty/serial/qcom_geni_serial.c
@@ -149,12 +149,6 @@ static unsigned int qcom_geni_serial_tx_empty(struct uart_port *port);
static void qcom_geni_serial_stop_rx(struct uart_port *uport);
static void qcom_geni_serial_handle_rx(struct uart_port *uport, bool drop);
-static const unsigned long root_freq[] = {7372800, 14745600, 19200000, 29491200,
- 32000000, 48000000, 51200000, 64000000,
- 80000000, 96000000, 100000000,
- 102400000, 112000000, 120000000,
- 128000000};
-
#define to_dev_port(ptr, member) \
container_of(ptr, struct qcom_geni_serial_port, member)
@@ -941,30 +935,22 @@ static int qcom_geni_serial_startup(struct uart_port *uport)
return 0;
}
-static unsigned long get_clk_cfg(unsigned long clk_freq)
-{
- int i;
-
- for (i = 0; i < ARRAY_SIZE(root_freq); i++) {
- if (!(root_freq[i] % clk_freq))
- return root_freq[i];
- }
- return 0;
-}
-
-static unsigned long get_clk_div_rate(unsigned int baud,
- unsigned int sampling_rate, unsigned int *clk_div)
+static unsigned long get_clk_div_rate(const struct geni_se *se,
+ unsigned int baud, unsigned int sampling_rate,
+ unsigned int *clk_div)
{
unsigned long ser_clk;
unsigned long desired_clk;
+ long actual_clk;
desired_clk = baud * sampling_rate;
- ser_clk = get_clk_cfg(desired_clk);
- if (!ser_clk) {
+ actual_clk = clk_round_rate(se->clk, desired_clk);
+ if (actual_clk % desired_clk != 0) {
pr_err("%s: Can't find matching DFS entry for baud %d\n",
__func__, baud);
- return ser_clk;
+ return 0;
}
+ ser_clk = actual_clk;
*clk_div = ser_clk / desired_clk;
return ser_clk;
@@ -998,7 +984,7 @@ static void qcom_geni_serial_set_termios(struct uart_port *uport,
if (GENI_SE_VERSION_MAJOR(ver) >= 2 && GENI_SE_VERSION_MINOR(ver) >= 5)
sampling_rate /= 2;
- clk_rate = get_clk_div_rate(baud, sampling_rate, &clk_div);
+ clk_rate = get_clk_div_rate(&port->se, baud, sampling_rate, &clk_div);
if (!clk_rate)
goto out_restart_rx;
--
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] tty: serial: qcom_geni_serial: Remove the UART frequency table
2020-08-12 5:48 [PATCH] tty: serial: qcom_geni_serial: Remove the UART frequency table satya priya
@ 2020-08-12 7:42 ` Stephen Boyd
0 siblings, 0 replies; 2+ messages in thread
From: Stephen Boyd @ 2020-08-12 7:42 UTC (permalink / raw)
To: Greg Kroah-Hartman, satya priya
Cc: mgautam, linux-arm-msm, linux-serial, akashast, rojay, msavaliy,
satya priya
Quoting satya priya (2020-08-11 22:48:48)
> diff --git a/drivers/tty/serial/qcom_geni_serial.c b/drivers/tty/serial/qcom_geni_serial.c
> index 3aa29d2..312daa24 100644
> --- a/drivers/tty/serial/qcom_geni_serial.c
> +++ b/drivers/tty/serial/qcom_geni_serial.c
> @@ -941,30 +935,22 @@ static int qcom_geni_serial_startup(struct uart_port *uport)
> return 0;
> }
>
> -static unsigned long get_clk_cfg(unsigned long clk_freq)
> -{
> - int i;
> -
> - for (i = 0; i < ARRAY_SIZE(root_freq); i++) {
> - if (!(root_freq[i] % clk_freq))
> - return root_freq[i];
> - }
> - return 0;
> -}
> -
> -static unsigned long get_clk_div_rate(unsigned int baud,
> - unsigned int sampling_rate, unsigned int *clk_div)
> +static unsigned long get_clk_div_rate(const struct geni_se *se,
> + unsigned int baud, unsigned int sampling_rate,
> + unsigned int *clk_div)
> {
> unsigned long ser_clk;
> unsigned long desired_clk;
> + long actual_clk;
>
> desired_clk = baud * sampling_rate;
> - ser_clk = get_clk_cfg(desired_clk);
> - if (!ser_clk) {
> + actual_clk = clk_round_rate(se->clk, desired_clk);
> + if (actual_clk % desired_clk != 0) {
The logic isn't the same. Is that a concern? Before we would loop
through all the frequencies this driver knew about and try to find a
frequency that evenly divides by the 'desired_clk'. With this patch
we'll do that calculation exactly once, and ask the clk driver what rate
can be achieved if we call clk_set_rate() with 'desired_clk' as the
argument.
Maybe we need to loop and call clk_round_rate() with 'desired_clk <<= 1'
until it overflows or reaches some limit?
> pr_err("%s: Can't find matching DFS entry for baud %d\n",
> __func__, baud);
> - return ser_clk;
> + return 0;
> }
> + ser_clk = actual_clk;
>
> *clk_div = ser_clk / desired_clk;
> return ser_clk;
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-08-12 7:42 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-12 5:48 [PATCH] tty: serial: qcom_geni_serial: Remove the UART frequency table satya priya
2020-08-12 7:42 ` Stephen Boyd
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).