mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-02 15:23:53 -06:00
libqos: split I2CAdapter initialization and allocation
Provide *_init functions that populate an I2CAdapter struct without allocating one, and make the existing *_create functions wrap them. Because in the new setup *_create might return a pointer inside the IMXI2C or OMAPI2C struct, create companion *_free functions to go back to the outer pointer. All this is temporary until allocation will be handled entirely by qgraph. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
c4f00daa5b
commit
732c919cf0
5 changed files with 67 additions and 34 deletions
|
@ -30,13 +30,6 @@ enum IMXI2CDirection {
|
|||
IMX_I2C_WRITE,
|
||||
};
|
||||
|
||||
typedef struct IMXI2C {
|
||||
I2CAdapter parent;
|
||||
|
||||
uint64_t addr;
|
||||
} IMXI2C;
|
||||
|
||||
|
||||
static void imx_i2c_set_slave_addr(IMXI2C *s, uint8_t addr,
|
||||
enum IMXI2CDirection direction)
|
||||
{
|
||||
|
@ -47,7 +40,7 @@ static void imx_i2c_set_slave_addr(IMXI2C *s, uint8_t addr,
|
|||
static void imx_i2c_send(I2CAdapter *i2c, uint8_t addr,
|
||||
const uint8_t *buf, uint16_t len)
|
||||
{
|
||||
IMXI2C *s = (IMXI2C *)i2c;
|
||||
IMXI2C *s = container_of(i2c, IMXI2C, parent);
|
||||
uint8_t data;
|
||||
uint8_t status;
|
||||
uint16_t size = 0;
|
||||
|
@ -107,7 +100,7 @@ static void imx_i2c_send(I2CAdapter *i2c, uint8_t addr,
|
|||
static void imx_i2c_recv(I2CAdapter *i2c, uint8_t addr,
|
||||
uint8_t *buf, uint16_t len)
|
||||
{
|
||||
IMXI2C *s = (IMXI2C *)i2c;
|
||||
IMXI2C *s = container_of(i2c, IMXI2C, parent);
|
||||
uint8_t data;
|
||||
uint8_t status;
|
||||
uint16_t size = 0;
|
||||
|
@ -193,16 +186,30 @@ static void imx_i2c_recv(I2CAdapter *i2c, uint8_t addr,
|
|||
g_assert((status & I2SR_IBB) == 0);
|
||||
}
|
||||
|
||||
void imx_i2c_init(IMXI2C *s, QTestState *qts, uint64_t addr)
|
||||
{
|
||||
s->addr = addr;
|
||||
|
||||
s->parent.send = imx_i2c_send;
|
||||
s->parent.recv = imx_i2c_recv;
|
||||
s->parent.qts = qts;
|
||||
}
|
||||
|
||||
I2CAdapter *imx_i2c_create(QTestState *qts, uint64_t addr)
|
||||
{
|
||||
IMXI2C *s = g_malloc0(sizeof(*s));
|
||||
I2CAdapter *i2c = (I2CAdapter *)s;
|
||||
|
||||
s->addr = addr;
|
||||
|
||||
i2c->send = imx_i2c_send;
|
||||
i2c->recv = imx_i2c_recv;
|
||||
i2c->qts = qts;
|
||||
|
||||
return i2c;
|
||||
imx_i2c_init(s, qts, addr);
|
||||
return &s->parent;
|
||||
}
|
||||
|
||||
void imx_i2c_free(I2CAdapter *i2c)
|
||||
{
|
||||
IMXI2C *s;
|
||||
|
||||
if (!i2c) {
|
||||
return;
|
||||
}
|
||||
s = container_of(i2c, IMXI2C, parent);
|
||||
g_free(s);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue