All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Rafał Miłecki" <zajec5@gmail.com>
To: Florian Fainelli <f.fainelli@gmail.com>,
	Rob Herring <robh+dt@kernel.org>
Cc: "Vivek Unune" <npcomplete13@gmail.com>,
	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, "Rafał Miłecki" <rafal@milecki.pl>
Subject: [PATCH stblinux.git 2/2] firmware: bcm47xx_nvram: support platform device "brcm,nvram"
Date: Tue,  2 Mar 2021 08:44:05 +0100	[thread overview]
Message-ID: <20210302074405.18998-2-zajec5@gmail.com> (raw)
In-Reply-To: <20210302074405.18998-1-zajec5@gmail.com>

From: Rafał Miłecki <rafal@milecki.pl>

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 <rafal@milecki.pl>
---
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 <linux/kernel.h>
 #include <linux/string.h>
 #include <linux/mtd/mtd.h>
+#include <linux/platform_device.h>
 #include <linux/bcm47xx_nvram.h>
 
 #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;
-- 
2.26.2


WARNING: multiple messages have this Message-ID (diff)
From: "Rafał Miłecki" <zajec5@gmail.com>
To: Florian Fainelli <f.fainelli@gmail.com>,
	Rob Herring <robh+dt@kernel.org>
Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-mips@vger.kernel.org,
	bcm-kernel-feedback-list@broadcom.com,
	"Vivek Unune" <npcomplete13@gmail.com>,
	"Rafał Miłecki" <rafal@milecki.pl>,
	linux-arm-kernel@lists.infradead.org
Subject: [PATCH stblinux.git 2/2] firmware: bcm47xx_nvram: support platform device "brcm, nvram"
Date: Tue,  2 Mar 2021 08:44:05 +0100	[thread overview]
Message-ID: <20210302074405.18998-2-zajec5@gmail.com> (raw)
In-Reply-To: <20210302074405.18998-1-zajec5@gmail.com>

From: Rafał Miłecki <rafal@milecki.pl>

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 <rafal@milecki.pl>
---
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 <linux/kernel.h>
 #include <linux/string.h>
 #include <linux/mtd/mtd.h>
+#include <linux/platform_device.h>
 #include <linux/bcm47xx_nvram.h>
 
 #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;
-- 
2.26.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2021-03-02  8:39 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-02  7:44 [PATCH stblinux.git 1/2] dt-bindings: firmware: add Broadcom's NVRAM memory mapping Rafał Miłecki
2021-03-02  7:44 ` Rafał Miłecki
2021-03-02  7:44 ` Rafał Miłecki [this message]
2021-03-02  7:44   ` [PATCH stblinux.git 2/2] firmware: bcm47xx_nvram: support platform device "brcm, nvram" Rafał Miłecki
2021-03-02 16:59   ` [PATCH stblinux.git 2/2] firmware: bcm47xx_nvram: support platform device "brcm,nvram" Florian Fainelli
2021-03-02 16:59     ` Florian Fainelli
2021-03-03 11:44     ` Rafał Miłecki
2021-03-03 11:44       ` Rafał Miłecki
2021-03-08 18:43 ` [PATCH stblinux.git 1/2] dt-bindings: firmware: add Broadcom's NVRAM memory mapping Rob Herring
2021-03-08 18:43   ` Rob Herring
2021-03-08 21:37   ` Rafał Miłecki
2021-03-08 21:37     ` Rafał Miłecki
2021-03-08 21:41     ` Rafał Miłecki
2021-03-08 21:41       ` Rafał Miłecki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210302074405.18998-2-zajec5@gmail.com \
    --to=zajec5@gmail.com \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=devicetree@vger.kernel.org \
    --cc=f.fainelli@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=npcomplete13@gmail.com \
    --cc=rafal@milecki.pl \
    --cc=robh+dt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.