cdns_uart_calc_baud_divs(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’« cdns_uart_calc_baud_divs πŸ’«

okay so we're in the Kernel API Manual bestie, and today's main character is cdns_uart_calc_baud_divs(9) β€” the little function that does the math so your UART can actually talk at the speed you asked for 🫢


🌸 NAME 🌸

cdns_uart_calc_baud_divs β€” calculate baud rate divisors, no cap, that's literally the whole job ✨


πŸŽ€ SYNOPSIS πŸŽ€

unsigned int cdns_uart_calc_baud_divs (unsigned int clk , unsigned int
baud , u32 *rbdiv , u32 *rcd , int *div8 );

πŸ’… ARGUMENTS πŸ’…

  • clk β€” the UART module input clock, your starting vibe ⏰
  • baud β€” the desired baud rate, aka what you want πŸ”₯
  • rbdiv β€” the BDIV value, and yes it's a return value, it gets filled in for you πŸ’–
  • rcd β€” the CD value, also a return value, also getting filled in πŸŽ€
  • div8 β€” the value for the clk_sel bit in mod, return value too, she's the third output bestie 🌸

πŸ‘‘ RETURN πŸ‘‘

the baud rate πŸ’« β€” specifically: the requested baud when it's possible, or the actual baud when there was too much error, or zero if no valid divisors are found 😭 (that last one is the sad ending, we don't speak of it)


πŸ¦‹ DESCRIPTION πŸ¦‹

okay so the formula to obtain the baud rate is right here and it's giving iconic:

baud_tx/rx rate = clk/CD * (BDIV + 1)

and the details, because they matter:

  • input_clk = (Uart User Defined Clock or Apb Clock) β€” which one it is depends on UCLKEN in the MR Reg 🧚
  • clk = input_clk or input_clk/8 β€” depends on CLKS in the MR reg ⭐
  • CD and BDIV depend on values in the baud rate generate register and the baud rate clock divisor register 🌈

like. it's just divisors all the way down, and honestly? slay πŸ’…


πŸ“ SEE ALSO πŸ“

the kernel file ./drivers/tty/serial/xilinx_uartps.c, plus the whole friend group:


and that's the page!! πŸ’–βœ¨ brought to you straight outta ./drivers/tty/serial, dated October 2026 β€” mwah, go divide some clocks bestie πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from