#define DIV_R_IN 2
static int msi3101_set_usb_adc(struct msi3101_state *s)
{
- int ret, div_n, div_m, div_r_out, f_sr, f_vco;
+ int ret, div_n, div_m, div_r_out, f_sr, f_vco, fract;
u32 reg4, reg3;
/*
* Synthesizer config is just a educated guess...
* [12:10] output divider
* [13] 0 ?
* [14] 0 ?
- * [15] increase sr by max fract
+ * [15] fractional MSB, bit 20
* [16:19] N
* [23:20] ?
* [24:31] 0x01
f_sr = s->ctrl_sampling_rate->val64;
reg3 = 0x01c00303;
+ reg4 = 0x00000004;
for (div_r_out = 4; div_r_out < 16; div_r_out += 2) {
f_vco = f_sr * div_r_out * 12;
div_n = f_vco / (F_REF * DIV_R_IN);
div_m = f_vco % (F_REF * DIV_R_IN);
+ fract = 0x200000ul * div_m / (F_REF * DIV_R_IN);
reg3 |= div_n << 16;
reg3 |= (div_r_out / 2 - 1) << 10;
- reg4 = 0x0ffffful * div_m / F_REF;
-
- if (reg4 >= 0x0ffffful) {
- dev_dbg(&s->udev->dev,
- "%s: extending fractional part value %08x\n",
- __func__, reg4);
- reg4 -= 0x0ffffful;
- reg3 |= 1 << 15;
- }
-
- reg4 = (reg4 << 8) | 0x04;
+ reg3 |= ((fract >> 20) & 0x000001) << 15; /* [20] */
+ reg4 |= ((fract >> 0) & 0x0fffff) << 8; /* [19:0] */
dev_dbg(&s->udev->dev,
- "%s: f_sr=%d f_vco=%d div_n=%d div_m=%d div_r_out=%d reg4=%08x\n",
- __func__, f_sr, f_vco, div_n, div_m, div_r_out, reg4);
+ "%s: f_sr=%d f_vco=%d div_n=%d div_m=%d div_r_out=%d reg3=%08x reg4=%08x\n",
+ __func__, f_sr, f_vco, div_n, div_m, div_r_out, reg3, reg4);
ret = msi3101_ctrl_msg(s, CMD_WREG, 0x00608008);
if (ret)