xref: /qemu/hw/i2c/ppc4xx_i2c.c (revision 7709dbf12c0bb9a86c186c2c0f7ae67ce363dc80)
165ca801bSBALATON Zoltan /*
265ca801bSBALATON Zoltan  * PPC4xx I2C controller emulation
365ca801bSBALATON Zoltan  *
465ca801bSBALATON Zoltan  * Copyright (c) 2007 Jocelyn Mayer
5*7709dbf1SBALATON Zoltan  * Copyright (c) 2012 François Revol
6*7709dbf1SBALATON Zoltan  * Copyright (c) 2016 BALATON Zoltan
765ca801bSBALATON Zoltan  *
865ca801bSBALATON Zoltan  * Permission is hereby granted, free of charge, to any person obtaining a copy
965ca801bSBALATON Zoltan  * of this software and associated documentation files (the "Software"), to deal
1065ca801bSBALATON Zoltan  * in the Software without restriction, including without limitation the rights
1165ca801bSBALATON Zoltan  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1265ca801bSBALATON Zoltan  * copies of the Software, and to permit persons to whom the Software is
1365ca801bSBALATON Zoltan  * furnished to do so, subject to the following conditions:
1465ca801bSBALATON Zoltan  *
1565ca801bSBALATON Zoltan  * The above copyright notice and this permission notice shall be included in
1665ca801bSBALATON Zoltan  * all copies or substantial portions of the Software.
1765ca801bSBALATON Zoltan  *
1865ca801bSBALATON Zoltan  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1965ca801bSBALATON Zoltan  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2065ca801bSBALATON Zoltan  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
2165ca801bSBALATON Zoltan  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2265ca801bSBALATON Zoltan  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2365ca801bSBALATON Zoltan  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2465ca801bSBALATON Zoltan  * THE SOFTWARE.
2565ca801bSBALATON Zoltan  */
2665ca801bSBALATON Zoltan 
2765ca801bSBALATON Zoltan #include "qemu/osdep.h"
2865ca801bSBALATON Zoltan #include "qapi/error.h"
2965ca801bSBALATON Zoltan #include "qemu-common.h"
30*7709dbf1SBALATON Zoltan #include "qemu/log.h"
3165ca801bSBALATON Zoltan #include "cpu.h"
3265ca801bSBALATON Zoltan #include "hw/hw.h"
333b09bb0fSBALATON Zoltan #include "hw/i2c/ppc4xx_i2c.h"
3465ca801bSBALATON Zoltan 
35*7709dbf1SBALATON Zoltan #define PPC4xx_I2C_MEM_SIZE 0x12
3665ca801bSBALATON Zoltan 
37*7709dbf1SBALATON Zoltan #define IIC_CNTL_PT         (1 << 0)
38*7709dbf1SBALATON Zoltan #define IIC_CNTL_READ       (1 << 1)
39*7709dbf1SBALATON Zoltan #define IIC_CNTL_CHT        (1 << 2)
40*7709dbf1SBALATON Zoltan #define IIC_CNTL_RPST       (1 << 3)
41*7709dbf1SBALATON Zoltan 
42*7709dbf1SBALATON Zoltan #define IIC_STS_PT          (1 << 0)
43*7709dbf1SBALATON Zoltan #define IIC_STS_ERR         (1 << 2)
44*7709dbf1SBALATON Zoltan #define IIC_STS_MDBS        (1 << 5)
45*7709dbf1SBALATON Zoltan 
46*7709dbf1SBALATON Zoltan #define IIC_EXTSTS_XFRA     (1 << 0)
47*7709dbf1SBALATON Zoltan 
48*7709dbf1SBALATON Zoltan #define IIC_XTCNTLSS_SRST   (1 << 0)
49*7709dbf1SBALATON Zoltan 
50*7709dbf1SBALATON Zoltan static void ppc4xx_i2c_reset(DeviceState *s)
51*7709dbf1SBALATON Zoltan {
52*7709dbf1SBALATON Zoltan     PPC4xxI2CState *i2c = PPC4xx_I2C(s);
53*7709dbf1SBALATON Zoltan 
54*7709dbf1SBALATON Zoltan     /* FIXME: Should also reset bus?
55*7709dbf1SBALATON Zoltan      *if (s->address != ADDR_RESET) {
56*7709dbf1SBALATON Zoltan      *    i2c_end_transfer(s->bus);
57*7709dbf1SBALATON Zoltan      *}
58*7709dbf1SBALATON Zoltan      */
59*7709dbf1SBALATON Zoltan 
60*7709dbf1SBALATON Zoltan     i2c->mdata = 0;
61*7709dbf1SBALATON Zoltan     i2c->lmadr = 0;
62*7709dbf1SBALATON Zoltan     i2c->hmadr = 0;
63*7709dbf1SBALATON Zoltan     i2c->cntl = 0;
64*7709dbf1SBALATON Zoltan     i2c->mdcntl = 0;
65*7709dbf1SBALATON Zoltan     i2c->sts = 0;
66*7709dbf1SBALATON Zoltan     i2c->extsts = 0x8f;
67*7709dbf1SBALATON Zoltan     i2c->sdata = 0;
68*7709dbf1SBALATON Zoltan     i2c->lsadr = 0;
69*7709dbf1SBALATON Zoltan     i2c->hsadr = 0;
70*7709dbf1SBALATON Zoltan     i2c->clkdiv = 0;
71*7709dbf1SBALATON Zoltan     i2c->intrmsk = 0;
72*7709dbf1SBALATON Zoltan     i2c->xfrcnt = 0;
73*7709dbf1SBALATON Zoltan     i2c->xtcntlss = 0;
74*7709dbf1SBALATON Zoltan     i2c->directcntl = 0x0f;
75*7709dbf1SBALATON Zoltan     i2c->intr = 0;
76*7709dbf1SBALATON Zoltan }
77*7709dbf1SBALATON Zoltan 
78*7709dbf1SBALATON Zoltan static inline bool ppc4xx_i2c_is_master(PPC4xxI2CState *i2c)
79*7709dbf1SBALATON Zoltan {
80*7709dbf1SBALATON Zoltan     return true;
81*7709dbf1SBALATON Zoltan }
8265ca801bSBALATON Zoltan 
833b09bb0fSBALATON Zoltan static uint64_t ppc4xx_i2c_readb(void *opaque, hwaddr addr, unsigned int size)
8465ca801bSBALATON Zoltan {
853b09bb0fSBALATON Zoltan     PPC4xxI2CState *i2c = PPC4xx_I2C(opaque);
863b09bb0fSBALATON Zoltan     uint64_t ret;
8765ca801bSBALATON Zoltan 
8865ca801bSBALATON Zoltan     switch (addr) {
8965ca801bSBALATON Zoltan     case 0x00:
9065ca801bSBALATON Zoltan         ret = i2c->mdata;
91*7709dbf1SBALATON Zoltan         if (ppc4xx_i2c_is_master(i2c)) {
92*7709dbf1SBALATON Zoltan             ret = 0xff;
93*7709dbf1SBALATON Zoltan 
94*7709dbf1SBALATON Zoltan             if (!(i2c->sts & IIC_STS_MDBS)) {
95*7709dbf1SBALATON Zoltan                 qemu_log_mask(LOG_GUEST_ERROR, "[%s]%s: Trying to read "
96*7709dbf1SBALATON Zoltan                               "without starting transfer\n",
97*7709dbf1SBALATON Zoltan                               TYPE_PPC4xx_I2C, __func__);
98*7709dbf1SBALATON Zoltan             } else {
99*7709dbf1SBALATON Zoltan                 int pending = (i2c->cntl >> 4) & 3;
100*7709dbf1SBALATON Zoltan 
101*7709dbf1SBALATON Zoltan                 /* get the next byte */
102*7709dbf1SBALATON Zoltan                 int byte = i2c_recv(i2c->bus);
103*7709dbf1SBALATON Zoltan 
104*7709dbf1SBALATON Zoltan                 if (byte < 0) {
105*7709dbf1SBALATON Zoltan                     qemu_log_mask(LOG_GUEST_ERROR, "[%s]%s: read failed "
106*7709dbf1SBALATON Zoltan                                   "for device 0x%02x\n", TYPE_PPC4xx_I2C,
107*7709dbf1SBALATON Zoltan                                   __func__, i2c->lmadr);
108*7709dbf1SBALATON Zoltan                     ret = 0xff;
109*7709dbf1SBALATON Zoltan                 } else {
110*7709dbf1SBALATON Zoltan                     ret = byte;
111*7709dbf1SBALATON Zoltan                     /* Raise interrupt if enabled */
112*7709dbf1SBALATON Zoltan                     /*ppc4xx_i2c_raise_interrupt(i2c)*/;
113*7709dbf1SBALATON Zoltan                 }
114*7709dbf1SBALATON Zoltan 
115*7709dbf1SBALATON Zoltan                 if (!pending) {
116*7709dbf1SBALATON Zoltan                     i2c->sts &= ~IIC_STS_MDBS;
117*7709dbf1SBALATON Zoltan                     /*i2c_end_transfer(i2c->bus);*/
118*7709dbf1SBALATON Zoltan                 /*} else if (i2c->cntl & (IIC_CNTL_RPST | IIC_CNTL_CHT)) {*/
119*7709dbf1SBALATON Zoltan                 } else if (pending) {
120*7709dbf1SBALATON Zoltan                     /* current smbus implementation doesn't like
121*7709dbf1SBALATON Zoltan                        multibyte xfer repeated start */
122*7709dbf1SBALATON Zoltan                     i2c_end_transfer(i2c->bus);
123*7709dbf1SBALATON Zoltan                     if (i2c_start_transfer(i2c->bus, i2c->lmadr >> 1, 1)) {
124*7709dbf1SBALATON Zoltan                         /* if non zero is returned, the adress is not valid */
125*7709dbf1SBALATON Zoltan                         i2c->sts &= ~IIC_STS_PT;
126*7709dbf1SBALATON Zoltan                         i2c->sts |= IIC_STS_ERR;
127*7709dbf1SBALATON Zoltan                         i2c->extsts |= IIC_EXTSTS_XFRA;
128*7709dbf1SBALATON Zoltan                     } else {
129*7709dbf1SBALATON Zoltan                         /*i2c->sts |= IIC_STS_PT;*/
130*7709dbf1SBALATON Zoltan                         i2c->sts |= IIC_STS_MDBS;
131*7709dbf1SBALATON Zoltan                         i2c->sts &= ~IIC_STS_ERR;
132*7709dbf1SBALATON Zoltan                         i2c->extsts = 0;
133*7709dbf1SBALATON Zoltan                     }
134*7709dbf1SBALATON Zoltan                 }
135*7709dbf1SBALATON Zoltan                 pending--;
136*7709dbf1SBALATON Zoltan                 i2c->cntl = (i2c->cntl & 0xcf) | (pending << 4);
137*7709dbf1SBALATON Zoltan             }
138*7709dbf1SBALATON Zoltan         } else {
139*7709dbf1SBALATON Zoltan             qemu_log_mask(LOG_UNIMP, "[%s]%s: slave mode not implemented\n",
140*7709dbf1SBALATON Zoltan                           TYPE_PPC4xx_I2C, __func__);
141*7709dbf1SBALATON Zoltan         }
14265ca801bSBALATON Zoltan         break;
14365ca801bSBALATON Zoltan     case 0x02:
14465ca801bSBALATON Zoltan         ret = i2c->sdata;
14565ca801bSBALATON Zoltan         break;
14665ca801bSBALATON Zoltan     case 0x04:
14765ca801bSBALATON Zoltan         ret = i2c->lmadr;
14865ca801bSBALATON Zoltan         break;
14965ca801bSBALATON Zoltan     case 0x05:
15065ca801bSBALATON Zoltan         ret = i2c->hmadr;
15165ca801bSBALATON Zoltan         break;
15265ca801bSBALATON Zoltan     case 0x06:
15365ca801bSBALATON Zoltan         ret = i2c->cntl;
15465ca801bSBALATON Zoltan         break;
15565ca801bSBALATON Zoltan     case 0x07:
15665ca801bSBALATON Zoltan         ret = i2c->mdcntl;
15765ca801bSBALATON Zoltan         break;
15865ca801bSBALATON Zoltan     case 0x08:
15965ca801bSBALATON Zoltan         ret = i2c->sts;
16065ca801bSBALATON Zoltan         break;
16165ca801bSBALATON Zoltan     case 0x09:
16265ca801bSBALATON Zoltan         ret = i2c->extsts;
16365ca801bSBALATON Zoltan         break;
16465ca801bSBALATON Zoltan     case 0x0A:
16565ca801bSBALATON Zoltan         ret = i2c->lsadr;
16665ca801bSBALATON Zoltan         break;
16765ca801bSBALATON Zoltan     case 0x0B:
16865ca801bSBALATON Zoltan         ret = i2c->hsadr;
16965ca801bSBALATON Zoltan         break;
17065ca801bSBALATON Zoltan     case 0x0C:
17165ca801bSBALATON Zoltan         ret = i2c->clkdiv;
17265ca801bSBALATON Zoltan         break;
17365ca801bSBALATON Zoltan     case 0x0D:
17465ca801bSBALATON Zoltan         ret = i2c->intrmsk;
17565ca801bSBALATON Zoltan         break;
17665ca801bSBALATON Zoltan     case 0x0E:
17765ca801bSBALATON Zoltan         ret = i2c->xfrcnt;
17865ca801bSBALATON Zoltan         break;
17965ca801bSBALATON Zoltan     case 0x0F:
18065ca801bSBALATON Zoltan         ret = i2c->xtcntlss;
18165ca801bSBALATON Zoltan         break;
18265ca801bSBALATON Zoltan     case 0x10:
18365ca801bSBALATON Zoltan         ret = i2c->directcntl;
18465ca801bSBALATON Zoltan         break;
185*7709dbf1SBALATON Zoltan     case 0x11:
186*7709dbf1SBALATON Zoltan         ret = i2c->intr;
187*7709dbf1SBALATON Zoltan         break;
18865ca801bSBALATON Zoltan     default:
189*7709dbf1SBALATON Zoltan         qemu_log_mask(LOG_GUEST_ERROR, "[%s]%s: Bad address at offset 0x%"
190*7709dbf1SBALATON Zoltan                       HWADDR_PRIx "\n", TYPE_PPC4xx_I2C, __func__, addr);
191*7709dbf1SBALATON Zoltan         ret = 0;
19265ca801bSBALATON Zoltan         break;
19365ca801bSBALATON Zoltan     }
19465ca801bSBALATON Zoltan 
19565ca801bSBALATON Zoltan     return ret;
19665ca801bSBALATON Zoltan }
19765ca801bSBALATON Zoltan 
1983b09bb0fSBALATON Zoltan static void ppc4xx_i2c_writeb(void *opaque, hwaddr addr, uint64_t value,
1993b09bb0fSBALATON Zoltan                               unsigned int size)
20065ca801bSBALATON Zoltan {
2013b09bb0fSBALATON Zoltan     PPC4xxI2CState *i2c = opaque;
202*7709dbf1SBALATON Zoltan 
20365ca801bSBALATON Zoltan     switch (addr) {
20465ca801bSBALATON Zoltan     case 0x00:
20565ca801bSBALATON Zoltan         i2c->mdata = value;
206*7709dbf1SBALATON Zoltan         if (!i2c_bus_busy(i2c->bus)) {
207*7709dbf1SBALATON Zoltan             /* assume we start a write transfer */
208*7709dbf1SBALATON Zoltan             if (i2c_start_transfer(i2c->bus, i2c->lmadr >> 1, 0)) {
209*7709dbf1SBALATON Zoltan                 /* if non zero is returned, the adress is not valid */
210*7709dbf1SBALATON Zoltan                 i2c->sts &= ~IIC_STS_PT;
211*7709dbf1SBALATON Zoltan                 i2c->sts |= IIC_STS_ERR;
212*7709dbf1SBALATON Zoltan                 i2c->extsts |= IIC_EXTSTS_XFRA;
213*7709dbf1SBALATON Zoltan             } else {
214*7709dbf1SBALATON Zoltan                 i2c->sts |= IIC_STS_PT;
215*7709dbf1SBALATON Zoltan                 i2c->sts &= ~IIC_STS_ERR;
216*7709dbf1SBALATON Zoltan                 i2c->extsts = 0;
217*7709dbf1SBALATON Zoltan             }
218*7709dbf1SBALATON Zoltan         }
219*7709dbf1SBALATON Zoltan         if (i2c_bus_busy(i2c->bus)) {
220*7709dbf1SBALATON Zoltan             if (i2c_send(i2c->bus, i2c->mdata)) {
221*7709dbf1SBALATON Zoltan                 /* if the target return non zero then end the transfer */
222*7709dbf1SBALATON Zoltan                 i2c->sts &= ~IIC_STS_PT;
223*7709dbf1SBALATON Zoltan                 i2c->sts |= IIC_STS_ERR;
224*7709dbf1SBALATON Zoltan                 i2c->extsts |= IIC_EXTSTS_XFRA;
225*7709dbf1SBALATON Zoltan                 i2c_end_transfer(i2c->bus);
226*7709dbf1SBALATON Zoltan             }
227*7709dbf1SBALATON Zoltan         }
22865ca801bSBALATON Zoltan         break;
22965ca801bSBALATON Zoltan     case 0x02:
23065ca801bSBALATON Zoltan         i2c->sdata = value;
23165ca801bSBALATON Zoltan         break;
23265ca801bSBALATON Zoltan     case 0x04:
23365ca801bSBALATON Zoltan         i2c->lmadr = value;
234*7709dbf1SBALATON Zoltan         if (i2c_bus_busy(i2c->bus)) {
235*7709dbf1SBALATON Zoltan             i2c_end_transfer(i2c->bus);
236*7709dbf1SBALATON Zoltan         }
23765ca801bSBALATON Zoltan         break;
23865ca801bSBALATON Zoltan     case 0x05:
23965ca801bSBALATON Zoltan         i2c->hmadr = value;
24065ca801bSBALATON Zoltan         break;
24165ca801bSBALATON Zoltan     case 0x06:
24265ca801bSBALATON Zoltan         i2c->cntl = value;
243*7709dbf1SBALATON Zoltan         if (i2c->cntl & IIC_CNTL_PT) {
244*7709dbf1SBALATON Zoltan             if (i2c->cntl & IIC_CNTL_READ) {
245*7709dbf1SBALATON Zoltan                 if (i2c_bus_busy(i2c->bus)) {
246*7709dbf1SBALATON Zoltan                     /* end previous transfer */
247*7709dbf1SBALATON Zoltan                     i2c->sts &= ~IIC_STS_PT;
248*7709dbf1SBALATON Zoltan                     i2c_end_transfer(i2c->bus);
249*7709dbf1SBALATON Zoltan                 }
250*7709dbf1SBALATON Zoltan                 if (i2c_start_transfer(i2c->bus, i2c->lmadr >> 1, 1)) {
251*7709dbf1SBALATON Zoltan                     /* if non zero is returned, the adress is not valid */
252*7709dbf1SBALATON Zoltan                     i2c->sts &= ~IIC_STS_PT;
253*7709dbf1SBALATON Zoltan                     i2c->sts |= IIC_STS_ERR;
254*7709dbf1SBALATON Zoltan                     i2c->extsts |= IIC_EXTSTS_XFRA;
255*7709dbf1SBALATON Zoltan                 } else {
256*7709dbf1SBALATON Zoltan                     /*i2c->sts |= IIC_STS_PT;*/
257*7709dbf1SBALATON Zoltan                     i2c->sts |= IIC_STS_MDBS;
258*7709dbf1SBALATON Zoltan                     i2c->sts &= ~IIC_STS_ERR;
259*7709dbf1SBALATON Zoltan                     i2c->extsts = 0;
260*7709dbf1SBALATON Zoltan                 }
261*7709dbf1SBALATON Zoltan             } else {
262*7709dbf1SBALATON Zoltan                 /* we actually already did the write transfer... */
263*7709dbf1SBALATON Zoltan                 i2c->sts &= ~IIC_STS_PT;
264*7709dbf1SBALATON Zoltan             }
265*7709dbf1SBALATON Zoltan         }
26665ca801bSBALATON Zoltan         break;
26765ca801bSBALATON Zoltan     case 0x07:
26865ca801bSBALATON Zoltan         i2c->mdcntl = value & 0xDF;
26965ca801bSBALATON Zoltan         break;
27065ca801bSBALATON Zoltan     case 0x08:
27165ca801bSBALATON Zoltan         i2c->sts &= ~(value & 0x0A);
27265ca801bSBALATON Zoltan         break;
27365ca801bSBALATON Zoltan     case 0x09:
27465ca801bSBALATON Zoltan         i2c->extsts &= ~(value & 0x8F);
27565ca801bSBALATON Zoltan         break;
27665ca801bSBALATON Zoltan     case 0x0A:
27765ca801bSBALATON Zoltan         i2c->lsadr = value;
278*7709dbf1SBALATON Zoltan         /*i2c_set_slave_address(i2c->bus, i2c->lsadr);*/
27965ca801bSBALATON Zoltan         break;
28065ca801bSBALATON Zoltan     case 0x0B:
28165ca801bSBALATON Zoltan         i2c->hsadr = value;
28265ca801bSBALATON Zoltan         break;
28365ca801bSBALATON Zoltan     case 0x0C:
28465ca801bSBALATON Zoltan         i2c->clkdiv = value;
28565ca801bSBALATON Zoltan         break;
28665ca801bSBALATON Zoltan     case 0x0D:
28765ca801bSBALATON Zoltan         i2c->intrmsk = value;
28865ca801bSBALATON Zoltan         break;
28965ca801bSBALATON Zoltan     case 0x0E:
29065ca801bSBALATON Zoltan         i2c->xfrcnt = value & 0x77;
29165ca801bSBALATON Zoltan         break;
29265ca801bSBALATON Zoltan     case 0x0F:
293*7709dbf1SBALATON Zoltan         if (value & IIC_XTCNTLSS_SRST) {
294*7709dbf1SBALATON Zoltan             /* Is it actually a full reset? U-Boot sets some regs before */
295*7709dbf1SBALATON Zoltan             ppc4xx_i2c_reset(DEVICE(i2c));
296*7709dbf1SBALATON Zoltan             break;
297*7709dbf1SBALATON Zoltan         }
29865ca801bSBALATON Zoltan         i2c->xtcntlss = value;
29965ca801bSBALATON Zoltan         break;
30065ca801bSBALATON Zoltan     case 0x10:
30165ca801bSBALATON Zoltan         i2c->directcntl = value & 0x7;
30265ca801bSBALATON Zoltan         break;
303*7709dbf1SBALATON Zoltan     case 0x11:
304*7709dbf1SBALATON Zoltan         i2c->intr = value;
305*7709dbf1SBALATON Zoltan         break;
306*7709dbf1SBALATON Zoltan     default:
307*7709dbf1SBALATON Zoltan         qemu_log_mask(LOG_GUEST_ERROR, "[%s]%s: Bad address at offset 0x%"
308*7709dbf1SBALATON Zoltan                       HWADDR_PRIx "\n", TYPE_PPC4xx_I2C, __func__, addr);
309*7709dbf1SBALATON Zoltan         break;
31065ca801bSBALATON Zoltan     }
31165ca801bSBALATON Zoltan }
31265ca801bSBALATON Zoltan 
3133b09bb0fSBALATON Zoltan static const MemoryRegionOps ppc4xx_i2c_ops = {
3143b09bb0fSBALATON Zoltan     .read = ppc4xx_i2c_readb,
3153b09bb0fSBALATON Zoltan     .write = ppc4xx_i2c_writeb,
3163b09bb0fSBALATON Zoltan     .valid.min_access_size = 1,
3173b09bb0fSBALATON Zoltan     .valid.max_access_size = 4,
3183b09bb0fSBALATON Zoltan     .impl.min_access_size = 1,
3193b09bb0fSBALATON Zoltan     .impl.max_access_size = 1,
32065ca801bSBALATON Zoltan     .endianness = DEVICE_NATIVE_ENDIAN,
32165ca801bSBALATON Zoltan };
32265ca801bSBALATON Zoltan 
3233b09bb0fSBALATON Zoltan static void ppc4xx_i2c_init(Object *o)
32465ca801bSBALATON Zoltan {
3253b09bb0fSBALATON Zoltan     PPC4xxI2CState *s = PPC4xx_I2C(o);
32665ca801bSBALATON Zoltan 
3273b09bb0fSBALATON Zoltan     memory_region_init_io(&s->iomem, OBJECT(s), &ppc4xx_i2c_ops, s,
3283b09bb0fSBALATON Zoltan                           TYPE_PPC4xx_I2C, PPC4xx_I2C_MEM_SIZE);
3293b09bb0fSBALATON Zoltan     sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->iomem);
3303b09bb0fSBALATON Zoltan     sysbus_init_irq(SYS_BUS_DEVICE(s), &s->irq);
3313b09bb0fSBALATON Zoltan     s->bus = i2c_init_bus(DEVICE(s), "i2c");
33265ca801bSBALATON Zoltan }
3333b09bb0fSBALATON Zoltan 
3343b09bb0fSBALATON Zoltan static void ppc4xx_i2c_class_init(ObjectClass *klass, void *data)
3353b09bb0fSBALATON Zoltan {
3363b09bb0fSBALATON Zoltan     DeviceClass *dc = DEVICE_CLASS(klass);
3373b09bb0fSBALATON Zoltan 
3383b09bb0fSBALATON Zoltan     dc->reset = ppc4xx_i2c_reset;
3393b09bb0fSBALATON Zoltan }
3403b09bb0fSBALATON Zoltan 
3413b09bb0fSBALATON Zoltan static const TypeInfo ppc4xx_i2c_type_info = {
3423b09bb0fSBALATON Zoltan     .name = TYPE_PPC4xx_I2C,
3433b09bb0fSBALATON Zoltan     .parent = TYPE_SYS_BUS_DEVICE,
3443b09bb0fSBALATON Zoltan     .instance_size = sizeof(PPC4xxI2CState),
3453b09bb0fSBALATON Zoltan     .instance_init = ppc4xx_i2c_init,
3463b09bb0fSBALATON Zoltan     .class_init = ppc4xx_i2c_class_init,
3473b09bb0fSBALATON Zoltan };
3483b09bb0fSBALATON Zoltan 
3493b09bb0fSBALATON Zoltan static void ppc4xx_i2c_register_types(void)
3503b09bb0fSBALATON Zoltan {
3513b09bb0fSBALATON Zoltan     type_register_static(&ppc4xx_i2c_type_info);
3523b09bb0fSBALATON Zoltan }
3533b09bb0fSBALATON Zoltan 
3543b09bb0fSBALATON Zoltan type_init(ppc4xx_i2c_register_types)
355