From patchwork Tue Sep 25 09:03:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 147407 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp472139lji; Tue, 25 Sep 2018 02:03:49 -0700 (PDT) X-Google-Smtp-Source: ACcGV61O6sKyQqwQzwJAdII9s5Gv3b2JjcSxRBivIhxWRgG949D/GXHe3zxs8bO5SME6VPtpd/QX X-Received: by 2002:a62:db46:: with SMTP id f67-v6mr37159pfg.1.1537866229651; Tue, 25 Sep 2018 02:03:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537866229; cv=none; d=google.com; s=arc-20160816; b=pr/1lNxmDg3g8DHmCrc7nrG/ALvjz0SZ53HjlP7FRnC9lUMhBy7D8yOCMyUneky/je pK6jfTz3AmKvt9ePk/EzE1kNijGz7Ro4BpTuFc0jK20nk9fAOtZw3E3VFBfywFMmN6HO im0V1ub5E7ieGOxPxjKsBgTFd0xr0NpOR/cqpfEtA+kFamGzNSbqY/jRYN8LlyjFt2WQ TpOk0/EkDLyYKA31lMLLiV3NVrBBGGXYMnPkkDLcTBwbgALjNmcpHa6El19f49h399vt 7yxGXwg6qr4l9h5CIYnMMh03btk/F+AdWXP4thh5xQ2LtGNLloiudPh96hmEvgrHvhT9 51pA== 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=JKtye1UkuEcXKPFhNVW7GNxXrGnc1c47iAdiNPq2Uxg=; b=Qa+1qbnPmW22y6FuUn+Y6smI7nEyiam5gl+sTOimWNssqIRvOvSZU8IcAITzHT73Ov lEWA0D512KpblcdOvCLKjG0uurQr+iIyLuTvT50MNu/knd51kDUKm9z735YxZopuiQpy aZu5WQQie4L2ZUZQWcVBtY68uHlLKFpTTsEuVS/jVddTn/C4HhVl/gQ+g3Jm9cQtxWzC kgbZNPwlaAMKyIh37RFYbr26cKGwpttdwCE4KVKv7CwfgpcuI0A8Heq49xjSogXasIpw Qk3wfzx9EFp13iyF+GL1P+7nncCSOIoN4GM8a2E8lYjoYoAG0N+u8oPOJRO6f/2MsaCV a7xA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cbdFeuBr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 3-v6si1873633plx.173.2018.09.25.02.03.49; Tue, 25 Sep 2018 02:03:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=cbdFeuBr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 S1728543AbeIYPKU (ORCPT + 32 others); Tue, 25 Sep 2018 11:10:20 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:35470 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727678AbeIYPKT (ORCPT ); Tue, 25 Sep 2018 11:10:19 -0400 Received: by mail-wr1-f67.google.com with SMTP id o16so9157172wrx.2 for ; Tue, 25 Sep 2018 02:03:46 -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=JKtye1UkuEcXKPFhNVW7GNxXrGnc1c47iAdiNPq2Uxg=; b=cbdFeuBrE/DKJJz1QSZJFGPjEAFse41UeHzPKMZERRGt78pGqap+46Di+4OVPQcwzE l6jZrWxI0t16pbiLxIBXRHXKQZh+1cJgRSvKvA4223WBrOP7jJw9txR+eBP5fzsDoxC1 wDgRHAuoHLqv4a0XOIhNGzjKfsHOWV2R9cHJI= 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=JKtye1UkuEcXKPFhNVW7GNxXrGnc1c47iAdiNPq2Uxg=; b=fce6h2nGMn7fPFswUlS5y35E2XhAMe4EB7UZWvWhOdpKqBQWNZhQ6oEggFzBio5Z8S NgyEa2suR8UpF1mWfxMEnjiIQP75nsSJ56S1qRk8Es0jTc4TUO4DdWdPkwalHG7GcIoI fyfKpenIvCg1RQ5pvULzFNHqpvmBrvosFgWvnLAQeC7Ch2Chu8Qpa/TCZVpqkm5ThDzm 5tOsqY4jyCuCD1QrNeVHGr675ORD0s/mhBmWopFfzOVgy0XaNNmQ3oPb4Xesda3DmmoF 69TZ6Ga5QPaItLYG1Jkwcv7b2AJvJNMBIPYhv3NvhuAgFTQsTr8hBNY+KYMFmAidfSKC rOpw== X-Gm-Message-State: ABuFfojLWZR/VG9YQMoRG7avzmhd1nxivwQEFqF7/lsjyvj02bJnWjJq U6l7RFvSRc6XLMRk7W3A0X2K+w== X-Received: by 2002:adf:80a3:: with SMTP id 32-v6mr1131wrl.231.1537866225446; Tue, 25 Sep 2018 02:03:45 -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.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 25 Sep 2018 02:03:42 -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 02/14] thermal/drivers/hisi: Change the driver to be sensor oriented Date: Tue, 25 Sep 2018 11:03:00 +0200 Message-Id: <1537866192-12320-3-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In order to support multiple sensors, we have to change the code to deal with sensors and not the hisi thermal structure. Add a back pointer to the hisi thermal structure (containerof is not a good option because later we convert the sensor field to a pointer). Change the functions parameters to take a sensor instead of this hisi thermal 'data' structure. Signed-off-by: Daniel Lezcano --- drivers/thermal/hisi_thermal.c | 72 ++++++++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 30 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 9794cfe..1fdda55 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -58,27 +58,28 @@ #define HI6220_DEFAULT_SENSOR 2 #define HI3660_DEFAULT_SENSOR 1 +struct hisi_thermal_data; + struct hisi_thermal_sensor { + struct hisi_thermal_data *data; struct thermal_zone_device *tzd; uint32_t id; uint32_t thres_temp; }; -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 (*get_temp)(struct hisi_thermal_sensor *sensor); + int (*enable_sensor)(struct hisi_thermal_sensor *sensor); + int (*disable_sensor)(struct hisi_thermal_sensor *sensor); + int (*irq_handler)(struct hisi_thermal_sensor *sensor); int (*probe)(struct hisi_thermal_data *data); }; struct hisi_thermal_data { const struct hisi_thermal_ops *ops; + struct hisi_thermal_sensor sensor; struct platform_device *pdev; struct clk *clk; - struct hisi_thermal_sensor sensor; void __iomem *regs; int irq; }; @@ -273,30 +274,40 @@ static inline void hi6220_thermal_hdak_set(void __iomem *addr, int value) (value << 4), addr + HI6220_TEMP0_CFG); } -static int hi6220_thermal_irq_handler(struct hisi_thermal_data *data) +static int hi6220_thermal_irq_handler(struct hisi_thermal_sensor *sensor) { + struct hisi_thermal_data *data = sensor->data; + hi6220_thermal_alarm_clear(data->regs, 1); return 0; } -static int hi3660_thermal_irq_handler(struct hisi_thermal_data *data) +static int hi3660_thermal_irq_handler(struct hisi_thermal_sensor *sensor) { - hi3660_thermal_alarm_clear(data->regs, data->sensor.id, 1); + struct hisi_thermal_data *data = sensor->data; + + hi3660_thermal_alarm_clear(data->regs, sensor->id, 1); return 0; } -static int hi6220_thermal_get_temp(struct hisi_thermal_data *data) +static int hi6220_thermal_get_temp(struct hisi_thermal_sensor *sensor) { + struct hisi_thermal_data *data = sensor->data; + return hi6220_thermal_get_temperature(data->regs); } -static int hi3660_thermal_get_temp(struct hisi_thermal_data *data) +static int hi3660_thermal_get_temp(struct hisi_thermal_sensor *sensor) { - return hi3660_thermal_get_temperature(data->regs, data->sensor.id); + struct hisi_thermal_data *data = sensor->data; + + return hi3660_thermal_get_temperature(data->regs, sensor->id); } -static int hi6220_thermal_disable_sensor(struct hisi_thermal_data *data) +static int hi6220_thermal_disable_sensor(struct hisi_thermal_sensor *sensor) { + struct hisi_thermal_data *data = sensor->data; + /* disable sensor module */ hi6220_thermal_enable(data->regs, 0); hi6220_thermal_alarm_enable(data->regs, 0); @@ -307,16 +318,18 @@ static int hi6220_thermal_disable_sensor(struct hisi_thermal_data *data) return 0; } -static int hi3660_thermal_disable_sensor(struct hisi_thermal_data *data) +static int hi3660_thermal_disable_sensor(struct hisi_thermal_sensor *sensor) { + struct hisi_thermal_data *data = sensor->data; + /* disable sensor module */ - hi3660_thermal_alarm_enable(data->regs, data->sensor.id, 0); + hi3660_thermal_alarm_enable(data->regs, sensor->id, 0); return 0; } -static int hi6220_thermal_enable_sensor(struct hisi_thermal_data *data) +static int hi6220_thermal_enable_sensor(struct hisi_thermal_sensor *sensor) { - struct hisi_thermal_sensor *sensor = &data->sensor; + struct hisi_thermal_data *data = sensor->data; int ret; /* enable clock for tsensor */ @@ -352,10 +365,10 @@ static int hi6220_thermal_enable_sensor(struct hisi_thermal_data *data) return 0; } -static int hi3660_thermal_enable_sensor(struct hisi_thermal_data *data) +static int hi3660_thermal_enable_sensor(struct hisi_thermal_sensor *sensor) { unsigned int value; - struct hisi_thermal_sensor *sensor = &data->sensor; + struct hisi_thermal_data *data = sensor->data; /* disable interrupt */ hi3660_thermal_alarm_enable(data->regs, sensor->id, 0); @@ -432,7 +445,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->ops->get_temp(data); + *temp = data->ops->get_temp(sensor); dev_dbg(&data->pdev->dev, "id=%d, temp=%d, thres=%d\n", sensor->id, *temp, sensor->thres_temp); @@ -450,7 +463,7 @@ static irqreturn_t hisi_thermal_alarm_irq_thread(int irq, void *dev) struct hisi_thermal_sensor *sensor = &data->sensor; int temp = 0; - data->ops->irq_handler(data); + data->ops->irq_handler(sensor); hisi_thermal_get_temp(data, &temp); @@ -470,10 +483,10 @@ static irqreturn_t hisi_thermal_alarm_irq_thread(int irq, void *dev) } static int hisi_thermal_register_sensor(struct platform_device *pdev, - struct hisi_thermal_data *data, struct hisi_thermal_sensor *sensor) { int ret, i; + struct hisi_thermal_data *data = sensor->data; const struct thermal_trip *trip; sensor->tzd = devm_thermal_zone_of_sensor_register(&pdev->dev, @@ -549,21 +562,20 @@ static int hisi_thermal_probe(struct platform_device *pdev) data->pdev = pdev; platform_set_drvdata(pdev, data); - + data->sensor.data = data; data->ops = of_device_get_match_data(dev); ret = data->ops->probe(data); if (ret) return ret; - ret = hisi_thermal_register_sensor(pdev, data, - &data->sensor); + ret = hisi_thermal_register_sensor(pdev, &data->sensor); if (ret) { dev_err(dev, "failed to register thermal sensor: %d\n", ret); return ret; } - ret = data->ops->enable_sensor(data); + ret = data->ops->enable_sensor(&data->sensor); if (ret) { dev_err(dev, "Failed to setup the sensor: %d\n", ret); return ret; @@ -591,7 +603,7 @@ static int hisi_thermal_remove(struct platform_device *pdev) hisi_thermal_toggle_sensor(sensor, false); - data->ops->disable_sensor(data); + data->ops->disable_sensor(&data->sensor); return 0; } @@ -601,7 +613,7 @@ static int hisi_thermal_suspend(struct device *dev) { struct hisi_thermal_data *data = dev_get_drvdata(dev); - data->ops->disable_sensor(data); + data->ops->disable_sensor(&data->sensor); return 0; } @@ -610,7 +622,7 @@ static int hisi_thermal_resume(struct device *dev) { struct hisi_thermal_data *data = dev_get_drvdata(dev); - return data->ops->enable_sensor(data); + return data->ops->enable_sensor(&data->sensor); } #endif