Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3492388rdh; Thu, 28 Sep 2023 13:19:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHyxVi8BAc5AoJpiNZshpOnJzh6qnzQHiTivY/XU6wiIICwCmxwGVuyUZ31nh1PetmE/xVC X-Received: by 2002:a17:902:f7c6:b0:1c6:1ab1:93eb with SMTP id h6-20020a170902f7c600b001c61ab193ebmr2020661plw.17.1695932389657; Thu, 28 Sep 2023 13:19:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695932389; cv=none; d=google.com; s=arc-20160816; b=dGK1t2yXLLVy128K2Xft8FiC79MBxt77EMxADd6ngyoK/KLe0VTq9aIFPqZL4JNLnY iwRKf0ZzYZLL0MRyGlRHbps+fK8PLZkqBRujoG8ma0UzmVNrNHfQ2hMgC7Ag1PF1BM8z 6nCI0ZkqrG5ji4hrxO0DMp9TOdyNLzFF7F/ApwmBBcZ065UbLyjbf/MBl6pW3irPgV8x QmkjvcSQox7K029x2m/sTIt46G/2W4wJUFqXNkOXElJjQi+7pHm4dcvSzBpfQz4soYzb SrlyJ24zlxmXnHJiTYpJXGo0RLu5sDk1trumLTet1oNHiSWSSOjPVkN3RvnKpXDznCNJ y2Uw== 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=iQgZZ0oRWuTy3DC5xTKJCLZOIR/z4qccHxDUtANpzhw=; fh=J+iFXvHUbStFrBktvFnqRKdg784OABtOz/QMCCPbZpw=; b=vEByX8KfctrScBYpHvGVvTF5V2MRV+2KgwvhvzVRl9oGYflqU4NbQH4jxXRuBL03k4 WHNAGU87XNoa8XczQYftO6/VX50O3lgjVNBP2+XM9xZ8lh0ZwMnowJXr2HlLZ0SgpRWR Bx3kF3lmaCE7JWNB3xeWaBSLAxZOepAzkw63h7mopbbr52LRusQhNjuSYf/yXhMVoOGD RHXiiqEOmHeuZYcNv2GSwgwdR0eSH40zotZ/e/fnAkfR0uevsS+fZOknpzJItLH2goBF NAdLlfEGr60aIW8a/Hkk/T8PO8TE5RCN1ZzKGcs0WA3tu85XediLA0btT+7lIxB2V6aT Kh9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=k07cqYLM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id c7-20020a170903234700b001a6bb7b7a44si20535203plh.307.2023.09.28.13.19.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 13:19:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=k07cqYLM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 808B080C5A14; Thu, 28 Sep 2023 13:12:33 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231701AbjI1UMO (ORCPT + 99 others); Thu, 28 Sep 2023 16:12:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231171AbjI1UMN (ORCPT ); Thu, 28 Sep 2023 16:12:13 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B191194; Thu, 28 Sep 2023 13:12:11 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C4DD7C433C9; Thu, 28 Sep 2023 20:12:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695931930; bh=bqzkqO5GyJ3b2u9PxXpLcSb3jCjFoeXu76DGP/lb7pY=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=k07cqYLMDuODh0aykrMMpsUvxH/Z57r7GwQA/x9ygRAVxKm1DZywYEsNsoYFjrUt/ 7Ntrb/rh1mWt0RWaydcnbLeocG2gUuT+qHM6iVMJSlb9f5PsuHNVRyQVQnG7Lhvbm3 clY9JUil4uUM/ZuItAEq6jE7N0OzcAQrN35BH/3teo+gi1/M1tWEv7xhZGg+uNeCht LtCS4eEHoYPV9NgoTaxef8d1QiMk2uYi5hLZheAzc3jrrIX9WBHxhmT6aoZf9Nmsdr WM5TNS+Crm5DPUsM8q1FznRYp2Iw+JYkYeUgBwyLCs/jAg2jYm5vQy5uy6b3nG+/rW mQsweC3Y8nagw== Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-5041d6d8b10so21942607e87.2; Thu, 28 Sep 2023 13:12:10 -0700 (PDT) X-Gm-Message-State: AOJu0YzsoZ3Ab25Mr7c38AvmJ+sHVwUaE1XWjKildegA18gHpd4bPZ/a BCwwTrvF/C2ZCWhbtS+6tpAlc7CjfCimTqpPKw== X-Received: by 2002:ac2:4d8e:0:b0:503:3890:ca3a with SMTP id g14-20020ac24d8e000000b005033890ca3amr2003265lfe.66.1695931928910; Thu, 28 Sep 2023 13:12:08 -0700 (PDT) MIME-Version: 1.0 References: <20230921102420.RFC.1.I9dddd99ccdca175e3ceb1b9fa1827df0928c5101@changeid> In-Reply-To: From: Rob Herring Date: Thu, 28 Sep 2023 15:11:56 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH] of: device: Support 2nd sources of probeable but undiscoverable devices To: Doug Anderson Cc: Krzysztof Kozlowski , Conor Dooley , devicetree@vger.kernel.org, Benjamin Tissoires , Chen-Yu Tsai , linux-input@vger.kernel.org, Jiri Kosina , Hsin-Yi Wang , linux-gpio@vger.kernel.org, linus.walleij@linaro.org, Dmitry Torokhov , Johan Hovold , andriy.shevchenko@linux.intel.com, broonie@kernel.org, frowand.list@gmail.com, gregkh@linuxfoundation.org, hdegoede@redhat.com, james.clark@arm.com, james@equiv.tech, keescook@chromium.org, linux-kernel@vger.kernel.org, rafael@kernel.org, tglx@linutronix.de Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Thu, 28 Sep 2023 13:12:33 -0700 (PDT) On Fri, Sep 22, 2023 at 7:11=E2=80=AFPM Doug Anderson wrote: > > Hi, > > On Fri, Sep 22, 2023 at 12:08=E2=80=AFPM Rob Herring = wrote: > > > > > > This seems like overkill to me. Do we really need groups and a mute= x > > > > for each group? Worst case is what? 2-3 groups of 2-3 devices? > > > > Instead, what about extending "status" with another value > > > > ("fail-needs-probe"? (fail-xxx is a documented value)). Currently, = the > > > > kernel would just ignore nodes with that status. Then we can proces= s > > > > those nodes separately 1-by-1. > > > > > > My worry here is that this has the potential to impact boot speed in = a > > > non-trivial way. While trackpads and touchscreens _are_ probable, > > > their probe routines are often quite slow. This is even mentioned in > > > Dmitry's initial patches adding async probe to the kernel. See commit > > > 765230b5f084 ("driver-core: add asynchronous probing support for > > > drivers") where he specifically brings up input devices as examples. > > > > Perhaps then this should be solved in userspace where it can learn > > which device is actually present and save that information for > > subsequent boots. > > Yeah, the thought occurred to me as well. I think there are a few > problems, though: > > a) Userspace can't itself probe these devices effectively. While > userspace could turn on GPIOs manually and query the i2c bus manually, > it can't (I believe) turn on regulators nor can it turn on clocks, if > they are needed. About the best userspace could do would be to blindly > try binding an existing kernel driver, and in that case why did we > need userspace involved anyway? > > b) While deferring to userspace can work for solutions like ChromeOS > or Android where it's easy to ensure the userspace bits are there, > it's less appealing as a general solution. I think in Johan's case > he's taking a laptop that initially ran Windows and then is trying to > run a generic Linux distro on it. For anyone in a similar situation, > they'd either need to pick a Linux distro that has the magic userspace > bits that are needed or they need to know that, on their laptop, they > need to manually install some software. While requiring special > userspace might make sense if you've got a special peripheral, like an > LTE modem, it makes less sense to need special userspace just to get > the right devices bound... I did not mean do it all in userspace, but for userspace to save off what devices are actually present. For example, if userspace has access to the dtb, it could just update the dtb to enable the right nodes. Then after the first boot, boot time is faster. Or a driver could try to load an overlay with the config enabling the right devices. Though maybe waiting til userspace is available wouldn't speed things up. > > > It wouldn't be absurd to have a system that has multiple sources for > > > both the trackpad and the touchscreen. If we have to probe each of > > > these one at a time then it could be slow. It would be quicker to be > > > able to probe the trackpads (one at a time) at the same time we're > > > probing the touchscreens (one at a time). Using the "fail-needs-probe= " > > > doesn't provide information needed to know which devices conflict wit= h > > > each other. > > > > I would guess most of the time that's pretty evident. They are going > > to be on the same bus/link. If unrelated devices are on the same bus, > > then that's going to get serialized anyways (if bus accesses are what > > make things slow). > > > > We could add information on the class of device. touchscreen and > > touchpad aliases or something. > > Ah, I see. So something like "fail-needs-probe-". The > touchscreens could have "fail-needs-probe-touchscreen" and the > trackpads could have "fail-needs-probe-trackpad" ? That could work. In > theory that could fall back to the same solution of grabbing a mutex > based on the group ID... I would not combine the 2 things. Knowing the class/type of the device may be useful independent of your problem. > Also: if having the mutex in the "struct device" is seen as a bad > idea, it would also be easy to remove. __driver_probe_device() could > just make a call like "of_device_probe_start()" at the beginning that > locks the mutex and then "of_device_probe_end()" that unlocks it. Both > of those calls could easily lookup the mutex in a list, which would > get rid of the need to store it in the "struct device". That could be useful for other things too. Like moving some of the hw init we do outside of probe (though that's mostly abstracted to be not DT specific, so maybe not). > > > That would lead me to suggest this: > > > > > > &i2c_bus { > > > trackpad-prober { > > > compatible =3D "mt8173-elm-hana-trackpad-prober"; > > > > > > tp1: trackpad@10 { > > > compatible =3D "hid-over-i2c"; > > > reg =3D <0x10>; > > > ... > > > post-power-on-delay-ms =3D <200>; > > > }; > > > tp2: trackpad@20 { > > > compatible =3D "hid-over-i2c"; > > > reg =3D <0x20>; > > > ... > > > post-power-on-delay-ms =3D <200>; > > > }; > > > }; > > > }; > > > > > > ...but I suspect that would be insta-NAKed because it's creating a > > > completely virtual device ("mt8173-elm-hana-trackpad-prober") in the > > > device tree. I don't know if there's something that's functionally > > > similar that would be OK? > > > > Why do you need the intermediate node other than a convenient way to > > instantiate a driver? You just need a flag in each node which needs > > this special handling. Again, "status" could work well here since it > > keeps the normal probe from happening. But I'm not saying you can't > > have some board specific code. Sometimes you just need code to deal > > with this stuff. Don't try to parameterize everything to DT > > properties. > > I think I'd have an easier time understanding if I knew where you > envisioned the board-specific code living. Do you have an example of > board specific code running at boot time in the kernel on DT systems? drivers/soc/ or drivers/platform/ are the dumping grounds. Don't we already have CrOS stuff there? > > Note that the above only works with "generic" compatibles with > > "generic" power sequencing properties (I won't repeat my dislike > > again). > > I don't think so? I was imagining that we'd have some board specific > code that ran that knew all the possible combinations of devices, > could probe them, and then could instantiate the correct driver. Okay, just making sure you weren't trying to parameterize everything when generally, how to power sequence is implicit. > > Imagine that instead of the hated "hid-over-i2c" compatible we were > using two other devices. Imagine that a given board could have a > "elan,ekth6915" and a "goodix,gt7375p". Both of these devices have > specific timing requirements on how to sequence their supplies and > reset GPIOs. For Elan we power on the supplies, wait at least 1 ms, > deassert reset, wait at least 300 ms, and then can talk i2c. For > Goodix we power on the supply, wait at least 10 ms, deassert reset, > wait at least 180 ms, and then can talk i2c. If we had a > board-specific probing driver then it would power on the supplies, > wait at least 10 ms (the max of the two), deassert reset, wait at > least 300 ms (the max of the two), and then see which device talked. > Then it would instantiate whichever of the two drivers. This could be > done for any two devices that EEs have determined have "compatible" > probing sequences. My point was that in the above example, all these delay times would have to be defined in the kernel, not DT. > Ideally in the above situation we'd be able to avoid turning the > device off and on again between the board-specific probe code and the > normal driver. That optimization might need special code per-driver > but it feels doable by passing some sort of hint to the child driver > when it's instantiated. I think fixing regulators getting turned off on failed probes and having a "regulator on time" would go a long way towards providing that hint even if the on time was just since clocksource started. > > If only the driver knows how to handle the device, then you > > still just have to have the driver probe. If you *only* wanted to > > solve the above case, I'd just make "hid-over-i2c" take a 2nd (and > > 3rd) I2C address in reg and have those as fallbacks. > > Yeah, it did occur to me that having "hid-over-i2c" take more than one > register (and I guess more than one "hid-descr-addr") would work in my > earlier example and this might actually be a good solution for Johan. > I'm hoping for a better generic solution, though. > > > > You could always make the driver probe smarter where if your supply > > was already powered on, then don't delay. Then something else could > > ensure that the supply is enabled. I'm not sure if regulators have the > > same issue as clocks where the clock might be on from the bootloader, > > then a failed probe which gets then puts the clock turns it off. > > I'm not sure it's that simple. Even if the supply didn't turn off by > itself in some cases, we wouldn't know how long the supply was on. We know the time since the clocksource was initialized. I'd imagine for most cases, more than enough time would elapse by the time you get to these drivers. Rob