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: 10613713 X-Patchwork-Delegate: eduardo.valentin@ti.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D865216B1 for ; Tue, 25 Sep 2018 09:04:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB1B72836F for ; Tue, 25 Sep 2018 09:04:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BF02229342; Tue, 25 Sep 2018 09:04:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 584032836F for ; Tue, 25 Sep 2018 09:04:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728659AbeIYPKd (ORCPT ); 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-Google-Smtp-Source: ACcGV60mDHOmUD35l0uF2lPStiIueUCz2vCAOHzvHOURJmTuNlK5tExCmgR/b9nxFZ4CxpzhMHhgbg== 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 X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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;