From patchwork Tue Aug 21 17:02:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 144777 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp5581492ljj; Tue, 21 Aug 2018 11:05:44 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdaam+3PJ8+FtHagZRSjmzMOar4l///9TEQAD5MitChOMxMEvKk0Q1rNYd+57RgttgLLtDbr X-Received: by 2002:a37:1b68:: with SMTP id b101-v6mr9870392qkb.349.1534874743895; Tue, 21 Aug 2018 11:05:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534874743; cv=none; d=google.com; s=arc-20160816; b=rjXJRO4L+WNboHQC13WS9v7uvcR3jvZ0Urf+0DQ3l5SjJJQpsiU8FZ/Ncl18BzVruo yjAbyV8dP51cUitxxDqqPH3aHgO56eOO34ZZTugG31LJUN1vc/wahdICzjEJyHA5wFJS Fw3191MTIpDyBV1lcOOA0KH5aRut2IYKFy1g5ePukbdrosIW0awrfLLJag4nF5gZQvGG 8QiDM47edTKArdJmn1FiDOIriL3fE230bcP9DlHAdXK0se9prEtYy3JYp8xg1C7jtwA7 WzU1GcIKl7ChbNp6uXxbFaRQ/IOKAd4sPekM+2oqnJ/Kw/VQtkdcfz7WsV0eyo7xj3ef lZsA== 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:arc-authentication-results; bh=Fxt2Bv77vlZwD2j8q4OUZx5Q3dcBbFO2qTPQ+/Jhk80=; b=P+Dam1ROVX2qqfleH48HQGCbbKZMbLxqE5MLd3C4sHu7ZQrL+r11vtzDXxN5z4ExIU OT+xaZc+jB3Vhm6b6iTe4Gj8T2z6u3xLbC3EfgqB/V8Ap6xPu24meszafrWhMvv31iBo HMweKvPTb7vHoFDvjZzr29Yx72m724wUbwbyYqpxNMkTMoo64QHYnkPNlHOLTelINBId SivNqfHS0OjpB9Tm7Dk1JRYugQCJ3wbnreG+8NYlGN+tsrleBC9URC7C0CUgISR4Tawi YRptmwMhA6ouWycZlCdY7hH8TLi9h4GhMmcy9Rj/+EeisxOAcSSdPSB9Fr53StxrZK6y UppQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=fJXiWL2v; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id z89-v6si6397084qvz.121.2018.08.21.11.05.43 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 21 Aug 2018 11:05:43 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=fJXiWL2v; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1]:55275 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fsB2F-0005Vu-BJ for patch@linaro.org; Tue, 21 Aug 2018 14:05:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34075) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fsA57-0002aD-0o for qemu-devel@nongnu.org; Tue, 21 Aug 2018 13:04:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fsA4p-0007Ea-66 for qemu-devel@nongnu.org; Tue, 21 Aug 2018 13:04:33 -0400 Received: from mail-wm0-x22f.google.com ([2a00:1450:400c:c09::22f]:35743) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fsA4o-00071s-R9 for qemu-devel@nongnu.org; Tue, 21 Aug 2018 13:04:19 -0400 Received: by mail-wm0-x22f.google.com with SMTP id o18-v6so3533365wmc.0 for ; Tue, 21 Aug 2018 10:04:10 -0700 (PDT) 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=Fxt2Bv77vlZwD2j8q4OUZx5Q3dcBbFO2qTPQ+/Jhk80=; b=fJXiWL2vdmM0icFEFgbz98aAXIaXqyR4fONO9u/vceGzPHC2FhMP88CBAJuyCcuE3R RLm4I/A4h9VHOc97U3lTkDCG+ZbMaxBYDl67+0jwfJv5ibG/3ODmD/p5AsvFqrx6/ZWh XSfqCkxsrI5HWXnZ0Q2X1K9ZhdmkOaWswUt8YmbdJiAausZXhikElGsTlTDym6ALHG0S usF+G+i+mmQ10b+/dRKWa1h7NAJ5EFs1cOMoectFlrcr9nCcBTPtXLPA5MgOH7YyCeNE 7Jk+pmfSTRAiN7dVGsGFv/j0PuqNXY+IyTfOG/so9kbkaPW8c4/QqfF+fbDPo1uEHBE9 4Ixw== 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=Fxt2Bv77vlZwD2j8q4OUZx5Q3dcBbFO2qTPQ+/Jhk80=; b=ZifNKBVylKwWWhImDTLQJJcRvdYB8wNHghE5rJyKtxVv7A2oQWxjXxIo42tJTCqZYL EtRXsfxeZpODv+IAAArynLP6qc8pZoH1iv0p77FdEYT0GdbLelMB5YtV9s0Iuo39oBvr DkhHeXolZcA5QD1MZTASyIWTonkgVxLciNlecaNRqJht38MwV+TttcJgQqwrJwF822kj WpKsWO0cqDIMSirBa9x8B7VzAyS8Nk+N5MabTWzdYyO5AXNt0dQzSm5Wh1p1V2V96Ph3 v0BVz11wkN4pJrtIJViS4MRJp76f4zOAM9sa3LzbY9MHww6lmqrZF0aYM8gMnHOfztRG TILw== X-Gm-Message-State: APzg51BiLdi31KLbKqhmY0JerAgsZ4qvQHHNMn8EJhPl9X4vnY6RyFx9 mCjfgkHdmyReCTCB3kso8NsYBHwo X-Received: by 2002:a1c:e595:: with SMTP id c143-v6mr133477wmh.85.1534871049088; Tue, 21 Aug 2018 10:04:09 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-184-244.clienti.tiscali.it. [78.12.184.244]) by smtp.gmail.com with ESMTPSA id v6-v6sm2608955wmc.43.2018.08.21.10.04.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Aug 2018 10:04:08 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 21 Aug 2018 19:02:34 +0200 Message-Id: <1534870966-9287-63-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1534870966-9287-1-git-send-email-pbonzini@redhat.com> References: <1534870966-9287-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::22f Subject: [Qemu-devel] [PULL 62/74] i2c: pm_smbus: Clean up some style issues 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: Corey Minyard , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard Fix some spacing issues, remove extraneous comments, add some defines instead of hard-coding numbers. Signed-off-by: Corey Minyard Cc: Michael S. Tsirkin Cc: Paolo Bonzini Message-Id: <1534796770-10295-2-git-send-email-minyard@acm.org> Signed-off-by: Paolo Bonzini --- hw/i2c/pm_smbus.c | 58 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 20 deletions(-) -- 1.8.3.1 diff --git a/hw/i2c/pm_smbus.c b/hw/i2c/pm_smbus.c index 0d26e0f..83c2377 100644 --- a/hw/i2c/pm_smbus.c +++ b/hw/i2c/pm_smbus.c @@ -22,8 +22,6 @@ #include "hw/i2c/pm_smbus.h" #include "hw/i2c/smbus.h" -/* no save/load? */ - #define SMBHSTSTS 0x00 #define SMBHSTCNT 0x02 #define SMBHSTCMD 0x03 @@ -32,19 +30,34 @@ #define SMBHSTDAT1 0x06 #define SMBBLKDAT 0x07 -#define STS_HOST_BUSY (1) -#define STS_INTR (1<<1) -#define STS_DEV_ERR (1<<2) -#define STS_BUS_ERR (1<<3) -#define STS_FAILED (1<<4) -#define STS_SMBALERT (1<<5) -#define STS_INUSE_STS (1<<6) -#define STS_BYTE_DONE (1<<7) +#define STS_HOST_BUSY (1 << 0) +#define STS_INTR (1 << 1) +#define STS_DEV_ERR (1 << 2) +#define STS_BUS_ERR (1 << 3) +#define STS_FAILED (1 << 4) +#define STS_SMBALERT (1 << 5) +#define STS_INUSE_STS (1 << 6) +#define STS_BYTE_DONE (1 << 7) /* Signs of successfully transaction end : * ByteDoneStatus = 1 (STS_BYTE_DONE) and INTR = 1 (STS_INTR ) */ -//#define DEBUG +#define CTL_INTREN (1 << 0) +#define CTL_KILL (1 << 1) +#define CTL_LAST_BYTE (1 << 5) +#define CTL_START (1 << 6) +#define CTL_PEC_EN (1 << 7) +#define CTL_RETURN_MASK 0x1f + +#define PROT_QUICK 0 +#define PROT_BYTE 1 +#define PROT_BYTE_DATA 2 +#define PROT_WORD_DATA 3 +#define PROT_PROC_CALL 4 +#define PROT_BLOCK_DATA 5 +#define PROT_I2C_BLOCK_DATA 6 + +/*#define DEBUG*/ #ifdef DEBUG # define SMBUS_DPRINTF(format, ...) printf(format, ## __VA_ARGS__) @@ -70,11 +83,12 @@ static void smb_transaction(PMSMBus *s) if ((s->smb_stat & STS_DEV_ERR) != 0) { goto error; } + switch(prot) { - case 0x0: + case PROT_QUICK: ret = smbus_quick_command(bus, addr, read); goto done; - case 0x1: + case PROT_BYTE: if (read) { ret = smbus_receive_byte(bus, addr); goto data8; @@ -82,7 +96,7 @@ static void smb_transaction(PMSMBus *s) ret = smbus_send_byte(bus, addr, cmd); goto done; } - case 0x2: + case PROT_BYTE_DATA: if (read) { ret = smbus_read_byte(bus, addr, cmd); goto data8; @@ -91,16 +105,17 @@ static void smb_transaction(PMSMBus *s) goto done; } break; - case 0x3: + case PROT_WORD_DATA: if (read) { ret = smbus_read_word(bus, addr, cmd); goto data16; } else { - ret = smbus_write_word(bus, addr, cmd, (s->smb_data1 << 8) | s->smb_data0); + ret = smbus_write_word(bus, addr, cmd, + (s->smb_data1 << 8) | s->smb_data0); goto done; } break; - case 0x5: + case PROT_I2C_BLOCK_DATA: if (read) { ret = smbus_read_block(bus, addr, cmd, s->smb_data); goto data8; @@ -158,8 +173,9 @@ static void smb_ioport_writeb(void *opaque, hwaddr addr, uint64_t val, break; case SMBHSTCNT: s->smb_ctl = val; - if (val & 0x40) + if (s->smb_ctl & CTL_START) { smb_transaction_start(s); + } break; case SMBHSTCMD: s->smb_cmd = val; @@ -198,7 +214,7 @@ static uint64_t smb_ioport_readb(void *opaque, hwaddr addr, unsigned width) break; case SMBHSTCNT: s->smb_index = 0; - val = s->smb_ctl & 0x1f; + val = s->smb_ctl & CTL_RETURN_MASK; break; case SMBHSTCMD: val = s->smb_cmd; @@ -221,7 +237,9 @@ static uint64_t smb_ioport_readb(void *opaque, hwaddr addr, unsigned width) val = 0; break; } - SMBUS_DPRINTF("SMB readb port=0x%04" HWADDR_PRIx " val=0x%02x\n", addr, val); + SMBUS_DPRINTF("SMB readb port=0x%04" HWADDR_PRIx " val=0x%02x\n", + addr, val); + return val; }