forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nvmem: brcm_nvram: new driver exposing Broadcom's NVRAM
This driver provides access to Broadcom's NVRAM. Signed-off-by: Rafał Miłecki <[email protected]> Signed-off-by: Srinivas Kandagatla <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
- Loading branch information
Showing
3 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// SPDX-License-Identifier: GPL-2.0-only | ||
/* | ||
* Copyright (C) 2021 Rafał Miłecki <[email protected]> | ||
*/ | ||
|
||
#include <linux/io.h> | ||
#include <linux/mod_devicetable.h> | ||
#include <linux/module.h> | ||
#include <linux/nvmem-provider.h> | ||
#include <linux/platform_device.h> | ||
|
||
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); |