Commit graph

1451 commits

Author SHA1 Message Date
Amit Kucheria e8c24c6f5d drivers: thermal: tsens: Add generic support for TSENS v1 IP
qcs404 has a single TSENS IP block with 10 sensors. It uses version 1.4
of the TSENS IP, functionality for which is encapsulated inside the
qcom,tsens-v1 compatible.

Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
2019-05-14 07:00:21 -07:00
Amit Kucheria 14bbe98811 drivers: thermal: tsens: Common get_temp() learns to do ADC conversion
get_temp() learns to return temperature regardless of whether it is
returned as ADC code or direct temperature.

Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
2019-05-14 06:59:22 -07:00
Amit Kucheria c8b6169093 drivers: thermal: tsens: Move get_temp_tsens_v2 to allow sharing
Just rename the function and move it to allow code sharing with future
versions of TSENS IP

Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
2019-05-14 06:59:21 -07:00
Amit Kucheria dbdaa582e4 drivers: thermal: tsens: simplify get_temp_tsens_v2 routine
The current implementation is based on an algorithm published in the
docs. Instead of reading the temperature thrice w/o any explanation,
improve the algorithm.

This will become the basis for a common get_temp routine in the future.

Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
2019-05-14 06:59:20 -07:00
Amit Kucheria 1b6e3e517f drivers: thermal: tsens: Introduce IP-specific max_sensor count
The IP can support 'm' sensors while the platform can enable 'n' sensors
of the 'm' where n <= m.

Track maximum sensors supported by the IP so that we can correctly track
what subset of the sensors are supported on the platform.

Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
2019-05-14 06:59:19 -07:00
Amit Kucheria 66ad8a1009 drivers: thermal: tsens: change data type for sensor IDs
The IDs cannot be negative, fix the data type.

Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
2019-05-14 06:59:18 -07:00
Amit Kucheria 3e6a8fb330 drivers: thermal: tsens: Add new operation to check if a sensor is enabled
is_sensor_enabled() checks if the sensors are enabled on this platform.
It is possible that the SoC might choose not to enable all the sensors
that the IP block is capable of supporting.

Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
2019-05-14 06:59:17 -07:00
Amit Kucheria fc7d18cf6a drivers: thermal: tsens: Don't print error message on -EPROBE_DEFER
We print a calibration failure message on -EPROBE_DEFER from
nvmem/qfprom as follows:
[    3.003090] qcom-tsens 4a9000.thermal-sensor: version: 1.4
[    3.005376] qcom-tsens 4a9000.thermal-sensor: tsens calibration failed
[    3.113248] qcom-tsens 4a9000.thermal-sensor: version: 1.4

This confuses people when, in fact, calibration succeeds later when
nvmem/qfprom device is available. Don't print this message on a
-EPROBE_DEFER.

Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
2019-05-14 06:59:16 -07:00
Amit Kucheria 52eafd66ef drivers: thermal: tsens: Save reference to the device pointer and use it
Code cleanup making it easier to read

Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
2019-05-14 06:59:15 -07:00
Amit Kucheria c19970548e drivers: thermal: tsens: Introduce reg_fields to deal with register description
As we add support for newer versions of the TSENS IP, the current
approach isn't scaling because registers and bitfields get moved around,
requiring platform-specific hacks in the code. By moving to regmap, we
can hide the register level differences away from the code.

Define a common set of registers and bit-fields that we care about
across the various tsens IP versions.

Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
2019-05-14 06:59:12 -07:00
Amit Kucheria 582a0c4194 drivers: thermal: tsens: Merge tsens-8974 into tsens-v0_1
8974 and 8916 have the same version of the TSENS IP. Merge the files to
allow for better code reuse.

Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
2019-05-13 20:35:37 -07:00
Amit Kucheria 774ccb0819 drivers: thermal: tsens: Rename constants to prepare to merge with tsens-8974
Some #defines in tsens-v_0_1.c clash with those in tsens-8974.c. Prefix
them with 8916 to avoid the clash so we can merge the two files.

Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
2019-05-13 20:35:36 -07:00
Amit Kucheria 2be2076303 drivers: thermal: tsens: Rename tsens-8916 to prepare to merge with tsens-8974
8916 and 8974 use v0.1.0 of the TSENS IP. Rename tsens-8916 to prepare
it for merging with tsens-8974 in a later commit.

Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
2019-05-13 20:35:36 -07:00
Amit Kucheria 68b3314d7c drivers: thermal: tsens: Function prototypes should have argument names
check_patch complains a lot as follows:

