* [PATCH v4 00/12] QorIQ TMU multi-sensor and HWMON support
@ 2019-04-13 8:27 Andrey Smirnov
2019-04-13 8:27 ` [PATCH v4 01/12] thermal: qoriq: Remove unnecessary DT node is NULL check Andrey Smirnov
` (12 more replies)
0 siblings, 13 replies; 23+ messages in thread
From: Andrey Smirnov @ 2019-04-13 8:27 UTC (permalink / raw)
To: linux-pm
Cc: Andrey Smirnov, Chris Healy, Lucas Stach, Eduardo Valentin,
Daniel Lezcano, Angus Ainslie, linux-imx, linux-kernel
Everyone:
This series contains patches adding support for HWMON integration, bug
fixes and general improvements (hopefully) for TMU driver I made while
working on it on i.MX8MQ.
Feedback is welcome!
Thanks,
Andrey Smirnov
Changes since [v3]
- Series reabse on top of [rfc]
- Fixed incorrect goto label in "thermal: qoriq: Pass data to
qoriq_tmu_calibration()"
- Added REGS_TRITSR() register description to "thermal: qoriq: Do
not report invalid temperature reading"
- Reworded commit message of "thermal: qoriq: Remove unnecessary
DT node is NULL check"
Changes since [v2]
- Patches rebased on v5.1-rc1
Changes since [v1]
- Rebased on "linus" branch of
git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux-soc-thermal.git
that included latest chagnes adding multi-sensors support
- Dropped
thermal: qoriq: Add support for multiple thremal sites
thermal: qoriq: Be more strict when parsing
thermal: qoriq: Simplify error handling in qoriq_tmu_get_sensor_id()
since they are no longer relevant
- Added
thermal: qoriq: Don't store struct thermal_zone_device reference
thermal: qoriq: Add local struct qoriq_sensor pointer
thermal: qoriq: Embed per-sensor data into struct qoriq_tmu_data
thermal: qoriq: Pass data to qoriq_tmu_register_tmu_zone() directly
to simplify latest codebase
- Changed "thermal: qoriq: Do not report invalid temperature
reading" to use regmap_read_poll_timeout() to make sure that
tmu_get_temp() waits for fist sample to be ready before
reporting it. This case is triggered on my setup if
qoriq_thermal is compiled as a module
[v1] lore.kernel.org/lkml/20190218191141.3729-1-andrew.smirnov@gmail.com
[v2] lore.kernel.org/lkml/20190222200508.26325-1-andrew.smirnov@gmail.com
[v3] lore.kernel.org/lkml/20190401041418.5999-1-andrew.smirnov@gmail.com
[rfc] lore.kernel.org/lkml/20190404080647.8173-1-daniel.lezcano@linaro.org
Andrey Smirnov (12):
thermal: qoriq: Remove unnecessary DT node is NULL check
thermal: qoriq: Add local struct device pointer
thermal: qoriq: Don't store struct thermal_zone_device reference
thermal: qoriq: Drop per-sensor data
thermal: qoriq: Pass data to qoriq_tmu_register_tmu_zone() directly
thermal: qoriq: Pass data to qoriq_tmu_calibration() directly
thermal: qoriq: Convert driver to use devm_ioremap()
thermal: qoriq: Convert driver to use regmap API
thermal: qoriq: Enable all sensors before registering them
thermal: qoriq: Do not report invalid temperature reading
thermal_hwmon: Add devres wrapper for thermal_add_hwmon_sysfs()
thermal: qoriq: Add hwmon support
drivers/thermal/qoriq_thermal.c | 287 +++++++++++++++-----------------
drivers/thermal/thermal_hwmon.c | 28 ++++
drivers/thermal/thermal_hwmon.h | 7 +
3 files changed, 171 insertions(+), 151 deletions(-)
--
2.20.1
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH v4 01/12] thermal: qoriq: Remove unnecessary DT node is NULL check
2019-04-13 8:27 [PATCH v4 00/12] QorIQ TMU multi-sensor and HWMON support Andrey Smirnov
@ 2019-04-13 8:27 ` Andrey Smirnov
2019-04-13 8:27 ` [PATCH v4 02/12] thermal: qoriq: Add local struct device pointer Andrey Smirnov
` (11 subsequent siblings)
12 siblings, 0 replies; 23+ messages in thread
From: Andrey Smirnov @ 2019-04-13 8:27 UTC (permalink / raw)
To: linux-pm
Cc: Andrey Smirnov, Daniel Lezcano, Chris Healy, Lucas Stach,
Eduardo Valentin, Angus Ainslie, linux-imx, linux-kernel
It's impossible to use this driver outside of Device Tree, so if the
probe function is called, the dev.of_node is guaranteed to not be NULL
and guarding against that is pointless. Drop it.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: Chris Healy <cphealy@gmail.com>
Cc: Lucas Stach <l.stach@pengutronix.de>
Cc: Eduardo Valentin <edubezval@gmail.com>
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: Angus Ainslie (Purism) <angus@akkea.ca>
Cc: linux-imx@nxp.com
Cc: linux-pm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
drivers/thermal/qoriq_thermal.c | 5 -----
1 file changed, 5 deletions(-)
diff --git a/drivers/thermal/qoriq_thermal.c b/drivers/thermal/qoriq_thermal.c
index 405d1fbdd0cb..5828314ec74d 100644
--- a/drivers/thermal/qoriq_thermal.c
+++ b/drivers/thermal/qoriq_thermal.c
@@ -193,11 +193,6 @@ static int qoriq_tmu_probe(struct platform_device *pdev)
struct qoriq_tmu_data *data;
struct device_node *np = pdev->dev.of_node;
- if (!np) {
- dev_err(&pdev->dev, "Device OF-Node is NULL");
- return -ENODEV;
- }
-
data = devm_kzalloc(&pdev->dev, sizeof(struct qoriq_tmu_data),
GFP_KERNEL);
if (!data)
--
2.20.1
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH v4 02/12] thermal: qoriq: Add local struct device pointer
2019-04-13 8:27 [PATCH v4 00/12] QorIQ TMU multi-sensor and HWMON support Andrey Smirnov
2019-04-13 8:27 ` [PATCH v4 01/12] thermal: qoriq: Remove unnecessary DT node is NULL check Andrey Smirnov
@ 2019-04-13 8:27 ` Andrey Smirnov
2019-04-13 8:27 ` [PATCH v4 03/12] thermal: qoriq: Don't store struct thermal_zone_device reference Andrey Smirnov
` (10 subsequent siblings)
12 siblings, 0 replies; 23+ messages in thread
From: Andrey Smirnov @ 2019-04-13 8:27 UTC (permalink / raw)
To: linux-pm
Cc: Andrey Smirnov, Daniel Lezcano, Chris Healy, Lucas Stach,
Eduardo Valentin, Angus Ainslie, linux-imx, linux-kernel
Use a local "struct device *dev" for brevity. No functional change
intended.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: Chris Healy <cphealy@gmail.com>
Cc: Lucas Stach <l.stach@pengutronix.de>
Cc: Eduardo Valentin <edubezval@gmail.com>
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: Angus Ainslie (Purism) <angus@akkea.ca>
Cc: linux-imx@nxp.com
Cc: linux-pm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
drivers/thermal/qoriq_thermal.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/thermal/qoriq_thermal.c b/drivers/thermal/qoriq_thermal.c
index 5828314ec74d..c3ed6ed81dfb 100644
--- a/drivers/thermal/qoriq_thermal.c
+++ b/drivers/thermal/qoriq_thermal.c
@@ -192,8 +192,9 @@ static int qoriq_tmu_probe(struct platform_device *pdev)
int ret;
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;
@@ -204,7 +205,7 @@ static int qoriq_tmu_probe(struct platform_device *pdev)
data->regs = of_iomap(np, 0);
if (!data->regs) {
- dev_err(&pdev->dev, "Failed to get memory region\n");
+ dev_err(dev, "Failed to get memory region\n");
ret = -ENODEV;
goto err_iomap;
}
@@ -217,7 +218,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_iomap;
}
--
2.20.1
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH v4 03/12] thermal: qoriq: Don't store struct thermal_zone_device reference
2019-04-13 8:27 [PATCH v4 00/12] QorIQ TMU multi-sensor and HWMON support Andrey Smirnov
2019-04-13 8:27 ` [PATCH v4 01/12] thermal: qoriq: Remove unnecessary DT node is NULL check Andrey Smirnov
2019-04-13 8:27 ` [PATCH v4 02/12] thermal: qoriq: Add local struct device pointer Andrey Smirnov
@ 2019-04-13 8:27 ` Andrey Smirnov
2019-04-13 8:27 ` [PATCH v4 04/12] thermal: qoriq: Drop per-sensor data Andrey Smirnov
` (9 subsequent siblings)
12 siblings, 0 replies; 23+ messages in thread
From: Andrey Smirnov @ 2019-04-13 8:27 UTC (permalink / raw)
To: linux-pm
Cc: Andrey Smirnov, Daniel Lezcano, Chris Healy, Lucas Stach,
Eduardo Valentin, Angus Ainslie, linux-imx, linux-kernel
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 <andrew.smirnov@gmail.com>
Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: Chris Healy <cphealy@gmail.com>
Cc: Lucas Stach <l.stach@pengutronix.de>
Cc: Eduardo Valentin <edubezval@gmail.com>
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: Angus Ainslie (Purism) <angus@akkea.ca>
Cc: linux-imx@nxp.com
Cc: linux-pm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
drivers/thermal/qoriq_thermal.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/drivers/thermal/qoriq_thermal.c b/drivers/thermal/qoriq_thermal.c
index c3ed6ed81dfb..c041d1ae3500 100644
--- a/drivers/thermal/qoriq_thermal.c
+++ b/drivers/thermal/qoriq_thermal.c
@@ -65,7 +65,6 @@ struct qoriq_tmu_data;
* Thermal zone data
*/
struct qoriq_sensor {
- struct thermal_zone_device *tzd;
struct qoriq_tmu_data *qdata;
int id;
};
@@ -114,6 +113,8 @@ 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;
+
qdata->sensor[id] = devm_kzalloc(&pdev->dev,
sizeof(struct qoriq_sensor), GFP_KERNEL);
if (!qdata->sensor[id])
@@ -121,13 +122,15 @@ 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);
+ if (IS_ERR(tzd)) {
+ if (PTR_ERR(tzd) == -ENODEV)
continue;
else
- return PTR_ERR(qdata->sensor[id]->tzd);
+ return PTR_ERR(tzd);
}
sites |= 0x1 << (15 - id);
--
2.20.1
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH v4 04/12] thermal: qoriq: Drop per-sensor data
2019-04-13 8:27 [PATCH v4 00/12] QorIQ TMU multi-sensor and HWMON support Andrey Smirnov
` (2 preceding siblings ...)
2019-04-13 8:27 ` [PATCH v4 03/12] thermal: qoriq: Don't store struct thermal_zone_device reference Andrey Smirnov
@ 2019-04-13 8:27 ` Andrey Smirnov
2019-04-16 17:23 ` Daniel Lezcano
2019-04-13 8:27 ` [PATCH v4 05/12] thermal: qoriq: Pass data to qoriq_tmu_register_tmu_zone() directly Andrey Smirnov
` (8 subsequent siblings)
12 siblings, 1 reply; 23+ messages in thread
From: Andrey Smirnov @ 2019-04-13 8:27 UTC (permalink / raw)
To: linux-pm
Cc: Andrey Smirnov, Chris Healy, Lucas Stach, Eduardo Valentin,
Daniel Lezcano, Angus Ainslie, linux-imx, linux-kernel
Now that driver is converted to use get_temp_id() instead of
get_temp() we no longer need per sensor data. Drop all of the code
related to it.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Cc: Chris Healy <cphealy@gmail.com>
Cc: Lucas Stach <l.stach@pengutronix.de>
Cc: Eduardo Valentin <edubezval@gmail.com>
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: Angus Ainslie (Purism) <angus@akkea.ca>
Cc: linux-imx@nxp.com
Cc: linux-pm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
drivers/thermal/qoriq_thermal.c | 25 ++-----------------------
1 file changed, 2 insertions(+), 23 deletions(-)
diff --git a/drivers/thermal/qoriq_thermal.c b/drivers/thermal/qoriq_thermal.c
index c041d1ae3500..3500e238fe3e 100644
--- a/drivers/thermal/qoriq_thermal.c
+++ b/drivers/thermal/qoriq_thermal.c
@@ -59,20 +59,9 @@ struct qoriq_tmu_regs {
u32 ttr3cr; /* Temperature Range 3 Control Register */
};
-struct qoriq_tmu_data;
-
-/*
- * Thermal zone data
- */
-struct qoriq_sensor {
- struct qoriq_tmu_data *qdata;
- int id;
-};
-
struct qoriq_tmu_data {
struct qoriq_tmu_regs __iomem *regs;
bool little_endian;
- struct qoriq_sensor *sensor[SITES_MAX];
};
static void tmu_write(struct qoriq_tmu_data *p, u32 val, void __iomem *addr)
@@ -93,8 +82,7 @@ static u32 tmu_read(struct qoriq_tmu_data *p, void __iomem *addr)
static int tmu_get_temp(int id, void *p, int *temp)
{
- struct qoriq_sensor *qsensor = p;
- struct qoriq_tmu_data *qdata = qsensor->qdata;
+ struct qoriq_tmu_data *qdata = p;
u32 val;
val = tmu_read(qdata, &qdata->regs->site[id].tritsr);
@@ -115,17 +103,8 @@ static int qoriq_tmu_register_tmu_zone(struct platform_device *pdev)
for (id = 0; id < SITES_MAX; id++) {
struct thermal_zone_device *tzd;
- qdata->sensor[id] = 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;
-
tzd = devm_thermal_zone_of_sensor_register(&pdev->dev, id,
- qdata->sensor[id],
- &tmu_tz_ops);
+ qdata, &tmu_tz_ops);
if (IS_ERR(tzd)) {
if (PTR_ERR(tzd) == -ENODEV)
continue;
--
2.20.1
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH v4 05/12] thermal: qoriq: Pass data to qoriq_tmu_register_tmu_zone() directly
2019-04-13 8:27 [PATCH v4 00/12] QorIQ TMU multi-sensor and HWMON support Andrey Smirnov
` (3 preceding siblings ...)
2019-04-13 8:27 ` [PATCH v4 04/12] thermal: qoriq: Drop per-sensor data Andrey Smirnov
@ 2019-04-13 8:27 ` Andrey Smirnov
2019-04-13 8:27 ` [PATCH v4 06/12] thermal: qoriq: Pass data to qoriq_tmu_calibration() directly Andrey Smirnov
` (7 subsequent siblings)
12 siblings, 0 replies; 23+ messages in thread
From: Andrey Smirnov @ 2019-04-13 8:27 UTC (permalink / raw)
To: linux-pm
Cc: Andrey Smirnov, Daniel Lezcano, Chris Healy, Lucas Stach,
Eduardo Valentin, Angus Ainslie, linux-imx, linux-kernel
Pass all necessary data to qoriq_tmu_register_tmu_zone() directly
instead of passing a paltform device and then deriving it. This is
done as a first step to simplify resource deallocation code.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: Chris Healy <cphealy@gmail.com>
Cc: Lucas Stach <l.stach@pengutronix.de>
Cc: Eduardo Valentin <edubezval@gmail.com>
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: Angus Ainslie (Purism) <angus@akkea.ca>
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 3500e238fe3e..3419505a2f0a 100644
--- a/drivers/thermal/qoriq_thermal.c
+++ b/drivers/thermal/qoriq_thermal.c
@@ -95,15 +95,15 @@ static const struct thermal_zone_of_device_ops tmu_tz_ops = {
.get_temp_id = 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++) {
struct thermal_zone_device *tzd;
- tzd = devm_thermal_zone_of_sensor_register(&pdev->dev, id,
+ tzd = devm_thermal_zone_of_sensor_register(dev, id,
qdata, &tmu_tz_ops);
if (IS_ERR(tzd)) {
if (PTR_ERR(tzd) == -ENODEV)
@@ -198,7 +198,7 @@ static int qoriq_tmu_probe(struct platform_device *pdev)
if (ret < 0)
goto err_tmu;
- 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;
--
2.20.1
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH v4 06/12] thermal: qoriq: Pass data to qoriq_tmu_calibration() directly
2019-04-13 8:27 [PATCH v4 00/12] QorIQ TMU multi-sensor and HWMON support Andrey Smirnov
` (4 preceding siblings ...)
2019-04-13 8:27 ` [PATCH v4 05/12] thermal: qoriq: Pass data to qoriq_tmu_register_tmu_zone() directly Andrey Smirnov
@ 2019-04-13 8:27 ` Andrey Smirnov
2019-04-16 16:51 ` Daniel Lezcano
2019-04-13 8:27 ` [PATCH v4 07/12] thermal: qoriq: Convert driver to use devm_ioremap() Andrey Smirnov
` (6 subsequent siblings)
12 siblings, 1 reply; 23+ messages in thread
From: Andrey Smirnov @ 2019-04-13 8:27 UTC (permalink / raw)
To: linux-pm
Cc: Andrey Smirnov, Chris Healy, Lucas Stach, Eduardo Valentin,
Daniel Lezcano, Angus Ainslie, linux-imx, linux-kernel
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 consequently would be able to drop the "err_iomap" error path.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Cc: Chris Healy <cphealy@gmail.com>
Cc: Lucas Stach <l.stach@pengutronix.de>
Cc: Eduardo Valentin <edubezval@gmail.com>
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: Angus Ainslie (Purism) <angus@akkea.ca>
Cc: linux-imx@nxp.com
Cc: linux-pm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
drivers/thermal/qoriq_thermal.c | 24 ++++++++++--------------
1 file changed, 10 insertions(+), 14 deletions(-)
diff --git a/drivers/thermal/qoriq_thermal.c b/drivers/thermal/qoriq_thermal.c
index 3419505a2f0a..0b6937bbc7d0 100644
--- a/drivers/thermal/qoriq_thermal.c
+++ b/drivers/thermal/qoriq_thermal.c
@@ -122,16 +122,16 @@ 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;
if (of_property_read_u32_array(np, "fsl,tmu-range", range, 4)) {
- dev_err(&pdev->dev, "missing calibration range.\n");
+ dev_err(dev, "missing calibration range.\n");
return -ENODEV;
}
@@ -143,7 +143,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;
}
@@ -181,20 +181,17 @@ 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 = of_iomap(np, 0);
if (!data->regs) {
dev_err(dev, "Failed to get memory region\n");
- ret = -ENODEV;
- goto err_iomap;
+ return -ENODEV;
}
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_tmu;
@@ -202,17 +199,16 @@ static int qoriq_tmu_probe(struct platform_device *pdev)
if (ret < 0) {
dev_err(dev, "Failed to register sensors\n");
ret = -ENODEV;
- goto err_iomap;
+ goto err_tmu;
}
+ platform_set_drvdata(pdev, data);
+
return 0;
err_tmu:
iounmap(data->regs);
-err_iomap:
- platform_set_drvdata(pdev, NULL);
-
return ret;
}
--
2.20.1
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH v4 07/12] thermal: qoriq: Convert driver to use devm_ioremap()
2019-04-13 8:27 [PATCH v4 00/12] QorIQ TMU multi-sensor and HWMON support Andrey Smirnov
` (5 preceding siblings ...)
2019-04-13 8:27 ` [PATCH v4 06/12] thermal: qoriq: Pass data to qoriq_tmu_calibration() directly Andrey Smirnov
@ 2019-04-13 8:27 ` Andrey Smirnov
2019-04-16 16:52 ` Daniel Lezcano
2019-04-13 8:27 ` [PATCH v4 08/12] thermal: qoriq: Convert driver to use regmap API Andrey Smirnov
` (5 subsequent siblings)
12 siblings, 1 reply; 23+ messages in thread
From: Andrey Smirnov @ 2019-04-13 8:27 UTC (permalink / raw)
To: linux-pm
Cc: Andrey Smirnov, Chris Healy, Lucas Stach, Eduardo Valentin,
Daniel Lezcano, Angus Ainslie, linux-imx, linux-kernel
Convert driver to use devm_ioremap() to simplify memory deallocation
and error handling code. No functional change intended.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Cc: Chris Healy <cphealy@gmail.com>
Cc: Lucas Stach <l.stach@pengutronix.de>
Cc: Eduardo Valentin <edubezval@gmail.com>
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: Angus Ainslie (Purism) <angus@akkea.ca>
Cc: linux-imx@nxp.com
Cc: linux-pm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
drivers/thermal/qoriq_thermal.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/drivers/thermal/qoriq_thermal.c b/drivers/thermal/qoriq_thermal.c
index 0b6937bbc7d0..64cad6d4c1d7 100644
--- a/drivers/thermal/qoriq_thermal.c
+++ b/drivers/thermal/qoriq_thermal.c
@@ -175,6 +175,7 @@ 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;
+ struct resource *io;
data = devm_kzalloc(dev, sizeof(struct qoriq_tmu_data),
GFP_KERNEL);
@@ -183,7 +184,13 @@ static int qoriq_tmu_probe(struct platform_device *pdev)
data->little_endian = of_property_read_bool(np, "little-endian");
- data->regs = of_iomap(np, 0);
+ io = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ if (!io) {
+ dev_err(dev, "Failed to get memory region\n");
+ return -ENODEV;
+ }
+
+ data->regs = devm_ioremap(dev, io->start, resource_size(io));
if (!data->regs) {
dev_err(dev, "Failed to get memory region\n");
return -ENODEV;
@@ -193,23 +200,17 @@ static int qoriq_tmu_probe(struct platform_device *pdev)
ret = qoriq_tmu_calibration(dev, data); /* TMU calibration */
if (ret < 0)
- goto err_tmu;
+ return ret;
ret = qoriq_tmu_register_tmu_zone(dev, data);
if (ret < 0) {
dev_err(dev, "Failed to register sensors\n");
- ret = -ENODEV;
- goto err_tmu;
+ return -ENODEV;
}
platform_set_drvdata(pdev, data);
return 0;
-
-err_tmu:
- iounmap(data->regs);
-
- return ret;
}
static int qoriq_tmu_remove(struct platform_device *pdev)
@@ -219,7 +220,6 @@ static int qoriq_tmu_remove(struct platform_device *pdev)
/* Disable monitoring */
tmu_write(data, TMR_DISABLE, &data->regs->tmr);
- iounmap(data->regs);
platform_set_drvdata(pdev, NULL);
return 0;
--
2.20.1
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH v4 08/12] thermal: qoriq: Convert driver to use regmap API
2019-04-13 8:27 [PATCH v4 00/12] QorIQ TMU multi-sensor and HWMON support Andrey Smirnov
` (6 preceding siblings ...)
2019-04-13 8:27 ` [PATCH v4 07/12] thermal: qoriq: Convert driver to use devm_ioremap() Andrey Smirnov
@ 2019-04-13 8:27 ` Andrey Smirnov
2019-04-16 16:58 ` Daniel Lezcano
2019-04-13 8:27 ` [PATCH v4 09/12] thermal: qoriq: Enable all sensors before registering them Andrey Smirnov
` (4 subsequent siblings)
12 siblings, 1 reply; 23+ messages in thread
From: Andrey Smirnov @ 2019-04-13 8:27 UTC (permalink / raw)
To: linux-pm
Cc: Andrey Smirnov, Chris Healy, Lucas Stach, Eduardo Valentin,
Daniel Lezcano, Angus Ainslie, linux-imx, linux-kernel
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 <andrew.smirnov@gmail.com>
Cc: Chris Healy <cphealy@gmail.com>
Cc: Lucas Stach <l.stach@pengutronix.de>
Cc: Eduardo Valentin <edubezval@gmail.com>
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: Angus Ainslie (Purism) <angus@akkea.ca>
Cc: linux-imx@nxp.com
Cc: linux-pm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
drivers/thermal/qoriq_thermal.c | 159 +++++++++++++++-----------------
1 file changed, 74 insertions(+), 85 deletions(-)
diff --git a/drivers/thermal/qoriq_thermal.c b/drivers/thermal/qoriq_thermal.c
index 64cad6d4c1d7..9774323a17bf 100644
--- a/drivers/thermal/qoriq_thermal.c
+++ b/drivers/thermal/qoriq_thermal.c
@@ -8,6 +8,7 @@
#include <linux/io.h>
#include <linux/of.h>
#include <linux/of_address.h>
+#include <linux/regmap.h>
#include <linux/thermal.h>
#include "thermal_core.h"
@@ -17,75 +18,37 @@
/*
* QorIQ TMU Registers
*/
-struct qoriq_tmu_site_regs {
- u32 tritsr; /* Immediate Temperature Site Register */
- u32 tratsr; /* Average Temperature Site Register */
- u8 res0[0x8];
-};
-struct qoriq_tmu_regs {
- u32 tmr; /* Mode Register */
+#define REGS_TMR 0x000 /* Mode Register */
#define TMR_DISABLE 0x0
#define TMR_ME 0x80000000
#define TMR_ALPF 0x0c000000
- u32 tsr; /* Status Register */
- u32 tmtmir; /* Temperature measurement interval Register */
+
+#define REGS_TMTMIR 0x008 /* Temperature measurement interval Register */
#define TMTMIR_DEFAULT 0x0000000f
- u8 res0[0x14];
- u32 tier; /* Interrupt Enable Register */
+
+#define REGS_TIER 0x020 /* Interrupt Enable Register */
#define TIER_DISABLE 0x0
- 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 ttr0cr; /* Temperature Range 0 Control Register */
- u32 ttr1cr; /* Temperature Range 1 Control Register */
- u32 ttr2cr; /* Temperature Range 2 Control Register */
- u32 ttr3cr; /* Temperature Range 3 Control Register */
-};
+#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
+ */
struct qoriq_tmu_data {
- struct qoriq_tmu_regs __iomem *regs;
- bool little_endian;
+ struct regmap *regmap;
};
-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(int id, void *p, int *temp)
{
struct qoriq_tmu_data *qdata = p;
u32 val;
- val = tmu_read(qdata, &qdata->regs->site[id].tritsr);
+ regmap_read(qdata->regmap, REGS_TRITSR(id), &val);
*temp = (val & 0xff) * 1000;
return 0;
@@ -117,7 +80,8 @@ static int qoriq_tmu_register_tmu_zone(struct device *dev,
/* Enable monitoring */
if (sites != 0)
- tmu_write(qdata, sites | TMR_ME | TMR_ALPF, &qdata->regs->tmr);
+ regmap_write(qdata->regmap, REGS_TMR,
+ sites | TMR_ME | TMR_ALPF);
return 0;
}
@@ -136,10 +100,8 @@ static int qoriq_tmu_calibration(struct device *dev,
}
/* Init temperature range registers */
- tmu_write(data, range[0], &data->regs->ttr0cr);
- tmu_write(data, range[1], &data->regs->ttr1cr);
- tmu_write(data, range[2], &data->regs->ttr2cr);
- tmu_write(data, range[3], &data->regs->ttr3cr);
+ for (i = 0; i < ARRAY_SIZE(range); i++)
+ regmap_write(data->regmap, REGS_TTRnCR(i), range[i]);
calibration = of_get_property(np, "fsl,tmu-calibration", &len);
if (calibration == NULL || len % 8) {
@@ -149,9 +111,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;
@@ -160,15 +122,32 @@ 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 */
- tmu_write(data, TMTMIR_DEFAULT, &data->regs->tmtmir);
+ regmap_write(data->regmap, REGS_TMTMIR, TMTMIR_DEFAULT);
/* 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)),
+ /* 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;
@@ -176,26 +155,44 @@ static int qoriq_tmu_probe(struct platform_device *pdev)
struct device_node *np = pdev->dev.of_node;
struct device *dev = &pdev->dev;
struct resource *io;
+ 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");
-
io = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!io) {
dev_err(dev, "Failed to get memory region\n");
return -ENODEV;
}
- data->regs = devm_ioremap(dev, io->start, resource_size(io));
- if (!data->regs) {
+ base = devm_ioremap(dev, io->start, resource_size(io));
+ if (!base) {
dev_err(dev, "Failed to get memory region\n");
return -ENODEV;
}
+ data->regmap = devm_regmap_init_mmio(dev, base, ®map_config);
+ if (IS_ERR(data->regmap)) {
+ ret = PTR_ERR(data->regmap);
+ dev_err(dev, "Failed to init regmap (%d)\n", ret);
+ return ret;
+ }
+
qoriq_tmu_init_device(data); /* TMU initialization */
ret = qoriq_tmu_calibration(dev, data); /* TMU calibration */
@@ -218,7 +215,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);
platform_set_drvdata(pdev, NULL);
@@ -226,30 +223,22 @@ static int qoriq_tmu_remove(struct platform_device *pdev)
}
#ifdef CONFIG_PM_SLEEP
-static int qoriq_tmu_suspend(struct device *dev)
+
+static int qoriq_tmu_suspend_resume(struct device *dev, unsigned int val)
{
- u32 tmr;
struct qoriq_tmu_data *data = dev_get_drvdata(dev);
- /* Disable monitoring */
- tmr = tmu_read(data, &data->regs->tmr);
- tmr &= ~TMR_ME;
- tmu_write(data, tmr, &data->regs->tmr);
+ return regmap_update_bits(data->regmap, REGS_TMR, TMR_ME, val);
+}
- return 0;
+static int qoriq_tmu_suspend(struct device *dev)
+{
+ return qoriq_tmu_suspend_resume(dev, 0);
}
static int qoriq_tmu_resume(struct device *dev)
{
- u32 tmr;
- struct qoriq_tmu_data *data = dev_get_drvdata(dev);
-
- /* Enable monitoring */
- tmr = tmu_read(data, &data->regs->tmr);
- tmr |= TMR_ME;
- tmu_write(data, tmr, &data->regs->tmr);
-
- return 0;
+ return qoriq_tmu_suspend_resume(dev, TMR_ME);
}
#endif
--
2.20.1
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH v4 09/12] thermal: qoriq: Enable all sensors before registering them
2019-04-13 8:27 [PATCH v4 00/12] QorIQ TMU multi-sensor and HWMON support Andrey Smirnov
` (7 preceding siblings ...)
2019-04-13 8:27 ` [PATCH v4 08/12] thermal: qoriq: Convert driver to use regmap API Andrey Smirnov
@ 2019-04-13 8:27 ` Andrey Smirnov
2019-04-16 17:09 ` Daniel Lezcano
2019-04-13 8:27 ` [PATCH v4 10/12] thermal: qoriq: Do not report invalid temperature reading Andrey Smirnov
` (3 subsequent siblings)
12 siblings, 1 reply; 23+ messages in thread
From: Andrey Smirnov @ 2019-04-13 8:27 UTC (permalink / raw)
To: linux-pm
Cc: Andrey Smirnov, Chris Healy, Lucas Stach, Eduardo Valentin,
Daniel Lezcano, Angus Ainslie, linux-imx, linux-kernel
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 <andrew.smirnov@gmail.com>
Cc: Chris Healy <cphealy@gmail.com>
Cc: Lucas Stach <l.stach@pengutronix.de>
Cc: Eduardo Valentin <edubezval@gmail.com>
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: Angus Ainslie (Purism) <angus@akkea.ca>
Cc: linux-imx@nxp.com
Cc: linux-pm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
drivers/thermal/qoriq_thermal.c | 27 ++++++++++++++-------------
1 file changed, 14 insertions(+), 13 deletions(-)
diff --git a/drivers/thermal/qoriq_thermal.c b/drivers/thermal/qoriq_thermal.c
index 9774323a17bf..abbbfe88422e 100644
--- a/drivers/thermal/qoriq_thermal.c
+++ b/drivers/thermal/qoriq_thermal.c
@@ -23,6 +23,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
@@ -61,28 +62,28 @@ 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, ret;
+
+ regmap_write(qdata->regmap, REGS_TMR,
+ TMR_MSITE_ALL | TMR_ME | TMR_ALPF);
for (id = 0; id < SITES_MAX; id++) {
struct thermal_zone_device *tzd;
tzd = devm_thermal_zone_of_sensor_register(dev, id,
qdata, &tmu_tz_ops);
- if (IS_ERR(tzd)) {
- if (PTR_ERR(tzd) == -ENODEV)
- continue;
- else
- return PTR_ERR(tzd);
+ ret = PTR_ERR_OR_ZERO(tzd);
+ switch (ret) {
+ case -ENODEV:
+ continue;
+ case 0:
+ break;
+ default:
+ regmap_write(qdata->regmap, REGS_TMR, TMR_DISABLE);
+ return ret;
}
-
- sites |= 0x1 << (15 - id);
}
- /* Enable monitoring */
- if (sites != 0)
- regmap_write(qdata->regmap, REGS_TMR,
- sites | TMR_ME | TMR_ALPF);
-
return 0;
}
--
2.20.1
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH v4 10/12] thermal: qoriq: Do not report invalid temperature reading
2019-04-13 8:27 [PATCH v4 00/12] QorIQ TMU multi-sensor and HWMON support Andrey Smirnov
` (8 preceding siblings ...)
2019-04-13 8:27 ` [PATCH v4 09/12] thermal: qoriq: Enable all sensors before registering them Andrey Smirnov
@ 2019-04-13 8:27 ` Andrey Smirnov
2019-04-16 17:11 ` Daniel Lezcano
2019-04-13 8:27 ` [PATCH v4 11/12] thermal_hwmon: Add devres wrapper for thermal_add_hwmon_sysfs() Andrey Smirnov
` (2 subsequent siblings)
12 siblings, 1 reply; 23+ messages in thread
From: Andrey Smirnov @ 2019-04-13 8:27 UTC (permalink / raw)
To: linux-pm
Cc: Andrey Smirnov, Chris Healy, Lucas Stach, Eduardo Valentin,
Daniel Lezcano, Angus Ainslie, linux-imx, linux-kernel
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 <andrew.smirnov@gmail.com>
Cc: Chris Healy <cphealy@gmail.com>
Cc: Lucas Stach <l.stach@pengutronix.de>
Cc: Eduardo Valentin <edubezval@gmail.com>
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: Angus Ainslie (Purism) <angus@akkea.ca>
Cc: linux-imx@nxp.com
Cc: linux-pm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
drivers/thermal/qoriq_thermal.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/drivers/thermal/qoriq_thermal.c b/drivers/thermal/qoriq_thermal.c
index abbbfe88422e..5c459a9d0db3 100644
--- a/drivers/thermal/qoriq_thermal.c
+++ b/drivers/thermal/qoriq_thermal.c
@@ -37,6 +37,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
*/
@@ -48,10 +49,25 @@ static int tmu_get_temp(int id, void *p, int *temp)
{
struct qoriq_tmu_data *qdata = p;
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(id),
+ val,
+ val & TRITSR_V,
+ USEC_PER_MSEC,
+ 10 * USEC_PER_MSEC))
+ return -ENODATA;
- regmap_read(qdata->regmap, REGS_TRITSR(id), &val);
*temp = (val & 0xff) * 1000;
-
return 0;
}
--
2.20.1
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH v4 11/12] thermal_hwmon: Add devres wrapper for thermal_add_hwmon_sysfs()
2019-04-13 8:27 [PATCH v4 00/12] QorIQ TMU multi-sensor and HWMON support Andrey Smirnov
` (9 preceding siblings ...)
2019-04-13 8:27 ` [PATCH v4 10/12] thermal: qoriq: Do not report invalid temperature reading Andrey Smirnov
@ 2019-04-13 8:27 ` Andrey Smirnov
2019-04-16 17:16 ` Daniel Lezcano
2019-04-13 8:27 ` [PATCH v4 12/12] thermal: qoriq: Add hwmon support Andrey Smirnov
2019-04-16 17:24 ` [PATCH v4 00/12] QorIQ TMU multi-sensor and HWMON support Lucas Stach
12 siblings, 1 reply; 23+ messages in thread
From: Andrey Smirnov @ 2019-04-13 8:27 UTC (permalink / raw)
To: linux-pm
Cc: Andrey Smirnov, Chris Healy, Lucas Stach, Eduardo Valentin,
Daniel Lezcano, Angus Ainslie, linux-imx, linux-kernel
Add devres wrapper for thermal_add_hwmon_sysfs() to simplify driver
code.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Cc: Chris Healy <cphealy@gmail.com>
Cc: Lucas Stach <l.stach@pengutronix.de>
Cc: Eduardo Valentin <edubezval@gmail.com>
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: Angus Ainslie (Purism) <angus@akkea.ca>
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 40c69a533b24..4e79524182e1 100644
--- a/drivers/thermal/thermal_hwmon.c
+++ b/drivers/thermal/thermal_hwmon.c
@@ -244,3 +244,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)
{
--
2.20.1
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH v4 12/12] thermal: qoriq: Add hwmon support
2019-04-13 8:27 [PATCH v4 00/12] QorIQ TMU multi-sensor and HWMON support Andrey Smirnov
` (10 preceding siblings ...)
2019-04-13 8:27 ` [PATCH v4 11/12] thermal_hwmon: Add devres wrapper for thermal_add_hwmon_sysfs() Andrey Smirnov
@ 2019-04-13 8:27 ` Andrey Smirnov
2019-04-16 17:17 ` Daniel Lezcano
2019-04-16 17:24 ` [PATCH v4 00/12] QorIQ TMU multi-sensor and HWMON support Lucas Stach
12 siblings, 1 reply; 23+ messages in thread
From: Andrey Smirnov @ 2019-04-13 8:27 UTC (permalink / raw)
To: linux-pm
Cc: Andrey Smirnov, Chris Healy, Lucas Stach, Eduardo Valentin,
Daniel Lezcano, Angus Ainslie, linux-imx, linux-kernel
Expose thermal readings as a HWMON device, so that it could be
accessed using lm-sensors.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Cc: Chris Healy <cphealy@gmail.com>
Cc: Lucas Stach <l.stach@pengutronix.de>
Cc: Eduardo Valentin <edubezval@gmail.com>
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: Angus Ainslie (Purism) <angus@akkea.ca>
Cc: linux-imx@nxp.com
Cc: linux-pm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
drivers/thermal/qoriq_thermal.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/thermal/qoriq_thermal.c b/drivers/thermal/qoriq_thermal.c
index 5c459a9d0db3..897b3424b43b 100644
--- a/drivers/thermal/qoriq_thermal.c
+++ b/drivers/thermal/qoriq_thermal.c
@@ -12,6 +12,7 @@
#include <linux/thermal.h>
#include "thermal_core.h"
+#include "thermal_hwmon.h"
#define SITES_MAX 16
@@ -93,6 +94,10 @@ static int qoriq_tmu_register_tmu_zone(struct device *dev,
case -ENODEV:
continue;
case 0:
+ ret = devm_thermal_add_hwmon_sysfs(tzd);
+ if (ret)
+ dev_warn(dev,
+ "Failed to add hwmon sysfs attributes\n");
break;
default:
regmap_write(qdata->regmap, REGS_TMR, TMR_DISABLE);
--
2.20.1
^ permalink raw reply related [flat|nested] 23+ messages in thread
* Re: [PATCH v4 06/12] thermal: qoriq: Pass data to qoriq_tmu_calibration() directly
2019-04-13 8:27 ` [PATCH v4 06/12] thermal: qoriq: Pass data to qoriq_tmu_calibration() directly Andrey Smirnov
@ 2019-04-16 16:51 ` Daniel Lezcano
0 siblings, 0 replies; 23+ messages in thread
From: Daniel Lezcano @ 2019-04-16 16:51 UTC (permalink / raw)
To: Andrey Smirnov, linux-pm
Cc: Chris Healy, Lucas Stach, Eduardo Valentin, Angus Ainslie,
linux-imx, linux-kernel
On 13/04/2019 10:27, Andrey Smirnov wrote:
> 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 consequently would be able to drop the "err_iomap" error path.
>
> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> Cc: Chris Healy <cphealy@gmail.com>
> Cc: Lucas Stach <l.stach@pengutronix.de>
> Cc: Eduardo Valentin <edubezval@gmail.com>
> Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
> Cc: Angus Ainslie (Purism) <angus@akkea.ca>
> Cc: linux-imx@nxp.com
> Cc: linux-pm@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
> ---
> drivers/thermal/qoriq_thermal.c | 24 ++++++++++--------------
> 1 file changed, 10 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/thermal/qoriq_thermal.c b/drivers/thermal/qoriq_thermal.c
> index 3419505a2f0a..0b6937bbc7d0 100644
> --- a/drivers/thermal/qoriq_thermal.c
> +++ b/drivers/thermal/qoriq_thermal.c
> @@ -122,16 +122,16 @@ 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;
>
> if (of_property_read_u32_array(np, "fsl,tmu-range", range, 4)) {
> - dev_err(&pdev->dev, "missing calibration range.\n");
> + dev_err(dev, "missing calibration range.\n");
> return -ENODEV;
> }
>
> @@ -143,7 +143,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;
> }
>
> @@ -181,20 +181,17 @@ 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 = of_iomap(np, 0);
> if (!data->regs) {
> dev_err(dev, "Failed to get memory region\n");
> - ret = -ENODEV;
> - goto err_iomap;
> + return -ENODEV;
> }
>
> 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_tmu;
>
> @@ -202,17 +199,16 @@ static int qoriq_tmu_probe(struct platform_device *pdev)
> if (ret < 0) {
> dev_err(dev, "Failed to register sensors\n");
> ret = -ENODEV;
> - goto err_iomap;
> + goto err_tmu;
> }
>
> + platform_set_drvdata(pdev, data);
> +
> return 0;
>
> err_tmu:
> iounmap(data->regs);
>
> -err_iomap:
> - platform_set_drvdata(pdev, NULL);
> -
> return ret;
> }
>
>
--
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs
Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH v4 07/12] thermal: qoriq: Convert driver to use devm_ioremap()
2019-04-13 8:27 ` [PATCH v4 07/12] thermal: qoriq: Convert driver to use devm_ioremap() Andrey Smirnov
@ 2019-04-16 16:52 ` Daniel Lezcano
0 siblings, 0 replies; 23+ messages in thread
From: Daniel Lezcano @ 2019-04-16 16:52 UTC (permalink / raw)
To: Andrey Smirnov, linux-pm
Cc: Chris Healy, Lucas Stach, Eduardo Valentin, Angus Ainslie,
linux-imx, linux-kernel
On 13/04/2019 10:27, Andrey Smirnov wrote:
> Convert driver to use devm_ioremap() to simplify memory deallocation
> and error handling code. No functional change intended.
>
> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> Cc: Chris Healy <cphealy@gmail.com>
> Cc: Lucas Stach <l.stach@pengutronix.de>
> Cc: Eduardo Valentin <edubezval@gmail.com>
> Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
> Cc: Angus Ainslie (Purism) <angus@akkea.ca>
> Cc: linux-imx@nxp.com
> Cc: linux-pm@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
> ---
> drivers/thermal/qoriq_thermal.c | 20 ++++++++++----------
> 1 file changed, 10 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/thermal/qoriq_thermal.c b/drivers/thermal/qoriq_thermal.c
> index 0b6937bbc7d0..64cad6d4c1d7 100644
> --- a/drivers/thermal/qoriq_thermal.c
> +++ b/drivers/thermal/qoriq_thermal.c
> @@ -175,6 +175,7 @@ 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;
> + struct resource *io;
>
> data = devm_kzalloc(dev, sizeof(struct qoriq_tmu_data),
> GFP_KERNEL);
> @@ -183,7 +184,13 @@ static int qoriq_tmu_probe(struct platform_device *pdev)
>
> data->little_endian = of_property_read_bool(np, "little-endian");
>
> - data->regs = of_iomap(np, 0);
> + io = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> + if (!io) {
> + dev_err(dev, "Failed to get memory region\n");
> + return -ENODEV;
> + }
> +
> + data->regs = devm_ioremap(dev, io->start, resource_size(io));
> if (!data->regs) {
> dev_err(dev, "Failed to get memory region\n");
> return -ENODEV;
> @@ -193,23 +200,17 @@ static int qoriq_tmu_probe(struct platform_device *pdev)
>
> ret = qoriq_tmu_calibration(dev, data); /* TMU calibration */
> if (ret < 0)
> - goto err_tmu;
> + return ret;
>
> ret = qoriq_tmu_register_tmu_zone(dev, data);
> if (ret < 0) {
> dev_err(dev, "Failed to register sensors\n");
> - ret = -ENODEV;
> - goto err_tmu;
> + return -ENODEV;
> }
>
> platform_set_drvdata(pdev, data);
>
> return 0;
> -
> -err_tmu:
> - iounmap(data->regs);
> -
> - return ret;
> }
>
> static int qoriq_tmu_remove(struct platform_device *pdev)
> @@ -219,7 +220,6 @@ static int qoriq_tmu_remove(struct platform_device *pdev)
> /* Disable monitoring */
> tmu_write(data, TMR_DISABLE, &data->regs->tmr);
>
> - iounmap(data->regs);
> platform_set_drvdata(pdev, NULL);
>
> return 0;
>
--
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs
Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH v4 08/12] thermal: qoriq: Convert driver to use regmap API
2019-04-13 8:27 ` [PATCH v4 08/12] thermal: qoriq: Convert driver to use regmap API Andrey Smirnov
@ 2019-04-16 16:58 ` Daniel Lezcano
0 siblings, 0 replies; 23+ messages in thread
From: Daniel Lezcano @ 2019-04-16 16:58 UTC (permalink / raw)
To: Andrey Smirnov, linux-pm
Cc: Chris Healy, Lucas Stach, Eduardo Valentin, Angus Ainslie,
linux-imx, linux-kernel
On 13/04/2019 10:27, Andrey Smirnov wrote:
> 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 <andrew.smirnov@gmail.com>
> Cc: Chris Healy <cphealy@gmail.com>
> Cc: Lucas Stach <l.stach@pengutronix.de>
> Cc: Eduardo Valentin <edubezval@gmail.com>
> Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
> Cc: Angus Ainslie (Purism) <angus@akkea.ca>
> Cc: linux-imx@nxp.com
> Cc: linux-pm@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> ---
Nice!
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
--
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs
Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH v4 09/12] thermal: qoriq: Enable all sensors before registering them
2019-04-13 8:27 ` [PATCH v4 09/12] thermal: qoriq: Enable all sensors before registering them Andrey Smirnov
@ 2019-04-16 17:09 ` Daniel Lezcano
2019-04-18 20:02 ` Andrey Smirnov
0 siblings, 1 reply; 23+ messages in thread
From: Daniel Lezcano @ 2019-04-16 17:09 UTC (permalink / raw)
To: Andrey Smirnov, linux-pm
Cc: Chris Healy, Lucas Stach, Eduardo Valentin, Angus Ainslie,
linux-imx, linux-kernel
On 13/04/2019 10:27, Andrey Smirnov wrote:
> 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 <andrew.smirnov@gmail.com>
> Cc: Chris Healy <cphealy@gmail.com>
> Cc: Lucas Stach <l.stach@pengutronix.de>
> Cc: Eduardo Valentin <edubezval@gmail.com>
> Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
> Cc: Angus Ainslie (Purism) <angus@akkea.ca>
> Cc: linux-imx@nxp.com
> Cc: linux-pm@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> ---
> drivers/thermal/qoriq_thermal.c | 27 ++++++++++++++-------------
> 1 file changed, 14 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/thermal/qoriq_thermal.c b/drivers/thermal/qoriq_thermal.c
> index 9774323a17bf..abbbfe88422e 100644
> --- a/drivers/thermal/qoriq_thermal.c
> +++ b/drivers/thermal/qoriq_thermal.c
> @@ -23,6 +23,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
> @@ -61,28 +62,28 @@ 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, ret;
> +
> + regmap_write(qdata->regmap, REGS_TMR,
> + TMR_MSITE_ALL | TMR_ME | TMR_ALPF);
>
> for (id = 0; id < SITES_MAX; id++) {
> struct thermal_zone_device *tzd;
>
> tzd = devm_thermal_zone_of_sensor_register(dev, id,
> qdata, &tmu_tz_ops);
> - if (IS_ERR(tzd)) {
> - if (PTR_ERR(tzd) == -ENODEV)
> - continue;
> - else
> - return PTR_ERR(tzd);
> + ret = PTR_ERR_OR_ZERO(tzd);
> + switch (ret) {
> + case -ENODEV:
> + continue;
> + case 0:
Why not simply:
if (!IS_ERR(tzd) || PTR_ERR(tzd) == -ENODEV)
continue;
regmap_write(qdata->regmap, REGS_TMR, TMR_DISABLE);
return PTR_ERR(tzd);
?
> + break;
> + default:
> + regmap_write(qdata->regmap, REGS_TMR, TMR_DISABLE);
> + return ret;
> }
> -
> - sites |= 0x1 << (15 - id);
> }
>
> - /* Enable monitoring */
> - if (sites != 0)
> - regmap_write(qdata->regmap, REGS_TMR,
> - sites | TMR_ME | TMR_ALPF);
> -
> return 0;
> }
>
>
--
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs
Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH v4 10/12] thermal: qoriq: Do not report invalid temperature reading
2019-04-13 8:27 ` [PATCH v4 10/12] thermal: qoriq: Do not report invalid temperature reading Andrey Smirnov
@ 2019-04-16 17:11 ` Daniel Lezcano
0 siblings, 0 replies; 23+ messages in thread
From: Daniel Lezcano @ 2019-04-16 17:11 UTC (permalink / raw)
To: Andrey Smirnov, linux-pm
Cc: Chris Healy, Lucas Stach, Eduardo Valentin, Angus Ainslie,
linux-imx, linux-kernel
On 13/04/2019 10:27, Andrey Smirnov wrote:
> 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 <andrew.smirnov@gmail.com>
> Cc: Chris Healy <cphealy@gmail.com>
> Cc: Lucas Stach <l.stach@pengutronix.de>
> Cc: Eduardo Valentin <edubezval@gmail.com>
> Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
> Cc: Angus Ainslie (Purism) <angus@akkea.ca>
> Cc: linux-imx@nxp.com
> Cc: linux-pm@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> ---
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
> drivers/thermal/qoriq_thermal.c | 20 ++++++++++++++++++--
> 1 file changed, 18 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/thermal/qoriq_thermal.c b/drivers/thermal/qoriq_thermal.c
> index abbbfe88422e..5c459a9d0db3 100644
> --- a/drivers/thermal/qoriq_thermal.c
> +++ b/drivers/thermal/qoriq_thermal.c
> @@ -37,6 +37,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
> */
> @@ -48,10 +49,25 @@ static int tmu_get_temp(int id, void *p, int *temp)
> {
> struct qoriq_tmu_data *qdata = p;
> 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(id),
> + val,
> + val & TRITSR_V,
> + USEC_PER_MSEC,
> + 10 * USEC_PER_MSEC))
> + return -ENODATA;
>
> - regmap_read(qdata->regmap, REGS_TRITSR(id), &val);
> *temp = (val & 0xff) * 1000;
> -
> return 0;
> }
>
>
--
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs
Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH v4 11/12] thermal_hwmon: Add devres wrapper for thermal_add_hwmon_sysfs()
2019-04-13 8:27 ` [PATCH v4 11/12] thermal_hwmon: Add devres wrapper for thermal_add_hwmon_sysfs() Andrey Smirnov
@ 2019-04-16 17:16 ` Daniel Lezcano
0 siblings, 0 replies; 23+ messages in thread
From: Daniel Lezcano @ 2019-04-16 17:16 UTC (permalink / raw)
To: Andrey Smirnov, linux-pm
Cc: Chris Healy, Lucas Stach, Eduardo Valentin, Angus Ainslie,
linux-imx, linux-kernel
On 13/04/2019 10:27, Andrey Smirnov wrote:
> Add devres wrapper for thermal_add_hwmon_sysfs() to simplify driver
> code.
>
> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> Cc: Chris Healy <cphealy@gmail.com>
> Cc: Lucas Stach <l.stach@pengutronix.de>
> Cc: Eduardo Valentin <edubezval@gmail.com>
> Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
> Cc: Angus Ainslie (Purism) <angus@akkea.ca>
> Cc: linux-imx@nxp.com
> Cc: linux-pm@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> ---
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
--
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs
Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH v4 12/12] thermal: qoriq: Add hwmon support
2019-04-13 8:27 ` [PATCH v4 12/12] thermal: qoriq: Add hwmon support Andrey Smirnov
@ 2019-04-16 17:17 ` Daniel Lezcano
0 siblings, 0 replies; 23+ messages in thread
From: Daniel Lezcano @ 2019-04-16 17:17 UTC (permalink / raw)
To: Andrey Smirnov, linux-pm
Cc: Chris Healy, Lucas Stach, Eduardo Valentin, Angus Ainslie,
linux-imx, linux-kernel
On 13/04/2019 10:27, Andrey Smirnov wrote:
> Expose thermal readings as a HWMON device, so that it could be
> accessed using lm-sensors.
>
> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> Cc: Chris Healy <cphealy@gmail.com>
> Cc: Lucas Stach <l.stach@pengutronix.de>
> Cc: Eduardo Valentin <edubezval@gmail.com>
> Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
> Cc: Angus Ainslie (Purism) <angus@akkea.ca>
> Cc: linux-imx@nxp.com
> Cc: linux-pm@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> ---
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
> drivers/thermal/qoriq_thermal.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/thermal/qoriq_thermal.c b/drivers/thermal/qoriq_thermal.c
> index 5c459a9d0db3..897b3424b43b 100644
> --- a/drivers/thermal/qoriq_thermal.c
> +++ b/drivers/thermal/qoriq_thermal.c
> @@ -12,6 +12,7 @@
> #include <linux/thermal.h>
>
> #include "thermal_core.h"
> +#include "thermal_hwmon.h"
>
> #define SITES_MAX 16
>
> @@ -93,6 +94,10 @@ static int qoriq_tmu_register_tmu_zone(struct device *dev,
> case -ENODEV:
> continue;
> case 0:
> + ret = devm_thermal_add_hwmon_sysfs(tzd);
> + if (ret)
> + dev_warn(dev,
> + "Failed to add hwmon sysfs attributes\n");
> break;
> default:
> regmap_write(qdata->regmap, REGS_TMR, TMR_DISABLE);
>
--
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs
Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH v4 04/12] thermal: qoriq: Drop per-sensor data
2019-04-13 8:27 ` [PATCH v4 04/12] thermal: qoriq: Drop per-sensor data Andrey Smirnov
@ 2019-04-16 17:23 ` Daniel Lezcano
0 siblings, 0 replies; 23+ messages in thread
From: Daniel Lezcano @ 2019-04-16 17:23 UTC (permalink / raw)
To: Andrey Smirnov, linux-pm
Cc: Chris Healy, Lucas Stach, Eduardo Valentin, Angus Ainslie,
linux-imx, linux-kernel
On 13/04/2019 10:27, Andrey Smirnov wrote:
> Now that driver is converted to use get_temp_id() instead of
> get_temp() we no longer need per sensor data. Drop all of the code
> related to it.
Rui, Eduardo,
I just want to point out this patch is depending on:
"[PATCH] thermal/drivers/of: Add a get_temp_id callback function"
> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> Cc: Chris Healy <cphealy@gmail.com>
> Cc: Lucas Stach <l.stach@pengutronix.de>
> Cc: Eduardo Valentin <edubezval@gmail.com>
> Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
> Cc: Angus Ainslie (Purism) <angus@akkea.ca>
> Cc: linux-imx@nxp.com
> Cc: linux-pm@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> ---
> drivers/thermal/qoriq_thermal.c | 25 ++-----------------------
> 1 file changed, 2 insertions(+), 23 deletions(-)
>
> diff --git a/drivers/thermal/qoriq_thermal.c b/drivers/thermal/qoriq_thermal.c
> index c041d1ae3500..3500e238fe3e 100644
> --- a/drivers/thermal/qoriq_thermal.c
> +++ b/drivers/thermal/qoriq_thermal.c
> @@ -59,20 +59,9 @@ struct qoriq_tmu_regs {
> u32 ttr3cr; /* Temperature Range 3 Control Register */
> };
>
> -struct qoriq_tmu_data;
> -
> -/*
> - * Thermal zone data
> - */
> -struct qoriq_sensor {
> - struct qoriq_tmu_data *qdata;
> - int id;
> -};
> -
> struct qoriq_tmu_data {
> struct qoriq_tmu_regs __iomem *regs;
> bool little_endian;
> - struct qoriq_sensor *sensor[SITES_MAX];
> };
>
> static void tmu_write(struct qoriq_tmu_data *p, u32 val, void __iomem *addr)
> @@ -93,8 +82,7 @@ static u32 tmu_read(struct qoriq_tmu_data *p, void __iomem *addr)
>
> static int tmu_get_temp(int id, void *p, int *temp)
> {
> - struct qoriq_sensor *qsensor = p;
> - struct qoriq_tmu_data *qdata = qsensor->qdata;
> + struct qoriq_tmu_data *qdata = p;
> u32 val;
>
> val = tmu_read(qdata, &qdata->regs->site[id].tritsr);
> @@ -115,17 +103,8 @@ static int qoriq_tmu_register_tmu_zone(struct platform_device *pdev)
> for (id = 0; id < SITES_MAX; id++) {
> struct thermal_zone_device *tzd;
>
> - qdata->sensor[id] = 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;
> -
> tzd = devm_thermal_zone_of_sensor_register(&pdev->dev, id,
> - qdata->sensor[id],
> - &tmu_tz_ops);
> + qdata, &tmu_tz_ops);
> if (IS_ERR(tzd)) {
> if (PTR_ERR(tzd) == -ENODEV)
> continue;
>
--
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs
Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH v4 00/12] QorIQ TMU multi-sensor and HWMON support
2019-04-13 8:27 [PATCH v4 00/12] QorIQ TMU multi-sensor and HWMON support Andrey Smirnov
` (11 preceding siblings ...)
2019-04-13 8:27 ` [PATCH v4 12/12] thermal: qoriq: Add hwmon support Andrey Smirnov
@ 2019-04-16 17:24 ` Lucas Stach
12 siblings, 0 replies; 23+ messages in thread
From: Lucas Stach @ 2019-04-16 17:24 UTC (permalink / raw)
To: Andrey Smirnov, linux-pm
Cc: Chris Healy, Eduardo Valentin, Daniel Lezcano, Angus Ainslie,
linux-imx, linux-kernel
Series is:
Tested-by: Lucas Stach <l.stach@pengutronix.de>
Regards,
Lucas
Am Samstag, den 13.04.2019, 01:27 -0700 schrieb Andrey Smirnov:
> Everyone:
>
> This series contains patches adding support for HWMON integration, bug
> fixes and general improvements (hopefully) for TMU driver I made while
> working on it on i.MX8MQ.
>
> Feedback is welcome!
>
> Thanks,
> Andrey Smirnov
>
> Changes since [v3]
>
> - Series reabse on top of [rfc]
>
> - Fixed incorrect goto label in "thermal: qoriq: Pass data to
> qoriq_tmu_calibration()"
>
> - Added REGS_TRITSR() register description to "thermal: qoriq: Do
> not report invalid temperature reading"
>
> - Reworded commit message of "thermal: qoriq: Remove unnecessary
> DT node is NULL check"
>
> Changes since [v2]
>
> - Patches rebased on v5.1-rc1
>
> Changes since [v1]
>
> - Rebased on "linus" branch of
> git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux-soc-thermal.git
> that included latest chagnes adding multi-sensors support
>
> - Dropped
>
> thermal: qoriq: Add support for multiple thremal sites
> thermal: qoriq: Be more strict when parsing
> thermal: qoriq: Simplify error handling in qoriq_tmu_get_sensor_id()
>
> since they are no longer relevant
>
> - Added
>
> thermal: qoriq: Don't store struct thermal_zone_device reference
> thermal: qoriq: Add local struct qoriq_sensor pointer
> thermal: qoriq: Embed per-sensor data into struct qoriq_tmu_data
> thermal: qoriq: Pass data to qoriq_tmu_register_tmu_zone() directly
>
> to simplify latest codebase
>
> - Changed "thermal: qoriq: Do not report invalid temperature
> reading" to use regmap_read_poll_timeout() to make sure that
> tmu_get_temp() waits for fist sample to be ready before
> reporting it. This case is triggered on my setup if
> qoriq_thermal is compiled as a module
>
> [v1] lore.kernel.org/lkml/20190218191141.3729-1-andrew.smirnov@gmail.com
> [v2] lore.kernel.org/lkml/20190222200508.26325-1-andrew.smirnov@gmail.com
> [v3] lore.kernel.org/lkml/20190401041418.5999-1-andrew.smirnov@gmail.com
> [rfc] lore.kernel.org/lkml/20190404080647.8173-1-daniel.lezcano@linaro.org
>
> Andrey Smirnov (12):
> thermal: qoriq: Remove unnecessary DT node is NULL check
> thermal: qoriq: Add local struct device pointer
> thermal: qoriq: Don't store struct thermal_zone_device reference
> thermal: qoriq: Drop per-sensor data
> thermal: qoriq: Pass data to qoriq_tmu_register_tmu_zone() directly
> thermal: qoriq: Pass data to qoriq_tmu_calibration() directly
> thermal: qoriq: Convert driver to use devm_ioremap()
> thermal: qoriq: Convert driver to use regmap API
> thermal: qoriq: Enable all sensors before registering them
> thermal: qoriq: Do not report invalid temperature reading
> thermal_hwmon: Add devres wrapper for thermal_add_hwmon_sysfs()
> thermal: qoriq: Add hwmon support
>
> drivers/thermal/qoriq_thermal.c | 287 +++++++++++++++-----------------
> drivers/thermal/thermal_hwmon.c | 28 ++++
> drivers/thermal/thermal_hwmon.h | 7 +
> 3 files changed, 171 insertions(+), 151 deletions(-)
>
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH v4 09/12] thermal: qoriq: Enable all sensors before registering them
2019-04-16 17:09 ` Daniel Lezcano
@ 2019-04-18 20:02 ` Andrey Smirnov
0 siblings, 0 replies; 23+ messages in thread
From: Andrey Smirnov @ 2019-04-18 20:02 UTC (permalink / raw)
To: Daniel Lezcano
Cc: linux-pm, Chris Healy, Lucas Stach, Eduardo Valentin,
Angus Ainslie, dl-linux-imx, linux-kernel
On Tue, Apr 16, 2019 at 10:09 AM Daniel Lezcano
<daniel.lezcano@linaro.org> wrote:
>
> On 13/04/2019 10:27, Andrey Smirnov wrote:
> > 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 <andrew.smirnov@gmail.com>
> > Cc: Chris Healy <cphealy@gmail.com>
> > Cc: Lucas Stach <l.stach@pengutronix.de>
> > Cc: Eduardo Valentin <edubezval@gmail.com>
> > Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
> > Cc: Angus Ainslie (Purism) <angus@akkea.ca>
> > Cc: linux-imx@nxp.com
> > Cc: linux-pm@vger.kernel.org
> > Cc: linux-kernel@vger.kernel.org
> > ---
> > drivers/thermal/qoriq_thermal.c | 27 ++++++++++++++-------------
> > 1 file changed, 14 insertions(+), 13 deletions(-)
> >
> > diff --git a/drivers/thermal/qoriq_thermal.c b/drivers/thermal/qoriq_thermal.c
> > index 9774323a17bf..abbbfe88422e 100644
> > --- a/drivers/thermal/qoriq_thermal.c
> > +++ b/drivers/thermal/qoriq_thermal.c
> > @@ -23,6 +23,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
> > @@ -61,28 +62,28 @@ 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, ret;
> > +
> > + regmap_write(qdata->regmap, REGS_TMR,
> > + TMR_MSITE_ALL | TMR_ME | TMR_ALPF);
> >
> > for (id = 0; id < SITES_MAX; id++) {
> > struct thermal_zone_device *tzd;
> >
> > tzd = devm_thermal_zone_of_sensor_register(dev, id,
> > qdata, &tmu_tz_ops);
> > - if (IS_ERR(tzd)) {
> > - if (PTR_ERR(tzd) == -ENODEV)
> > - continue;
> > - else
> > - return PTR_ERR(tzd);
> > + ret = PTR_ERR_OR_ZERO(tzd);
> > + switch (ret) {
> > + case -ENODEV:
> > + continue;
> > + case 0:
>
> Why not simply:
>
> if (!IS_ERR(tzd) || PTR_ERR(tzd) == -ENODEV)
> continue;
>
> regmap_write(qdata->regmap, REGS_TMR, TMR_DISABLE);
>
> return PTR_ERR(tzd);
>
> ?
Seemed like less typing and smaller diff for following patch that adds
hwmon sensor registration. I can probable make "if" work kind of the
same, so I'll change that. I do dislike that you had to use *_ERR
macro three times though, so I'll stick with PTR_ERR_OR_ZERO.
Thanks,
Andrey Smirnov
^ permalink raw reply [flat|nested] 23+ messages in thread
end of thread, other threads:[~2019-04-18 20:02 UTC | newest]
Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-13 8:27 [PATCH v4 00/12] QorIQ TMU multi-sensor and HWMON support Andrey Smirnov
2019-04-13 8:27 ` [PATCH v4 01/12] thermal: qoriq: Remove unnecessary DT node is NULL check Andrey Smirnov
2019-04-13 8:27 ` [PATCH v4 02/12] thermal: qoriq: Add local struct device pointer Andrey Smirnov
2019-04-13 8:27 ` [PATCH v4 03/12] thermal: qoriq: Don't store struct thermal_zone_device reference Andrey Smirnov
2019-04-13 8:27 ` [PATCH v4 04/12] thermal: qoriq: Drop per-sensor data Andrey Smirnov
2019-04-16 17:23 ` Daniel Lezcano
2019-04-13 8:27 ` [PATCH v4 05/12] thermal: qoriq: Pass data to qoriq_tmu_register_tmu_zone() directly Andrey Smirnov
2019-04-13 8:27 ` [PATCH v4 06/12] thermal: qoriq: Pass data to qoriq_tmu_calibration() directly Andrey Smirnov
2019-04-16 16:51 ` Daniel Lezcano
2019-04-13 8:27 ` [PATCH v4 07/12] thermal: qoriq: Convert driver to use devm_ioremap() Andrey Smirnov
2019-04-16 16:52 ` Daniel Lezcano
2019-04-13 8:27 ` [PATCH v4 08/12] thermal: qoriq: Convert driver to use regmap API Andrey Smirnov
2019-04-16 16:58 ` Daniel Lezcano
2019-04-13 8:27 ` [PATCH v4 09/12] thermal: qoriq: Enable all sensors before registering them Andrey Smirnov
2019-04-16 17:09 ` Daniel Lezcano
2019-04-18 20:02 ` Andrey Smirnov
2019-04-13 8:27 ` [PATCH v4 10/12] thermal: qoriq: Do not report invalid temperature reading Andrey Smirnov
2019-04-16 17:11 ` Daniel Lezcano
2019-04-13 8:27 ` [PATCH v4 11/12] thermal_hwmon: Add devres wrapper for thermal_add_hwmon_sysfs() Andrey Smirnov
2019-04-16 17:16 ` Daniel Lezcano
2019-04-13 8:27 ` [PATCH v4 12/12] thermal: qoriq: Add hwmon support Andrey Smirnov
2019-04-16 17:17 ` Daniel Lezcano
2019-04-16 17:24 ` [PATCH v4 00/12] QorIQ TMU multi-sensor and HWMON support Lucas Stach
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).