2 * PPC4xx I2C controller emulation
4 * Copyright (c) 2007 Jocelyn Mayer
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 #include "qemu/osdep.h"
26 #include "qapi/error.h"
27 #include "qemu-common.h"
30 #include "hw/i2c/ppc4xx_i2c.h"
34 #define PPC4xx_I2C_MEM_SIZE 0x11
36 static uint64_t ppc4xx_i2c_readb(void *opaque
, hwaddr addr
, unsigned int size
)
38 PPC4xxI2CState
*i2c
= PPC4xx_I2C(opaque
);
42 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
46 /*i2c_readbyte(&i2c->mdata);*/
89 ret
= i2c
->directcntl
;
96 printf("%s: addr " TARGET_FMT_plx
" %02" PRIx64
"\n", __func__
, addr
, ret
);
102 static void ppc4xx_i2c_writeb(void *opaque
, hwaddr addr
, uint64_t value
,
105 PPC4xxI2CState
*i2c
= opaque
;
107 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx64
"\n",
108 __func__
, addr
, value
);
113 /*i2c_sendbyte(&i2c->mdata);*/
128 i2c
->mdcntl
= value
& 0xDF;
131 i2c
->sts
&= ~(value
& 0x0A);
134 i2c
->extsts
&= ~(value
& 0x8F);
146 i2c
->intrmsk
= value
;
149 i2c
->xfrcnt
= value
& 0x77;
152 i2c
->xtcntlss
= value
;
155 i2c
->directcntl
= value
& 0x7;
160 static const MemoryRegionOps ppc4xx_i2c_ops
= {
161 .read
= ppc4xx_i2c_readb
,
162 .write
= ppc4xx_i2c_writeb
,
163 .valid
.min_access_size
= 1,
164 .valid
.max_access_size
= 4,
165 .impl
.min_access_size
= 1,
166 .impl
.max_access_size
= 1,
167 .endianness
= DEVICE_NATIVE_ENDIAN
,
170 static void ppc4xx_i2c_reset(DeviceState
*s
)
172 PPC4xxI2CState
*i2c
= PPC4xx_I2C(s
);
182 i2c
->directcntl
= 0x0F;
185 static void ppc4xx_i2c_init(Object
*o
)
187 PPC4xxI2CState
*s
= PPC4xx_I2C(o
);
189 memory_region_init_io(&s
->iomem
, OBJECT(s
), &ppc4xx_i2c_ops
, s
,
190 TYPE_PPC4xx_I2C
, PPC4xx_I2C_MEM_SIZE
);
191 sysbus_init_mmio(SYS_BUS_DEVICE(s
), &s
->iomem
);
192 sysbus_init_irq(SYS_BUS_DEVICE(s
), &s
->irq
);
193 s
->bus
= i2c_init_bus(DEVICE(s
), "i2c");
196 static void ppc4xx_i2c_class_init(ObjectClass
*klass
, void *data
)
198 DeviceClass
*dc
= DEVICE_CLASS(klass
);
200 dc
->reset
= ppc4xx_i2c_reset
;
203 static const TypeInfo ppc4xx_i2c_type_info
= {
204 .name
= TYPE_PPC4xx_I2C
,
205 .parent
= TYPE_SYS_BUS_DEVICE
,
206 .instance_size
= sizeof(PPC4xxI2CState
),
207 .instance_init
= ppc4xx_i2c_init
,
208 .class_init
= ppc4xx_i2c_class_init
,
211 static void ppc4xx_i2c_register_types(void)
213 type_register_static(&ppc4xx_i2c_type_info
);
216 type_init(ppc4xx_i2c_register_types
)