Revision 0077147e

b/hw/omap_i2c.c
24 24
struct omap_i2c_s {
25 25
    qemu_irq irq;
26 26
    qemu_irq drq[2];
27
    i2c_slave slave;
28 27
    i2c_bus *bus;
29 28

  
30 29
    uint8_t revision;
......
55 54
        qemu_set_irq(s->drq[1], (s->stat >> 4) & 1);		/* XRDY */
56 55
}
57 56

  
58
/* These are only stubs now.  */
59
static void omap_i2c_event(i2c_slave *i2c, enum i2c_event event)
60
{
61
    struct omap_i2c_s *s = (struct omap_i2c_s *) i2c;
62

  
63
    if ((~s->control >> 15) & 1)				/* I2C_EN */
64
        return;
65

  
66
    switch (event) {
67
    case I2C_START_SEND:
68
    case I2C_START_RECV:
69
        s->stat |= 1 << 9;					/* AAS */
70
        break;
71
    case I2C_FINISH:
72
        s->stat |= 1 << 2;					/* ARDY */
73
        break;
74
    case I2C_NACK:
75
        s->stat |= 1 << 1;					/* NACK */
76
        break;
77
    }
78

  
79
    omap_i2c_interrupts_update(s);
80
}
81

  
82
static int omap_i2c_rx(i2c_slave *i2c)
83
{
84
    struct omap_i2c_s *s = (struct omap_i2c_s *) i2c;
85
    uint8_t ret = 0;
86

  
87
    if ((~s->control >> 15) & 1)				/* I2C_EN */
88
        return -1;
89

  
90
    if (s->txlen)
91
        ret = s->fifo >> ((-- s->txlen) << 3) & 0xff;
92
    else
93
        s->stat |= 1 << 10;					/* XUDF */
94
    s->stat |= 1 << 4;						/* XRDY */
95

  
96
    omap_i2c_interrupts_update(s);
97
    return ret;
98
}
99

  
100
static int omap_i2c_tx(i2c_slave *i2c, uint8_t data)
101
{
102
    struct omap_i2c_s *s = (struct omap_i2c_s *) i2c;
103

  
104
    if ((~s->control >> 15) & 1)				/* I2C_EN */
105
        return 1;
106

  
107
    if (s->rxlen < 4)
108
        s->fifo |= data << ((s->rxlen ++) << 3);
109
    else
110
        s->stat |= 1 << 11;					/* ROVR */
111
    s->stat |= 1 << 3;						/* RRDY */
112

  
113
    omap_i2c_interrupts_update(s);
114
    return 1;
115
}
116

  
117 57
static void omap_i2c_fifo_run(struct omap_i2c_s *s)
118 58
{
119 59
    int ack = 1;
......
406 346

  
407 347
    case 0x28:	/* I2C_OA */
408 348
        s->addr[0] = value & 0x3ff;
409
        i2c_set_slave_address(&s->slave, value & 0x7f);
410 349
        break;
411 350

  
412 351
    case 0x2c:	/* I2C_SA */
......
494 433
    s->irq = irq;
495 434
    s->drq[0] = dma[0];
496 435
    s->drq[1] = dma[1];
497
    s->slave.event = omap_i2c_event;
498
    s->slave.recv = omap_i2c_rx;
499
    s->slave.send = omap_i2c_tx;
500 436
    s->bus = i2c_init_bus();
501 437
    omap_i2c_reset(s);
502 438

  
......
518 454
    s->irq = irq;
519 455
    s->drq[0] = dma[0];
520 456
    s->drq[1] = dma[1];
521
    s->slave.event = omap_i2c_event;
522
    s->slave.recv = omap_i2c_rx;
523
    s->slave.send = omap_i2c_tx;
524 457
    s->bus = i2c_init_bus();
525 458
    omap_i2c_reset(s);
526 459

  

Also available in: Unified diff