drivers/i2c/designware/dw_i2c: return enum cb_err from dw_i2c_init
Using enum cb_err as return type instead of int improves the readability
of the code.
Signed-off-by: Felix Held <felix-coreboot@felixheld.de>
Change-Id: I55e6d93ca141b687871ceaa763bbbbe966c4b4a3
Reviewed-on: https://review.coreboot.org/c/coreboot/+/61511
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Raul Rangel <rrangel@chromium.org>
Reviewed-by: Jason Glenesk <jason.glenesk@gmail.com>
diff --git a/src/drivers/i2c/designware/dw_i2c.c b/src/drivers/i2c/designware/dw_i2c.c
index ec34f42..e29d54f 100644
--- a/src/drivers/i2c/designware/dw_i2c.c
+++ b/src/drivers/i2c/designware/dw_i2c.c
@@ -687,33 +687,33 @@
* The bus speed can be passed in Hz or using values from device/i2c.h and
* will default to I2C_SPEED_FAST if it is not provided.
*/
-int dw_i2c_init(unsigned int bus, const struct dw_i2c_bus_config *bcfg)
+enum cb_err dw_i2c_init(unsigned int bus, const struct dw_i2c_bus_config *bcfg)
{
struct dw_i2c_regs *regs;
enum i2c_speed speed;
if (!bcfg)
- return -1;
+ return CB_ERR;
speed = bcfg->speed ? : I2C_SPEED_FAST;
regs = (struct dw_i2c_regs *)dw_i2c_base_address(bus);
if (!regs) {
printk(BIOS_ERR, "I2C bus %u base address not found\n", bus);
- return -1;
+ return CB_ERR;
}
if (read32(®s->comp_type) != DW_I2C_COMP_TYPE) {
printk(BIOS_ERR, "I2C bus %u has unknown type 0x%x.\n", bus,
read32(®s->comp_type));
- return -1;
+ return CB_ERR;
}
printk(BIOS_DEBUG, "I2C bus %u version 0x%x\n", bus, read32(®s->comp_version));
if (dw_i2c_disable(regs) != CB_SUCCESS) {
printk(BIOS_ERR, "I2C timeout disabling bus %u\n", bus);
- return -1;
+ return CB_ERR;
}
/* Put controller in master mode with restart enabled */
@@ -723,7 +723,7 @@
/* Set bus speed to FAST by default */
if (dw_i2c_set_speed(bus, speed, bcfg) != CB_SUCCESS) {
printk(BIOS_ERR, "I2C failed to set speed for bus %u\n", bus);
- return -1;
+ return CB_ERR;
}
/* Set RX/TX thresholds to smallest values */
@@ -736,7 +736,7 @@
printk(BIOS_INFO, "DW I2C bus %u at %p (%u KHz)\n",
bus, regs, speed / KHz);
- return 0;
+ return CB_SUCCESS;
}
/*
diff --git a/src/drivers/i2c/designware/dw_i2c.h b/src/drivers/i2c/designware/dw_i2c.h
index c010b11..64e27c0 100644
--- a/src/drivers/i2c/designware/dw_i2c.h
+++ b/src/drivers/i2c/designware/dw_i2c.h
@@ -95,11 +95,8 @@
/*
* Initialize this bus controller and set the speed
- * Return value:
- * -1 = failure
- * 0 = success
*/
-int dw_i2c_init(unsigned int bus, const struct dw_i2c_bus_config *bcfg);
+enum cb_err dw_i2c_init(unsigned int bus, const struct dw_i2c_bus_config *bcfg);
/*
* Generate speed config based on clock
diff --git a/src/soc/amd/common/block/i2c/i2c.c b/src/soc/amd/common/block/i2c/i2c.c
index a70645c..733ad88 100644
--- a/src/soc/amd/common/block/i2c/i2c.c
+++ b/src/soc/amd/common/block/i2c/i2c.c
@@ -96,7 +96,7 @@
cfg->early_init != is_early_init)
continue;
- if (dw_i2c_init(bus, cfg)) {
+ if (dw_i2c_init(bus, cfg) != CB_SUCCESS) {
printk(BIOS_ERR, "Failed to init i2c bus %u\n", bus);
continue;
}
diff --git a/src/soc/intel/common/block/i2c/i2c.c b/src/soc/intel/common/block/i2c/i2c.c
index acc23ab..7fdf818 100644
--- a/src/soc/intel/common/block/i2c/i2c.c
+++ b/src/soc/intel/common/block/i2c/i2c.c
@@ -72,7 +72,7 @@
lpss_set_power_state(dev, STATE_D0);
/* Initialize the controller */
- if (dw_i2c_init(bus, config) < 0) {
+ if (dw_i2c_init(bus, config) != CB_SUCCESS) {
printk(BIOS_ERR, "I2C%u failed to initialize\n", bus);
return -1;
}