From patchwork Tue Sep 25 09:02:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 147406 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp472060lji; Tue, 25 Sep 2018 02:03:44 -0700 (PDT) X-Google-Smtp-Source: ACcGV63KWZHafdoXInwzvUdzbXFXSmsDgy++JJOabS1+M+qlBf3jVTtQSsC3+pNjTMeVBW/FV142 X-Received: by 2002:a62:798f:: with SMTP id u137-v6mr35972pfc.23.1537866224435; Tue, 25 Sep 2018 02:03:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537866224; cv=none; d=google.com; s=arc-20160816; b=C6YM828EnCEAEijZ4ZhFGz0teSatyfuNkhyIlj0J7Nk+Lu4m35ToSIPzpqnGH63wqd fvqvacw40pdMe+bb+KMCHs9eeKYC+otbndXPbMeORKRSPaIds5UeksUTddXt4mMC5j9W wOh+cEP3tJRbtVhLt6dPcCGEwVfdA8dXSHHUGz5L9PilAjtpxMfFnYODPLqVp5xvlYor /T7eYz0d8fP4vmMJWZwFQQF+b7M6Lz5oVq9A5SS94z/oPa6qh/iJuzntnmpcgp/AWsEa 4OO6Vj5vtxuhOMKKEN/Y3asNRmgKtAKzmnfQGEN/6eEZh5fZwVXjkI7/eXggs4V/s/8M 5OqA== 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=OZ13DAcracUk8ECXRhZzoH+2ruBFRvOw19LoCvex9TQ=; b=qyjY9ENbziEWA9Ae36wcx9upQqUTRH4jURCJKWGmuhaz3szt5gO/8A+42av7pbOgh8 7jAbZg84xvzuOdfC76xyvm06dtfEWCrnB2XTv0aQ8wNIdjH7kVTsw1pC4ztb5jAUY0zy +WwyeymENtqTsA6R11jOh7XSJ7MYwj2fKwXY9QykK9yeHhbxXkqxmwPcXoZm3Scz9+PQ pO2PbSwco5nS4u8RsQN85swBwkwxTEZZCBMF2nmtkjjVIcj7L8KAzb7Bj1j/k0s8bWkc zEqwH0hoxs0RTg2aXQYWzhl6aJmyH1BLRYnECJ18g2MH0dnCrDbLNCHbJ5yOaF1v9F0f 6Gqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TX+zyk2y; 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 12-v6si1893959pgv.351.2018.09.25.02.03.43; Tue, 25 Sep 2018 02:03:44 -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=TX+zyk2y; 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 S1728328AbeIYPKP (ORCPT + 10 others); Tue, 25 Sep 2018 11:10:15 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:34164 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728317AbeIYPKO (ORCPT ); Tue, 25 Sep 2018 11:10:14 -0400 Received: by mail-wm1-f65.google.com with SMTP id j25-v6so12031985wmc.1 for ; Tue, 25 Sep 2018 02:03:41 -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=OZ13DAcracUk8ECXRhZzoH+2ruBFRvOw19LoCvex9TQ=; b=TX+zyk2yMB85ok2KiqzJvZnSaiL9mgIg40Cql/dIOJgkjKtACF146jhkyKkuqVe5MW MMk8FW7QNx98TzIo+hNdYV5yDiVV1X0bV5+59jVE2ln28Y1Y74DobGx55stxdKmXOSOI lc01di//q6BRsnZchp2qAOhPKhA50VB9ID/pY= 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=OZ13DAcracUk8ECXRhZzoH+2ruBFRvOw19LoCvex9TQ=; b=HbLer+wYurkGwbldEKjYBsZg5XEjW9Th50KtIkxVYhLTY3jBLLC3i4004lkXkYJjcT CAZKqFt3y3dNKxfZkg2VC4EYUsKtyYZIkbrZZ8URjtgycLStGWxJ6V5uvvxFOIyN1SXG sP7U33uEe9qDylawCfz8OROwXMGm28lm0AZtmZfM8IgyCW43nb2PSrKgVL9iT30I76SF 71MRUBe52TgxqyUW+QUbYbQlGkbzn61sGIZmEerCu57KkzOTF8t2ZbZ6TEE2GgMizfhB jDQ655A8iHpyfgDiRZc6SVi2wPphqgq2no2mSIUCD+CS/tdWtkIZER+F2IPDmTHl/8jH o+jw== X-Gm-Message-State: ABuFfoirIc+1B+aad/8V4PYdPT6jTsS8epmWXkvpeGNEWT2LwxjnAyk+ 3uA3T8EgfbNCoi3JPXuGg00pXw== X-Received: by 2002:a1c:f11a:: with SMTP id p26-v6mr68368wmh.92.1537866220410; Tue, 25 Sep 2018 02:03:40 -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.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 25 Sep 2018 02:03:35 -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 01/14] thermal/drivers/hisi: Change the platform data pointer to sensor ops Date: Tue, 25 Sep 2018 11:02:59 +0200 Message-Id: <1537866192-12320-2-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 Group the temperature sensor specific ops into a single structure and assign it to hisi thermal data structure. Change the platform data pointer to reference the specific sensor ops instead of the probe functions. Moving out those allow to split the code to self-encapsulate the sensor object. Signed-off-by: Daniel Lezcano --- drivers/thermal/hisi_thermal.c | 60 ++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 26 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 761d055..9794cfe 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -64,11 +64,18 @@ struct hisi_thermal_sensor { uint32_t thres_temp; }; -struct hisi_thermal_data { +struct hisi_thermal_data; + +struct hisi_thermal_ops { int (*get_temp)(struct hisi_thermal_data *data); int (*enable_sensor)(struct hisi_thermal_data *data); int (*disable_sensor)(struct hisi_thermal_data *data); int (*irq_handler)(struct hisi_thermal_data *data); + int (*probe)(struct hisi_thermal_data *data); +}; + +struct hisi_thermal_data { + const struct hisi_thermal_ops *ops; struct platform_device *pdev; struct clk *clk; struct hisi_thermal_sensor sensor; @@ -374,11 +381,6 @@ static int hi6220_thermal_probe(struct hisi_thermal_data *data) struct resource *res; int ret; - data->get_temp = hi6220_thermal_get_temp; - data->enable_sensor = hi6220_thermal_enable_sensor; - data->disable_sensor = hi6220_thermal_disable_sensor; - data->irq_handler = hi6220_thermal_irq_handler; - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); data->regs = devm_ioremap_resource(dev, res); if (IS_ERR(data->regs)) { @@ -409,11 +411,6 @@ static int hi3660_thermal_probe(struct hisi_thermal_data *data) struct device *dev = &pdev->dev; struct resource *res; - data->get_temp = hi3660_thermal_get_temp; - data->enable_sensor = hi3660_thermal_enable_sensor; - data->disable_sensor = hi3660_thermal_disable_sensor; - data->irq_handler = hi3660_thermal_irq_handler; - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); data->regs = devm_ioremap_resource(dev, res); if (IS_ERR(data->regs)) { @@ -435,7 +432,7 @@ static int hisi_thermal_get_temp(void *__data, int *temp) struct hisi_thermal_data *data = __data; struct hisi_thermal_sensor *sensor = &data->sensor; - *temp = data->get_temp(data); + *temp = data->ops->get_temp(data); dev_dbg(&data->pdev->dev, "id=%d, temp=%d, thres=%d\n", sensor->id, *temp, sensor->thres_temp); @@ -453,7 +450,7 @@ static irqreturn_t hisi_thermal_alarm_irq_thread(int irq, void *dev) struct hisi_thermal_sensor *sensor = &data->sensor; int temp = 0; - data->irq_handler(data); + data->ops->irq_handler(data); hisi_thermal_get_temp(data, &temp); @@ -502,14 +499,30 @@ static int hisi_thermal_register_sensor(struct platform_device *pdev, return 0; } +static const struct hisi_thermal_ops hi6220_ops = { + .get_temp = hi6220_thermal_get_temp, + .enable_sensor = hi6220_thermal_enable_sensor, + .disable_sensor = hi6220_thermal_disable_sensor, + .irq_handler = hi6220_thermal_irq_handler, + .probe = hi6220_thermal_probe, +}; + +static const struct hisi_thermal_ops hi3660_ops = { + .get_temp = hi3660_thermal_get_temp, + .enable_sensor = hi3660_thermal_enable_sensor, + .disable_sensor = hi3660_thermal_disable_sensor, + .irq_handler = hi3660_thermal_irq_handler, + .probe = hi3660_thermal_probe, +}; + static const struct of_device_id of_hisi_thermal_match[] = { { .compatible = "hisilicon,tsensor", - .data = hi6220_thermal_probe + .data = &hi6220_ops, }, { .compatible = "hisilicon,hi3660-tsensor", - .data = hi3660_thermal_probe + .data = &hi3660_ops, }, { /* end */ } }; @@ -527,7 +540,6 @@ static void hisi_thermal_toggle_sensor(struct hisi_thermal_sensor *sensor, static int hisi_thermal_probe(struct platform_device *pdev) { struct hisi_thermal_data *data; - int (*platform_probe)(struct hisi_thermal_data *); struct device *dev = &pdev->dev; int ret; @@ -538,13 +550,9 @@ static int hisi_thermal_probe(struct platform_device *pdev) data->pdev = pdev; platform_set_drvdata(pdev, data); - platform_probe = of_device_get_match_data(dev); - if (!platform_probe) { - dev_err(dev, "failed to get probe func\n"); - return -EINVAL; - } + data->ops = of_device_get_match_data(dev); - ret = platform_probe(data); + ret = data->ops->probe(data); if (ret) return ret; @@ -555,7 +563,7 @@ static int hisi_thermal_probe(struct platform_device *pdev) return ret; } - ret = data->enable_sensor(data); + ret = data->ops->enable_sensor(data); if (ret) { dev_err(dev, "Failed to setup the sensor: %d\n", ret); return ret; @@ -583,7 +591,7 @@ static int hisi_thermal_remove(struct platform_device *pdev) hisi_thermal_toggle_sensor(sensor, false); - data->disable_sensor(data); + data->ops->disable_sensor(data); return 0; } @@ -593,7 +601,7 @@ static int hisi_thermal_suspend(struct device *dev) { struct hisi_thermal_data *data = dev_get_drvdata(dev); - data->disable_sensor(data); + data->ops->disable_sensor(data); return 0; } @@ -602,7 +610,7 @@ static int hisi_thermal_resume(struct device *dev) { struct hisi_thermal_data *data = dev_get_drvdata(dev); - return data->enable_sensor(data); + return data->ops->enable_sensor(data); } #endif