From patchwork Thu Nov 9 10:05:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 1861905 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=RxQLjM2b; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45d1:ec00::1; helo=ny.mirrors.kernel.org; envelope-from=devicetree+bounces-14773-incoming-dt=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [IPv6:2604:1380:45d1:ec00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SQyKk18FNz1yQK for ; Thu, 9 Nov 2023 21:06:50 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 6609B1C20B9D for ; Thu, 9 Nov 2023 10:06:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A2DCE14A83; Thu, 9 Nov 2023 10:06:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="RxQLjM2b" X-Original-To: devicetree@vger.kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0887113FE3 for ; Thu, 9 Nov 2023 10:06:45 +0000 (UTC) Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5EA662D51 for ; Thu, 9 Nov 2023 02:06:45 -0800 (PST) Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1cc53d0030fso6522205ad.0 for ; Thu, 09 Nov 2023 02:06:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1699524405; x=1700129205; darn=vger.kernel.org; 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=DGm2vHynu/hBFToljMIoyOJ5nVIf243JSwQjqrxxy/0=; b=RxQLjM2bpQKhpTuVZYebaJEIhWTLLYFe2dDFIchDI28Yf0eDype1TS7wThG0GTEenH qlbre4oclTVVYs6pRFJZ2NZVUOLMadbJhxKxUTln0w8sak6nNsXVQZ1gKipnx0fun9E7 3+T8Fnpl1WI07B0G3Cylkf8Qs3GBiwsmN7Wz4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699524405; x=1700129205; 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=DGm2vHynu/hBFToljMIoyOJ5nVIf243JSwQjqrxxy/0=; b=QvAp15znK07uSNF1xgABNNosDy2Pe4SoBqXS25xE1mEGquD9ysNduoGv0Xzk/pE/c9 Td5KsITwIY/OmmCOEBE+1jN+DXur22f++1fKmSuTfkB3XR6twGYp3lvnRKNojI/Sazhu Ye4mMv4ao/3rxSSEf7mBeqr39sLaGLYak1lxhUGHz7X8iNv+5+AehZnrv+sVyPHgKhya hLJ8qviVNwjXlT6nCiXEl57q9E1V2J5OsLV2voeYNITEMbyUOOQTGCixePhR4vVG/N0o dYFy+WCib+pQHkIv4PNCI7NljqLjBQGcJMEgALT3uHMef2mSOBbvjWr1c6ZqxiofPyho qdXA== X-Gm-Message-State: AOJu0Yxgvy+n8t/8LrdfNXE9jFaWHyBoXpjr1O6WSo6o8ILiNyODsusv c7r783WNl75dWiFTVt6NIQqIvA== X-Google-Smtp-Source: AGHT+IFiKBNutMsj7ANOubArOU/tBBm0unUxGA8equMZgzL/JO0wpYcbiQ5Wq/R+556TKcVcpFKnlQ== X-Received: by 2002:a17:902:ec89:b0:1cc:436f:70c2 with SMTP id x9-20020a170902ec8900b001cc436f70c2mr7534166plg.9.1699524404876; Thu, 09 Nov 2023 02:06:44 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:6f57:d4c:468c:5daf]) by smtp.gmail.com with ESMTPSA id c13-20020a170902d48d00b001c60ba709b7sm3127511plg.125.2023.11.09.02.06.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 02:06:44 -0800 (PST) From: Chen-Yu Tsai To: Rob Herring , Frank Rowand , Krzysztof Kozlowski , Conor Dooley , Matthias Brugger , AngeloGioacchino Del Regno Cc: 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, petr.tesarik.ext@huawei.com, rafael@kernel.org, tglx@linutronix.de, Jeff LaBundy , linux-input@vger.kernel.org, Chen-Yu Tsai , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Douglas Anderson , Johan Hovold Subject: [RFC PATCH v2 1/7] of: base: Add of_device_is_fail Date: Thu, 9 Nov 2023 18:05:58 +0800 Message-ID: <20231109100606.1245545-2-wenst@chromium.org> X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog In-Reply-To: <20231109100606.1245545-1-wenst@chromium.org> References: <20231109100606.1245545-1-wenst@chromium.org> Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In some cases we want to check that a device is not only unavailable, but specifically marked as "fail". This will be used in a following change in the hardware prober driver. Signed-off-by: Chen-Yu Tsai --- drivers/of/base.c | 20 ++++++++++++++++++++ include/linux/of.h | 6 ++++++ 2 files changed, 26 insertions(+) diff --git a/drivers/of/base.c b/drivers/of/base.c index 8d93cb6ea9cd..2726e5dce1bf 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -486,6 +486,26 @@ static bool __of_device_is_fail(const struct device_node *device) return !strcmp(status, "fail") || !strncmp(status, "fail-", 5); } +/** + * of_device_is_fail - check if a device has status "fail" or "fail-..." + * + * @device: Node to check status for + * + * Return: True if the status property is set to "fail" or "fail-..." (for any + * error code suffix), false otherwise + */ +bool of_device_is_fail(const struct device_node *device) +{ + unsigned long flags; + bool res; + + raw_spin_lock_irqsave(&devtree_lock, flags); + res = __of_device_is_fail(device); + raw_spin_unlock_irqrestore(&devtree_lock, flags); + return res; +} +EXPORT_SYMBOL(of_device_is_fail); + /** * of_device_is_big_endian - check if a device has BE registers * diff --git a/include/linux/of.h b/include/linux/of.h index 6a9ddf20e79a..463fbf0072bd 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -350,6 +350,7 @@ extern int of_device_is_compatible(const struct device_node *device, extern int of_device_compatible_match(const struct device_node *device, const char *const *compat); extern bool of_device_is_available(const struct device_node *device); +extern bool of_device_is_fail(const struct device_node *device); extern bool of_device_is_big_endian(const struct device_node *device); extern const void *of_get_property(const struct device_node *node, const char *name, @@ -584,6 +585,11 @@ static inline bool of_device_is_available(const struct device_node *device) return false; } +static inline bool of_device_is_fail(const struct device_node *device) +{ + return false; +} + static inline bool of_device_is_big_endian(const struct device_node *device) { return false; From patchwork Thu Nov 9 10:05:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 1861906 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=hZBMy4UD; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45e3:2400::1; helo=sv.mirrors.kernel.org; envelope-from=devicetree+bounces-14774-incoming-dt=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [IPv6:2604:1380:45e3:2400::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SQyKx2jTtz1yQK for ; Thu, 9 Nov 2023 21:07:01 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id C6104281316 for ; Thu, 9 Nov 2023 10:06:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F089615EA2; Thu, 9 Nov 2023 10:06:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="hZBMy4UD" X-Original-To: devicetree@vger.kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CFC2013FE3 for ; Thu, 9 Nov 2023 10:06:50 +0000 (UTC) Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5097530C5 for ; Thu, 9 Nov 2023 02:06:50 -0800 (PST) Received: by mail-pg1-x532.google.com with SMTP id 41be03b00d2f7-5bda105206fso535076a12.3 for ; Thu, 09 Nov 2023 02:06:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1699524410; x=1700129210; darn=vger.kernel.org; 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=t5ye6xQE9knRoa1If0NJpRXCWT7E3YY80pCdkZR9RUU=; b=hZBMy4UDuygUobGSPbCJdhb96NSnsSTjP2nF6QnsG8V12c3KKo1pIJGq9xtZ7CzMzY sphs0p80O7vxqDIuBLcl+hRtdFJL03cgV2gegaHWB213UJhwgOSwZaUZi1lFIzORVff0 QZyTC2jQNVjSP1hJ5OG/14Q6vcmTeKlec3gqc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699524410; x=1700129210; 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=t5ye6xQE9knRoa1If0NJpRXCWT7E3YY80pCdkZR9RUU=; b=jrTChpns34sKNZygcvYxe5Bg0k0n0tpBb0T0Zqt3PoEt6bmT3/j3SNwCPEwFxNpWRB 3q622DGZiL9PZ7DzBmTgfDUCWPtRsh2Em6QCmgdYM7CMQiUqnvacS+6T/o8hnOpmzGX3 M0Y4EgCyThQD1PxG0eI1yC+aPzy9c+Hx0f1jdg/28/PdMhUKW+YhM1LDTeWvObybCgwR 031/WCId1ZiT19Pr0C3EXr1uDfYXwMU6dsjJsjoeXBgYUDBse393C7t/JjZzJvIGyjZa G8qsmJFQG1WwlcMYbr97fT02bCQFeHSUhmhYutb4DaBA24aTrXj7iCVxE27lYTJJNwb3 UpYw== X-Gm-Message-State: AOJu0YzIIq+cm27LWGRAIcOuk1dWZ/VEN7jLBA/J7ww1A5CPWhgsXLu7 +X5/MKc/+KfPzJeJNmMVGdk0fg== X-Google-Smtp-Source: AGHT+IHfRhp6aSHaPlAD6Z0UbsTUInpZ/6xri+wdrZK5r1MjtzbG8S3+Ea6iHjo67SKMt6d5dpyRgA== X-Received: by 2002:a17:902:8c83:b0:1cc:2c45:757a with SMTP id t3-20020a1709028c8300b001cc2c45757amr4475248plo.10.1699524409702; Thu, 09 Nov 2023 02:06:49 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:6f57:d4c:468c:5daf]) by smtp.gmail.com with ESMTPSA id c13-20020a170902d48d00b001c60ba709b7sm3127511plg.125.2023.11.09.02.06.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 02:06:49 -0800 (PST) From: Chen-Yu Tsai To: Rob Herring , Frank Rowand , Krzysztof Kozlowski , Conor Dooley , Matthias Brugger , AngeloGioacchino Del Regno Cc: 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, petr.tesarik.ext@huawei.com, rafael@kernel.org, tglx@linutronix.de, Jeff LaBundy , linux-input@vger.kernel.org, Chen-Yu Tsai , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Douglas Anderson , Johan Hovold Subject: [RFC PATCH v2 2/7] of: Introduce hardware prober driver Date: Thu, 9 Nov 2023 18:05:59 +0800 Message-ID: <20231109100606.1245545-3-wenst@chromium.org> X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog In-Reply-To: <20231109100606.1245545-1-wenst@chromium.org> References: <20231109100606.1245545-1-wenst@chromium.org> Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Some devices are designed and manufactured with some components having multiple drop-in replacement options. These components are often connected to the mainboard via ribbon cables, having the same signals and pin assignments across all options. These may include the display panel and touchscreen on laptops and tablets, and the trackpad on laptops. Sometimes which component option is used in a particular device can be detected by some firmware provided identifier, other times that information is not available, and the kernel has to try to probe each device. This change attempts to make the "probe each device" case cleaner. The current approach is to have all options added and enabled in the device tree. The kernel would then bind each device and run each driver's probe function. This works, but has been broken before due to the introduction of asynchronous probing, causing multiple instances requesting "shared" resources, such as pinmuxes, GPIO pins, interrupt lines, at the same time, with only one instance succeeding. Work arounds for these include moving the pinmux to the parent I2C controller, using GPIO hogs or pinmux settings to keep the GPIO pins in some fixed configuration, and requesting the interrupt line very late. Such configurations can be seen on the MT8183 Krane Chromebook tablets, and the Qualcomm sc8280xp-based Lenovo Thinkpad 13S. Instead of this delicate dance between drivers and device tree quirks, this change introduces a simple I2C component prober. For any given class of devices on the same I2C bus, it will go through all of them, doing a simple I2C read transfer and see which one of them responds. It will then enable the device that responds. This requires some minor modifications in the existing device tree. The status for all the device nodes for the component options must be set to "failed-needs-probe-xxx". This makes it clear that some mechanism is needed to enable one of them, and also prevents the prober and device drivers running at the same time. Signed-off-by: Chen-Yu Tsai --- drivers/of/Kconfig | 13 ++++ drivers/of/Makefile | 1 + drivers/of/hw_prober.c | 154 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 168 insertions(+) create mode 100644 drivers/of/hw_prober.c diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig index da9826accb1b..269d20d51936 100644 --- a/drivers/of/Kconfig +++ b/drivers/of/Kconfig @@ -102,4 +102,17 @@ config OF_OVERLAY config OF_NUMA bool +config HW_PROBER + bool "Hardware Prober driver" + select I2C + select OF_DYNAMIC + help + Some devices will have multiple drop-in options for one component. + In many cases the different options are indistinguishable by the + kernel without actually probing each possible option. + + This driver is meant to handle the probing of such components, and + update the running device tree such that the correct variant is + made available. + endif # OF diff --git a/drivers/of/Makefile b/drivers/of/Makefile index eff624854575..ed3875cdc554 100644 --- a/drivers/of/Makefile +++ b/drivers/of/Makefile @@ -12,6 +12,7 @@ obj-$(CONFIG_OF_RESERVED_MEM) += of_reserved_mem.o obj-$(CONFIG_OF_RESOLVE) += resolver.o obj-$(CONFIG_OF_OVERLAY) += overlay.o obj-$(CONFIG_OF_NUMA) += of_numa.o +obj-$(CONFIG_HW_PROBER) += hw_prober.o ifdef CONFIG_KEXEC_FILE ifdef CONFIG_OF_FLATTREE diff --git a/drivers/of/hw_prober.c b/drivers/of/hw_prober.c new file mode 100644 index 000000000000..442da6eff896 --- /dev/null +++ b/drivers/of/hw_prober.c @@ -0,0 +1,154 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * hw_prober.c - Hardware prober driver + * + * Copyright (c) 2023 Google LLC + */ + +#include +#include +#include +#include + +#define DRV_NAME "hw_prober" + +/** + * struct hw_prober_entry - Holds an entry for the hardware prober + * + * @compatible: compatible string to match against the machine + * @prober: prober function to call when machine matches + * @data: extra data for the prober function + */ +struct hw_prober_entry { + const char *compatible; + int (*prober)(struct platform_device *pdev, const void *data); + const void *data; +}; + +/* + * Some devices, such as Google Hana Chromebooks, are produced by multiple + * vendors each using their preferred components. This prober assumes such + * drop-in parts are on dedicated I2C busses, have non-conflicting addresses, + * and can be directly probed by seeing which address responds without needing + * regulators or GPIOs being enabled or toggled. + */ +static int i2c_component_prober(struct platform_device *pdev, const void *data) +{ + const char *node_name = data; + struct device_node *node, *i2c_node; + struct i2c_adapter *i2c; + int ret = 0; + + node = of_find_node_by_name(NULL, node_name); + if (!node) + return dev_err_probe(&pdev->dev, -ENODEV, "Could not find %s device node\n", + node_name); + + i2c_node = of_get_next_parent(node); + if (strcmp(i2c_node->name, "i2c")) { + of_node_put(i2c_node); + return dev_err_probe(&pdev->dev, -EINVAL, "%s device isn't on I2C bus\n", + node_name); + } + + for_each_child_of_node(i2c_node, node) { + if (!of_node_name_prefix(node, node_name)) + continue; + if (!of_device_is_fail(node)) { + /* device tree has component already enabled */ + of_node_put(node); + of_node_put(i2c_node); + return 0; + } + } + + i2c = of_get_i2c_adapter_by_node(i2c_node); + if (!i2c) { + of_node_put(i2c_node); + return dev_err_probe(&pdev->dev, -EPROBE_DEFER, "Couldn't get I2C adapter\n"); + } + + for_each_child_of_node(i2c_node, node) { + struct property *prop; + union i2c_smbus_data data; + u32 addr; + + if (!of_node_name_prefix(node, node_name)) + continue; + if (of_property_read_u32(node, "reg", &addr)) + continue; + if (i2c_smbus_xfer(i2c, addr, 0, I2C_SMBUS_READ, 0, I2C_SMBUS_BYTE, &data) < 0) + continue; + + dev_info(&pdev->dev, "Enabling %pOF\n", node); + + prop = kzalloc(sizeof(*prop), GFP_KERNEL); + if (!prop) { + ret = -ENOMEM; + of_node_put(node); + break; + } + + prop->name = "status"; + prop->length = 5; + prop->value = "okay"; + + /* Found a device that is responding */ + ret = of_update_property(node, prop); + if (ret) + kfree(prop); + + of_node_put(node); + break; + } + + i2c_put_adapter(i2c); + of_node_put(i2c_node); + + return ret; +} + +static const struct hw_prober_entry hw_prober_platforms[] = { + { .compatible = "google,hana", .prober = i2c_component_prober, .data = "touchscreen" }, + { .compatible = "google,hana", .prober = i2c_component_prober, .data = "trackpad" }, +}; + +static int hw_prober_probe(struct platform_device *pdev) +{ + for (int i = 0; i < ARRAY_SIZE(hw_prober_platforms); i++) + if (of_machine_is_compatible(hw_prober_platforms[i].compatible)) { + int ret; + + ret = hw_prober_platforms[i].prober(pdev, hw_prober_platforms[i].data); + if (ret) + return ret; + } + + return 0; +} + +static struct platform_driver hw_prober_driver = { + .probe = hw_prober_probe, + .driver = { + .name = DRV_NAME, + }, +}; + +static int __init hw_prober_driver_init(void) +{ + struct platform_device *pdev; + int ret; + + ret = platform_driver_register(&hw_prober_driver); + if (ret) + return ret; + + pdev = platform_device_register_simple(DRV_NAME, -1, NULL, 0); + if (!IS_ERR(pdev)) + return 0; + + platform_driver_unregister(&hw_prober_driver); + + return PTR_ERR(pdev); +} +device_initcall(hw_prober_driver_init); From patchwork Thu Nov 9 10:06:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 1861907 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=HAkuhHb7; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:40f1:3f00::1; helo=sy.mirrors.kernel.org; envelope-from=devicetree+bounces-14777-incoming-dt=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org [IPv6:2604:1380:40f1:3f00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SQyL800T7z1yQK for ; Thu, 9 Nov 2023 21:07:11 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 96DE1B20A9A for ; Thu, 9 Nov 2023 10:07:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AA694156C1; Thu, 9 Nov 2023 10:07:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="HAkuhHb7" X-Original-To: devicetree@vger.kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CCDD013FE3 for ; Thu, 9 Nov 2023 10:07:04 +0000 (UTC) Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77CAB30E0 for ; Thu, 9 Nov 2023 02:07:04 -0800 (PST) Received: by mail-pg1-x52a.google.com with SMTP id 41be03b00d2f7-565334377d0so563746a12.2 for ; Thu, 09 Nov 2023 02:07:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1699524424; x=1700129224; darn=vger.kernel.org; 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=Rs4qbwNofKphTE2zreJeFqCc6xRNAsKGF5LoBHdl0a8=; b=HAkuhHb7SzSz6OhGNf394Dui6jFOjbDVL3coBmNzq37xaektQl4rJtUPvTlaBeB42p q+As9HodIdDYp7KbqaNKRJTu1ASdCL5Fs1DdUMHs5q/gYAUtIuu2QVd5jVlYsoRlPPyL fpUw1CLXQhgPD3R7s6HFUjMFYsN+RuzDmDWk0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699524424; x=1700129224; 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=Rs4qbwNofKphTE2zreJeFqCc6xRNAsKGF5LoBHdl0a8=; b=bOX2OWimfvY9hcuIcDBKfPAJRjERrAF9P6Iam2bViYzbbh8NTp+OL7PcZKetL8p9We NbjLgtT2EQ01m+GqkXXrUwDzy3J3dWVWuZfjWel4N31EjQ24cPVX5zi7fpY++mc5uasO FU4yvUqeDDF+kJRPOstqHW1oBisFJDU0PCPis3AsyEjeSNGienoyGMRUvTuUaT/UVMeg 1wJcbCgh5H3nP4IMShnAvfvbjiGf+6ftpDf97PA9TEgdivmM3HOyvvb4ISCa1RvvfQp5 NILN/DrC4vMSj7uXjZXJN+c9bVPau3iCINQuznhmDyCuOezaTU2uPk1iWf/a9RU32UiE a9eg== X-Gm-Message-State: AOJu0YxS+N/d5cMxIUsGLXlC400DxqlBu8aiZfg/F0ltfYw0/L1XJOiw Q1edzKRvOnxngjlngS7en7v0Pw== X-Google-Smtp-Source: AGHT+IHWUtsr4bhvzCEP1VHdQwxeHKMo7QV044imQ44mdSODoeojv4KtXVlrqKklo16HOdu2p0mAvw== X-Received: by 2002:a17:902:f807:b0:1c9:b2c1:139c with SMTP id ix7-20020a170902f80700b001c9b2c1139cmr4180478plb.62.1699524423943; Thu, 09 Nov 2023 02:07:03 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:6f57:d4c:468c:5daf]) by smtp.gmail.com with ESMTPSA id c13-20020a170902d48d00b001c60ba709b7sm3127511plg.125.2023.11.09.02.06.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 02:07:03 -0800 (PST) From: Chen-Yu Tsai To: Rob Herring , Frank Rowand , Krzysztof Kozlowski , Conor Dooley , Matthias Brugger , AngeloGioacchino Del Regno Cc: 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, petr.tesarik.ext@huawei.com, rafael@kernel.org, tglx@linutronix.de, Jeff LaBundy , linux-input@vger.kernel.org, Chen-Yu Tsai , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Douglas Anderson , Johan Hovold Subject: [RFC PATCH v2 5/7] of: hw_prober: Support Chromebook SKU ID based component selection Date: Thu, 9 Nov 2023 18:06:02 +0800 Message-ID: <20231109100606.1245545-6-wenst@chromium.org> X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog In-Reply-To: <20231109100606.1245545-1-wenst@chromium.org> References: <20231109100606.1245545-1-wenst@chromium.org> Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In cases where the same Chromebook model is manufactured with different components (MIPI DSI panels, MIPI CSI camera sensors, or trackpad / touchscreens with conflicting addresses), a different SKU ID is allocated to each specific combination. This SKU ID is exported by the bootloader into the device tree, and can be used to "discover" which combination is present on the current machine. This change adds a hardware prober that will match the SKU ID against a provided table, and enable the component for the matched entry based on the given compatible string. In the MIPI DSI panel and MIPI CSI camera sensor cases which have OF graphs, it will also update the remote endpoint to point to the enabled component. This assumes a single endpoint only. This will provide a path to reducing the number of Chromebook device trees. Signed-off-by: Chen-Yu Tsai --- drivers/of/hw_prober.c | 160 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) diff --git a/drivers/of/hw_prober.c b/drivers/of/hw_prober.c index 442da6eff896..4345e5aed6d8 100644 --- a/drivers/of/hw_prober.c +++ b/drivers/of/hw_prober.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #define DRV_NAME "hw_prober" @@ -108,9 +109,168 @@ static int i2c_component_prober(struct platform_device *pdev, const void *data) return ret; } +static int cros_get_coreboot_sku_id(struct device *dev, u32 *sku_id) +{ + struct device_node *node = NULL; + int ret; + + node = of_find_node_by_path("/firmware/coreboot"); + if (!node) + return dev_err_probe(dev, -EINVAL, "Cannot find coreboot firmware node\n"); + + ret = of_property_read_u32(node, "sku-id", sku_id); + if (ret) + dev_err_probe(dev, ret, "Cannot get SKU ID\n"); + + of_node_put(node); + return ret; +} + +struct cros_sku_option { + u32 sku_id_val; + u32 sku_id_mask; + const char *compatible; +}; + +struct cros_sku_component_data { + const struct cros_sku_option *options; + int num_options; +}; + +/* + * cros_sku_component_selector - Selectively enable a component based on SKU ID + * + * Based on the list of component options and SKU ID read back from the device + * tree, enable the matching component. Also update the OF graph if it exists, + * so that the enabled component's remote endpoint correctly points to it. This + * assumes a single local endpoint, which should be the case for panels and + * camera sensors. + */ +static int cros_sku_component_selector(struct platform_device *pdev, const void *data) +{ + const struct cros_sku_component_data *pdata = data; + const char *compatible; + struct device_node *node = NULL, *endpoint = NULL, *remote = NULL; + struct property *status_prop = NULL, *endpoint_prop = NULL; + struct of_changeset *ocs = NULL; + __be32 *val = NULL; + int ret, i; + u32 sku_id; + + if (!data) + return dev_err_probe(&pdev->dev, -EINVAL, "No data given\n"); + + ret = cros_get_coreboot_sku_id(&pdev->dev, &sku_id); + if (ret) + return ret; + + for (i = 0; i < pdata->num_options; i++) + if ((sku_id & pdata->options[i].sku_id_mask) == pdata->options[i].sku_id_val) { + compatible = pdata->options->compatible; + break; + } + + if (i == pdata->num_options) + return dev_err_probe(&pdev->dev, -EINVAL, "Unknown SKU ID: 0x%x\n", sku_id); + + node = of_find_compatible_node(NULL, NULL, compatible); + if (!node) + return dev_err_probe(&pdev->dev, -ENODEV, "Cannot find matching device node\n"); + + /* device node not marked as fail; don't mess with the device tree */ + if (!of_device_is_fail(node)) + goto err_free; + + dev_info(&pdev->dev, "Enabling %pOF for SKU 0x%x\n", node, sku_id); + + ret = -ENOMEM; + ocs = kzalloc(sizeof(*ocs), GFP_KERNEL); + if (!ocs) + goto err_free; + + status_prop = kzalloc(sizeof(*status_prop), GFP_KERNEL); + if (!status_prop) + goto err_free; + + status_prop->name = "status"; + status_prop->length = 5; + status_prop->value = "okay"; + + /* Create changeset to apply DT changes atomically */ + of_changeset_init(ocs); + + if (of_graph_is_present(node)) { + ret = -EINVAL; + + /* This currently assumes a single port on the component. */ + endpoint = of_graph_get_next_endpoint(node, NULL); + if (!endpoint) { + dev_err(&pdev->dev, "No endpoint found for %pOF\n", node); + goto err_destroy_ocs; + } + + remote = of_graph_get_remote_endpoint(endpoint); + if (!remote) { + dev_err(&pdev->dev, "No remote endpoint node found for %pOF\n", endpoint); + goto err_destroy_ocs; + } + + endpoint_prop = kzalloc(sizeof(*endpoint_prop), GFP_KERNEL); + if (!endpoint_prop) + goto err_destroy_ocs; + + val = kzalloc(sizeof(*val), GFP_KERNEL); + if (!val) + goto err_destroy_ocs; + + *val = cpu_to_be32(endpoint->phandle); + endpoint_prop->name = "remote-endpoint"; + endpoint_prop->length = sizeof(*val); + endpoint_prop->value = val; + + ret = of_changeset_update_property(ocs, node, endpoint_prop); + if (ret) + goto err_destroy_ocs; + } + + ret = of_changeset_update_property(ocs, node, status_prop); + if (ret) + goto err_destroy_ocs; + ret = of_changeset_apply(ocs); + if (ret) + goto err_destroy_ocs; + + of_node_put(node); + + return 0; + +err_destroy_ocs: + of_node_put(remote); + of_node_put(endpoint); + kfree(val); + kfree(endpoint_prop); + of_changeset_destroy(ocs); +err_free: + kfree(ocs); + kfree(status_prop); + of_node_put(node); + return ret; +} + +static const struct cros_sku_option cros_krane_panel_options[] = { + { .sku_id_val = 0x00, .sku_id_mask = 0xf0, .compatible = "auo,kd101n80-45na" }, + { .sku_id_val = 0xb0, .sku_id_mask = 0xf0, .compatible = "boe,tv101wum-nl6" }, +}; + +static const struct cros_sku_component_data cros_krane_panel_data = { + .options = cros_krane_panel_options, + .num_options = ARRAY_SIZE(cros_krane_panel_options), +}; + static const struct hw_prober_entry hw_prober_platforms[] = { { .compatible = "google,hana", .prober = i2c_component_prober, .data = "touchscreen" }, { .compatible = "google,hana", .prober = i2c_component_prober, .data = "trackpad" }, + { .compatible = "google,krane", .prober = cros_sku_component_selector, .data = &cros_krane_panel_data }, }; static int hw_prober_probe(struct platform_device *pdev) From patchwork Thu Nov 9 10:06:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 1861908 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=V+U3PVkf; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:40f1:3f00::1; helo=sy.mirrors.kernel.org; envelope-from=devicetree+bounces-14778-incoming-dt=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org [IPv6:2604:1380:40f1:3f00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SQyL93hNqz1yRQ for ; Thu, 9 Nov 2023 21:07:13 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 443C2B20D33 for ; Thu, 9 Nov 2023 10:07:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4436C156FD; Thu, 9 Nov 2023 10:07:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="V+U3PVkf" X-Original-To: devicetree@vger.kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ACA7313FE3 for ; Thu, 9 Nov 2023 10:07:09 +0000 (UTC) Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C7D73252 for ; Thu, 9 Nov 2023 02:07:09 -0800 (PST) Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1cc1ee2d8dfso6248335ad.3 for ; Thu, 09 Nov 2023 02:07:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1699524428; x=1700129228; darn=vger.kernel.org; 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=0ireTpCfN0lAkDpS22SoHjbEWTJUzLlFEUnZESQj8kY=; b=V+U3PVkfF5uxOrXpN8BVULqi55XRpztj0ymrjnICLVyJmKd10JQNEw0fITvjirFT0S kik+ceQR3+ctMCdte0jR42wXZWRkoVmrmRqVtcCGiAdVfi/krDrfZC9zTyL2/U0yP2EW xRwymNhHUdCT7ZuaIklIrRPeOvpXWr5Vn05ZY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699524428; x=1700129228; 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=0ireTpCfN0lAkDpS22SoHjbEWTJUzLlFEUnZESQj8kY=; b=pn2qmMnyfVwDUuaUBPXHQvv/I+A7+O+/fxylLMVxixk9nqe0CGxxQjOYoiwVkthNON Pi6PDaCrZjJtSxtg9t5AF2+gxeyJzQZahSXr604qHJqD1cJRJ0pEKQJmyU7FtPoKwki1 gTfdXqQW9ODdHCY58bBbaEMU1rjsiGwDgOsksevoSbdx5A7gRr3K5pkdqiWm5doIQj8y OUBnze92NpA+5jVSLB5faUF6XdGCyekvHVM6cMWJ3jo4mndzAurgqiddikWjZ4XnmSJM kFO9FFLdNPwkPDiclXt5Non63SYz20bIDddMrYzXtc/EBXTpCNMbjCmmEholHX9jb37J Ik6g== X-Gm-Message-State: AOJu0Yx6jgZfjvkYiFCsOG3HEVv/teznRAZx+0OV7aCZIxOUriOzRKtL bcf8lxbcsV/hN7xiutcHTiUe4Q== X-Google-Smtp-Source: AGHT+IFYLvEMMUZ9GrbH908WNtQJvicj83HyjofOmfRWFZrCflNz7TaOuy+rHHNosFSsiJ8aNjo+JQ== X-Received: by 2002:a17:902:ecc1:b0:1cc:2ed0:5ab1 with SMTP id a1-20020a170902ecc100b001cc2ed05ab1mr5039394plh.17.1699524428617; Thu, 09 Nov 2023 02:07:08 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:6f57:d4c:468c:5daf]) by smtp.gmail.com with ESMTPSA id c13-20020a170902d48d00b001c60ba709b7sm3127511plg.125.2023.11.09.02.07.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 02:07:08 -0800 (PST) From: Chen-Yu Tsai To: Rob Herring , Frank Rowand , Krzysztof Kozlowski , Conor Dooley , Matthias Brugger , AngeloGioacchino Del Regno Cc: 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, petr.tesarik.ext@huawei.com, rafael@kernel.org, tglx@linutronix.de, Jeff LaBundy , linux-input@vger.kernel.org, Chen-Yu Tsai , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Douglas Anderson , Johan Hovold Subject: [RFC PATCH v2 6/7] dt-bindings: arm: mediatek: Remove SKU specific compatibles for Google Krane Date: Thu, 9 Nov 2023 18:06:03 +0800 Message-ID: <20231109100606.1245545-7-wenst@chromium.org> X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog In-Reply-To: <20231109100606.1245545-1-wenst@chromium.org> References: <20231109100606.1245545-1-wenst@chromium.org> Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In cases where the same Chromebook model is manufactured with different components (MIPI DSI panels, MIPI CSI camera sensors, or trackpad / touchscreens with conflicting addresses), a different SKU ID is allocated to each specific combination. This SKU ID is exported by the bootloader into the device tree, and can be used to "discover" which combination is present on the current machine. Thus we no longer have to specify separate compatible strings for each of them. Remove the SKU specific compatible strings for Google Krane. Signed-off-by: Chen-Yu Tsai --- Documentation/devicetree/bindings/arm/mediatek.yaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/Documentation/devicetree/bindings/arm/mediatek.yaml b/Documentation/devicetree/bindings/arm/mediatek.yaml index a4541855a838..ef3dfb286814 100644 --- a/Documentation/devicetree/bindings/arm/mediatek.yaml +++ b/Documentation/devicetree/bindings/arm/mediatek.yaml @@ -186,9 +186,6 @@ properties: - const: mediatek,mt8183 - description: Google Krane (Lenovo IdeaPad Duet, 10e,...) items: - - enum: - - google,krane-sku0 - - google,krane-sku176 - const: google,krane - const: mediatek,mt8183 - description: Google Willow (Acer Chromebook 311 C722/C722T)