From patchwork Wed Feb 20 13:59:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 158830 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp5080278jaa; Wed, 20 Feb 2019 07:52:41 -0800 (PST) X-Google-Smtp-Source: AHgI3IYHHMS3aJyh3MusZiC0SqtGrMWFGsnRY5bF5r65awRC7gQ6a4kHOXnzcNx/PEfQg5bXxVH3 X-Received: by 2002:a25:a0ca:: with SMTP id i10mr28971947ybm.54.1550677961777; Wed, 20 Feb 2019 07:52:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550677961; cv=none; d=google.com; s=arc-20160816; b=OHY08UmnPKDnCKJN/1ufVy0IB69MYDthbSmnU1Rs2GgvTmE03PzdBNaZxNlFQgxiGA qIjIEo99a45kk9H/Vonibx4HfZsbXTuDlAikEijTUtSxiOiBswCoP5dzjFCm+T8eUt8h +9GEpEOTiGkwBdEaFoOXXqnEYRstp9wAKBisMWh68IwRmXgy4rsSS4sKwiXBam9hjih2 1vQkeB1SZhPy2zFp3fvMiFmzA3fwTeYowcwWma8lVoGsv5+z616bjU7k6wuGHLBcA4MD ZgoH3g5MO8bnMsc9WJxQSVTdg2TinRA7WHoqd57G1rSHGj8hgwcl1LNWFwsjiUk0QHTt 2dZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=+I7WOBJKScZxxI8BQQihtBpw1M5lszgobVCD62ghJ6E=; b=HMjSmgiY0oJ3FbeOvJkwhJ5SLY9sSbf/R72jvokoPs9XbXyzvpB1uQXeaPQO0nF00S 2Ru8dx39VQ59fHahttEeKmll6qmG2uLwyCa1nsirGkGbozdk2ATisBKwbL3w4sG8HBJf UNEiY4hloeheOXNsp3Bevwgm2Dc8ySbuqqGjjAFFx+N2RV5hlFd4eEJydbuNO/Pzeasl V6lafa4pz4Z7Ncxtr4fysEvG7aJ6mWtbSMiREYlCo4bzHqySOgMB8iGNCkDeyf3t0iti tX+J5DY6GB7pbMyi16U/Q1G2iv6F423zMKT6E9gThnxlxSm3+ckKeotm8aIBfqbfQvCc +O7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=TCyCHvQo; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id f37si12400052ybj.125.2019.02.20.07.52.41 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 20 Feb 2019 07:52:41 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=TCyCHvQo; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([127.0.0.1]:41316 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwUAr-0005Wf-8S for patch@linaro.org; Wed, 20 Feb 2019 10:52:41 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43619) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwTmX-00029M-Hv for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:27:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwTmV-0000ET-Eq for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:27:33 -0500 Received: from mail-ot1-x344.google.com ([2607:f8b0:4864:20::344]:35335) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gwTmT-0008Ss-9K for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:27:31 -0500 Received: by mail-ot1-x344.google.com with SMTP id z19so40821193otm.2 for ; Wed, 20 Feb 2019 07:27:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=+I7WOBJKScZxxI8BQQihtBpw1M5lszgobVCD62ghJ6E=; b=TCyCHvQokrqqNXBMN7D+hsYN2Q9k+rvWpXK12XLpGAsLFNH3cE/7NbPrPK8nUreeLU Qzm08ptoTM2mD017ASPuAeFsud651nHSZcfB+coVO2uAKgmNQVfwHW846wJST9/GihVd awFeA0vj/7zYoPZCpgQC+OX/R9U33TpPO7Mi3Pu13TF3GXIKzoqbduaGwaKWqh10DRq+ l3EjmM/gI76etBlUbo+nDKKylLhM2oAXACUCD7PwY/A+DH92Y0wl6++DPg0AErKu+9nP famU28nLIZhHY1CtD+BwTSI5864OAp/XrAcw5eLv1hBXJaxTDKo3VWg8BauDKCn2jJNx Oc9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=+I7WOBJKScZxxI8BQQihtBpw1M5lszgobVCD62ghJ6E=; b=umHhwxGreiqwMIaL3HDn+c7tiKqwRS2HrVDqMyxajQ8wJPpx1ooERjgd3cRwZmrBJk PbRoKiefrTm1KjHcnafgHhV6YNtkYNs506QbY/CjZEqOZ49kP6EsoFSK9exLIDW+zRQ2 zx0tt5w8aR3r9IJ72ERd8NyeiA7xFZaiQ94f41ZXukhYzKCeLShhlJxewN6OOpNDbxaD Xyor1xsnYjJlhELqJ0giSOnL+Y3nJKHliCALwdWAE3r2KESkPmtCAfesMihXHg/suMeJ ALBa2PICZN0RyVwkMvx7XbXSqL1QvISc7ihMMBDWhimAQ8FN2X2QabxEz/XBZno8um8q dQPA== X-Gm-Message-State: AHQUAuZEgrI8NJ6dK+gciJqIBiMkfbBOvKFpJWhDxbZg5eRNc+HVYr4r qw92VfQgGfkemAVtdygAHGZn6PH4mQ== X-Received: by 2002:a9d:138:: with SMTP id 53mr4958447otu.169.1550671210971; Wed, 20 Feb 2019 06:00:10 -0800 (PST) Received: from serve.minyard.net ([47.184.128.64]) by smtp.gmail.com with ESMTPSA id a62sm14491230otb.72.2019.02.20.06.00.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Feb 2019 06:00:09 -0800 (PST) Received: from t430.minyard.net (unknown [IPv6:2001:470:b8f6:1b:d1f6:7172:48bb:512b]) by serve.minyard.net (Postfix) with ESMTPA id AE90A1808F2; Wed, 20 Feb 2019 14:00:08 +0000 (UTC) Received: by t430.minyard.net (Postfix, from userid 1000) id 78186302A6C; Wed, 20 Feb 2019 08:00:07 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org Date: Wed, 20 Feb 2019 07:59:42 -0600 Message-Id: <20190220135956.22589-6-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190220135956.22589-1-minyard@acm.org> References: <20190220135956.22589-1-minyard@acm.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::344 Subject: [Qemu-devel] [PATCH 05/19] i2c:smbus: Correct the working of quick commands X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Corey Minyard , Corey Minyard , "Michael S . Tsirkin" , "Dr . David Alan Gilbert" , Paolo Bonzini Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard The logic of handling quick SMBus commands was wrong. If you get a finish event with no data, that's a quick command. Document the quick command while we are at it. Signed-off-by: Corey Minyard --- hw/i2c/smbus_slave.c | 35 +++++++++++++++++++---------------- include/hw/i2c/smbus_slave.h | 5 +++++ 2 files changed, 24 insertions(+), 16 deletions(-) -- 2.17.1 diff --git a/hw/i2c/smbus_slave.c b/hw/i2c/smbus_slave.c index 6e4d542f51..6a89a286e3 100644 --- a/hw/i2c/smbus_slave.c +++ b/hw/i2c/smbus_slave.c @@ -54,9 +54,7 @@ static void smbus_do_write(SMBusDevice *dev) { SMBusDeviceClass *sc = SMBUS_DEVICE_GET_CLASS(dev); - if (dev->data_len == 0) { - smbus_do_quick_cmd(dev, 0); - } else if (dev->data_len == 1) { + if (dev->data_len == 1) { DPRINTF("Send Byte\n"); if (sc->send_byte) { sc->send_byte(dev, dev->data_buf[0]); @@ -120,19 +118,24 @@ static int smbus_i2c_event(I2CSlave *s, enum i2c_event event) break; case I2C_FINISH: - switch (dev->mode) { - case SMBUS_WRITE_DATA: - smbus_do_write(dev); - break; - case SMBUS_RECV_BYTE: - smbus_do_quick_cmd(dev, 1); - break; - case SMBUS_READ_DATA: - BADF("Unexpected stop during receive\n"); - break; - default: - /* Nothing to do. */ - break; + if (dev->data_len == 0) { + if (dev->mode == SMBUS_WRITE_DATA || dev->mode == SMBUS_READ_DATA) { + smbus_do_quick_cmd(dev, dev->mode == SMBUS_READ_DATA); + } + } else { + switch (dev->mode) { + case SMBUS_WRITE_DATA: + smbus_do_write(dev); + break; + + case SMBUS_READ_DATA: + BADF("Unexpected stop during receive\n"); + break; + + default: + /* Nothing to do. */ + break; + } } dev->mode = SMBUS_IDLE; dev->data_len = 0; diff --git a/include/hw/i2c/smbus_slave.h b/include/hw/i2c/smbus_slave.h index 46b8948f0f..5ef1c72ad0 100644 --- a/include/hw/i2c/smbus_slave.h +++ b/include/hw/i2c/smbus_slave.h @@ -40,6 +40,11 @@ typedef struct SMBusDevice SMBusDevice; typedef struct SMBusDeviceClass { I2CSlaveClass parent_class; + + /* + * An operation with no data, special in SMBus. + * This may be NULL, quick commands are ignore in that case. + */ void (*quick_cmd)(SMBusDevice *dev, uint8_t read); void (*send_byte)(SMBusDevice *dev, uint8_t val); uint8_t (*receive_byte)(SMBusDevice *dev);