From patchwork Fri Mar 5 18:32:35 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: 12119169 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=ham 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 94061C433DB for ; Fri, 5 Mar 2021 18:36:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 689F365085 for ; Fri, 5 Mar 2021 18:36:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229797AbhCESfr (ORCPT ); Fri, 5 Mar 2021 13:35:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230426AbhCESfV (ORCPT ); Fri, 5 Mar 2021 13:35:21 -0500 Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1F21C061763; Fri, 5 Mar 2021 10:32:53 -0800 (PST) Received: by mail-lj1-x22e.google.com with SMTP id q14so4001725ljp.4; Fri, 05 Mar 2021 10:32:53 -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=yCWtEFyrceH7BJ6AukIJ81DQ9V6t6R7qk/KayCrGAnE=; b=IwjMsHqY0DBH5/GX0MF09rd8LLvvJZArlEX+lXLd7JDgWs4ZfESNowujUiqKdWwPu0 PglTOEeijYt0rq+5tBZ8LDE2oW06KcKOlmBffkhibSn9eS/CFqKU/knEbnAdoP0sqKNH 0+w4647siaUVFtvf5FX4VZNzEgtOR4Yc6/DSHYfdtxrXq1hTilZP/tTuOD4VVhMIWKPv 0yOzKeQJ3IVXJM5XjwgZL81gNZO9UGjZcns2DDW9ikyl3NdiNuS12ebbAyrXpMJWzqKT GKrKOdcWVYq37VmUdfFyLb1itwQvtPaqRIjsAeeGRY5KsaPNgNyvjmXLdFMaSR1NpHxI wNPA== 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=yCWtEFyrceH7BJ6AukIJ81DQ9V6t6R7qk/KayCrGAnE=; b=GwMmGgEErNh8kmka/G4MhN7rDxk/uK4sYK6LrjTyJuhba00x2h5WLFmElEyweyokGx ax3jYRy3C5ls9a4lFJKGsEzO6JQIkxILUKTsP1nh2cE3BE2DZFIDhTMwNHypcKqTekNp SkK2ioQbJ0Jo/p+AuKAPI7/D4O/JTrNZB3ouYosLyFLSwcWx94Qa5oFAmiQ/nlHGADi+ 3qI9/b4LARJjwqIhe34HZkyaZ0oTPo2QT+wIFT2gR1LDX2JT3uzjXNlqYVUiWEIAdl4B 6vIXO+Kw/ZazRvMAU2qboxKmvkJGzS45kKztffTb7jXDPynSEjo5brB7j3ja2OCxulg5 Du1w== X-Gm-Message-State: AOAM532XDcPogS8n5XxF99VFOozoquSYvil9kSKCIPn9Ird5SxObSZvo 9Gw0FJWDKiw8ACRJiZZhWI4= X-Google-Smtp-Source: ABdhPJyxr9PnPzpKcN7Pkw/wsx3UbzX9kFmZsLiHylfTvjTD1rjrTAiozInXXb3SfwdQIijlVCvKPw== X-Received: by 2002:a2e:a48f:: with SMTP id h15mr6002521lji.234.1614969172315; Fri, 05 Mar 2021 10:32:52 -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 a10sm396571lfu.263.2021.03.05.10.32.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 10:32:51 -0800 (PST) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: Srinivas Kandagatla , Rob Herring Cc: devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, Florian Fainelli , Vivek Unune , bcm-kernel-feedback-list@broadcom.com, linux-kernel@vger.kernel.org, =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= Subject: [PATCH V2 1/2] dt-bindings: nvmem: add Broadcom's NVRAM Date: Fri, 5 Mar 2021 19:32:35 +0100 Message-Id: <20210305183236.11784-1-zajec5@gmail.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org From: Rafał Miłecki Broadcom's NVRAM structure contains device data and can be accessed using I/O mapping. Signed-off-by: Rafał Miłecki Reviewed-by: Rob Herring --- V2: Use Broadcom's NVRAM specific binding. Generic "nvmem-iomap" binding didn't make much sense. Thanks Srinivas! --- .../devicetree/bindings/nvmem/brcm,nvram.yaml | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml diff --git a/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml b/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml new file mode 100644 index 000000000000..58ff6b0bdb1a --- /dev/null +++ b/Documentation/devicetree/bindings/nvmem/brcm,nvram.yaml @@ -0,0 +1,34 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/nvmem/brcm,nvram.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Broadcom's NVRAM + +description: | + Broadcom's NVRAM is a structure containing device specific environment + variables. It is used for storing device configuration, booting parameters + and calibration data. + + NVRAM can be accessed on Broadcom BCM47xx MIPS and Northstar ARM Cortex-A9 + devices usiong I/O mapped memory. + +maintainers: + - Rafał Miłecki + +allOf: + - $ref: "nvmem.yaml#" + +properties: + compatible: + const: brcm,nvram + +unevaluatedProperties: false + +examples: + - | + nvram@1eff0000 { + compatible = "brcm,nvram"; + reg = <0x1eff0000 0x10000>; + }; From patchwork Fri Mar 5 18:32:36 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: 12119171 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 E6DA3C433E6 for ; Fri, 5 Mar 2021 18:36:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B51646508B for ; Fri, 5 Mar 2021 18:36:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229615AbhCESfr (ORCPT ); Fri, 5 Mar 2021 13:35:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230423AbhCESfV (ORCPT ); Fri, 5 Mar 2021 13:35:21 -0500 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6696FC061764; Fri, 5 Mar 2021 10:32:56 -0800 (PST) Received: by mail-lf1-x135.google.com with SMTP id 18so5232762lff.6; Fri, 05 Mar 2021 10:32:56 -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=PjTLZM8e0f8v+1gejOLEjQVfC8/951TSPeQCDviKHHE=; b=c8F10EakFYE4/GxV/Ief/dUTChUo0NchyO0rnDhbLxOyUZfkKNYBftoGuYnc36qNMJ r1XcWF+15ill/E+3tHDr25e/llt/sx6YWztfmXDm/mkU7JISLDy00OFAbT93OFB7uJUL BR+3e5PcxLZx90OYTyt0GEmqaDaLaPcV6DwYkHxWnXgrffPTHd7RkCq60EZ2oMnJm4uO ZjyhZWe1Ci8+rKxdI3+OHSKhi1Gz0843TQXjNkV9WC4rSq86g/SKuivYJW0N0dUVmVWP Hf3aYuls75QFDoObpxEDQmMaq6aSZeOI8/wGjJoNl03jfI7aTbGR1Yb8hD1MJfad/Fcs HdvA== 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=PjTLZM8e0f8v+1gejOLEjQVfC8/951TSPeQCDviKHHE=; b=bqVjfXTlKKGBJPIuTq7KFiV/cIJPtrqj3ZLI2ZF8pWtzYWHvsTwg48rRh6EL/jXq3x 9M7kRxoeCTJpbINa6ca6fN6EwEFMaM+9iENLFGOfpZxNgMI8F++6JJCAAx8L7AzVV1lX XAPiCVuQPX2lfvzHWOL21hzOhY+5N9l7TPazTTTydqhdkIystep8lqiytQFIkSYRumWx 7hIItNDJr7Joa/Xn5KOvlWNu0ELPvS63PMJ+C7AxE+Bqd5ltrNjN2zbMM1bDqaPzMqxE K4IDYS5uRUzh7HnNqBuifqh6cKR2Nj8iKsmuxoZsvhMODnd/AmVv/AnahALghy5esFGF 4wSw== X-Gm-Message-State: AOAM533PngwPxma5nQ1CMWp3ZSN6xxK6WP77R/a1vM3UuUYJNqrfTtM3 qdpPgxwRnMnkfOjkMSKfz+U= X-Google-Smtp-Source: ABdhPJxSdmXgEv6uNaFa3yqkiHSVOFdEspqIMjmdF5gYiieNZhHq+zLsvUcH7B5w/GDeXtbkwcvLYA== X-Received: by 2002:a19:4c41:: with SMTP id z62mr6035631lfa.360.1614969174885; Fri, 05 Mar 2021 10:32:54 -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 a10sm396571lfu.263.2021.03.05.10.32.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 10:32:54 -0800 (PST) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: Srinivas Kandagatla , Rob Herring Cc: devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, Florian Fainelli , Vivek Unune , bcm-kernel-feedback-list@broadcom.com, linux-kernel@vger.kernel.org, =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= Subject: [PATCH V2 2/2] nvmem: brcm_nvram: new driver exposing Broadcom's NVRAM Date: Fri, 5 Mar 2021 19:32:36 +0100 Message-Id: <20210305183236.11784-2-zajec5@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210305183236.11784-1-zajec5@gmail.com> References: <20210305183236.11784-1-zajec5@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org From: Rafał Miłecki This driver provides access to Broadcom's NVRAM. Signed-off-by: Rafał Miłecki --- V2: Applied Srinivas's suggestions: * Simplified brcm_nvram_read * Drop unneeded check & prints from probe * Fixed MODULE_LICENSE * Switched to Broadcom specific binding & driver. This is such a trivial driver that even if we get another similar one, it probably won't be worth it to share their code. Thank you Srinivas! --- drivers/nvmem/Kconfig | 9 +++++ drivers/nvmem/Makefile | 2 + drivers/nvmem/brcm_nvram.c | 78 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 drivers/nvmem/brcm_nvram.c diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig index 75d2594c16e1..d2a848fab82a 100644 --- a/drivers/nvmem/Kconfig +++ b/drivers/nvmem/Kconfig @@ -278,4 +278,13 @@ config NVMEM_RMEM This driver can also be built as a module. If so, the module will be called nvmem-rmem. + +config NVMEM_BRCM_NVRAM + tristate "Broadcom's NVRAM support" + depends on ARCH_BCM_5301X || COMPILE_TEST + depends on HAS_IOMEM + help + This driver provides support for Broadcom's NVRAM that can be accessed + using I/O mapping. + endif diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile index 5376b8e0dae5..bbea1410240a 100644 --- a/drivers/nvmem/Makefile +++ b/drivers/nvmem/Makefile @@ -57,3 +57,5 @@ obj-$(CONFIG_SPRD_EFUSE) += nvmem_sprd_efuse.o nvmem_sprd_efuse-y := sprd-efuse.o obj-$(CONFIG_NVMEM_RMEM) += nvmem-rmem.o nvmem-rmem-y := rmem.o +obj-$(CONFIG_NVMEM_BRCM_NVRAM) += nvmem_brcm_nvram.o +nvmem_brcm_nvram-y := brcm_nvram.o diff --git a/drivers/nvmem/brcm_nvram.c b/drivers/nvmem/brcm_nvram.c new file mode 100644 index 000000000000..bd2ecaaf4585 --- /dev/null +++ b/drivers/nvmem/brcm_nvram.c @@ -0,0 +1,78 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2021 Rafał Miłecki + */ + +#include +#include +#include +#include +#include + +struct brcm_nvram { + struct device *dev; + void __iomem *base; +}; + +static int brcm_nvram_read(void *context, unsigned int offset, void *val, + size_t bytes) +{ + struct brcm_nvram *priv = context; + u8 *dst = val; + + while (bytes--) + *dst++ = readb(priv->base + offset++); + + return 0; +} + +static int brcm_nvram_probe(struct platform_device *pdev) +{ + struct nvmem_config config = { + .name = "brcm-nvram", + .reg_read = brcm_nvram_read, + }; + struct device *dev = &pdev->dev; + struct resource *res; + struct brcm_nvram *priv; + + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + priv->dev = dev; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + priv->base = devm_ioremap_resource(dev, res); + if (IS_ERR(priv->base)) + return PTR_ERR(priv->base); + + config.dev = dev; + config.priv = priv; + config.size = resource_size(res); + + return PTR_ERR_OR_ZERO(devm_nvmem_register(dev, &config)); +} + +static const struct of_device_id brcm_nvram_of_match_table[] = { + { .compatible = "brcm,nvram", }, + {}, +}; + +static struct platform_driver brcm_nvram_driver = { + .probe = brcm_nvram_probe, + .driver = { + .name = "brcm_nvram", + .of_match_table = brcm_nvram_of_match_table, + }, +}; + +static int __init brcm_nvram_init(void) +{ + return platform_driver_register(&brcm_nvram_driver); +} + +subsys_initcall_sync(brcm_nvram_init); + +MODULE_AUTHOR("Rafał Miłecki"); +MODULE_LICENSE("GPL"); +MODULE_DEVICE_TABLE(of, brcm_nvram_of_match_table);