Maxim Polyakov has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/39845 )
Change subject: ec/kontron: add option to configure I2C frequency ......................................................................
ec/kontron: add option to configure I2C frequency
Allows to change the frequency for the I2C bus by overriding 2c_freq option from the devicetree of the board. For example, if the bus is not beyond the board, then we can increase the frequency in order to read DMI parameters from EEPROM faster.
Tested on kontron COMe module with T10-TNI carrierboard [1,2]
[1] https://review.coreboot.org/c/coreboot/+/39133 [2]
Change-Id: I36a7ae30f1197f77854634fac3a9e1911ce92093 Signed-off-by: Maxim Polyakov max.senia.poliak@gmail.com --- M src/ec/kontron/kempld/chip.h M src/ec/kontron/kempld/kempld_i2c.c 2 files changed, 20 insertions(+), 4 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/45/39845/1
diff --git a/src/ec/kontron/kempld/chip.h b/src/ec/kontron/kempld/chip.h index 597f281..2b18faf 100644 --- a/src/ec/kontron/kempld/chip.h +++ b/src/ec/kontron/kempld/chip.h @@ -32,6 +32,7 @@
struct ec_kontron_kempld_config { struct kempld_uart uart[KEMPLD_NUM_UARTS]; + unsigned short i2c_freq; };
#endif /* EC_KONTRON_KEMPLD_CHIP_H */ diff --git a/src/ec/kontron/kempld/kempld_i2c.c b/src/ec/kontron/kempld/kempld_i2c.c index ab41097..24297f0c9 100644 --- a/src/ec/kontron/kempld/kempld_i2c.c +++ b/src/ec/kontron/kempld/kempld_i2c.c @@ -27,6 +27,7 @@ #include <timer.h> #include <delay.h>
+#include "chip.h" #include "kempld.h" #include "kempld_internal.h"
@@ -54,8 +55,8 @@ #define I2C_CMD_READ_NACK 0x29 #define I2C_CMD_IACK 0x01
-#define KEMPLD_I2C_FREQ_MAX 2700 /* 2.7 mHz */ -#define KEMPLD_I2C_FREQ_STD 100 /* 100 kHz */ +#define KEMPLD_I2C_FREQ_MAX 2700 /* 2.7 mHz */ +#define KEMPLD_I2C_FREQ_STD_DEFAULT 100 /* 100 kHz */
#define EIO 5 #define ENXIO 6 @@ -244,12 +245,17 @@
void kempld_i2c_device_init(struct device *const dev) { + const struct ec_kontron_kempld_config *const config = dev->chip_info; + unsigned short frequency; u16 prescale_corr; long prescale; u8 ctrl; u8 stat; u8 cfg;
+ if (!config) + return; + if (kempld_get_mutex(100) < 0) return;
@@ -258,11 +264,20 @@ ctrl &= ~(I2C_CTRL_EN | I2C_CTRL_IEN); kempld_write8(KEMPLD_I2C_CTRL, ctrl);
+ frequency = KEMPLD_I2C_FREQ_STD_DEFAULT; + if (config->i2c_freq) { + if (config->i2c_freq <= KEMPLD_I2C_FREQ_MAX) + frequency = config->i2c_freq + else + printk(BIOS_INFO, "kempld_i2c: %d kHz is an invalid frequency value. " + "Set default value %d kHz\n", config->i2c_freq, frequency); + } + const u8 spec_major = KEMPLD_SPEC_GET_MAJOR(kempld_read8(KEMPLD_SPEC)); if (spec_major == 1) - prescale = KEMPLD_CLK / (KEMPLD_I2C_FREQ_STD * 5) - 1000; + prescale = KEMPLD_CLK / (frequency * 5) - 1000; else - prescale = KEMPLD_CLK / (KEMPLD_I2C_FREQ_STD * 4) - 3000; + prescale = KEMPLD_CLK / (frequency * 4) - 3000;
if (prescale < 0) prescale = 0;