AnsweredAssumed Answered

Division in linux kernel

Question asked by alsanie80 on Jan 28, 2016
Latest reply on Feb 2, 2016 by milosoftware

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

Outcomes