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: 10822413 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1C875922 for ; Wed, 20 Feb 2019 15:51:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 01CDE2ED90 for ; Wed, 20 Feb 2019 15:51:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F3E982ED97; Wed, 20 Feb 2019 15:51:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 78D8B2ED90 for ; Wed, 20 Feb 2019 15:51:09 +0000 (UTC) Received: from localhost ([127.0.0.1]:41316 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwU9M-0005Wf-4W for patchwork-qemu-devel@patchwork.kernel.org; Wed, 20 Feb 2019 10:51:08 -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-Google-Smtp-Source: AHgI3IasT5iEnwv+0rVZhinQc9/RGld6SrVa2uPrWCs9n7SAIvjo2fV8VKQEU2NN+DutFIQ0i3QO1A== 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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);