WARNING: function definition argument 'struct tsens_priv *' should also have an identifier name
+       int (*init)(struct tsens_priv *);

Fix it.

Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
2019-05-13 20:35:36 -07:00
Amit Kucheria 2cbcd2eab0 drivers: thermal: tsens: Use consistent names for variables
tsens_get_temp() uses the name 'data' for the void pointer, use the same
in tsens_get_trend() for consistency.

Remove a stray space while we're at it.

Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
2019-05-13 20:35:36 -07:00
Amit Kucheria 69b628ac71 drivers: thermal: tsens: Rename variable tmdev
tmdev seems to imply that this is a device pointer when in fact it is
just private platform data for each tsens device. Rename it to priv
improve code readability.

Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
2019-05-13 20:35:36 -07:00
Amit Kucheria 24ae447291 drivers: thermal: tsens: Rename tsens_device
Rename to tsens_priv to denote that it is private data for each tsens
instance.

Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
2019-05-13 20:35:35 -07:00
Amit Kucheria 3c040ce087 drivers: thermal: tsens: Rename tsens_data
Rename to tsens_plat_data to denote that it is platform-data passed in
at compile-time.

Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
2019-05-13 20:35:35 -07:00
Amit Kucheria 20a7a2db19 drivers: thermal: tsens: Document the data structures
Describe how the TSENS device and the various sensors connected to it
are described in the driver

Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
2019-05-13 20:35:35 -07:00
Wolfram Sang df535485bb thermal: stm32: simplify getting .driver_data
We should get 'driver_data' from 'struct device' directly. Going via
platform_device is an unneeded step back and forth.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Reviewed-by: Simon Horman <horms+renesas@verge.net.au>
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
2019-05-13 20:35:35 -07:00
Enrico Weigelt, metux IT consult 0f54aa5caf drivers: thermal: Kconfig: pedantic cleanups
Formatting of Kconfig files doesn't look so pretty, so just
take damp cloth and clean it up.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
2019-05-13 20:35:34 -07:00
Yangtao Li 7ffd87c63d of: thermal: Improve print information
Define pr_fmt macro to add a prefix to the message,
this can make the thermal log better recognized.

Before:

[    0.602672] nfc: nfc_init: NFC Core ver 0.1
[    0.602828] NET: Registered protocol family 39
[    0.603435] clocksource: Switched to clocksource mct-frc
[    0.746216] failed to build thermal zone cpu-thermal: -22
[    0.746451] NET: Registered protocol family 2

After:

[    0.602804] NET: Registered protocol family 39
[    0.603463] clocksource: Switched to clocksource mct-frc
[    0.746309] thermal_sys: failed to build thermal zone cpu-thermal: -22
[    0.746545] NET: Registered protocol family 2

Signed-off-by: Yangtao Li <tiny.windzz@gmail.com>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
2019-05-13 20:35:34 -07:00
Wei Ni 1dcc242c7c thermal: tegra: enable OC hw throttle
Parse Over Current settings from DT and program them to
generate interrupts. Also enable hw throttling whenever
there are OC events. Log the OC events as debug messages.

Signed-off-by: Wei Ni <wni@nvidia.com>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
2019-05-13 20:35:34 -07:00
Wei Ni 4a04beb1bf thermal: tegra: add support for EDP IRQ
Add support to generate OC (over-current) interrupts to
indicate the OC event and print out alarm messages.

Signed-off-by: Wei Ni <wni@nvidia.com>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
2019-05-13 20:35:34 -07:00
Wei Ni 5c9d6ac231 thermal: tegra: add set_trips functionality
Implement set_trips ops to set passive trip points.

Signed-off-by: Wei Ni <wni@nvidia.com>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
2019-05-13 20:35:33 -07:00
Wei Ni d7180be0d5 thermal: tegra: add support for thermal IRQ
Support to generate an interrupt when the temperature
crosses a programmed threshold and notify the thermal framework.

Signed-off-by: Wei Ni <wni@nvidia.com>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
2019-05-13 20:35:33 -07:00
Wei Ni 6ca29b7e82 thermal: tegra: add support for gpu hw-throttle
Add support to trigger pulse skippers on the GPU
when a HOT trip point is triggered. The pulse skippers
can be signalled to throttle at low, medium and high
depths\levels.

Signed-off-by: Wei Ni <wni@nvidia.com>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
2019-05-13 20:35:33 -07:00
Wei Ni 2510aa56ab thermal: tegra: support hw and sw shutdown
Currently the critical trip points in thermal framework are the only
way to specify a temperature at which HW should shutdown. This is
insufficient for certain platforms which would want an orderly
software shutdown in addition to HW shutdown.

This change support to parse "nvidia, thermtrips" property,
it allows soctherm DT to specify thermtrip temperatures so that
critical trip points framework can be used for doing software
shutdown.

Signed-off-by: Wei Ni <wni@nvidia.com>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
2019-05-13 20:35:32 -07:00
Zhang Rui 2d7c4e1781 Merge branches 'fixes' and 'thermal-intel' into next 2019-03-18 22:37:44 +08:00
Zhang Rui e925b5be57 thermal/intel_powerclamp: fix truncated kthread name
kthread name only allows 15 characters (TASK_COMMON_LEN is 16).
Thus rename the kthreads created by intel_powerclamp driver from
"kidle_inject/ + decimal cpuid" to "kidle_inj/ + decimal cpuid"
to avoid truncated kthead name for cpu 100 and later.

Signed-off-by: Zhang Rui <rui.zhang@intel.com>
2019-03-18 22:26:33 +08:00
Pi-Hsun Shih fb4d83f293 thermal: mtk: Allocate enough space for mtk_thermal.
The mtk_thermal struct contains a 'struct mtk_thermal_bank banks[];',
but the allocation only allocates sizeof(struct mtk_thermal) bytes,
which cause out of bound access with the ->banks[] member. Change it to
a fixed size array instead.

Signed-off-by: Pi-Hsun Shih <pihsun@chromium.org>
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
2019-03-18 22:23:10 +08:00
Matthew Garrett 396ee4d0cd thermal/int340x_thermal: fix mode setting
int3400 only pushes the UUID into the firmware when the mode is flipped
to "enable". The current code only exposes the mode flag if the firmware
supports the PASSIVE_1 UUID, which not all machines do. Remove the
restriction.

Signed-off-by: Matthew Garrett <mjg59@google.com>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
2019-03-18 22:13:21 +08:00
Matthew Garrett 16fc8eca19 thermal/int340x_thermal: Add additional UUIDs
Add more supported DPTF policies than the driver currently exposes.

Signed-off-by: Matthew Garrett <mjg59@google.com>
Cc: Nisha Aram <nisha.aram@intel.com>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
2019-03-18 22:13:21 +08:00
Shaokun Zhang e0fda7377d thermal: cpu_cooling: Remove unused cur_freq variable
The 'cur_freq' local variable became unused after commit 84fe2cab48
("cpu_cooling: Drop static-power related stuff"), let's remove it.

