[PATCH 2/6] soc/tegra: fuse: Add function to register nvmem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add helper function tegra_fuse_nvmem_register() to register
Tegra Fuse nvmem and use it in tegra_fuse_probe(). So, this can be
shared between device-tree and ACPI probe, which is to be introduced
later.

Signed-off-by: Kartik <kkartik@xxxxxxxxxx>
---
 drivers/soc/tegra/fuse/fuse-tegra.c | 62 +++++++++++++++++------------
 1 file changed, 37 insertions(+), 25 deletions(-)

diff --git a/drivers/soc/tegra/fuse/fuse-tegra.c b/drivers/soc/tegra/fuse/fuse-tegra.c
index a2c28f493a75..45784ac6393d 100644
--- a/drivers/soc/tegra/fuse/fuse-tegra.c
+++ b/drivers/soc/tegra/fuse/fuse-tegra.c
@@ -113,10 +113,44 @@ static void tegra_fuse_restore(void *base)
 	fuse->clk = NULL;
 }
 
+static int tegra_fuse_nvmem_register(struct tegra_fuse *fuse,
+				     struct device *dev)
+{
+	struct nvmem_config nvmem;
+	int err;
+
+	memset(&nvmem, 0, sizeof(nvmem));
+	nvmem.dev = dev;
+	nvmem.name = "fuse";
+	nvmem.id = -1;
+	nvmem.owner = THIS_MODULE;
+	nvmem.cells = fuse->soc->cells;
+	nvmem.ncells = fuse->soc->num_cells;
+	nvmem.keepout = fuse->soc->keepouts;
+	nvmem.nkeepout = fuse->soc->num_keepouts;
+	nvmem.type = NVMEM_TYPE_OTP;
+	nvmem.read_only = true;
+	nvmem.root_only = false;
+	nvmem.reg_read = tegra_fuse_read;
+	nvmem.size = fuse->soc->info->size;
+	nvmem.word_size = 4;
+	nvmem.stride = 4;
+	nvmem.priv = fuse;
+
+	fuse->nvmem = devm_nvmem_register(dev, &nvmem);
+	if (IS_ERR(fuse->nvmem)) {
+		err = PTR_ERR(fuse->nvmem);
+		dev_err(dev, "failed to register NVMEM device: %d\n",
+			err);
+		return err;
+	}
+
+	return 0;
+}
+
 static int tegra_fuse_probe(struct platform_device *pdev)
 {
 	void __iomem *base = fuse->base;
-	struct nvmem_config nvmem;
 	struct resource *res;
 	int err;
 
@@ -152,31 +186,9 @@ static int tegra_fuse_probe(struct platform_device *pdev)
 			return err;
 	}
 
-	memset(&nvmem, 0, sizeof(nvmem));
-	nvmem.dev = &pdev->dev;
-	nvmem.name = "fuse";
-	nvmem.id = -1;
-	nvmem.owner = THIS_MODULE;
-	nvmem.cells = fuse->soc->cells;
-	nvmem.ncells = fuse->soc->num_cells;
-	nvmem.keepout = fuse->soc->keepouts;
-	nvmem.nkeepout = fuse->soc->num_keepouts;
-	nvmem.type = NVMEM_TYPE_OTP;
-	nvmem.read_only = true;
-	nvmem.root_only = false;
-	nvmem.reg_read = tegra_fuse_read;
-	nvmem.size = fuse->soc->info->size;
-	nvmem.word_size = 4;
-	nvmem.stride = 4;
-	nvmem.priv = fuse;
-
-	fuse->nvmem = devm_nvmem_register(&pdev->dev, &nvmem);
-	if (IS_ERR(fuse->nvmem)) {
-		err = PTR_ERR(fuse->nvmem);
-		dev_err(&pdev->dev, "failed to register NVMEM device: %d\n",
-			err);
+	err = tegra_fuse_nvmem_register(fuse, &pdev->dev);
+	if (err)
 		return err;
-	}
 
 	fuse->rst = devm_reset_control_get_optional(&pdev->dev, "fuse");
 	if (IS_ERR(fuse->rst)) {
-- 
2.34.1




[Index of Archives]     [ARM Kernel]     [Linux ARM]     [Linux ARM MSM]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux