xref: /qemu/hw/i2c/ppc4xx_i2c.c (revision 42a907e83921ff2c4f5e6ca9fa6aa6791b43a73f)
165ca801bSBALATON Zoltan /*
265ca801bSBALATON Zoltan  * PPC4xx I2C controller emulation
365ca801bSBALATON Zoltan  *
465ca801bSBALATON Zoltan  * Copyright (c) 2007 Jocelyn Mayer
57709dbf1SBALATON Zoltan  * Copyright (c) 2012 François Revol
67709dbf1SBALATON 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 "qemu-common.h"
297709dbf1SBALATON Zoltan #include "qemu/log.h"
3065ca801bSBALATON Zoltan #include "cpu.h"
3165ca801bSBALATON Zoltan #include "hw/hw.h"
323b09bb0fSBALATON Zoltan #include "hw/i2c/ppc4xx_i2c.h"
3365ca801bSBALATON Zoltan 
34*42a907e8SBALATON Zoltan #define PPC4xx_I2C_MEM_SIZE 18
3565ca801bSBALATON Zoltan 
367709dbf1SBALATON Zoltan #define IIC_CNTL_PT         (1 << 0)
377709dbf1SBALATON Zoltan #define IIC_CNTL_READ       (1 << 1)
387709dbf1SBALATON Zoltan #define IIC_CNTL_CHT        (1 << 2)
397709dbf1SBALATON Zoltan #define IIC_CNTL_RPST       (1 << 3)
407709dbf1SBALATON Zoltan 
417709dbf1SBALATON Zoltan #define IIC_STS_PT          (1 << 0)
427709dbf1SBALATON Zoltan #define IIC_STS_ERR         (1 << 2)
437709dbf1SBALATON Zoltan #define IIC_STS_MDBS        (1 << 5)
447709dbf1SBALATON Zoltan 
457709dbf1SBALATON Zoltan #define IIC_EXTSTS_XFRA     (1 << 0)
467709dbf1SBALATON Zoltan 
477709dbf1SBALATON Zoltan #define IIC_XTCNTLSS_SRST   (1 << 0)
487709dbf1SBALATON Zoltan 
497709dbf1SBALATON Zoltan static void ppc4xx_i2c_reset(DeviceState *s)
507709dbf1SBALATON Zoltan {
517709dbf1SBALATON Zoltan     PPC4xxI2CState *i2c = PPC4xx_I2C(s);
527709dbf1SBALATON Zoltan 
537709dbf1SBALATON Zoltan     /* FIXME: Should also reset bus?
547709dbf1SBALATON Zoltan      *if (s->address != ADDR_RESET) {
557709dbf1SBALATON Zoltan      *    i2c_end_transfer(s->bus);
567709dbf1SBALATON Zoltan      *}
577709dbf1SBALATON Zoltan      */
587709dbf1SBALATON Zoltan 
597709dbf1SBALATON Zoltan     i2c->mdata = 0;
607709dbf1SBALATON Zoltan     i2c->lmadr = 0;
617709dbf1SBALATON Zoltan     i2c->hmadr = 0;
627709dbf1SBALATON Zoltan     i2c->cntl = 0;
637709dbf1SBALATON Zoltan     i2c->mdcntl = 0;
647709dbf1SBALATON Zoltan     i2c->sts = 0;
657709dbf1SBALATON Zoltan     i2c->extsts = 0x8f;
667709dbf1SBALATON Zoltan     i2c->sdata = 0;
677709dbf1SBALATON Zoltan     i2c->lsadr = 0;
687709dbf1SBALATON Zoltan     i2c->hsadr = 0;
697709dbf1SBALATON Zoltan     i2c->clkdiv = 0;
707709dbf1SBALATON Zoltan     i2c->intrmsk = 0;
717709dbf1SBALATON Zoltan     i2c->xfrcnt = 0;
727709dbf1SBALATON Zoltan     i2c->xtcntlss = 0;
73*42a907e8SBALATON Zoltan     i2c->directcntl = 0xf;
747709dbf1SBALATON Zoltan     i2c->intr = 0;
757709dbf1SBALATON Zoltan }
767709dbf1SBALATON Zoltan 
777709dbf1SBALATON Zoltan static inline bool ppc4xx_i2c_is_master(PPC4xxI2CState *i2c)
787709dbf1SBALATON Zoltan {
797709dbf1SBALATON Zoltan     return true;
807709dbf1SBALATON Zoltan }
8165ca801bSBALATON Zoltan 
823b09bb0fSBALATON Zoltan static uint64_t ppc4xx_i2c_readb(void *opaque, hwaddr addr, unsigned int size)
8365ca801bSBALATON Zoltan {
843b09bb0fSBALATON Zoltan     PPC4xxI2CState *i2c = PPC4xx_I2C(opaque);
853b09bb0fSBALATON Zoltan     uint64_t ret;
8665ca801bSBALATON Zoltan 
8765ca801bSBALATON Zoltan     switch (addr) {
88*42a907e8SBALATON Zoltan     case 0:
8965ca801bSBALATON Zoltan         ret = i2c->mdata;
907709dbf1SBALATON Zoltan         if (ppc4xx_i2c_is_master(i2c)) {
917709dbf1SBALATON Zoltan             ret = 0xff;
927709dbf1SBALATON Zoltan 
937709dbf1SBALATON Zoltan             if (!(i2c->sts & IIC_STS_MDBS)) {
947709dbf1SBALATON Zoltan                 qemu_log_mask(LOG_GUEST_ERROR, "[%s]%s: Trying to read "
957709dbf1SBALATON Zoltan                               "without starting transfer\n",
967709dbf1SBALATON Zoltan                               TYPE_PPC4xx_I2C, __func__);
977709dbf1SBALATON Zoltan             } else {
987709dbf1SBALATON Zoltan                 int pending = (i2c->cntl >> 4) & 3;
997709dbf1SBALATON Zoltan 
1007709dbf1SBALATON Zoltan                 /* get the next byte */
1017709dbf1SBALATON Zoltan                 int byte = i2c_recv(i2c->bus);
1027709dbf1SBALATON Zoltan 
1037709dbf1SBALATON Zoltan                 if (byte < 0) {
1047709dbf1SBALATON Zoltan                     qemu_log_mask(LOG_GUEST_ERROR, "[%s]%s: read failed "
1057709dbf1SBALATON Zoltan                                   "for device 0x%02x\n", TYPE_PPC4xx_I2C,
1067709dbf1SBALATON Zoltan                                   __func__, i2c->lmadr);
1077709dbf1SBALATON Zoltan                     ret = 0xff;
1087709dbf1SBALATON Zoltan                 } else {
1097709dbf1SBALATON Zoltan                     ret = byte;
1107709dbf1SBALATON Zoltan                     /* Raise interrupt if enabled */
1117709dbf1SBALATON Zoltan                     /*ppc4xx_i2c_raise_interrupt(i2c)*/;
1127709dbf1SBALATON Zoltan                 }
1137709dbf1SBALATON Zoltan 
1147709dbf1SBALATON Zoltan                 if (!pending) {
1157709dbf1SBALATON Zoltan                     i2c->sts &= ~IIC_STS_MDBS;
1167709dbf1SBALATON Zoltan                     /*i2c_end_transfer(i2c->bus);*/
1177709dbf1SBALATON Zoltan                 /*} else if (i2c->cntl & (IIC_CNTL_RPST | IIC_CNTL_CHT)) {*/
1187709dbf1SBALATON Zoltan                 } else if (pending) {
1197709dbf1SBALATON Zoltan                     /* current smbus implementation doesn't like
1207709dbf1SBALATON Zoltan                        multibyte xfer repeated start */
1217709dbf1SBALATON Zoltan                     i2c_end_transfer(i2c->bus);
1227709dbf1SBALATON Zoltan                     if (i2c_start_transfer(i2c->bus, i2c->lmadr >> 1, 1)) {
1237709dbf1SBALATON Zoltan                         /* if non zero is returned, the adress is not valid */
1247709dbf1SBALATON Zoltan                         i2c->sts &= ~IIC_STS_PT;
1257709dbf1SBALATON Zoltan                         i2c->sts |= IIC_STS_ERR;
1267709dbf1SBALATON Zoltan                         i2c->extsts |= IIC_EXTSTS_XFRA;
1277709dbf1SBALATON Zoltan                     } else {
1287709dbf1SBALATON Zoltan                         /*i2c->sts |= IIC_STS_PT;*/
1297709dbf1SBALATON Zoltan                         i2c->sts |= IIC_STS_MDBS;
1307709dbf1SBALATON Zoltan                         i2c->sts &= ~IIC_STS_ERR;
1317709dbf1SBALATON Zoltan                         i2c->extsts = 0;
1327709dbf1SBALATON Zoltan                     }
1337709dbf1SBALATON Zoltan                 }
1347709dbf1SBALATON Zoltan                 pending--;
1357709dbf1SBALATON Zoltan                 i2c->cntl = (i2c->cntl & 0xcf) | (pending << 4);
1367709dbf1SBALATON Zoltan             }
1377709dbf1SBALATON Zoltan         } else {
1387709dbf1SBALATON Zoltan             qemu_log_mask(LOG_UNIMP, "[%s]%s: slave mode not implemented\n",
1397709dbf1SBALATON Zoltan                           TYPE_PPC4xx_I2C, __func__);
1407709dbf1SBALATON Zoltan         }
14165ca801bSBALATON Zoltan         break;
142*42a907e8SBALATON Zoltan     case 2:
14365ca801bSBALATON Zoltan         ret = i2c->sdata;
14465ca801bSBALATON Zoltan         break;
145*42a907e8SBALATON Zoltan     case 4:
14665ca801bSBALATON Zoltan         ret = i2c->lmadr;
14765ca801bSBALATON Zoltan         break;
148*42a907e8SBALATON Zoltan     case 5:
14965ca801bSBALATON Zoltan         ret = i2c->hmadr;
15065ca801bSBALATON Zoltan         break;
151*42a907e8SBALATON Zoltan     case 6:
15265ca801bSBALATON Zoltan         ret = i2c->cntl;
15365ca801bSBALATON Zoltan         break;
154*42a907e8SBALATON Zoltan     case 7:
15565ca801bSBALATON Zoltan         ret = i2c->mdcntl;
15665ca801bSBALATON Zoltan         break;
157*42a907e8SBALATON Zoltan     case 8:
15865ca801bSBALATON Zoltan         ret = i2c->sts;
15965ca801bSBALATON Zoltan         break;
160*42a907e8SBALATON Zoltan     case 9:
16165ca801bSBALATON Zoltan         ret = i2c->extsts;
16265ca801bSBALATON Zoltan         break;
163*42a907e8SBALATON Zoltan     case 10:
16465ca801bSBALATON Zoltan         ret = i2c->lsadr;
16565ca801bSBALATON Zoltan         break;
166*42a907e8SBALATON Zoltan     case 11:
16765ca801bSBALATON Zoltan         ret = i2c->hsadr;
16865ca801bSBALATON Zoltan         break;
169*42a907e8SBALATON Zoltan     case 12:
17065ca801bSBALATON Zoltan         ret = i2c->clkdiv;
17165ca801bSBALATON Zoltan         break;
172*42a907e8SBALATON Zoltan     case 13:
17365ca801bSBALATON Zoltan         ret = i2c->intrmsk;
17465ca801bSBALATON Zoltan         break;
175*42a907e8SBALATON Zoltan     case 14:
17665ca801bSBALATON Zoltan         ret = i2c->xfrcnt;
17765ca801bSBALATON Zoltan         break;
178*42a907e8SBALATON Zoltan     case 15:
17965ca801bSBALATON Zoltan         ret = i2c->xtcntlss;
18065ca801bSBALATON Zoltan         break;
181*42a907e8SBALATON Zoltan     case 16:
18265ca801bSBALATON Zoltan         ret = i2c->directcntl;
18365ca801bSBALATON Zoltan         break;
184*42a907e8SBALATON Zoltan     case 17:
1857709dbf1SBALATON Zoltan         ret = i2c->intr;
1867709dbf1SBALATON Zoltan         break;
18765ca801bSBALATON Zoltan     default:
188*42a907e8SBALATON Zoltan         if (addr < PPC4xx_I2C_MEM_SIZE) {
189*42a907e8SBALATON Zoltan             qemu_log_mask(LOG_UNIMP, "%s: Unimplemented register 0x%"
190*42a907e8SBALATON Zoltan                           HWADDR_PRIx "\n", __func__, addr);
191*42a907e8SBALATON Zoltan         } else {
192*42a907e8SBALATON Zoltan             qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad address 0x%"
193*42a907e8SBALATON Zoltan                           HWADDR_PRIx "\n", __func__, addr);
194*42a907e8SBALATON Zoltan         }
1957709dbf1SBALATON Zoltan         ret = 0;
19665ca801bSBALATON Zoltan         break;
19765ca801bSBALATON Zoltan     }
19865ca801bSBALATON Zoltan     return ret;
19965ca801bSBALATON Zoltan }
20065ca801bSBALATON Zoltan 
2013b09bb0fSBALATON Zoltan static void ppc4xx_i2c_writeb(void *opaque, hwaddr addr, uint64_t value,
2023b09bb0fSBALATON Zoltan                               unsigned int size)
20365ca801bSBALATON Zoltan {
2043b09bb0fSBALATON Zoltan     PPC4xxI2CState *i2c = opaque;
2057709dbf1SBALATON Zoltan 
20665ca801bSBALATON Zoltan     switch (addr) {
207*42a907e8SBALATON Zoltan     case 0:
20865ca801bSBALATON Zoltan         i2c->mdata = value;
2097709dbf1SBALATON Zoltan         if (!i2c_bus_busy(i2c->bus)) {
2107709dbf1SBALATON Zoltan             /* assume we start a write transfer */
2117709dbf1SBALATON Zoltan             if (i2c_start_transfer(i2c->bus, i2c->lmadr >> 1, 0)) {
2127709dbf1SBALATON Zoltan                 /* if non zero is returned, the adress is not valid */
2137709dbf1SBALATON Zoltan                 i2c->sts &= ~IIC_STS_PT;
2147709dbf1SBALATON Zoltan                 i2c->sts |= IIC_STS_ERR;
2157709dbf1SBALATON Zoltan                 i2c->extsts |= IIC_EXTSTS_XFRA;
2167709dbf1SBALATON Zoltan             } else {
2177709dbf1SBALATON Zoltan                 i2c->sts |= IIC_STS_PT;
2187709dbf1SBALATON Zoltan                 i2c->sts &= ~IIC_STS_ERR;
2197709dbf1SBALATON Zoltan                 i2c->extsts = 0;
2207709dbf1SBALATON Zoltan             }
2217709dbf1SBALATON Zoltan         }
2227709dbf1SBALATON Zoltan         if (i2c_bus_busy(i2c->bus)) {
2237709dbf1SBALATON Zoltan             if (i2c_send(i2c->bus, i2c->mdata)) {
2247709dbf1SBALATON Zoltan                 /* if the target return non zero then end the transfer */
2257709dbf1SBALATON Zoltan                 i2c->sts &= ~IIC_STS_PT;
2267709dbf1SBALATON Zoltan                 i2c->sts |= IIC_STS_ERR;
2277709dbf1SBALATON Zoltan                 i2c->extsts |= IIC_EXTSTS_XFRA;
2287709dbf1SBALATON Zoltan                 i2c_end_transfer(i2c->bus);
2297709dbf1SBALATON Zoltan             }
2307709dbf1SBALATON Zoltan         }
23165ca801bSBALATON Zoltan         break;
232*42a907e8SBALATON Zoltan     case 2:
23365ca801bSBALATON Zoltan         i2c->sdata = value;
23465ca801bSBALATON Zoltan         break;
235*42a907e8SBALATON Zoltan     case 4:
23665ca801bSBALATON Zoltan         i2c->lmadr = value;
2377709dbf1SBALATON Zoltan         if (i2c_bus_busy(i2c->bus)) {
2387709dbf1SBALATON Zoltan             i2c_end_transfer(i2c->bus);
2397709dbf1SBALATON Zoltan         }
24065ca801bSBALATON Zoltan         break;
241*42a907e8SBALATON Zoltan     case 5:
24265ca801bSBALATON Zoltan         i2c->hmadr = value;
24365ca801bSBALATON Zoltan         break;
244*42a907e8SBALATON Zoltan     case 6:
24565ca801bSBALATON Zoltan         i2c->cntl = value;
2467709dbf1SBALATON Zoltan         if (i2c->cntl & IIC_CNTL_PT) {
2477709dbf1SBALATON Zoltan             if (i2c->cntl & IIC_CNTL_READ) {
2487709dbf1SBALATON Zoltan                 if (i2c_bus_busy(i2c->bus)) {
2497709dbf1SBALATON Zoltan                     /* end previous transfer */
2507709dbf1SBALATON Zoltan                     i2c->sts &= ~IIC_STS_PT;
2517709dbf1SBALATON Zoltan                     i2c_end_transfer(i2c->bus);
2527709dbf1SBALATON Zoltan                 }
2537709dbf1SBALATON Zoltan                 if (i2c_start_transfer(i2c->bus, i2c->lmadr >> 1, 1)) {
2547709dbf1SBALATON Zoltan                     /* if non zero is returned, the adress is not valid */
2557709dbf1SBALATON Zoltan                     i2c->sts &= ~IIC_STS_PT;
2567709dbf1SBALATON Zoltan                     i2c->sts |= IIC_STS_ERR;
2577709dbf1SBALATON Zoltan                     i2c->extsts |= IIC_EXTSTS_XFRA;
2587709dbf1SBALATON Zoltan                 } else {
2597709dbf1SBALATON Zoltan                     /*i2c->sts |= IIC_STS_PT;*/
2607709dbf1SBALATON Zoltan                     i2c->sts |= IIC_STS_MDBS;
2617709dbf1SBALATON Zoltan                     i2c->sts &= ~IIC_STS_ERR;
2627709dbf1SBALATON Zoltan                     i2c->extsts = 0;
2637709dbf1SBALATON Zoltan                 }
2647709dbf1SBALATON Zoltan             } else {
2657709dbf1SBALATON Zoltan                 /* we actually already did the write transfer... */
2667709dbf1SBALATON Zoltan                 i2c->sts &= ~IIC_STS_PT;
2677709dbf1SBALATON Zoltan             }
2687709dbf1SBALATON Zoltan         }
26965ca801bSBALATON Zoltan         break;
270*42a907e8SBALATON Zoltan     case 7:
271*42a907e8SBALATON Zoltan         i2c->mdcntl = value & 0xdf;
27265ca801bSBALATON Zoltan         break;
273*42a907e8SBALATON Zoltan     case 8:
274*42a907e8SBALATON Zoltan         i2c->sts &= ~(value & 0xa);
27565ca801bSBALATON Zoltan         break;
276*42a907e8SBALATON Zoltan     case 9:
277*42a907e8SBALATON Zoltan         i2c->extsts &= ~(value & 0x8f);
27865ca801bSBALATON Zoltan         break;
279*42a907e8SBALATON Zoltan     case 10:
28065ca801bSBALATON Zoltan         i2c->lsadr = value;
28165ca801bSBALATON Zoltan         break;
282*42a907e8SBALATON Zoltan     case 11:
28365ca801bSBALATON Zoltan         i2c->hsadr = value;
28465ca801bSBALATON Zoltan         break;
285*42a907e8SBALATON Zoltan     case 12:
28665ca801bSBALATON Zoltan         i2c->clkdiv = value;
28765ca801bSBALATON Zoltan         break;
288*42a907e8SBALATON Zoltan     case 13:
28965ca801bSBALATON Zoltan         i2c->intrmsk = value;
29065ca801bSBALATON Zoltan         break;
291*42a907e8SBALATON Zoltan     case 14:
29265ca801bSBALATON Zoltan         i2c->xfrcnt = value & 0x77;
29365ca801bSBALATON Zoltan         break;
294*42a907e8SBALATON Zoltan     case 15:
2957709dbf1SBALATON Zoltan         if (value & IIC_XTCNTLSS_SRST) {
2967709dbf1SBALATON Zoltan             /* Is it actually a full reset? U-Boot sets some regs before */
2977709dbf1SBALATON Zoltan             ppc4xx_i2c_reset(DEVICE(i2c));
2987709dbf1SBALATON Zoltan             break;
2997709dbf1SBALATON Zoltan         }
30065ca801bSBALATON Zoltan         i2c->xtcntlss = value;
30165ca801bSBALATON Zoltan         break;
302*42a907e8SBALATON Zoltan     case 16:
30365ca801bSBALATON Zoltan         i2c->directcntl = value & 0x7;
30465ca801bSBALATON Zoltan         break;
305*42a907e8SBALATON Zoltan     case 17:
3067709dbf1SBALATON Zoltan         i2c->intr = value;
3077709dbf1SBALATON Zoltan         break;
3087709dbf1SBALATON Zoltan     default:
309*42a907e8SBALATON Zoltan         if (addr < PPC4xx_I2C_MEM_SIZE) {
310*42a907e8SBALATON Zoltan             qemu_log_mask(LOG_UNIMP, "%s: Unimplemented register 0x%"
311*42a907e8SBALATON Zoltan                           HWADDR_PRIx "\n", __func__, addr);
312*42a907e8SBALATON Zoltan         } else {
313*42a907e8SBALATON Zoltan             qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad address 0x%"
314*42a907e8SBALATON Zoltan                           HWADDR_PRIx "\n", __func__, addr);
315*42a907e8SBALATON Zoltan         }
3167709dbf1SBALATON Zoltan         break;
31765ca801bSBALATON Zoltan     }
31865ca801bSBALATON Zoltan }
31965ca801bSBALATON Zoltan 
3203b09bb0fSBALATON Zoltan static const MemoryRegionOps ppc4xx_i2c_ops = {
3213b09bb0fSBALATON Zoltan     .read = ppc4xx_i2c_readb,
3223b09bb0fSBALATON Zoltan     .write = ppc4xx_i2c_writeb,
3233b09bb0fSBALATON Zoltan     .valid.min_access_size = 1,
3243b09bb0fSBALATON Zoltan     .valid.max_access_size = 4,
3253b09bb0fSBALATON Zoltan     .impl.min_access_size = 1,
3263b09bb0fSBALATON Zoltan     .impl.max_access_size = 1,
32765ca801bSBALATON Zoltan     .endianness = DEVICE_NATIVE_ENDIAN,
32865ca801bSBALATON Zoltan };
32965ca801bSBALATON Zoltan 
3303b09bb0fSBALATON Zoltan static void ppc4xx_i2c_init(Object *o)
33165ca801bSBALATON Zoltan {
3323b09bb0fSBALATON Zoltan     PPC4xxI2CState *s = PPC4xx_I2C(o);
33365ca801bSBALATON Zoltan 
3343b09bb0fSBALATON Zoltan     memory_region_init_io(&s->iomem, OBJECT(s), &ppc4xx_i2c_ops, s,
3353b09bb0fSBALATON Zoltan                           TYPE_PPC4xx_I2C, PPC4xx_I2C_MEM_SIZE);
3363b09bb0fSBALATON Zoltan     sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->iomem);
3373b09bb0fSBALATON Zoltan     sysbus_init_irq(SYS_BUS_DEVICE(s), &s->irq);
3383b09bb0fSBALATON Zoltan     s->bus = i2c_init_bus(DEVICE(s), "i2c");
33965ca801bSBALATON Zoltan }
3403b09bb0fSBALATON Zoltan 
3413b09bb0fSBALATON Zoltan static void ppc4xx_i2c_class_init(ObjectClass *klass, void *data)
3423b09bb0fSBALATON Zoltan {
3433b09bb0fSBALATON Zoltan     DeviceClass *dc = DEVICE_CLASS(klass);
3443b09bb0fSBALATON Zoltan 
3453b09bb0fSBALATON Zoltan     dc->reset = ppc4xx_i2c_reset;
3463b09bb0fSBALATON Zoltan }
3473b09bb0fSBALATON Zoltan 
3483b09bb0fSBALATON Zoltan static const TypeInfo ppc4xx_i2c_type_info = {
3493b09bb0fSBALATON Zoltan     .name = TYPE_PPC4xx_I2C,
3503b09bb0fSBALATON Zoltan     .parent = TYPE_SYS_BUS_DEVICE,
3513b09bb0fSBALATON Zoltan     .instance_size = sizeof(PPC4xxI2CState),
3523b09bb0fSBALATON Zoltan     .instance_init = ppc4xx_i2c_init,
3533b09bb0fSBALATON Zoltan     .class_init = ppc4xx_i2c_class_init,
3543b09bb0fSBALATON Zoltan };
3553b09bb0fSBALATON Zoltan 
3563b09bb0fSBALATON Zoltan static void ppc4xx_i2c_register_types(void)
3573b09bb0fSBALATON Zoltan {
3583b09bb0fSBALATON Zoltan     type_register_static(&ppc4xx_i2c_type_info);
3593b09bb0fSBALATON Zoltan }
3603b09bb0fSBALATON Zoltan 
3613b09bb0fSBALATON Zoltan type_init(ppc4xx_i2c_register_types)
362