From patchwork Wed Feb 20 05:29:54 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Crosthwaite X-Patchwork-Id: 221948 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 F295D2C0082 for ; Wed, 20 Feb 2013 16:30:37 +1100 (EST) Received: from localhost ([::1]:49447 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U82GJ-0004K0-PH for incoming@patchwork.ozlabs.org; Wed, 20 Feb 2013 00:30:35 -0500 Received: from eggs.gnu.org ([208.118.235.92]:35324) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U82G6-0004JR-C9 for qemu-devel@nongnu.org; Wed, 20 Feb 2013 00:30:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U82G4-0004Gq-VT for qemu-devel@nongnu.org; Wed, 20 Feb 2013 00:30:22 -0500 Received: from mail-pb0-f51.google.com ([209.85.160.51]:47119) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U82G4-0004Gi-QS for qemu-devel@nongnu.org; Wed, 20 Feb 2013 00:30:20 -0500 Received: by mail-pb0-f51.google.com with SMTP id un15so2682479pbc.10 for ; Tue, 19 Feb 2013 21:30:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:in-reply-to:references:x-gm-message-state; bh=vD/JvlJVde+CW5fMaF7UMr1SwPjVSjzaB7J7x1vYU5M=; b=RasSIY/k4glYZeuIV+rWkk2yJlVzPR76HJgtVRwrFqZeKwP83zMvAbGjOR3jQBVDz4 TiaPdamZNDhhYlIufyhCQCZyLXTG+BtZu9uuXQsbVXyFJK+AjN3PqbhJLqdJ+zFpdmWY ZaHBNalt8hkb2BwKmLalXh/wsFbJSZ9DT4TzSqTFIZjXWK+12Qk2hiRSchJELwsHukyE Y16Ih1xKtU9cCqbr9TDi/LNF1F9MjZ0xb2+mgEpW242IBiL2L9xwksU3xaoBvZ1KbknU 19Z5QkMXpLxAeHg7gYREr8GdBiPm4ULj4uMPypQb16NAykXW60s5BiwzGdljKl8eNtIx Rv9Q== X-Received: by 10.66.158.201 with SMTP id ww9mr567176pab.102.1361338219937; Tue, 19 Feb 2013 21:30:19 -0800 (PST) Received: from localhost ([1.128.17.184]) by mx.google.com with ESMTPS id kl4sm6184756pbc.31.2013.02.19.21.30.16 (version=TLSv1.1 cipher=RC4-SHA bits=128/128); Tue, 19 Feb 2013 21:30:19 -0800 (PST) From: Peter Crosthwaite To: qemu-devel@nongnu.org Date: Wed, 20 Feb 2013 15:29:54 +1000 Message-Id: <29889099adf9f3347cd43b8c95f1201de5fa8e71.1361337686.git.peter.crosthwaite@xilinx.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: References: In-Reply-To: References: X-Gm-Message-State: ALoCoQkvX/eIeNxSa1a4fZCMIjpR2Hoiyt7/BxVz/tnOTyKEMatEVpaZDgvGkKA8956JCQdEGB8t X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.160.51 Cc: edgar.iglesias@gmail.com, Peter Crosthwaite , peter.maydell@linaro.org Subject: [Qemu-devel] [PATCH v1 1/6] i2c: support address ranges 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 Some I2C devices (eg m24c08) can decode a linear range of addresses (e.g. 0b10100xx). Add the address_range field to I2C slave that specifies the number of consecutive addresses the device decodes. Signed-off-by: Peter Crosthwaite --- hw/i2c.c | 14 ++++++++++---- hw/i2c.h | 6 ++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/hw/i2c.c b/hw/i2c.c index ec314a4..a9004e6 100644 --- a/hw/i2c.c +++ b/hw/i2c.c @@ -19,6 +19,7 @@ struct i2c_bus static Property i2c_props[] = { DEFINE_PROP_UINT8("address", struct I2CSlave, address, 0), + DEFINE_PROP_UINT8("address-range", struct I2CSlave, address_range, 1), DEFINE_PROP_END_OF_LIST(), }; @@ -93,7 +94,8 @@ int i2c_start_transfer(i2c_bus *bus, uint8_t address, int recv) QTAILQ_FOREACH(kid, &bus->qbus.children, sibling) { DeviceState *qdev = kid->child; I2CSlave *candidate = I2C_SLAVE(qdev); - if (candidate->address == address) { + if (address >= candidate->address && + address < candidate->address + candidate->address_range) { slave = candidate; break; } @@ -110,6 +112,9 @@ int i2c_start_transfer(i2c_bus *bus, uint8_t address, int recv) if (sc->event) { sc->event(slave, recv ? I2C_START_RECV : I2C_START_SEND); } + if (sc->decode_address) { + sc->decode_address(slave, address); + } return 0; } @@ -192,12 +197,13 @@ static int i2c_slave_post_load(void *opaque, int version_id) const VMStateDescription vmstate_i2c_slave = { .name = "I2CSlave", - .version_id = 1, - .minimum_version_id = 1, - .minimum_version_id_old = 1, + .version_id = 2, + .minimum_version_id = 2, + .minimum_version_id_old = 2, .post_load = i2c_slave_post_load, .fields = (VMStateField []) { VMSTATE_UINT8(address, I2CSlave), + VMSTATE_UINT8(address_range, I2CSlave), VMSTATE_END_OF_LIST() } }; diff --git a/hw/i2c.h b/hw/i2c.h index 0e80d5a..0021125 100644 --- a/hw/i2c.h +++ b/hw/i2c.h @@ -40,6 +40,11 @@ typedef struct I2CSlaveClass /* Notify the slave of a bus state change. */ void (*event)(I2CSlave *s, enum i2c_event event); + + /* Notify the slave what address was decoded. Only needed for slaves that + * decode multiple addresses. Called after event() for I2C_START_RECV/SEND + */ + void (*decode_address)(I2CSlave *s, uint8_t address); } I2CSlaveClass; struct I2CSlave @@ -48,6 +53,7 @@ struct I2CSlave /* Remaining fields for internal use by the I2C code. */ uint8_t address; + uint8_t address_range; }; i2c_bus *i2c_init_bus(DeviceState *parent, const char *name);