From patchwork Tue Sep 25 09:03:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 147409 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp472341lji; Tue, 25 Sep 2018 02:04:03 -0700 (PDT) X-Google-Smtp-Source: ACcGV60ns0UtqkbHANxKx15//y15YErHG0skkm1TC/xsQeQgK/gVqsjf7D4ZZsOiFPy42Rt6PmpW X-Received: by 2002:a17:902:b287:: with SMTP id u7-v6mr71488plr.123.1537866243118; Tue, 25 Sep 2018 02:04:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537866243; cv=none; d=google.com; s=arc-20160816; b=B1Pa9IOF6Pk+mWrtVa2qbNjAgwjOyfa4xk69aNxNMtEDdAS0C4dxnXiHGiVSHWZH1+ /fxw7mpitUP17zCAtyIaXzbpyTQJojhiud2k24MBf18K6gtK1OoIvudBNlo57P6qxtiF wGaFUs/TTvCLQFs9Fx8F49RNumkF9Fy+6Z0cltthxOVDScQp+CilbEuqzzZkHUMwd5ea 9yWQ6dtTIX11kwO6jw1WYAIW/sxPNVofDxwvvE7JEXcSqTaLVkgaA0xgfWTYcT4FR4ic psSN+jxYPU0rnTLn1lf1wPVvc3qaUEY7MqH3B7kLflpK5GgDUvp+ah4oVysPRaAeA7Pj nFPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=n7P2OSw8y61wcHZXfde/sCT0rh4Lfv8tdnBhTgzGYnU=; b=s5IwoeSXnQh1jXeg1SgMMRSnjJ/q9Tgj86MHIVu9CnR7jFPuJ6Upof5wCI/PjqEJHN O5ZvjJIyyONfeyLr+v029KKgNbTZ3n+IOM78UTZSxN7VobKy+xEJz54C7VrE0Iwap7YN qqb+3eAalcVm2+CeJa2qAQU8mD1Y1T7v5Wven8JbWGJeZoU5qdHK0FJrKjfVD5Aej8wC 9zECCoe1tnk0GPcZmPZi7TbpYMSAiYkUKV7d+zIuQQnA0HGusPOLNEmww1qbR3kaFZQ+ SyslS5gGUtLKKtPcFK5lyYJqsDgiwizbN66nhVEVuu4NeE1CWlyzyYKV+VNVyb2GjV8o KYoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="LQ/xRaZn"; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cb8-v6si1602909plb.178.2018.09.25.02.04.02; Tue, 25 Sep 2018 02:04:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="LQ/xRaZn"; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728659AbeIYPKd (ORCPT + 10 others); Tue, 25 Sep 2018 11:10:33 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:36461 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728655AbeIYPKd (ORCPT ); Tue, 25 Sep 2018 11:10:33 -0400 Received: by mail-wr1-f66.google.com with SMTP id e1-v6so22478473wrt.3 for ; Tue, 25 Sep 2018 02:04:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=n7P2OSw8y61wcHZXfde/sCT0rh4Lfv8tdnBhTgzGYnU=; b=LQ/xRaZnZ/dByBF9rTFaqMOVQLxUFJsdsQuNwcwYXVMOiE7ZzLbROcZKTmIbOpZ7TN AFsSF6M724qkJoYhG7DpaOM+diUc+jLwuKIRT6vYf8jSkGcQ/mOc6zEjdMH5c8j2Kgyd bpbUEU+Zci6i7DYhWpNqC+AEv/rWss5sWztRg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=n7P2OSw8y61wcHZXfde/sCT0rh4Lfv8tdnBhTgzGYnU=; b=fpu7F0aApoJ6sQ+EUXXKTX/O1+5IGJ9mMv6Zk3qD2NsJvdoHdnstuG5BF9S8DkALCh 3cYRmdyqfdIIDpgvS+XSVPIbGDwz6+z61+vNRLdLON3D3VBGyxYJngoM6cL+OAhOmYVa gAk2pz8T1sj/O9mWatKwzzcELl+VNpyK9gU5b54krCs3ipA/3E9DlO4UulrXxOf/CW63 J5exDniiIOJGpXyIc4kbhPtHosOmLKjojze+rDtW4VQtRByGAxlBE+FgZPnqge+SXqXI K+gv7SAH/DR0UNThcebAgqSaBkQ+JMAju1Ow/FXIhBe7H4+ugpCGOm6+C4bQgLr/MXVi djhg== X-Gm-Message-State: ABuFfogJ/I05kmC60AYclxIx3wvTft/GY655+X34xP3qYeXCqA7ta9Ty wsS0lsAMnZPg3IndlfE/H6SIyg== X-Received: by 2002:adf:8425:: with SMTP id 34-v6mr12377wrf.153.1537866239922; Tue, 25 Sep 2018 02:03:59 -0700 (PDT) Received: from localhost.localdomain (251.150.136.77.rev.sfr.net. [77.136.150.251]) by smtp.gmail.com with ESMTPSA id y206-v6sm1523828wmg.14.2018.09.25.02.03.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 25 Sep 2018 02:03:52 -0700 (PDT) From: Daniel Lezcano To: edubezval@gmail.com Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, daniel.lezcano@linaro.org, leo.yan@linaro.org, Zhang Rui Subject: [PATCH 04/14] thermal/drivers/hisi: Factor out the probe functions Date: Tue, 25 Sep 2018 11:03:02 +0200 Message-Id: <1537866192-12320-5-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1537866192-12320-1-git-send-email-daniel.lezcano@linaro.org> References: <1537866192-12320-1-git-send-email-daniel.lezcano@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org 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 --- drivers/thermal/hisi_thermal.c | 39 ++++++++++++--------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 567fde6..7287818 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) { 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); @@ -409,10 +401,6 @@ 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; @@ -420,21 +408,6 @@ static int hi6220_thermal_probe(struct hisi_thermal_data *data) 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; @@ -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); @@ -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;