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: 156832 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3721926jaa; Mon, 28 Jan 2019 10:07:06 -0800 (PST) X-Google-Smtp-Source: ALg8bN4mc4muw+q6xmHPqSbfgeSF7StAY5FsptjKyyOCQxGFsdS14YE9ioGTWz9DBkBv1rh9k8Zu X-Received: by 2002:a1c:c70f:: with SMTP id x15mr17952668wmf.130.1548698826588; Mon, 28 Jan 2019 10:07:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548698826; cv=none; d=google.com; s=arc-20160816; b=xcjuJvT8l/8/j5SgN2Aagmp8AZ3D9cfo0fkRr2JYimYm4v04zjGmPSashAZu1lZPTE LbwwGHGGHMJpTmeH/6UqUYKkQvzdKe0vY5EhrE44vlzJszzF61G8S5M+hji+76BXJtvG zMQV4cMu4kfSnH4lEFwE8DKGmMyyo48cdXNtGGylYET5SOvPF/SY/qBTJa/bXgnY4+at pfI3+aNzlE54Q8hu4uKrASc4q8AfMmIXIM64aBcRRz0USh9Ux5u0uTWwjM3RUwgHoBiG 1YiVz4tVsSUxqiccdI5vk/vAH9wKnlBPxr+7L5LsJxlfuUTfX657WgCljEjw0g4f2xEV +W3A== 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=vfCxqYRfJPhX2fj8vENKKEumXT87MkbK2AiQbJhNdDLqf8K0B0eKXbJUlAzJg7xWnR MlUy+CK0Rx98QO2fGH952J2zt49E7E3wMBXhANybVcOm0DpceqtNE1v1x9MrvEvKHMSK eE2DOSff3e8p/BxnvJ7bcn8ha0j/7VIBCU8TftxB0Ur/hFh+Pnv+ngnZ+EPnGwUDIjMy Jjrlb+N0UHaLklyiQAiNMyOkdoOt0/95k4TBG7tSWnDVgXda4bp5SL/96pI4Fe84+Y3L IqPpgqMi1NUlJf963vy9b4Xi5oXdMfO+50/+5LLkJN8gt8s59n2n4wcDpSRP8pXkYACY Frtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=S9DOUmG0; 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 q15si79408098wrr.127.2019.01.28.10.07.06 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 28 Jan 2019 10:07:06 -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=S9DOUmG0; 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]:36278 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBJJ-0006f0-EX for patch@linaro.org; Mon, 28 Jan 2019 13:07:05 -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-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+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);