Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2562434ybt; Tue, 16 Jun 2020 09:06:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxCDjqfcnh7eMX5rjRr9L4RyxbCLb+HP71dFlWJibxWOFxrBnVQ5a1V0GSFiRa5iI52weYD X-Received: by 2002:a17:906:3951:: with SMTP id g17mr3568758eje.414.1592323562409; Tue, 16 Jun 2020 09:06:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592323562; cv=none; d=google.com; s=arc-20160816; b=AJbsPqY4PL8iWv4X+lPp/+UDAFfzXorf2rWBy4CRpuru4FB3dI5pMVpSCBM4l4GcdI QsBqQmMNGndt5tDC/BRF0DK2Rku2TcVY/yhetQVUdQcrpgvV0mfhNnK2cW0hEXEccoEZ Nl3hFO0b9ufITlFPH0J7PtX9RbLvfPxUk3jU4qgpzWkWyh3ODB3NXsLTRdgyIB0NWBkN G9ftINPd2A63H+rr/KuSaK1aZ/kaoE8OkGqmhFdDpfL2lVVFsCNIaHzEt1TO1GJPwpRb 5RylLDGgTjpFsNrwgojCDg25RB2dP0F+1mWbN9Pc9P8nHcazOU9piKdCR5hYF6VL5WKp O1bQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=pFrRHq1XVs88zCS7gViaAQplZ6MV/Otf8rLxL7f/kd8=; b=qcUS/I5+l/xa1c3NntZ/+7mrxh9ZX+ChpgzKAekuoVPBljH38totvWFT9Fqm68BkWf Nf3c4mYuswuh7kG7FTF2OaVusmexnJ9N+dj35IafXDrG01/824K/y/rZjmEPMNdAMelR A0SY1Kzpz5daeLsZ8zteBp2a2mAwnJOCqbsdA61NeZv/VjYxN8asejMuFlSD2RVx0yU1 qdyTpJt8dxtFQdWCE1iczqr0OQATk6rogUAJrC3BDQI/eCED+jiuQcf7dxN8PYeuUAvw pANAgkAwPqorQ/3tV9Z/luK68627SFQJMTpQvmds+VUfPeOrCEay1NqcPgnq3sjamrGR HATA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=c3wGbVWH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dn16si14128062ejc.427.2020.06.16.09.05.38; Tue, 16 Jun 2020 09:06:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=c3wGbVWH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732678AbgFPQDu (ORCPT + 99 others); Tue, 16 Jun 2020 12:03:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730401AbgFPPt5 (ORCPT ); Tue, 16 Jun 2020 11:49:57 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0821C061573; Tue, 16 Jun 2020 08:49:57 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id l24so826410pgb.5; Tue, 16 Jun 2020 08:49:57 -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 :mime-version:content-transfer-encoding; bh=pFrRHq1XVs88zCS7gViaAQplZ6MV/Otf8rLxL7f/kd8=; b=c3wGbVWHycQTd3FhMQJMCIvSPCX0sIf914T+Ow7XL1zuxIkMnMSYQJRKeAI6P7O4bz QhBd87rsmaMDXZAWD6iuH/j46lXMJZLUwHr7HHt1DlBZUJDOCqSK0eAGDB3b/OR5S7lI Ph+hmGbbzUknIG2WIxhcxpeNNegn3zXHX7CvAd3aA2HfUXFScKDKoDgQGJ7Pd0ZqgEx+ ZDa4mWnWcmAA2LbL2DPXmPC3kwJto6HdzQ9hWclskR+XsLmz7mqcOUfQvs6N+qVZ4vu7 jyvbTjqlMx4N5lmyP6I6DZLOjWxmOionysqtJeqkdIRjhDxFM9Rvz9NSbp4tZvdXmod+ 2agg== 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:mime-version:content-transfer-encoding; bh=pFrRHq1XVs88zCS7gViaAQplZ6MV/Otf8rLxL7f/kd8=; b=dw7aYj7Lz1YNIXaydYr0cZHP1f1+sfHwUxOevahONR+UHP2CpAqOAfedV7COiR4REt xmPgaf8S8Pj6TFle3GvgrUlFmLRwscJfT2JYCtknqkljfilRmfCYHOr7gz6mlfBKvmmK S2fAIhktOLevPVykCUBP+xZyaDnY3ht3nZrpC3tLqv7fZ/g7rxrOBZIbs7AhrQOAJ1U5 q3HGCdgDgRlgTBKAZkzT8dAwNsCpyZDnNly1zo01YQ9qhoDEPu1O6umwsPmdXFVoVZz2 De0JjgcKkZFUE+CJGPZsMXS0VFCXfGblbJ/NPDhXImYEkZasGxZeAo1WtJqhGuyfuFIq PxEw== X-Gm-Message-State: AOAM533MQLusfWIysWm/AOreoCXgKaxbSGogb5ujIebSTrbENY3ROxrD 48RGrD1cRkCOf3I/WJGs8vI= X-Received: by 2002:a62:ddc4:: with SMTP id w187mr2616321pff.63.1592322597492; Tue, 16 Jun 2020 08:49:57 -0700 (PDT) Received: from sultan-box.localdomain ([89.45.90.111]) by smtp.gmail.com with ESMTPSA id l195sm7668873pfd.18.2020.06.16.08.49.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jun 2020 08:49:56 -0700 (PDT) From: Sultan Alsawaf X-Google-Original-From: Sultan Alsawaf To: jarkko.nikula@linux.intel.com Cc: aaron.ma@canonical.com, admin@kryma.net, andriy.shevchenko@linux.intel.com, benjamin.tissoires@redhat.com, hdegoede@redhat.com, hn.chen@weidahitech.com, jikos@kernel.org, kai.heng.feng@canonical.com, linux-i2c@vger.kernel.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, mika.westerberg@linux.intel.com, sultan@kerneltoast.com, vicamo.yang@canonical.com, wsa@kernel.org Subject: [PATCH v2] HID: i2c-hid: Use block reads when possible to save power Date: Tue, 16 Jun 2020 08:49:51 -0700 Message-Id: <20200616154951.3050-1-sultan@kerneltoast.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sultan Alsawaf We have no way of knowing how large an incoming payload is going to be, so the only strategy available up until now has been to always retrieve the maximum possible report length over i2c, which can be quite inefficient. For devices that send reports in block read format, the i2c controller driver can read the payload length on the fly and terminate the i2c transaction early, resulting in considerable power savings. On a Dell Precision 15 5540 with an i9-9880H, resting my finger on the touchpad causes psys power readings to go up by about 4W and hover there until I remove my finger. With this patch, my psys readings go from 4.7W down to 3.1W, yielding about 1.6W in savings. This is because my touchpad's max report length is 60 bytes, but all of the regular reports it sends for touch events are only 32 bytes, so the i2c transfer is roughly halved for the common case. Signed-off-by: Sultan Alsawaf --- Jarkko, could you try this? drivers/hid/i2c-hid/i2c-hid-core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/hid/i2c-hid/i2c-hid-core.c b/drivers/hid/i2c-hid/i2c-hid-core.c index 294c84e136d7..739dccfc57e1 100644 --- a/drivers/hid/i2c-hid/i2c-hid-core.c +++ b/drivers/hid/i2c-hid/i2c-hid-core.c @@ -472,11 +472,14 @@ static void i2c_hid_get_input(struct i2c_hid *ihid) int ret; u32 ret_size; int size = le16_to_cpu(ihid->hdesc.wMaxInputLength); + u16 flags; if (size > ihid->bufsize) size = ihid->bufsize; - ret = i2c_master_recv(ihid->client, ihid->inbuf, size); + /* Try to do a block read if the size fits in one byte */ + flags = size > 255 ? I2C_M_RD : I2C_M_RD | I2C_M_RECV_LEN; + ret = i2c_transfer_buffer_flags(ihid->client, ihid->inbuf, size, flags); if (ret != size) { if (ret < 0) return; -- 2.27.0