From patchwork Tue Dec 10 16:41:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11282977 X-Patchwork-Delegate: daniel.lezcano@linaro.org Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7C9656C1 for ; Tue, 10 Dec 2019 16:42:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5A58F20836 for ; Tue, 10 Dec 2019 16:42:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="R340kJVk" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727664AbfLJQmL (ORCPT ); Tue, 10 Dec 2019 11:42:11 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:46003 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727508AbfLJQmJ (ORCPT ); Tue, 10 Dec 2019 11:42:09 -0500 Received: by mail-pg1-f196.google.com with SMTP id b9so8755179pgk.12; Tue, 10 Dec 2019 08:42:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pjibFk638PnQ42hwKONZvOkVbixVgcRlW8yZGOEeC5k=; b=R340kJVkWJNHcEMhdnyHpd44lvGwReYozuc5ySZzK5nc1oJ0Pjk60wYFad1hFzc3AA t8dN6jAavm6xOs/1GFfbz9hcqOEO4bfr1bRLx2nddNNVyRPWGDov9Sbjut1A8d/IgMw7 vJ4iX8Sr+njRpuDt7rTRBGpjjVkMnyE2cjFstZIs6cPMa8rFN5ef8hLukjaKC5FUqZvi yNLn2WM44kTm3p0GZehSIB7iCqXVciT0X2KXedXbemK1QfehzCkz6Xk5IP7lfOW3aGHu MiJ5hy66syJbHNkKz36R3C/IMdop2wl1WamBFAu7HRJcIXNKP+LSgALmNtntkZ8DMN9A XMlg== 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:mime-version:content-transfer-encoding; bh=pjibFk638PnQ42hwKONZvOkVbixVgcRlW8yZGOEeC5k=; b=OWvYK7hEzxbstDr7LKFipG0e2SOpZoLAncGOWFeARkEbpwp/5AE55V6exS6sGYMnA1 Khr1slKJdQFjGV2JUJWBS7bJfk8eEAMZ+X5SwGvorm9nY9I4opsZHUKKT1O6O4xDUdTB 8i0MKuvoeqoWxzhZ3EnRYcqcKuKLzCR9XROWPbXutg+h6nxLgWUo0gaSQwF8QCyLi0L2 iK0F3VsNndc9q84BC7bxsnBYBlhwE5gMP5PDP26r3iH352bQxsLaCFXyFFihOQVL9ukN ba673NBsJjYWU7Idwl+fBakxK0bHFNYDDneFe7DpCFMqmPbcC/+K5VYP8i4pZFGXBd/T K0dg== X-Gm-Message-State: APjAAAVFbubGrMOquIwSXuY3Y2JOhjqbDKEsaL9L20R4oygvmcqD3UY6 3bsTQjdhEyN7OJSw6EO5J3Ebgswgr60= X-Google-Smtp-Source: APXvYqzWk6B2yzJ7FtTSAlswTDUDgrDrRvzUx/IRVowCGQH2J+1hpA2U+w/5ZLO/F5QjJwreNWe3UA== X-Received: by 2002:a63:4b24:: with SMTP id y36mr25444347pga.176.1575996128192; Tue, 10 Dec 2019 08:42:08 -0800 (PST) Received: from localhost.localdomain (c-67-165-113-11.hsd1.wa.comcast.net. [67.165.113.11]) by smtp.gmail.com with ESMTPSA id j38sm4034634pgj.27.2019.12.10.08.42.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 08:42:06 -0800 (PST) From: Andrey Smirnov To: Daniel Lezcano Cc: Andrey Smirnov , Lucas Stach , Chris Healy , Eduardo Valentin , Angus Ainslie , linux-imx@nxp.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v8 01/12] thermal: qoriq: Add local struct device pointer Date: Tue, 10 Dec 2019 08:41:42 -0800 Message-Id: <20191210164153.10463-2-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191210164153.10463-1-andrew.smirnov@gmail.com> References: <20191210164153.10463-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Use a local "struct device *dev" for brevity. No functional change intended. Signed-off-by: Andrey Smirnov Acked-by: Daniel Lezcano Tested-by: Lucas Stach Cc: Chris Healy Cc: Lucas Stach Cc: Eduardo Valentin Cc: Daniel Lezcano Cc: Angus Ainslie (Purism) Cc: linux-imx@nxp.com Cc: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/thermal/qoriq_thermal.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/thermal/qoriq_thermal.c b/drivers/thermal/qoriq_thermal.c index 45e9fcb172cc..dd47b31aeecc 100644 --- a/drivers/thermal/qoriq_thermal.c +++ b/drivers/thermal/qoriq_thermal.c @@ -262,8 +262,9 @@ static int qoriq_tmu_probe(struct platform_device *pdev) u32 ver; struct qoriq_tmu_data *data; struct device_node *np = pdev->dev.of_node; + struct device *dev = &pdev->dev; - data = devm_kzalloc(&pdev->dev, sizeof(struct qoriq_tmu_data), + data = devm_kzalloc(dev, sizeof(struct qoriq_tmu_data), GFP_KERNEL); if (!data) return -ENOMEM; @@ -274,17 +275,17 @@ static int qoriq_tmu_probe(struct platform_device *pdev) data->regs = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(data->regs)) { - dev_err(&pdev->dev, "Failed to get memory region\n"); + dev_err(dev, "Failed to get memory region\n"); return PTR_ERR(data->regs); } - data->clk = devm_clk_get_optional(&pdev->dev, NULL); + data->clk = devm_clk_get_optional(dev, NULL); if (IS_ERR(data->clk)) return PTR_ERR(data->clk); ret = clk_prepare_enable(data->clk); if (ret) { - dev_err(&pdev->dev, "Failed to enable clock\n"); + dev_err(dev, "Failed to enable clock\n"); return ret; } @@ -302,7 +303,7 @@ static int qoriq_tmu_probe(struct platform_device *pdev) ret = qoriq_tmu_register_tmu_zone(pdev); if (ret < 0) { - dev_err(&pdev->dev, "Failed to register sensors\n"); + dev_err(dev, "Failed to register sensors\n"); ret = -ENODEV; goto err; } From patchwork Tue Dec 10 16:41:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11282999 X-Patchwork-Delegate: daniel.lezcano@linaro.org Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BF9A01593 for ; Tue, 10 Dec 2019 16:43:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9E8A820838 for ; Tue, 10 Dec 2019 16:43:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SeHa9vyU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727673AbfLJQmM (ORCPT ); Tue, 10 Dec 2019 11:42:12 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:42312 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727663AbfLJQmL (ORCPT ); Tue, 10 Dec 2019 11:42:11 -0500 Received: by mail-pf1-f194.google.com with SMTP id 4so108837pfz.9; Tue, 10 Dec 2019 08:42:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1CVdA9r3UVKQnabq2mx7w9JDC1aJtWHX+VPZ20Gprac=; b=SeHa9vyU4/5ORBBMIwkil5fZpYyec136edPWMMh+HEhNU6zc9cWB9Qx+uE2+58kuep 5L70XerBhwQ4FqIHu4/ZKmJAHLUSC5TCHhkSQthO8sqZSGZq1uMr1uysm2Ja2IqEMHy8 tpivOuNxjQcQBBqV5puReQtQteCyL1LOCOeAc6A17KDUob4iHSozZYgfDP6Ow9oRBFYY H6/yAgnkrhHH+pvh0rYBjYO6vvZr2om4LWeb2yqNovgMhfbqYXT2vesX9zdU7fXi5S2G ne4MW1Vc9a25MecMJVb0pvi7spG7pa1ER3hzRx7BPXXTXiqCDb8uRtDCHsee5rpoPNXi GqIA== 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:mime-version:content-transfer-encoding; bh=1CVdA9r3UVKQnabq2mx7w9JDC1aJtWHX+VPZ20Gprac=; b=PUYMcwthJgYRSPkHIZVGsDUQZWtnc65S/0YwVe5lX3o7JwSAlYRE7V9yHNnNEcdXdf gTmhN3bnte5HvtSs2Edi3lZ4TmI/x1hSNdmXm6ngE0icgiNL2jDF49354/znKH7eVpxL QPY2vaMrw90sslktaqtlXtjiThxDj3A1ztArFlw/ACkxd16w6ZcuMq4vgJpmcIQYBASW Ck2KLzt0zJ+86oLyyAS+DFdxek78o+m92p6lw5bBJEHRIO7RJJYGTaqjkwC9ykVeg/aV 0tFau2MfZsg85ht7/u+m3neQR8N1S5r+yyfhE1ngoaHGU5PneGWo8aJPyd0dZq3rvsZY IoAg== X-Gm-Message-State: APjAAAUIraUykaEcgWyqu4PNQxEJF0lDl0aRDcyZnPmY3kJf7Fgz96aI M5XPmLG9OzPqXN96z5iz7YE= X-Google-Smtp-Source: APXvYqxUtptb6cnnNgY1Bwgg6JzPFzKBJ6mgYUz1QfoIVpSeV9cebiCsDCynPLK5dYhXpHISIBUExA== X-Received: by 2002:a63:28c7:: with SMTP id o190mr24892871pgo.394.1575996130884; Tue, 10 Dec 2019 08:42:10 -0800 (PST) Received: from localhost.localdomain (c-67-165-113-11.hsd1.wa.comcast.net. [67.165.113.11]) by smtp.gmail.com with ESMTPSA id j38sm4034634pgj.27.2019.12.10.08.42.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 08:42:08 -0800 (PST) From: Andrey Smirnov To: Daniel Lezcano Cc: Andrey Smirnov , Lucas Stach , Chris Healy , Eduardo Valentin , Angus Ainslie , linux-imx@nxp.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v8 02/12] thermal: qoriq: Don't store struct thermal_zone_device reference Date: Tue, 10 Dec 2019 08:41:43 -0800 Message-Id: <20191210164153.10463-3-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191210164153.10463-1-andrew.smirnov@gmail.com> References: <20191210164153.10463-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Struct thermal_zone_device reference stored as sensor's private data isn't really used anywhere in the code. Drop it. Signed-off-by: Andrey Smirnov Acked-by: Daniel Lezcano Tested-by: Lucas Stach Cc: Chris Healy Cc: Lucas Stach Cc: Eduardo Valentin Cc: Daniel Lezcano Cc: Angus Ainslie (Purism) Cc: linux-imx@nxp.com Cc: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/thermal/qoriq_thermal.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/drivers/thermal/qoriq_thermal.c b/drivers/thermal/qoriq_thermal.c index dd47b31aeecc..2f2f5ffa8f26 100644 --- a/drivers/thermal/qoriq_thermal.c +++ b/drivers/thermal/qoriq_thermal.c @@ -110,7 +110,6 @@ struct qoriq_tmu_data; * Thermal zone data */ struct qoriq_sensor { - struct thermal_zone_device *tzd; struct qoriq_tmu_data *qdata; int id; }; @@ -162,6 +161,9 @@ static int qoriq_tmu_register_tmu_zone(struct platform_device *pdev) int id, sites = 0; for (id = 0; id < SITES_MAX; id++) { + struct thermal_zone_device *tzd; + int ret; + qdata->sensor[id] = devm_kzalloc(&pdev->dev, sizeof(struct qoriq_sensor), GFP_KERNEL); if (!qdata->sensor[id]) @@ -169,13 +171,16 @@ static int qoriq_tmu_register_tmu_zone(struct platform_device *pdev) qdata->sensor[id]->id = id; qdata->sensor[id]->qdata = qdata; - qdata->sensor[id]->tzd = devm_thermal_zone_of_sensor_register( - &pdev->dev, id, qdata->sensor[id], &tmu_tz_ops); - if (IS_ERR(qdata->sensor[id]->tzd)) { - if (PTR_ERR(qdata->sensor[id]->tzd) == -ENODEV) + + tzd = devm_thermal_zone_of_sensor_register(&pdev->dev, id, + qdata->sensor[id], + &tmu_tz_ops); + ret = PTR_ERR_OR_ZERO(tzd); + if (ret) { + if (ret == -ENODEV) continue; else - return PTR_ERR(qdata->sensor[id]->tzd); + return ret; } if (qdata->ver == TMU_VER1) From patchwork Tue Dec 10 16:41:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11282997 X-Patchwork-Delegate: daniel.lezcano@linaro.org Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E79B26C1 for ; Tue, 10 Dec 2019 16:42:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C5A43207FF for ; Tue, 10 Dec 2019 16:42:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="sNq8+BmR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727685AbfLJQmO (ORCPT ); Tue, 10 Dec 2019 11:42:14 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:32800 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727756AbfLJQmN (ORCPT ); Tue, 10 Dec 2019 11:42:13 -0500 Received: by mail-pg1-f195.google.com with SMTP id 6so9173608pgk.0; Tue, 10 Dec 2019 08:42:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KrHHV8WagrQw//LLkgB8ANSCBK2Q9bQ9Pa7bMN8q10Q=; b=sNq8+BmRFRIpUJlu7Y61TqM613g3/K9Xa44jR5RpgWtbW+U/9hu4ydJ1NmwezZK1E1 U+LVihdsXKe5IOaSX1+0wk2Do8WlQlspWMnh6jPkf6ThBlk0+i0eCBBVkYLH0gX+6Ess ZpoY2fopIkshVVjNnl9BGufqrK9SWARJLURBXxdsWgO8gQ3w2edeCjf7+EOffytsFIZC s6xa94kxIETdANklRB/MHmyUYL77K0re0+pDsnsYzRAKrQzbFNzyotODOi+OZ0HvRUJN 4RkA+gsSHnxev0R2feRBCbtPBaOwAYBAia4tDK5Txi+0W3EOYyhP3L1FNowZQIltwiT1 TWCA== 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:mime-version:content-transfer-encoding; bh=KrHHV8WagrQw//LLkgB8ANSCBK2Q9bQ9Pa7bMN8q10Q=; b=NuEs0C8ljkL6I/ulnVIvXkAgIggB+OsnSz+jhQGAe5SUpNx/VUIyG4xWgPyN04GKNi UfljwTODzXcNPgvQG/+LZIANrTW2+hcbWdSEzAwkM0s5XdN8ZHvi6WJ84+XJuVYn+pi5 ETbmweCq/OiNs2Q5L7nKAfDSdIcoaf/F5mjI5Tk1A0YpT66ctUkxcZ1HYJRVAnOklV5H P9b2Ulmiitf9YyVjvIr4DoqwOMWYGP8tVWw0pGSsnHCin2VinKUv9dhidbevDsV5jb+V EGjoz7QSqLjXeiXaaSS21IUVgmrUBI8XVWVYGpF6i6DmSHTCh8AB1W+ys1XOAP3a4/iQ 6UXQ== X-Gm-Message-State: APjAAAXZaTli3WckMbBvy6wN0Fa53HcElfvrJRtEkKd9HQ6JSwD0pJ8L epoP7ni+DW3KrhmJoPhX/VE= X-Google-Smtp-Source: APXvYqxyi9b/k2Vg/oO5+FvVdGeeUDa+i4WKHQaorgFlG57MNypLssR4bNffFqPzHTASi7VIfmlm9A== X-Received: by 2002:a63:fa04:: with SMTP id y4mr25730627pgh.413.1575996133176; Tue, 10 Dec 2019 08:42:13 -0800 (PST) Received: from localhost.localdomain (c-67-165-113-11.hsd1.wa.comcast.net. [67.165.113.11]) by smtp.gmail.com with ESMTPSA id j38sm4034634pgj.27.2019.12.10.08.42.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 08:42:11 -0800 (PST) From: Andrey Smirnov To: Daniel Lezcano Cc: Andrey Smirnov , Chris Healy , Lucas Stach , Zhang Rui , Eduardo Valentin , Angus Ainslie , linux-imx@nxp.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v8 03/12] thermal: qoriq: Add local struct qoriq_sensor pointer Date: Tue, 10 Dec 2019 08:41:44 -0800 Message-Id: <20191210164153.10463-4-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191210164153.10463-1-andrew.smirnov@gmail.com> References: <20191210164153.10463-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Add local struct qoriq_sensor pointer in qoriq_tmu_register_tmu_zone() for brevity. Signed-off-by: Andrey Smirnov Cc: Chris Healy Cc: Lucas Stach Cc: Zhang Rui Cc: Eduardo Valentin Cc: Daniel Lezcano Cc: Angus Ainslie (Purism) Cc: linux-imx@nxp.com Cc: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/thermal/qoriq_thermal.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/thermal/qoriq_thermal.c b/drivers/thermal/qoriq_thermal.c index 2f2f5ffa8f26..61733d820e1b 100644 --- a/drivers/thermal/qoriq_thermal.c +++ b/drivers/thermal/qoriq_thermal.c @@ -162,18 +162,22 @@ static int qoriq_tmu_register_tmu_zone(struct platform_device *pdev) for (id = 0; id < SITES_MAX; id++) { struct thermal_zone_device *tzd; + struct qoriq_sensor *sensor; int ret; - qdata->sensor[id] = devm_kzalloc(&pdev->dev, - sizeof(struct qoriq_sensor), GFP_KERNEL); + sensor = devm_kzalloc(&pdev->dev, + sizeof(struct qoriq_sensor), + GFP_KERNEL); if (!qdata->sensor[id]) return -ENOMEM; - qdata->sensor[id]->id = id; - qdata->sensor[id]->qdata = qdata; + qdata->sensor[id] = sensor; + + sensor->id = id; + sensor->qdata = qdata; tzd = devm_thermal_zone_of_sensor_register(&pdev->dev, id, - qdata->sensor[id], + sensor, &tmu_tz_ops); ret = PTR_ERR_OR_ZERO(tzd); if (ret) { From patchwork Tue Dec 10 16:41:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11282995 X-Patchwork-Delegate: daniel.lezcano@linaro.org Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A670E6C1 for ; Tue, 10 Dec 2019 16:42:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 849F52073D for ; Tue, 10 Dec 2019 16:42:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mOIiF9oP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727766AbfLJQmQ (ORCPT ); Tue, 10 Dec 2019 11:42:16 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:41780 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727764AbfLJQmP (ORCPT ); Tue, 10 Dec 2019 11:42:15 -0500 Received: by mail-pg1-f195.google.com with SMTP id x8so9159249pgk.8; Tue, 10 Dec 2019 08:42:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6kNjFdHXf8jZm7sjagZ2hATQl5PtTR6d1QOCcaqLh2I=; b=mOIiF9oPquNnCy4V6LIjRZvWTVS5vV33CcpIUt8APDh+1oFKSKWx3dE3e8OM6H0gYe FjKc0F319QN/um7fHtsnuO4wgEM7zsILukEF4PylaQh+P+eQK8MN0y5QTtVaU9avXrlA 5Q4rCrcXPs+825DlJNMvjz11hHhYUt7kTpbD9h8Rx5uJj7ii/mDClvOlC3KaT064oTAY Npp+ghUgG+pStWpPeYLs7LlI4Abf3acFZY+4ZaiRpWhrDwegweNEDAJkGnbc9yB3hv3f pSWV6qrMfscpVZhdZslfjP2aACSlo7/JFr1cUMqf9vo5sdniamNDPrf2+cN2pErkBgzO t8Pw== 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:mime-version:content-transfer-encoding; bh=6kNjFdHXf8jZm7sjagZ2hATQl5PtTR6d1QOCcaqLh2I=; b=ZAdtyQS6WCuVvJM157QO+0HhohivI556F3S15xWijp3uODlbncZUw7kIiQXDcg990o AZGlfw9x++eldtfNGpqdFbdEokG01ZZ5Ibw+BiPQbWIeNEdB7CFMsdHFHneQHjEBgPJJ KaMDX23rjYGJrppLEhSspmVPBdo9R8U663pHCvY16R/52xqnnNsFz9Uy/dtwbQB9j6Me NqE3RXRLYXKfuf7L07Hap8jlFQQg/i5mOPvjTRAM+duNBGemYd+iHn1McqjL0KXE59qU 2FO1YQItrvHtYkZZjyqWKUsMBBDEeIxM2dZRIXjwjv5DgZkKMd7LEsKfOrBBUFm0eOpf ynyA== X-Gm-Message-State: APjAAAWDo6AgFZAx3Y6/9uRIHzNLgWj7Lhu+zPKQZZGx00kVdJ9G8/kL zp1R3/PI2MYH/VP2a4BlKTM= X-Google-Smtp-Source: APXvYqw7kNA6VaT0g+YqyUQMqtJyNciwqVJCBpHydxtARq7ao18awyG9LMIIEfCeFLNN5E9ywC0sdA== X-Received: by 2002:a63:3089:: with SMTP id w131mr26268693pgw.453.1575996134840; Tue, 10 Dec 2019 08:42:14 -0800 (PST) Received: from localhost.localdomain (c-67-165-113-11.hsd1.wa.comcast.net. [67.165.113.11]) by smtp.gmail.com with ESMTPSA id j38sm4034634pgj.27.2019.12.10.08.42.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 08:42:13 -0800 (PST) From: Andrey Smirnov To: Daniel Lezcano Cc: Andrey Smirnov , Chris Healy , Lucas Stach , Zhang Rui , Eduardo Valentin , Angus Ainslie , linux-imx@nxp.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v8 04/12] thermal: qoriq: Embed per-sensor data into struct qoriq_tmu_data Date: Tue, 10 Dec 2019 08:41:45 -0800 Message-Id: <20191210164153.10463-5-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191210164153.10463-1-andrew.smirnov@gmail.com> References: <20191210164153.10463-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Embed per-sensor data into struct qoriq_tmu_data so we can drop the code allocating it. This also allows us to get rid of per-sensor back reference to struct qoriq_tmu_data since now its address can be calculated using container_of(). Signed-off-by: Andrey Smirnov Cc: Chris Healy Cc: Lucas Stach Cc: Zhang Rui Cc: Eduardo Valentin Cc: Daniel Lezcano Cc: Angus Ainslie (Purism) Cc: linux-imx@nxp.com Cc: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/thermal/qoriq_thermal.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/drivers/thermal/qoriq_thermal.c b/drivers/thermal/qoriq_thermal.c index 61733d820e1b..9886daf8ac97 100644 --- a/drivers/thermal/qoriq_thermal.c +++ b/drivers/thermal/qoriq_thermal.c @@ -104,13 +104,10 @@ struct qoriq_tmu_regs_v2 { u32 ttrcr[4]; /* Temperature Range Control Register */ }; -struct qoriq_tmu_data; - /* * Thermal zone data */ struct qoriq_sensor { - struct qoriq_tmu_data *qdata; int id; }; @@ -120,9 +117,14 @@ struct qoriq_tmu_data { struct qoriq_tmu_regs_v2 __iomem *regs_v2; struct clk *clk; bool little_endian; - struct qoriq_sensor *sensor[SITES_MAX]; + struct qoriq_sensor sensor[SITES_MAX]; }; +static struct qoriq_tmu_data *qoriq_sensor_to_data(struct qoriq_sensor *s) +{ + return container_of(s, struct qoriq_tmu_data, sensor[s->id]); +} + static void tmu_write(struct qoriq_tmu_data *p, u32 val, void __iomem *addr) { if (p->little_endian) @@ -142,7 +144,7 @@ static u32 tmu_read(struct qoriq_tmu_data *p, void __iomem *addr) static int tmu_get_temp(void *p, int *temp) { struct qoriq_sensor *qsensor = p; - struct qoriq_tmu_data *qdata = qsensor->qdata; + struct qoriq_tmu_data *qdata = qoriq_sensor_to_data(qsensor); u32 val; val = tmu_read(qdata, &qdata->regs->site[qsensor->id].tritsr); @@ -162,19 +164,10 @@ static int qoriq_tmu_register_tmu_zone(struct platform_device *pdev) for (id = 0; id < SITES_MAX; id++) { struct thermal_zone_device *tzd; - struct qoriq_sensor *sensor; + struct qoriq_sensor *sensor = &qdata->sensor[id]; int ret; - sensor = devm_kzalloc(&pdev->dev, - sizeof(struct qoriq_sensor), - GFP_KERNEL); - if (!qdata->sensor[id]) - return -ENOMEM; - - qdata->sensor[id] = sensor; - sensor->id = id; - sensor->qdata = qdata; tzd = devm_thermal_zone_of_sensor_register(&pdev->dev, id, sensor, From patchwork Tue Dec 10 16:41:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11282993 X-Patchwork-Delegate: daniel.lezcano@linaro.org Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0845B1593 for ; Tue, 10 Dec 2019 16:42:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DA3B7207FF for ; Tue, 10 Dec 2019 16:42:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Y5TxFprY" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727785AbfLJQmT (ORCPT ); Tue, 10 Dec 2019 11:42:19 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:46723 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727777AbfLJQmR (ORCPT ); Tue, 10 Dec 2019 11:42:17 -0500 Received: by mail-pl1-f196.google.com with SMTP id k20so78604pll.13; Tue, 10 Dec 2019 08:42:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tkuYRLy1ofAGSImjiPenlpmLUxwnT2nMpEQWVPZ5MwQ=; b=Y5TxFprYUtsGWcFEl4Lm6WMCQfOYOqTlZO0TqmCMJv52nHQuC65B7PwNGN/X7VUeDj 4rZnFmto41tnf1t9hzvdjA3+/sP3Tky8i7sBk0Z0kAltU6o8zYHD2HrD8V7v1G0aDZku H290a57FG7kQpf4nip85l2o8uS1Lt1Xri1p8aIhNOViKU9xIRTou7SgJdEbfovylJdwg n8bxvEUKbX3Ct8sGH7m8qwaBypmXAF7wEOtM0/Q+XGIRw68c1k9O1g494pjW5+7nrX6C +PuSQ1+8kDh7ZCPTwphYuBsJYL3FRoh/RYwQv1oPZd3jRKpfuNguRteSnzctA2/GHVi7 X+hQ== 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:mime-version:content-transfer-encoding; bh=tkuYRLy1ofAGSImjiPenlpmLUxwnT2nMpEQWVPZ5MwQ=; b=NbMZ1Vd3MEvU0h8qfc1zEIMPUqvoMbGheiQw5ozgttQo1kkxq/KfSNcK0Nlfre0XcK /qTJ2Eve1tjF5bFfKsehno16+QMipuT5y90f0F8/1Bjb1+1LE6tmOcf7F8nK4Z2xUHO3 bpCvOpPWiY5TMwA/iJ7DpKl9N8C7Gp/Wf/778tdbjzTnPcxzzbyLfemcBJMpjYwzBWXv WvWkkCnOL/yRPY0b7mmahoMvOUvwgr/PlCmsF4GhBkAwxwqMkkf+Qqr72qDM2PzBIrMT UgPuCmIN9gUBr29PEkgFMmXCddbtYiT4nq1MDJMrIZU70T2XB24Dal8w6d0mXk15IxGJ yIgQ== X-Gm-Message-State: APjAAAUStGITNx9EegCTIW+ffo4T+YCGGLqwOqrK/ZzHC5j2wu825cVX En4EAEQEq7ORMqjzosVUwM8= X-Google-Smtp-Source: APXvYqx3v7mWsEzAXUvxVt62oRQGZc8cbd6WMYs+ZDKa+d3C2QPfBf+QQDq+dFmxN3qGywPbrAgtPA== X-Received: by 2002:a17:90a:948a:: with SMTP id s10mr6318285pjo.140.1575996136714; Tue, 10 Dec 2019 08:42:16 -0800 (PST) Received: from localhost.localdomain (c-67-165-113-11.hsd1.wa.comcast.net. [67.165.113.11]) by smtp.gmail.com with ESMTPSA id j38sm4034634pgj.27.2019.12.10.08.42.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 08:42:15 -0800 (PST) From: Andrey Smirnov To: Daniel Lezcano Cc: Andrey Smirnov , Lucas Stach , Chris Healy , Eduardo Valentin , Angus Ainslie , linux-imx@nxp.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v8 05/12] thermal: qoriq: Pass data to qoriq_tmu_register_tmu_zone() directly Date: Tue, 10 Dec 2019 08:41:46 -0800 Message-Id: <20191210164153.10463-6-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191210164153.10463-1-andrew.smirnov@gmail.com> References: <20191210164153.10463-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Pass all necessary data to qoriq_tmu_register_tmu_zone() directly instead of passing a platform device and then deriving it. This is done as a first step to simplify resource deallocation code. Signed-off-by: Andrey Smirnov Acked-by: Daniel Lezcano Tested-by: Lucas Stach Cc: Chris Healy Cc: Lucas Stach Cc: Eduardo Valentin Cc: Daniel Lezcano Cc: Angus Ainslie (Purism) Cc: linux-imx@nxp.com Cc: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/thermal/qoriq_thermal.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/thermal/qoriq_thermal.c b/drivers/thermal/qoriq_thermal.c index 9886daf8ac97..f024ac68e2ed 100644 --- a/drivers/thermal/qoriq_thermal.c +++ b/drivers/thermal/qoriq_thermal.c @@ -157,9 +157,9 @@ static const struct thermal_zone_of_device_ops tmu_tz_ops = { .get_temp = tmu_get_temp, }; -static int qoriq_tmu_register_tmu_zone(struct platform_device *pdev) +static int qoriq_tmu_register_tmu_zone(struct device *dev, + struct qoriq_tmu_data *qdata) { - struct qoriq_tmu_data *qdata = platform_get_drvdata(pdev); int id, sites = 0; for (id = 0; id < SITES_MAX; id++) { @@ -169,7 +169,7 @@ static int qoriq_tmu_register_tmu_zone(struct platform_device *pdev) sensor->id = id; - tzd = devm_thermal_zone_of_sensor_register(&pdev->dev, id, + tzd = devm_thermal_zone_of_sensor_register(dev, id, sensor, &tmu_tz_ops); ret = PTR_ERR_OR_ZERO(tzd); @@ -303,7 +303,7 @@ static int qoriq_tmu_probe(struct platform_device *pdev) if (ret < 0) goto err; - ret = qoriq_tmu_register_tmu_zone(pdev); + ret = qoriq_tmu_register_tmu_zone(dev, data); if (ret < 0) { dev_err(dev, "Failed to register sensors\n"); ret = -ENODEV; From patchwork Tue Dec 10 16:41:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11282991 X-Patchwork-Delegate: daniel.lezcano@linaro.org Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D1917112B for ; Tue, 10 Dec 2019 16:42:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9B96D208C3 for ; Tue, 10 Dec 2019 16:42:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RR/KqD97" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727654AbfLJQms (ORCPT ); Tue, 10 Dec 2019 11:42:48 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:37236 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727764AbfLJQmT (ORCPT ); Tue, 10 Dec 2019 11:42:19 -0500 Received: by mail-pl1-f195.google.com with SMTP id c23so95716plz.4; Tue, 10 Dec 2019 08:42:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wsWFQ3Z6EFYQnpUSOkIidynsctL0yAXSVPN00DmSMSU=; b=RR/KqD97Nx8ISod240BNcDjZXFkKcI0DWk6K49ikM67NadPyaq/H7rGl6G2+dg3NR3 I3TIpjyFvX4cpzLkwPah6kiozSbk9KCqHuMx/Fk3e591bY3CYakTWJi7rhrjbKXZo+mV Bbw75Qxxamx9g58hQ/77KwRR5HzA9VfOUJAnO3fTGP3rZtxKjveJ18GIphcY9+v+yWkx RZ1L2Zo4AGUp1eNeFegOfY4nDPAVdBsbX0ycAu3xI6R+Hvj5Kn+xbs5OLkqhr5AxCgye l15W5iS8fEMJ3tRJIkMo2lOio0gK8NfjmU5/L2DYvo9Nb+EkofqJ0goGjt2Up4t+B/Ed jbsQ== 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:mime-version:content-transfer-encoding; bh=wsWFQ3Z6EFYQnpUSOkIidynsctL0yAXSVPN00DmSMSU=; b=UIf+Xafjt6+JCL5Xe+M8BgAwtAU8EVUgEY48SPJo8g04qR2HWDmmpX+gLcAxbSe5zh IipqHbAZANMhwsDQaYq+3yHXW6eKH1YRieSA4Do7MXgM6B/l4UnlzobR7Wvrix8kAIK0 Km7IvAq7juBkueBUbO7g4u26iZVyRIl+ChTim+EFAm5KyXWsj0SiZ1oA2sFiOrWqwxYe 7ZOxu5yRJ22cn5QpzDGKJ9wAxbA+zA157yLpCtdef4G1DUJTNzxaPcKPeA8lQj0gHu15 e3h7FF7t4UD/f77HVtCQ/J9Cc2kPlTdD9fze1VeuTNmXeWwZDFtSLodbWRE2dqnRlgHx 29uQ== X-Gm-Message-State: APjAAAXgN/9zN5Qa5GzAmNgGiLJ3dE9uM7l+5f957IiGUPAR6IOgKush soQ5Sj3Ib9FtoDjq1VecBkE= X-Google-Smtp-Source: APXvYqzRGi+EksK6arKc90+mQhmy0P0yiIltqzJBfTr2fQ97XZupoJeod/TKokNSS4J+V4eeJ8FegA== X-Received: by 2002:a17:90a:6346:: with SMTP id v6mr6310012pjs.51.1575996138248; Tue, 10 Dec 2019 08:42:18 -0800 (PST) Received: from localhost.localdomain (c-67-165-113-11.hsd1.wa.comcast.net. [67.165.113.11]) by smtp.gmail.com with ESMTPSA id j38sm4034634pgj.27.2019.12.10.08.42.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 08:42:17 -0800 (PST) From: Andrey Smirnov To: Daniel Lezcano Cc: Andrey Smirnov , Lucas Stach , Chris Healy , Eduardo Valentin , Angus Ainslie , linux-imx@nxp.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v8 06/12] thermal: qoriq: Pass data to qoriq_tmu_calibration() directly Date: Tue, 10 Dec 2019 08:41:47 -0800 Message-Id: <20191210164153.10463-7-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191210164153.10463-1-andrew.smirnov@gmail.com> References: <20191210164153.10463-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org We can simplify error cleanup code if instead of passing a "struct platform_device *" to qoriq_tmu_calibration() and deriving a bunch of pointers from it, we pass those pointers directly. This way we won't be force to call platform_set_drvdata() as early in qoriq_tmu_probe() and need to have "platform_set_drvdata(pdev, NULL);" in error path. Signed-off-by: Andrey Smirnov Reviewed-by: Daniel Lezcano Tested-by: Lucas Stach Cc: Chris Healy Cc: Lucas Stach Cc: Eduardo Valentin Cc: Daniel Lezcano Cc: Angus Ainslie (Purism) Cc: linux-imx@nxp.com Cc: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/thermal/qoriq_thermal.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/drivers/thermal/qoriq_thermal.c b/drivers/thermal/qoriq_thermal.c index f024ac68e2ed..de8c9cd115aa 100644 --- a/drivers/thermal/qoriq_thermal.c +++ b/drivers/thermal/qoriq_thermal.c @@ -201,23 +201,23 @@ static int qoriq_tmu_register_tmu_zone(struct device *dev, return 0; } -static int qoriq_tmu_calibration(struct platform_device *pdev) +static int qoriq_tmu_calibration(struct device *dev, + struct qoriq_tmu_data *data) { int i, val, len; u32 range[4]; const u32 *calibration; - struct device_node *np = pdev->dev.of_node; - struct qoriq_tmu_data *data = platform_get_drvdata(pdev); + struct device_node *np = dev->of_node; len = of_property_count_u32_elems(np, "fsl,tmu-range"); if (len < 0 || len > 4) { - dev_err(&pdev->dev, "invalid range data.\n"); + dev_err(dev, "invalid range data.\n"); return len; } val = of_property_read_u32_array(np, "fsl,tmu-range", range, len); if (val != 0) { - dev_err(&pdev->dev, "failed to read range data.\n"); + dev_err(dev, "failed to read range data.\n"); return val; } @@ -227,7 +227,7 @@ static int qoriq_tmu_calibration(struct platform_device *pdev) calibration = of_get_property(np, "fsl,tmu-calibration", &len); if (calibration == NULL || len % 8) { - dev_err(&pdev->dev, "invalid calibration data.\n"); + dev_err(dev, "invalid calibration data.\n"); return -ENODEV; } @@ -271,8 +271,6 @@ static int qoriq_tmu_probe(struct platform_device *pdev) if (!data) return -ENOMEM; - platform_set_drvdata(pdev, data); - data->little_endian = of_property_read_bool(np, "little-endian"); data->regs = devm_platform_ioremap_resource(pdev, 0); @@ -299,7 +297,7 @@ static int qoriq_tmu_probe(struct platform_device *pdev) qoriq_tmu_init_device(data); /* TMU initialization */ - ret = qoriq_tmu_calibration(pdev); /* TMU calibration */ + ret = qoriq_tmu_calibration(dev, data); /* TMU calibration */ if (ret < 0) goto err; @@ -310,11 +308,12 @@ static int qoriq_tmu_probe(struct platform_device *pdev) goto err; } + platform_set_drvdata(pdev, data); + return 0; err: clk_disable_unprepare(data->clk); - platform_set_drvdata(pdev, NULL); return ret; } From patchwork Tue Dec 10 16:41:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11282989 X-Patchwork-Delegate: daniel.lezcano@linaro.org Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2CC036C1 for ; Tue, 10 Dec 2019 16:42:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 03AD724680 for ; Tue, 10 Dec 2019 16:42:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Tr0SyHBM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727800AbfLJQmU (ORCPT ); Tue, 10 Dec 2019 11:42:20 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:40245 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727793AbfLJQmU (ORCPT ); Tue, 10 Dec 2019 11:42:20 -0500 Received: by mail-pl1-f193.google.com with SMTP id g6so89964plp.7; Tue, 10 Dec 2019 08:42:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KAZmhDLq44fHUuJGfTTESQPx/1QL+Ta6yKiRVIXpUF0=; b=Tr0SyHBMO2y3mbJLXSrmGeiJsEDUyMma4adOG4cGUtAzqIO7+9T5sEC3/ov3VSkQxQ OsaQxqAoD/WIEqsupov1DkcXzKWG6w8VkEdnfsbOmlI1rU4TgLkqCQzAHlybWsBEazsL S6OhwyJjS8c3Qq04r5HQY92yv+iUAO9nKrMAfXnlG0sUj6z5a2qSIJDVrfYGqn3rhcbV PAGYgUpgCfzmQ/5yUBDAqvXjnTzckmXZBSfX0hvzziA8HF+mNPfxddPy2jDeUpatGUlS UYfNwz8KBCGv7JE54c9d+Pt9m6KG1SShDYbJJOcUUJ+/5mRSP9giNkbOsPPXunBASOdu sZzQ== 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:mime-version:content-transfer-encoding; bh=KAZmhDLq44fHUuJGfTTESQPx/1QL+Ta6yKiRVIXpUF0=; b=AZpDK8fIEdsHUeO1DIW9zMlRuKz49mXtW0c1ZjIEheF6glWVd9Lpf7xKBctyGDdx8e X+NmM0bbko30uwlXpRKYXqbAbRM1slQS3KPPbS3hI/wZhW0EZ6JT0Hgg7fye/WxYkL8e t5jlyH5LqtABr+D1zekCTT3ZHhg7v+evrWtaZryZ7a1jZvmCyUiR4Wavx3gDFkeQpHWE M0TpJAHZvXO4NTRZzQxhnwjc+eYLFVSGqdQn0VrYyYA/qHUyBnBrZj6DLEMx1G5aoyCs hzHjPUuyPmYAdgNvr3pI7izdXsYWJrLSci9iETynOIA+KbVy4beAvSfAQUv4sbSHAHZO Le9g== X-Gm-Message-State: APjAAAWBupaLSpRfJyqQP70JEWRwzHGkW2P7xJYzsK6hw6xF+l3C3phY rJFb2xL4Lr4shcyYB2Ud4z6F/9ntLjM= X-Google-Smtp-Source: APXvYqxuSY0ZTZjSLzycVFH0h3HqUrDh3xGSHPfzvt4EscYbB9Cpb50MHFQhK01A7nBPxwIPWLqN0w== X-Received: by 2002:a17:90a:e291:: with SMTP id d17mr6623044pjz.116.1575996139886; Tue, 10 Dec 2019 08:42:19 -0800 (PST) Received: from localhost.localdomain (c-67-165-113-11.hsd1.wa.comcast.net. [67.165.113.11]) by smtp.gmail.com with ESMTPSA id j38sm4034634pgj.27.2019.12.10.08.42.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 08:42:18 -0800 (PST) From: Andrey Smirnov To: Daniel Lezcano Cc: Andrey Smirnov , Lucas Stach , Chris Healy , Eduardo Valentin , Angus Ainslie , linux-imx@nxp.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v8 07/12] thermal: qoriq: Drop unnecessary drvdata cleanup Date: Tue, 10 Dec 2019 08:41:48 -0800 Message-Id: <20191210164153.10463-8-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191210164153.10463-1-andrew.smirnov@gmail.com> References: <20191210164153.10463-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Driver data of underlying struct device will be set to NULL by Linux's driver infrastructure. Clearing it here is unnecessary. Signed-off-by: Andrey Smirnov Reviewed-by: Daniel Lezcano Tested-by: Lucas Stach Cc: Chris Healy Cc: Lucas Stach Cc: Eduardo Valentin Cc: Daniel Lezcano Cc: Angus Ainslie (Purism) Cc: linux-imx@nxp.com Cc: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/thermal/qoriq_thermal.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/thermal/qoriq_thermal.c b/drivers/thermal/qoriq_thermal.c index de8c9cd115aa..11749c673b3b 100644 --- a/drivers/thermal/qoriq_thermal.c +++ b/drivers/thermal/qoriq_thermal.c @@ -327,8 +327,6 @@ static int qoriq_tmu_remove(struct platform_device *pdev) clk_disable_unprepare(data->clk); - platform_set_drvdata(pdev, NULL); - return 0; } From patchwork Tue Dec 10 16:41:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11282987 X-Patchwork-Delegate: daniel.lezcano@linaro.org Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AEAF6112B for ; Tue, 10 Dec 2019 16:42:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 77FE62073D for ; Tue, 10 Dec 2019 16:42:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="clu6UwUA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727695AbfLJQmX (ORCPT ); Tue, 10 Dec 2019 11:42:23 -0500 Received: from mail-pj1-f65.google.com ([209.85.216.65]:38074 "EHLO mail-pj1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727793AbfLJQmW (ORCPT ); Tue, 10 Dec 2019 11:42:22 -0500 Received: by mail-pj1-f65.google.com with SMTP id l4so7622478pjt.5; Tue, 10 Dec 2019 08:42:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=q9bf2Um2I03H1aR/t3yvhuhmSHJaNa/0Zn+VgWwhcjA=; b=clu6UwUAvGq2ztqNbmDKHQ4at62Rhn22aKVuDU/CgAoQnI4dnAgLMsu3W6yXng7QK7 a2trSxKbXemF3G0k+WqQ832tcNIebUiJqNTwXoVJRlvopJnSGg8YYu6TwdALEWsf+oaR DRJ1Ax6pAdI+qA/aqKbtRkyMarmeY1rxTQ074Vhi4neZJgNp4q56wiZAPnNXAeakafFy 3Rbb8gZNAsRWNw0v9j9lmJs1nOInJHcG2iQU57Trqtp8EsCZT7vfb3VGOe4QBttWBPTo pU4MclX/SMFgxUIqGTWtBPcmjAjSYgHn27qoUIZHJlJ9nBd5Zg9XJ143ihszZalcNxAx +xMQ== 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:mime-version:content-transfer-encoding; bh=q9bf2Um2I03H1aR/t3yvhuhmSHJaNa/0Zn+VgWwhcjA=; b=ll8TYSrpzA6aQvU3j3/xW3Cw2Pe/dvUBaCLCX2GxRAv49Qj6XtXzI+cf5LqV633lBE jt2apwOtYtq4/hiTgdhdXfEM/xDladb3c5t5nKbmiXzHIdVF746xmQR+H7FJEnZKW+02 kmbyX/pBUENEg7Z06moACyl89Ozfi5SUy9ZXyh+huL8FrhIdnmlLPEPYycY+FNaxgjpB CgZVmDDSgA4VAKn5S/bUI4wf99wvtwTeUjw++DGxMbPOf3l91iNpADcp0Uyc0zqcY/Qz PNLKoXby7HHS8vbxPHY6L8NiJsABQ3CzEHWU/PcvGSQ3PS7dUM5OIRUlE+s0AR1ZeROi arzA== X-Gm-Message-State: APjAAAUurM8g8xAzpfRN8g8T9reskD0ldkD3sYufJJ4y522wJ3O7dSFN ryY/pckmbs9CycbxWjWE35Y= X-Google-Smtp-Source: APXvYqxcjD/0UpITqG0KPZRfHP5YG4Gkz9fH6MNjHVuVho4XW0Vt34CnDNxE6L/YLK1svws/3k1TAQ== X-Received: by 2002:a17:90a:8c1:: with SMTP id 1mr6679827pjn.12.1575996141541; Tue, 10 Dec 2019 08:42:21 -0800 (PST) Received: from localhost.localdomain (c-67-165-113-11.hsd1.wa.comcast.net. [67.165.113.11]) by smtp.gmail.com with ESMTPSA id j38sm4034634pgj.27.2019.12.10.08.42.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 08:42:20 -0800 (PST) From: Andrey Smirnov To: Daniel Lezcano Cc: Andrey Smirnov , Yuantian Tang , Anson Huang , Lucas Stach , Chris Healy , Eduardo Valentin , Angus Ainslie , linux-imx@nxp.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v8 08/12] thermal: qoriq: Convert driver to use regmap API Date: Tue, 10 Dec 2019 08:41:49 -0800 Message-Id: <20191210164153.10463-9-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191210164153.10463-1-andrew.smirnov@gmail.com> References: <20191210164153.10463-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Convert driver to use regmap API, drop custom LE/BE IO helpers and simplify bit manipulation using regmap_update_bits(). This also allows us to convert some register initialization to use loops and adds convenient debug access to TMU registers via debugfs. Signed-off-by: Andrey Smirnov Reviewed-by: Daniel Lezcano Tested-by: Lucas Stach Cc: Chris Healy Cc: Lucas Stach Cc: Eduardo Valentin Cc: Daniel Lezcano Cc: Angus Ainslie (Purism) Cc: linux-imx@nxp.com Cc: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- Yuantian, Anson: I don't have access to Layerscape HW that has v2 register layout, so if you could give this patch a try and verify that I got the 'qoriq_yes_ranges' right, I'd really appreciate it. Thanks, Andrey Smirnov drivers/thermal/qoriq_thermal.c | 228 ++++++++++++++------------------ 1 file changed, 98 insertions(+), 130 deletions(-) diff --git a/drivers/thermal/qoriq_thermal.c b/drivers/thermal/qoriq_thermal.c index 11749c673b3b..6227c940b9b0 100644 --- a/drivers/thermal/qoriq_thermal.c +++ b/drivers/thermal/qoriq_thermal.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include "thermal_core.h" @@ -24,85 +25,35 @@ #define TMU_VER1 0x1 #define TMU_VER2 0x2 -/* - * QorIQ TMU Registers - */ -struct qoriq_tmu_site_regs { - u32 tritsr; /* Immediate Temperature Site Register */ - u32 tratsr; /* Average Temperature Site Register */ - u8 res0[0x8]; -}; +#define REGS_TMR 0x000 /* Mode Register */ +#define TMR_DISABLE 0x0 +#define TMR_ME 0x80000000 +#define TMR_ALPF 0x0c000000 -struct qoriq_tmu_regs_v1 { - u32 tmr; /* Mode Register */ - u32 tsr; /* Status Register */ - u32 tmtmir; /* Temperature measurement interval Register */ - u8 res0[0x14]; - u32 tier; /* Interrupt Enable Register */ - u32 tidr; /* Interrupt Detect Register */ - u32 tiscr; /* Interrupt Site Capture Register */ - u32 ticscr; /* Interrupt Critical Site Capture Register */ - u8 res1[0x10]; - u32 tmhtcrh; /* High Temperature Capture Register */ - u32 tmhtcrl; /* Low Temperature Capture Register */ - u8 res2[0x8]; - u32 tmhtitr; /* High Temperature Immediate Threshold */ - u32 tmhtatr; /* High Temperature Average Threshold */ - u32 tmhtactr; /* High Temperature Average Crit Threshold */ - u8 res3[0x24]; - u32 ttcfgr; /* Temperature Configuration Register */ - u32 tscfgr; /* Sensor Configuration Register */ - u8 res4[0x78]; - struct qoriq_tmu_site_regs site[SITES_MAX]; - u8 res5[0x9f8]; - u32 ipbrr0; /* IP Block Revision Register 0 */ - u32 ipbrr1; /* IP Block Revision Register 1 */ - u8 res6[0x310]; - u32 ttrcr[4]; /* Temperature Range Control Register */ -}; +#define REGS_TMTMIR 0x008 /* Temperature measurement interval Register */ +#define TMTMIR_DEFAULT 0x0000000f -struct qoriq_tmu_regs_v2 { - u32 tmr; /* Mode Register */ - u32 tsr; /* Status Register */ - u32 tmsr; /* monitor site register */ - u32 tmtmir; /* Temperature measurement interval Register */ - u8 res0[0x10]; - u32 tier; /* Interrupt Enable Register */ - u32 tidr; /* Interrupt Detect Register */ - u8 res1[0x8]; - u32 tiiscr; /* interrupt immediate site capture register */ - u32 tiascr; /* interrupt average site capture register */ - u32 ticscr; /* Interrupt Critical Site Capture Register */ - u32 res2; - u32 tmhtcr; /* monitor high temperature capture register */ - u32 tmltcr; /* monitor low temperature capture register */ - u32 tmrtrcr; /* monitor rising temperature rate capture register */ - u32 tmftrcr; /* monitor falling temperature rate capture register */ - u32 tmhtitr; /* High Temperature Immediate Threshold */ - u32 tmhtatr; /* High Temperature Average Threshold */ - u32 tmhtactr; /* High Temperature Average Crit Threshold */ - u32 res3; - u32 tmltitr; /* monitor low temperature immediate threshold */ - u32 tmltatr; /* monitor low temperature average threshold register */ - u32 tmltactr; /* monitor low temperature average critical threshold */ - u32 res4; - u32 tmrtrctr; /* monitor rising temperature rate critical threshold */ - u32 tmftrctr; /* monitor falling temperature rate critical threshold*/ - u8 res5[0x8]; - u32 ttcfgr; /* Temperature Configuration Register */ - u32 tscfgr; /* Sensor Configuration Register */ - u8 res6[0x78]; - struct qoriq_tmu_site_regs site[SITES_MAX]; - u8 res7[0x9f8]; - u32 ipbrr0; /* IP Block Revision Register 0 */ - u32 ipbrr1; /* IP Block Revision Register 1 */ - u8 res8[0x300]; - u32 teumr0; - u32 teumr1; - u32 teumr2; - u32 res9; - u32 ttrcr[4]; /* Temperature Range Control Register */ -}; +#define REGS_V2_TMSR 0x008 /* monitor site register */ + +#define REGS_V2_TMTMIR 0x00c /* Temperature measurement interval Register */ + +#define REGS_TIER 0x020 /* Interrupt Enable Register */ +#define TIER_DISABLE 0x0 + + +#define REGS_TTCFGR 0x080 /* Temperature Configuration Register */ +#define REGS_TSCFGR 0x084 /* Sensor Configuration Register */ + +#define REGS_TRITSR(n) (0x100 + 16 * (n)) /* Immediate Temperature + * Site Register + */ +#define REGS_TTRnCR(n) (0xf10 + 4 * (n)) /* Temperature Range n + * Control Register + */ +#define REGS_IPBRR(n) (0xbf8 + 4 * (n)) /* IP Block Revision + * Register n + */ +#define REGS_V2_TEUMR(n) (0xf00 + 4 * (n)) /* * Thermal zone data @@ -113,10 +64,8 @@ struct qoriq_sensor { struct qoriq_tmu_data { int ver; - struct qoriq_tmu_regs_v1 __iomem *regs; - struct qoriq_tmu_regs_v2 __iomem *regs_v2; + struct regmap *regmap; struct clk *clk; - bool little_endian; struct qoriq_sensor sensor[SITES_MAX]; }; @@ -125,29 +74,13 @@ static struct qoriq_tmu_data *qoriq_sensor_to_data(struct qoriq_sensor *s) return container_of(s, struct qoriq_tmu_data, sensor[s->id]); } -static void tmu_write(struct qoriq_tmu_data *p, u32 val, void __iomem *addr) -{ - if (p->little_endian) - iowrite32(val, addr); - else - iowrite32be(val, addr); -} - -static u32 tmu_read(struct qoriq_tmu_data *p, void __iomem *addr) -{ - if (p->little_endian) - return ioread32(addr); - else - return ioread32be(addr); -} - static int tmu_get_temp(void *p, int *temp) { struct qoriq_sensor *qsensor = p; struct qoriq_tmu_data *qdata = qoriq_sensor_to_data(qsensor); u32 val; - val = tmu_read(qdata, &qdata->regs->site[qsensor->id].tritsr); + regmap_read(qdata->regmap, REGS_TRITSR(qsensor->id), &val); *temp = (val & 0xff) * 1000; return 0; @@ -189,12 +122,12 @@ static int qoriq_tmu_register_tmu_zone(struct device *dev, /* Enable monitoring */ if (sites != 0) { if (qdata->ver == TMU_VER1) { - tmu_write(qdata, sites | TMR_ME | TMR_ALPF, - &qdata->regs->tmr); + regmap_write(qdata->regmap, REGS_TMR, + sites | TMR_ME | TMR_ALPF); } else { - tmu_write(qdata, sites, &qdata->regs_v2->tmsr); - tmu_write(qdata, TMR_ME | TMR_ALPF_V2, - &qdata->regs_v2->tmr); + regmap_write(qdata->regmap, REGS_V2_TMSR, sites); + regmap_write(qdata->regmap, REGS_TMR, + TMR_ME | TMR_ALPF_V2); } } @@ -223,7 +156,7 @@ static int qoriq_tmu_calibration(struct device *dev, /* Init temperature range registers */ for (i = 0; i < len; i++) - tmu_write(data, range[i], &data->regs->ttrcr[i]); + regmap_write(data->regmap, REGS_TTRnCR(i), range[i]); calibration = of_get_property(np, "fsl,tmu-calibration", &len); if (calibration == NULL || len % 8) { @@ -233,9 +166,9 @@ static int qoriq_tmu_calibration(struct device *dev, for (i = 0; i < len; i += 8, calibration += 2) { val = of_read_number(calibration, 1); - tmu_write(data, val, &data->regs->ttcfgr); + regmap_write(data->regmap, REGS_TTCFGR, val); val = of_read_number(calibration + 1, 1); - tmu_write(data, val, &data->regs->tscfgr); + regmap_write(data->regmap, REGS_TSCFGR, val); } return 0; @@ -244,20 +177,40 @@ static int qoriq_tmu_calibration(struct device *dev, static void qoriq_tmu_init_device(struct qoriq_tmu_data *data) { /* Disable interrupt, using polling instead */ - tmu_write(data, TIER_DISABLE, &data->regs->tier); + regmap_write(data->regmap, REGS_TIER, TIER_DISABLE); /* Set update_interval */ + if (data->ver == TMU_VER1) { - tmu_write(data, TMTMIR_DEFAULT, &data->regs->tmtmir); + regmap_write(data->regmap, REGS_TMTMIR, TMTMIR_DEFAULT); } else { - tmu_write(data, TMTMIR_DEFAULT, &data->regs_v2->tmtmir); - tmu_write(data, TEUMR0_V2, &data->regs_v2->teumr0); + regmap_write(data->regmap, REGS_V2_TMTMIR, TMTMIR_DEFAULT); + regmap_write(data->regmap, REGS_V2_TEUMR(0), TEUMR0_V2); } /* Disable monitoring */ - tmu_write(data, TMR_DISABLE, &data->regs->tmr); + regmap_write(data->regmap, REGS_TMR, TMR_DISABLE); } +static const struct regmap_range qoriq_yes_ranges[] = { + regmap_reg_range(REGS_TMR, REGS_TSCFGR), + regmap_reg_range(REGS_TTRnCR(0), REGS_TTRnCR(3)), + regmap_reg_range(REGS_V2_TEUMR(0), REGS_V2_TEUMR(2)), + regmap_reg_range(REGS_IPBRR(0), REGS_IPBRR(1)), + /* Read only registers below */ + regmap_reg_range(REGS_TRITSR(0), REGS_TRITSR(15)), +}; + +static const struct regmap_access_table qoriq_wr_table = { + .yes_ranges = qoriq_yes_ranges, + .n_yes_ranges = ARRAY_SIZE(qoriq_yes_ranges) - 1, +}; + +static const struct regmap_access_table qoriq_rd_table = { + .yes_ranges = qoriq_yes_ranges, + .n_yes_ranges = ARRAY_SIZE(qoriq_yes_ranges), +}; + static int qoriq_tmu_probe(struct platform_device *pdev) { int ret; @@ -265,18 +218,37 @@ static int qoriq_tmu_probe(struct platform_device *pdev) struct qoriq_tmu_data *data; struct device_node *np = pdev->dev.of_node; struct device *dev = &pdev->dev; + const bool little_endian = of_property_read_bool(np, "little-endian"); + const enum regmap_endian format_endian = + little_endian ? REGMAP_ENDIAN_LITTLE : REGMAP_ENDIAN_BIG; + const struct regmap_config regmap_config = { + .reg_bits = 32, + .val_bits = 32, + .reg_stride = 4, + .rd_table = &qoriq_rd_table, + .wr_table = &qoriq_wr_table, + .val_format_endian = format_endian, + .max_register = SZ_4K, + }; + void __iomem *base; data = devm_kzalloc(dev, sizeof(struct qoriq_tmu_data), GFP_KERNEL); if (!data) return -ENOMEM; - data->little_endian = of_property_read_bool(np, "little-endian"); - - data->regs = devm_platform_ioremap_resource(pdev, 0); - if (IS_ERR(data->regs)) { + base = devm_platform_ioremap_resource(pdev, 0); + ret = PTR_ERR_OR_ZERO(base); + if (ret) { dev_err(dev, "Failed to get memory region\n"); - return PTR_ERR(data->regs); + return ret; + } + + data->regmap = devm_regmap_init_mmio(dev, base, ®map_config); + ret = PTR_ERR_OR_ZERO(data->regmap); + if (ret) { + dev_err(dev, "Failed to init regmap (%d)\n", ret); + return ret; } data->clk = devm_clk_get_optional(dev, NULL); @@ -290,10 +262,12 @@ static int qoriq_tmu_probe(struct platform_device *pdev) } /* version register offset at: 0xbf8 on both v1 and v2 */ - ver = tmu_read(data, &data->regs->ipbrr0); + ret = regmap_read(data->regmap, REGS_IPBRR(0), &ver); + if (ret) { + dev_err(&pdev->dev, "Failed to read IP block version\n"); + return ret; + } data->ver = (ver >> 8) & 0xff; - if (data->ver == TMU_VER2) - data->regs_v2 = (void __iomem *)data->regs; qoriq_tmu_init_device(data); /* TMU initialization */ @@ -323,7 +297,7 @@ static int qoriq_tmu_remove(struct platform_device *pdev) struct qoriq_tmu_data *data = platform_get_drvdata(pdev); /* Disable monitoring */ - tmu_write(data, TMR_DISABLE, &data->regs->tmr); + regmap_write(data->regmap, REGS_TMR, TMR_DISABLE); clk_disable_unprepare(data->clk); @@ -332,13 +306,12 @@ static int qoriq_tmu_remove(struct platform_device *pdev) static int __maybe_unused qoriq_tmu_suspend(struct device *dev) { - u32 tmr; struct qoriq_tmu_data *data = dev_get_drvdata(dev); + int ret; - /* Disable monitoring */ - tmr = tmu_read(data, &data->regs->tmr); - tmr &= ~TMR_ME; - tmu_write(data, tmr, &data->regs->tmr); + ret = regmap_update_bits(data->regmap, REGS_TMR, TMR_ME, 0); + if (ret) + return ret; clk_disable_unprepare(data->clk); @@ -347,7 +320,6 @@ static int __maybe_unused qoriq_tmu_suspend(struct device *dev) static int __maybe_unused qoriq_tmu_resume(struct device *dev) { - u32 tmr; int ret; struct qoriq_tmu_data *data = dev_get_drvdata(dev); @@ -356,11 +328,7 @@ static int __maybe_unused qoriq_tmu_resume(struct device *dev) return ret; /* Enable monitoring */ - tmr = tmu_read(data, &data->regs->tmr); - tmr |= TMR_ME; - tmu_write(data, tmr, &data->regs->tmr); - - return 0; + return regmap_update_bits(data->regmap, REGS_TMR, TMR_ME, TMR_ME); } static SIMPLE_DEV_PM_OPS(qoriq_tmu_pm_ops, From patchwork Tue Dec 10 16:41:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11282985 X-Patchwork-Delegate: daniel.lezcano@linaro.org Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C0B3E112B for ; Tue, 10 Dec 2019 16:42:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9EB4B21D7D for ; Tue, 10 Dec 2019 16:42:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EUhUSu8H" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727823AbfLJQmY (ORCPT ); Tue, 10 Dec 2019 11:42:24 -0500 Received: from mail-pj1-f68.google.com ([209.85.216.68]:40133 "EHLO mail-pj1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727818AbfLJQmX (ORCPT ); Tue, 10 Dec 2019 11:42:23 -0500 Received: by mail-pj1-f68.google.com with SMTP id s35so7613481pjb.7; Tue, 10 Dec 2019 08:42:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2b2cjI9ppTDYWjSViWcD+9AH23luExy4LBLn3g5jjpw=; b=EUhUSu8HjuWa8gIUg0BSvq3u75rGGhe2q57nbZPxShzH3xnWa0+0xUQ3mJYypp8zDA DEQCUllE9EVT7HV+6JapUHzsgDYaPfJQwwCtsiALrQXNW1G8JIuUNtJ42zZYwjgG/+c1 5jcBRwU/sl1Gj2IpSJMlK36LJWQ64GffdlNBhkq/84IIgiT6ukx9uS0K7blDDBRQVL+A 9wI0sfUG3nLju+gODjP+OyeL27MZTbtg9L/h8uVaxzULkIuDfzCzkWnTut34LnczrMgz QXrsghAGFe6pzAt2iAjd1J4lstALygq6/Iu/MNc8TJwABsM5pviZKGJKmu3lrbIR4Wxv LMLw== 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:mime-version:content-transfer-encoding; bh=2b2cjI9ppTDYWjSViWcD+9AH23luExy4LBLn3g5jjpw=; b=ceedYVxzDd42BgCh088g9enHQ3KLG8bgoWYOYsvwG7Ux9rmzIEr3gWKu3uKseHrbqX KCAWamn7CFseB4OCVQC+IyS0jl5GaEPVsOgXIFwOn2pjto2WXAUlGknhzycB7GmFZQwV 4M6BjRudb0gglxz9P7lTIjx+j1lufFUPEXWUI+1fidJcicqvORITx063OYdOmataitg2 1kl2BGI0ZSNFOHbu6yeQ51WC4B5em8AHfxKmdJJQ8IhHcppiggapbMfgKA4i7QKbTrwf tw3btt3FHrBDdx/FIOCiLTiwpNh5QdiznzkmHa/f31D1j/3OTT1/GGUqcSJuPucDrEWg AnaQ== X-Gm-Message-State: APjAAAVZvlf33bbKvumWIuy8dqiWA5J+w7FHnw+3EKsbR+zqIadX09CY c/QgUfo6gy49WaISkK8FIlI= X-Google-Smtp-Source: APXvYqwAeq3goTCXyPcasARNMmw1ZHElw7Cz+sIEzVBZ34FebrIsYXDzc3MK65C03mhXZeK9WHTC2w== X-Received: by 2002:a17:90a:1b6b:: with SMTP id q98mr6559278pjq.106.1575996143035; Tue, 10 Dec 2019 08:42:23 -0800 (PST) Received: from localhost.localdomain (c-67-165-113-11.hsd1.wa.comcast.net. [67.165.113.11]) by smtp.gmail.com with ESMTPSA id j38sm4034634pgj.27.2019.12.10.08.42.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 08:42:22 -0800 (PST) From: Andrey Smirnov To: Daniel Lezcano Cc: Andrey Smirnov , Lucas Stach , Chris Healy , Eduardo Valentin , Angus Ainslie , linux-imx@nxp.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v8 09/12] thermal: qoriq: Enable all sensors before registering them Date: Tue, 10 Dec 2019 08:41:50 -0800 Message-Id: <20191210164153.10463-10-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191210164153.10463-1-andrew.smirnov@gmail.com> References: <20191210164153.10463-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Tmu_get_temp will get called as a part of sensor registration via devm_thermal_zone_of_sensor_register(). To prevent it from retruning bogus data we need to enable sensor monitoring before that. Looking at the datasheet (i.MX8MQ RM) there doesn't seem to be any harm in enabling them all, so, for the sake of simplicity, change the code to do just that. Signed-off-by: Andrey Smirnov Tested-by: Lucas Stach Cc: Chris Healy Cc: Lucas Stach Cc: Eduardo Valentin Cc: Daniel Lezcano Cc: Angus Ainslie (Purism) Cc: linux-imx@nxp.com Cc: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/thermal/qoriq_thermal.c | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/drivers/thermal/qoriq_thermal.c b/drivers/thermal/qoriq_thermal.c index 6227c940b9b0..6c5e53ea7711 100644 --- a/drivers/thermal/qoriq_thermal.c +++ b/drivers/thermal/qoriq_thermal.c @@ -29,6 +29,7 @@ #define TMR_DISABLE 0x0 #define TMR_ME 0x80000000 #define TMR_ALPF 0x0c000000 +#define TMR_MSITE_ALL GENMASK(15, 0) #define REGS_TMTMIR 0x008 /* Temperature measurement interval Register */ #define TMTMIR_DEFAULT 0x0000000f @@ -93,7 +94,15 @@ static const struct thermal_zone_of_device_ops tmu_tz_ops = { static int qoriq_tmu_register_tmu_zone(struct device *dev, struct qoriq_tmu_data *qdata) { - int id, sites = 0; + int id; + + if (qdata->ver == TMU_VER1) { + regmap_write(qdata->regmap, REGS_TMR, + TMR_MSITE_ALL | TMR_ME | TMR_ALPF); + } else { + regmap_write(qdata->regmap, REGS_V2_TMSR, TMR_MSITE_ALL); + regmap_write(qdata->regmap, REGS_TMR, TMR_ME | TMR_ALPF_V2); + } for (id = 0; id < SITES_MAX; id++) { struct thermal_zone_device *tzd; @@ -109,25 +118,9 @@ static int qoriq_tmu_register_tmu_zone(struct device *dev, if (ret) { if (ret == -ENODEV) continue; - else - return ret; - } - if (qdata->ver == TMU_VER1) - sites |= 0x1 << (15 - id); - else - sites |= 0x1 << id; - } - - /* Enable monitoring */ - if (sites != 0) { - if (qdata->ver == TMU_VER1) { - regmap_write(qdata->regmap, REGS_TMR, - sites | TMR_ME | TMR_ALPF); - } else { - regmap_write(qdata->regmap, REGS_V2_TMSR, sites); - regmap_write(qdata->regmap, REGS_TMR, - TMR_ME | TMR_ALPF_V2); + regmap_write(qdata->regmap, REGS_TMR, TMR_DISABLE); + return ret; } } From patchwork Tue Dec 10 16:41:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11282983 X-Patchwork-Delegate: daniel.lezcano@linaro.org Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 189096C1 for ; Tue, 10 Dec 2019 16:42:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E644320828 for ; Tue, 10 Dec 2019 16:42:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Masq6otl" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727843AbfLJQm0 (ORCPT ); Tue, 10 Dec 2019 11:42:26 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:40252 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727831AbfLJQmZ (ORCPT ); Tue, 10 Dec 2019 11:42:25 -0500 Received: by mail-pl1-f195.google.com with SMTP id g6so90066plp.7; Tue, 10 Dec 2019 08:42:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jdPbCHrU2X5cb40jCnETs7i2ifIUn3Ola/UP2b4mOwM=; b=Masq6otl9D8o4RjM+csEhLQJelHQhLQftYTI7Vq2zmqnRdCp8gLt3kIYVKEWnyqFI8 lnFLUTaL6kiDNNp2bTBipgRDTIQ+BgbNrDT9sQJ89p/PvFgNxPmvl2z+FIj+rkVWaUtn Vv+WqZpFpa0nPcUHiVVvNxM2OHrMJzqIAT4PMLyy+0BVXqA7DgmVYhfaEkzgBpuWGU6u OBAU5FRp1vuraJ+xXeZeVu4O85V4cWC6b6hJiyUFMagOrwO9XkpXTvkqtyX7Z+x4YaAT fKhKGHZ7F9pgNyofbFKjJu1jpE7P0vUqy/yJWUgA7Wt81uBxp04hwKwO40PUx5hjlZMY +AFA== 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:mime-version:content-transfer-encoding; bh=jdPbCHrU2X5cb40jCnETs7i2ifIUn3Ola/UP2b4mOwM=; b=gTV4zw4RibJeNVB6JDiOAZBtSxskwuo28ePYjTqEBKTGCvJ00tgftUnDnTJgVbLyEm 065W3HyLdVd6unYBgs2Q5EbHXm0bC8bL4Bu96rpQ9+jR32WRPnAXPZ7W4AAlDm5W408R ap2/4SuDUKFmnMu1LPQbOYwRlntCRe44TaMQvt7+y6nETiS68cWYEtNeS49wcl4dHPHf zAAILV4sA2TqRz22ClEAsgykQHltTFQ+0YpERJMc3Ov0Kk7TrlFcSkxalz128UBFwYbJ NfQhZXmZMIru7AFdjH89aC73zkrxKkgSDFlZNfLmC9YWj1PafhWWmnRlFr/Lh091/K9W EfGw== X-Gm-Message-State: APjAAAV4IcLLcVGvq6RUQfCFas6+te68IhnbX7KaB0Jr+vTjXshOJO5i Nfef00+niPeuhnWN0C5F62s= X-Google-Smtp-Source: APXvYqzg1kGqZqDCA++XjokNIDG/tNGgx+rNswAZxzPTKl4YOXbWBUDHmIBvd2JsRIGtJ9Auwf5bgA== X-Received: by 2002:a17:90a:8989:: with SMTP id v9mr6398145pjn.119.1575996144681; Tue, 10 Dec 2019 08:42:24 -0800 (PST) Received: from localhost.localdomain (c-67-165-113-11.hsd1.wa.comcast.net. [67.165.113.11]) by smtp.gmail.com with ESMTPSA id j38sm4034634pgj.27.2019.12.10.08.42.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 08:42:23 -0800 (PST) From: Andrey Smirnov To: Daniel Lezcano Cc: Andrey Smirnov , Lucas Stach , Chris Healy , Eduardo Valentin , Angus Ainslie , linux-imx@nxp.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v8 10/12] thermal: qoriq: Do not report invalid temperature reading Date: Tue, 10 Dec 2019 08:41:51 -0800 Message-Id: <20191210164153.10463-11-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191210164153.10463-1-andrew.smirnov@gmail.com> References: <20191210164153.10463-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Before returning measured temperature data to upper layer we need to make sure that the reading was marked as "valid" to avoid reporting bogus data. Signed-off-by: Andrey Smirnov Reviewed-by: Daniel Lezcano Tested-by: Lucas Stach Cc: Chris Healy Cc: Lucas Stach Cc: Eduardo Valentin Cc: Daniel Lezcano Cc: Angus Ainslie (Purism) Cc: linux-imx@nxp.com Cc: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/thermal/qoriq_thermal.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/thermal/qoriq_thermal.c b/drivers/thermal/qoriq_thermal.c index 6c5e53ea7711..b684d3ceda69 100644 --- a/drivers/thermal/qoriq_thermal.c +++ b/drivers/thermal/qoriq_thermal.c @@ -48,6 +48,7 @@ #define REGS_TRITSR(n) (0x100 + 16 * (n)) /* Immediate Temperature * Site Register */ +#define TRITSR_V BIT(31) #define REGS_TTRnCR(n) (0xf10 + 4 * (n)) /* Temperature Range n * Control Register */ @@ -80,8 +81,24 @@ static int tmu_get_temp(void *p, int *temp) struct qoriq_sensor *qsensor = p; struct qoriq_tmu_data *qdata = qoriq_sensor_to_data(qsensor); u32 val; + /* + * REGS_TRITSR(id) has the following layout: + * + * 31 ... 7 6 5 4 3 2 1 0 + * V TEMP + * + * Where V bit signifies if the measurement is ready and is + * within sensor range. TEMP is an 8 bit value representing + * temperature in C. + */ + if (regmap_read_poll_timeout(qdata->regmap, + REGS_TRITSR(qsensor->id), + val, + val & TRITSR_V, + USEC_PER_MSEC, + 10 * USEC_PER_MSEC)) + return -ENODATA; - regmap_read(qdata->regmap, REGS_TRITSR(qsensor->id), &val); *temp = (val & 0xff) * 1000; return 0; From patchwork Tue Dec 10 16:41:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11282981 X-Patchwork-Delegate: daniel.lezcano@linaro.org Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1C8F0112B for ; Tue, 10 Dec 2019 16:42:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EF07820828 for ; Tue, 10 Dec 2019 16:42:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VZSJzE9v" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727873AbfLJQmd (ORCPT ); Tue, 10 Dec 2019 11:42:33 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:36338 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727846AbfLJQm0 (ORCPT ); Tue, 10 Dec 2019 11:42:26 -0500 Received: by mail-pl1-f196.google.com with SMTP id d15so98332pll.3; Tue, 10 Dec 2019 08:42:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=e0lwGN+LUXDKi5KuFbcc2RGuv/5GribWzP248c589m4=; b=VZSJzE9vD8fY8ler14aQN+zwXNhOpwWdw7wwDyGHH0PP48U06fRdhDtZNJBoz4rLy0 IvzGsmB7KAv+EM7NiV35TniZ9SYrvOqeHa+aKAlhoRlHo/G+LpVpdaBL4wjUCG9Lb4vl Yl1M/wh+HU1bmsKKc/dfTkFioiTBQiG0uVVGF6v4WWa/92ymS4RdX/YLqAKm1UDdSx4K 9ShPmgYrYT9mWayqRlt/WF4Ao5PcMzfH7N8qWCmuokoBmqggQlyDdvbK5vbeHRpM2JD+ YHl9gFTJK/YoMEbZijuuGE7qOeNehsm5NE62gRE75Dl4gxE+ZM7j0yoMUoeaGGJzq/yb w1Vw== 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:mime-version:content-transfer-encoding; bh=e0lwGN+LUXDKi5KuFbcc2RGuv/5GribWzP248c589m4=; b=H4VXUAuBR46ppmVHaBm0hI/U3MS2gUSmiI441ZyqGR+l5+NMteyPOMKgmWWGqiXojB /vGAukRF7v69oqJO38TX4z+dCudK0TdMz14+YN2lqDOL4q+3oYlTeHKDtj6I5aTWRM2q nMEV4JKdHha/vx0BiM3F/GPucXs4kkBTgKB81PvAhPZpJzNcPEoEoJFmFZBEAGn5Vt+p a7tLNk6Yr3Uuwqu6qsUw8k9W2vgH4lE4I890BgMZt5dI2/xdP3AmK+uysKaJAh6rbgsI lIb6DDo/elN+ZWS9NsG8yx3oe9yC5WSnskK+Gzyo3b22Hd0vA5+HFwPm91UkIGwrwPdc Ra4g== X-Gm-Message-State: APjAAAX7pFj48LslBSaVTg8ougTEYuqntIMXiZW3wkwmkklmcHpWyLIr YP1tp7xtPEeYQ1qWt0PhRAo= X-Google-Smtp-Source: APXvYqy3rkbCa2BQ/IHR1Htn/kCvysMrYaozap7ez+/KB9iNEljuIhjVFnpS3CEmhoy8EjDsdQrJhg== X-Received: by 2002:a17:90a:d78f:: with SMTP id z15mr6481689pju.36.1575996146180; Tue, 10 Dec 2019 08:42:26 -0800 (PST) Received: from localhost.localdomain (c-67-165-113-11.hsd1.wa.comcast.net. [67.165.113.11]) by smtp.gmail.com with ESMTPSA id j38sm4034634pgj.27.2019.12.10.08.42.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 08:42:25 -0800 (PST) From: Andrey Smirnov To: Daniel Lezcano Cc: Andrey Smirnov , Lucas Stach , Chris Healy , Eduardo Valentin , Angus Ainslie , linux-imx@nxp.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v8 11/12] thermal_hwmon: Add devres wrapper for thermal_add_hwmon_sysfs() Date: Tue, 10 Dec 2019 08:41:52 -0800 Message-Id: <20191210164153.10463-12-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191210164153.10463-1-andrew.smirnov@gmail.com> References: <20191210164153.10463-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Add devres wrapper for thermal_add_hwmon_sysfs() to simplify driver code. Signed-off-by: Andrey Smirnov Reviewed-by: Daniel Lezcano Tested-by: Lucas Stach Cc: Chris Healy Cc: Lucas Stach Cc: Eduardo Valentin Cc: Daniel Lezcano Cc: Angus Ainslie (Purism) Cc: linux-imx@nxp.com Cc: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/thermal/thermal_hwmon.c | 28 ++++++++++++++++++++++++++++ drivers/thermal/thermal_hwmon.h | 7 +++++++ 2 files changed, 35 insertions(+) diff --git a/drivers/thermal/thermal_hwmon.c b/drivers/thermal/thermal_hwmon.c index dd5d8ee37928..c8d2620f2e42 100644 --- a/drivers/thermal/thermal_hwmon.c +++ b/drivers/thermal/thermal_hwmon.c @@ -248,3 +248,31 @@ void thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz) kfree(hwmon); } EXPORT_SYMBOL_GPL(thermal_remove_hwmon_sysfs); + +static void devm_thermal_hwmon_release(struct device *dev, void *res) +{ + thermal_remove_hwmon_sysfs(*(struct thermal_zone_device **)res); +} + +int devm_thermal_add_hwmon_sysfs(struct thermal_zone_device *tz) +{ + struct thermal_zone_device **ptr; + int ret; + + ptr = devres_alloc(devm_thermal_hwmon_release, sizeof(*ptr), + GFP_KERNEL); + if (!ptr) + return -ENOMEM; + + ret = thermal_add_hwmon_sysfs(tz); + if (ret) { + devres_free(ptr); + return ret; + } + + *ptr = tz; + devres_add(&tz->device, ptr); + + return ret; +} +EXPORT_SYMBOL_GPL(devm_thermal_add_hwmon_sysfs); diff --git a/drivers/thermal/thermal_hwmon.h b/drivers/thermal/thermal_hwmon.h index a160b9d62dd0..1a9d65f6a6a8 100644 --- a/drivers/thermal/thermal_hwmon.h +++ b/drivers/thermal/thermal_hwmon.h @@ -17,6 +17,7 @@ #ifdef CONFIG_THERMAL_HWMON int thermal_add_hwmon_sysfs(struct thermal_zone_device *tz); +int devm_thermal_add_hwmon_sysfs(struct thermal_zone_device *tz); void thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz); #else static inline int @@ -25,6 +26,12 @@ thermal_add_hwmon_sysfs(struct thermal_zone_device *tz) return 0; } +static inline int +devm_thermal_add_hwmon_sysfs(struct thermal_zone_device *tz) +{ + return 0; +} + static inline void thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz) { From patchwork Tue Dec 10 16:41:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 11282979 X-Patchwork-Delegate: daniel.lezcano@linaro.org Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6BD466C1 for ; Tue, 10 Dec 2019 16:42:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 49B102073D for ; Tue, 10 Dec 2019 16:42:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ga+8gM7y" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727861AbfLJQm3 (ORCPT ); Tue, 10 Dec 2019 11:42:29 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:35274 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727831AbfLJQm2 (ORCPT ); Tue, 10 Dec 2019 11:42:28 -0500 Received: by mail-pf1-f194.google.com with SMTP id b19so126731pfo.2; Tue, 10 Dec 2019 08:42:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=U90+xxPa/n6CEWdGb92kTN2mRHFkhOKFhP+vKnVn8pU=; b=ga+8gM7y0/a7dq8h7Be7uego7Viw+xRA4OAMvc8ASgW2a/Ugh5/sGxd2g+uaSYRNmq fqYAUgo5R3hQWYC8S6daWKT4SJZrDKv9CRhN8o7rne8oSWovy6DIxNaheBvFJWerApSU 6Mzg8h+BoufdPRY4Dl0aRCqlaTI7YA99ndFzTNU9DPmT5eK4OWGz/7oj4FPLdO70a1i7 W6awMxhNGDcTjeUq+xY6cniGqZqsFIbidlJq7NntjMV0RU9/E0q52KndT2C8mCz3Lh3Q k5VX8/aVTT1Fi1ZdneHBVhaNX8z3Djz+jNH1J6SHVWRjex4QXBRnxVnotR6kp6ASw8T/ D+IA== 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:mime-version:content-transfer-encoding; bh=U90+xxPa/n6CEWdGb92kTN2mRHFkhOKFhP+vKnVn8pU=; b=gXlqgDy80gld2MVfrRyUBfOTZ9rQcrUpjQLhJyXJ54lFVcp48dCazn82FhkNxZ197x eIg+Rvd0sjYGNDMOD9KeRzhEJKd/DhKe/VWJS2Kjs2Z5MtNOp+2H9L+OYVSB727L3tn7 prAyB+T5abb/vNvKnSodJE+7Bu24HPc66pDGF3lUo8pW0DjucTUhuXLoZdH7lxbg7aF/ m80OvavBRiJe8p/NNy00i3ZM6K/9HtMKdIFCsiQSDI5+/ABs9QMktsF+LlUyUaWYv/TP 1e6p611YvqA8suhqQOzHt9Wlb1Ayuc4l0N1/ek01Rm/3SogeP9qHzHdPNCleMfcMe/Uk W9HA== X-Gm-Message-State: APjAAAWU6M8wajj0M2K6FXV7r2KSYugWQGirexc4V1mjn86V7CyxpztM 6nOno3M4MA+0F9muw15V3LA= X-Google-Smtp-Source: APXvYqxNayeTWaLSe9RInRfTVj1oOjtaqUWtxFeFSKVUSRKIs280RrcgkQ0po0Tu4au3EG3heSR9FA== X-Received: by 2002:a63:4f64:: with SMTP id p36mr26649705pgl.271.1575996148068; Tue, 10 Dec 2019 08:42:28 -0800 (PST) Received: from localhost.localdomain (c-67-165-113-11.hsd1.wa.comcast.net. [67.165.113.11]) by smtp.gmail.com with ESMTPSA id j38sm4034634pgj.27.2019.12.10.08.42.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 08:42:26 -0800 (PST) From: Andrey Smirnov To: Daniel Lezcano Cc: Andrey Smirnov , Lucas Stach , Chris Healy , Eduardo Valentin , Angus Ainslie , linux-imx@nxp.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v8 12/12] thermal: qoriq: Add hwmon support Date: Tue, 10 Dec 2019 08:41:53 -0800 Message-Id: <20191210164153.10463-13-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191210164153.10463-1-andrew.smirnov@gmail.com> References: <20191210164153.10463-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Expose thermal readings as a HWMON device, so that it could be accessed using lm-sensors. Signed-off-by: Andrey Smirnov Reviewed-by: Daniel Lezcano Tested-by: Lucas Stach Cc: Chris Healy Cc: Lucas Stach Cc: Eduardo Valentin Cc: Daniel Lezcano Cc: Angus Ainslie (Purism) Cc: linux-imx@nxp.com Cc: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/thermal/qoriq_thermal.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/thermal/qoriq_thermal.c b/drivers/thermal/qoriq_thermal.c index b684d3ceda69..b75d34e07da5 100644 --- a/drivers/thermal/qoriq_thermal.c +++ b/drivers/thermal/qoriq_thermal.c @@ -13,6 +13,7 @@ #include #include "thermal_core.h" +#include "thermal_hwmon.h" #define SITES_MAX 16 #define TMR_DISABLE 0x0 @@ -139,6 +140,11 @@ static int qoriq_tmu_register_tmu_zone(struct device *dev, regmap_write(qdata->regmap, REGS_TMR, TMR_DISABLE); return ret; } + + if (devm_thermal_add_hwmon_sysfs(tzd)) + dev_warn(dev, + "Failed to add hwmon sysfs attributes\n"); + } return 0;