From patchwork Fri Dec 30 15:21:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 89377 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp6486344qgi; Fri, 30 Dec 2016 07:24:30 -0800 (PST) X-Received: by 10.55.204.25 with SMTP id r25mr50511452qki.213.1483111470694; Fri, 30 Dec 2016 07:24:30 -0800 (PST) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 9si34760278qtu.252.2016.12.30.07.24.30 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 30 Dec 2016 07:24:30 -0800 (PST) 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; 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 Received: from localhost ([::1]:40308 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cMz2k-0003Tl-58 for patch@linaro.org; Fri, 30 Dec 2016 10:24:30 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43273) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cMz0Q-0002HK-02 for qemu-devel@nongnu.org; Fri, 30 Dec 2016 10:22:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cMz0O-0000E9-Pn for qemu-devel@nongnu.org; Fri, 30 Dec 2016 10:22:05 -0500 Received: from mail-pg0-x242.google.com ([2607:f8b0:400e:c05::242]:33864) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cMz0O-0000Dm-K2 for qemu-devel@nongnu.org; Fri, 30 Dec 2016 10:22:04 -0500 Received: by mail-pg0-x242.google.com with SMTP id b1so22369286pgc.1 for ; Fri, 30 Dec 2016 07:22: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=f7SYDlCGkkvFSGPLe9Y4L56GarImFleSm0Dz6IF5L9E=; b=NT9hFAKX2wSNo2NK6Rabgupb8d+SsmI3L8Ekyjb9Bs9gHl3VktAx6WE4usL4wdRrrA hlB7U3OqnXqM1rhj+eOVapgJeJSrFpiO3eD5M1xe97OYWjivGbfjRAi9kNyZp5sBErzu dx2j1OzsPPcrUtyFDRfIlm9x6om/7bEAkp4HgFGEiKApGz8N8YWkfnhFc+O0yeD2dQOK 0/nVCQNdJw5s0uHLgChlHN4v28QZIQQ3d+N3exsIqxeFy8rNQEmcOYVIwOIcZSKTjn4Z jCm/KvWS+rKJHk81iRVBnzmw32fhGQRPfTKS/V8Uvvw91er/xpO23rpUUDGfLSrLzYrt jNow== 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=f7SYDlCGkkvFSGPLe9Y4L56GarImFleSm0Dz6IF5L9E=; b=SG1bmil8mzn8VHyVTDh5MK6A7rUgmAmDi7whiDcuIiE6ea9SV40G8xLkwVcpWUrq4l bcX7r0Dps+V174vbonqP7Gyyq/etAazBQKCWEaUOJS/1eF3qbmCA1UszOfHArf7+EtGg bN9HuBIPp+zJguaxL9CXMFS2J/gDeLvzAlSJ0871juF4kVbVqWbDvzUrzD3mOIh+Ptlh tCmvQi3NNHQ586aYL7NChb1Wht6vaTcQU1E46YwMGFhPAAGK48Yy0uoZYEciKUy9B5x5 rznlyzbSfHW5HxcmcwBxNoPQ8qbGBZwNamfbLgUqCffDKGA6kdHQmJrQGMtuWdA3aYxP E41g== X-Gm-Message-State: AIkVDXKKC4e1nhgXu7CClwFFUtRAMDzvRuq9vWQ+bOblTVroI1SxEjkU/kzFFQosInchog== X-Received: by 10.99.226.83 with SMTP id y19mr86125039pgj.147.1483111323867; Fri, 30 Dec 2016 07:22:03 -0800 (PST) Received: from serve.minyard.net ([47.184.183.230]) by smtp.gmail.com with ESMTPSA id 65sm113476572pfn.12.2016.12.30.07.22.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Dec 2016 07:22:01 -0800 (PST) Received: from t430.minyard.net (unknown [IPv6:2001:470:b8f6:1b:3850:e313:ed7:8ae4]) by serve.minyard.net (Postfix) with ESMTPA id 11E00A136; Fri, 30 Dec 2016 09:21:57 -0600 (CST) Received: by t430.minyard.net (Postfix, from userid 1000) id D61CB300099; Fri, 30 Dec 2016 09:21:54 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org Date: Fri, 30 Dec 2016 09:21:48 -0600 Message-Id: <1483111310-24808-18-git-send-email-minyard@acm.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1483111310-24808-1-git-send-email-minyard@acm.org> References: <1483111310-24808-1-git-send-email-minyard@acm.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c05::242 Subject: [Qemu-devel] [PATCH 17/19] i2c: Allow SMBus device to NAK start events 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 , minyard@acm.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard The I2C code has been modified to allow devices to NAK start events, the SMBus code should, too. Signed-off-by: Corey Minyard --- hw/i2c/smbus.c | 11 +++++++++++ include/hw/i2c/smbus.h | 2 ++ 2 files changed, 13 insertions(+) -- 2.7.4 diff --git a/hw/i2c/smbus.c b/hw/i2c/smbus.c index 4cb651e..87a1669 100644 --- a/hw/i2c/smbus.c +++ b/hw/i2c/smbus.c @@ -71,6 +71,17 @@ static int smbus_i2c_event(I2CSlave *s, enum i2c_event event) { SMBusDevice *dev = SMBUS_DEVICE(s); + if (event == I2C_START_SEND || event == I2C_START_RECV) { + /* Allow the device to NAK the start event. */ + SMBusDeviceClass *sc = SMBUS_DEVICE_GET_CLASS(dev); + + if (sc->event) { + int rv = sc->event(dev, event); + if (rv) + return rv; + } + } + switch (event) { case I2C_START_SEND: switch (dev->mode) { diff --git a/include/hw/i2c/smbus.h b/include/hw/i2c/smbus.h index f1b8078..fc995eb 100644 --- a/include/hw/i2c/smbus.h +++ b/include/hw/i2c/smbus.h @@ -39,6 +39,8 @@ typedef struct SMBusDeviceClass { I2CSlaveClass parent_class; int (*init)(SMBusDevice *dev); + /* Allow the device to get start and stop events so they can NAK them. */ + int (*event)(SMBusDevice *dev, enum i2c_event event); void (*quick_cmd)(SMBusDevice *dev, uint8_t read); void (*send_byte)(SMBusDevice *dev, uint8_t val); uint8_t (*receive_byte)(SMBusDevice *dev);