forked from Mirrors/opensbi
lib: utils/i2c: Use fdt_driver for initialization
The i2c driver subsystem does not need any extra data, so it can use `struct fdt_driver` directly. It always initializes the driver for a specific DT node. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
This commit is contained in:

committed by
Anup Patel

parent
bef8f9b806
commit
333133edaa
@@ -10,15 +10,9 @@
|
|||||||
#ifndef __FDT_I2C_H__
|
#ifndef __FDT_I2C_H__
|
||||||
#define __FDT_I2C_H__
|
#define __FDT_I2C_H__
|
||||||
|
|
||||||
|
#include <sbi_utils/fdt/fdt_driver.h>
|
||||||
#include <sbi_utils/i2c/i2c.h>
|
#include <sbi_utils/i2c/i2c.h>
|
||||||
|
|
||||||
/** FDT based I2C adapter driver */
|
|
||||||
struct fdt_i2c_adapter {
|
|
||||||
const struct fdt_match *match_table;
|
|
||||||
int (*init)(const void *fdt, int nodeoff,
|
|
||||||
const struct fdt_match *match);
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Get I2C adapter identified by nodeoff */
|
/** Get I2C adapter identified by nodeoff */
|
||||||
int fdt_i2c_adapter_get(const void *fdt, int nodeoff,
|
int fdt_i2c_adapter_get(const void *fdt, int nodeoff,
|
||||||
struct i2c_adapter **out_adapter);
|
struct i2c_adapter **out_adapter);
|
||||||
|
@@ -11,36 +11,11 @@
|
|||||||
* Anup Patel <anup.patel@wdc.com>
|
* Anup Patel <anup.patel@wdc.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <libfdt.h>
|
|
||||||
#include <sbi/sbi_error.h>
|
#include <sbi/sbi_error.h>
|
||||||
#include <sbi_utils/fdt/fdt_helper.h>
|
|
||||||
#include <sbi_utils/i2c/fdt_i2c.h>
|
#include <sbi_utils/i2c/fdt_i2c.h>
|
||||||
|
|
||||||
/* List of FDT i2c adapter drivers generated at compile time */
|
/* List of FDT i2c adapter drivers generated at compile time */
|
||||||
extern struct fdt_i2c_adapter *const fdt_i2c_adapter_drivers[];
|
extern const struct fdt_driver *const fdt_i2c_adapter_drivers[];
|
||||||
|
|
||||||
static int fdt_i2c_adapter_init(const void *fdt, int nodeoff)
|
|
||||||
{
|
|
||||||
int pos, rc;
|
|
||||||
struct fdt_i2c_adapter *drv;
|
|
||||||
const struct fdt_match *match;
|
|
||||||
|
|
||||||
/* Try all I2C drivers one-by-one */
|
|
||||||
for (pos = 0; fdt_i2c_adapter_drivers[pos]; pos++) {
|
|
||||||
drv = fdt_i2c_adapter_drivers[pos];
|
|
||||||
match = fdt_match_node(fdt, nodeoff, drv->match_table);
|
|
||||||
if (match && drv->init) {
|
|
||||||
rc = drv->init(fdt, nodeoff, match);
|
|
||||||
if (rc == SBI_ENODEV)
|
|
||||||
continue;
|
|
||||||
if (rc)
|
|
||||||
return rc;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return SBI_ENOSYS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int fdt_i2c_adapter_find(const void *fdt, int nodeoff,
|
static int fdt_i2c_adapter_find(const void *fdt, int nodeoff,
|
||||||
struct i2c_adapter **out_adapter)
|
struct i2c_adapter **out_adapter)
|
||||||
@@ -50,7 +25,8 @@ static int fdt_i2c_adapter_find(const void *fdt, int nodeoff,
|
|||||||
|
|
||||||
if (!adapter) {
|
if (!adapter) {
|
||||||
/* I2C adapter not found so initialize matching driver */
|
/* I2C adapter not found so initialize matching driver */
|
||||||
rc = fdt_i2c_adapter_init(fdt, nodeoff);
|
rc = fdt_driver_init_by_offset(fdt, nodeoff,
|
||||||
|
fdt_i2c_adapter_drivers);
|
||||||
if (rc)
|
if (rc)
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
|
@@ -1,3 +1,3 @@
|
|||||||
HEADER: sbi_utils/i2c/fdt_i2c.h
|
HEADER: sbi_utils/i2c/fdt_i2c.h
|
||||||
TYPE: struct fdt_i2c_adapter
|
TYPE: const struct fdt_driver
|
||||||
NAME: fdt_i2c_adapter_drivers
|
NAME: fdt_i2c_adapter_drivers
|
||||||
|
@@ -49,7 +49,7 @@ static const struct fdt_match fdt_dw_i2c_match[] = {
|
|||||||
{ },
|
{ },
|
||||||
};
|
};
|
||||||
|
|
||||||
struct fdt_i2c_adapter fdt_i2c_adapter_dw = {
|
const struct fdt_driver fdt_i2c_adapter_dw = {
|
||||||
.match_table = fdt_dw_i2c_match,
|
.match_table = fdt_dw_i2c_match,
|
||||||
.init = fdt_dw_i2c_init,
|
.init = fdt_dw_i2c_init,
|
||||||
};
|
};
|
||||||
|
@@ -265,7 +265,7 @@ static const struct fdt_match sifive_i2c_match[] = {
|
|||||||
{ },
|
{ },
|
||||||
};
|
};
|
||||||
|
|
||||||
struct fdt_i2c_adapter fdt_i2c_adapter_sifive = {
|
const struct fdt_driver fdt_i2c_adapter_sifive = {
|
||||||
.match_table = sifive_i2c_match,
|
.match_table = sifive_i2c_match,
|
||||||
.init = sifive_i2c_init,
|
.init = sifive_i2c_init,
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user