Message ID | 20230607144931.v2.8.Ib1a98309c455cd7e26b931c69993d4fba33bbe15@changeid |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp513495vqr; Wed, 7 Jun 2023 15:11:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7Xe5+a9k3WwjFWRW4u7+VBtAYor1EfYG/YPTqi0iOkF1Z850ce2IAlZz4ciG/8//WZtRlJ X-Received: by 2002:a05:6a00:23c4:b0:65e:d5da:b3c6 with SMTP id g4-20020a056a0023c400b0065ed5dab3c6mr6750192pfc.7.1686175905085; Wed, 07 Jun 2023 15:11:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686175905; cv=none; d=google.com; s=arc-20160816; b=ZKGu4B0NbCxSqdBSh4NhJngU5igkIkOvwSrme5Jb60jwXMHkSvGj1NwKgLn5vCMRo4 Sob6nIr4+792d0ypT0WNXw1l2Au75Rx28BSPbJUE5WPiqiTcQojperqpl+IO92iGI/MK AYMiTTzaMDHwlmMQw9w12hfTqFDatixEEj7YRiIRUq3Hw0JiT4R7gXE0GIzYgAE4aELi 9y8zgMUWLBEkez7Ge4Kd188mvYRDlMpyrMP5vrvJKrwIOMQp/8HFcd5Cdb9iRLrii5ZW ya7uP2Re1gVyn0Kbn0gQzUZ34BvYYqDYezWCObkP8l9EDaGjp2t5wHS705uMChwAuLF7 ggNA== 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=+rHz1jZnjpSiv5HKR2V1CEWNHmLWqUe5SsAOtRVLc3E=; b=EZt8So16gbwkVEpSn5liT+3gvtUxaJt+2qJyEASv63FepQYE9GmLFBFcJq9QMAtG3l 63/QtTOKJvGcBKhnFiIQMf3yRBrpalHMzzkUfo7DN39vPGIQR46IVlvbkZ/j4paTQjkC 8LQHyLSAahO1XnTYFHyxx9KUC2VXtVt6wCKFGhX2Aa1/qqmP0AZc0CwmKESZcBPYKDlL CvFsffjbvAyp6rZpmw+74P//+y7/OCO6htrlacOACiVCqJ11f03ggJy89DwzzitNBoJh 2h6mE00c7xa7MXBiaIR3EVVL7xaqYWfMY+G/nXsI9bEK8suuZ5hEOEI1EQ869wHrPEnu o50w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=hdbjyXWz; 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 h4-20020aa79f44000000b0064f7150b45bsi9123624pfr.352.2023.06.07.15.11.25; Wed, 07 Jun 2023 15:11:45 -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=hdbjyXWz; 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 S229730AbjFGVxx (ORCPT <rfc822;literming00@gmail.com> + 99 others); Wed, 7 Jun 2023 17:53:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232140AbjFGVx2 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 7 Jun 2023 17:53:28 -0400 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D8BB2132 for <linux-kernel@vger.kernel.org>; Wed, 7 Jun 2023 14:53:26 -0700 (PDT) Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-651ffcc1d3dso4721511b3a.3 for <linux-kernel@vger.kernel.org>; Wed, 07 Jun 2023 14:53:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1686174805; x=1688766805; 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=+rHz1jZnjpSiv5HKR2V1CEWNHmLWqUe5SsAOtRVLc3E=; b=hdbjyXWzHfwxcUwfwb+qucn8Y1kzJgDBVnByK1lmUyw+Rig23C+S4Y6GODf2Asa3Rj 9LFMI+tJIkfnSgqmixDuthZjEXGWhYiiE9sj2Kk1wy9zu2bWc/lao9ZXaAP0IItUKllQ EP4VvisdXYOA1Pwgd8nvslaeA7bwp/nRScBzc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686174805; x=1688766805; 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=+rHz1jZnjpSiv5HKR2V1CEWNHmLWqUe5SsAOtRVLc3E=; b=i+Odt7Glmwm58DebFJpY0OjkB9S8k0eyOTwJwkjMdl+kjFGBoozd7GfV3rIjGqvtli kgxors+6/OECnyQagknjZqDuoCsg+vCHYrVG/1Ls7WMomAcpI96zPITV9u8NgCPYxbU2 DJ+zm8881j2n8t0z+xArTsmeoW5S1qlbj8iRjcGwNGbXPjx+wN4YkfohPbUrYeZFYO9X 9KpVCN610v9ab5l/neaP3/DJtnRnzJLkyn7BogM1n6izARq9ur3OAPsDhDTE5RR7SEOS Q6SofFe9HcqHit8rj1rXUL9qBkQLCekQoiEcbCfhlKulDWDl8tpP5lJq6DUda0LVtiE0 8DYA== X-Gm-Message-State: AC+VfDzSOzAR7hSIrrTjkYP6BOZJg9SgtseeuEwSMWznp2+Uhp7t60fs 5rs40C24UttsjvZjGjQ+zuKemA== X-Received: by 2002:a05:6a00:114e:b0:643:98cb:ec1 with SMTP id b14-20020a056a00114e00b0064398cb0ec1mr5634126pfm.0.1686174805605; Wed, 07 Jun 2023 14:53:25 -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.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jun 2023 14:53:25 -0700 (PDT) From: Douglas Anderson <dianders@chromium.org> To: Jiri Kosina <jikos@kernel.org>, Benjamin Tissoires <benjamin.tissoires@redhat.com>, Bjorn Andersson <andersson@kernel.org>, Konrad Dybcio <konrad.dybcio@linaro.org>, Rob Herring <robh+dt@kernel.org>, Frank Rowand <frowand.list@gmail.com>, Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>, Conor Dooley <conor+dt@kernel.org>, Neil Armstrong <neil.armstrong@linaro.org>, Sam Ravnborg <sam@ravnborg.org>, Maarten Lankhorst <maarten.lankhorst@linux.intel.com>, Maxime Ripard <mripard@kernel.org>, Thomas Zimmermann <tzimmermann@suse.de> Cc: dri-devel@lists.freedesktop.org, Dmitry Torokhov <dmitry.torokhov@gmail.com>, linux-input@vger.kernel.org, Daniel Vetter <daniel@ffwll.ch>, 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 <macroalpha82@gmail.com>, Douglas Anderson <dianders@chromium.org> Subject: [PATCH v2 08/10] HID: i2c-hid: Support being a panel follower Date: Wed, 7 Jun 2023 14:49:30 -0700 Message-ID: <20230607144931.v2.8.Ib1a98309c455cd7e26b931c69993d4fba33bbe15@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 Content-Transfer-Encoding: 8bit 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768083585944767139?= X-GMAIL-MSGID: =?utf-8?q?1768083585944767139?= |
Series |
drm/panel and i2c-hid: Allow panels and touchscreens to power sequence together
|
|
Commit Message
Doug Anderson
June 7, 2023, 9:49 p.m. UTC
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. In
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.
Signed-off-by: Douglas Anderson <dianders@chromium.org>
---
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(-)
Comments
Hi Douglas, kernel test robot noticed the following build errors: [auto build test ERROR on robh/for-next] [also build test ERROR on hid/for-next dtor-input/next dtor-input/for-linus] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Douglas-Anderson/dt-bindings-HID-i2c-hid-Add-panel-property-to-i2c-hid-backed-touchscreens/20230608-055515 base: https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next patch link: https://lore.kernel.org/r/20230607144931.v2.8.Ib1a98309c455cd7e26b931c69993d4fba33bbe15%40changeid patch subject: [PATCH v2 08/10] HID: i2c-hid: Support being a panel follower config: arc-randconfig-r021-20230607 (https://download.01.org/0day-ci/archive/20230608/202306081344.M0jNn0Ce-lkp@intel.com/config) compiler: arceb-elf-gcc (GCC) 12.3.0 reproduce (this is a W=1 build): mkdir -p ~/bin wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross git remote add robh https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git git fetch robh for-next git checkout robh/for-next b4 shazam https://lore.kernel.org/r/20230607144931.v2.8.Ib1a98309c455cd7e26b931c69993d4fba33bbe15@changeid # save the config file mkdir build_dir && cp config build_dir/.config COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.3.0 ~/bin/make.cross W=1 O=build_dir ARCH=arc olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.3.0 ~/bin/make.cross W=1 O=build_dir ARCH=arc SHELL=/bin/bash If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202306081344.M0jNn0Ce-lkp@intel.com/ All errors (new ones prefixed by >>): `.exit.text' referenced in section `__jump_table' of lib/test_dynamic_debug.o: defined in discarded section `.exit.text' of lib/test_dynamic_debug.o `.exit.text' referenced in section `__jump_table' of lib/test_dynamic_debug.o: defined in discarded section `.exit.text' of lib/test_dynamic_debug.o `.exit.text' referenced in section `__jump_table' of drivers/misc/phantom.o: defined in discarded section `.exit.text' of drivers/misc/phantom.o `.exit.text' referenced in section `__jump_table' of drivers/misc/phantom.o: defined in discarded section `.exit.text' of drivers/misc/phantom.o `.exit.text' referenced in section `__jump_table' of drivers/target/target_core_configfs.o: defined in discarded section `.exit.text' of drivers/target/target_core_configfs.o `.exit.text' referenced in section `__jump_table' of drivers/target/target_core_configfs.o: defined in discarded section `.exit.text' of drivers/target/target_core_configfs.o arceb-elf-ld: drivers/hid/i2c-hid/i2c-hid-core.o: in function `i2c_hid_core_remove': drivers/hid/i2c-hid/i2c-hid-core.c:1218: undefined reference to `drm_panel_remove_follower' >> arceb-elf-ld: drivers/hid/i2c-hid/i2c-hid-core.c:1218: undefined reference to `drm_panel_remove_follower' arceb-elf-ld: drivers/hid/i2c-hid/i2c-hid-core.o: in function `i2c_hid_core_probe': drivers/hid/i2c-hid/i2c-hid-core.c:1159: undefined reference to `drm_panel_add_follower' >> arceb-elf-ld: drivers/hid/i2c-hid/i2c-hid-core.c:1159: undefined reference to `drm_panel_add_follower'
Hi Douglas, kernel test robot noticed the following build errors: [auto build test ERROR on robh/for-next] [also build test ERROR on hid/for-next dtor-input/next dtor-input/for-linus drm-misc/drm-misc-next linus/master v6.4-rc5 next-20230607] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Douglas-Anderson/dt-bindings-HID-i2c-hid-Add-panel-property-to-i2c-hid-backed-touchscreens/20230608-055515 base: https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next patch link: https://lore.kernel.org/r/20230607144931.v2.8.Ib1a98309c455cd7e26b931c69993d4fba33bbe15%40changeid patch subject: [PATCH v2 08/10] HID: i2c-hid: Support being a panel follower config: i386-randconfig-i003-20230607 (https://download.01.org/0day-ci/archive/20230608/202306081419.Dzz0T4iW-lkp@intel.com/config) compiler: clang version 15.0.7 (https://github.com/llvm/llvm-project.git 8dfdcc7b7bf66834a761bd8de445840ef68e4d1a) reproduce (this is a W=1 build): mkdir -p ~/bin wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross git remote add robh https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git git fetch robh for-next git checkout robh/for-next b4 shazam https://lore.kernel.org/r/20230607144931.v2.8.Ib1a98309c455cd7e26b931c69993d4fba33bbe15@changeid # save the config file mkdir build_dir && cp config build_dir/.config COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang ~/bin/make.cross W=1 O=build_dir ARCH=i386 olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang ~/bin/make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202306081419.Dzz0T4iW-lkp@intel.com/ All errors (new ones prefixed by >>): >> ld.lld: error: undefined symbol: drm_panel_add_follower >>> referenced by i2c-hid-core.c:1159 (drivers/hid/i2c-hid/i2c-hid-core.c:1159) >>> drivers/hid/i2c-hid/i2c-hid-core.o:(i2c_hid_core_probe) in archive vmlinux.a -- >> ld.lld: error: undefined symbol: drm_panel_remove_follower >>> referenced by i2c-hid-core.c:1218 (drivers/hid/i2c-hid/i2c-hid-core.c:1218) >>> drivers/hid/i2c-hid/i2c-hid-core.o:(i2c_hid_core_remove) in archive vmlinux.a
Hi, On Thu, Jun 8, 2023 at 12:15 AM kernel test robot <lkp@intel.com> wrote: > > Hi Douglas, > > kernel test robot noticed the following build errors: > > [auto build test ERROR on robh/for-next] > [also build test ERROR on hid/for-next dtor-input/next dtor-input/for-linus drm-misc/drm-misc-next linus/master v6.4-rc5 next-20230607] > [If your patch is applied to the wrong git tree, kindly drop us a note. > And when submitting patch, we suggest to use '--base' as documented in > https://git-scm.com/docs/git-format-patch#_base_tree_information] > > url: https://github.com/intel-lab-lkp/linux/commits/Douglas-Anderson/dt-bindings-HID-i2c-hid-Add-panel-property-to-i2c-hid-backed-touchscreens/20230608-055515 > base: https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next > patch link: https://lore.kernel.org/r/20230607144931.v2.8.Ib1a98309c455cd7e26b931c69993d4fba33bbe15%40changeid > patch subject: [PATCH v2 08/10] HID: i2c-hid: Support being a panel follower > config: i386-randconfig-i003-20230607 (https://download.01.org/0day-ci/archive/20230608/202306081419.Dzz0T4iW-lkp@intel.com/config) > compiler: clang version 15.0.7 (https://github.com/llvm/llvm-project.git 8dfdcc7b7bf66834a761bd8de445840ef68e4d1a) > reproduce (this is a W=1 build): > mkdir -p ~/bin > wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross > chmod +x ~/bin/make.cross > git remote add robh https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git > git fetch robh for-next > git checkout robh/for-next > b4 shazam https://lore.kernel.org/r/20230607144931.v2.8.Ib1a98309c455cd7e26b931c69993d4fba33bbe15@changeid > # save the config file > mkdir build_dir && cp config build_dir/.config > COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang ~/bin/make.cross W=1 O=build_dir ARCH=i386 olddefconfig > COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang ~/bin/make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash > > If you fix the issue in a separate patch/commit (i.e. not just a new version of > the same patch/commit), kindly add following tags > | Reported-by: kernel test robot <lkp@intel.com> > | Closes: https://lore.kernel.org/oe-kbuild-all/202306081419.Dzz0T4iW-lkp@intel.com/ > > All errors (new ones prefixed by >>): > > >> ld.lld: error: undefined symbol: drm_panel_add_follower > >>> referenced by i2c-hid-core.c:1159 (drivers/hid/i2c-hid/i2c-hid-core.c:1159) > >>> drivers/hid/i2c-hid/i2c-hid-core.o:(i2c_hid_core_probe) in archive vmlinux.a > -- > >> ld.lld: error: undefined symbol: drm_panel_remove_follower > >>> referenced by i2c-hid-core.c:1218 (drivers/hid/i2c-hid/i2c-hid-core.c:1218) > >>> drivers/hid/i2c-hid/i2c-hid-core.o:(i2c_hid_core_remove) in archive vmlinux.a Thanks for the report! Ugh, I guess I forgot that even though DRM_PANEL is bool, it gets bundled up into all of DRM which can be a module. Assuming that this series looks mostly the same in the next version, I'll plan to add this: depends on DRM || !DRM # if DRM=m, this can't be 'y' ...to each of the i2c-hid subclasses. -Doug
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. In > 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... Anyway, a remark inlined (at least): > > Signed-off-by: Douglas Anderson <dianders@chromium.org> > --- > > 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 <linux/mutex.h> > #include <asm/unaligned.h> > > +#include <drm/drm_panel.h> > + > #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(struct i2c_hid *ihid) > return ret; > } > > +static int i2c_hid_core_panel_prepared(struct drm_panel_follower *follower) > +{ > + struct i2c_hid *ihid = container_of(follower, struct i2c_hid, panel_follower); > + struct hid_device *hid = ihid->hid; > + > + /* > + * hid->version is set on the first power up. If it's still zero then > + * this is the first power on so we should perform initial power 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 = 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_follower_funcs = { > + .panel_prepared = i2c_hid_core_panel_prepared, > + .panel_unpreparing = 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. Actually, I'd be even more happier if it were in a different compilation unit. Not necessary a different module, but at least a different file. Cheers, Benjamin > + > int i2c_hid_core_probe(struct i2c_client *client, struct i2chid_ops *ops, > u16 hid_descriptor_address, u32 quirks) > { > @@ -1119,6 +1151,41 @@ int i2c_hid_core_probe(struct i2c_client *client, struct i2chid_ops *ops, > hid->bus = BUS_I2C; > hid->initial_quirks = quirks; > > + /* > + * See if we're following a panel. If drm_panel_add_follower() > + * returns no error then we are. > + */ > + ihid->panel_follower.funcs = &i2c_hid_core_panel_follower_funcs; > + ret = drm_panel_add_follower(&client->dev, &ihid->panel_follower); > + if (!ret) { > + /* We're a follower. That means we'll power things up later. */ > + ihid->is_panel_follower = true; > + > + /* > + * If we're not in control of our own power up/power down then > + * we can't do the logic to manage wakeups. Give a warning if > + * a user thought that was possible then force the capability > + * off. > + */ > + if (device_can_wakeup(&client->dev)) { > + dev_warn(&client->dev, "Can't wakeup if following panel\n"); > + device_set_wakeup_capable(&client->dev, false); > + } > + > + return 0; > + } > + > + /* > + * -ENODEV means that we're not following a panel, so any other error > + * is a real problem (like -EPROBE_DEFER, -ENOMEM, ...). > + */ > + if (ret != -ENODEV) > + goto err_mem_free; > + > + /* > + * We're not following a panel. That's fine and means that we > + * can power up right away. > + */ > ret = i2c_hid_core_initial_power_up(ihid); > if (ret) > goto err_mem_free; > @@ -1143,7 +1210,14 @@ void i2c_hid_core_remove(struct i2c_client *client) > struct i2c_hid *ihid = i2c_get_clientdata(client); > struct hid_device *hid; > > - i2c_hid_core_power_down(ihid); > + /* > + * If we're a follower, the act of unfollowing will cause us to be > + * powered down. Otherwise we need to manually do it. > + */ > + if (ihid->is_panel_follower) > + drm_panel_remove_follower(&ihid->panel_follower); > + else > + i2c_hid_core_power_down(ihid); > > hid = ihid->hid; > hid_destroy_device(hid); > @@ -1171,6 +1245,9 @@ static int i2c_hid_core_pm_suspend(struct device *dev) > struct i2c_client *client = to_i2c_client(dev); > struct i2c_hid *ihid = i2c_get_clientdata(client); > > + if (ihid->is_panel_follower) > + return 0; > + > return i2c_hid_core_suspend(ihid); > } > > @@ -1179,6 +1256,9 @@ static int i2c_hid_core_pm_resume(struct device *dev) > struct i2c_client *client = to_i2c_client(dev); > struct i2c_hid *ihid = i2c_get_clientdata(client); > > + if (ihid->is_panel_follower) > + return 0; > + > return i2c_hid_core_resume(ihid); > } > > -- > 2.41.0.162.gfafddb0af9-goog >
Hi, On Thu, Jun 8, 2023 at 8:37 AM Benjamin Tissoires <benjamin.tissoires@redhat.com> 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. In > > 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 <dianders@chromium.org> > > --- > > > > 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 <linux/mutex.h> > > #include <asm/unaligned.h> > > > > +#include <drm/drm_panel.h> > > + > > #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(struct i2c_hid *ihid) > > return ret; > > } > > > > +static int i2c_hid_core_panel_prepared(struct drm_panel_follower *follower) > > +{ > > + struct i2c_hid *ihid = container_of(follower, struct i2c_hid, panel_follower); > > + struct hid_device *hid = ihid->hid; > > + > > + /* > > + * hid->version is set on the first power up. If it's still zero then > > + * this is the first power on so we should perform initial power 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 = 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_follower_funcs = { > > + .panel_prepared = i2c_hid_core_panel_prepared, > > + .panel_unpreparing = 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 compilation > 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.
On Thu, Jun 8, 2023 at 6:43 PM Doug Anderson <dianders@chromium.org> wrote: > > Hi, > > On Thu, Jun 8, 2023 at 8:37 AM Benjamin Tissoires > <benjamin.tissoires@redhat.com> 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. In > > > 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 <dianders@chromium.org> > > > --- > > > > > > 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 <linux/mutex.h> > > > #include <asm/unaligned.h> > > > > > > +#include <drm/drm_panel.h> > > > + > > > #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(struct i2c_hid *ihid) > > > return ret; > > > } > > > > > > +static int i2c_hid_core_panel_prepared(struct drm_panel_follower *follower) > > > +{ > > > + struct i2c_hid *ihid = container_of(follower, struct i2c_hid, panel_follower); > > > + struct hid_device *hid = ihid->hid; > > > + > > > + /* > > > + * hid->version is set on the first power up. If it's still zero then > > > + * this is the first power on so we should perform initial power 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 = 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_follower_funcs = { > > > + .panel_prepared = i2c_hid_core_panel_prepared, > > > + .panel_unpreparing = 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 compilation > > 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
Hi, On Fri, Jun 9, 2023 at 2:27 AM Benjamin Tissoires <benjamin.tissoires@redhat.com> wrote: > > > 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? There is no reason why this problem would be limited to devices using devicetree. Even if ACPI could somehow magically power sequence the touchscreen and panel together, doing it behind the back of the kernel driver would be a bad idea anyway so folks using ACPI would need the same code. I don't have tons of experience with ACPI nor how to hook this up there, but I purposely made the API for registering the panel follower such that the client doesn't pass anything devicetree specific. If someone could figure out how to detect a link between a panel and a touchscreen for ACPI and add this code to drm_panel_add_follower() then it would automatically work for the ACPI case as well. -Doug
Benjamin, On Thu, Jun 8, 2023 at 8:37 AM Benjamin Tissoires <benjamin.tissoires@redhat.com> wrote: > > > +static const struct drm_panel_follower_funcs i2c_hid_core_panel_follower_funcs = { > > + .panel_prepared = i2c_hid_core_panel_prepared, > > + .panel_unpreparing = 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. Now that other concerns are addressed, I started trying to write up a v3 and I found myself writing this as the description of the Kconfig entry: -- config I2C_HID_SUPPORT_PANEL_FOLLOWER bool "Support i2c-hid devices that must be power sequenced with a panel" Say Y here if you want support for i2c-hid devices that need to coordinate power sequencing with a panel. This is typically important when you have a panel and a touchscreen that share power rails or reset GPIOs. If you say N here then the kernel will not try to honor any shared power sequencing for your hardware. In the best case, ignoring power sequencing when it's needed will draw extra power. In the worst case this will prevent your hardware from functioning or could even damage your hardware. If unsure, say Y. -- I can certainly go that way, but I just wanted to truly make sure that's what we want. Specifically: 1. If we put the panel follower code behind a Kconfig then we actually have no idea if a touchscreen was intended to be a panel follower. Specifically the panel follower API is the one that detects the connection between the panel and the i2c-hid device, so without being able to call the panel follower API we have no idea that an i2c-hid device was supposed to be a panel follower. 2. It is conceivable that power sequencing a device incorrectly could truly cause hardware damage. Together, those points mean that if you turn off the Kconfig entry and then try to boot on a device that needed that Kconfig setting that you might damage hardware. I can code it up that way if you want, but it worries me... Alternatives that I can think of: a) I could change the panel follower API so that panel followers are in charge of detecting the panel that they follow. Today, that looks like: panel_np = of_parse_phandle(dev->of_node, "panel", 0); if (panel_np) /* It's a panel follower */ of_node_put(panel_np); ...so we could put that code in each touchscreen driver and then fail to probe i2c-hid if we detect that we're supposed to be a panel follower but the Kconfig is turned off. The above doesn't seem massively ideal since it duplicates code. Also, one reason why I put that code in drm_panel_add_follower() is that I think this concept will eventually be needed even for non-DT cases. I don't know how to write the non-DT code right now, though... b) I could open-code detect the panel follower case but leave the actual linking to the panel follower API. AKA add to i2c-hid: if (of_property_read_bool(dev->of_node, "panel")) /* It's a panel follower */ ...that's a smaller bit of code, but feels like an abstraction violation. It also would need to be updated if/when we added support for non-DT panel followers. c) I could add a "static inline" implementation of b) to "drm_panel.h". That sounds great and I started doing it. ...but then realized that it means adding to drm_panel.h: #include <linux/device.h> #include <linux/of.h> ...because otherwise of_property_read_bool() isn't defined and "struct device" can't be dereferenced. That might be OK, but it looks as if folks have been working hard to avoid things like this in header files. Presumably it would get uglier if/when we added the non-DT case, as well. That being said, I can give it a shot... -- At this point, I'm hoping for some advice. How important is it for you to have a Kconfig for "I2C_HID_SUPPORT_PANEL_FOLLOWER"? NOTE: even if I don't add the Kconfig, I could at least create a function for registering the panel follower that would get most of the panel follower logic out of the probe function. Would that be enough? Thanks! -Doug
Benjamin, On Mon, Jun 26, 2023 at 3:49 PM Doug Anderson <dianders@chromium.org> wrote: > > Benjamin, > > On Thu, Jun 8, 2023 at 8:37 AM Benjamin Tissoires > <benjamin.tissoires@redhat.com> wrote: > > > > > +static const struct drm_panel_follower_funcs i2c_hid_core_panel_follower_funcs = { > > > + .panel_prepared = i2c_hid_core_panel_prepared, > > > + .panel_unpreparing = 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. > > Now that other concerns are addressed, I started trying to write up a > v3 and I found myself writing this as the description of the Kconfig > entry: > > -- > config I2C_HID_SUPPORT_PANEL_FOLLOWER > bool "Support i2c-hid devices that must be power sequenced with a panel" > > Say Y here if you want support for i2c-hid devices that need to > coordinate power sequencing with a panel. This is typically important > when you have a panel and a touchscreen that share power rails or > reset GPIOs. If you say N here then the kernel will not try to honor > any shared power sequencing for your hardware. In the best case, > ignoring power sequencing when it's needed will draw extra power. In > the worst case this will prevent your hardware from functioning or > could even damage your hardware. > > If unsure, say Y. > > -- > > I can certainly go that way, but I just wanted to truly make sure > that's what we want. Specifically: > > 1. If we put the panel follower code behind a Kconfig then we actually > have no idea if a touchscreen was intended to be a panel follower. > Specifically the panel follower API is the one that detects the > connection between the panel and the i2c-hid device, so without being > able to call the panel follower API we have no idea that an i2c-hid > device was supposed to be a panel follower. > > 2. It is conceivable that power sequencing a device incorrectly could > truly cause hardware damage. > > Together, those points mean that if you turn off the Kconfig entry and > then try to boot on a device that needed that Kconfig setting that you > might damage hardware. I can code it up that way if you want, but it > worries me... > > > Alternatives that I can think of: > > a) I could change the panel follower API so that panel followers are > in charge of detecting the panel that they follow. Today, that looks > like: > > panel_np = of_parse_phandle(dev->of_node, "panel", 0); > if (panel_np) > /* It's a panel follower */ > of_node_put(panel_np); > > ...so we could put that code in each touchscreen driver and then fail > to probe i2c-hid if we detect that we're supposed to be a panel > follower but the Kconfig is turned off. The above doesn't seem > massively ideal since it duplicates code. Also, one reason why I put > that code in drm_panel_add_follower() is that I think this concept > will eventually be needed even for non-DT cases. I don't know how to > write the non-DT code right now, though... > > > b) I could open-code detect the panel follower case but leave the > actual linking to the panel follower API. AKA add to i2c-hid: > > if (of_property_read_bool(dev->of_node, "panel")) > /* It's a panel follower */ > > ...that's a smaller bit of code, but feels like an abstraction > violation. It also would need to be updated if/when we added support > for non-DT panel followers. > > > c) I could add a "static inline" implementation of b) to "drm_panel.h". > > That sounds great and I started doing it. ...but then realized that it > means adding to drm_panel.h: > > #include <linux/device.h> > #include <linux/of.h> > > ...because otherwise of_property_read_bool() isn't defined and "struct > device" can't be dereferenced. That might be OK, but it looks as if > folks have been working hard to avoid things like this in header > files. Presumably it would get uglier if/when we added the non-DT > case, as well. That being said, I can give it a shot... > > -- > > At this point, I'm hoping for some advice. How important is it for you > to have a Kconfig for "I2C_HID_SUPPORT_PANEL_FOLLOWER"? > > NOTE: even if I don't add the Kconfig, I could at least create a > function for registering the panel follower that would get most of the > panel follower logic out of the probe function. Would that be enough? I'd love to send a new version of this patch series, but I'm still stuck with the above issue. I'm hoping you might have a minute to provide your thoughts. If I don't hear anything, I'll try a v3 where I don't have the Kconfig for "I2C_HID_SUPPORT_PANEL_FOLLOWER" but just try to pull a little more of the code out of the probe function. Thanks for your time! -Doug
Hi, On Mon, Jul 17, 2023 at 11:15 AM Doug Anderson <dianders@chromium.org> wrote: > > Benjamin, > > On Mon, Jun 26, 2023 at 3:49 PM Doug Anderson <dianders@chromium.org> wrote: > > > > Benjamin, > > > > On Thu, Jun 8, 2023 at 8:37 AM Benjamin Tissoires > > <benjamin.tissoires@redhat.com> wrote: > > > > > > > +static const struct drm_panel_follower_funcs i2c_hid_core_panel_follower_funcs = { > > > > + .panel_prepared = i2c_hid_core_panel_prepared, > > > > + .panel_unpreparing = 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. > > > > Now that other concerns are addressed, I started trying to write up a > > v3 and I found myself writing this as the description of the Kconfig > > entry: > > > > -- > > config I2C_HID_SUPPORT_PANEL_FOLLOWER > > bool "Support i2c-hid devices that must be power sequenced with a panel" > > > > Say Y here if you want support for i2c-hid devices that need to > > coordinate power sequencing with a panel. This is typically important > > when you have a panel and a touchscreen that share power rails or > > reset GPIOs. If you say N here then the kernel will not try to honor > > any shared power sequencing for your hardware. In the best case, > > ignoring power sequencing when it's needed will draw extra power. In > > the worst case this will prevent your hardware from functioning or > > could even damage your hardware. > > > > If unsure, say Y. > > > > -- > > > > I can certainly go that way, but I just wanted to truly make sure > > that's what we want. Specifically: > > > > 1. If we put the panel follower code behind a Kconfig then we actually > > have no idea if a touchscreen was intended to be a panel follower. > > Specifically the panel follower API is the one that detects the > > connection between the panel and the i2c-hid device, so without being > > able to call the panel follower API we have no idea that an i2c-hid > > device was supposed to be a panel follower. > > > > 2. It is conceivable that power sequencing a device incorrectly could > > truly cause hardware damage. > > > > Together, those points mean that if you turn off the Kconfig entry and > > then try to boot on a device that needed that Kconfig setting that you > > might damage hardware. I can code it up that way if you want, but it > > worries me... > > > > > > Alternatives that I can think of: > > > > a) I could change the panel follower API so that panel followers are > > in charge of detecting the panel that they follow. Today, that looks > > like: > > > > panel_np = of_parse_phandle(dev->of_node, "panel", 0); > > if (panel_np) > > /* It's a panel follower */ > > of_node_put(panel_np); > > > > ...so we could put that code in each touchscreen driver and then fail > > to probe i2c-hid if we detect that we're supposed to be a panel > > follower but the Kconfig is turned off. The above doesn't seem > > massively ideal since it duplicates code. Also, one reason why I put > > that code in drm_panel_add_follower() is that I think this concept > > will eventually be needed even for non-DT cases. I don't know how to > > write the non-DT code right now, though... > > > > > > b) I could open-code detect the panel follower case but leave the > > actual linking to the panel follower API. AKA add to i2c-hid: > > > > if (of_property_read_bool(dev->of_node, "panel")) > > /* It's a panel follower */ > > > > ...that's a smaller bit of code, but feels like an abstraction > > violation. It also would need to be updated if/when we added support > > for non-DT panel followers. > > > > > > c) I could add a "static inline" implementation of b) to "drm_panel.h". > > > > That sounds great and I started doing it. ...but then realized that it > > means adding to drm_panel.h: > > > > #include <linux/device.h> > > #include <linux/of.h> > > > > ...because otherwise of_property_read_bool() isn't defined and "struct > > device" can't be dereferenced. That might be OK, but it looks as if > > folks have been working hard to avoid things like this in header > > files. Presumably it would get uglier if/when we added the non-DT > > case, as well. That being said, I can give it a shot... > > > > -- > > > > At this point, I'm hoping for some advice. How important is it for you > > to have a Kconfig for "I2C_HID_SUPPORT_PANEL_FOLLOWER"? > > > > NOTE: even if I don't add the Kconfig, I could at least create a > > function for registering the panel follower that would get most of the > > panel follower logic out of the probe function. Would that be enough? > > I'd love to send a new version of this patch series, but I'm still > stuck with the above issue. I'm hoping you might have a minute to > provide your thoughts. If I don't hear anything, I'll try a v3 where I > don't have the Kconfig for "I2C_HID_SUPPORT_PANEL_FOLLOWER" but just > try to pull a little more of the code out of the probe function. To provide breadcrumbs, I posted the v3 which pulls a bit more code out of the probe function but is otherwise largely unchanged. The cover letter for v3 can be found at: https://lore.kernel.org/r/20230725203545.2260506-1-dianders@chromium.org/
On Jul 25 2023, Doug Anderson wrote: > Hi, > > On Mon, Jul 17, 2023 at 11:15 AM Doug Anderson <dianders@chromium.org> wrote: > > > > Benjamin, > > > > On Mon, Jun 26, 2023 at 3:49 PM Doug Anderson <dianders@chromium.org> wrote: > > > > > > Benjamin, > > > > > > On Thu, Jun 8, 2023 at 8:37 AM Benjamin Tissoires > > > <benjamin.tissoires@redhat.com> wrote: > > > > > > > > > +static const struct drm_panel_follower_funcs i2c_hid_core_panel_follower_funcs = { > > > > > + .panel_prepared = i2c_hid_core_panel_prepared, > > > > > + .panel_unpreparing = 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. > > > > > > Now that other concerns are addressed, I started trying to write up a > > > v3 and I found myself writing this as the description of the Kconfig > > > entry: > > > > > > -- > > > config I2C_HID_SUPPORT_PANEL_FOLLOWER > > > bool "Support i2c-hid devices that must be power sequenced with a panel" > > > > > > Say Y here if you want support for i2c-hid devices that need to > > > coordinate power sequencing with a panel. This is typically important > > > when you have a panel and a touchscreen that share power rails or > > > reset GPIOs. If you say N here then the kernel will not try to honor > > > any shared power sequencing for your hardware. In the best case, > > > ignoring power sequencing when it's needed will draw extra power. In > > > the worst case this will prevent your hardware from functioning or > > > could even damage your hardware. > > > > > > If unsure, say Y. > > > > > > -- > > > > > > I can certainly go that way, but I just wanted to truly make sure > > > that's what we want. Specifically: > > > > > > 1. If we put the panel follower code behind a Kconfig then we actually > > > have no idea if a touchscreen was intended to be a panel follower. > > > Specifically the panel follower API is the one that detects the > > > connection between the panel and the i2c-hid device, so without being > > > able to call the panel follower API we have no idea that an i2c-hid > > > device was supposed to be a panel follower. > > > > > > 2. It is conceivable that power sequencing a device incorrectly could > > > truly cause hardware damage. > > > > > > Together, those points mean that if you turn off the Kconfig entry and > > > then try to boot on a device that needed that Kconfig setting that you > > > might damage hardware. I can code it up that way if you want, but it > > > worries me... > > > > > > > > > Alternatives that I can think of: > > > > > > a) I could change the panel follower API so that panel followers are > > > in charge of detecting the panel that they follow. Today, that looks > > > like: > > > > > > panel_np = of_parse_phandle(dev->of_node, "panel", 0); > > > if (panel_np) > > > /* It's a panel follower */ > > > of_node_put(panel_np); > > > > > > ...so we could put that code in each touchscreen driver and then fail > > > to probe i2c-hid if we detect that we're supposed to be a panel > > > follower but the Kconfig is turned off. The above doesn't seem > > > massively ideal since it duplicates code. Also, one reason why I put > > > that code in drm_panel_add_follower() is that I think this concept > > > will eventually be needed even for non-DT cases. I don't know how to > > > write the non-DT code right now, though... > > > > > > > > > b) I could open-code detect the panel follower case but leave the > > > actual linking to the panel follower API. AKA add to i2c-hid: > > > > > > if (of_property_read_bool(dev->of_node, "panel")) > > > /* It's a panel follower */ > > > > > > ...that's a smaller bit of code, but feels like an abstraction > > > violation. It also would need to be updated if/when we added support > > > for non-DT panel followers. > > > > > > > > > c) I could add a "static inline" implementation of b) to "drm_panel.h". > > > > > > That sounds great and I started doing it. ...but then realized that it > > > means adding to drm_panel.h: > > > > > > #include <linux/device.h> > > > #include <linux/of.h> > > > > > > ...because otherwise of_property_read_bool() isn't defined and "struct > > > device" can't be dereferenced. That might be OK, but it looks as if > > > folks have been working hard to avoid things like this in header > > > files. Presumably it would get uglier if/when we added the non-DT > > > case, as well. That being said, I can give it a shot... > > > > > > -- > > > > > > At this point, I'm hoping for some advice. How important is it for you > > > to have a Kconfig for "I2C_HID_SUPPORT_PANEL_FOLLOWER"? > > > > > > NOTE: even if I don't add the Kconfig, I could at least create a > > > function for registering the panel follower that would get most of the > > > panel follower logic out of the probe function. Would that be enough? > > > > I'd love to send a new version of this patch series, but I'm still > > stuck with the above issue. I'm hoping you might have a minute to > > provide your thoughts. If I don't hear anything, I'll try a v3 where I > > don't have the Kconfig for "I2C_HID_SUPPORT_PANEL_FOLLOWER" but just > > try to pull a little more of the code out of the probe function. > > To provide breadcrumbs, I posted the v3 which pulls a bit more code > out of the probe function but is otherwise largely unchanged. The > cover letter for v3 can be found at: Apologies for the delay. Given that you received feedbacks from other folks I wanted things to settle down a little bit before returning to this discussion. Sorry. > > https://lore.kernel.org/r/20230725203545.2260506-1-dianders@chromium.org/ I like the 8th patch of this series much more. If there is a risk of damaging the device, then we should not have the Kconfig to disable it. I have some comments on that particular patch (v3 8/10), but I; ll reply inline. Cheers, Benjamin
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 <linux/mutex.h> #include <asm/unaligned.h> +#include <drm/drm_panel.h> + #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(struct i2c_hid *ihid) return ret; } +static int i2c_hid_core_panel_prepared(struct drm_panel_follower *follower) +{ + struct i2c_hid *ihid = container_of(follower, struct i2c_hid, panel_follower); + struct hid_device *hid = ihid->hid; + + /* + * hid->version is set on the first power up. If it's still zero then + * this is the first power on so we should perform initial power 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 = 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_follower_funcs = { + .panel_prepared = i2c_hid_core_panel_prepared, + .panel_unpreparing = i2c_hid_core_panel_unpreparing, +}; + int i2c_hid_core_probe(struct i2c_client *client, struct i2chid_ops *ops, u16 hid_descriptor_address, u32 quirks) { @@ -1119,6 +1151,41 @@ int i2c_hid_core_probe(struct i2c_client *client, struct i2chid_ops *ops, hid->bus = BUS_I2C; hid->initial_quirks = quirks; + /* + * See if we're following a panel. If drm_panel_add_follower() + * returns no error then we are. + */ + ihid->panel_follower.funcs = &i2c_hid_core_panel_follower_funcs; + ret = drm_panel_add_follower(&client->dev, &ihid->panel_follower); + if (!ret) { + /* We're a follower. That means we'll power things up later. */ + ihid->is_panel_follower = true; + + /* + * If we're not in control of our own power up/power down then + * we can't do the logic to manage wakeups. Give a warning if + * a user thought that was possible then force the capability + * off. + */ + if (device_can_wakeup(&client->dev)) { + dev_warn(&client->dev, "Can't wakeup if following panel\n"); + device_set_wakeup_capable(&client->dev, false); + } + + return 0; + } + + /* + * -ENODEV means that we're not following a panel, so any other error + * is a real problem (like -EPROBE_DEFER, -ENOMEM, ...). + */ + if (ret != -ENODEV) + goto err_mem_free; + + /* + * We're not following a panel. That's fine and means that we + * can power up right away. + */ ret = i2c_hid_core_initial_power_up(ihid); if (ret) goto err_mem_free; @@ -1143,7 +1210,14 @@ void i2c_hid_core_remove(struct i2c_client *client) struct i2c_hid *ihid = i2c_get_clientdata(client); struct hid_device *hid; - i2c_hid_core_power_down(ihid); + /* + * If we're a follower, the act of unfollowing will cause us to be + * powered down. Otherwise we need to manually do it. + */ + if (ihid->is_panel_follower) + drm_panel_remove_follower(&ihid->panel_follower); + else + i2c_hid_core_power_down(ihid); hid = ihid->hid; hid_destroy_device(hid); @@ -1171,6 +1245,9 @@ static int i2c_hid_core_pm_suspend(struct device *dev) struct i2c_client *client = to_i2c_client(dev); struct i2c_hid *ihid = i2c_get_clientdata(client); + if (ihid->is_panel_follower) + return 0; + return i2c_hid_core_suspend(ihid); } @@ -1179,6 +1256,9 @@ static int i2c_hid_core_pm_resume(struct device *dev) struct i2c_client *client = to_i2c_client(dev); struct i2c_hid *ihid = i2c_get_clientdata(client); + if (ihid->is_panel_follower) + return 0; + return i2c_hid_core_resume(ihid); }