From patchwork Tue Oct 10 05:34:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 115335 Delivered-To: patches@linaro.org Received: by 10.140.22.163 with SMTP id 32csp3355595qgn; Mon, 9 Oct 2017 22:34:33 -0700 (PDT) X-Received: by 10.99.176.79 with SMTP id z15mr11040539pgo.230.1507613673129; Mon, 09 Oct 2017 22:34:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507613673; cv=none; d=google.com; s=arc-20160816; b=geuhBadV2m1OEmAqUykjL0kaqhrkG5CZfBN/w/nX7H+DEUWK4KSEUjrQ0A9BMnRJjf cFpG0luqx6xV49eexq8KrehyCEX3Puun1M9CcttQYi2aE2Hd7yBWlHuZm+7iem2Co/ZJ 8BWhu5HR0jY0TDuJFuLwY4KlGCgw0ui8Z4F/QzBH2rUCP7G6z3gTtCpiua+TIIQCRtE/ tMR5grdbcJmMHq576IldJU/bZI61SU/Ww2TPnckBhfBQFZe/Pl2itSueVJZv3h7Gabas V7qIP/yJS5GTmyTIfGGUZOq1uTMR7RThORITj4nacITDO21JLajpYhGZJpfUbVRSPeX+ 3IWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=oyBGrreuEehOIgRBjcmGcyWNneK5HzR45wbuPAHHq78=; b=JXMGO9h48eIC2LU5VrtkLt8ftu7Aht7uZjlF0aG0Q32EiVRKvivCiibjoyLCwVZ2Ma g3ulK9wZ7Wg/faHRsaCoLTsKryVAtB4IygSxD0ec+0RFofcolpwS/N+xbITEywWYuDjX N95dZTAjR95IAy74jH8cXsfIHo7Pi3t4lxoeEFVHgFWiyaOvidIx3P31KVOk4pr7b8n6 n7lMCZ2zfwJO458EhN257jnLJXy73qb/d2+jaCUtSck+LVXY4zVFZPNkPSFFTQF+NB+f HbiaaEWgI8N9wpd+pmySDKVMsJ95pTlszl3aOUx4uBf+X+umxuvrbvKfFdrg09fE7ZNS tc+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hVTCr6cS; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id v6sor1413230plp.52.2017.10.09.22.34.33 for (Google Transport Security); Mon, 09 Oct 2017 22:34:33 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hVTCr6cS; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=oyBGrreuEehOIgRBjcmGcyWNneK5HzR45wbuPAHHq78=; b=hVTCr6cSuxoKfdfXxtz2BCov0jyBbRZXNWsqQV1BYJRArbykNr/olgsut6aWyZxSfE sFi6CRHmOQ1v0/zQs4O0lD3ZOyT8PbvE/7+36T1ikGAZx6zA6cVftodeZViz+ZGxod3b wsB7AZgu3ew4TQAmEXxNYjXAjZ+T0FArFQa70= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=oyBGrreuEehOIgRBjcmGcyWNneK5HzR45wbuPAHHq78=; b=sLrsTZVSoY8V0SXslig1XqAPbuZoXQ90e+5Hquu8lT7wrcYFy1j/e4Wv3pJH4rBryA rKsQVLvkoDBnjHmEexbpktotZqQXHjzl63a4JD0EMEJX/IP6dXvbyDnSno0pVp+p3X4h zngJ4TdlYc+HdTUTFypLug04qYTHJiKCgDml6l1t/OLVnFYP0R9nCRoAhZm5LY0CrLRc ZKzqzAKjDhZX8aVnlxQB02FQv8XmTDp5Zq1KyIbmq1JXPIj6rIT9/o0rdUqSUsCqIWm7 2k/sjk+yL2H1fRTKd4YUqDZaQ9FhD/A2qdbfhawkYYP2ue/c/qxUO/aLPC2wzBiNWAXi CyUg== X-Gm-Message-State: AMCzsaUz8Q3uv2oWJ4dNHUYeRAZBpbW7qzuQHfo1jd7iOGTV/BOfHqx9 BvFIV7IPIXF+ZCHmxfYimQYyy3ZM X-Google-Smtp-Source: AOwi7QCRBkH6o91T4+GjgCRW/A4r/WLs2HtGOTD5LjUN+95Y/F7A/5Q966MRi0sLfDvdtQA9R0ogxA== X-Received: by 10.84.234.2 with SMTP id m2mr11219791plk.391.1507613672803; Mon, 09 Oct 2017 22:34:32 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:1002:83f0:4e72:b9ff:fe99:466a]) by smtp.gmail.com with ESMTPSA id b16sm9603595pfe.58.2017.10.09.22.34.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 09 Oct 2017 22:34:31 -0700 (PDT) From: John Stultz To: lkml Cc: Dmitry Shmidt , Rob Herring , Mark Rutland , Frank Rowand , devicetree@vger.kernel.org, John Stultz Subject: [RFC][PATCH 1/3] of: overlay_mgr: Add overlay manager driver Date: Mon, 9 Oct 2017 22:34:18 -0700 Message-Id: <1507613660-27236-2-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1507613660-27236-1-git-send-email-john.stultz@linaro.org> References: <1507613660-27236-1-git-send-email-john.stultz@linaro.org> From: Dmitry Shmidt This patch adds a driver to manage applying pre-defined DT overlay fragments at bootup. The pre-defined DT fragments are specified via the main overlay_mng entry which includes all the possible HW config setups. Then kernel command line option is used to choose between them. These entries are specified on kernel boot arguments as follows: overlay_mgr.overlay_dt_entry=hardware_cfg_0 Example DT entry: overlay_mgr { compatible = "linux,overlay_manager"; hardware_cfg_0 { overlay@0 { fragment@0 { __overlay__ { }; }; }; overlay@1 { fragment@0 { __overlay__ { }; }; }; }; }; Cc: Rob Herring Cc: Mark Rutland Cc: Frank Rowand Cc: Dmitry Shmidt Cc: devicetree@vger.kernel.org Signed-off-by: Dmitry Shmidt [jstultz: Reworded commit message] Signed-off-by: John Stultz --- .../devicetree/bindings/of/overlay_mgr.txt | 32 ++++++++ drivers/of/Kconfig | 10 +++ drivers/of/Makefile | 1 + drivers/of/overlay_mgr.c | 90 ++++++++++++++++++++++ 4 files changed, 133 insertions(+) create mode 100644 Documentation/devicetree/bindings/of/overlay_mgr.txt create mode 100644 drivers/of/overlay_mgr.c -- 2.7.4 diff --git a/Documentation/devicetree/bindings/of/overlay_mgr.txt b/Documentation/devicetree/bindings/of/overlay_mgr.txt new file mode 100644 index 0000000..5f3ce4c --- /dev/null +++ b/Documentation/devicetree/bindings/of/overlay_mgr.txt @@ -0,0 +1,32 @@ +overlay_mgr + +Required properties: +- compatible: "linux,overlay_manager"; + +Optional properties: +- starts from the word "hardware": hardware_cfg_0 + +These properties can be chosen from kernel command line: +overlay_mgr.overlay_dt_entry=hardware_cfg_0 +DT contains main overlay_mng entry with all possible +HW config setups. And then kernel command line option +will allow to choose between them. + +Example: + overlay_mgr { + compatible = "linux,overlay_manager"; + hardware_cfg_0 { + overlay@0 { + fragment@0 { + __overlay__ { + }; + }; + }; + overlay@1 { + fragment@0 { + __overlay__ { + }; + }; + }; + }; + }; diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig index ba7b034..5132e41 100644 --- a/drivers/of/Kconfig +++ b/drivers/of/Kconfig @@ -112,4 +112,14 @@ config OF_OVERLAY config OF_NUMA bool +config OF_OVERLAY_MGR + bool "Enable Overlay manager" + default n + depends on OF_OVERLAY + help + Enables Overlay manager - it accepts DT entry from command line + overlay_mgr.overlay_dt_entry= and applies all overlays in + it to current DT. It is also possible to apply predefined DT + entry on the fly by writing it to 'current_overlay' sysfs entry. + endif # OF diff --git a/drivers/of/Makefile b/drivers/of/Makefile index 97dc01c..e2b8afa 100644 --- a/drivers/of/Makefile +++ b/drivers/of/Makefile @@ -14,5 +14,6 @@ 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_OF_OVERLAY_MGR) += overlay_mgr.o obj-$(CONFIG_OF_UNITTEST) += unittest-data/ diff --git a/drivers/of/overlay_mgr.c b/drivers/of/overlay_mgr.c new file mode 100644 index 0000000..1fdeb0a --- /dev/null +++ b/drivers/of/overlay_mgr.c @@ -0,0 +1,90 @@ +/* + * Overlay manager that allows to apply list of overlays from DT entry + * + * Copyright (C) 2016 Google, Inc. + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include +#include + +static char *of_overlay_dt_entry; +module_param_named(overlay_dt_entry, of_overlay_dt_entry, charp, 0644); + +static int of_overlay_mgr_apply_overlay(struct device_node *onp) +{ + int ret; + + ret = of_overlay_create(onp); + if (ret < 0) { + pr_err("overlay_mgr: fail to create overlay: %d\n", ret); + of_node_put(onp); + return ret; + } + pr_info("overlay_mgr: %s overlay applied\n", onp->name); + return 0; +} + +static int of_overlay_mgr_apply_dt(struct device *dev, char *dt_entry) +{ + struct device_node *enp = dev->of_node; + struct device_node *next; + struct device_node *prev = NULL; + + if (!enp) { + pr_err("overlay_mgr: no dt entry\n"); + return -ENODEV; + } + + enp = of_get_child_by_name(enp, dt_entry); + if (!enp) { + pr_err("overlay_mgr: dt entry %s not found\n", dt_entry); + return -ENODEV; + } + pr_info("overlay_mgr: apply %s dt entry\n", enp->name); + while ((next = of_get_next_available_child(enp, prev)) != NULL) { + if (strncmp(next->name, "overlay", 7) == 0) + of_overlay_mgr_apply_overlay(next); + prev = next; + } + return 0; +} + +static int of_overlay_mgr_probe(struct platform_device *pdev) +{ + if (!of_overlay_dt_entry) + return 0; + of_overlay_mgr_apply_dt(&pdev->dev, of_overlay_dt_entry); + return 0; +} + +static const struct of_device_id of_overlay_mgr_match[] = { + { .compatible = "linux,overlay_manager", }, + {} +}; + +static struct platform_driver of_overlay_mgr_driver = { + .probe = of_overlay_mgr_probe, + .driver = { + .name = "overlay_manager", + .of_match_table = of_match_ptr(of_overlay_mgr_match), + }, +}; + +static int __init of_overlay_mgr_init(void) +{ + return platform_driver_register(&of_overlay_mgr_driver); +} + +postcore_initcall(of_overlay_mgr_init);