aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio/frequency/adf4350.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/iio/frequency/adf4350.c')
-rw-r--r--drivers/iio/frequency/adf4350.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/drivers/iio/frequency/adf4350.c b/drivers/iio/frequency/adf4350.c
index 59fbb3ae40e7..e35bb8f6fe75 100644
--- a/drivers/iio/frequency/adf4350.c
+++ b/drivers/iio/frequency/adf4350.c
@@ -129,7 +129,7 @@ static int adf4350_set_freq(struct adf4350_state *st, unsigned long long freq)
129{ 129{
130 struct adf4350_platform_data *pdata = st->pdata; 130 struct adf4350_platform_data *pdata = st->pdata;
131 u64 tmp; 131 u64 tmp;
132 u32 div_gcd, prescaler; 132 u32 div_gcd, prescaler, chspc;
133 u16 mdiv, r_cnt = 0; 133 u16 mdiv, r_cnt = 0;
134 u8 band_sel_div; 134 u8 band_sel_div;
135 135
@@ -158,14 +158,20 @@ static int adf4350_set_freq(struct adf4350_state *st, unsigned long long freq)
158 if (pdata->ref_div_factor) 158 if (pdata->ref_div_factor)
159 r_cnt = pdata->ref_div_factor - 1; 159 r_cnt = pdata->ref_div_factor - 1;
160 160
161 do { 161 chspc = st->chspc;
162 r_cnt = adf4350_tune_r_cnt(st, r_cnt);
163 162
164 st->r1_mod = st->fpfd / st->chspc; 163 do {
165 while (st->r1_mod > ADF4350_MAX_MODULUS) { 164 do {
166 r_cnt = adf4350_tune_r_cnt(st, r_cnt); 165 do {
167 st->r1_mod = st->fpfd / st->chspc; 166 r_cnt = adf4350_tune_r_cnt(st, r_cnt);
168 } 167 st->r1_mod = st->fpfd / chspc;
168 if (r_cnt > ADF4350_MAX_R_CNT) {
169 /* try higher spacing values */
170 chspc++;
171 r_cnt = 0;
172 }
173 } while ((st->r1_mod > ADF4350_MAX_MODULUS) && r_cnt);
174 } while (r_cnt == 0);
169 175
170 tmp = freq * (u64)st->r1_mod + (st->fpfd > 1); 176 tmp = freq * (u64)st->r1_mod + (st->fpfd > 1);
171 do_div(tmp, st->fpfd); /* Div round closest (n + d/2)/d */ 177 do_div(tmp, st->fpfd); /* Div round closest (n + d/2)/d */
@@ -194,7 +200,7 @@ static int adf4350_set_freq(struct adf4350_state *st, unsigned long long freq)
194 st->regs[ADF4350_REG0] = ADF4350_REG0_INT(st->r0_int) | 200 st->regs[ADF4350_REG0] = ADF4350_REG0_INT(st->r0_int) |
195 ADF4350_REG0_FRACT(st->r0_fract); 201 ADF4350_REG0_FRACT(st->r0_fract);
196 202
197 st->regs[ADF4350_REG1] = ADF4350_REG1_PHASE(0) | 203 st->regs[ADF4350_REG1] = ADF4350_REG1_PHASE(1) |
198 ADF4350_REG1_MOD(st->r1_mod) | 204 ADF4350_REG1_MOD(st->r1_mod) |
199 prescaler; 205 prescaler;
200 206