aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Boyd <sboyd@codeaurora.org>2013-06-03 15:39:44 -0400
committerDavid Brown <davidb@codeaurora.org>2013-06-12 17:50:12 -0400
commit1aa3d1a3c7d235c47e30c7c8c6b5ef02fb1536b3 (patch)
tree1f1cf15f61d59cfd17cf7063d9db523353524b6d
parent43f68444bce70e360ff6ce3653a54e511625f651 (diff)
mfd: ssbi: Use devm_* and simplify code
Use devm_ioremap_resource and devm_kzalloc to simplify error paths and reduce lines of code. Also use dev_err() to keep consistency and drop the .remove function because the devm functions take care of what it's doing besides the now obsolete platform_set_drvdata() which we can just drop. Finally, use module_platform_driver() to save some more lines. Cc: David Brown <davidb@codeaurora.org> Signed-off-by: Stephen Boyd <sboyd@codeaurora.org> Signed-off-by: David Brown <davidb@codeaurora.org>
-rw-r--r--drivers/ssbi/ssbi.c69
1 files changed, 11 insertions, 58 deletions
diff --git a/drivers/ssbi/ssbi.c b/drivers/ssbi/ssbi.c
index f32da0258a8e..a62e85f4016b 100644
--- a/drivers/ssbi/ssbi.c
+++ b/drivers/ssbi/ssbi.c
@@ -268,35 +268,23 @@ static int ssbi_probe(struct platform_device *pdev)
268 struct device_node *np = pdev->dev.of_node; 268 struct device_node *np = pdev->dev.of_node;
269 struct resource *mem_res; 269 struct resource *mem_res;
270 struct ssbi *ssbi; 270 struct ssbi *ssbi;
271 int ret = 0;
272 const char *type; 271 const char *type;
273 272
274 ssbi = kzalloc(sizeof(struct ssbi), GFP_KERNEL); 273 ssbi = devm_kzalloc(&pdev->dev, sizeof(*ssbi), GFP_KERNEL);
275 if (!ssbi) { 274 if (!ssbi)
276 pr_err("can not allocate ssbi_data\n");
277 return -ENOMEM; 275 return -ENOMEM;
278 }
279 276
280 mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 277 mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
281 if (!mem_res) { 278 ssbi->base = devm_ioremap_resource(&pdev->dev, mem_res);
282 pr_err("missing mem resource\n"); 279 if (IS_ERR(ssbi->base))
283 ret = -EINVAL; 280 return PTR_ERR(ssbi->base);
284 goto err_get_mem_res;
285 }
286 281
287 ssbi->base = ioremap(mem_res->start, resource_size(mem_res));
288 if (!ssbi->base) {
289 pr_err("ioremap of 0x%p failed\n", (void *)mem_res->start);
290 ret = -EINVAL;
291 goto err_ioremap;
292 }
293 platform_set_drvdata(pdev, ssbi); 282 platform_set_drvdata(pdev, ssbi);
294 283
295 type = of_get_property(np, "qcom,controller-type", NULL); 284 type = of_get_property(np, "qcom,controller-type", NULL);
296 if (type == NULL) { 285 if (type == NULL) {
297 pr_err("Missing qcom,controller-type property\n"); 286 dev_err(&pdev->dev, "Missing qcom,controller-type property\n");
298 ret = -EINVAL; 287 return -EINVAL;
299 goto err_ssbi_controller;
300 } 288 }
301 dev_info(&pdev->dev, "SSBI controller type: '%s'\n", type); 289 dev_info(&pdev->dev, "SSBI controller type: '%s'\n", type);
302 if (strcmp(type, "ssbi") == 0) 290 if (strcmp(type, "ssbi") == 0)
@@ -306,9 +294,8 @@ static int ssbi_probe(struct platform_device *pdev)
306 else if (strcmp(type, "pmic-arbiter") == 0) 294 else if (strcmp(type, "pmic-arbiter") == 0)
307 ssbi->controller_type = MSM_SBI_CTRL_PMIC_ARBITER; 295 ssbi->controller_type = MSM_SBI_CTRL_PMIC_ARBITER;
308 else { 296 else {
309 pr_err("Unknown qcom,controller-type\n"); 297 dev_err(&pdev->dev, "Unknown qcom,controller-type\n");
310 ret = -EINVAL; 298 return -EINVAL;
311 goto err_ssbi_controller;
312 } 299 }
313 300
314 if (ssbi->controller_type == MSM_SBI_CTRL_PMIC_ARBITER) { 301 if (ssbi->controller_type == MSM_SBI_CTRL_PMIC_ARBITER) {
@@ -321,29 +308,7 @@ static int ssbi_probe(struct platform_device *pdev)
321 308
322 spin_lock_init(&ssbi->lock); 309 spin_lock_init(&ssbi->lock);
323 310
324 ret = of_platform_populate(np, NULL, NULL, &pdev->dev); 311 return of_platform_populate(np, NULL, NULL, &pdev->dev);
325 if (ret)
326 goto err_ssbi_controller;
327
328 return 0;
329
330err_ssbi_controller:
331 platform_set_drvdata(pdev, NULL);
332 iounmap(ssbi->base);
333err_ioremap:
334err_get_mem_res:
335 kfree(ssbi);
336 return ret;
337}
338
339static int ssbi_remove(struct platform_device *pdev)
340{
341 struct ssbi *ssbi = platform_get_drvdata(pdev);
342
343 platform_set_drvdata(pdev, NULL);
344 iounmap(ssbi->base);
345 kfree(ssbi);
346 return 0;
347} 312}
348 313
349static struct of_device_id ssbi_match_table[] = { 314static struct of_device_id ssbi_match_table[] = {
@@ -353,25 +318,13 @@ static struct of_device_id ssbi_match_table[] = {
353 318
354static struct platform_driver ssbi_driver = { 319static struct platform_driver ssbi_driver = {
355 .probe = ssbi_probe, 320 .probe = ssbi_probe,
356 .remove = ssbi_remove,
357 .driver = { 321 .driver = {
358 .name = "ssbi", 322 .name = "ssbi",
359 .owner = THIS_MODULE, 323 .owner = THIS_MODULE,
360 .of_match_table = ssbi_match_table, 324 .of_match_table = ssbi_match_table,
361 }, 325 },
362}; 326};
363 327module_platform_driver(ssbi_driver);
364static int __init ssbi_init(void)
365{
366 return platform_driver_register(&ssbi_driver);
367}
368module_init(ssbi_init);
369
370static void __exit ssbi_exit(void)
371{
372 platform_driver_unregister(&ssbi_driver);
373}
374module_exit(ssbi_exit)
375 328
376MODULE_LICENSE("GPL v2"); 329MODULE_LICENSE("GPL v2");
377MODULE_VERSION("1.0"); 330MODULE_VERSION("1.0");