aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Lezcano <daniel.lezcano@linaro.org>2018-09-25 05:03:02 -0400
committerEduardo Valentin <edubezval@gmail.com>2018-10-22 20:43:41 -0400
commit9bb4ec8d9e93f0d1a94e8aa9100c5f42fd364078 (patch)
tree469c54c081860d9d35573a68a0faad4c884fb99b
parent49e778d1c750d5b1f773edeb93dfef963bef3f21 (diff)
thermal/drivers/hisi: Factor out the probe functions
The hi6220 and the hi3660 probe functions are doing almost the same operations, they can share 90% of their code. Factor out the probe functions by moving the common code in the common probe function. Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org> Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
-rw-r--r--drivers/thermal/hisi_thermal.c39
1 files changed, 12 insertions, 27 deletions
diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c
index 567fde6ea369..7287818a66b6 100644
--- a/drivers/thermal/hisi_thermal.c
+++ b/drivers/thermal/hisi_thermal.c
@@ -391,16 +391,8 @@ static int hi6220_thermal_probe(struct hisi_thermal_data *data)
391{ 391{
392 struct platform_device *pdev = data->pdev; 392 struct platform_device *pdev = data->pdev;
393 struct device *dev = &pdev->dev; 393 struct device *dev = &pdev->dev;
394 struct resource *res;
395 int ret; 394 int ret;
396 395
397 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
398 data->regs = devm_ioremap_resource(dev, res);
399 if (IS_ERR(data->regs)) {
400 dev_err(dev, "failed to get io address\n");
401 return PTR_ERR(data->regs);
402 }
403
404 data->clk = devm_clk_get(dev, "thermal_clk"); 396 data->clk = devm_clk_get(dev, "thermal_clk");
405 if (IS_ERR(data->clk)) { 397 if (IS_ERR(data->clk)) {
406 ret = PTR_ERR(data->clk); 398 ret = PTR_ERR(data->clk);
@@ -409,10 +401,6 @@ static int hi6220_thermal_probe(struct hisi_thermal_data *data)
409 return ret; 401 return ret;
410 } 402 }
411 403
412 data->irq = platform_get_irq(pdev, 0);
413 if (data->irq < 0)
414 return data->irq;
415
416 data->sensor.id = HI6220_DEFAULT_SENSOR; 404 data->sensor.id = HI6220_DEFAULT_SENSOR;
417 405
418 return 0; 406 return 0;
@@ -420,21 +408,6 @@ static int hi6220_thermal_probe(struct hisi_thermal_data *data)
420 408
421static int hi3660_thermal_probe(struct hisi_thermal_data *data) 409static int hi3660_thermal_probe(struct hisi_thermal_data *data)
422{ 410{
423 struct platform_device *pdev = data->pdev;
424 struct device *dev = &pdev->dev;
425 struct resource *res;
426
427 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
428 data->regs = devm_ioremap_resource(dev, res);
429 if (IS_ERR(data->regs)) {
430 dev_err(dev, "failed to get io address\n");
431 return PTR_ERR(data->regs);
432 }
433
434 data->irq = platform_get_irq(pdev, 0);
435 if (data->irq < 0)
436 return data->irq;
437
438 data->sensor.id = HI3660_DEFAULT_SENSOR; 411 data->sensor.id = HI3660_DEFAULT_SENSOR;
439 412
440 return 0; 413 return 0;
@@ -553,6 +526,7 @@ static int hisi_thermal_probe(struct platform_device *pdev)
553{ 526{
554 struct hisi_thermal_data *data; 527 struct hisi_thermal_data *data;
555 struct device *dev = &pdev->dev; 528 struct device *dev = &pdev->dev;
529 struct resource *res;
556 int ret; 530 int ret;
557 531
558 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); 532 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
@@ -564,6 +538,17 @@ static int hisi_thermal_probe(struct platform_device *pdev)
564 data->sensor.data = data; 538 data->sensor.data = data;
565 data->ops = of_device_get_match_data(dev); 539 data->ops = of_device_get_match_data(dev);
566 540
541 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
542 data->regs = devm_ioremap_resource(dev, res);
543 if (IS_ERR(data->regs)) {
544 dev_err(dev, "failed to get io address\n");
545 return PTR_ERR(data->regs);
546 }
547
548 data->irq = platform_get_irq(pdev, 0);
549 if (data->irq < 0)
550 return data->irq;
551
567 ret = data->ops->probe(data); 552 ret = data->ops->probe(data);
568 if (ret) 553 if (ret)
569 return ret; 554 return ret;