cdns_i2c_setclk(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… cdns_i2c_setclk β€” the Kernel API Manual, bestie edition ✨

okay so you're looking at cdns_i2c_setclk(9)</p>, straight out of the Kernel API Manual, and honestly? it's a little icon. it does exactly one job and it does it cute: it sets the serial clock rate for the I2C device. that's the whole personality. πŸ’–


✨ SYNOPSIS ✨

int cdns_i2c_setclk (unsigned long clk_in , struct cdns_i2c *id );

yes she returns an int, yes she takes two args, no we will not be normal about it 🫢


πŸŽ€ ARGUMENTS πŸŽ€

  • clk_in β€” the I2C clock input frequency, in Hz. that's her. that's the number you're feeding in πŸ’…
  • id β€” a pointer to the I2C device structure (struct cdns_i2c). your main character struct, fr fr.

🌸 DESCRIPTION 🌸

okay so before you even think about setting these device options, the device has to be idle, not busy transferring data. not me stressing this β€” it's literally in the doc. read the room (and the hardware state) first, bestie 😭

the data rate? set by the values in the control register. and the formula for figuring out the correct register values is:

Fscl = Fpclk/(22 x (divisor_a+1) x (divisor_b+1))

copy that exactly, i don't make the rules, the hardware does. πŸ’€

for a full explanation of setting the serial clock rate, go check the hardware data sheet β€” it's giving required reading, i know, but slay.

⚠️ important vibe check: the clock can not be faster than the input clock divided by 22. no cap. that's the ceiling.

the two most common clock rates are 100KHz and 400KHz β€” the classics, the icons, the ones everyone actually uses ⭐


πŸ‘‘ RETURN πŸ‘‘

  • 0 on success πŸŽ‰
  • negative error otherwise πŸ™ˆ

basically: zero means she ate, negative means something went sideways.


🌈 SEE ALSO 🌈

start with the kernel file itself: ./drivers/i2c/busses/i2c-cadence.c β€” that's where the magic lives 🧚

and then the whole friend group, all of them, no one left out:


and that's the page, bestie!! πŸŽ€ this little beauty lives over in ./drivers/i2c/busses, stamped October 2026 β€” go forth, set those clocks, stay idle before you configure, and remember: divide by 22 or perish πŸ’œβœ¨

πŸ“¦ where this page comes from