Maxim Polyakov has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/45372 )
Change subject: ec/kontron/kempld: Fix code style ......................................................................
ec/kontron/kempld: Fix code style
Change-Id: Ia5ad0715b742427dffa6c0c507269d904fe19bcb Signed-off-by: Maxim Polyakov max.senia.poliak@gmail.com --- M src/ec/kontron/kempld/chip.h M src/ec/kontron/kempld/early_kempld.c M src/ec/kontron/kempld/kempld.c M src/ec/kontron/kempld/kempld_i2c.c M src/ec/kontron/kempld/kempld_internal.h 5 files changed, 30 insertions(+), 46 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/72/45372/1
diff --git a/src/ec/kontron/kempld/chip.h b/src/ec/kontron/kempld/chip.h index 2ac0949..b520e6e 100644 --- a/src/ec/kontron/kempld/chip.h +++ b/src/ec/kontron/kempld/chip.h @@ -3,7 +3,7 @@ #ifndef EC_KONTRON_KEMPLD_CHIP_H #define EC_KONTRON_KEMPLD_CHIP_H
-#define KEMPLD_NUM_UARTS 2 +#define KEMPLD_NUM_UARTS 2
enum kempld_uart_io { KEMPLD_UART_3F8 = 0, @@ -19,7 +19,7 @@
struct ec_kontron_kempld_config { struct kempld_uart uart[KEMPLD_NUM_UARTS]; - unsigned short i2c_freq_khz; + unsigned short i2c_freq_khz; };
#endif /* EC_KONTRON_KEMPLD_CHIP_H */ diff --git a/src/ec/kontron/kempld/early_kempld.c b/src/ec/kontron/kempld/early_kempld.c index cb33a8b..d25896c 100644 --- a/src/ec/kontron/kempld/early_kempld.c +++ b/src/ec/kontron/kempld/early_kempld.c @@ -3,7 +3,6 @@ #include <stdint.h> #include <arch/io.h> #include <delay.h> - #include "chip.h" #include "kempld.h" #include "kempld_internal.h" @@ -43,13 +42,11 @@ switch (CONFIG_UART_FOR_CONSOLE) { case 0: kempld_write8(KEMPLD_UART_0, - KEMPLD_UART_ENABLE | - KEMPLD_UART_3F8 << KEMPLD_UART_IO_SHIFT); + KEMPLD_UART_ENABLE | KEMPLD_UART_3F8 << KEMPLD_UART_IO_SHIFT); break; case 1: kempld_write8(KEMPLD_UART_1, - KEMPLD_UART_ENABLE | - KEMPLD_UART_2F8 << KEMPLD_UART_IO_SHIFT); + KEMPLD_UART_ENABLE | KEMPLD_UART_2F8 << KEMPLD_UART_IO_SHIFT); break; default: break; diff --git a/src/ec/kontron/kempld/kempld.c b/src/ec/kontron/kempld/kempld.c index 19376c7..22e5376 100644 --- a/src/ec/kontron/kempld/kempld.c +++ b/src/ec/kontron/kempld/kempld.c @@ -2,7 +2,6 @@
#include <console/console.h> #include <device/device.h> - #include "chip.h" #include "kempld.h" #include "kempld_internal.h" @@ -10,27 +9,24 @@ static void kempld_uart_read_resources(struct device *dev) { static const unsigned int io_addr[] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 }; - const struct ec_kontron_kempld_config *const config = dev->chip_info; - struct resource *const res_io = new_resource(dev, 0); struct resource *const res_irq = new_resource(dev, 1); const unsigned int uart = dev->path.generic.subid; + if (!config || !res_io || !res_irq || uart >= KEMPLD_NUM_UARTS) return;
const enum kempld_uart_io io = config->uart[uart].io; if (io >= ARRAY_SIZE(io_addr)) { - printk(BIOS_ERR, "KEMPLD: Bad io value '%d' for UART#%u\n.", - io, uart); + printk(BIOS_ERR, "KEMPLD: Bad io value '%d' for UART#%u\n.", io, uart); dev->enabled = false; return; }
const int irq = config->uart[uart].irq; if (irq >= 16) { - printk(BIOS_ERR, "KEMPLD: Bad irq value '%d' for UART#%u\n.", - irq, uart); + printk(BIOS_ERR, "KEMPLD: Bad irq value '%d' for UART#%u\n.", irq, uart); dev->enabled = false; return; } @@ -49,22 +45,23 @@
const uint8_t reg = uart ? KEMPLD_UART_1 : KEMPLD_UART_0; const uint8_t val = kempld_read8(reg); - kempld_write8(reg, (val & ~(KEMPLD_UART_IO_MASK | KEMPLD_UART_IRQ_MASK)) - | io << KEMPLD_UART_IO_SHIFT - | irq << KEMPLD_UART_IRQ_SHIFT); + kempld_write8(reg, + (val & ~(KEMPLD_UART_IO_MASK | KEMPLD_UART_IRQ_MASK)) | + io << KEMPLD_UART_IO_SHIFT | + irq << KEMPLD_UART_IRQ_SHIFT);
kempld_release_mutex(); }
static void kempld_uart_enable_resources(struct device *dev) { + const unsigned int uart = dev->path.generic.subid; + const uint8_t reg = uart ? KEMPLD_UART_1 : KEMPLD_UART_0; + if (kempld_get_mutex(100) < 0) return;
- const unsigned int uart = dev->path.generic.subid; - const uint8_t reg = uart ? KEMPLD_UART_1 : KEMPLD_UART_0; kempld_write8(reg, kempld_read8(reg) | KEMPLD_UART_ENABLE); - kempld_release_mutex(); }
@@ -90,9 +87,7 @@ } /* Fall through. */ default: - printk(BIOS_WARNING, - "KEMPLD: Spurious device %s.\n", - dev_path(dev)); + printk(BIOS_WARNING, "KEMPLD: Spurious device %s.\n", dev_path(dev)); break; } } diff --git a/src/ec/kontron/kempld/kempld_i2c.c b/src/ec/kontron/kempld/kempld_i2c.c index 0145d97..8701205 100644 --- a/src/ec/kontron/kempld/kempld_i2c.c +++ b/src/ec/kontron/kempld/kempld_i2c.c @@ -1,18 +1,11 @@ /* SPDX-License-Identifier: GPL-2.0-only */
-/* - * I2C bus driver for Kontron COM modules - * - * Based on the similar driver in Linux. - */ - #include <stdint.h> #include <console/console.h> #include <device/device.h> #include <device/i2c_bus.h> #include <timer.h> #include <delay.h> - #include "chip.h" #include "kempld.h" #include "kempld_internal.h" @@ -41,10 +34,10 @@ #define I2C_CMD_READ_NACK 0x29 #define I2C_CMD_IACK 0x01
-#define EIO 5 -#define ENXIO 6 -#define EAGAIN 11 -#define EBUSY 16 +#define EIO 5 +#define ENXIO 6 +#define EAGAIN 11 +#define EBUSY 16 #define ETIMEDOUT 110
enum kempld_i2c_freq_stadart { @@ -66,10 +59,10 @@ };
struct kempld_i2c_data { - const struct i2c_msg *msg; - size_t pos; - size_t nmsgs; - enum kempld_i2c_state state; + const struct i2c_msg *msg; + size_t pos; + size_t nmsgs; + enum kempld_i2c_state state; };
/* @@ -158,8 +151,7 @@ i2c->state = STATE_ADDR; return 0; } - i2c->state = (msg->flags & I2C_M_RD) - ? STATE_READ : STATE_WRITE; + i2c->state = (msg->flags & I2C_M_RD) ? STATE_READ : STATE_WRITE; } else { i2c->state = STATE_DONE; kempld_write8(KEMPLD_I2C_CMD, I2C_CMD_STOP); @@ -229,8 +221,8 @@ };
static struct device_operations kempld_i2c_dev_ops = { - .scan_bus = &scan_smbus, - .ops_i2c_bus = &kempld_i2c_bus_ops, + .scan_bus = &scan_smbus, + .ops_i2c_bus = &kempld_i2c_bus_ops, };
void kempld_i2c_device_init(struct device *const dev) diff --git a/src/ec/kontron/kempld/kempld_internal.h b/src/ec/kontron/kempld/kempld_internal.h index 014778c..4fb42dc 100644 --- a/src/ec/kontron/kempld/kempld_internal.h +++ b/src/ec/kontron/kempld/kempld_internal.h @@ -6,9 +6,9 @@ #include <device/device.h>
/* i/o ports */ -#define KEMPLD_IDX 0xa80 -#define KEMPLD_MUTEX_KEY 0x80 -#define KEMPLD_DAT 0xa81 +#define KEMPLD_IDX 0xa80 +#define KEMPLD_MUTEX_KEY 0x80 +#define KEMPLD_DAT 0xa81
/* indexed registers */ #define KEMPLD_SPEC 0x06 @@ -26,7 +26,7 @@ #define KEMPLD_UART_IO_MASK (0x3 << KEMPLD_UART_IO_SHIFT) #define KEMPLD_UART_ENABLE 0x80
-#define KEMPLD_CLK 33333333 /* 33MHz */ +#define KEMPLD_CLK 33333333 /* 33MHz */
void kempld_i2c_device_init(struct device *const dev);