From patchwork Mon Jan 28 17:54:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 10784215 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 951F86C2 for ; Mon, 28 Jan 2019 18:05:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 851D42B713 for ; Mon, 28 Jan 2019 18:05:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 793132B807; Mon, 28 Jan 2019 18:05:47 +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 628012B713 for ; Mon, 28 Jan 2019 18:05:43 +0000 (UTC) Received: from localhost ([127.0.0.1]:36278 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBHy-0006f0-JO for patchwork-qemu-devel@patchwork.kernel.org; Mon, 28 Jan 2019 13:05:42 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37283) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBEF-0003b9-Rc for qemu-devel@nongnu.org; Mon, 28 Jan 2019 13:01:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1goB7r-0005WU-Sb for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:55:30 -0500 Received: from mail-io1-xd41.google.com ([2607:f8b0:4864:20::d41]:37734) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1goB7r-0005WA-Np for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:55:15 -0500 Received: by mail-io1-xd41.google.com with SMTP id g8so14245248iok.4 for ; Mon, 28 Jan 2019 09:55:15 -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=S9DOUmG0H0tEWkIwTCBYa51K4Twm8L3pouBIKgJssUUXjYtmL9dAIWNTH8paAqCCZd er8wgPuumXFgcwlCjn97cq9HjaIW2SwUEUagxv7tyLkRQCme2eXVoh1C/vqh+cmBErpO 0+JGbw8KMkiiYA9KBUoryHvuUWPjbd/hDwhZ+tpLgHMpJTe+EXCy3CaJ39blVBJLie9f lcD87JYA9Nh3x8COl8E9uUi6nPGzWAe9GGaRkA9Fl6bOR1xkP78kvWa70VitAhpqOOtg xALqKzFUbrFVpuQRcu8tOSsXOCO3NmMvsOneHZRo/o1Jv/fXemjKaPzYEqdkYX0IM/Zh 6bXg== 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=D1yeA0/Jg1oa1EE4aNdJqpZhYb2uyIgQzaBhCWN2GeogmQqvF8VDa009jew77z9PmE 9HItceRDEhoAPbME33szIkKIJn7sfjAA4s6iHVNlHMjLUEe7CVmt9GtYez4rH0dVzeDr y4iStWg5yUkivDNeksaunFSP5LOmhrzU2t1Cpo11tGLvaWfzJdEI84c6220EmBL5ufWU lprzSnQVscK8CzyjfIDHzA9Tpj33NslySyLDIaMgnYNFxf3Ph1vHxUdme0+W6a8/bGK3 jgz8w4hg89BE0WGVPeT4JSNIFQrDZuuuUlp/M+y26ckA3N+d0nPP7TWk6gcNJ+0Ox1W+ 1yGQ== X-Gm-Message-State: AHQUAuYSxgkyXUvTkBg3nIDrIYRQwl3DVqdDtKKbHOtg4+ehZQT3Q3Ue V7vZ0KpU6c3YYg0XN1FZ4e4sjv4= X-Google-Smtp-Source: AHgI3IZEG0s1qmisrmp3l8Ma8Z6H3YOIA7PLXxqZxutxhD5elMCx4v/Y9ekb46Qie3eqExjdSTqCvw== X-Received: by 2002:a5e:8908:: with SMTP id k8mr13545127ioj.300.1548698115030; Mon, 28 Jan 2019 09:55:15 -0800 (PST) Received: from serve.minyard.net ([47.184.128.64]) by smtp.gmail.com with ESMTPSA id f21sm46148itc.14.2019.01.28.09.55.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Jan 2019 09:55:13 -0800 (PST) Received: from t430.minyard.net (unknown [IPv6:2001:470:b8f6:1b:c8f8:7971:e432:a838]) by serve.minyard.net (Postfix) with ESMTPA id 6800BBEF; Mon, 28 Jan 2019 11:55:12 -0600 (CST) Received: by t430.minyard.net (Postfix, from userid 1000) id 8B74D30115C; Mon, 28 Jan 2019 11:55:07 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org, "Dr . David Alan Gilbert" Date: Mon, 28 Jan 2019 11:54:44 -0600 Message-Id: <20190128175458.27255-6-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190128175458.27255-1-minyard@acm.org> References: <20190128175458.27255-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::d41 Subject: [Qemu-devel] [PATCH v4 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 , Paolo Bonzini , Corey Minyard , Corey Minyard , "Michael S . Tsirkin" 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);