u-boot.lists.denx.de archive mirror
 help / color / mirror / Atom feed
* [PATCH] serial: zynq: Use DIV_ROUND_CLOSEST() to calcurate divider value
@ 2022-07-13  1:38 Kunihiko Hayashi
  2022-07-15 10:48 ` Michal Simek
  0 siblings, 1 reply; 3+ messages in thread
From: Kunihiko Hayashi @ 2022-07-13  1:38 UTC (permalink / raw)
  To: Michal Simek; +Cc: u-boot, Kunihiko Hayashi

Since the calulation of "bgen" is rounded down, using a higher
baudrate will result in a larger difference from the actual
baudrate. Should use DIV_ROUND_CLOSEST() like the Linux driver.

Signed-off-by: Kunihiko Hayashi <hayashi.kunihiko@socionext.com>
---
 drivers/serial/serial_zynq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/serial/serial_zynq.c b/drivers/serial/serial_zynq.c
index 83adfb5fb98a..857c570c5836 100644
--- a/drivers/serial/serial_zynq.c
+++ b/drivers/serial/serial_zynq.c
@@ -75,7 +75,7 @@ static void _uart_zynq_serial_setbrg(struct uart_zynq *regs,
 	 * Find acceptable values for baud generation.
 	 */
 	for (bdiv = 4; bdiv < 255; bdiv++) {
-		bgen = clock / (baud * (bdiv + 1));
+		bgen = DIV_ROUND_CLOSEST(clock, (baud * (bdiv + 1)));
 		if (bgen < 2 || bgen > 65535)
 			continue;
 
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] serial: zynq: Use DIV_ROUND_CLOSEST() to calcurate divider value
  2022-07-13  1:38 [PATCH] serial: zynq: Use DIV_ROUND_CLOSEST() to calcurate divider value Kunihiko Hayashi
@ 2022-07-15 10:48 ` Michal Simek
  2022-07-16 16:34   ` Kunihiko Hayashi
  0 siblings, 1 reply; 3+ messages in thread
From: Michal Simek @ 2022-07-15 10:48 UTC (permalink / raw)
  To: Kunihiko Hayashi; +Cc: u-boot



On 7/13/22 03:38, Kunihiko Hayashi wrote:
> Since the calulation of "bgen" is rounded down, using a higher
> baudrate will result in a larger difference from the actual
> baudrate. Should use DIV_ROUND_CLOSEST() like the Linux driver.
> 
> Signed-off-by: Kunihiko Hayashi <hayashi.kunihiko@socionext.com>
> ---
>   drivers/serial/serial_zynq.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/serial/serial_zynq.c b/drivers/serial/serial_zynq.c
> index 83adfb5fb98a..857c570c5836 100644
> --- a/drivers/serial/serial_zynq.c
> +++ b/drivers/serial/serial_zynq.c
> @@ -75,7 +75,7 @@ static void _uart_zynq_serial_setbrg(struct uart_zynq *regs,
>   	 * Find acceptable values for baud generation.
>   	 */
>   	for (bdiv = 4; bdiv < 255; bdiv++) {
> -		bgen = clock / (baud * (bdiv + 1));
> +		bgen = DIV_ROUND_CLOSEST(clock, (baud * (bdiv + 1)));

Applied but I have removed one level of () in second parameter which is not needed.

Thanks,
Michal

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] serial: zynq: Use DIV_ROUND_CLOSEST() to calcurate divider value
  2022-07-15 10:48 ` Michal Simek
@ 2022-07-16 16:34   ` Kunihiko Hayashi
  0 siblings, 0 replies; 3+ messages in thread
From: Kunihiko Hayashi @ 2022-07-16 16:34 UTC (permalink / raw)
  To: Michal Simek; +Cc: u-boot

Hi Michal,

On 2022/07/15 19:48, Michal Simek wrote:
> 
> 
> On 7/13/22 03:38, Kunihiko Hayashi wrote:
>> Since the calulation of "bgen" is rounded down, using a higher
>> baudrate will result in a larger difference from the actual
>> baudrate. Should use DIV_ROUND_CLOSEST() like the Linux driver.
>>
>> Signed-off-by: Kunihiko Hayashi <hayashi.kunihiko@socionext.com>
>> ---
>>    drivers/serial/serial_zynq.c | 2 +-
>>    1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/serial/serial_zynq.c b/drivers/serial/serial_zynq.c
>> index 83adfb5fb98a..857c570c5836 100644
>> --- a/drivers/serial/serial_zynq.c
>> +++ b/drivers/serial/serial_zynq.c
>> @@ -75,7 +75,7 @@ static void _uart_zynq_serial_setbrg(struct uart_zynq
>> *regs,
>>    	 * Find acceptable values for baud generation.
>>    	 */
>>    	for (bdiv = 4; bdiv < 255; bdiv++) {
>> -		bgen = clock / (baud * (bdiv + 1));
>> +		bgen = DIV_ROUND_CLOSEST(clock, (baud * (bdiv + 1)));
> 
> Applied but I have removed one level of () in second parameter which is not
> needed.
Sorry I forgot to remove it.
Thanks for pointing out.

---
Best Regards
Kunihiko Hayashi

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-07-16 16:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-13  1:38 [PATCH] serial: zynq: Use DIV_ROUND_CLOSEST() to calcurate divider value Kunihiko Hayashi
2022-07-15 10:48 ` Michal Simek
2022-07-16 16:34   ` Kunihiko Hayashi

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).