Maxim Polyakov has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/44476 )
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 i2c_freq_khz option from the devicetree of the board.
Tested on Kontron mAL10 COMe module with T10-TNI carrierboard [1,2].
[1] https: //review.coreboot.org/c/coreboot/+/39133 [2] https: //review.coreboot.org/c/coreboot/+/39846
Change-Id: If0eb477af10d00eb4f17f9c01209f170b746ad3d 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, 22 insertions(+), 4 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/76/44476/1
diff --git a/src/ec/kontron/kempld/chip.h b/src/ec/kontron/kempld/chip.h index 8ca8d24..2ac0949 100644 --- a/src/ec/kontron/kempld/chip.h +++ b/src/ec/kontron/kempld/chip.h @@ -19,6 +19,7 @@
struct ec_kontron_kempld_config { struct kempld_uart uart[KEMPLD_NUM_UARTS]; + unsigned short i2c_freq_khz; };
#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 296cf76..9ba2f71 100644 --- a/src/ec/kontron/kempld/kempld_i2c.c +++ b/src/ec/kontron/kempld/kempld_i2c.c @@ -13,6 +13,7 @@ #include <timer.h> #include <delay.h>
+#include "chip.h" #include "kempld.h" #include "kempld_internal.h"
@@ -40,8 +41,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 @@ -230,12 +231,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;
@@ -244,11 +250,22 @@ ctrl &= ~(I2C_CTRL_EN | I2C_CTRL_IEN); kempld_write8(KEMPLD_I2C_CTRL, ctrl);
+ frequency = KEMPLD_I2C_FREQ_STD_DEFAULT; + if (config->i2c_freq_khz) { + if (config->i2c_freq_khz <= KEMPLD_I2C_FREQ_MAX) + frequency = config->i2c_freq_khz; + else + printk(BIOS_WARNING, + "kempld_i2c: %d kHz is an invalid frequency value\n", + config->i2c_freq_khz); + } + printk(BIOS_INFO, "kempld_i2c: Use frequency %d\n", 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;