Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp2813704rdb; Mon, 4 Dec 2023 08:12:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IEXQ3nQ5qUvRMQBgvgHgG/bB6rwGgRS1j4uqBP1PUrUw6CP427Tx/xuK6J8W+Rv+egFa3hF X-Received: by 2002:a05:6a21:6d90:b0:18f:97c:925a with SMTP id wl16-20020a056a216d9000b0018f097c925amr1686998pzb.63.1701706339480; Mon, 04 Dec 2023 08:12:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701706339; cv=none; d=google.com; s=arc-20160816; b=raY1kjUHwM7dZ92J9s3uiNII4S72hrIb7MYcKLpFpv2sDOTX4vJ2y3z4qAiuH8aDrS MHrenxY9bEwq7zjZqbOQoGiLBy/XXsEthycaXR6FizAuVV145TVwSPHWHca4WOMf6WPe sVGImHrZ4Xp8HIiYRzlJ4K55Ruymwxcoo9afk+I49zN86KfCNTG8fZQNA40ePEJIf8pC GJl5lSGwQ6QYDaBbun2aiaF5qJLpu/dzSM3GzBKMpxnXlvAwX+n7s7vrZu3zUp80zeOa /SbkvdnsfGFF8mOGXGY9lDBEpsVnwbpivlbDodhvWP6FGBmd00FQoSQ+caAJe2C+2EA9 1/RA== 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=7fXQC8kMEIVpKhirV/8r5WlQUD6sGUWR7e162LHNTZo=; fh=Q1RxP2X9paNZolKg3pHrtm4ZCcjmtQ/+ll8//m7K5u0=; b=uRZeWCdTBOOvrHoInZ4T9AAC06QBwPVdh2xCuOA2k1Eo7oorwpn7qjKK7BraJVIsRN TqoAfLkYiI/EK8sgF1ya237rre4E3aHiacJl5QsI10M2KOOb25ygT+RMABCwQlXYdQBA Gj49UhIasmIsaMVnpNjvYi8iZnfjzirP/qnqSNQwEXjLCJFDSXGw9j6bBg0pzolLS09m mIj29ANvJHKrbjloiVpQkEVoHMe9AJiHJ/zkFy2MDpFWDM1W+Y+or9Z/BcLTG016n+oo qzlbWeV4DPHtZyS1e7YrSmTgF8Ra11HzDBv+jZxxPPtWbBs+djw2K26pjHuoB8bxMInw /7Bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="JkF1c/+g"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id 17-20020a631651000000b005c66a7d710esi3541285pgw.456.2023.12.04.08.12.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 08:12:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="JkF1c/+g"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id C708C804E693; Mon, 4 Dec 2023 08:12:17 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234647AbjLDQMF (ORCPT + 99 others); Mon, 4 Dec 2023 11:12:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230496AbjLDQME (ORCPT ); Mon, 4 Dec 2023 11:12:04 -0500 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7EEB0A9 for ; Mon, 4 Dec 2023 08:12:10 -0800 (PST) Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-a00191363c1so642818266b.0 for ; Mon, 04 Dec 2023 08:12:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1701706329; x=1702311129; 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=7fXQC8kMEIVpKhirV/8r5WlQUD6sGUWR7e162LHNTZo=; b=JkF1c/+gqmha+kzmylcTB4/fxDTgiC54H+nE6/W8bBOmumeZIN6o2w3+LYujIZoK5F J1Q4TJWZ/usECYf/Jgem7UAY4XPjIN69hyEy7Gjw2LYfGX9EI0gRWzyj/qL4y5jiojEj PeSpaLFe0EQKuEaDuk1jt/p7FGrb8esrTDxNQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701706329; x=1702311129; 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=7fXQC8kMEIVpKhirV/8r5WlQUD6sGUWR7e162LHNTZo=; b=PFsqL2VPwF/IWzDGme4MTBgNuv9UOIm41ruWN40Ui3BpTbL33sOcKqKFY/UAlHKxjr xkBZ25Vnas2eSSEvDhvDJQrMFsuRrPpPptdJsjxSrzEWbiTANJXKUEIx4DwUIGCERcnK G3LB575xq/sm6t8MtCxoXr+3V/OUHBUsHcb3ets2+RgJAFywMk/KrPjL7nIWJe25Blw1 hpA9jY8hk2ZN+D2AxWzrdZ0A6VV7dmp6k2AUs6sOk5Dgc83MfIXmmbWtQAjGg3FvKjV7 6KNaqqqIDsemUfdq1AnVGVhQRJGF2N8rxpcau1H9iKT/zPjz4ftZk3EpqH35IT2F5tH0 a6iQ== X-Gm-Message-State: AOJu0YykvRIzrIOooEIv3oMKS2HQ6mK3/73tqsanygd9SXatkqfUp+zT 7j0/ADFC0UpWoXP8qYkICBM4BBb0pA2uV7D6VyC+ZLDw X-Received: by 2002:a17:907:1041:b0:a19:a1ba:bad3 with SMTP id oy1-20020a170907104100b00a19a1babad3mr1697903ejb.121.1701706328583; Mon, 04 Dec 2023 08:12:08 -0800 (PST) Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com. [209.85.208.45]) by smtp.gmail.com with ESMTPSA id h11-20020a17090634cb00b00a0f770ae91bsm5378250ejb.89.2023.12.04.08.12.08 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 Dec 2023 08:12:08 -0800 (PST) Received: by mail-ed1-f45.google.com with SMTP id 4fb4d7f45d1cf-54c77d011acso13991a12.1 for ; Mon, 04 Dec 2023 08:12:08 -0800 (PST) X-Received: by 2002:a50:99de:0:b0:54a:ee8b:7a99 with SMTP id n30-20020a5099de000000b0054aee8b7a99mr280850edb.0.1701705841514; Mon, 04 Dec 2023 08:04:01 -0800 (PST) MIME-Version: 1.0 References: <20231128084236.157152-1-wenst@chromium.org> <20231128084236.157152-3-wenst@chromium.org> In-Reply-To: From: Doug Anderson Date: Mon, 4 Dec 2023 08:03:44 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH v3 2/5] i2c: of: Introduce component probe function To: Chen-Yu Tsai Cc: Wolfram Sang , Rob Herring , Frank Rowand , Krzysztof Kozlowski , Conor Dooley , Matthias Brugger , AngeloGioacchino Del Regno , Benson Leung , Tzung-Bi Shih , chrome-platform@lists.linux.dev, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Johan Hovold , Hsin-Yi Wang , Dmitry Torokhov , andriy.shevchenko@linux.intel.com, Jiri Kosina , linus.walleij@linaro.org, broonie@kernel.org, gregkh@linuxfoundation.org, hdegoede@redhat.com, james.clark@arm.com, james@equiv.tech, keescook@chromium.org, rafael@kernel.org, tglx@linutronix.de, Jeff LaBundy , linux-input@vger.kernel.org, linux-i2c@vger.kernel.org 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,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 04 Dec 2023 08:12:17 -0800 (PST) Hi, On Mon, Dec 4, 2023 at 1:53=E2=80=AFAM Chen-Yu Tsai wr= ote: > > > IMO you should prototype how you're going to handle regulators and > > GPIOs before finalizing the design. I was going to write that you > > should just document that it was up to the caller to power things up > > before calling this function, but then I realized that the caller > > would have to duplicate much of this function in order to do so. In > > the very least they'd have to find the nodes of the relevant devices > > so that they could grab regulators and/or GPIOs. In order to avoid > > this duplication, would the design need to change? Perhaps this would > > be as simple as adding a callback function here that's called with all > > of the nodes before probing? If that's right, it would be nice to have > > that callback from the beginning so we don't need two variants of the > > function... > > So I think I can prototype designs with one GPIO and multiple regulators, > assuming each node has the same number of both? At least they should if > they're on the same connector. > > More than one GPIO probably means there are some ordering and timing > constraints, and won't be as generic. I was hoping to see a prototype of how this could work in the non-generic case where the board needed a custom function to power things up. It seems like we'd still want to be able to use your code for probing. > > > + for_each_child_of_node(i2c_node, node) { > > > + union i2c_smbus_data data; > > > + u32 addr; > > > + > > > + if (!of_node_name_prefix(node, type)) > > > + continue; > > > + if (of_property_read_u32(node, "reg", &addr)) > > > + continue; > > > + if (i2c_smbus_xfer(i2c, addr, 0, I2C_SMBUS_READ, 0, I= 2C_SMBUS_BYTE, &data) < 0) > > > > I'd be tempted to say that the caller should be able to pass in a > > function pointer here so they could use an alternative method to probe > > instead of i2c_smbus_xfer(), though you'd want to make it easy to > > default to i2c_smbus_xfer(). I could imagine someone might need a > > different way to probe. For instance if you had two touchscreens both > > at the same "reg" but that had different "hid-descr-addr" then this > > could be important. > > I'd say the only specific probable type is hid-i2c. And that could be > generic enough that we could incorporate it here if we wanted. However > I think we want to keep the initial version a bit simpler. I don't mind if the initial version is simpler, but I'd love to understand how this will grow. It doesn't feel terrible to take in a function pointer that will probe the device and then provide a function that callers could pass in that simply did the simple i2c_smbus_xfer(). > > > + continue; > > > + > > > > Put the "break" right here. You've found the device and that was the > > point of the loop. > > In its place we'd have an if (node) { } block. I guess it > makes it easier to read still? ...or perhaps an "if (!node) goto exit" block and then you don't need indentation? Essentially the loop becomes the implementation: "node =3D find_the_one_that_exists(...)". -Doug