Skip to content

Commit

Permalink
thermal/drivers/hisi: Factor out the probe functions
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Daniel Lezcano authored and Eduardo Valentin committed Oct 23, 2018
1 parent 49e778d commit 9bb4ec8
Showing 1 changed file with 12 additions and 27 deletions.
39 changes: 12 additions & 27 deletions drivers/thermal/hisi_thermal.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,16 +391,8 @@ static int hi6220_thermal_probe(struct hisi_thermal_data *data)
{
struct platform_device *pdev = data->pdev;
struct device *dev = &pdev->dev;
struct resource *res;
int ret;

res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
data->regs = devm_ioremap_resource(dev, res);
if (IS_ERR(data->regs)) {
dev_err(dev, "failed to get io address\n");
return PTR_ERR(data->regs);
}

data->clk = devm_clk_get(dev, "thermal_clk");
if (IS_ERR(data->clk)) {
ret = PTR_ERR(data->clk);
Expand All @@ -409,32 +401,13 @@ static int hi6220_thermal_probe(struct hisi_thermal_data *data)
return ret;
}

data->irq = platform_get_irq(pdev, 0);
if (data->irq < 0)
return data->irq;

data->sensor.id = HI6220_DEFAULT_SENSOR;

return 0;
}

static int hi3660_thermal_probe(struct hisi_thermal_data *data)
{
struct platform_device *pdev = data->pdev;
struct device *dev = &pdev->dev;
struct resource *res;

res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
data->regs = devm_ioremap_resource(dev, res);
if (IS_ERR(data->regs)) {
dev_err(dev, "failed to get io address\n");
return PTR_ERR(data->regs);
}

data->irq = platform_get_irq(pdev, 0);
if (data->irq < 0)
return data->irq;

data->sensor.id = HI3660_DEFAULT_SENSOR;

return 0;
Expand Down Expand Up @@ -553,6 +526,7 @@ static int hisi_thermal_probe(struct platform_device *pdev)
{
struct hisi_thermal_data *data;
struct device *dev = &pdev->dev;
struct resource *res;
int ret;

data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
Expand All @@ -564,6 +538,17 @@ static int hisi_thermal_probe(struct platform_device *pdev)
data->sensor.data = data;
data->ops = of_device_get_match_data(dev);

res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
data->regs = devm_ioremap_resource(dev, res);
if (IS_ERR(data->regs)) {
dev_err(dev, "failed to get io address\n");
return PTR_ERR(data->regs);
}

data->irq = platform_get_irq(pdev, 0);
if (data->irq < 0)
return data->irq;

ret = data->ops->probe(data);
if (ret)
return ret;
Expand Down

0 comments on commit 9bb4ec8

Please sign in to comment.