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>
This commit is contained in:
Felix Held 2022-01-31 15:52:36 +01:00
parent 2a542da89f
commit 3d945890d8
4 changed files with 10 additions and 13 deletions

View File

@ -687,33 +687,33 @@ static enum cb_err dw_i2c_set_speed(unsigned int bus, enum i2c_speed speed,
* 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(&regs->comp_type) != DW_I2C_COMP_TYPE) {
printk(BIOS_ERR, "I2C bus %u has unknown type 0x%x.\n", bus,
read32(&regs->comp_type));
return -1;
return CB_ERR;
}
printk(BIOS_DEBUG, "I2C bus %u version 0x%x\n", bus, read32(&regs->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 @@ int dw_i2c_init(unsigned int bus, const struct dw_i2c_bus_config *bcfg)
/* 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 @@ int dw_i2c_init(unsigned int bus, const struct dw_i2c_bus_config *bcfg)
printk(BIOS_INFO, "DW I2C bus %u at %p (%u KHz)\n",
bus, regs, speed / KHz);
return 0;
return CB_SUCCESS;
}
/*

View File

@ -95,11 +95,8 @@ uintptr_t dw_i2c_base_address(unsigned int bus);
/*
* 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

View File

@ -96,7 +96,7 @@ static void dw_i2c_soc_init(bool is_early_init)
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;
}

View File

@ -72,7 +72,7 @@ static int lpss_i2c_early_init_bus(unsigned int bus)
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;
}