From patchwork Fri Feb 11 20:57:39 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 82832 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id EA0A0B7197 for ; Sat, 12 Feb 2011 08:04:51 +1100 (EST) Received: from localhost ([127.0.0.1]:36501 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Po0Aa-0001uf-CO for incoming@patchwork.ozlabs.org; Fri, 11 Feb 2011 16:04:48 -0500 Received: from [140.186.70.92] (port=41844 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Po04V-0007vo-Qw for qemu-devel@nongnu.org; Fri, 11 Feb 2011 15:58:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Po04T-0003Et-AL for qemu-devel@nongnu.org; Fri, 11 Feb 2011 15:58:31 -0500 Received: from mail-fx0-f45.google.com ([209.85.161.45]:47910) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Po04T-00036r-47 for qemu-devel@nongnu.org; Fri, 11 Feb 2011 15:58:29 -0500 Received: by mail-fx0-f45.google.com with SMTP id 12so3249832fxm.4 for ; Fri, 11 Feb 2011 12:58:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:subject:date:message-id:x-mailer :in-reply-to:references; bh=OBnHF9iFlwm6FnGGNjhLRv7dmQnlSPGbtQVycLAgmR4=; b=ARMDh8j3PbZ/yGgYVo7lh1leB4St9diqWterhYxWAJ7f909YwNLfMRxMsXdsbraK6s ATaWwdCNwdyUkS0nQWNgN1HqwyfbyUzcHslwPySwOG2YfmeIs1IMq1NFiYoAP53C9mbP lvrWGXtPxleCJx6yr2JoloSLvFcwvCwIryGV8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:subject:date:message-id:x-mailer:in-reply-to:references; b=bIAbtYDwmgBSoREDICclXoDivh5Lpu5Hbt8YbKCcaCNhxEl+0Ot4fPZSd7XKMnnjq9 p14XJJE/x3H+oGmBfMrWTtd3mPcfBD/IfGdwK64G1nOYtJJUMAM9IBqA0TyGwOoOJpCl Alw/xOhxYlF2qKAxpLZb/G1lbttyflRaMGjMg= Received: by 10.223.71.195 with SMTP id i3mr13104436faj.149.1297457886495; Fri, 11 Feb 2011 12:58:06 -0800 (PST) Received: from doriath.ww600.siemens.net (ppp89-110-8-230.pppoe.avangarddsl.ru [89.110.8.230]) by mx.google.com with ESMTPS id c11sm618019fav.2.2011.02.11.12.58.05 (version=SSLv3 cipher=OTHER); Fri, 11 Feb 2011 12:58:06 -0800 (PST) From: Dmitry Eremin-Solenikov To: qemu-devel@nongnu.org Date: Fri, 11 Feb 2011 23:57:39 +0300 Message-Id: <1297457859-15685-7-git-send-email-dbaryshkov@gmail.com> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <1297457859-15685-1-git-send-email-dbaryshkov@gmail.com> References: <1297457859-15685-1-git-send-email-dbaryshkov@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.161.45 Subject: [Qemu-devel] [PATCH 7/7] pxa2xx: convert i2c master to use qdev/vmsd X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Dmitry Eremin-Solenikov --- hw/pxa2xx.c | 53 ++++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 42 insertions(+), 11 deletions(-) diff --git a/hw/pxa2xx.c b/hw/pxa2xx.c index d966846..9ebbce6 100644 --- a/hw/pxa2xx.c +++ b/hw/pxa2xx.c @@ -1262,10 +1262,12 @@ typedef struct { } PXA2xxI2CSlaveState; struct PXA2xxI2CState { + SysBusDevice busdev; PXA2xxI2CSlaveState *slave; i2c_bus *bus; qemu_irq irq; - target_phys_addr_t offset; + uint32_t offset; + uint32_t region_size; uint16_t control; uint16_t status; @@ -1499,27 +1501,42 @@ static I2CSlaveInfo pxa2xx_i2c_slave_info = { PXA2xxI2CState *pxa2xx_i2c_init(target_phys_addr_t base, qemu_irq irq, uint32_t region_size) { - int iomemtype; DeviceState *dev; - PXA2xxI2CState *s = qemu_mallocz(sizeof(PXA2xxI2CState)); + SysBusDevice *i2c_dev; + PXA2xxI2CState *s; + + i2c_dev = sysbus_from_qdev(qdev_create(NULL, "pxa2xx_i2c")); + qdev_prop_set_uint32(&i2c_dev->qdev, "size", region_size + 1); + qdev_prop_set_uint32(&i2c_dev->qdev, "offset", + base - (base & (~region_size) & TARGET_PAGE_MASK)); + + qdev_init_nofail(&i2c_dev->qdev); + + sysbus_mmio_map(i2c_dev, 0, base & ~region_size); + sysbus_connect_irq(i2c_dev, 0, irq); + s = FROM_SYSBUS(PXA2xxI2CState, i2c_dev); /* FIXME: Should the slave device really be on a separate bus? */ dev = i2c_create_slave(i2c_init_bus(NULL, "dummy"), "pxa2xx-i2c-slave", 0); s->slave = FROM_I2C_SLAVE(PXA2xxI2CSlaveState, I2C_SLAVE_FROM_QDEV(dev)); s->slave->host = s; - s->irq = irq; - s->bus = i2c_init_bus(NULL, "i2c"); - s->offset = base - (base & (~region_size) & TARGET_PAGE_MASK); + return s; +} + +static int pxa2xx_i2c_initfn(SysBusDevice *dev) +{ + PXA2xxI2CState *s = FROM_SYSBUS(PXA2xxI2CState, dev); + int iomemtype; + + s->bus = i2c_init_bus(&dev->qdev, "i2c"); iomemtype = cpu_register_io_memory(pxa2xx_i2c_readfn, pxa2xx_i2c_writefn, s, DEVICE_NATIVE_ENDIAN); - cpu_register_physical_memory(base & ~region_size, - region_size + 1, iomemtype); - - vmstate_register(NULL, base, &vmstate_pxa2xx_i2c, s); + sysbus_init_mmio(dev, s->region_size, iomemtype); + sysbus_init_irq(dev, &s->irq); - return s; + return 0; } i2c_bus *pxa2xx_i2c_bus(PXA2xxI2CState *s) @@ -1527,6 +1544,19 @@ i2c_bus *pxa2xx_i2c_bus(PXA2xxI2CState *s) return s->bus; } +static SysBusDeviceInfo pxa2xx_i2c_info = { + .init = pxa2xx_i2c_initfn, + .qdev.name = "pxa2xx_i2c", + .qdev.desc = "PXA2xx I2C Bus Controller", + .qdev.size = sizeof(PXA2xxI2CState), + .qdev.vmsd = &vmstate_pxa2xx_i2c, + .qdev.props = (Property[]) { + DEFINE_PROP_UINT32("size", PXA2xxI2CState, region_size, 0x10000), + DEFINE_PROP_UINT32("offset", PXA2xxI2CState, offset, 0), + DEFINE_PROP_END_OF_LIST(), + }, +}; + /* PXA Inter-IC Sound Controller */ static void pxa2xx_i2s_reset(PXA2xxI2SState *i2s) { @@ -2287,6 +2317,7 @@ static void pxa2xx_register_devices(void) { i2c_register_slave(&pxa2xx_i2c_slave_info); sysbus_register_dev("pxa2xx-ssp", sizeof(PXA2xxSSPState), pxa2xx_ssp_init); + sysbus_register_withprop(&pxa2xx_i2c_info); } device_init(pxa2xx_register_devices)