xref: /qemu/hw/i2c/ppc4xx_i2c.c (revision ef9173a5c086b5114343a86943f9b26a9c72d7d6)
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
639aeba6cSBALATON Zoltan  * Copyright (c) 2016-2018 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"
33*ef9173a5SBALATON Zoltan #include "bitbang_i2c.h"
3465ca801bSBALATON Zoltan 
3542a907e8SBALATON Zoltan #define PPC4xx_I2C_MEM_SIZE 18
3665ca801bSBALATON Zoltan 
377709dbf1SBALATON Zoltan #define IIC_CNTL_PT         (1 << 0)
387709dbf1SBALATON Zoltan #define IIC_CNTL_READ       (1 << 1)
397709dbf1SBALATON Zoltan #define IIC_CNTL_CHT        (1 << 2)
407709dbf1SBALATON Zoltan #define IIC_CNTL_RPST       (1 << 3)
417709dbf1SBALATON Zoltan 
427709dbf1SBALATON Zoltan #define IIC_STS_PT          (1 << 0)
437709dbf1SBALATON Zoltan #define IIC_STS_ERR         (1 << 2)
447709dbf1SBALATON Zoltan #define IIC_STS_MDBS        (1 << 5)
457709dbf1SBALATON Zoltan 
467709dbf1SBALATON Zoltan #define IIC_EXTSTS_XFRA     (1 << 0)
477709dbf1SBALATON Zoltan 
487709dbf1SBALATON Zoltan #define IIC_XTCNTLSS_SRST   (1 << 0)
497709dbf1SBALATON Zoltan 
50*ef9173a5SBALATON Zoltan #define IIC_DIRECTCNTL_SDAC (1 << 3)
51*ef9173a5SBALATON Zoltan #define IIC_DIRECTCNTL_SCLC (1 << 2)
52*ef9173a5SBALATON Zoltan #define IIC_DIRECTCNTL_MSDA (1 << 1)
53*ef9173a5SBALATON Zoltan #define IIC_DIRECTCNTL_MSCL (1 << 0)
54*ef9173a5SBALATON Zoltan 
557709dbf1SBALATON Zoltan static void ppc4xx_i2c_reset(DeviceState *s)
567709dbf1SBALATON Zoltan {
577709dbf1SBALATON Zoltan     PPC4xxI2CState *i2c = PPC4xx_I2C(s);
587709dbf1SBALATON Zoltan 
597709dbf1SBALATON Zoltan     /* FIXME: Should also reset bus?
607709dbf1SBALATON Zoltan      *if (s->address != ADDR_RESET) {
617709dbf1SBALATON Zoltan      *    i2c_end_transfer(s->bus);
627709dbf1SBALATON Zoltan      *}
637709dbf1SBALATON Zoltan      */
647709dbf1SBALATON Zoltan 
657709dbf1SBALATON Zoltan     i2c->mdata = 0;
667709dbf1SBALATON Zoltan     i2c->lmadr = 0;
677709dbf1SBALATON Zoltan     i2c->hmadr = 0;
687709dbf1SBALATON Zoltan     i2c->cntl = 0;
697709dbf1SBALATON Zoltan     i2c->mdcntl = 0;
707709dbf1SBALATON Zoltan     i2c->sts = 0;
717709dbf1SBALATON Zoltan     i2c->extsts = 0x8f;
727709dbf1SBALATON Zoltan     i2c->lsadr = 0;
737709dbf1SBALATON Zoltan     i2c->hsadr = 0;
747709dbf1SBALATON Zoltan     i2c->clkdiv = 0;
757709dbf1SBALATON Zoltan     i2c->intrmsk = 0;
767709dbf1SBALATON Zoltan     i2c->xfrcnt = 0;
777709dbf1SBALATON Zoltan     i2c->xtcntlss = 0;
7842a907e8SBALATON Zoltan     i2c->directcntl = 0xf;
797709dbf1SBALATON Zoltan }
807709dbf1SBALATON Zoltan 
817709dbf1SBALATON Zoltan static inline bool ppc4xx_i2c_is_master(PPC4xxI2CState *i2c)
827709dbf1SBALATON Zoltan {
837709dbf1SBALATON Zoltan     return true;
847709dbf1SBALATON Zoltan }
8565ca801bSBALATON Zoltan 
863b09bb0fSBALATON Zoltan static uint64_t ppc4xx_i2c_readb(void *opaque, hwaddr addr, unsigned int size)
8765ca801bSBALATON Zoltan {
883b09bb0fSBALATON Zoltan     PPC4xxI2CState *i2c = PPC4xx_I2C(opaque);
893b09bb0fSBALATON Zoltan     uint64_t ret;
9065ca801bSBALATON Zoltan 
9165ca801bSBALATON Zoltan     switch (addr) {
9242a907e8SBALATON Zoltan     case 0:
9365ca801bSBALATON Zoltan         ret = i2c->mdata;
947709dbf1SBALATON Zoltan         if (ppc4xx_i2c_is_master(i2c)) {
957709dbf1SBALATON Zoltan             ret = 0xff;
967709dbf1SBALATON Zoltan 
977709dbf1SBALATON Zoltan             if (!(i2c->sts & IIC_STS_MDBS)) {
987709dbf1SBALATON Zoltan                 qemu_log_mask(LOG_GUEST_ERROR, "[%s]%s: Trying to read "
997709dbf1SBALATON Zoltan                               "without starting transfer\n",
1007709dbf1SBALATON Zoltan                               TYPE_PPC4xx_I2C, __func__);
1017709dbf1SBALATON Zoltan             } else {
1027709dbf1SBALATON Zoltan                 int pending = (i2c->cntl >> 4) & 3;
1037709dbf1SBALATON Zoltan 
1047709dbf1SBALATON Zoltan                 /* get the next byte */
1057709dbf1SBALATON Zoltan                 int byte = i2c_recv(i2c->bus);
1067709dbf1SBALATON Zoltan 
1077709dbf1SBALATON Zoltan                 if (byte < 0) {
1087709dbf1SBALATON Zoltan                     qemu_log_mask(LOG_GUEST_ERROR, "[%s]%s: read failed "
1097709dbf1SBALATON Zoltan                                   "for device 0x%02x\n", TYPE_PPC4xx_I2C,
1107709dbf1SBALATON Zoltan                                   __func__, i2c->lmadr);
1117709dbf1SBALATON Zoltan                     ret = 0xff;
1127709dbf1SBALATON Zoltan                 } else {
1137709dbf1SBALATON Zoltan                     ret = byte;
1147709dbf1SBALATON Zoltan                     /* Raise interrupt if enabled */
1157709dbf1SBALATON Zoltan                     /*ppc4xx_i2c_raise_interrupt(i2c)*/;
1167709dbf1SBALATON Zoltan                 }
1177709dbf1SBALATON Zoltan 
1187709dbf1SBALATON Zoltan                 if (!pending) {
1197709dbf1SBALATON Zoltan                     i2c->sts &= ~IIC_STS_MDBS;
1207709dbf1SBALATON Zoltan                     /*i2c_end_transfer(i2c->bus);*/
1217709dbf1SBALATON Zoltan                 /*} else if (i2c->cntl & (IIC_CNTL_RPST | IIC_CNTL_CHT)) {*/
1227709dbf1SBALATON Zoltan                 } else if (pending) {
1237709dbf1SBALATON Zoltan                     /* current smbus implementation doesn't like
1247709dbf1SBALATON Zoltan                        multibyte xfer repeated start */
1257709dbf1SBALATON Zoltan                     i2c_end_transfer(i2c->bus);
1267709dbf1SBALATON Zoltan                     if (i2c_start_transfer(i2c->bus, i2c->lmadr >> 1, 1)) {
1277709dbf1SBALATON Zoltan                         /* if non zero is returned, the adress is not valid */
1287709dbf1SBALATON Zoltan                         i2c->sts &= ~IIC_STS_PT;
1297709dbf1SBALATON Zoltan                         i2c->sts |= IIC_STS_ERR;
1307709dbf1SBALATON Zoltan                         i2c->extsts |= IIC_EXTSTS_XFRA;
1317709dbf1SBALATON Zoltan                     } else {
1327709dbf1SBALATON Zoltan                         /*i2c->sts |= IIC_STS_PT;*/
1337709dbf1SBALATON Zoltan                         i2c->sts |= IIC_STS_MDBS;
1347709dbf1SBALATON Zoltan                         i2c->sts &= ~IIC_STS_ERR;
1357709dbf1SBALATON Zoltan                         i2c->extsts = 0;
1367709dbf1SBALATON Zoltan                     }
1377709dbf1SBALATON Zoltan                 }
1387709dbf1SBALATON Zoltan                 pending--;
1397709dbf1SBALATON Zoltan                 i2c->cntl = (i2c->cntl & 0xcf) | (pending << 4);
1407709dbf1SBALATON Zoltan             }
1417709dbf1SBALATON Zoltan         } else {
1427709dbf1SBALATON Zoltan             qemu_log_mask(LOG_UNIMP, "[%s]%s: slave mode not implemented\n",
1437709dbf1SBALATON Zoltan                           TYPE_PPC4xx_I2C, __func__);
1447709dbf1SBALATON Zoltan         }
14565ca801bSBALATON Zoltan         break;
14642a907e8SBALATON Zoltan     case 4:
14765ca801bSBALATON Zoltan         ret = i2c->lmadr;
14865ca801bSBALATON Zoltan         break;
14942a907e8SBALATON Zoltan     case 5:
15065ca801bSBALATON Zoltan         ret = i2c->hmadr;
15165ca801bSBALATON Zoltan         break;
15242a907e8SBALATON Zoltan     case 6:
15365ca801bSBALATON Zoltan         ret = i2c->cntl;
15465ca801bSBALATON Zoltan         break;
15542a907e8SBALATON Zoltan     case 7:
15665ca801bSBALATON Zoltan         ret = i2c->mdcntl;
15765ca801bSBALATON Zoltan         break;
15842a907e8SBALATON Zoltan     case 8:
15965ca801bSBALATON Zoltan         ret = i2c->sts;
16065ca801bSBALATON Zoltan         break;
16142a907e8SBALATON Zoltan     case 9:
16265ca801bSBALATON Zoltan         ret = i2c->extsts;
16365ca801bSBALATON Zoltan         break;
16442a907e8SBALATON Zoltan     case 10:
16565ca801bSBALATON Zoltan         ret = i2c->lsadr;
16665ca801bSBALATON Zoltan         break;
16742a907e8SBALATON Zoltan     case 11:
16865ca801bSBALATON Zoltan         ret = i2c->hsadr;
16965ca801bSBALATON Zoltan         break;
17042a907e8SBALATON Zoltan     case 12:
17165ca801bSBALATON Zoltan         ret = i2c->clkdiv;
17265ca801bSBALATON Zoltan         break;
17342a907e8SBALATON Zoltan     case 13:
17465ca801bSBALATON Zoltan         ret = i2c->intrmsk;
17565ca801bSBALATON Zoltan         break;
17642a907e8SBALATON Zoltan     case 14:
17765ca801bSBALATON Zoltan         ret = i2c->xfrcnt;
17865ca801bSBALATON Zoltan         break;
17942a907e8SBALATON Zoltan     case 15:
18065ca801bSBALATON Zoltan         ret = i2c->xtcntlss;
18165ca801bSBALATON Zoltan         break;
18242a907e8SBALATON Zoltan     case 16:
18365ca801bSBALATON Zoltan         ret = i2c->directcntl;
18465ca801bSBALATON Zoltan         break;
18565ca801bSBALATON Zoltan     default:
18642a907e8SBALATON Zoltan         if (addr < PPC4xx_I2C_MEM_SIZE) {
18742a907e8SBALATON Zoltan             qemu_log_mask(LOG_UNIMP, "%s: Unimplemented register 0x%"
18842a907e8SBALATON Zoltan                           HWADDR_PRIx "\n", __func__, addr);
18942a907e8SBALATON Zoltan         } else {
19042a907e8SBALATON Zoltan             qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad address 0x%"
19142a907e8SBALATON Zoltan                           HWADDR_PRIx "\n", __func__, addr);
19242a907e8SBALATON Zoltan         }
1937709dbf1SBALATON Zoltan         ret = 0;
19465ca801bSBALATON Zoltan         break;
19565ca801bSBALATON Zoltan     }
19665ca801bSBALATON Zoltan     return ret;
19765ca801bSBALATON Zoltan }
19865ca801bSBALATON Zoltan 
1993b09bb0fSBALATON Zoltan static void ppc4xx_i2c_writeb(void *opaque, hwaddr addr, uint64_t value,
2003b09bb0fSBALATON Zoltan                               unsigned int size)
20165ca801bSBALATON Zoltan {
2023b09bb0fSBALATON Zoltan     PPC4xxI2CState *i2c = opaque;
2037709dbf1SBALATON Zoltan 
20465ca801bSBALATON Zoltan     switch (addr) {
20542a907e8SBALATON Zoltan     case 0:
20665ca801bSBALATON Zoltan         i2c->mdata = value;
2077709dbf1SBALATON Zoltan         if (!i2c_bus_busy(i2c->bus)) {
2087709dbf1SBALATON Zoltan             /* assume we start a write transfer */
2097709dbf1SBALATON Zoltan             if (i2c_start_transfer(i2c->bus, i2c->lmadr >> 1, 0)) {
2107709dbf1SBALATON Zoltan                 /* if non zero is returned, the adress is not valid */
2117709dbf1SBALATON Zoltan                 i2c->sts &= ~IIC_STS_PT;
2127709dbf1SBALATON Zoltan                 i2c->sts |= IIC_STS_ERR;
2137709dbf1SBALATON Zoltan                 i2c->extsts |= IIC_EXTSTS_XFRA;
2147709dbf1SBALATON Zoltan             } else {
2157709dbf1SBALATON Zoltan                 i2c->sts |= IIC_STS_PT;
2167709dbf1SBALATON Zoltan                 i2c->sts &= ~IIC_STS_ERR;
2177709dbf1SBALATON Zoltan                 i2c->extsts = 0;
2187709dbf1SBALATON Zoltan             }
2197709dbf1SBALATON Zoltan         }
2207709dbf1SBALATON Zoltan         if (i2c_bus_busy(i2c->bus)) {
2217709dbf1SBALATON Zoltan             if (i2c_send(i2c->bus, i2c->mdata)) {
2227709dbf1SBALATON Zoltan                 /* if the target return non zero then end the transfer */
2237709dbf1SBALATON Zoltan                 i2c->sts &= ~IIC_STS_PT;
2247709dbf1SBALATON Zoltan                 i2c->sts |= IIC_STS_ERR;
2257709dbf1SBALATON Zoltan                 i2c->extsts |= IIC_EXTSTS_XFRA;
2267709dbf1SBALATON Zoltan                 i2c_end_transfer(i2c->bus);
2277709dbf1SBALATON Zoltan             }
2287709dbf1SBALATON Zoltan         }
22965ca801bSBALATON Zoltan         break;
23042a907e8SBALATON Zoltan     case 4:
23165ca801bSBALATON Zoltan         i2c->lmadr = value;
2327709dbf1SBALATON Zoltan         if (i2c_bus_busy(i2c->bus)) {
2337709dbf1SBALATON Zoltan             i2c_end_transfer(i2c->bus);
2347709dbf1SBALATON Zoltan         }
23565ca801bSBALATON Zoltan         break;
23642a907e8SBALATON Zoltan     case 5:
23765ca801bSBALATON Zoltan         i2c->hmadr = value;
23865ca801bSBALATON Zoltan         break;
23942a907e8SBALATON Zoltan     case 6:
24065ca801bSBALATON Zoltan         i2c->cntl = value;
2417709dbf1SBALATON Zoltan         if (i2c->cntl & IIC_CNTL_PT) {
2427709dbf1SBALATON Zoltan             if (i2c->cntl & IIC_CNTL_READ) {
2437709dbf1SBALATON Zoltan                 if (i2c_bus_busy(i2c->bus)) {
2447709dbf1SBALATON Zoltan                     /* end previous transfer */
2457709dbf1SBALATON Zoltan                     i2c->sts &= ~IIC_STS_PT;
2467709dbf1SBALATON Zoltan                     i2c_end_transfer(i2c->bus);
2477709dbf1SBALATON Zoltan                 }
2487709dbf1SBALATON Zoltan                 if (i2c_start_transfer(i2c->bus, i2c->lmadr >> 1, 1)) {
2497709dbf1SBALATON Zoltan                     /* if non zero is returned, the adress is not valid */
2507709dbf1SBALATON Zoltan                     i2c->sts &= ~IIC_STS_PT;
2517709dbf1SBALATON Zoltan                     i2c->sts |= IIC_STS_ERR;
2527709dbf1SBALATON Zoltan                     i2c->extsts |= IIC_EXTSTS_XFRA;
2537709dbf1SBALATON Zoltan                 } else {
2547709dbf1SBALATON Zoltan                     /*i2c->sts |= IIC_STS_PT;*/
2557709dbf1SBALATON Zoltan                     i2c->sts |= IIC_STS_MDBS;
2567709dbf1SBALATON Zoltan                     i2c->sts &= ~IIC_STS_ERR;
2577709dbf1SBALATON Zoltan                     i2c->extsts = 0;
2587709dbf1SBALATON Zoltan                 }
2597709dbf1SBALATON Zoltan             } else {
2607709dbf1SBALATON Zoltan                 /* we actually already did the write transfer... */
2617709dbf1SBALATON Zoltan                 i2c->sts &= ~IIC_STS_PT;
2627709dbf1SBALATON Zoltan             }
2637709dbf1SBALATON Zoltan         }
26465ca801bSBALATON Zoltan         break;
26542a907e8SBALATON Zoltan     case 7:
26642a907e8SBALATON Zoltan         i2c->mdcntl = value & 0xdf;
26765ca801bSBALATON Zoltan         break;
26842a907e8SBALATON Zoltan     case 8:
26942a907e8SBALATON Zoltan         i2c->sts &= ~(value & 0xa);
27065ca801bSBALATON Zoltan         break;
27142a907e8SBALATON Zoltan     case 9:
27242a907e8SBALATON Zoltan         i2c->extsts &= ~(value & 0x8f);
27365ca801bSBALATON Zoltan         break;
27442a907e8SBALATON Zoltan     case 10:
27565ca801bSBALATON Zoltan         i2c->lsadr = value;
27665ca801bSBALATON Zoltan         break;
27742a907e8SBALATON Zoltan     case 11:
27865ca801bSBALATON Zoltan         i2c->hsadr = value;
27965ca801bSBALATON Zoltan         break;
28042a907e8SBALATON Zoltan     case 12:
28165ca801bSBALATON Zoltan         i2c->clkdiv = value;
28265ca801bSBALATON Zoltan         break;
28342a907e8SBALATON Zoltan     case 13:
28465ca801bSBALATON Zoltan         i2c->intrmsk = value;
28565ca801bSBALATON Zoltan         break;
28642a907e8SBALATON Zoltan     case 14:
28765ca801bSBALATON Zoltan         i2c->xfrcnt = value & 0x77;
28865ca801bSBALATON Zoltan         break;
28942a907e8SBALATON Zoltan     case 15:
2907709dbf1SBALATON Zoltan         if (value & IIC_XTCNTLSS_SRST) {
2917709dbf1SBALATON Zoltan             /* Is it actually a full reset? U-Boot sets some regs before */
2927709dbf1SBALATON Zoltan             ppc4xx_i2c_reset(DEVICE(i2c));
2937709dbf1SBALATON Zoltan             break;
2947709dbf1SBALATON Zoltan         }
29565ca801bSBALATON Zoltan         i2c->xtcntlss = value;
29665ca801bSBALATON Zoltan         break;
29742a907e8SBALATON Zoltan     case 16:
298*ef9173a5SBALATON Zoltan         i2c->directcntl = value & (IIC_DIRECTCNTL_SDAC & IIC_DIRECTCNTL_SCLC);
299*ef9173a5SBALATON Zoltan         i2c->directcntl |= (value & IIC_DIRECTCNTL_SCLC ? 1 : 0);
300*ef9173a5SBALATON Zoltan         bitbang_i2c_set(i2c->bitbang, BITBANG_I2C_SCL,
301*ef9173a5SBALATON Zoltan                         i2c->directcntl & IIC_DIRECTCNTL_MSCL);
302*ef9173a5SBALATON Zoltan         i2c->directcntl |= bitbang_i2c_set(i2c->bitbang, BITBANG_I2C_SDA,
303*ef9173a5SBALATON Zoltan                                (value & IIC_DIRECTCNTL_SDAC) != 0) << 1;
30465ca801bSBALATON Zoltan         break;
3057709dbf1SBALATON Zoltan     default:
30642a907e8SBALATON Zoltan         if (addr < PPC4xx_I2C_MEM_SIZE) {
30742a907e8SBALATON Zoltan             qemu_log_mask(LOG_UNIMP, "%s: Unimplemented register 0x%"
30842a907e8SBALATON Zoltan                           HWADDR_PRIx "\n", __func__, addr);
30942a907e8SBALATON Zoltan         } else {
31042a907e8SBALATON Zoltan             qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad address 0x%"
31142a907e8SBALATON Zoltan                           HWADDR_PRIx "\n", __func__, addr);
31242a907e8SBALATON Zoltan         }
3137709dbf1SBALATON Zoltan         break;
31465ca801bSBALATON Zoltan     }
31565ca801bSBALATON Zoltan }
31665ca801bSBALATON Zoltan 
3173b09bb0fSBALATON Zoltan static const MemoryRegionOps ppc4xx_i2c_ops = {
3183b09bb0fSBALATON Zoltan     .read = ppc4xx_i2c_readb,
3193b09bb0fSBALATON Zoltan     .write = ppc4xx_i2c_writeb,
3203b09bb0fSBALATON Zoltan     .valid.min_access_size = 1,
3213b09bb0fSBALATON Zoltan     .valid.max_access_size = 4,
3223b09bb0fSBALATON Zoltan     .impl.min_access_size = 1,
3233b09bb0fSBALATON Zoltan     .impl.max_access_size = 1,
32465ca801bSBALATON Zoltan     .endianness = DEVICE_NATIVE_ENDIAN,
32565ca801bSBALATON Zoltan };
32665ca801bSBALATON Zoltan 
3273b09bb0fSBALATON Zoltan static void ppc4xx_i2c_init(Object *o)
32865ca801bSBALATON Zoltan {
3293b09bb0fSBALATON Zoltan     PPC4xxI2CState *s = PPC4xx_I2C(o);
33065ca801bSBALATON Zoltan 
3313b09bb0fSBALATON Zoltan     memory_region_init_io(&s->iomem, OBJECT(s), &ppc4xx_i2c_ops, s,
3323b09bb0fSBALATON Zoltan                           TYPE_PPC4xx_I2C, PPC4xx_I2C_MEM_SIZE);
3333b09bb0fSBALATON Zoltan     sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->iomem);
3343b09bb0fSBALATON Zoltan     sysbus_init_irq(SYS_BUS_DEVICE(s), &s->irq);
3353b09bb0fSBALATON Zoltan     s->bus = i2c_init_bus(DEVICE(s), "i2c");
336*ef9173a5SBALATON Zoltan     s->bitbang = bitbang_i2c_init(s->bus);
33765ca801bSBALATON Zoltan }
3383b09bb0fSBALATON Zoltan 
3393b09bb0fSBALATON Zoltan static void ppc4xx_i2c_class_init(ObjectClass *klass, void *data)
3403b09bb0fSBALATON Zoltan {
3413b09bb0fSBALATON Zoltan     DeviceClass *dc = DEVICE_CLASS(klass);
3423b09bb0fSBALATON Zoltan 
3433b09bb0fSBALATON Zoltan     dc->reset = ppc4xx_i2c_reset;
3443b09bb0fSBALATON Zoltan }
3453b09bb0fSBALATON Zoltan 
3463b09bb0fSBALATON Zoltan static const TypeInfo ppc4xx_i2c_type_info = {
3473b09bb0fSBALATON Zoltan     .name = TYPE_PPC4xx_I2C,
3483b09bb0fSBALATON Zoltan     .parent = TYPE_SYS_BUS_DEVICE,
3493b09bb0fSBALATON Zoltan     .instance_size = sizeof(PPC4xxI2CState),
3503b09bb0fSBALATON Zoltan     .instance_init = ppc4xx_i2c_init,
3513b09bb0fSBALATON Zoltan     .class_init = ppc4xx_i2c_class_init,
3523b09bb0fSBALATON Zoltan };
3533b09bb0fSBALATON Zoltan 
3543b09bb0fSBALATON Zoltan static void ppc4xx_i2c_register_types(void)
3553b09bb0fSBALATON Zoltan {
3563b09bb0fSBALATON Zoltan     type_register_static(&ppc4xx_i2c_type_info);
3573b09bb0fSBALATON Zoltan }
3583b09bb0fSBALATON Zoltan 
3593b09bb0fSBALATON Zoltan type_init(ppc4xx_i2c_register_types)
360