mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-03 23:58:05 +00:00
nvmem: sunxi-sid: read NVMEM size from device compatible
Sometimes the SID device have more memory address space than the real NVMEM size (for the registers used to read/write the SID). Fetch the NVMEM size from device compatible, rather than the memory address space's length, in order to prepare for adding some registers-based read support. Signed-off-by: Icenowy Zheng <icenowy@aosc.xyz> Acked-by: Maxime Ripard <maxime.ripard@free-electrons.com> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
5253193d54
commit
4a72cda530
1 changed files with 23 additions and 4 deletions
|
@ -20,6 +20,7 @@
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
#include <linux/nvmem-provider.h>
|
#include <linux/nvmem-provider.h>
|
||||||
#include <linux/of.h>
|
#include <linux/of.h>
|
||||||
|
#include <linux/of_device.h>
|
||||||
#include <linux/platform_device.h>
|
#include <linux/platform_device.h>
|
||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
#include <linux/random.h>
|
#include <linux/random.h>
|
||||||
|
@ -32,6 +33,10 @@ static struct nvmem_config econfig = {
|
||||||
.owner = THIS_MODULE,
|
.owner = THIS_MODULE,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct sunxi_sid_cfg {
|
||||||
|
u32 size;
|
||||||
|
};
|
||||||
|
|
||||||
struct sunxi_sid {
|
struct sunxi_sid {
|
||||||
void __iomem *base;
|
void __iomem *base;
|
||||||
};
|
};
|
||||||
|
@ -72,18 +77,24 @@ static int sunxi_sid_probe(struct platform_device *pdev)
|
||||||
struct sunxi_sid *sid;
|
struct sunxi_sid *sid;
|
||||||
int ret, i, size;
|
int ret, i, size;
|
||||||
char *randomness;
|
char *randomness;
|
||||||
|
const struct sunxi_sid_cfg *cfg;
|
||||||
|
|
||||||
sid = devm_kzalloc(dev, sizeof(*sid), GFP_KERNEL);
|
sid = devm_kzalloc(dev, sizeof(*sid), GFP_KERNEL);
|
||||||
if (!sid)
|
if (!sid)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
|
cfg = of_device_get_match_data(dev);
|
||||||
|
if (!cfg)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||||
sid->base = devm_ioremap_resource(dev, res);
|
sid->base = devm_ioremap_resource(dev, res);
|
||||||
if (IS_ERR(sid->base))
|
if (IS_ERR(sid->base))
|
||||||
return PTR_ERR(sid->base);
|
return PTR_ERR(sid->base);
|
||||||
|
|
||||||
size = resource_size(res) - 1;
|
size = cfg->size;
|
||||||
econfig.size = resource_size(res);
|
|
||||||
|
econfig.size = size;
|
||||||
econfig.dev = dev;
|
econfig.dev = dev;
|
||||||
econfig.reg_read = sunxi_sid_read;
|
econfig.reg_read = sunxi_sid_read;
|
||||||
econfig.priv = sid;
|
econfig.priv = sid;
|
||||||
|
@ -119,9 +130,17 @@ static int sunxi_sid_remove(struct platform_device *pdev)
|
||||||
return nvmem_unregister(nvmem);
|
return nvmem_unregister(nvmem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const struct sunxi_sid_cfg sun4i_a10_cfg = {
|
||||||
|
.size = 0x10,
|
||||||
|
};
|
||||||
|
|
||||||
|
static const struct sunxi_sid_cfg sun7i_a20_cfg = {
|
||||||
|
.size = 0x200,
|
||||||
|
};
|
||||||
|
|
||||||
static const struct of_device_id sunxi_sid_of_match[] = {
|
static const struct of_device_id sunxi_sid_of_match[] = {
|
||||||
{ .compatible = "allwinner,sun4i-a10-sid" },
|
{ .compatible = "allwinner,sun4i-a10-sid", .data = &sun4i_a10_cfg },
|
||||||
{ .compatible = "allwinner,sun7i-a20-sid" },
|
{ .compatible = "allwinner,sun7i-a20-sid", .data = &sun7i_a20_cfg },
|
||||||
{/* sentinel */},
|
{/* sentinel */},
|
||||||
};
|
};
|
||||||
MODULE_DEVICE_TABLE(of, sunxi_sid_of_match);
|
MODULE_DEVICE_TABLE(of, sunxi_sid_of_match);
|
||||||
|
|
Loading…
Reference in a new issue