max7310: finish qdev'ication

1) Move GPIO-related functionality to qdev. Now one can use directly
qdev_get_gpio_in()/qdev_connect_gpio_out() on max7310 devices.

2) Make reset to be called through qdev.reset callback.

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Signed-off-by: Andrzej Zaborowski <andrew.zaborowski@intel.com>
This commit is contained in:
Dmitry Eremin-Solenikov 2011-02-11 23:57:38 +03:00 committed by Andrzej Zaborowski
parent 2e4b4e79c6
commit 987e8b3b03
2 changed files with 5 additions and 26 deletions

View File

@ -59,11 +59,6 @@ void i2c_register_slave(I2CSlaveInfo *type);
DeviceState *i2c_create_slave(i2c_bus *bus, const char *name, uint8_t addr); DeviceState *i2c_create_slave(i2c_bus *bus, const char *name, uint8_t addr);
/* max7310.c */
void max7310_reset(i2c_slave *i2c);
qemu_irq *max7310_gpio_in_get(i2c_slave *i2c);
void max7310_gpio_out_set(i2c_slave *i2c, int line, qemu_irq handler);
/* wm8750.c */ /* wm8750.c */
void wm8750_data_req_set(DeviceState *dev, void wm8750_data_req_set(DeviceState *dev,
void (*data_req)(void *, int, int), void *opaque); void (*data_req)(void *, int, int), void *opaque);

View File

@ -23,9 +23,9 @@ typedef struct {
qemu_irq *gpio_in; qemu_irq *gpio_in;
} MAX7310State; } MAX7310State;
void max7310_reset(i2c_slave *i2c) static void max7310_reset(DeviceState *dev)
{ {
MAX7310State *s = (MAX7310State *) i2c; MAX7310State *s = FROM_I2C_SLAVE(MAX7310State, I2C_SLAVE_FROM_QDEV(dev));
s->level &= s->direction; s->level &= s->direction;
s->direction = 0xff; s->direction = 0xff;
s->polarity = 0xf0; s->polarity = 0xf0;
@ -179,33 +179,17 @@ static int max7310_init(i2c_slave *i2c)
{ {
MAX7310State *s = FROM_I2C_SLAVE(MAX7310State, i2c); MAX7310State *s = FROM_I2C_SLAVE(MAX7310State, i2c);
s->gpio_in = qemu_allocate_irqs(max7310_gpio_set, s, qdev_init_gpio_in(&i2c->qdev, max7310_gpio_set, 8);
ARRAY_SIZE(s->handler)); qdev_init_gpio_out(&i2c->qdev, s->handler, 8);
max7310_reset(&s->i2c);
return 0; return 0;
} }
qemu_irq *max7310_gpio_in_get(i2c_slave *i2c)
{
MAX7310State *s = (MAX7310State *) i2c;
return s->gpio_in;
}
void max7310_gpio_out_set(i2c_slave *i2c, int line, qemu_irq handler)
{
MAX7310State *s = (MAX7310State *) i2c;
if (line >= ARRAY_SIZE(s->handler) || line < 0)
hw_error("bad GPIO line");
s->handler[line] = handler;
}
static I2CSlaveInfo max7310_info = { static I2CSlaveInfo max7310_info = {
.qdev.name = "max7310", .qdev.name = "max7310",
.qdev.size = sizeof(MAX7310State), .qdev.size = sizeof(MAX7310State),
.qdev.vmsd = &vmstate_max7310, .qdev.vmsd = &vmstate_max7310,
.qdev.reset = max7310_reset,
.init = max7310_init, .init = max7310_init,
.event = max7310_event, .event = max7310_event,
.recv = max7310_rx, .recv = max7310_rx,