aboutsummaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorAndreas Färber <afaerber@suse.de>2013-12-19 22:34:05 +0100
committerAndreas Färber <afaerber@suse.de>2014-02-14 16:22:32 +0100
commit59ab56b9ad543f0290fbcc29a7fb2248b2920ef8 (patch)
tree7ab038c410070a55255b166978804db795e5f879 /hw
parent933069eb534ad37db67eb5b550798170fccbc64c (diff)
ds1338: QOM'ify
Replace usages of FROM_I2C_SLAVE() with QOM cast macro. Rename parent field. Reviewed-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com> Signed-off-by: Andreas Färber <afaerber@suse.de>
Diffstat (limited to 'hw')
-rw-r--r--hw/timer/ds1338.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/hw/timer/ds1338.c b/hw/timer/ds1338.c
index 8987cdc9e0..bb2f8ee8b3 100644
--- a/hw/timer/ds1338.c
+++ b/hw/timer/ds1338.c
@@ -23,8 +23,12 @@
#define HOURS_PM 0x20
#define CTRL_OSF 0x20
-typedef struct {
- I2CSlave i2c;
+#define TYPE_DS1338 "ds1338"
+#define DS1338(obj) OBJECT_CHECK(DS1338State, (obj), TYPE_DS1338)
+
+typedef struct DS1338State {
+ I2CSlave parent_obj;
+
int64_t offset;
uint8_t wday_offset;
uint8_t nvram[NVRAM_SIZE];
@@ -38,7 +42,7 @@ static const VMStateDescription vmstate_ds1338 = {
.minimum_version_id = 1,
.minimum_version_id_old = 1,
.fields = (VMStateField[]) {
- VMSTATE_I2C_SLAVE(i2c, DS1338State),
+ VMSTATE_I2C_SLAVE(parent_obj, DS1338State),
VMSTATE_INT64(offset, DS1338State),
VMSTATE_UINT8_V(wday_offset, DS1338State, 2),
VMSTATE_UINT8_ARRAY(nvram, DS1338State, NVRAM_SIZE),
@@ -90,7 +94,7 @@ static void inc_regptr(DS1338State *s)
static void ds1338_event(I2CSlave *i2c, enum i2c_event event)
{
- DS1338State *s = FROM_I2C_SLAVE(DS1338State, i2c);
+ DS1338State *s = DS1338(i2c);
switch (event) {
case I2C_START_RECV:
@@ -111,7 +115,7 @@ static void ds1338_event(I2CSlave *i2c, enum i2c_event event)
static int ds1338_recv(I2CSlave *i2c)
{
- DS1338State *s = FROM_I2C_SLAVE(DS1338State, i2c);
+ DS1338State *s = DS1338(i2c);
uint8_t res;
res = s->nvram[s->ptr];
@@ -121,7 +125,8 @@ static int ds1338_recv(I2CSlave *i2c)
static int ds1338_send(I2CSlave *i2c, uint8_t data)
{
- DS1338State *s = FROM_I2C_SLAVE(DS1338State, i2c);
+ DS1338State *s = DS1338(i2c);
+
if (s->addr_byte) {
s->ptr = data & (NVRAM_SIZE - 1);
s->addr_byte = false;
@@ -198,7 +203,7 @@ static int ds1338_init(I2CSlave *i2c)
static void ds1338_reset(DeviceState *dev)
{
- DS1338State *s = FROM_I2C_SLAVE(DS1338State, I2C_SLAVE(dev));
+ DS1338State *s = DS1338(dev);
/* The clock is running and synchronized with the host */
s->offset = 0;
@@ -222,7 +227,7 @@ static void ds1338_class_init(ObjectClass *klass, void *data)
}
static const TypeInfo ds1338_info = {
- .name = "ds1338",
+ .name = TYPE_DS1338,
.parent = TYPE_I2C_SLAVE,
.instance_size = sizeof(DS1338State),
.class_init = ds1338_class_init,