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:
parent
2a542da89f
commit
3d945890d8
|
@ -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
|
* 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.
|
* 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;
|
struct dw_i2c_regs *regs;
|
||||||
enum i2c_speed speed;
|
enum i2c_speed speed;
|
||||||
|
|
||||||
if (!bcfg)
|
if (!bcfg)
|
||||||
return -1;
|
return CB_ERR;
|
||||||
|
|
||||||
speed = bcfg->speed ? : I2C_SPEED_FAST;
|
speed = bcfg->speed ? : I2C_SPEED_FAST;
|
||||||
|
|
||||||
regs = (struct dw_i2c_regs *)dw_i2c_base_address(bus);
|
regs = (struct dw_i2c_regs *)dw_i2c_base_address(bus);
|
||||||
if (!regs) {
|
if (!regs) {
|
||||||
printk(BIOS_ERR, "I2C bus %u base address not found\n", bus);
|
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) {
|
if (read32(®s->comp_type) != DW_I2C_COMP_TYPE) {
|
||||||
printk(BIOS_ERR, "I2C bus %u has unknown type 0x%x.\n", bus,
|
printk(BIOS_ERR, "I2C bus %u has unknown type 0x%x.\n", bus,
|
||||||
read32(®s->comp_type));
|
read32(®s->comp_type));
|
||||||
return -1;
|
return CB_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
printk(BIOS_DEBUG, "I2C bus %u version 0x%x\n", bus, read32(®s->comp_version));
|
printk(BIOS_DEBUG, "I2C bus %u version 0x%x\n", bus, read32(®s->comp_version));
|
||||||
|
|
||||||
if (dw_i2c_disable(regs) != CB_SUCCESS) {
|
if (dw_i2c_disable(regs) != CB_SUCCESS) {
|
||||||
printk(BIOS_ERR, "I2C timeout disabling bus %u\n", bus);
|
printk(BIOS_ERR, "I2C timeout disabling bus %u\n", bus);
|
||||||
return -1;
|
return CB_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Put controller in master mode with restart enabled */
|
/* 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 */
|
/* Set bus speed to FAST by default */
|
||||||
if (dw_i2c_set_speed(bus, speed, bcfg) != CB_SUCCESS) {
|
if (dw_i2c_set_speed(bus, speed, bcfg) != CB_SUCCESS) {
|
||||||
printk(BIOS_ERR, "I2C failed to set speed for bus %u\n", bus);
|
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 */
|
/* 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",
|
printk(BIOS_INFO, "DW I2C bus %u at %p (%u KHz)\n",
|
||||||
bus, regs, speed / KHz);
|
bus, regs, speed / KHz);
|
||||||
|
|
||||||
return 0;
|
return CB_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -95,11 +95,8 @@ uintptr_t dw_i2c_base_address(unsigned int bus);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize this bus controller and set the speed
|
* 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
|
* Generate speed config based on clock
|
||||||
|
|
|
@ -96,7 +96,7 @@ static void dw_i2c_soc_init(bool is_early_init)
|
||||||
cfg->early_init != is_early_init)
|
cfg->early_init != is_early_init)
|
||||||
continue;
|
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);
|
printk(BIOS_ERR, "Failed to init i2c bus %u\n", bus);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,7 @@ static int lpss_i2c_early_init_bus(unsigned int bus)
|
||||||
lpss_set_power_state(dev, STATE_D0);
|
lpss_set_power_state(dev, STATE_D0);
|
||||||
|
|
||||||
/* Initialize the controller */
|
/* 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);
|
printk(BIOS_ERR, "I2C%u failed to initialize\n", bus);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue