Skip to content

Commit 9948c29

Browse files
GTLin08nashif
authored andcommitted
ITE: drivers/i2c: Adjust the prescale of I2C SCL low and high period
When adjusting the prescale to increase the I2C SCL low period, the high period must also be subtracted to maintain a consistent frequency. Signed-off-by: Tim Lin <[email protected]>
1 parent ba11dc8 commit 9948c29

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

drivers/i2c/i2c_ite_enhance.c

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,9 @@ static void i2c_enhanced_port_set_frequency(const struct device *dev,
294294
int freq_hz)
295295
{
296296
const struct i2c_enhance_config *config = dev->config;
297-
uint32_t clk_div, psr, pll_clock;
297+
uint32_t clk_div, psr, pll_clock, psr_h, psr_l;
298298
uint8_t *base = config->base;
299+
uint8_t prescale_scl = config->prescale_scl_low;
299300

300301
pll_clock = chip_get_pll_freq();
301302
/*
@@ -318,11 +319,28 @@ static void i2c_enhanced_port_set_frequency(const struct device *dev,
318319
}
319320

320321
/* Adjust SCL low period prescale */
321-
psr += config->prescale_scl_low;
322+
psr_l = psr + prescale_scl;
323+
if (psr_l > 0xFD) {
324+
psr_l = 0xFD;
325+
LOG_WRN("(psr + prescale_scl) can not be greater than 0xfd.");
326+
}
327+
328+
/*
329+
* Adjust SCL high period prescale
330+
* The property setting prescale_scl must be less than psr and
331+
* the minimum value of psr_h is 2.
332+
*/
333+
if (psr > (prescale_scl + 2)) {
334+
psr_h = psr - prescale_scl;
335+
} else {
336+
psr_h = 2;
337+
LOG_WRN("prescale_scl_low should be less than (psr - 2).");
338+
}
322339

323-
/* Set I2C Speed */
324-
IT8XXX2_I2C_PSR(base) = psr & 0xFF;
325-
IT8XXX2_I2C_HSPR(base) = psr & 0xFF;
340+
/* Set I2C Speed for SCL low period. */
341+
IT8XXX2_I2C_PSR(base) = psr_l & 0xFF;
342+
/* Set I2C Speed for SCL high period. */
343+
IT8XXX2_I2C_HSPR(base) = psr_h & 0xFF;
326344
}
327345

328346
}

0 commit comments

Comments
 (0)