Skip to content

Commit ccab425

Browse files
committed
iio: frequency: adf4382: Fix phase bleed constant and phase adjust clamping
Update ADF4382_PHASE_BLEED_CNST_DIV from 285 to 250 and replace the simple 8-bit mask with proper bounds checking and clamping for the phase adjust register value. Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
1 parent a80276d commit ccab425

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

drivers/iio/frequency/adf4382.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@
434434
#define ADF4382_SCRATCHPAD_VAL 0xA5
435435

436436
#define ADF4382_PHASE_BLEED_CNST_MUL 511
437-
#define ADF4382_PHASE_BLEED_CNST_DIV 285
437+
#define ADF4382_PHASE_BLEED_CNST_DIV 250
438438
#define ADF4382_VCO_CAL_CNT 202
439439
#define ADF4382_VCO_CAL_VTUNE 124
440440
#define ADF4382_VCO_CAL_ALC 250
@@ -1267,8 +1267,21 @@ static int adf4382_set_phase_adjust(struct adf4382_state *st, u32 phase_fs)
12671267
phase_value = div_u64(phase_value, PERIOD_IN_DEG);
12681268
phase_value = DIV_ROUND_CLOSEST_ULL(phase_value, MILLI);
12691269

1270-
// Mask the value to 8 bits
1271-
phase_reg_value = phase_value & 0xff;
1270+
if (phase_value == 0 && phase_fs != 0) {
1271+
dev_warn(&st->spi->dev,
1272+
"Phase %u fs too small to represent at Icp %u uA.\n",
1273+
phase_fs, adf4382_ci_ua[st->cp_i]);
1274+
phase_value = 1u;
1275+
}
1276+
1277+
if (phase_value > U8_MAX) {
1278+
dev_warn(&st->spi->dev,
1279+
"Phase adjust register clamped to 255 (computed %llu).\n",
1280+
phase_value);
1281+
phase_value = U8_MAX;
1282+
}
1283+
1284+
phase_reg_value = (u8)phase_value;
12721285

12731286
ret = regmap_write(st->regmap, 0x33, phase_reg_value);
12741287
if (ret)

0 commit comments

Comments
 (0)