Commit fd1eb2ea4286bb42ea4cf008ece14bbfbb598d21

Authored by Paul Brook
1 parent d3356811

TOSC DAC i2c qdev voncersion

Signed-off-by: Paul Brook <paul@codesourcery.com>
Showing 1 changed file with 22 additions and 7 deletions
hw/tosa.c
... ... @@ -132,7 +132,7 @@ typedef struct {
132 132  
133 133 static int tosa_dac_send(i2c_slave *i2c, uint8_t data)
134 134 {
135   - TosaDACState *s = (TosaDACState *)i2c;
  135 + TosaDACState *s = FROM_I2C_SLAVE(TosaDACState, i2c);
136 136 s->buf[s->len] = data;
137 137 if (s->len ++ > 2) {
138 138 #ifdef VERBOSE
... ... @@ -151,7 +151,7 @@ static int tosa_dac_send(i2c_slave *i2c, uint8_t data)
151 151  
152 152 static void tosa_dac_event(i2c_slave *i2c, enum i2c_event event)
153 153 {
154   - TosaDACState *s = (TosaDACState *)i2c;
  154 + TosaDACState *s = FROM_I2C_SLAVE(TosaDACState, i2c);
155 155 s->len = 0;
156 156 switch (event) {
157 157 case I2C_START_SEND:
... ... @@ -178,14 +178,15 @@ static int tosa_dac_recv(i2c_slave *s)
178 178 return -1;
179 179 }
180 180  
  181 +static void tosa_dac_init(i2c_slave *i2c)
  182 +{
  183 + /* Nothing to do. */
  184 +}
  185 +
181 186 static void tosa_tg_init(PXA2xxState *cpu)
182 187 {
183 188 i2c_bus *bus = pxa2xx_i2c_bus(cpu->i2c[0]);
184   - i2c_slave *dac = i2c_slave_init(bus, 0, sizeof(TosaDACState));
185   - dac->send = tosa_dac_send;
186   - dac->event = tosa_dac_event;
187   - dac->recv = tosa_dac_recv;
188   - i2c_set_slave_address(dac, DAC_BASE);
  189 + i2c_create_slave(bus, "tosa_dac", DAC_BASE);
189 190 pxa2xx_ssp_attach(cpu->ssp[1], tosa_ssp_read,
190 191 tosa_ssp_write, cpu);
191 192 }
... ... @@ -241,3 +242,17 @@ QEMUMachine tosapda_machine = {
241 242 .desc = "Tosa PDA (PXA255)",
242 243 .init = tosa_init,
243 244 };
  245 +
  246 +static I2CSlaveInfo tosa_dac_info = {
  247 + .init = tosa_dac_init,
  248 + .event = tosa_dac_event,
  249 + .recv = tosa_dac_recv,
  250 + .send = tosa_dac_send
  251 +};
  252 +
  253 +static void tosa_register_devices(void)
  254 +{
  255 + i2c_register_slave("tosa_dac", sizeof(TosaDACState), &tosa_dac_info);
  256 +}
  257 +
  258 +device_init(tosa_register_devices)
... ...