drivers/i2c/designware/dw_i2c: use enum cb_err for static functions
Using enum cb_err as return type instead of int improves the readability of the code. This commit only changes the return value of the static functions in this file keeping the external interface identical. Signed-off-by: Felix Held <felix-coreboot@felixheld.de> Change-Id: I80300e0b24591fc660c3134139b9257e002cdbbb Reviewed-on: https://review.coreboot.org/c/coreboot/+/61510 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Raul Rangel <rrangel@chromium.org>
This commit is contained in:
parent
78695fd969
commit
2a542da89f
|
@ -265,7 +265,7 @@ static void dw_i2c_enable(struct dw_i2c_regs *regs)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Disable this I2C controller */
|
/* Disable this I2C controller */
|
||||||
static int dw_i2c_disable(struct dw_i2c_regs *regs)
|
static enum cb_err dw_i2c_disable(struct dw_i2c_regs *regs)
|
||||||
{
|
{
|
||||||
uint32_t enable = read32(®s->enable);
|
uint32_t enable = read32(®s->enable);
|
||||||
|
|
||||||
|
@ -278,14 +278,14 @@ static int dw_i2c_disable(struct dw_i2c_regs *regs)
|
||||||
stopwatch_init_usecs_expire(&sw, DW_I2C_TIMEOUT_US);
|
stopwatch_init_usecs_expire(&sw, DW_I2C_TIMEOUT_US);
|
||||||
while (read32(®s->enable_status) & ENABLE_CONTROLLER)
|
while (read32(®s->enable_status) & ENABLE_CONTROLLER)
|
||||||
if (stopwatch_expired(&sw))
|
if (stopwatch_expired(&sw))
|
||||||
return -1;
|
return CB_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return CB_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Wait for this I2C controller to go idle for transmit */
|
/* Wait for this I2C controller to go idle for transmit */
|
||||||
static int dw_i2c_wait_for_bus_idle(struct dw_i2c_regs *regs)
|
static enum cb_err dw_i2c_wait_for_bus_idle(struct dw_i2c_regs *regs)
|
||||||
{
|
{
|
||||||
struct stopwatch sw;
|
struct stopwatch sw;
|
||||||
|
|
||||||
|
@ -301,17 +301,17 @@ static int dw_i2c_wait_for_bus_idle(struct dw_i2c_regs *regs)
|
||||||
|
|
||||||
/* Check for TX FIFO empty to indicate TX idle */
|
/* Check for TX FIFO empty to indicate TX idle */
|
||||||
if (status & STATUS_TX_FIFO_EMPTY)
|
if (status & STATUS_TX_FIFO_EMPTY)
|
||||||
return 0;
|
return CB_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Timed out while waiting for bus to go idle */
|
/* Timed out while waiting for bus to go idle */
|
||||||
return -1;
|
return CB_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Transfer one byte of one segment, sending stop bit if requested */
|
/* Transfer one byte of one segment, sending stop bit if requested */
|
||||||
static int dw_i2c_transfer_byte(struct dw_i2c_regs *regs,
|
static enum cb_err dw_i2c_transfer_byte(struct dw_i2c_regs *regs,
|
||||||
const struct i2c_msg *segment,
|
const struct i2c_msg *segment,
|
||||||
size_t byte, int send_stop)
|
size_t byte, int send_stop)
|
||||||
{
|
{
|
||||||
struct stopwatch sw;
|
struct stopwatch sw;
|
||||||
uint32_t cmd = CMD_DATA_CMD; /* Read op */
|
uint32_t cmd = CMD_DATA_CMD; /* Read op */
|
||||||
|
@ -323,7 +323,7 @@ static int dw_i2c_transfer_byte(struct dw_i2c_regs *regs,
|
||||||
while (!(read32(®s->status) & STATUS_TX_FIFO_NOT_FULL)) {
|
while (!(read32(®s->status) & STATUS_TX_FIFO_NOT_FULL)) {
|
||||||
if (stopwatch_expired(&sw)) {
|
if (stopwatch_expired(&sw)) {
|
||||||
printk(BIOS_ERR, "I2C transmit timeout\n");
|
printk(BIOS_ERR, "I2C transmit timeout\n");
|
||||||
return -1;
|
return CB_ERR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cmd = segment->buf[byte];
|
cmd = segment->buf[byte];
|
||||||
|
@ -340,27 +340,27 @@ static int dw_i2c_transfer_byte(struct dw_i2c_regs *regs,
|
||||||
while (!(read32(®s->status) & STATUS_RX_FIFO_NOT_EMPTY)) {
|
while (!(read32(®s->status) & STATUS_RX_FIFO_NOT_EMPTY)) {
|
||||||
if (stopwatch_expired(&sw)) {
|
if (stopwatch_expired(&sw)) {
|
||||||
printk(BIOS_ERR, "I2C receive timeout\n");
|
printk(BIOS_ERR, "I2C receive timeout\n");
|
||||||
return -1;
|
return CB_ERR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
segment->buf[byte] = read32(®s->cmd_data);
|
segment->buf[byte] = read32(®s->cmd_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return CB_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _dw_i2c_transfer(unsigned int bus, const struct i2c_msg *segments,
|
static enum cb_err _dw_i2c_transfer(unsigned int bus, const struct i2c_msg *segments,
|
||||||
size_t count)
|
size_t count)
|
||||||
{
|
{
|
||||||
struct stopwatch sw;
|
struct stopwatch sw;
|
||||||
struct dw_i2c_regs *regs;
|
struct dw_i2c_regs *regs;
|
||||||
size_t byte;
|
size_t byte;
|
||||||
int ret = -1;
|
enum cb_err ret = CB_ERR;
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The assumption is that the host controller is disabled -- either
|
/* The assumption is that the host controller is disabled -- either
|
||||||
|
@ -388,8 +388,8 @@ static int _dw_i2c_transfer(unsigned int bus, const struct i2c_msg *segments,
|
||||||
* Repeated start will be automatically generated
|
* Repeated start will be automatically generated
|
||||||
* by the controller on R->W or W->R switch.
|
* by the controller on R->W or W->R switch.
|
||||||
*/
|
*/
|
||||||
if (dw_i2c_transfer_byte(regs, segments, byte,
|
if (dw_i2c_transfer_byte(regs, segments, byte, count == 0) !=
|
||||||
count == 0) < 0) {
|
CB_SUCCESS) {
|
||||||
printk(BIOS_ERR, "I2C %s failed: bus %u "
|
printk(BIOS_ERR, "I2C %s failed: bus %u "
|
||||||
"addr 0x%02x\n",
|
"addr 0x%02x\n",
|
||||||
(segments->flags & I2C_M_RD) ?
|
(segments->flags & I2C_M_RD) ?
|
||||||
|
@ -430,7 +430,7 @@ static int _dw_i2c_transfer(unsigned int bus, const struct i2c_msg *segments,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Wait for the bus to go idle */
|
/* Wait for the bus to go idle */
|
||||||
if (dw_i2c_wait_for_bus_idle(regs)) {
|
if (dw_i2c_wait_for_bus_idle(regs) != CB_SUCCESS) {
|
||||||
printk(BIOS_ERR, "I2C timeout waiting for bus %u idle\n", bus);
|
printk(BIOS_ERR, "I2C timeout waiting for bus %u idle\n", bus);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
@ -445,7 +445,7 @@ static int _dw_i2c_transfer(unsigned int bus, const struct i2c_msg *segments,
|
||||||
read32(®s->cmd_data);
|
read32(®s->cmd_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
ret = CB_SUCCESS;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
read32(®s->clear_intr);
|
read32(®s->clear_intr);
|
||||||
|
@ -468,14 +468,14 @@ int dw_i2c_transfer(unsigned int bus, const struct i2c_msg *msg, size_t count)
|
||||||
|
|
||||||
for (i = 0, start = 0; i < count; i++, msg++) {
|
for (i = 0, start = 0; i < count; i++, msg++) {
|
||||||
if (addr != msg->slave) {
|
if (addr != msg->slave) {
|
||||||
if (_dw_i2c_transfer(bus, &orig_msg[start], i - start))
|
if (_dw_i2c_transfer(bus, &orig_msg[start], i - start) != CB_SUCCESS)
|
||||||
return -1;
|
return -1;
|
||||||
start = i;
|
start = i;
|
||||||
addr = msg->slave;
|
addr = msg->slave;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return _dw_i2c_transfer(bus, &orig_msg[start], count - start);
|
return _dw_i2c_transfer(bus, &orig_msg[start], count - start) == CB_SUCCESS ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Global I2C bus handler, defined in include/device/i2c_simple.h */
|
/* Global I2C bus handler, defined in include/device/i2c_simple.h */
|
||||||
|
@ -484,19 +484,19 @@ int platform_i2c_transfer(unsigned int bus, struct i2c_msg *msg, int count)
|
||||||
return dw_i2c_transfer(bus, msg, count < 0 ? 0 : count);
|
return dw_i2c_transfer(bus, msg, count < 0 ? 0 : count);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dw_i2c_set_speed_config(unsigned int bus,
|
static enum cb_err dw_i2c_set_speed_config(unsigned int bus,
|
||||||
const struct dw_i2c_speed_config *config)
|
const struct dw_i2c_speed_config *config)
|
||||||
{
|
{
|
||||||
struct dw_i2c_regs *regs;
|
struct dw_i2c_regs *regs;
|
||||||
void *hcnt_reg, *lcnt_reg;
|
void *hcnt_reg, *lcnt_reg;
|
||||||
|
|
||||||
regs = (struct dw_i2c_regs *)dw_i2c_base_address(bus);
|
regs = (struct dw_i2c_regs *)dw_i2c_base_address(bus);
|
||||||
if (!regs || !config)
|
if (!regs || !config)
|
||||||
return -1;
|
return CB_ERR;
|
||||||
|
|
||||||
/* Nothing to do if no values are set */
|
/* Nothing to do if no values are set */
|
||||||
if (!config->scl_lcnt && !config->scl_hcnt && !config->sda_hold)
|
if (!config->scl_lcnt && !config->scl_hcnt && !config->sda_hold)
|
||||||
return 0;
|
return CB_SUCCESS;
|
||||||
|
|
||||||
if (config->speed >= I2C_SPEED_HIGH) {
|
if (config->speed >= I2C_SPEED_HIGH) {
|
||||||
/* High and Fast Ultra speed */
|
/* High and Fast Ultra speed */
|
||||||
|
@ -522,14 +522,14 @@ static int dw_i2c_set_speed_config(unsigned int bus,
|
||||||
if (config->sda_hold)
|
if (config->sda_hold)
|
||||||
write32(®s->sda_hold, config->sda_hold);
|
write32(®s->sda_hold, config->sda_hold);
|
||||||
|
|
||||||
return 0;
|
return CB_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dw_i2c_gen_config_rise_fall_time(struct dw_i2c_regs *regs,
|
static enum cb_err dw_i2c_gen_config_rise_fall_time(struct dw_i2c_regs *regs,
|
||||||
enum i2c_speed speed,
|
enum i2c_speed speed,
|
||||||
const struct dw_i2c_bus_config *bcfg,
|
const struct dw_i2c_bus_config *bcfg,
|
||||||
int ic_clk,
|
int ic_clk,
|
||||||
struct dw_i2c_speed_config *config)
|
struct dw_i2c_speed_config *config)
|
||||||
{
|
{
|
||||||
const struct i2c_descriptor *bus;
|
const struct i2c_descriptor *bus;
|
||||||
const struct soc_clock *soc;
|
const struct soc_clock *soc;
|
||||||
|
@ -542,13 +542,13 @@ static int dw_i2c_gen_config_rise_fall_time(struct dw_i2c_regs *regs,
|
||||||
|
|
||||||
if (bus == NULL) {
|
if (bus == NULL) {
|
||||||
printk(BIOS_ERR, "dw_i2c: invalid bus speed %d\n", speed);
|
printk(BIOS_ERR, "dw_i2c: invalid bus speed %d\n", speed);
|
||||||
return -1;
|
return CB_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (soc == NULL) {
|
if (soc == NULL) {
|
||||||
printk(BIOS_ERR, "dw_i2c: invalid SoC clock speed %d MHz\n",
|
printk(BIOS_ERR, "dw_i2c: invalid SoC clock speed %d MHz\n",
|
||||||
ic_clk);
|
ic_clk);
|
||||||
return -1;
|
return CB_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the proper spike suppression count based on target speed. */
|
/* Get the proper spike suppression count based on target speed. */
|
||||||
|
@ -583,7 +583,7 @@ static int dw_i2c_gen_config_rise_fall_time(struct dw_i2c_regs *regs,
|
||||||
if (hcnt < 0 || lcnt < 0) {
|
if (hcnt < 0 || lcnt < 0) {
|
||||||
printk(BIOS_ERR, "dw_i2c: bad counts. hcnt = %d lcnt = %d\n",
|
printk(BIOS_ERR, "dw_i2c: bad counts. hcnt = %d lcnt = %d\n",
|
||||||
hcnt, lcnt);
|
hcnt, lcnt);
|
||||||
return -1;
|
return CB_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now add things back up to ensure the period is hit. If off,
|
/* Now add things back up to ensure the period is hit. If off,
|
||||||
|
@ -612,7 +612,7 @@ static int dw_i2c_gen_config_rise_fall_time(struct dw_i2c_regs *regs,
|
||||||
printk(DW_I2C_DEBUG, "dw_i2c: hcnt = %d lcnt = %d sda hold = %d\n",
|
printk(DW_I2C_DEBUG, "dw_i2c: hcnt = %d lcnt = %d sda hold = %d\n",
|
||||||
hcnt, lcnt, config->sda_hold);
|
hcnt, lcnt, config->sda_hold);
|
||||||
|
|
||||||
return 0;
|
return CB_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int dw_i2c_gen_speed_config(uintptr_t dw_i2c_addr,
|
int dw_i2c_gen_speed_config(uintptr_t dw_i2c_addr,
|
||||||
|
@ -638,11 +638,12 @@ int dw_i2c_gen_speed_config(uintptr_t dw_i2c_addr,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Use the time calculation. */
|
/* Use the time calculation. */
|
||||||
return dw_i2c_gen_config_rise_fall_time(regs, speed, bcfg, ic_clk, config);
|
return dw_i2c_gen_config_rise_fall_time(regs, speed, bcfg, ic_clk, config) ==
|
||||||
|
CB_SUCCESS ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dw_i2c_set_speed(unsigned int bus, enum i2c_speed speed,
|
static enum cb_err dw_i2c_set_speed(unsigned int bus, enum i2c_speed speed,
|
||||||
const struct dw_i2c_bus_config *bcfg)
|
const struct dw_i2c_bus_config *bcfg)
|
||||||
{
|
{
|
||||||
struct dw_i2c_regs *regs;
|
struct dw_i2c_regs *regs;
|
||||||
struct dw_i2c_speed_config config;
|
struct dw_i2c_speed_config config;
|
||||||
|
@ -651,7 +652,7 @@ static int dw_i2c_set_speed(unsigned int bus, enum i2c_speed speed,
|
||||||
/* Clock must be provided by Kconfig */
|
/* Clock must be provided by Kconfig */
|
||||||
regs = (struct dw_i2c_regs *)dw_i2c_base_address(bus);
|
regs = (struct dw_i2c_regs *)dw_i2c_base_address(bus);
|
||||||
if (!regs || !speed)
|
if (!regs || !speed)
|
||||||
return -1;
|
return CB_ERR;
|
||||||
|
|
||||||
control = read32(®s->control);
|
control = read32(®s->control);
|
||||||
control &= ~CONTROL_SPEED_MASK;
|
control &= ~CONTROL_SPEED_MASK;
|
||||||
|
@ -669,7 +670,7 @@ static int dw_i2c_set_speed(unsigned int bus, enum i2c_speed speed,
|
||||||
|
|
||||||
/* Generate speed config based on clock */
|
/* Generate speed config based on clock */
|
||||||
if (dw_i2c_gen_speed_config((uintptr_t)regs, speed, bcfg, &config) < 0)
|
if (dw_i2c_gen_speed_config((uintptr_t)regs, speed, bcfg, &config) < 0)
|
||||||
return -1;
|
return CB_ERR;
|
||||||
|
|
||||||
/* Select this speed in the control register */
|
/* Select this speed in the control register */
|
||||||
write32(®s->control, control);
|
write32(®s->control, control);
|
||||||
|
@ -677,7 +678,7 @@ static int dw_i2c_set_speed(unsigned int bus, enum i2c_speed speed,
|
||||||
/* Write the speed config that was generated earlier */
|
/* Write the speed config that was generated earlier */
|
||||||
dw_i2c_set_speed_config(bus, &config);
|
dw_i2c_set_speed_config(bus, &config);
|
||||||
|
|
||||||
return 0;
|
return CB_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -710,7 +711,7 @@ int dw_i2c_init(unsigned int bus, const struct dw_i2c_bus_config *bcfg)
|
||||||
|
|
||||||
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) < 0) {
|
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 -1;
|
||||||
}
|
}
|
||||||
|
@ -720,7 +721,7 @@ int dw_i2c_init(unsigned int bus, const struct dw_i2c_bus_config *bcfg)
|
||||||
CONTROL_RESTART_ENABLE);
|
CONTROL_RESTART_ENABLE);
|
||||||
|
|
||||||
/* Set bus speed to FAST by default */
|
/* Set bus speed to FAST by default */
|
||||||
if (dw_i2c_set_speed(bus, speed, bcfg) < 0) {
|
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 -1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue