diff options
author | Vladimir Zapolskiy <vladimir_zapolskiy@mentor.com> | 2015-06-01 15:29:59 +0300 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2015-06-12 17:03:56 -0700 |
commit | a0a5be0b36be31e644a10c8da89d7280a9b9384c (patch) | |
tree | 73f1f50637ed44f489a5116965ab620b98220295 /drivers/misc | |
parent | 665d82fbbccdb5997ddcff3536f2cad5b1634462 (diff) | |
download | linux-a0a5be0b36be31e644a10c8da89d7280a9b9384c.tar.gz linux-a0a5be0b36be31e644a10c8da89d7280a9b9384c.tar.bz2 linux-a0a5be0b36be31e644a10c8da89d7280a9b9384c.zip |
misc: sram: move reserved block logic out of probe function
No functional change, but now previously overloaded sram_probe() is
greatly simplified and perceptible, reserved regions logic also has
its own space.
Signed-off-by: Vladimir Zapolskiy <vladimir_zapolskiy@mentor.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/misc')
-rw-r--r-- | drivers/misc/sram.c | 82 |
1 files changed, 46 insertions, 36 deletions
diff --git a/drivers/misc/sram.c b/drivers/misc/sram.c index 9ecc7d5ed4f8..7502b6ceb338 100644 --- a/drivers/misc/sram.c +++ b/drivers/misc/sram.c @@ -57,47 +57,19 @@ static int sram_reserve_cmp(void *priv, struct list_head *a, return ra->start - rb->start; } -static int sram_probe(struct platform_device *pdev) +static int sram_reserve_regions(struct sram_dev *sram, struct resource *res) { - struct sram_dev *sram; - struct resource *res; - struct device_node *np = pdev->dev.of_node, *child; + struct device_node *np = sram->dev->of_node, *child; unsigned long size, cur_start, cur_size; struct sram_reserve *rblocks, *block; struct list_head reserve_list; unsigned int nblocks; - int ret; + int ret = 0; INIT_LIST_HEAD(&reserve_list); - sram = devm_kzalloc(&pdev->dev, sizeof(*sram), GFP_KERNEL); - if (!sram) - return -ENOMEM; - - sram->dev = &pdev->dev; - - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - if (!res) { - dev_err(sram->dev, "found no memory resource\n"); - return -EINVAL; - } - size = resource_size(res); - if (!devm_request_mem_region(sram->dev, res->start, size, pdev->name)) { - dev_err(sram->dev, "could not request region for resource\n"); - return -EBUSY; - } - - sram->virt_base = devm_ioremap_wc(sram->dev, res->start, size); - if (IS_ERR(sram->virt_base)) - return PTR_ERR(sram->virt_base); - - sram->pool = devm_gen_pool_create(sram->dev, - ilog2(SRAM_GRANULARITY), -1); - if (!sram->pool) - return -ENOMEM; - /* * We need an additional block to mark the end of the memory region * after the reserved blocks from the dt are processed. @@ -184,8 +156,51 @@ static int sram_probe(struct platform_device *pdev) cur_start = block->start + block->size; } + err_chunks: kfree(rblocks); + return ret; +} + +static int sram_probe(struct platform_device *pdev) +{ + struct sram_dev *sram; + struct resource *res; + size_t size; + int ret; + + sram = devm_kzalloc(&pdev->dev, sizeof(*sram), GFP_KERNEL); + if (!sram) + return -ENOMEM; + + sram->dev = &pdev->dev; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res) { + dev_err(sram->dev, "found no memory resource\n"); + return -EINVAL; + } + + size = resource_size(res); + + if (!devm_request_mem_region(sram->dev, res->start, size, pdev->name)) { + dev_err(sram->dev, "could not request region for resource\n"); + return -EBUSY; + } + + sram->virt_base = devm_ioremap_wc(sram->dev, res->start, size); + if (IS_ERR(sram->virt_base)) + return PTR_ERR(sram->virt_base); + + sram->pool = devm_gen_pool_create(sram->dev, + ilog2(SRAM_GRANULARITY), -1); + if (!sram->pool) + return -ENOMEM; + + ret = sram_reserve_regions(sram, res); + if (ret) + return ret; + sram->clk = devm_clk_get(sram->dev, NULL); if (IS_ERR(sram->clk)) sram->clk = NULL; @@ -198,11 +213,6 @@ static int sram_probe(struct platform_device *pdev) gen_pool_size(sram->pool) / 1024, sram->virt_base); return 0; - -err_chunks: - kfree(rblocks); - - return ret; } static int sram_remove(struct platform_device *pdev) |