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: Dynamically allocate nvmem_config structure
The sunxi_sid driver currently uses a statically allocated nvmem_config structure that is updated at probe time. This is sub-optimal as it limits the driver to one instance, and also takes up space even if the device is not present. Modify the driver to allocate the nvmem_config structure at probe time, plugging in the desired parameters along the way. Signed-off-by: Chen-Yu Tsai <wens@csie.org> Acked-by: Maxime Ripard <maxime.ripard@bootlin.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
de2a3eaea5
commit
7fa5ad23db
1 changed files with 17 additions and 15 deletions
|
@ -35,13 +35,6 @@
|
||||||
#define SUN8I_SID_OP_LOCK (0xAC << 8)
|
#define SUN8I_SID_OP_LOCK (0xAC << 8)
|
||||||
#define SUN8I_SID_READ BIT(1)
|
#define SUN8I_SID_READ BIT(1)
|
||||||
|
|
||||||
static struct nvmem_config econfig = {
|
|
||||||
.name = "sunxi-sid",
|
|
||||||
.read_only = true,
|
|
||||||
.stride = 4,
|
|
||||||
.word_size = 1,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct sunxi_sid_cfg {
|
struct sunxi_sid_cfg {
|
||||||
u32 value_offset;
|
u32 value_offset;
|
||||||
u32 size;
|
u32 size;
|
||||||
|
@ -150,6 +143,7 @@ static int sunxi_sid_probe(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct device *dev = &pdev->dev;
|
struct device *dev = &pdev->dev;
|
||||||
struct resource *res;
|
struct resource *res;
|
||||||
|
struct nvmem_config *nvmem_cfg;
|
||||||
struct nvmem_device *nvmem;
|
struct nvmem_device *nvmem;
|
||||||
struct sunxi_sid *sid;
|
struct sunxi_sid *sid;
|
||||||
int size;
|
int size;
|
||||||
|
@ -172,14 +166,23 @@ static int sunxi_sid_probe(struct platform_device *pdev)
|
||||||
|
|
||||||
size = cfg->size;
|
size = cfg->size;
|
||||||
|
|
||||||
econfig.size = size;
|
nvmem_cfg = devm_kzalloc(dev, sizeof(*nvmem_cfg), GFP_KERNEL);
|
||||||
econfig.dev = dev;
|
if (!nvmem_cfg)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
nvmem_cfg->dev = dev;
|
||||||
|
nvmem_cfg->name = "sunxi-sid";
|
||||||
|
nvmem_cfg->read_only = true;
|
||||||
|
nvmem_cfg->size = cfg->size;
|
||||||
|
nvmem_cfg->word_size = 1;
|
||||||
|
nvmem_cfg->stride = 4;
|
||||||
|
nvmem_cfg->priv = sid;
|
||||||
if (cfg->need_register_readout)
|
if (cfg->need_register_readout)
|
||||||
econfig.reg_read = sun8i_sid_read_by_reg;
|
nvmem_cfg->reg_read = sun8i_sid_read_by_reg;
|
||||||
else
|
else
|
||||||
econfig.reg_read = sunxi_sid_read;
|
nvmem_cfg->reg_read = sunxi_sid_read;
|
||||||
econfig.priv = sid;
|
|
||||||
nvmem = devm_nvmem_register(dev, &econfig);
|
nvmem = devm_nvmem_register(dev, nvmem_cfg);
|
||||||
if (IS_ERR(nvmem))
|
if (IS_ERR(nvmem))
|
||||||
return PTR_ERR(nvmem);
|
return PTR_ERR(nvmem);
|
||||||
|
|
||||||
|
@ -187,8 +190,7 @@ static int sunxi_sid_probe(struct platform_device *pdev)
|
||||||
if (!randomness)
|
if (!randomness)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
econfig.reg_read(sid, 0, randomness, size);
|
nvmem_cfg->reg_read(sid, 0, randomness, size);
|
||||||
|
|
||||||
add_device_randomness(randomness, size);
|
add_device_randomness(randomness, size);
|
||||||
kfree(randomness);
|
kfree(randomness);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue