Setting frequency function for programmable oscillator (DS1077L)

hello every one,
I am using Arduino UNO with DS1077L by using the i2c protocol, I am getting 16.67Mhz frequency as shown in the code, the maximum oscillator frequency is 66Mhz. I can generate any frequency between (66.6MHz -8.13k Hz) by using the OUT1 output pin of the oscillator (DS1077L).
The problem is;
I want to to make a function like if I send frequency value in the argument of function the corresponding register should set automatically. According to the required frequency among different frequency range (66.6MHz -8.13k Hz).
like

function(freq_value)// freq_value= any value between range of (66.6MHz -8.13k Hz)
{
//the register should be set according to that frequency (register(0x01) and MUX register( 0x02))
}

I am stuck into that, how can I make this function please help me. I will be very grateful to you.

#include <Wire.h>


const int ds_address = 0x58; //DS1077 default address

void setup() {
  Wire.begin();
  
  Serial.begin(9600);
 
  
  //Initialize DS1077

 i2c_write(ds_address, 0x02, 0x00, 0x00);
  
  
  i2c_write(ds_address, 0x01, 0x00, 0x80);
  
  
   i2c_write(ds_address, 0x0D, 0x08);
  
  i2c_write(ds_address, 0x3F);
  
}

void loop() {

}

void i2c_write(int device, byte address) {
     Wire.beginTransmission(device); //start transmission to device 
     Wire.write(address);        // send register address
     Wire.endTransmission(); //end transmission
}

void i2c_write(int device, byte address, byte val1) {
     Wire.beginTransmission(device); //start transmission to device 
     Wire.write(address);        // send register address
     Wire.write(val1);        // send value to write
     Wire.endTransmission(); //end transmission
}

void i2c_write(int device, byte address, byte val1, byte val2) {
     Wire.beginTransmission(device); //start transmission to device 
     Wire.write(address);        // send register address
     Wire.write(val1);        // send value to write
     Wire.write(val2);        // send value to write
     Wire.endTransmission(); //end transmission
}

The following code might work (not tested):

#define MAIN_FREQ 66000000L
void set_frequency(uint32_t freq) {
  uint32_t tot_div = MAIN_FREQ / freq;
  uint32_t main_div = tot_div / 1024 + 1;
  uint8_t div1 = 0;
  uint8_t p1 = 0;
  uint8_t prescal = 1;
  if (main_div > 7) {
    p1 = 3;
    prescal = 8;
  } else if (main_div > 3) {
    p1 = 2;
    prescal = 4;
  } else if (main_div > 1) {
    p1 = 1;
    prescal = 2;
  }
  int16_t n = tot_div / prescal - 2;
  if (n < 1) {
    n = 0;
    div1 = 1;
  }
  // write MUX
  i2c_write(ds_address, 0x02, p1 >> 1, p1 & 0x01 << 7 | div1 << 6);
  // write DIV
  i2c_write(ds_address, 0x01, n >> 2, n & 0x03 << 6);
}