From patchwork Tue Apr 3 20:29:55 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oskar Andero X-Patchwork-Id: 150545 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6BE02B6FE8 for ; Wed, 4 Apr 2012 06:56:54 +1000 (EST) Received: from localhost ([::1]:36326 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SFAma-0004om-De for incoming@patchwork.ozlabs.org; Tue, 03 Apr 2012 16:56:52 -0400 Received: from eggs.gnu.org ([208.118.235.92]:49250) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SFAPT-0003OF-7O for qemu-devel@nongnu.org; Tue, 03 Apr 2012 16:33:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SFAPR-0000d0-BM for qemu-devel@nongnu.org; Tue, 03 Apr 2012 16:32:58 -0400 Received: from mail-bk0-f45.google.com ([209.85.214.45]:57457) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SFAPR-0000ce-1u for qemu-devel@nongnu.org; Tue, 03 Apr 2012 16:32:57 -0400 Received: by bkcjg9 with SMTP id jg9so154305bkc.4 for ; Tue, 03 Apr 2012 13:32:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer; bh=FIPTYqJZ6zNlOTrZCVN67LUKJCIcoSt4JEs87XasWoc=; b=p/V6yZ2XPvNo7V52otOEAK8L+JPdUCpLu+bDdNnixAjqJ0xgaziK2OlFurQGw1qs00 b5DMgN/C1raXxtmKiUN0lZXU5wxK/DU3gyYUg0NE0xPCexdStbE5TeSyT6t/3Rpk6KQb WXrHN5QhPJXl0c8Uh9cWiVlemxkuG6S/6pNqLdfREQHwGMhrUrWp1MgEgLOplHkj7IFg 0kUhp6hUuYB7HQmzaUc45IvBatC0+RSsDfCEGAUgmn0fOyvZfVIU0DVyQzPqv7REAshC 35h3NC7gw67Kq1EjxlDsqjgeGpesRuVgnkb6WrspYg9Tk6+V1SRlBMCGDiSmT1kG47Ym mnWQ== Received: by 10.204.129.21 with SMTP id m21mr6213318bks.124.1333485174070; Tue, 03 Apr 2012 13:32:54 -0700 (PDT) Received: from localhost.localdomain (h107n5-m-fb-gr100.ias.bredband.telia.com. [81.236.172.107]) by mx.google.com with ESMTPS id t17sm48347359bke.6.2012.04.03.13.32.52 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 03 Apr 2012 13:32:53 -0700 (PDT) From: Oskar Andero To: qemu-devel@nongnu.org Date: Tue, 3 Apr 2012 22:29:55 +0200 Message-Id: <1333484995-9101-1-git-send-email-oskar.andero@gmail.com> X-Mailer: git-send-email 1.7.3.4 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.214.45 X-Mailman-Approved-At: Tue, 03 Apr 2012 16:56:47 -0400 Cc: peter.maydell@linaro.org, Oskar Andero , afaerber@suse.de, paul@codesourcery.com Subject: [Qemu-devel] [PATCH v2] versatilepb: add i2c support X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Oskar Andero --- hw/versatilepb.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 80 insertions(+), 0 deletions(-) diff --git a/hw/versatilepb.c b/hw/versatilepb.c index 25afb1e..d4fe168 100644 --- a/hw/versatilepb.c +++ b/hw/versatilepb.c @@ -16,9 +16,18 @@ #include "boards.h" #include "blockdev.h" #include "exec-memory.h" +#include "bitbang_i2c.h" /* Primary interrupt controller. */ +typedef struct { + SysBusDevice busdev; + MemoryRegion iomem; + bitbang_i2c_interface *bitbang; + int out; + int in; +} VPBI2CState; + typedef struct vpb_sic_state { SysBusDevice busdev; @@ -153,6 +162,64 @@ static int vpb_sic_init(SysBusDevice *dev) return 0; } +static uint64_t vpb_i2c_read(void *opaque, target_phys_addr_t offset, + unsigned size) +{ + VPBI2CState *s = (VPBI2CState *)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 vpb_i2c_write(void *opaque, target_phys_addr_t offset, + uint64_t value, unsigned size) +{ + VPBI2CState *s = (VPBI2CState *)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 vpb_i2c_ops = { + .read = vpb_i2c_read, + .write = vpb_i2c_write, + .endianness = DEVICE_NATIVE_ENDIAN, +}; + +static int vpb_i2c_init(SysBusDevice *dev) +{ + VPBI2CState *s = FROM_SYSBUS(VPBI2CState, dev); + i2c_bus *bus; + + bus = i2c_init_bus(&dev->qdev, "i2c"); + s->bitbang = bitbang_i2c_init(bus); + memory_region_init_io(&s->iomem, &vpb_i2c_ops, s, + "vpb-i2c", 0x1000); + sysbus_init_mmio(dev, &s->iomem); + return 0; +} + +static void vpb_i2c_class_init(ObjectClass *klass, void *data) +{ + SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); + + k->init = vpb_i2c_init; +} + /* Board init. */ /* The AB and PB boards both use the same core, just with different @@ -177,6 +244,7 @@ static void versatile_init(ram_addr_t ram_size, SysBusDevice *busdev; DeviceState *pl041; PCIBus *pci_bus; + i2c_bus *i2c; NICInfo *nd; int n; int done_smc = 0; @@ -268,6 +336,10 @@ static void versatile_init(ram_addr_t ram_size, /* Add PL031 Real Time Clock. */ sysbus_create_simple("pl031", 0x101e8000, pic[10]); + dev = sysbus_create_simple("vpb_i2c", 0x10002000, NULL); + i2c = (i2c_bus *)qdev_get_child_bus(dev, "i2c"); + i2c_create_slave(i2c, "ds1338", 0x68); + /* Add PL041 AACI Interface to the LM4549 codec */ pl041 = qdev_create(NULL, "pl041"); qdev_prop_set_uint32(pl041, "nc_fifo_depth", 512); @@ -380,9 +452,17 @@ static TypeInfo vpb_sic_info = { .class_init = vpb_sic_class_init, }; +static const TypeInfo vpb_i2c_info = { + .name = "vpb_i2c", + .parent = TYPE_SYS_BUS_DEVICE, + .instance_size = sizeof(VPBI2CState), + .class_init = vpb_i2c_class_init, +}; + static void versatilepb_register_types(void) { type_register_static(&vpb_sic_info); + type_register_static(&vpb_i2c_info); } type_init(versatilepb_register_types)