From patchwork Tue May 23 19:28:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 686080 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EFD21C7EE2E for ; Tue, 23 May 2023 19:32:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238408AbjEWTcF (ORCPT ); Tue, 23 May 2023 15:32:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238378AbjEWTcA (ORCPT ); Tue, 23 May 2023 15:32:00 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37EA3E4D for ; Tue, 23 May 2023 12:31:32 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1ae3f6e5d70so380905ad.1 for ; Tue, 23 May 2023 12:31:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1684870288; x=1687462288; 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=39PsOXs9zk855s8jQNy2CTlBaJON6A8TZDNhmmH/46Q=; b=GhI0C1TWak8+SbPb8fwi5YtahbPMUZ0q/xInXun3S9DYRbA5Ge3H9tdwPIREn6nwjE P0NSDWJJsCFsCfBimENA7d99Zzn2dZ0qOatCq9UiE4ucZ+9HBcsBrd0zPUL/yqHrtfyh UoSylkf8Zht+WYlD2AUIAy3mU3mfinXBoQVvM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684870288; x=1687462288; 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=39PsOXs9zk855s8jQNy2CTlBaJON6A8TZDNhmmH/46Q=; b=OwqBjO+Ruy1+qd29tqkC85Q6MR1xXLFYoI7q20la2boIXu3vlN/6GpCnD6Cu2xFlmG kw4UFuGW081dUdyamtVfqM7rw+JnSSVa+wsrqZEIS/chrzU3ysnWRNabj3XP8cLTD5Zm nMBmlKiEQsMNzJ/9hY2KAhwyfNZX16FaGOdDdxkmrmhI9SI5kUvsWIHBRbktEMzo/+d5 IRXuL0Ux2Ft6bDg0lu5eQUiP/Lo/dSMOAcZOxgJ6nfIUg40pttnR1Cx2Sy6e6CU1wYSe REdTEFDfVlzaNDdwkhpc9h+oN5Z11wv9F6t/DIq2+GPlWL2YxS/UOgoIt3bbu9ZkD1RR to9Q== X-Gm-Message-State: AC+VfDwTxQNmUFvIHmP8TfacrW55pbttyFhW98fpcRtcLqgQQ9oa/zqN Sh5QjIrshMJvaMFjPgVq6M+Ipg== X-Google-Smtp-Source: ACHHUZ4fsf7entq/TqQHyVWqJq0weOB/V/hoJn2umvRJrVqBR2ysA/a7Oxt/kBOm+TCRkfQxrBtHdQ== X-Received: by 2002:a17:902:ea08:b0:1af:cbb6:61ff with SMTP id s8-20020a170902ea0800b001afcbb661ffmr3900923plg.64.1684870287842; Tue, 23 May 2023 12:31:27 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:9d:2:af98:af9d:ed15:f8b3]) by smtp.gmail.com with ESMTPSA id y18-20020a170902b49200b001aaef9d0102sm7109947plr.197.2023.05.23.12.31.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 May 2023 12:31:27 -0700 (PDT) From: Douglas Anderson To: Jiri Kosina , Benjamin Tissoires , Bjorn Andersson , Konrad Dybcio , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Neil Armstrong , Sam Ravnborg , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann Cc: dri-devel@lists.freedesktop.org, linux-input@vger.kernel.org, Dmitry Torokhov , hsinyi@google.com, devicetree@vger.kernel.org, yangcong5@huaqin.corp-partner.google.com, linux-kernel@vger.kernel.org, Daniel Vetter , linux-arm-msm@vger.kernel.org, cros-qcom-dts-watchers@chromium.org, Douglas Anderson Subject: [PATCH 8/9] HID: i2c-hid: Do panel follower work on the system_wq Date: Tue, 23 May 2023 12:28:02 -0700 Message-ID: <20230523122802.8.I962bb462ede779005341c49320740ed95810021d@changeid> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog In-Reply-To: <20230523193017.4109557-1-dianders@chromium.org> References: <20230523193017.4109557-1-dianders@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org 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 --- drivers/hid/i2c-hid/i2c-hid-core.c | 42 +++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/drivers/hid/i2c-hid/i2c-hid-core.c b/drivers/hid/i2c-hid/i2c-hid-core.c index f1bb89377e8d..800f0dc6f6cf 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 @@ int i2c_hid_core_initial_power_up(struct i2c_hid *ihid) return ret; } -int i2c_hid_core_panel_prepared(struct drm_panel_follower *follower) +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,44 @@ 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); + + /* Match with i2c_hid_core_panel_unpreparing() */ + smp_wmb(); +} + +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; } 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 +1157,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