[PATCH] serial: zynq: Use DIV_ROUND_CLOSEST() to calcurate divider value

Kunihiko Hayashi hayashi.kunihiko at socionext.com
Sat Jul 16 18:34:36 CEST 2022


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 at 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


More information about the U-Boot mailing list