Hello everyone,

I have kernel driver that I need to make some division math. Here is the document that describe the computation:

https://www.silabs.com/Support%20Documents/TechnicalDocs/Si514.pdf

check this section: 2.2. Programming a Small Frequency Change (sub ±1000 ppm) I have the following logic:

/* Multiplier/divider settings */

struct tSi514_muldiv

{

u32 m_frac; /* 29-bit Fractional part of multiplier M */

u8 m_int; /* Integer part of multiplier M, 65..78 */

u8 ls_div_bits; /* 2nd divider, as 2^x */

u16 hs_div; /* 1st divider, must be even and 10<=x<=1022 */

};

struct tSi514_muldiv settings;

/* I have the following */

u64 desiredFrequency = currentFreq + shiftValHz;

u64 current_M = dev_data->settings.m_frac | ((__u64) dev_data->settings.m_int << 29);

/* Now I need to compute the new M */

/* As the link I sent you above the computation should be like this

u64 new_M = current_M x desiredFrequency / currentFreq */

Any thoughts how can you compute the above equation in Linux kernel??

Hi,

This forum is not meant to ask random Linux questions.

It about support for Analog Devices Linux device drivers.

Nevertheless take a look here -

linux/adf5355.c at xcomm_zynq · analogdevicesinc/linux · GitHub

do_div() (Linux/include/asm-generic/div64.h - Linux Cross Reference - Free Electrons) is one way to do 64-bit divide and modulo operation. The other ones can be found here: Linux/include/linux/math64.h - Linux Cross Reference - Free Electrons

-Michael