From patchwork Tue Mar 2 07:44:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 392348 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4D717C433DB for ; Tue, 2 Mar 2021 20:05:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ECB1D64F30 for ; Tue, 2 Mar 2021 20:05:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1839897AbhCBTz3 (ORCPT ); Tue, 2 Mar 2021 14:55:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376678AbhCBHsz (ORCPT ); Tue, 2 Mar 2021 02:48:55 -0500 Received: from mail-lj1-x236.google.com (mail-lj1-x236.google.com [IPv6:2a00:1450:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB2AAC061788; Mon, 1 Mar 2021 23:44:41 -0800 (PST) Received: by mail-lj1-x236.google.com with SMTP id r25so21736735ljk.11; Mon, 01 Mar 2021 23:44:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=3TtSrnXBguUPTi71hdOlnm4h8qMyGVSuM0R08lOrQW4=; b=uots3Sxm9SoiIi+QE2AQP6TZSdeyhTt/s5Xh/05aX+PTwfgq0Mm1+r1XygmqDKXg1v aidObKrhOU7m/gSqHRqUjOcBYCbjrn8SQUlhIRKPehAaZmxR7phXvLt3XAYGwhciak5m 3rrbNzKEDtMxygnR+Nao6WjEd9Z3xyW8eQXz9oLuE0NGqphifmyVF2jd6fcT2Usom8kB mYhRpgnGbB4oanr4KvJdBRxA/yoprN29gi7c8H3tMJRw20ONETkNSjRBeff/Inke4jWl o5XpzcwvReYXJ0sjZmIjb1FermlSQX4tAdZ/b7CcyxlxgnGJwC30JCXMPKyWXcAZdsDA gkyQ== 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:mime-version :content-transfer-encoding; bh=3TtSrnXBguUPTi71hdOlnm4h8qMyGVSuM0R08lOrQW4=; b=af7RAlnBp01/VPfLscy+GShMwDdCsAZKN4+H+xQcR1oF09EUInV4BARFoGvf6ViDDh xJ0iK90s6MedkjWBqPE0vDSTg5DNPCEorl9EwkCxE+gzDv/Y1IxZpPlD6/E79HfFFO/A G1vCi95XYVi0dA4O3mIzm1zzN3RO1VvCofqeGao9Xes69HN9YhZKnEviiZzCngr/Rcqj BrsgMsr4eeiu009VD8nXgmcXV1dzIM7q6cuQm2hI96AKSYIa3C5IPX5chMARb0/FhfDo 8D/YcbeazpogLnfLP4PUPXEiYpNRZLNMocBVlrNCsefP7kVqXaB5uonJN0hDw/P6T+La 2W6A== X-Gm-Message-State: AOAM531DuDhuF20TXX33+zCj0Na17c6m+qpji2/rP9jTQ1e9ovI9ad5s t2B8LO6i9F6wyZQQVXHLT4U= X-Google-Smtp-Source: ABdhPJzj5bJtO4TF9wl6Qz1I7getHrofm1x9Oh+YQo5fkpbR6AtYw3Jw8p0DBAzHIs5abIwxraiWwQ== X-Received: by 2002:a05:651c:1022:: with SMTP id w2mr10340293ljm.455.1614671080079; Mon, 01 Mar 2021 23:44:40 -0800 (PST) Received: from localhost.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id e15sm2552600lfs.83.2021.03.01.23.44.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Mar 2021 23:44:39 -0800 (PST) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: Florian Fainelli , Rob Herring Cc: Vivek Unune , linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, devicetree@vger.kernel.org, bcm-kernel-feedback-list@broadcom.com, linux-kernel@vger.kernel.org, =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= Subject: [PATCH stblinux.git 1/2] dt-bindings: firmware: add Broadcom's NVRAM memory mapping Date: Tue, 2 Mar 2021 08:44:04 +0100 Message-Id: <20210302074405.18998-1-zajec5@gmail.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Rafał Miłecki NVRAM structure contains device data and can be accessed using MMIO. Signed-off-by: Rafał Miłecki --- .../bindings/firmware/brcm,nvram.yaml | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Documentation/devicetree/bindings/firmware/brcm,nvram.yaml diff --git a/Documentation/devicetree/bindings/firmware/brcm,nvram.yaml b/Documentation/devicetree/bindings/firmware/brcm,nvram.yaml new file mode 100644 index 000000000000..12af8e2e7c9c --- /dev/null +++ b/Documentation/devicetree/bindings/firmware/brcm,nvram.yaml @@ -0,0 +1,41 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: "http://devicetree.org/schemas/firmware/brcm,nvram.yaml#" +$schema: "http://devicetree.org/meta-schemas/core.yaml#" + +title: Broadcom's NVRAM + +maintainers: + - Rafał Miłecki + +description: | + NVRAM is a structure containing device specific environment variables. + It is used for storing device configuration, booting parameters and + calibration data. + + It's required very early in booting process and so is made available + using memory mapping. + + NVRAM can be found on Broadcom BCM47xx MIPS, Northstar ARM Cortex-A9 + and some more devices. + +properties: + compatible: + const: brcm,nvram + + reg: + description: memory region with NVRAM data + maxItems: 1 + +required: + - reg + +additionalProperties: false + +examples: + - | + nvram@1e000000 { + compatible = "brcm,nvram"; + reg = <0x1e000000 0x10000>; + }; From patchwork Tue Mar 2 07:44:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 390541 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E8D73C433E0 for ; Tue, 2 Mar 2021 20:04:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ABC5364F21 for ; Tue, 2 Mar 2021 20:04:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1839892AbhCBTz0 (ORCPT ); Tue, 2 Mar 2021 14:55:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376680AbhCBHsT (ORCPT ); Tue, 2 Mar 2021 02:48:19 -0500 Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F2A8C06178A; Mon, 1 Mar 2021 23:44:45 -0800 (PST) Received: by mail-lj1-x22a.google.com with SMTP id k12so13708032ljg.9; Mon, 01 Mar 2021 23:44:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gZNTatbnHb+7B3cifLvu1nq4X6pcmEEmjpKFoMb/vdM=; b=veyh53ntviSLpdEMoBgWaX81jpp5Z5M40bdVat+k0hrZxC1K7QftkvE5LYiCpZH4lO HRaoEtTrY/yAe/gcoByU+9de1fYwZXVHvJ72j5hEr/10dL2FOj2spoG9fxfAj1uCZ3UU iKHnmUrfVsKensHxhw8pM5aPC5WagNMRTZ3mAfZxZYppBGLh63T3CuYwxKGKBS+vdrJE XUkzZyoa9RqbIPTjCj1hDMJNDcIkv60n1vusMsRVfqwnyCZzQP8QRssrauL5RSuy7m6N 368MAm97lWLGpQpZD4UPRC++8vJbOiLI7kZHmSjk15BxcW1s53rqECzyBdHjOTuxvN9V kdpg== 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:mime-version:content-transfer-encoding; bh=gZNTatbnHb+7B3cifLvu1nq4X6pcmEEmjpKFoMb/vdM=; b=JEt2WU9Wjw1gnVRYUtmuC7qr1xhiqDN8VM8A/6eJ/Re0VOARmkDFh89kt/6CL2gzGH SPhV2tfG0AQWXSni/Rcbx6UbOtRa2O95tuUk3MacGum4FDlnO3J1bvwvkro5B3RZBwxB LnwAWDhyFGSYpCz7CfQNgFSLAEaCHnV3TbHxtk3olKAGclmixjVPTWZI22mvrzOVh23r Vm1LTpDofXqVJKapQs9B9SiAINi7v7sYYY2mwroWStK7EgpbeGrCvImW+kSkiNsvooPF 5qDPW+RBDfUmreh+0jt8nqC79S/LxXDEWXddfb/87D0huBmTvQBudUlrWnW2OdTik5yN KoRw== X-Gm-Message-State: AOAM533NPR45NvAlH9l4aNMB/M/2yB+fC5NY+Tk0Tje8dSp1KiSDUq8e MZfWpA382PjYse4PUmynHwE= X-Google-Smtp-Source: ABdhPJy5WZKx8Db12jFNbVaHP3Fz1Red+MdnyuyzuB4bQ3KfRZmKcM41nCu17nw2QIiZIENKiPhvqQ== X-Received: by 2002:a2e:140e:: with SMTP id u14mr11582726ljd.413.1614671083925; Mon, 01 Mar 2021 23:44:43 -0800 (PST) Received: from localhost.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id e15sm2552600lfs.83.2021.03.01.23.44.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Mar 2021 23:44:43 -0800 (PST) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: Florian Fainelli , Rob Herring Cc: Vivek Unune , linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, devicetree@vger.kernel.org, bcm-kernel-feedback-list@broadcom.com, linux-kernel@vger.kernel.org, =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= Subject: [PATCH stblinux.git 2/2] firmware: bcm47xx_nvram: support platform device "brcm, nvram" Date: Tue, 2 Mar 2021 08:44:05 +0100 Message-Id: <20210302074405.18998-2-zajec5@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210302074405.18998-1-zajec5@gmail.com> References: <20210302074405.18998-1-zajec5@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Rafał Miłecki Add support for platform device providing mapping resource. This allows reading NVRAM based on DT mapping binding. It's required for devices that boot depending on NVRAM stored setup and provides early access to NVRAM data. Signed-off-by: Rafał Miłecki --- bcm47xx_nvram driver was originally added through MIPS tree, but this change doesn't affect BCM47XX (MIPS) as it doesn't use DT. It targets ARCH_BCM_5301X so I suggest this goes through the stblinux.git tree. --- drivers/firmware/broadcom/bcm47xx_nvram.c | 55 +++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/drivers/firmware/broadcom/bcm47xx_nvram.c b/drivers/firmware/broadcom/bcm47xx_nvram.c index 835ece9c00f1..d5d19dd1b9e1 100644 --- a/drivers/firmware/broadcom/bcm47xx_nvram.c +++ b/drivers/firmware/broadcom/bcm47xx_nvram.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #define NVRAM_MAGIC 0x48534C46 /* 'FLSH' */ @@ -162,6 +163,60 @@ static int nvram_init(void) return -ENXIO; } +static int brcm_nvram_probe(struct platform_device *pdev) +{ + struct nvram_header __iomem *header; + struct device *dev = &pdev->dev; + struct resource *res; + void __iomem *mmio; + size_t copy_len; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res) { + dev_err(dev, "Failed to get resource\n"); + return -ENODEV; + } + + mmio = ioremap(res->start, resource_size(res)); + if (!mmio) + return -ENOMEM; + + header = (struct nvram_header *)mmio; + copy_len = DIV_ROUND_UP(sizeof(*header) + header->len, 4); + if (header->magic != NVRAM_MAGIC) { + dev_err(dev, "No NVRAM found at %pR\n", res); + return -EPROTO; + } else if (copy_len > resource_size(res)) { + dev_err(dev, "NVRAM size exceeds %pR\n", res); + return -ERANGE; + } else if (copy_len >= NVRAM_SPACE) { + dev_err(dev, "NVRAM size exceeds buffer size %d\n", NVRAM_SPACE); + return -ENOMEM; + } + + __ioread32_copy(nvram_buf, mmio, copy_len); + nvram_buf[NVRAM_SPACE - 1] = '\0'; + + iounmap(mmio); + + return 0; +} + +static const struct of_device_id brcm_nvram_of_match[] = { + { .compatible = "brcm,nvram "}, + {}, +}; + +static struct platform_driver brcm_nvram_driver = { + .driver = { + .name = "brcm_nvram", + .of_match_table = brcm_nvram_of_match, + }, + .probe = brcm_nvram_probe, +}; + +module_platform_driver(brcm_nvram_driver); + int bcm47xx_nvram_getenv(const char *name, char *val, size_t val_len) { char *var, *value, *end, *eq;