aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorJonas Bonn <jonas@southpole.se>2010-11-24 11:26:21 -0500
committerBen Dooks <ben-linux@fluff.org>2011-01-03 20:04:23 -0500
commit47def5b80f087d033013c0609679812cfafd6b49 (patch)
tree6ec05ee144fdad62d3308aa50c1a1149e571a0e1 /drivers
parent049bb69d82e5f7f356949c1ae34a244b3338611b (diff)
i2c-ocores: Use devres for resource allocation
This patch converts the i2c-cores driver to use devres routines for resource allocation. Signed-off-by: Jonas Bonn <jonas@southpole.se> Signed-off-by: Ben Dooks <ben-linux@fluff.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/i2c/busses/i2c-ocores.c46
1 files changed, 11 insertions, 35 deletions
diff --git a/drivers/i2c/busses/i2c-ocores.c b/drivers/i2c/busses/i2c-ocores.c
index c05e8c44404a..dee0352737d7 100644
--- a/drivers/i2c/busses/i2c-ocores.c
+++ b/drivers/i2c/busses/i2c-ocores.c
@@ -253,22 +253,21 @@ static int __devinit ocores_i2c_probe(struct platform_device *pdev)
253 if (!res2) 253 if (!res2)
254 return -ENODEV; 254 return -ENODEV;
255 255
256 i2c = kzalloc(sizeof(*i2c), GFP_KERNEL); 256 i2c = devm_kzalloc(&pdev->dev, sizeof(*i2c), GFP_KERNEL);
257 if (!i2c) 257 if (!i2c)
258 return -ENOMEM; 258 return -ENOMEM;
259 259
260 if (!request_mem_region(res->start, resource_size(res), 260 if (!devm_request_mem_region(&pdev->dev, res->start,
261 pdev->name)) { 261 resource_size(res), pdev->name)) {
262 dev_err(&pdev->dev, "Memory region busy\n"); 262 dev_err(&pdev->dev, "Memory region busy\n");
263 ret = -EBUSY; 263 return -EBUSY;
264 goto request_mem_failed;
265 } 264 }
266 265
267 i2c->base = ioremap(res->start, resource_size(res)); 266 i2c->base = devm_ioremap_nocache(&pdev->dev, res->start,
267 resource_size(res));
268 if (!i2c->base) { 268 if (!i2c->base) {
269 dev_err(&pdev->dev, "Unable to map registers\n"); 269 dev_err(&pdev->dev, "Unable to map registers\n");
270 ret = -EIO; 270 return -EIO;
271 goto map_failed;
272 } 271 }
273 272
274 pdata = pdev->dev.platform_data; 273 pdata = pdev->dev.platform_data;
@@ -284,10 +283,11 @@ static int __devinit ocores_i2c_probe(struct platform_device *pdev)
284 ocores_init(i2c); 283 ocores_init(i2c);
285 284
286 init_waitqueue_head(&i2c->wait); 285 init_waitqueue_head(&i2c->wait);
287 ret = request_irq(res2->start, ocores_isr, 0, pdev->name, i2c); 286 ret = devm_request_irq(&pdev->dev, res2->start, ocores_isr, 0,
287 pdev->name, i2c);
288 if (ret) { 288 if (ret) {
289 dev_err(&pdev->dev, "Cannot claim IRQ\n"); 289 dev_err(&pdev->dev, "Cannot claim IRQ\n");
290 goto request_irq_failed; 290 return ret;
291 } 291 }
292 292
293 /* hook up driver to tree */ 293 /* hook up driver to tree */
@@ -303,7 +303,7 @@ static int __devinit ocores_i2c_probe(struct platform_device *pdev)
303 ret = i2c_add_adapter(&i2c->adap); 303 ret = i2c_add_adapter(&i2c->adap);
304 if (ret) { 304 if (ret) {
305 dev_err(&pdev->dev, "Failed to add adapter\n"); 305 dev_err(&pdev->dev, "Failed to add adapter\n");
306 goto add_adapter_failed; 306 return ret;
307 } 307 }
308 308
309 /* add in known devices to the bus */ 309 /* add in known devices to the bus */
@@ -313,23 +313,11 @@ static int __devinit ocores_i2c_probe(struct platform_device *pdev)
313 } 313 }
314 314
315 return 0; 315 return 0;
316
317add_adapter_failed:
318 free_irq(res2->start, i2c);
319request_irq_failed:
320 iounmap(i2c->base);
321map_failed:
322 release_mem_region(res->start, resource_size(res));
323request_mem_failed:
324 kfree(i2c);
325
326 return ret;
327} 316}
328 317
329static int __devexit ocores_i2c_remove(struct platform_device* pdev) 318static int __devexit ocores_i2c_remove(struct platform_device* pdev)
330{ 319{
331 struct ocores_i2c *i2c = platform_get_drvdata(pdev); 320 struct ocores_i2c *i2c = platform_get_drvdata(pdev);
332 struct resource *res;
333 321
334 /* disable i2c logic */ 322 /* disable i2c logic */
335 oc_setreg(i2c, OCI2C_CONTROL, oc_getreg(i2c, OCI2C_CONTROL) 323 oc_setreg(i2c, OCI2C_CONTROL, oc_getreg(i2c, OCI2C_CONTROL)
@@ -339,18 +327,6 @@ static int __devexit ocores_i2c_remove(struct platform_device* pdev)
339 i2c_del_adapter(&i2c->adap); 327 i2c_del_adapter(&i2c->adap);
340 platform_set_drvdata(pdev, NULL); 328 platform_set_drvdata(pdev, NULL);
341 329
342 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
343 if (res)
344 free_irq(res->start, i2c);
345
346 iounmap(i2c->base);
347
348 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
349 if (res)
350 release_mem_region(res->start, resource_size(res));
351
352 kfree(i2c);
353
354 return 0; 330 return 0;
355} 331}
356 332