forked from Mirrors/opensbi
lib: utils/i2c: Use heap in DesignWare and SiFive I2C drivers
Let's use heap allocation in DesignWare and SiFive I2C drivers instead of using a fixed size global array. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
This commit is contained in:
@@ -9,17 +9,12 @@
|
||||
|
||||
#include <sbi/riscv_io.h>
|
||||
#include <sbi/sbi_error.h>
|
||||
#include <sbi/sbi_heap.h>
|
||||
#include <sbi/sbi_string.h>
|
||||
#include <sbi_utils/fdt/fdt_helper.h>
|
||||
#include <sbi_utils/i2c/dw_i2c.h>
|
||||
#include <sbi_utils/i2c/fdt_i2c.h>
|
||||
|
||||
#define FDT_DW_I2C_ADAPTER_MAX 7
|
||||
|
||||
static unsigned int fdt_dw_i2c_adapter_count;
|
||||
static struct dw_i2c_adapter
|
||||
fdt_dw_i2c_adapter_array[FDT_DW_I2C_ADAPTER_MAX];
|
||||
|
||||
extern struct fdt_i2c_adapter fdt_i2c_adapter_dw;
|
||||
|
||||
static int fdt_dw_i2c_init(void *fdt, int nodeoff,
|
||||
@@ -29,23 +24,24 @@ static int fdt_dw_i2c_init(void *fdt, int nodeoff,
|
||||
struct dw_i2c_adapter *adapter;
|
||||
u64 addr;
|
||||
|
||||
if (fdt_dw_i2c_adapter_count >= FDT_DW_I2C_ADAPTER_MAX)
|
||||
return SBI_ENOSPC;
|
||||
|
||||
adapter = &fdt_dw_i2c_adapter_array[fdt_dw_i2c_adapter_count];
|
||||
adapter = sbi_zalloc(sizeof(*adapter));
|
||||
if (!adapter)
|
||||
return SBI_ENOMEM;
|
||||
|
||||
rc = fdt_get_node_addr_size(fdt, nodeoff, 0, &addr, NULL);
|
||||
if (rc)
|
||||
if (rc) {
|
||||
sbi_free(adapter);
|
||||
return rc;
|
||||
}
|
||||
|
||||
adapter->addr = addr;
|
||||
adapter->adapter.driver = &fdt_i2c_adapter_dw;
|
||||
|
||||
rc = dw_i2c_init(&adapter->adapter, nodeoff);
|
||||
if (rc)
|
||||
if (rc) {
|
||||
sbi_free(adapter);
|
||||
return rc;
|
||||
|
||||
fdt_dw_i2c_adapter_count++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user