From patchwork Thu Aug 8 09:59:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 13757186 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4A0BFC52D71 for ; Thu, 8 Aug 2024 10:00:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=NP++nqGZtSUGI7J35b2VGOlDWErcjczjXqKgEtz1Owk=; b=Ph3HqerSFejr+918+v/h6CU77A HgP7xlYVn08irThtQP98Ho/tRutxBGBnl8Mw+66jSbbXTyqZ5FdM9BxWN5dHvol/cPCHuNIcdqy9n ti+y3VjUvFVWPsdEDF03JuC9Is15HdlD+NscnzOE0X9IZ7Teb3Kclbb9rq/vdp2C/oz0Z5ZHJVCKT VoXIedUcDjLh7RPRBWiuP4nOJLY+fCRfIjAYWiTEDCdWKU0020kP488bUQKkVdl4fG60SGgUa+oYh hA1cd0HnxvXvPu1gpEuxzzq7C74Z8JWxlbhVXAKUeisBIazgz1xzcNdfBGV/VhpLt/7w18ZnSCwoA YKp5Hosw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbzwU-00000007oAR-2Mu3; Thu, 08 Aug 2024 10:00:22 +0000 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbzvu-00000007nze-0oXl for linux-arm-kernel@lists.infradead.org; Thu, 08 Aug 2024 09:59:47 +0000 Received: by mail-pg1-x529.google.com with SMTP id 41be03b00d2f7-7bd16405aa7so311056a12.3 for ; Thu, 08 Aug 2024 02:59:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1723111184; x=1723715984; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=NP++nqGZtSUGI7J35b2VGOlDWErcjczjXqKgEtz1Owk=; b=J9T2GUoHysoaGqIWvccF8Te+II5zWzmrJfg0eccTYS3T2IHb5dQydro9kZI6rB3jRk YwF4GfalcHuy7QxZ/XEkxugcGACTIhgNK6ssNRtDN+V1Ljlbx5575DkD40ICmyDSJIEL a4TvurhBraV5taqkKQfNav+JJiN/n26O5VQNw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723111184; x=1723715984; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=NP++nqGZtSUGI7J35b2VGOlDWErcjczjXqKgEtz1Owk=; b=QpuQtdTr+r38HYimpEV9OSwERJAB7eHVK7KoHKokgnl1wOj5fd8r/vVFoCgK9/HEG8 M1DwY5dWNMC25S+1QpETQ+KVlMJ0iMtDoc4QcnsHkk4MALaSsq+KRIZecXzDGIjTleOc f1dKnCzXGmfjUruXrkV4vDc6TrTEt8293RVvuCodFcjeIke5KwX4D2B2KKftPrq+cPvu ZXOz9enDSN/ZpqwgZI+IoO1EdZnKsVio7KZC+2SLZVG6y41+ztQdz78rlAmeJOm6J4vs CwshTHG0GwX19EeJC3sNbKbAHm2xeztmP1/fm2ku4u2+jSe+e/tLiCEHfCRlumyJ82+Q MUnw== X-Forwarded-Encrypted: i=1; AJvYcCXu7u7TFW4N3POas8lghPPeoMMd5mQN7CanRPAjrVpNH1f+8Hz8OXpteQQW0cKhWB32SfQlkOs28fc8/Dt8TDtv@lists.infradead.org X-Gm-Message-State: AOJu0YyM75W5Ft1BKhTH7kcSBhqgcljFB8lT2+F5kZHUIPp+6sgNjqRX P0ISFIKdgRA5LfawdoxJjo/ouEXj5hyPevnhYOz3ls4jbadK79+pEy9lasIVWQ== X-Google-Smtp-Source: AGHT+IHL9rv4DJSde7oadJWdI89Iu3rNnn3lai1eI+TVJJMzKxFKeEkjOe+alrLCoEqFD84PVNfHgw== X-Received: by 2002:a05:6a20:3945:b0:1c3:ba3d:3ec3 with SMTP id adf61e73a8af0-1c6fcf8133amr1257186637.36.1723111183924; Thu, 08 Aug 2024 02:59:43 -0700 (PDT) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:8b53:87e6:914:a00d]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ff59297707sm120784985ad.254.2024.08.08.02.59.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Aug 2024 02:59:43 -0700 (PDT) From: Chen-Yu Tsai To: Rob Herring , Saravana Kannan , Matthias Brugger , AngeloGioacchino Del Regno , Wolfram Sang , Benson Leung , Tzung-Bi Shih , Mark Brown , Liam Girdwood Cc: Chen-Yu Tsai , 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, Douglas Anderson , Johan Hovold , Jiri Kosina , Andy Shevchenko , linux-i2c@vger.kernel.org Subject: [PATCH v4 0/6] platform/chrome: Introduce DT hardware prober Date: Thu, 8 Aug 2024 17:59:23 +0800 Message-ID: <20240808095931.2649657-1-wenst@chromium.org> X-Mailer: git-send-email 2.46.0.rc2.264.g509ed76dc8-goog MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240808_025946_240738_753016E5 X-CRM114-Status: GOOD ( 27.35 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi everyone, This is v4 of my "of: Introduce hardware prober driver" [1] series. v4 mainly adds regulator and GPIO support. This part was separately tested on a MT8186 Voltorb device with a slightly device tree and an extra entry in the ChromeOS hardware prober. v2 continued Doug's "of: device: Support 2nd sources of probeable but undiscoverable devices" [2] series, but follows the scheme suggested by Rob, marking all second source component device nodes as "fail-needs-probe", and having a hardware prober driver enable the one of them. This time I trimmed down the Cc list. Changes since v3: - Patch 1 "of: dynamic: Add of_changeset_update_prop_string" - Use new __of_prop_free() helper (helper was added by Rob in 2024/04) - Add new line before header declaration - Patch 2 "regulator: Add regulator_of_get_optional() for pure DT" - New patch - Patch 3 "i2c: Introduce OF component probe function" - Complete kernel-doc - Return different error if I2C controller is disabled - Expand comment to explain assumptions and constraints - Split for-loop finding target node and operations on target node - Add missing i2c_put_adapter() - Move prober code to separate file - Patch 4 "i2c: of-prober: Add GPIO and regulator support" - New patch - Patch 5 "platform/chrome: Introduce device tree hardware prober" - Include linux/init.h - Rewrite for loop in driver probe function as suggested by Andy - Make prober driver buildable as module - Ignore prober errors other than probe deferral - Patch 6 "arm64: dts: mediatek: mt8173-elm-hana: Mark touchscreens and trackpads as fail" - Rebased Patch "arm64: dts: mediatek: mt8173-elm-hana: Add G2touch G7500 touchscreen" was merged separately and thus removed from this series. Changes since v2: - Added of_changeset_update_prop_string() - Moved generic I2C code to the I2C core - Moved remaining platform specific code to platform/chrome/ - Switched to of_node_is_available() to check if node is enabled. - Switched to OF changeset API to update status property - I2C probe helper function now accepts "struct device *dev" instead to reduce line length and dereferences - Moved "ret = 0" to just before for_each_child_of_node(i2c_node, node) - Depend on rather than select CONFIG_I2C - Copied machine check to driver init function - Explicitly mentioned "device tree" or OF in driver name, description and Kconfig symbol - Dropped filename from inside the file - Made loop variable size_t (instead of unsigned int as Andy asked) - Switched to PLATFORM_DEVID_NONE instead of raw -1 - Switched to standard goto error path pattern in hw_prober_driver_init() - Dropped device class from status property Patches removed from v3 and saved for later: - of: base: Add of_device_is_fail - of: hw_prober: Support Chromebook SKU ID based component selection - dt-bindings: arm: mediatek: Remove SKU specific compatibles for Google Krane - arm64: dts: mediatek: mt8183-kukui: Merge Krane device trees For the I2C component (touchscreens and trackpads) case from the original series, the hardware prober driver finds the particular class of device in the device tree, gets its parent I2C adapter, and tries to initiate a simple I2C read for each device under that I2C bus. When it finds one that responds, it considers that one present, marks it as "okay", and returns, letting the driver core actually probe the device. This works fine in most cases since these components are connected via a ribbon cable and always have the same resources. The prober will also grab these resources and enable them. The other case, selecting a display panel to use based on the SKU ID from the firmware, hit a bit of an issue with fixing the OF graph. It has been left out since v3. Patch 1 adds of_changeset_update_prop_string(), as requested by Rob. Patch 2 adds a function for retrieving regulator supplies solely using device tree nodes. Patch 3 implements probing the I2C bus for presence of components as a helper function in the I2C core. Patch 4 implements regulator supply and GPIO support for the I2C component prober. Patch 5 adds a ChromeOS specific DT hardware prober. This initial version targets the Hana Chromebooks, probing its I2C trackpads and touchscreens. Patch 6 modifies the Hana device tree and marks the touchscreens and trackpads as "fail-needs-probe", ready for the driver to probe. Assuming this is acceptable to folks, because there are compile time dependencies, I think it would be easier for the code bits (patches 1 through 4) to go through either the OF tree or I2C tree. Patches 5 and 6 can go through the soc tree via the mediatek tree. Thanks ChenYu Chen-Yu Tsai (6): of: dynamic: Add of_changeset_update_prop_string regulator: Add regulator_of_get_optional() for pure DT regulator lookup i2c: Introduce OF component probe function i2c: of-prober: Add GPIO and regulator support platform/chrome: Introduce device tree hardware prober arm64: dts: mediatek: mt8173-elm-hana: Mark touchscreens and trackpads as fail .../boot/dts/mediatek/mt8173-elm-hana.dtsi | 13 + arch/arm64/boot/dts/mediatek/mt8173-elm.dtsi | 4 +- drivers/i2c/Makefile | 1 + drivers/i2c/i2c-core-of-prober.c | 425 ++++++++++++++++++ drivers/of/dynamic.c | 44 ++ drivers/platform/chrome/Kconfig | 11 + drivers/platform/chrome/Makefile | 1 + .../platform/chrome/chromeos_of_hw_prober.c | 107 +++++ drivers/regulator/core.c | 81 +++- drivers/regulator/devres.c | 2 +- drivers/regulator/internal.h | 2 +- include/linux/i2c.h | 4 + include/linux/of.h | 4 + include/linux/regulator/consumer.h | 8 + 14 files changed, 681 insertions(+), 26 deletions(-) create mode 100644 drivers/i2c/i2c-core-of-prober.c create mode 100644 drivers/platform/chrome/chromeos_of_hw_prober.c