From patchwork Wed Jun 7 21:49:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 104738 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp504149vqr; Wed, 7 Jun 2023 14:55:03 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6sAJr4e8vEuSYKuG6fFIgJyLUFZ7cOXacpJ/jfvQXUXEKQbIFJXtj9SuYHXojeBG/qav4m X-Received: by 2002:a17:903:181:b0:1b0:276f:b26c with SMTP id z1-20020a170903018100b001b0276fb26cmr5217775plg.56.1686174902639; Wed, 07 Jun 2023 14:55:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686174902; cv=none; d=google.com; s=arc-20160816; b=t/qmjww+TJLH2Mc/mGJ2Oh6pUnUgqek5Y+d1GMPAyFTs8P4B9wpqw/h/kPN6bflKuk IgcnnF6GOizSgRrjPeMSI0YaMCclZnPYOWpPDOuCWeSLKo1DqPJTml4odEXACA1B0zPf WhIymGS8f33XwqwXwiWoMmtn1JFVJhDx+YQuKx9D06jjyPjLcVNnQiPNyegBDM8/Ae/N uzzWwpV0wnRlvCK/RpA9CcdDvpIxzcYbTefCnKnZyjfZ2I0R0RsC35vYEuVnNVUH5V0S +ao4MytYFwLhnsVpmEuvHp0RPe2bjAnwCYyG4dCgZWlf9+dr2upBajD7BEpPYXMu4ngq bWfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/h3em+INtG/UUK+PVeHaRGBuj9ZpztA48bg5EQZ3MT0=; b=l7EfE3v0684s0V0GiFaGqJbqPqrBqyyOLgtIcNDOATHpSB5kg1uYu3uatqV9yKZ6hE xVDaur8gWrg05kqrigk9Bt6dmApQfzo/HAONYKcR3mJVUfQFowOSJ+6aD56MU7tmZToV S6f5rGZpzHixKDUcTiR7s7wVPs40iweK+9931KPIukPVlRUMj0WCowkfPrvpt91qC0DT PlS9AsIpbdw/SRrmDs8R2xRBTGvrlPuYC3cWVnRty+IAfBYg3A9YTl8PC1nKkmyDgY1y YSOf8QpJW/7sKejpgrLoficnQsSUrObrOMdI+yhEXS8iBVNgfUX0p37/cIuGOMqb7Jv9 x9bQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ZLvHLs5d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u11-20020a170902e80b00b001ab29e00303si9752202plg.426.2023.06.07.14.54.51; Wed, 07 Jun 2023 14:55:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ZLvHLs5d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231500AbjFGVx6 (ORCPT + 99 others); Wed, 7 Jun 2023 17:53:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232508AbjFGVxl (ORCPT ); Wed, 7 Jun 2023 17:53:41 -0400 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D77A1FD6 for ; Wed, 7 Jun 2023 14:53:28 -0700 (PDT) Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-651f2f38634so7540564b3a.0 for ; Wed, 07 Jun 2023 14:53:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1686174808; x=1688766808; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/h3em+INtG/UUK+PVeHaRGBuj9ZpztA48bg5EQZ3MT0=; b=ZLvHLs5dOG1TPeYaxiFduJxz8FK7pBX6sxRTCg/aZwKCYFUfiL/X+PjM+I+zkpuBg+ V4fm2g2tewmOP3Nh+pNQNONSWT+TeKp9T5CjDmiibi6Ocgeaf+CVEG6fw3DEZI8uSS2W uF7dxpJegMiAAH0b2T/da7cBn3i7m7zQ37p8Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686174808; x=1688766808; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/h3em+INtG/UUK+PVeHaRGBuj9ZpztA48bg5EQZ3MT0=; b=Rh6gFoMumuxXfre0M8YqNXYag3G/F7AeaQ1bmMXKv2a8xou1GWDRSh2FH7tHaYFmCw Fc0n9GnwlWw1uQBOOf5CAJskzpEYmHz6VzR98mcXg59otgWvQ4t7cZkMPPy+QVnu88hZ itmnx0pQMbw4k0YEGp9PMfNSallPmOLzHfcwSTV2z5/9FnuiIm30tiag4gii99sap+u1 T1IUj2mx/uRao2v1g1oXEAXcXvm1OnJ6hgzZk11jvV645vputPY8nynZcb6yWy0ZU8wM na7HVXziXiwRwetnYYELIje5T9Y/AhwsoD6sNiWe9AKi6w+75OAtffKEN2mat9FX5VJW 5Aow== X-Gm-Message-State: AC+VfDxvzVpMTrQ1AFu8uQPsG26Z4XixmEQBHaehFuVzcZsIEyqipuny QjHUJTTLnlVuHcL9FOHlpK5lhw== X-Received: by 2002:a05:6a20:3d92:b0:118:b2e1:9adb with SMTP id s18-20020a056a203d9200b00118b2e19adbmr504121pzi.61.1686174807950; Wed, 07 Jun 2023 14:53:27 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:9d:2:34b2:b638:6b53:f6c2]) by smtp.gmail.com with ESMTPSA id j25-20020aa78d19000000b0065dd1e7c2c1sm1376486pfe.63.2023.06.07.14.53.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jun 2023 14:53:27 -0700 (PDT) From: Douglas Anderson To: Jiri Kosina , Benjamin Tissoires , Bjorn Andersson , Konrad Dybcio , Rob Herring , Frank Rowand , Krzysztof Kozlowski , Conor Dooley , Neil Armstrong , Sam Ravnborg , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann Cc: dri-devel@lists.freedesktop.org, Dmitry Torokhov , linux-input@vger.kernel.org, Daniel Vetter , linux-kernel@vger.kernel.org, hsinyi@google.com, cros-qcom-dts-watchers@chromium.org, devicetree@vger.kernel.org, yangcong5@huaqin.corp-partner.google.com, linux-arm-msm@vger.kernel.org, Chris Morgan , Douglas Anderson Subject: [PATCH v2 09/10] HID: i2c-hid: Do panel follower work on the system_wq Date: Wed, 7 Jun 2023 14:49:31 -0700 Message-ID: <20230607144931.v2.9.I962bb462ede779005341c49320740ed95810021d@changeid> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog In-Reply-To: <20230607215224.2067679-1-dianders@chromium.org> References: <20230607215224.2067679-1-dianders@chromium.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768082534556347350?= X-GMAIL-MSGID: =?utf-8?q?1768082534556347350?= Turning on an i2c-hid device can be a slow process. This is why i2c-hid devices use PROBE_PREFER_ASYNCHRONOUS. Unfortunately, when we're a panel follower the i2c-hid power up sequence now blocks the power on of the panel. Let's fix that by scheduling the work on the system_wq. Signed-off-by: Douglas Anderson --- Changes in v2: - ihid_core_panel_prepare_work() is now static. - Improve documentation for smp_wmb(). drivers/hid/i2c-hid/i2c-hid-core.c | 50 +++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/drivers/hid/i2c-hid/i2c-hid-core.c b/drivers/hid/i2c-hid/i2c-hid-core.c index 368db3ae612f..de1a0624be08 100644 --- a/drivers/hid/i2c-hid/i2c-hid-core.c +++ b/drivers/hid/i2c-hid/i2c-hid-core.c @@ -110,7 +110,9 @@ struct i2c_hid { struct i2chid_ops *ops; struct drm_panel_follower panel_follower; + struct work_struct panel_follower_prepare_work; bool is_panel_follower; + bool prepare_work_finished; }; static const struct i2c_hid_quirks { @@ -1062,10 +1064,12 @@ static int i2c_hid_core_initial_power_up(struct i2c_hid *ihid) return ret; } -static int i2c_hid_core_panel_prepared(struct drm_panel_follower *follower) +static void ihid_core_panel_prepare_work(struct work_struct *work) { - struct i2c_hid *ihid = container_of(follower, struct i2c_hid, panel_follower); + struct i2c_hid *ihid = container_of(work, struct i2c_hid, + panel_follower_prepare_work); struct hid_device *hid = ihid->hid; + int ret; /* * hid->version is set on the first power up. If it's still zero then @@ -1073,15 +1077,52 @@ static int i2c_hid_core_panel_prepared(struct drm_panel_follower *follower) * steps. */ if (!hid->version) - return i2c_hid_core_initial_power_up(ihid); + ret = i2c_hid_core_initial_power_up(ihid); + else + ret = i2c_hid_core_resume(ihid); - return i2c_hid_core_resume(ihid); + if (ret) + dev_warn(&ihid->client->dev, "Power on failed: %d\n", ret); + else + WRITE_ONCE(ihid->prepare_work_finished, true); + + /* + * The work APIs provide a number of memory ordering guarantees + * including one that says that memory writes before schedule_work() + * are always visible to the work function, but they don't appear to + * guarantee that a write that happened in the work is visible after + * cancel_work_sync(). We'll add a write memory barrier here to match + * with i2c_hid_core_panel_unpreparing() to ensure that our write to + * prepare_work_finished is visible there. + */ + smp_wmb(); +} + +static int i2c_hid_core_panel_prepared(struct drm_panel_follower *follower) +{ + struct i2c_hid *ihid = container_of(follower, struct i2c_hid, panel_follower); + + /* + * Powering on a touchscreen can be a slow process. Queue the work to + * the system workqueue so we don't block the panel's power up. + */ + WRITE_ONCE(ihid->prepare_work_finished, false); + schedule_work(&ihid->panel_follower_prepare_work); + + return 0; } static int i2c_hid_core_panel_unpreparing(struct drm_panel_follower *follower) { struct i2c_hid *ihid = container_of(follower, struct i2c_hid, panel_follower); + cancel_work_sync(&ihid->panel_follower_prepare_work); + + /* Match with ihid_core_panel_prepare_work() */ + smp_rmb(); + if (!READ_ONCE(ihid->prepare_work_finished)) + return 0; + return i2c_hid_core_suspend(ihid); } @@ -1124,6 +1165,7 @@ int i2c_hid_core_probe(struct i2c_client *client, struct i2chid_ops *ops, init_waitqueue_head(&ihid->wait); mutex_init(&ihid->reset_lock); + INIT_WORK(&ihid->panel_follower_prepare_work, ihid_core_panel_prepare_work); /* we need to allocate the command buffer without knowing the maximum * size of the reports. Let's use HID_MIN_BUFFER_SIZE, then we do the