Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1198412ybt; Sun, 14 Jun 2020 14:05:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzg4fOzUzhBUOy13N9bWo3NwmWuM3MtjyV6o3aYIji1MU9aorzP+mcH64VyPwYrdk7zbEGW X-Received: by 2002:a17:906:3282:: with SMTP id 2mr22014694ejw.93.1592168738453; Sun, 14 Jun 2020 14:05:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592168738; cv=none; d=google.com; s=arc-20160816; b=YSX0OSxsEtMhyAhW+m7NjxGTctEe9Gm8uKH2flH1ZJen52QoadKmid5/zvFRWXKxPU UIUKIh/ULvHSQEeYecz9quyLL6ub4SC+b2iu6OP+vN2puSBaDPNGj85004R2rmqNUK5s g+4ddQeriIR4Kp7VKF5cf3GyadFBR1xIthSvUZ0TpwZDbW2h1KizqmAj/oYuNxagY8Y3 qfAZhoJHUg39btK/gNIlp4SQcc0qtvexQt2EiitPtWvAishk5XZcKKtaXVHZzhm3HD6u fALkFZzg2nUFXaGy7ACKE7M1IQ0ICW62CEBJ2ex+s3GkLeVuuudW9d6bfIohS62pqolh Mngw== 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=LuKrGdsyJt363mkqnjfvHbulwnJ9TO1k3D/bFALSM6Q=; b=S01bfrQ4nN7uo8BpeNZxPWFQE7bLPFpjFHhmb/lzkTziP3wdecen/Nt3qHFlCKg7PP cuZOG2T/CxMCkRBYQpAQoGbAqi8SY6mii3BvuPxT2LAPxJlYPrXF4EY1OrhkLjCowPS3 n2YYtP0NfvAyO+fGD6CwJqFc4/Ue+qYv7ATB1Nqr90YpGOzyhSqKNYTNc29NT42BZdmK zkhlRYgIJuDd5G5uJJSW3+6Thhl65AdQznis874VQs7tUxK3+tw9Hh2rB4NutOH2OULp 96RKBLwp4JetDto8DLWz9R+9stQ9wNA7jf/FYPYmdoby6FbXIjf8P4VoAIoM226J9hSg gDcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=M1v4894O; 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 j14si7788656edy.342.2020.06.14.14.05.16; Sun, 14 Jun 2020 14:05:38 -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=M1v4894O; 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 S1727929AbgFNVDJ (ORCPT + 99 others); Sun, 14 Jun 2020 17:03:09 -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-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 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 --- 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; -- 2.27.0