Cc: Amit Daniel Kachhap <amit.kachhap@gmail.com>
Cc: Viresh Kumar <viresh.kumar@linaro.org>
Cc: Javi Merino <javi.merino@kernel.org>
Cc: Zhang Rui <rui.zhang@intel.com>
Cc: Eduardo Valentin <edubezval@gmail.com>
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
Signed-off-by: Shaokun Zhang <zhangshaokun@hisilicon.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
2019-03-18 22:11:06 +08:00
Phil Elwell 35122495a8 thermal: bcm2835: Fix crash in bcm2835_thermal_debugfs
"cat /sys/kernel/debug/bcm2835_thermal/regset" causes a NULL pointer
dereference in bcm2835_thermal_debugfs. The driver makes use of the
implementation details of the thermal framework to retrieve a pointer
to its private data from a struct thermal_zone_device, and gets it
wrong - leading to the crash. Instead, store its private data as the
drvdata and retrieve the thermal_zone_device pointer from it.

Fixes: bcb7dd9ef2 ("thermal: bcm2835: add thermal driver for bcm2835 SoC")

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
2019-03-18 22:11:06 +08:00
Marek Szyprowski 3b5236cc5d thermal: samsung: Fix incorrect check after code merge
Merge commit 19785cf93b ("Merge branch 'linus' of
git://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux-soc-thermal")
broke the code introduced by commit ffe6e16f14 ("thermal: exynos: Reduce
severity of too early temperature read"). Restore the original code from
the mentioned commit to finally fix the warning message during boot:

thermal thermal_zone0: failed to read out thermal zone (-22)

Reported-by: Marian Mihailescu <mihailescu2m@gmail.com>
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Fixes: 19785cf93b ("Merge branch 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux-soc-thermal")
Reviewed-by: Krzysztof Kozlowski <krzk@kernel.org>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
2019-03-18 22:11:06 +08:00
Luc Van Oostenryck aa36e36165 thermal/intel_powerclamp: fix __percpu declaration of worker_data
This variable is declared as:
	static struct powerclamp_worker_data * __percpu worker_data;
In other words, a percpu pointer to struct ...

But this variable not used like so but as a pointer to a percpu
struct powerclamp_worker_data.

So fix the declaration as:
	static struct powerclamp_worker_data __percpu *worker_data;

This also quiets Sparse's warnings from __verify_pcpu_ptr(), like:
  494:49: warning: incorrect type in initializer (different address spaces)
  494:49:    expected void const [noderef] <asn:3> *__vpp_verify
  494:49:    got struct powerclamp_worker_data *

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
2019-03-18 22:11:06 +08:00
Linus Torvalds 9f24a81e2e Merge branch 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux-soc-thermal
Pull thermal soc updates from Eduardo Valentin:
 "Specifics:

   - mediatek thermal now supports MT8183

   - broadcom thermal now supports Stingray

   - qoirq now supports multiple sensors

   - fixes on different drivers: rcar, tsens, tegra

  Some new drivers are still pending further review and I chose to leave
  them for the next merge window while still sending this material"

* 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux-soc-thermal:
  thermal: rcar_gen3_thermal: Register hwmon sysfs interface
  thermal/qcom/tsens-common : fix possible object reference leak
  thermal: tegra: add get_trend ops
  thermal: tegra: fix memory allocation
  thermal: tegra: remove unnecessary warnings
  thermal: mediatek: add support for MT8183
  dt-bindings: thermal: add binding document for mt8183 thermal controller
  thermal: mediatek: add flag for bank selection
  thermal: mediatek: add thermal controller offset
  thermal: mediatek: add calibration item
  thermal: mediatek: add common index of vts settings.
  thermal: mediatek: fix register index error
  thermal: qoriq: add multiple sensors support
  thermal: broadcom: Add Stingray thermal driver
  dt-bindings: thermal: Add binding document for SR thermal
2019-03-08 09:52:41 -08:00
Rafael J. Wysocki 17162a117c Merge back earlier cpufreq material for v5.1. 2019-02-24 21:18:05 +01:00
Marek Vasut 6269e9f790 thermal: rcar_gen3_thermal: Register hwmon sysfs interface
Register the hwmon sysfs interface on R-Car Gen3 thermal driver to
align it with Gen2 driver. Use devm_add_action() to unregister the
hwmon interface automatically.

Cc: Eduardo Valentin <edubezval@gmail.com>
Cc: Wolfram Sang <wsa+renesas@sang-engineering.com>
Cc: linux-renesas-soc@vger.kernel.org
To: linux-pm@vger.kernel.org
From: Marek Vasut <marek.vasut+renesas@gmail.com>
Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
2019-02-20 17:23:40 -08:00
Peng Hao a245b62be3 thermal/qcom/tsens-common : fix possible object reference leak
of_find_device_by_node() takes a reference to the struct device
when it finds a match via get_device.
We also should make sure to drop the reference to the device
taken by of_find_device_by_node() when returning error.

Signed-off-by: Peng Hao <peng.hao2@zte.com.cn>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
2019-02-20 17:23:39 -08:00
Wei Ni 76b1ae8698 thermal: tegra: add get_trend ops
Add support for get_trend ops that allows soctherm
sensors to be used with the step-wise governor.

Signed-off-by: Wei Ni <wni@nvidia.com>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
2019-02-20 17:23:38 -08:00
Wei Ni 3d88adf3ef thermal: tegra: fix memory allocation
Fix memory allocation to store the pointers to
thermal_zone_device.

Signed-off-by: Wei Ni <wni@nvidia.com>
Acked-by: Thierry Reding <treding@nvidia.com>
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
2019-02-20 17:23:37 -08:00
Wei Ni cd28561dce thermal: tegra: remove unnecessary warnings
Convert warnings to info as not all platforms may
have all the thresholds and sensors enabled.

Signed-off-by: Wei Ni <wni@nvidia.com>
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
2019-02-20 17:23:37 -08:00
Michael Kao a4ffe6b52d thermal: mediatek: add support for MT8183
MT8183 has two built-in thermal controllers with total six thermal
sensors. And it doesn't have bank, so doesn't need to select bank.
This patch adds support for mt8183.

Signed-off-by: Michael Kao <michael.kao@mediatek.com>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
2019-02-20 17:23:33 -08:00
Michael Kao cb82aaade9 thermal: mediatek: add flag for bank selection
For past ic designs, the thermal controller should select banks before
reading the thermal sensor.
And the new ic design architecture removes this mechanism.

Signed-off-by: Michael Kao <michael.kao@mediatek.com>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
2019-02-05 17:01:47 -08:00
Michael Kao bd9403943d thermal: mediatek: add thermal controller offset
One thermal controller can read four sensors at most,
so we need to add controller_offset for the project with
more than four sensors to reuse the same register settings.

Signed-off-by: Michael Kao <michael.kao@mediatek.com>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
2019-02-05 17:01:46 -08:00
Michael Kao f845147669 thermal: mediatek: add calibration item
Add calibration item in thermal_data to support
the project with different calibration coefficient.

Signed-off-by: Michael Kao <michael.kao@mediatek.com>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
2019-02-05 17:01:45 -08:00
Michael Kao 1d0819455e thermal: mediatek: add common index of vts settings.
Each project has different number of vts settings.
For the MT2701 just have to set three vts, but the
original code flow add five unnecessary vts.
Add common index of vts settings for scalablity,
and reduce the setting of unnecessary vts.

Signed-off-by: Michael Kao <michael.kao@mediatek.com>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
2019-02-05 17:01:44 -08:00
Michael Kao eb9aecd90d thermal: mediatek: fix register index error
The index of msr and adcpnp should match the sensor
which belongs to the selected bank in the for loop.

Fixes: b7cf005373 ("thermal: Add Mediatek thermal driver for mt2701.")
Signed-off-by: Michael Kao <michael.kao@mediatek.com>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
2019-02-05 17:01:35 -08:00