From patchwork Sun Jun 14 21:02:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sultan Alsawaf X-Patchwork-Id: 11603433 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7D55F6A2 for ; Sun, 14 Jun 2020 21:03:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 63D78206B7 for ; Sun, 14 Jun 2020 21:03:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dRCJLEYO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727893AbgFNVDE (ORCPT ); Sun, 14 Jun 2020 17:03:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726938AbgFNVDD (ORCPT ); Sun, 14 Jun 2020 17:03:03 -0400 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4738BC03E97C; Sun, 14 Jun 2020 14:03:03 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id j1so6921148pfe.4; Sun, 14 Jun 2020 14:03:03 -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=2q2lkPFOE1HHvSqY9cZoSA6nGM3ktOf/xAtJkt4U/Uw=; b=dRCJLEYOknC4Q65AQGXfeoeQt/C0O0Ubagurth12zIP89W8Ycx2CkZeL5O03eoQipT 8Vpk3C4QWR24/wtDHw8vc3WQBUd/LWygYtviJuzjg9mFUn8ODSrpnrr1D80pKPYB1qzg cBTGYnR1ro24q9Gju96PgmjzySd9tR3rARoFGHlcQAOG+0WjIYWmkXSxYzb6iev+Y9ze r1FpePsj96BJFvMkmODM0u2lrK0X91I/qt+TvpbVhQhC/YaxTfrpBVZNldeegg5Uauu1 XL4vflIlTJXobIA/EbNdPOgoyvliRejufvGdcsDXYv3q4FPtR36QVDsN48Sio7JpaybA s8KQ== 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=2q2lkPFOE1HHvSqY9cZoSA6nGM3ktOf/xAtJkt4U/Uw=; b=fMEYXCMX+KYGA7LOHurXMHr4o+MzpPPJ9S94d656uX8YRcB92aOpNzOC59JLUilPsN I/DWP01kgnwpMpE3HVi7BSl4TqNlPxgYQotNZR+c+bpv2lNKU1Wu9Qv5mmajHKWLXO4q JBMFfX18egwHKWK6YOANz1871PHXOW0etfB357d6CJizNfUOohM2nsDf36gh3zD35N1K JO5nSa9mOM78NDiBexg++qvwWh++xulmWZXWz4NNdW1+7hUL/c6tsJNp+m+nZ4Fp+R5X 36zm0MeT1G48nUmq1WFkU2cVD4YzcK3jU1mWk+J5b67RCWZ7v8Rlm+qY4yWNyg3WHszK zdpw== X-Gm-Message-State: AOAM530qw/wxmYycNTajBH7MsoD5adRCmlU/EVRxUi8fypfuPoRTHxdi 42cnz1pIgaxs61G4ej3TV14= X-Google-Smtp-Source: ABdhPJzw9epsD325xpNNSKo3Fuu16DuLxdXw28bisO0FNwLCA2uutIGU8+3mhVda0Si6mHCnSm1j0Q== X-Received: by 2002:a62:8608:: with SMTP id x8mr8124633pfd.96.1592168582669; Sun, 14 Jun 2020 14:03:02 -0700 (PDT) Received: from sultan-box.localdomain ([89.45.90.111]) by smtp.gmail.com with ESMTPSA id d184sm1827746pfd.85.2020.06.14.14.03.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Jun 2020 14:03:02 -0700 (PDT) From: Sultan Alsawaf X-Google-Original-From: Sultan Alsawaf To: Aaron Ma , Andy Shevchenko , Benjamin Tissoires , Hans de Goede , HungNien Chen , Jarkko Nikula , Jiri Kosina , Kai-Heng Feng , linux-i2c@vger.kernel.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Mika Westerberg , Pavel Balan , Tin Huynh , Wolfram Sang , You-Sheng Yang Cc: Sultan Alsawaf Subject: [PATCH 1/2] i2c: designware: Only check the first byte for SMBus block read length Date: Sun, 14 Jun 2020 14:02:54 -0700 Message-Id: <20200614210255.4641-2-sultan@kerneltoast.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200614210255.4641-1-sultan@kerneltoast.com> References: <20200614210255.4641-1-sultan@kerneltoast.com> MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Sultan Alsawaf SMBus block reads can be broken because the read function will just skip over bytes it doesn't like until reaching a byte that conforms to the length restrictions for block reads. This is problematic when it isn't known if the incoming payload is indeed a conforming block read. According to the SMBus specification, block reads will only send the payload length in the first byte, so we can fix this by only considering the first byte in a sequence for block read length purposes. Fixes: c3ae106050b9 ("i2c: designware: Implement support for SMBus block read and write") Signed-off-by: Sultan Alsawaf --- drivers/i2c/busses/i2c-designware-master.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/i2c/busses/i2c-designware-master.c b/drivers/i2c/busses/i2c-designware-master.c index d6425ad6e6a3..16d38b8fc19a 100644 --- a/drivers/i2c/busses/i2c-designware-master.c +++ b/drivers/i2c/busses/i2c-designware-master.c @@ -398,7 +398,6 @@ i2c_dw_recv_len(struct dw_i2c_dev *dev, u8 len) len += (flags & I2C_CLIENT_PEC) ? 2 : 1; dev->tx_buf_len = len - min_t(u8, len, dev->rx_outstanding); msgs[dev->msg_read_idx].len = len; - msgs[dev->msg_read_idx].flags &= ~I2C_M_RECV_LEN; return len; } @@ -430,10 +429,11 @@ i2c_dw_read(struct dw_i2c_dev *dev) u32 flags = msgs[dev->msg_read_idx].flags; regmap_read(dev->map, DW_IC_DATA_CMD, &tmp); - /* Ensure length byte is a valid value */ - if (flags & I2C_M_RECV_LEN && - tmp <= I2C_SMBUS_BLOCK_MAX && tmp > 0) { - len = i2c_dw_recv_len(dev, tmp); + if (flags & I2C_M_RECV_LEN) { + /* Ensure length byte is a valid value */ + if (tmp <= I2C_SMBUS_BLOCK_MAX && tmp > 0) + len = i2c_dw_recv_len(dev, tmp); + msgs[dev->msg_read_idx].flags &= ~I2C_M_RECV_LEN; } *buf++ = tmp; dev->rx_outstanding--; From patchwork Sun Jun 14 21:02:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sultan Alsawaf X-Patchwork-Id: 11603435 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 98A5F90 for ; Sun, 14 Jun 2020 21:03:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 80BC3206B7 for ; Sun, 14 Jun 2020 21:03:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="M1v4894O" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727918AbgFNVDI (ORCPT ); Sun, 14 Jun 2020 17:03:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726938AbgFNVDG (ORCPT ); Sun, 14 Jun 2020 17:03:06 -0400 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D72CC03E97C; Sun, 14 Jun 2020 14:03:05 -0700 (PDT) Received: by mail-pg1-x543.google.com with SMTP id w20so6710717pga.6; Sun, 14 Jun 2020 14:03:05 -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=LuKrGdsyJt363mkqnjfvHbulwnJ9TO1k3D/bFALSM6Q=; b=M1v4894OoBgKF8izTIkH6jmFVP524510jNiBjJGnDTw/E0a1oBDAeC1R0j+05TPxad CEGL557RLDnJuq/ExdD6BS1EOQZclyk74RTiDlDP77AlYuvQlbt3PZXgV8fhtXmu2hOL JPbBP9sDP55x5+07FGVJHPV1l/c4QYOhEFYi4dy+oQWyYO0J9oL8qe6GT5EjK+upQ+sy sAIMoSBxU5hoPudZ4wTMhTiD7w40r05FB2pfqqPXRMnEdKA0L50iUFetPr6ZM2qgWDjF HnhtV2NqK3z6H8viGcZWTOYmFOBN0CxAgB7nSq61BbvBwgtVkPcCf4iOBp1PJh64XWxb Gs7Q== 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=LuKrGdsyJt363mkqnjfvHbulwnJ9TO1k3D/bFALSM6Q=; b=fefG5bB6TXXd5NQRpykQPRUNxZyzJXB+RiczElFE1hsu29q7v8Qo2ktVmFlPdSfxSI iHmNP3Y+Rc8DwNahwpvQlk0l8nCYyu8uSvodEmU3gsGh8wk86oAO0aUFS/U6T9pgA8zd WGqfXnjalTrHq1p76fpRQCnayjgIHLAaJd9lqZ6TDhoh+2FuBNHry3nH4BuU6GxUr0hs Y/gJf5MZjj0rww3MCm5u51R0UXAOiUwf1l6ZZlOkeGwty5Qdmp4jyrvWOh5Mxnpy/gHJ wSap1b7b7nCKz43g8WDil/lIhcAl8c/aC4iAapAv38O0vkOBWClm6R/uhVhw861lDtMC EejQ== X-Gm-Message-State: AOAM531qyLpicWTCLpk+h5VMCPlqpIJxwgMbQCHWVOgle//+FtP6W71K lk1JJGvi6GZhtXaiiZSAQho= X-Google-Smtp-Source: ABdhPJwXDOBq8wOZFlPoba1fs6Y0oquuokAQpP5cQY0aeDvPQ3lMxVJGG2HLpazYAGspfRPXVGz15Q== X-Received: by 2002:a63:6bc5:: with SMTP id g188mr14069494pgc.395.1592168585045; Sun, 14 Jun 2020 14:03:05 -0700 (PDT) Received: from sultan-box.localdomain ([89.45.90.111]) by smtp.gmail.com with ESMTPSA id d184sm1827746pfd.85.2020.06.14.14.03.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Jun 2020 14:03:04 -0700 (PDT) From: Sultan Alsawaf X-Google-Original-From: Sultan Alsawaf To: Aaron Ma , Andy Shevchenko , Benjamin Tissoires , Hans de Goede , HungNien Chen , Jarkko Nikula , Jiri Kosina , Kai-Heng Feng , linux-i2c@vger.kernel.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Mika Westerberg , Pavel Balan , Tin Huynh , Wolfram Sang , You-Sheng Yang Cc: Sultan Alsawaf Subject: [PATCH 2/2] HID: i2c-hid: Use block reads when possible to save power Date: Sun, 14 Jun 2020 14:02:55 -0700 Message-Id: <20200614210255.4641-3-sultan@kerneltoast.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200614210255.4641-1-sultan@kerneltoast.com> References: <20200614210255.4641-1-sultan@kerneltoast.com> MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@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 --- drivers/hid/i2c-hid/i2c-hid-core.c | 3 ++- 1 file changed, 2 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..4b507de48d70 100644 --- a/drivers/hid/i2c-hid/i2c-hid-core.c +++ b/drivers/hid/i2c-hid/i2c-hid-core.c @@ -476,7 +476,8 @@ static void i2c_hid_get_input(struct i2c_hid *ihid) if (size > ihid->bufsize) size = ihid->bufsize; - ret = i2c_master_recv(ihid->client, ihid->inbuf, size); + ret = i2c_transfer_buffer_flags(ihid->client, ihid->inbuf, size, + I2C_M_RD | I2C_M_RECV_LEN); if (ret != size) { if (ret < 0) return;