aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVladimir Zapolskiy <vladimir_zapolskiy@mentor.com>2015-06-01 08:29:59 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2015-06-12 20:03:56 -0400
commita0a5be0b36be31e644a10c8da89d7280a9b9384c (patch)
tree73f1f50637ed44f489a5116965ab620b98220295
parent665d82fbbccdb5997ddcff3536f2cad5b1634462 (diff)
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>
-rw-r--r--drivers/misc/sram.c82
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,
57 return ra->start - rb->start; 57 return ra->start - rb->start;
58} 58}
59 59
60static int sram_probe(struct platform_device *pdev) 60static int sram_reserve_regions(struct sram_dev *sram, struct resource *res)
61{ 61{
62 struct sram_dev *sram; 62 struct device_node *np = sram->dev->of_node, *child;
63 struct resource *res;
64 struct device_node *np = pdev->dev.of_node, *child;
65 unsigned long size, cur_start, cur_size; 63 unsigned long size, cur_start, cur_size;
66 struct sram_reserve *rblocks, *block; 64 struct sram_reserve *rblocks, *block;
67 struct list_head reserve_list; 65 struct list_head reserve_list;
68 unsigned int nblocks; 66 unsigned int nblocks;
69 int ret; 67 int ret = 0;
70 68
71 INIT_LIST_HEAD(&reserve_list); 69 INIT_LIST_HEAD(&reserve_list);
72 70
73 sram = devm_kzalloc(&pdev->dev, sizeof(*sram), GFP_KERNEL);
74 if (!sram)
75 return -ENOMEM;
76
77 sram->dev = &pdev->dev;
78
79 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
80 if (!res) {
81 dev_err(sram->dev, "found no memory resource\n");
82 return -EINVAL;
83 }
84
85 size = resource_size(res); 71 size = resource_size(res);
86 72
87 if (!devm_request_mem_region(sram->dev, res->start, size, pdev->name)) {
88 dev_err(sram->dev, "could not request region for resource\n");
89 return -EBUSY;
90 }
91
92 sram->virt_base = devm_ioremap_wc(sram->dev, res->start, size);
93 if (IS_ERR(sram->virt_base))
94 return PTR_ERR(sram->virt_base);
95
96 sram->pool = devm_gen_pool_create(sram->dev,
97 ilog2(SRAM_GRANULARITY), -1);
98 if (!sram->pool)
99 return -ENOMEM;
100
101 /* 73 /*
102 * We need an additional block to mark the end of the memory region 74 * We need an additional block to mark the end of the memory region
103 * after the reserved blocks from the dt are processed. 75 * after the reserved blocks from the dt are processed.
@@ -184,8 +156,51 @@ static int sram_probe(struct platform_device *pdev)
184 cur_start = block->start + block->size; 156 cur_start = block->start + block->size;
185 } 157 }
186 158
159 err_chunks:
187 kfree(rblocks); 160 kfree(rblocks);
188 161
162 return ret;
163}
164
165static int sram_probe(struct platform_device *pdev)
166{
167 struct sram_dev *sram;
168 struct resource *res;
169 size_t size;
170 int ret;
171
172 sram = devm_kzalloc(&pdev->dev, sizeof(*sram), GFP_KERNEL);
173 if (!sram)
174 return -ENOMEM;
175
176 sram->dev = &pdev->dev;
177
178 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
179 if (!res) {
180 dev_err(sram->dev, "found no memory resource\n");
181 return -EINVAL;
182 }
183
184 size = resource_size(res);
185
186 if (!devm_request_mem_region(sram->dev, res->start, size, pdev->name)) {
187 dev_err(sram->dev, "could not request region for resource\n");
188 return -EBUSY;
189 }
190
191 sram->virt_base = devm_ioremap_wc(sram->dev, res->start, size);
192 if (IS_ERR(sram->virt_base))
193 return PTR_ERR(sram->virt_base);
194
195 sram->pool = devm_gen_pool_create(sram->dev,
196 ilog2(SRAM_GRANULARITY), -1);
197 if (!sram->pool)
198 return -ENOMEM;
199
200 ret = sram_reserve_regions(sram, res);
201 if (ret)
202 return ret;
203
189 sram->clk = devm_clk_get(sram->dev, NULL); 204 sram->clk = devm_clk_get(sram->dev, NULL);
190 if (IS_ERR(sram->clk)) 205 if (IS_ERR(sram->clk))
191 sram->clk = NULL; 206 sram->clk = NULL;
@@ -198,11 +213,6 @@ static int sram_probe(struct platform_device *pdev)
198 gen_pool_size(sram->pool) / 1024, sram->virt_base); 213 gen_pool_size(sram->pool) / 1024, sram->virt_base);
199 214
200 return 0; 215 return 0;
201
202err_chunks:
203 kfree(rblocks);
204
205 return ret;
206} 216}
207 217
208static int sram_remove(struct platform_device *pdev) 218static int sram_remove(struct platform_device *pdev)