Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1832099rwd; Fri, 9 Jun 2023 02:53:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7uyLPho3OBIseX1mmEgIu4Q9BbLItELOHYOBcLw1WfKLqD/LSQ1eqZ2HDarC2LiEuBLo52 X-Received: by 2002:a17:90b:4f8a:b0:258:ddc3:3efb with SMTP id qe10-20020a17090b4f8a00b00258ddc33efbmr847766pjb.10.1686304421001; Fri, 09 Jun 2023 02:53:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686304420; cv=none; d=google.com; s=arc-20160816; b=tvVKqpuqfUIsP0rt9F1oLhmATZwH5OnOfg9I+y/6esJwy+3VIZPGIiSuSp8PvsQQF3 BZ5m5AcGb3slOBa2adSOd13RFDv6j+geQUVKiuadeJFCkQEql4wnJXJgBJ96eaVVnWki hWe1UAR8DFltc6kYOwIK/s2YZXxqbkkE83NZjJrSdTMkkfN/Ksdyqq53mb9n+0CXzPbW l5jn+fxCQr7LY/UI77iYvu3amm9BdJnYcjOfHcwKpWCado2C2w9bg+OFImjJQ5E0gY+q hyuxrIOgUBkSisQHCwGpOUsUjhq3zileJqGe6TYEE9FbybfF5C5ilgEgREmcdPJRTlus MD0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=pmcy3J55zT63aAIMqIuRpUjqhj86xl68Bl2D1HlN7pE=; b=exNZ2tgSe77NBio9zXiqi4/my9DISMx1cEwe8enAsaT62icb5fNH1gmJPymLbGVlge uJojYFYynqRQKxzTGAUjOFTDZ73QETZ+VUHZO9oT6+7pQZ/tlvHcPENCedj05twiBzuj 6hijLDLC29GU8xGCUEtKKO3IMBE5m7JalcKcnalWMciTryvSXNUHOOjs/5mJsrJBZw74 VtNL3q9wuxro+fx38CErnxiJRaUh3N4naAQ/k+ARwV97nb+nkwcAcu0nedEoqmMmtWnO cR2iQsGYJWwWbANRkRMdV9us6dEFkdudF/THEY4AR1z3+8/2T3d2/VlKuujiHS3UabGA JauQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="Q7TET2/m"; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e10-20020a17090a728a00b00257a8dc0348si2523659pjg.75.2023.06.09.02.53.29; Fri, 09 Jun 2023 02:53:40 -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=@redhat.com header.s=mimecast20190719 header.b="Q7TET2/m"; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241626AbjFIJeh (ORCPT + 99 others); Fri, 9 Jun 2023 05:34:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241642AbjFIJeH (ORCPT ); Fri, 9 Jun 2023 05:34:07 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3BB576B0 for ; Fri, 9 Jun 2023 02:27:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686302863; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pmcy3J55zT63aAIMqIuRpUjqhj86xl68Bl2D1HlN7pE=; b=Q7TET2/mXXEDVuFkiFkarQ7wJSTNitqsK9cxo1V4vNtytDzplLzkD3DGmUuoL4Ugl05eGx LSry6JMUiqTcVgykg1jldaJlJvWXAkHBHMhyNoFb2yg/yajcPHFqCEXwbFkZbAiAT8wGtG NwY6UYUc1ZIf6O96Arwmp4oXvMo165s= Received: from mail-yw1-f198.google.com (mail-yw1-f198.google.com [209.85.128.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-625-o8LG9R8nOXir4v5aMD9_-Q-1; Fri, 09 Jun 2023 05:27:40 -0400 X-MC-Unique: o8LG9R8nOXir4v5aMD9_-Q-1 Received: by mail-yw1-f198.google.com with SMTP id 00721157ae682-5693861875fso22905577b3.1 for ; Fri, 09 Jun 2023 02:27:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686302859; x=1688894859; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pmcy3J55zT63aAIMqIuRpUjqhj86xl68Bl2D1HlN7pE=; b=FMC+qdcl4uRfQEiw3s0+IeLN+SE7Nl/ZsGqAO3CnZfGXrpLreCYogqGv3TqkSLLmT0 uU8RrUjw7hnU+/V1RcSV7QXCfog7YxZra3JqB68lDM92ZWBLzPlALqP+sEKAtINOXA8x DotsdLRJy4giOuUzeT42ClNHZeJvneuH6y0trE0TLXnnDypEHJ+dLaoHu3jKt9djhSxw LpJWmPDYUXtI6TUQcLdhOw8EGDCmKTjyRsGbnTLr+FwsxHNjMXY0/9WBy4p4X3bg0Nrp FDSvSFuOazmCAUZRWXAfWzBRFq3LBX41+6n+TLYKpzdxA/W7PSpJfVPjbPE7TqIp+t74 utQw== X-Gm-Message-State: AC+VfDw6fUdsAncMPU6vso4uiOpnWYx8vaNKYUaEnEEEhEx37KLdE65T hufOXEoJkeVNgrFTKoU3Y0NDm9LlynkYxF6283GaP4mF4beAfFFK8vrCJIqHT2+uTPm44h4F3Dj eSt8QhAWRozG0V98GVJQg51DXBeknULufH8TsRD2X X-Received: by 2002:a81:8397:0:b0:561:8fef:13ce with SMTP id t145-20020a818397000000b005618fef13cemr723940ywf.37.1686302859564; Fri, 09 Jun 2023 02:27:39 -0700 (PDT) X-Received: by 2002:a81:8397:0:b0:561:8fef:13ce with SMTP id t145-20020a818397000000b005618fef13cemr723918ywf.37.1686302859245; Fri, 09 Jun 2023 02:27:39 -0700 (PDT) MIME-Version: 1.0 References: <20230607215224.2067679-1-dianders@chromium.org> <20230607144931.v2.8.Ib1a98309c455cd7e26b931c69993d4fba33bbe15@changeid> In-Reply-To: From: Benjamin Tissoires Date: Fri, 9 Jun 2023 11:27:27 +0200 Message-ID: Subject: Re: [PATCH v2 08/10] HID: i2c-hid: Support being a panel follower To: Doug Anderson Cc: Jiri Kosina , Bjorn Andersson , Konrad Dybcio , Rob Herring , Frank Rowand , Krzysztof Kozlowski , Conor Dooley , Neil Armstrong , Sam Ravnborg , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 On Thu, Jun 8, 2023 at 6:43=E2=80=AFPM Doug Anderson wrote: > > Hi, > > On Thu, Jun 8, 2023 at 8:37=E2=80=AFAM Benjamin Tissoires > wrote: > > > > > > On Jun 07 2023, Douglas Anderson wrote: > > > > > > As talked about in the patch ("drm/panel: Add a way for other devices > > > to follow panel state"), we really want to keep the power states of a > > > touchscreen and the panel it's attached to in sync with each other. I= n > > > that spirit, add support to i2c-hid to be a panel follower. This will > > > let the i2c-hid driver get informed when the panel is powered on and > > > off. From there we can match the i2c-hid device's power state to that > > > of the panel. > > > > > > NOTE: this patch specifically _doesn't_ use pm_runtime to keep track > > > of / manage the power state of the i2c-hid device, even though my > > > first instinct said that would be the way to go. Specific problems > > > with using pm_runtime(): > > > * The initial power up couldn't happen in a runtime resume function > > > since it create sub-devices and, apparently, that's not good to do > > > in your resume function. > > > * Managing our power state with pm_runtime meant fighting to make the > > > right thing happen at system suspend to prevent the system from > > > trying to resume us only to suspend us again. While this might be > > > able to be solved, it added complexity. > > > Overall the code without pm_runtime() ended up being smaller and > > > easier to understand. > > > > Generally speaking, I'm not that happy when we need to coordinate with > > other subsystems for bringing up resources... > > Yeah, I'd agree that it's not amazingly elegant. Unfortunately, I > couldn't find any existing clean frameworks that would do what was > needed, which is (presumably) why this problem hasn't been solved > before. I could try to come up with a grand abstraction / new > framework, but that doesn't seem like a great choice either unless we > expect more users... > > > > Anyway, a remark inlined (at least): > > > > > > > > Signed-off-by: Douglas Anderson > > > --- > > > > > > Changes in v2: > > > - i2c_hid_core_panel_prepared() and ..._unpreparing() are now static. > > > > > > drivers/hid/i2c-hid/i2c-hid-core.c | 82 ++++++++++++++++++++++++++++= +- > > > 1 file changed, 81 insertions(+), 1 deletion(-) > > > > > > diff --git a/drivers/hid/i2c-hid/i2c-hid-core.c b/drivers/hid/i2c-hid= /i2c-hid-core.c > > > index fa8a1ca43d7f..368db3ae612f 100644 > > > --- a/drivers/hid/i2c-hid/i2c-hid-core.c > > > +++ b/drivers/hid/i2c-hid/i2c-hid-core.c > > > @@ -38,6 +38,8 @@ > > > #include > > > #include > > > > > > +#include > > > + > > > #include "../hid-ids.h" > > > #include "i2c-hid.h" > > > > > > @@ -107,6 +109,8 @@ struct i2c_hid { > > > struct mutex reset_lock; > > > > > > struct i2chid_ops *ops; > > > + struct drm_panel_follower panel_follower; > > > + bool is_panel_follower; > > > }; > > > > > > static const struct i2c_hid_quirks { > > > @@ -1058,6 +1062,34 @@ static int i2c_hid_core_initial_power_up(struc= t i2c_hid *ihid) > > > return ret; > > > } > > > > > > +static int i2c_hid_core_panel_prepared(struct drm_panel_follower *fo= llower) > > > +{ > > > + struct i2c_hid *ihid =3D container_of(follower, struct i2c_hid,= panel_follower); > > > + struct hid_device *hid =3D ihid->hid; > > > + > > > + /* > > > + * hid->version is set on the first power up. If it's still zer= o then > > > + * this is the first power on so we should perform initial powe= r up > > > + * steps. > > > + */ > > > + if (!hid->version) > > > + return i2c_hid_core_initial_power_up(ihid); > > > + > > > + return i2c_hid_core_resume(ihid); > > > +} > > > + > > > +static int i2c_hid_core_panel_unpreparing(struct drm_panel_follower = *follower) > > > +{ > > > + struct i2c_hid *ihid =3D container_of(follower, struct i2c_hid,= panel_follower); > > > + > > > + return i2c_hid_core_suspend(ihid); > > > +} > > > + > > > +static const struct drm_panel_follower_funcs i2c_hid_core_panel_foll= ower_funcs =3D { > > > + .panel_prepared =3D i2c_hid_core_panel_prepared, > > > + .panel_unpreparing =3D i2c_hid_core_panel_unpreparing, > > > +}; > > > > Can we make that above block at least behind a Kconfig? > > > > i2c-hid is often used for touchpads, and the notion of drm panel has > > nothing to do with them. So I'd be more confident if we could disable > > that code if not required. > > Happy to put it behind a Kconfig. I'll plan on that for v3. I'll stub > the functions out if there is no Kconfig, but plan to still leave > structure members just to avoid uglifying the sources too much. > > > > Actually, I'd be even more happier if it were in a different compilatio= n > > unit. Not necessary a different module, but at least a different file. > > I suspect that it's not worth it, but I'll do this if you feel > strongly about it. > > I guess the simplest way I can think of to move this to its own file > would be to put the whole private data structure (struct i2c_hid) in a > private header file and then add prototypes for i2c_hid_core_resume() > and i2c_hid_core_suspend() there. Then I could add something like > i2c_hid_core_handle_panel_follower() that would have all the > registration logic. I'd still need special cases in the core > suspend/resume/remove code unless I add a level of abstraction. While > the level of abstraction is more "pure", it also would make the code > harder to follow. > > Unless I hear a strong opinion (or if this series changes > significantly), I'll plan to keep things in the same file and just use > a Kconfig. > Right, a separate file might not be the best then :( Do you envision this to be used on the ACPI side of i2c-hid? Because if this is OF only, then maybe it would be interesting to put it there (in i2c-hid-of.c), instead of having it in the core. IIRC i2c-hid-of also has ways to set up/down regulators, so maybe it'll be better there? Cheers, Benjamin