From patchwork Tue Sep 25 09:03:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 147411 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp472826lji; Tue, 25 Sep 2018 02:04:30 -0700 (PDT) X-Google-Smtp-Source: ACcGV616Ypl12Oc7ak14dAMGzNTHapaAjYKqpHA5qaHGO6xg9KxEqtN45T5RF+UWeDzCKhBO0qaw X-Received: by 2002:a63:5c5d:: with SMTP id n29-v6mr55333pgm.253.1537866270670; Tue, 25 Sep 2018 02:04:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537866270; cv=none; d=google.com; s=arc-20160816; b=m8eXiBXuXlZ+6DO61PfA2hCh4CZ1ZLbVUmviQrukGLDJKtsEcbpil98M9x61tsjHJN 21oGFTS7mPO8MTywYOoH1yWf2WOmEPRUxH8RoDaEo4ccHRthKkBNECF9swvKUI7vrR7L rzDacJTQdd01RqRNP8EjSrdHa53/Iwqtb4XyoqX632yDvbktN0LgcQQzAUCniEXb5qLZ 009RCZzB8Wn8RWx+ld9z8l5Xa6iz0BnUL+7R6oFPQTx9vTL/I3AKJkIfVOn4PTe81buN eouyOufO7SJO+OyxsANecPxkT+sCRVn7GlEk6HZCeNNixFSkoMbchMUEuHb/ZL4lavTm KhQw== 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=WEayJ7v/hmTPrXvagArEZzBi0kAZmXnqnjkohn08PO0=; b=hyjziWwur3tZ0z+Ds1xh841hZHbgaKCWQ6ZwHRhdnW3gdLGj/b8I49jxvq9itXTM9Q hVfGXqCQvZXHvkNaqyo3aiRXBpz4zUMfLB6u4kkrhwog4n6ZrBHkalYF9dZS5uFKL8mb RyNWmYxFJMuIhNwfcg6BySY9d87PvGO0NUowaJ31aNqgq8iz00bYRblJwg/jeyBvASR9 X6vXKT+NZkl37KPdG0uBFsf0yIWYwCtjZKGhYsAeWuPi1vazuzX0eGowyTEcyc0Rn3Rp IHBPQPwvXdy2m+Od68OjXUAqcyJUveqRnpxKCKEJnd8Qi2JcTXxnEt/fmnMmy2tvOuLN 5/KQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Sb0oe1lb; 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 p15-v6si1932374pgr.336.2018.09.25.02.04.30; Tue, 25 Sep 2018 02:04:30 -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=Sb0oe1lb; 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 S1727767AbeIYPLB (ORCPT + 10 others); Tue, 25 Sep 2018 11:11:01 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:35565 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727606AbeIYPLB (ORCPT ); Tue, 25 Sep 2018 11:11:01 -0400 Received: by mail-wr1-f68.google.com with SMTP id o16so9159722wrx.2 for ; Tue, 25 Sep 2018 02:04:27 -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=WEayJ7v/hmTPrXvagArEZzBi0kAZmXnqnjkohn08PO0=; b=Sb0oe1lbClXkht5v1ucQ3Geuyw1Ij5+Gor0f/HIPYD6vunyMzaHIsQXNOU94M6JgPR /xx/ji5DaC/y69kOUsBpzHZwzBe+f6wfR7nTUaRL1GqcYR/Qszu4BTwADC/H6Sz5Ctp8 oOPFPbXb2d2JxKGgMgBxIA2m5jg18jipV/6E0= 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=WEayJ7v/hmTPrXvagArEZzBi0kAZmXnqnjkohn08PO0=; b=L5MkF73s6ggOxRs5Y8mBIOrmfe8JUGvh7dQHCdVGLxKnjLjN3hCQhg6PF2Gxrg+SSV bop6RYFuC7Ivou+4IRGJvqorEoN12Ihsp4Zkmk/L6gLdsJhQAe1l2nLbFc574nUH59ot n+d2CQ/WH+nTZkHhUBwZzHxX/VLC32zrx+oIWY5lGQV6doLBGt1eqyVSNDB0HHevGsCl rVLgn7nHZ1+O39LvE8ZmYptPof2QAzVS9nQi+pw+3RZJd095sM7ZUZ0poOlg9adeGuOU mDGKHny78olV8P05Er5Z8MTI9VwEkAjT3KhhjKdDy6JC849/XlyeYQpMuiN/Py/qCXCy NYLA== X-Gm-Message-State: ABuFfogMY5xkzfAg9lz3BEFzD+8ixhs33Oe3CC4CJe6GuV/fzTMSe4ro adqQxEtsCVC7NmVvrGD6c4S2Vw== X-Received: by 2002:a5d:448d:: with SMTP id j13-v6mr40153wrq.236.1537866266930; Tue, 25 Sep 2018 02:04:26 -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.04.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 25 Sep 2018 02:04:25 -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 06/14] thermal/drivers/hisi: Add multiple sensors support Date: Tue, 25 Sep 2018 11:03:04 +0200 Message-Id: <1537866192-12320-7-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 Change the code as it is dealing with several sensors. For git-bisect compatibility (compilation and booting), assume the DT is not yet changed and we have a single interrupt. Next changes will support multiple interrupt sorted by their name. Signed-off-by: Daniel Lezcano --- drivers/thermal/hisi_thermal.c | 79 +++++++++++++++++++++++++----------------- 1 file changed, 47 insertions(+), 32 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 87b82fb..a5756f6 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -448,8 +448,8 @@ static const struct thermal_zone_of_device_ops hisi_of_thermal_ops = { static irqreturn_t hisi_thermal_alarm_irq_thread(int irq, void *dev) { - struct hisi_thermal_data *data = dev; - struct hisi_thermal_sensor *sensor = &data->sensor[0]; + struct hisi_thermal_sensor *sensor = dev; + struct hisi_thermal_data *data = sensor->data; int temp = 0; data->ops->irq_handler(sensor); @@ -457,15 +457,17 @@ static irqreturn_t hisi_thermal_alarm_irq_thread(int irq, void *dev) hisi_thermal_get_temp(sensor, &temp); if (temp >= sensor->thres_temp) { - dev_crit(&data->pdev->dev, "THERMAL ALARM: %d > %d\n", - temp, sensor->thres_temp); + dev_crit(&data->pdev->dev, + "sensor <%d> THERMAL ALARM: %d > %d\n", + sensor->id, temp, sensor->thres_temp); - thermal_zone_device_update(data->sensor[0].tzd, + thermal_zone_device_update(sensor->tzd, THERMAL_EVENT_UNSPECIFIED); } else { - dev_crit(&data->pdev->dev, "THERMAL ALARM stopped: %d < %d\n", - temp, sensor->thres_temp); + dev_crit(&data->pdev->dev, + "sensor <%d> THERMAL ALARM stopped: %d < %d\n", + sensor->id, temp, sensor->thres_temp); } return IRQ_HANDLED; @@ -543,7 +545,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; + int i, ret; data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); if (!data) @@ -560,37 +562,41 @@ static int hisi_thermal_probe(struct platform_device *pdev) 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; - ret = hisi_thermal_register_sensor(pdev, &data->sensor[0]); - if (ret) { - dev_err(dev, "failed to register thermal sensor: %d\n", ret); - return ret; - } + for (i = 0; i < data->nr_sensors; i++) { + struct hisi_thermal_sensor *sensor = &data->sensor[i]; - ret = data->ops->enable_sensor(&data->sensor[0]); - if (ret) { - dev_err(dev, "Failed to setup the sensor: %d\n", ret); - return ret; - } + ret = hisi_thermal_register_sensor(pdev, sensor); + if (ret) { + dev_err(dev, "failed to register thermal sensor: %d\n", + ret); + return ret; + } + + data->irq = platform_get_irq(pdev, 0); + if (data->irq < 0) + return data->irq; - if (data->irq) { ret = devm_request_threaded_irq(dev, data->irq, NULL, - hisi_thermal_alarm_irq_thread, - IRQF_ONESHOT, "hisi_thermal", data); + hisi_thermal_alarm_irq_thread, + IRQF_ONESHOT, "hisi_thermal", + sensor); if (ret < 0) { dev_err(dev, "failed to request alarm irq: %d\n", ret); return ret; } - } - hisi_thermal_toggle_sensor(&data->sensor[0], true); + ret = data->ops->enable_sensor(sensor); + if (ret) { + dev_err(dev, "Failed to setup the sensor: %d\n", ret); + return ret; + } + + hisi_thermal_toggle_sensor(sensor, true); + } return 0; } @@ -598,11 +604,14 @@ static int hisi_thermal_probe(struct platform_device *pdev) static int hisi_thermal_remove(struct platform_device *pdev) { struct hisi_thermal_data *data = platform_get_drvdata(pdev); - struct hisi_thermal_sensor *sensor = &data->sensor[0]; + int i; - hisi_thermal_toggle_sensor(sensor, false); + for (i = 0; i < data->nr_sensors; i++) { + struct hisi_thermal_sensor *sensor = &data->sensor[i]; - data->ops->disable_sensor(sensor); + hisi_thermal_toggle_sensor(sensor, false); + data->ops->disable_sensor(sensor); + } return 0; } @@ -611,8 +620,10 @@ static int hisi_thermal_remove(struct platform_device *pdev) static int hisi_thermal_suspend(struct device *dev) { struct hisi_thermal_data *data = dev_get_drvdata(dev); + int i; - data->ops->disable_sensor(&data->sensor[0]); + for (i = 0; i < data->nr_sensors; i++) + data->ops->disable_sensor(&data->sensor[i]); return 0; } @@ -620,8 +631,12 @@ static int hisi_thermal_suspend(struct device *dev) static int hisi_thermal_resume(struct device *dev) { struct hisi_thermal_data *data = dev_get_drvdata(dev); + int i, ret = 0; + + for (i = 0; i < data->nr_sensors; i++) + ret |= data->ops->enable_sensor(&data->sensor[i]); - return data->ops->enable_sensor(&data->sensor[0]); + return ret; } #endif