aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVladimir Zapolskiy <vladimir_zapolskiy@mentor.com>2015-06-01 08:29:58 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2015-06-12 20:03:56 -0400
commit665d82fbbccdb5997ddcff3536f2cad5b1634462 (patch)
treee7c9692ab36f2da33af7715959766862d94bd460
parent4914f1c7179f056b69b0e2bddc3f5daadb70609d (diff)
misc: sram: add private struct device and virt_base members
No functional change, this is a preceding change to simplify separation of reserved partition handling logic from probe() function. Signed-off-by: Vladimir Zapolskiy <vladimir_zapolskiy@mentor.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/misc/sram.c54
1 files changed, 29 insertions, 25 deletions
diff --git a/drivers/misc/sram.c b/drivers/misc/sram.c
index dd66d5f72ee9..9ecc7d5ed4f8 100644
--- a/drivers/misc/sram.c
+++ b/drivers/misc/sram.c
@@ -35,6 +35,9 @@
35#define SRAM_GRANULARITY 32 35#define SRAM_GRANULARITY 32
36 36
37struct sram_dev { 37struct sram_dev {
38 struct device *dev;
39 void __iomem *virt_base;
40
38 struct gen_pool *pool; 41 struct gen_pool *pool;
39 struct clk *clk; 42 struct clk *clk;
40}; 43};
@@ -56,7 +59,6 @@ static int sram_reserve_cmp(void *priv, struct list_head *a,
56 59
57static int sram_probe(struct platform_device *pdev) 60static int sram_probe(struct platform_device *pdev)
58{ 61{
59 void __iomem *virt_base;
60 struct sram_dev *sram; 62 struct sram_dev *sram;
61 struct resource *res; 63 struct resource *res;
62 struct device_node *np = pdev->dev.of_node, *child; 64 struct device_node *np = pdev->dev.of_node, *child;
@@ -68,29 +70,31 @@ static int sram_probe(struct platform_device *pdev)
68 70
69 INIT_LIST_HEAD(&reserve_list); 71 INIT_LIST_HEAD(&reserve_list);
70 72
73 sram = devm_kzalloc(&pdev->dev, sizeof(*sram), GFP_KERNEL);
74 if (!sram)
75 return -ENOMEM;
76
77 sram->dev = &pdev->dev;
78
71 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 79 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
72 if (!res) { 80 if (!res) {
73 dev_err(&pdev->dev, "found no memory resource\n"); 81 dev_err(sram->dev, "found no memory resource\n");
74 return -EINVAL; 82 return -EINVAL;
75 } 83 }
76 84
77 size = resource_size(res); 85 size = resource_size(res);
78 86
79 if (!devm_request_mem_region(&pdev->dev, 87 if (!devm_request_mem_region(sram->dev, res->start, size, pdev->name)) {
80 res->start, size, pdev->name)) { 88 dev_err(sram->dev, "could not request region for resource\n");
81 dev_err(&pdev->dev, "could not request region for resource\n");
82 return -EBUSY; 89 return -EBUSY;
83 } 90 }
84 91
85 virt_base = devm_ioremap_wc(&pdev->dev, res->start, size); 92 sram->virt_base = devm_ioremap_wc(sram->dev, res->start, size);
86 if (IS_ERR(virt_base)) 93 if (IS_ERR(sram->virt_base))
87 return PTR_ERR(virt_base); 94 return PTR_ERR(sram->virt_base);
88
89 sram = devm_kzalloc(&pdev->dev, sizeof(*sram), GFP_KERNEL);
90 if (!sram)
91 return -ENOMEM;
92 95
93 sram->pool = devm_gen_pool_create(&pdev->dev, ilog2(SRAM_GRANULARITY), -1); 96 sram->pool = devm_gen_pool_create(sram->dev,
97 ilog2(SRAM_GRANULARITY), -1);
94 if (!sram->pool) 98 if (!sram->pool)
95 return -ENOMEM; 99 return -ENOMEM;
96 100
@@ -109,7 +113,7 @@ static int sram_probe(struct platform_device *pdev)
109 113
110 ret = of_address_to_resource(child, 0, &child_res); 114 ret = of_address_to_resource(child, 0, &child_res);
111 if (ret < 0) { 115 if (ret < 0) {
112 dev_err(&pdev->dev, 116 dev_err(sram->dev,
113 "could not get address for node %s\n", 117 "could not get address for node %s\n",
114 child->full_name); 118 child->full_name);
115 of_node_put(child); 119 of_node_put(child);
@@ -117,7 +121,7 @@ static int sram_probe(struct platform_device *pdev)
117 } 121 }
118 122
119 if (child_res.start < res->start || child_res.end > res->end) { 123 if (child_res.start < res->start || child_res.end > res->end) {
120 dev_err(&pdev->dev, 124 dev_err(sram->dev,
121 "reserved block %s outside the sram area\n", 125 "reserved block %s outside the sram area\n",
122 child->full_name); 126 child->full_name);
123 ret = -EINVAL; 127 ret = -EINVAL;
@@ -129,9 +133,8 @@ static int sram_probe(struct platform_device *pdev)
129 block->size = resource_size(&child_res); 133 block->size = resource_size(&child_res);
130 list_add_tail(&block->list, &reserve_list); 134 list_add_tail(&block->list, &reserve_list);
131 135
132 dev_dbg(&pdev->dev, "found reserved block 0x%x-0x%x\n", 136 dev_dbg(sram->dev, "found reserved block 0x%x-0x%x\n",
133 block->start, 137 block->start, block->start + block->size);
134 block->start + block->size);
135 138
136 block++; 139 block++;
137 } 140 }
@@ -148,7 +151,7 @@ static int sram_probe(struct platform_device *pdev)
148 list_for_each_entry(block, &reserve_list, list) { 151 list_for_each_entry(block, &reserve_list, list) {
149 /* can only happen if sections overlap */ 152 /* can only happen if sections overlap */
150 if (block->start < cur_start) { 153 if (block->start < cur_start) {
151 dev_err(&pdev->dev, 154 dev_err(sram->dev,
152 "block at 0x%x starts after current offset 0x%lx\n", 155 "block at 0x%x starts after current offset 0x%lx\n",
153 block->start, cur_start); 156 block->start, cur_start);
154 ret = -EINVAL; 157 ret = -EINVAL;
@@ -168,10 +171,11 @@ static int sram_probe(struct platform_device *pdev)
168 */ 171 */
169 cur_size = block->start - cur_start; 172 cur_size = block->start - cur_start;
170 173
171 dev_dbg(&pdev->dev, "adding chunk 0x%lx-0x%lx\n", 174 dev_dbg(sram->dev, "adding chunk 0x%lx-0x%lx\n",
172 cur_start, cur_start + cur_size); 175 cur_start, cur_start + cur_size);
176
173 ret = gen_pool_add_virt(sram->pool, 177 ret = gen_pool_add_virt(sram->pool,
174 (unsigned long)virt_base + cur_start, 178 (unsigned long)sram->virt_base + cur_start,
175 res->start + cur_start, cur_size, -1); 179 res->start + cur_start, cur_size, -1);
176 if (ret < 0) 180 if (ret < 0)
177 goto err_chunks; 181 goto err_chunks;
@@ -182,7 +186,7 @@ static int sram_probe(struct platform_device *pdev)
182 186
183 kfree(rblocks); 187 kfree(rblocks);
184 188
185 sram->clk = devm_clk_get(&pdev->dev, NULL); 189 sram->clk = devm_clk_get(sram->dev, NULL);
186 if (IS_ERR(sram->clk)) 190 if (IS_ERR(sram->clk))
187 sram->clk = NULL; 191 sram->clk = NULL;
188 else 192 else
@@ -190,8 +194,8 @@ static int sram_probe(struct platform_device *pdev)
190 194
191 platform_set_drvdata(pdev, sram); 195 platform_set_drvdata(pdev, sram);
192 196
193 dev_dbg(&pdev->dev, "SRAM pool: %zu KiB @ 0x%p\n", 197 dev_dbg(sram->dev, "SRAM pool: %zu KiB @ 0x%p\n",
194 gen_pool_size(sram->pool) / 1024, virt_base); 198 gen_pool_size(sram->pool) / 1024, sram->virt_base);
195 199
196 return 0; 200 return 0;
197 201
@@ -206,7 +210,7 @@ static int sram_remove(struct platform_device *pdev)
206 struct sram_dev *sram = platform_get_drvdata(pdev); 210 struct sram_dev *sram = platform_get_drvdata(pdev);
207 211
208 if (gen_pool_avail(sram->pool) < gen_pool_size(sram->pool)) 212 if (gen_pool_avail(sram->pool) < gen_pool_size(sram->pool))
209 dev_err(&pdev->dev, "removed while SRAM allocated\n"); 213 dev_err(sram->dev, "removed while SRAM allocated\n");
210 214
211 if (sram->clk) 215 if (sram->clk)
212 clk_disable_unprepare(sram->clk); 216 clk_disable_unprepare(sram->clk);