Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3618694rdh; Thu, 28 Sep 2023 18:28:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH5Ldh8GgxejHJFhhEUaxTKRvGKjzNRKan37Cw6er7wSkr4s04RfNYpiH9RGu6hvSpKDptY X-Received: by 2002:a05:6808:2c7:b0:3a0:38c2:2654 with SMTP id a7-20020a05680802c700b003a038c22654mr2471535oid.58.1695950897752; Thu, 28 Sep 2023 18:28:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695950897; cv=none; d=google.com; s=arc-20160816; b=O3CcC9sG61KHTfypjkRKrRInSwj1epzClwRu2sSsGkz28N1wR8sZc9rDMZWUoabeCG jPrWEtmgvr0zqZ/HW5e0VjnGay0gXkyy7KkmEQihFoA8MC0tPQfYW9zPejJWOAeL1yBA CYI3YexEKFon4NZuyiEzI8emat0voYlnMgJzcbMUZ1hwUYsDAokqMzzaUrQQCGEUhJ/P U2g6WbWAzmspPOYvJ9xrh1udcyUKeQz0gZLulDN6Ih10Fyom2X5oWFhf7q5tU5c6AJoj 9IhWdPAZ65d7YnFWLI4NOdf/PyHZ/3UH73JS73fv4fPcpQObhRyeYa/YQc3v/IE1iRy7 rFPA== 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=kzXr9frfCEIUWcjDMJGLPPctNew7UQMruDVGH/sn0ug=; fh=bQJCqrxySZOuuA6JrukLR5gbkQItkMIxUkPHenJokB0=; b=wJeAtlF9nwAR/rtYsfEat02WpT5/7O2eM3vTuz/U/PPFlN3YiOvSjTFlZQO3e9zgH6 V5/vPUJkl7H7WsFemOTEMaTJZZo4+9QJgRpzU1RPUuhuZAlTdLv3xazI0r+48qCVbM6q Foe0GRd6sMVI6X+KLQ8q45jpGYQ55ikmb+qVuyWsH79fGNjZjVJWGjWJlAla7inGuE/b goIGhQArYNZOUAvEf55xXuv2dzH8ULj5SdeztbWIbHh6mtzCkWYqKpBUQpTl7kzALMi4 37rNGdYD/cUOF14wqi1r/O3IJ34xF82MUwod5JrkISoJSTKDv8YC9wgImCLqyeG8KcS3 yQnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=H+ilNbwL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id q22-20020a056a00151600b00690f49d9e44si20933316pfu.400.2023.09.28.18.28.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 18:28:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=H+ilNbwL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 91C4582A677A; Thu, 28 Sep 2023 16:22:04 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231446AbjI1XV7 (ORCPT + 99 others); Thu, 28 Sep 2023 19:21:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232123AbjI1XV4 (ORCPT ); Thu, 28 Sep 2023 19:21:56 -0400 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 774A019F for ; Thu, 28 Sep 2023 16:21:51 -0700 (PDT) Received: by mail-ej1-x631.google.com with SMTP id a640c23a62f3a-9936b3d0286so1789462466b.0 for ; Thu, 28 Sep 2023 16:21:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1695943309; x=1696548109; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=kzXr9frfCEIUWcjDMJGLPPctNew7UQMruDVGH/sn0ug=; b=H+ilNbwLQsQW2/+98yjR/gMz5A1Wd+8zyzQyP0vHyadZvt29Oe+CjtiVc7StND+/S5 xnc4u95QRgZvrR0S2W7ZMy7+4z+jT2cUA2PNmfrl9vrGuZ/P7odPH4kHNGPzvwFgMM0s C0eQgqzbaoHRh2tx0R6/WxhqjVPYTv1WC+XsI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695943309; x=1696548109; 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=kzXr9frfCEIUWcjDMJGLPPctNew7UQMruDVGH/sn0ug=; b=APIUwoCtHcn6G/RHmMGjXgtEaBXJlVhGjjTkQVXzRApjdzZ5AUbYykk7GB9TNJJop4 2muv9WOfp8dFIjP/NfLwVjBQROsL/i+AVaj8xWNxhN4T4nuBiuypzs7MPKXy6jeCQHab KkFzna6NQRDuMCOTP+UjbgC17+WkOukysJ976gd4v1m/DUkNupn9qVEGInAtKPcRer07 daf01/CRIRqhR0fCfpNZcUamhySjj4aJn3+zFRSV6HkJyFv+9zOduKZfROWpc+rqDguY n71HKWodkE8UvDgM7LsO0Spvub6922wpS2EZbBP7DFpA/ROPs2pOgxfr1ZfIfYQD0jOv Ltow== X-Gm-Message-State: AOJu0YxlzG9ZufoVwEpQQIs0GtiVkKDoxcNwI8Up7cbnH/ioHnBXc+D9 62OgSMI53povKJ4tI8zUDazblB9VslJdb79SVkEtEijU X-Received: by 2002:a17:907:c241:b0:99c:b0c9:4ec0 with SMTP id tj1-20020a170907c24100b0099cb0c94ec0mr2426929ejc.30.1695943309651; Thu, 28 Sep 2023 16:21:49 -0700 (PDT) Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com. [209.85.208.52]) by smtp.gmail.com with ESMTPSA id g5-20020a17090670c500b009a13fdc139fsm11463730ejk.183.2023.09.28.16.21.49 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 28 Sep 2023 16:21:49 -0700 (PDT) Received: by mail-ed1-f52.google.com with SMTP id 4fb4d7f45d1cf-534694a9f26so3624a12.1 for ; Thu, 28 Sep 2023 16:21:49 -0700 (PDT) X-Received: by 2002:a50:d61c:0:b0:51e:16c5:2004 with SMTP id x28-20020a50d61c000000b0051e16c52004mr502642edi.6.1695943288955; Thu, 28 Sep 2023 16:21:28 -0700 (PDT) MIME-Version: 1.0 References: <20230921102420.RFC.1.I9dddd99ccdca175e3ceb1b9fa1827df0928c5101@changeid> In-Reply-To: From: Doug Anderson Date: Thu, 28 Sep 2023 16:21:16 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH] of: device: Support 2nd sources of probeable but undiscoverable devices To: Rob Herring Cc: Jeff LaBundy , 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=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,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 lindbergh.monkeyblade.net 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 (howler.vger.email [0.0.0.0]); Thu, 28 Sep 2023 16:22:04 -0700 (PDT) Hi, On Thu, Sep 28, 2023 at 1:38=E2=80=AFPM Rob Herring wr= ote: > > > About the best you could do would be to add a board-specific driver > > that understood that it could power up the rails, wait the maximum > > amount of time that all possible touchscreens might need, and then > > look for i2c ACKs. I'm still hoping to hear from Rob about how I would > > get a board-specific driver to load on a DT system so I can > > investigate / prototype this. > > foo_initcall() > { > if (of_machine_is_compatible(...)) > platform_device_create(); > } > > That chunk would have to be built in and if that's part of the driver > module, autoloading wouldn't work. > > We could have a match table of board compatibles and driver names. I'm > not worried about that list being big, so I'm happy to stick that in > drivers/of/. Ah, got it. So your proposal is that we don't add anything to the device tree but we just probe the hardware manager based on the top level compatible string. I guess it could work. It wouldn't mesh amazingly well with the current Chromebook rev/sku stuff in the top-level compatible without being a bit of a jumble. It could probably work with some sort of wildcarding (I'd assume glob-style is enough?). So essentially: static const struct hw_prober_map[] { { .glob =3D "google,lazor*", .func =3D lazor_hw_prober_init }, { .glob =3D "google,homestar*", .func =3D homestar_hw_prober_init }, ... }; for (i =3D 0; i < ARRAY_SIZE(hw_prober_map), i++) { if (of_machine_is_compatible_glob(hw_prober_map[i].glob) hw_prober_map[i].func(); } If that got to be too big to be built-in then I guess we could always figure out a way to move stuff to modules and have them auto-loaded. For now the driver could be in "drivers/platform/chrome/cros_hwprober.c" or something? Hmmm, I guess one issue of doing this, though, is that it's going to be more of a pain to find the DT nodes associated with the resources we want to enable, right? Since there's no DT note associated with the "HW prober" driver we don't just have phandles to them. Do we just use the whole "status" concept and search the whole DT for "fail-needs-probe" type statuses? Like if we have an elan vs. goodix touchscreen and we have a realtek vs. synaptic trackpad then we have statuses like: status =3D "fail-needs-probe-touchscreen-elan"; status =3D "fail-needs-probe-touchscreen-goodix"; status =3D "fail-needs-probe-trackpad-realtek"; status =3D "fail-needs-probe-trackpad-synaptic"; ...or did you have something else in mind? I'd rather not have the HW prober driver need to hardcode full DT paths for the devices it's looking for. > > > This solution seems a bit confusing to me, and would require more edi= ts > > > to the dts each time a second source is added. It also means one woul= d > > > have to write a small platform driver for each group of devices, corr= ect? > > > > No matter what we need to add something to the dts each time a second > > source is added, right? > > That was my thought. OK, cool. > There is the case of the devices are almost the > same, so we lie. That's what you are doing for displays IIRC. Well, we used to do it for display, but it kept biting us. That's why we created the generic "edp-panel", right? In any case, I'd tend to keep it as one node per possible device and have HW prober just update the status. > > While it's true that we'd end up with some extra drivers, if we do it > > correctly we don't necessarily need a driver for each group of devices > > nor even a driver per board. If several boards have very similar > > probing requirements then, even if they have unique "compatible" > > strings they could still end up using the same Linux driver. > > > > I've actually been talking offline with folks on ChromeOS more about > > this problem as well. Chen-Yu actually pointed at a patch series (that > > never landed, I guess) that has some similar ideas [1]. I guess in > > that case Hans was actually constructing device tree properties > > manually in the driver. I was thinking more of having all of the > > options listed in the device tree and then doing something that only > > causes some of them to probe. > > > > If Rob was OK with it, I guess I could have some sort of top-level > > "hwmanager" node like Hans did and then have phandle links to all the > > hardware that are managed by it. Then I could just change those to > > "okay"? > > That's really just making the mutex node link the other direction. The > devices link to the common mutex node vs. the hwmanager node(s) links > to all the devices. That's really just picking the paint colors. I don't think the HW Manager concept is the same as the common mutex at all, so I probably didn't explain it properly. With the mutex approach the idea is that you simply keep probing each device one at a time until one succeeds and the mutex keeps them all from probing at the same time. With the hardware manager approach you run a bit of board-specific code that understands which devices are available and can probe for them in a way that's safer and more efficient. It's safer because it can take into account the timing requirements of all the possible devices to ensure that none of their power sequences are violated. Imagine two touchscreens that each have two power rails and a reset line. The power sequences are: TS1: 1. Power up VCC 2. Wait 0 ms (ensure ordering between VCC and VCCIO) 3. Power up VCCIO 4. Wait 100 ms 5. Deassert reset 6. Wait 50 ms. 7. Talk I2C TS2: 1. Power up VCC 2. Wait 10 ms 3. Power up VCCIO 4. Wait 50 ms. 5. Deassert reset 6. Wait 100 ms 7. Talk I2C With the "mutex" approach then when we try probing TS1 we'll violate TS2's specs (not enough delay between VCC and VCCIO). When we try probing TS2 we'll violate TS1's specs (not enough time between VCCIO and deasserting reset). With the a board-specific hardware manager we could know that, for all possible touchscreens on this board, we can always safely probe for them with: 1. Power up VCC 2. Wait 10 ms 3. Power up VCCIO 4. Wait 100 ms. 5. Deassert reset 6. Wait 100 ms 7. Talk I2C Once we've realized which touchscreen is actually present then all future power ons (like after suspend/resume) can be faster, but this would be safer for the initial probe. The above is not only safer but also more efficient. If, in the mutex case, we probed TS1 first but actually had TS2 then we'd spend 100 + 50 + 10 + 50 + 100 =3D 310 ms. With the hardware manager we'd probe for both touchscreens in step 7 and thus we'd only take 10 + 100 + 100 =3D 210 ms. The issue with the hardware manager is that we'd then run the normal driver probe and, unless we could somehow give it a hint, it would need to re-run through the power sequence again. In your other response you suggested that the normal driver could just detect that its regulator was already on and it could skip the regulator power sequence. I'm not convinced that's a reliable hint. If nothing else there are some boards the touchscreen regulator is shared and/or always-on but that doesn't mean someone has properly power sequenced the "reset" GPIO. I feel like we'd want a more explicit hint, but that's more something to solve in the Linux driver model and not something to solve in DT bindings. > > Ideally, though, this could somehow use device tree "overlays" I > > guess. That seems like almost a perfect fit. I guess the issue here, > > though, is that I'd want the overlays bundled together with the > > original DT and then the board-specific "hardware prober" driver to > > actually apply the overlays after probing. Does that seem sensible? > > BTW, there was an idea long ago from maintainer emeritus Likely to > append overlays to the base DTB for the kernel to apply. > > How would that help you here? Are you going to have an overlay for > each device that enables it? It's much easier to just call > of_update_property() to change "status". Ah, OK. Somehow I assumed that using overlays would be more palatable. If it's OK to just update the property then that seems fine to me. ...although one other reason I thought to use overlays is I think you mentioned there was code to make late-arriving devices probe, but I'm sure that can be handled. --- So I guess the overall summary is: I'm strongly leaning towards prototyping the "HW prober" approach. Hopefully that sounds OK. -Doug