diff --git a/Makefile.target b/Makefile.target index 84951a09ec..b6a9330b90 100644 --- a/Makefile.target +++ b/Makefile.target @@ -364,6 +364,7 @@ endif obj-arm-y = integratorcp.o versatilepb.o arm_pic.o arm_timer.o obj-arm-y += arm_boot.o pl011.o pl031.o pl050.o pl080.o pl110.o pl181.o pl190.o obj-arm-y += versatile_pci.o +obj-arm-y += versatile_i2c.o obj-arm-y += cadence_uart.o obj-arm-y += cadence_ttc.o obj-arm-y += cadence_gem.o diff --git a/hw/realview.c b/hw/realview.c index cf55204c96..ecf470179a 100644 --- a/hw/realview.c +++ b/hw/realview.c @@ -15,91 +15,13 @@ #include "net.h" #include "sysemu.h" #include "boards.h" -#include "bitbang_i2c.h" +#include "i2c.h" #include "blockdev.h" #include "exec-memory.h" #define SMP_BOOT_ADDR 0xe0000000 #define SMP_BOOTREG_ADDR 0x10000030 -typedef struct { - SysBusDevice busdev; - MemoryRegion iomem; - bitbang_i2c_interface *bitbang; - int out; - int in; -} RealViewI2CState; - -static uint64_t realview_i2c_read(void *opaque, target_phys_addr_t offset, - unsigned size) -{ - RealViewI2CState *s = (RealViewI2CState *)opaque; - - if (offset == 0) { - return (s->out & 1) | (s->in << 1); - } else { - hw_error("realview_i2c_read: Bad offset 0x%x\n", (int)offset); - return -1; - } -} - -static void realview_i2c_write(void *opaque, target_phys_addr_t offset, - uint64_t value, unsigned size) -{ - RealViewI2CState *s = (RealViewI2CState *)opaque; - - switch (offset) { - case 0: - s->out |= value & 3; - break; - case 4: - s->out &= ~value; - break; - default: - hw_error("realview_i2c_write: Bad offset 0x%x\n", (int)offset); - } - bitbang_i2c_set(s->bitbang, BITBANG_I2C_SCL, (s->out & 1) != 0); - s->in = bitbang_i2c_set(s->bitbang, BITBANG_I2C_SDA, (s->out & 2) != 0); -} - -static const MemoryRegionOps realview_i2c_ops = { - .read = realview_i2c_read, - .write = realview_i2c_write, - .endianness = DEVICE_NATIVE_ENDIAN, -}; - -static int realview_i2c_init(SysBusDevice *dev) -{ - RealViewI2CState *s = FROM_SYSBUS(RealViewI2CState, dev); - i2c_bus *bus; - - bus = i2c_init_bus(&dev->qdev, "i2c"); - s->bitbang = bitbang_i2c_init(bus); - memory_region_init_io(&s->iomem, &realview_i2c_ops, s, - "realview-i2c", 0x1000); - sysbus_init_mmio(dev, &s->iomem); - return 0; -} - -static void realview_i2c_class_init(ObjectClass *klass, void *data) -{ - SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); - - k->init = realview_i2c_init; -} - -static TypeInfo realview_i2c_info = { - .name = "realview_i2c", - .parent = TYPE_SYS_BUS_DEVICE, - .instance_size = sizeof(RealViewI2CState), - .class_init = realview_i2c_class_init, -}; - -static void realview_register_types(void) -{ - type_register_static(&realview_i2c_info); -} - /* Board init. */ static struct arm_boot_info realview_binfo = { @@ -328,7 +250,7 @@ static void realview_init(ram_addr_t ram_size, } } - dev = sysbus_create_simple("realview_i2c", 0x10002000, NULL); + dev = sysbus_create_simple("versatile_i2c", 0x10002000, NULL); i2c = (i2c_bus *)qdev_get_child_bus(dev, "i2c"); i2c_create_slave(i2c, "ds1338", 0x68); @@ -492,4 +414,3 @@ static void realview_machine_init(void) } machine_init(realview_machine_init); -type_init(realview_register_types) diff --git a/hw/versatile_i2c.c b/hw/versatile_i2c.c new file mode 100644 index 0000000000..88f530aefc --- /dev/null +++ b/hw/versatile_i2c.c @@ -0,0 +1,105 @@ +/* + * ARM Versatile I2C controller + * + * Copyright (c) 2006-2007 CodeSourcery. + * Copyright (c) 2012 Oskar Andero + * + * This file is derived from hw/realview.c by Paul Brook + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + * + */ + +#include "sysbus.h" +#include "bitbang_i2c.h" + +typedef struct { + SysBusDevice busdev; + MemoryRegion iomem; + bitbang_i2c_interface *bitbang; + int out; + int in; +} VersatileI2CState; + +static uint64_t versatile_i2c_read(void *opaque, target_phys_addr_t offset, + unsigned size) +{ + VersatileI2CState *s = (VersatileI2CState *)opaque; + + if (offset == 0) { + return (s->out & 1) | (s->in << 1); + } else { + hw_error("%s: Bad offset 0x%x\n", __func__, (int)offset); + return -1; + } +} + +static void versatile_i2c_write(void *opaque, target_phys_addr_t offset, + uint64_t value, unsigned size) +{ + VersatileI2CState *s = (VersatileI2CState *)opaque; + + switch (offset) { + case 0: + s->out |= value & 3; + break; + case 4: + s->out &= ~value; + break; + default: + hw_error("%s: Bad offset 0x%x\n", __func__, (int)offset); + } + bitbang_i2c_set(s->bitbang, BITBANG_I2C_SCL, (s->out & 1) != 0); + s->in = bitbang_i2c_set(s->bitbang, BITBANG_I2C_SDA, (s->out & 2) != 0); +} + +static const MemoryRegionOps versatile_i2c_ops = { + .read = versatile_i2c_read, + .write = versatile_i2c_write, + .endianness = DEVICE_NATIVE_ENDIAN, +}; + +static int versatile_i2c_init(SysBusDevice *dev) +{ + VersatileI2CState *s = FROM_SYSBUS(VersatileI2CState, dev); + i2c_bus *bus; + + bus = i2c_init_bus(&dev->qdev, "i2c"); + s->bitbang = bitbang_i2c_init(bus); + memory_region_init_io(&s->iomem, &versatile_i2c_ops, s, + "versatile_i2c", 0x1000); + sysbus_init_mmio(dev, &s->iomem); + return 0; +} + +static void versatile_i2c_class_init(ObjectClass *klass, void *data) +{ + SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); + + k->init = versatile_i2c_init; +} + +static const TypeInfo versatile_i2c_info = { + .name = "versatile_i2c", + .parent = TYPE_SYS_BUS_DEVICE, + .instance_size = sizeof(VersatileI2CState), + .class_init = versatile_i2c_class_init, +}; + +static void versatile_i2c_register_types(void) +{ + type_register_static(&versatile_i2c_info); +} + +type_init(versatile_i2c_register_types)