public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v11 0/6] Add LVTS thermal architecture
@ 2023-01-24 13:17 bchihi
  2023-01-24 13:17 ` [PATCH v11 1/6] thermal/drivers/mediatek: Relocate driver to mediatek folder bchihi
                   ` (5 more replies)
  0 siblings, 6 replies; 59+ messages in thread
From: bchihi @ 2023-01-24 13:17 UTC (permalink / raw)
  To: daniel.lezcano, angelogioacchino.delregno, rafael, amitk,
	rui.zhang, matthias.bgg, robh+dt, krzysztof.kozlowski+dt, rdunlap,
	ye.xingchen, p.zabel
  Cc: linux-pm, linux-kernel, linux-arm-kernel, linux-mediatek,
	devicetree, khilman, james.lo, rex-bc.chen

From: Balsam CHIHI <bchihi@baylibre.com>

The LVTS (Low Voltage Thermal Sensor) driver is capable of monitoring
multiple hot points. For that, it contains 7 thermal control blocks
dedicated to specific devices on the die. Each control block can handle
up to 4 sensors. 

The thermal controller supports several interrupts. One for the cold
trip point, the hot trip point, the return to the normal trip point,
and a specific programmable trip point to monitor the temperature
dynamically.

The temperature measurement can be done in two ways, the immediate mode
where the temperature read is instantaneous and the filtered mode where
the controller uses, by configuration, an average of a set of values
removing the minimum and the maximum.

Finally, it is composed of 2 finite-state machines responsible for
the state of the temperature (cold, hot, hot 2 normal, hot hot),
the triggering of the interrupts, and the monitoring of the temperature.

As requested, the thermal driver has been reworked to reduce
the complexity of the code. At this time, the 4 little CPUs and
the 4 big CPUs are supported by the thermal driver.They are described
in a data structure and more devices can be added later.
The calibration routine has been simplified also.

The series provide the following changes:
 - Move the Mediatek drivers inside a dedicated folder as their number
   is increasing
 - Add the DT bindings for the controller
 - Add the efuse node for the mt8195
 - The LVTS driver
 - The thermal zones description in the DT

Changelog:
  v11:
     - Rebase on top of "thermal/linux-next" :
       base=0d568e144ead70189e7f16066dcb155b78ff9266
     - Remove unsupported SoC (mt8192) from dt-binding definition
     - Fix coding style issues :
       - Move litterals to define
       - Add interrupt macros
       - Remove wildcard : only mt8195 is supported for now

  v10:
     - Rebase on top of "thermal/linux-next" : thermal-v6.3-rc1
     - Rework the LVTS driver
     - Add the thermal trip temperature and cooling devices
       for the sensors supported by the driver

  v9:
     - Rebase on top of 6.0.0-rc1
     - Fix coding style issues
     - Fix commit titles and commit messages
     - Update dt-bindings :
     - Add "allOf:if:then:"
     - Use mt8192 as example (instead of mt8195)
     - Fix dt-binding errors
     - Fix DTS errors

  v8:
     - Fix coding style issues
     - Rebase on top of next-20220803
     - Add multi-instance support :
       - Rewrite DT-binding and DTS :
         - Add DT-binding and DTS for LVTS_v4 (MT8192 and MT8195)
           - One LVTS node for each HW Domain (AP and MCU)
         - One SW Instance for each HW Domain
         - Add a Kconfig sub-menu entry for LVTS and LVTS_v4 SoCs
     - Replace platform_get_resource by platform_get_mem_or_io to get
       Base Address
     - Replace platform_get_resource by platform_get_irq to get
       Interrupt Number
     - Add "lvts_" prefix to functions and structs

 v7:
     - Fix coding style issues
     - Rewrite dt bindings
       - was not accurate
       - Use mt8195 for example (instead of mt8192)
       - Rename mt6873 to mt8192
       - Remove clock name
     - Rebased on top of to series:
       - patchwork.kernel.org/project/linux-mediatek/list/?series=637849
       - patchwork.kernel.org/project/linux-pm/list/?series=639386

 v6:
     - Remove temperature aggregation (it will be added in another
       series)
     - Update the way to read the temperature (read one sensor
       instead of all)
     - Add support of mt8195

  v5:
     - Use 'git mv' for the relocated file.

  v4:
     - Rebase to kernel-v5.13-rc1

  v3:
     - change the expression in the lvts_temp_to_raw to dev_s64.

  v2:
     - Rebase to kernel-5.11-rc1.
     - sort headers
     - remove initial value 0 of msr_raw in the lvts_temp_to_raw.
     - disconstruct the api of lvts_read_tc_msr_raw.
     - add the initial value max_temp = 0 and compare e.q.
       in the lvts_read_all_tc_temperature.
     - add the return with an invalid number in the lvts_init.

Balsam CHIHI (6):
  thermal/drivers/mediatek: Relocate driver to mediatek folder
  dt-bindings/thermal/mediatek: Add LVTS thermal controllers dt-binding
    definition
  arm64/dts/mt8195: Add efuse node to mt8195
  thermal/drivers/mediatek: Add the Low Voltage Thermal Sensor driver
  arm64/dts/mt8195: Add thermal zones and thermal nodes
  arm64/dts/mt8195: Add temperature mitigation threshold

 .../thermal/mediatek,lvts-thermal.yaml        |  107 ++
 arch/arm64/boot/dts/mediatek/mt8195.dtsi      |  272 ++++
 drivers/thermal/Kconfig                       |   14 +-
 drivers/thermal/Makefile                      |    2 +-
 drivers/thermal/mediatek/Kconfig              |   36 +
 drivers/thermal/mediatek/Makefile             |    2 +
 .../auxadc_thermal.c}                         |    2 +-
 drivers/thermal/mediatek/lvts_thermal.c       | 1261 +++++++++++++++++
 include/dt-bindings/thermal/mediatek-lvts.h   |   19 +
 9 files changed, 1703 insertions(+), 12 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/thermal/mediatek,lvts-thermal.yaml
 create mode 100644 drivers/thermal/mediatek/Kconfig
 create mode 100644 drivers/thermal/mediatek/Makefile
 rename drivers/thermal/{mtk_thermal.c => mediatek/auxadc_thermal.c} (99%)
 create mode 100644 drivers/thermal/mediatek/lvts_thermal.c
 create mode 100644 include/dt-bindings/thermal/mediatek-lvts.h


base-commit: 0d568e144ead70189e7f16066dcb155b78ff9266
-- 
2.34.1


^ permalink raw reply	[flat|nested] 59+ messages in thread
* [PATCH] thermal/drivers/mediatek/lvts_thermal: fix memcpy's number of bytes in lvts_calibration_init()
@ 2023-03-07 13:51 bchihi
  2023-03-08 15:55 ` Balsam CHIHI
  0 siblings, 1 reply; 59+ messages in thread
From: bchihi @ 2023-03-07 13:51 UTC (permalink / raw)
  To: daniel.lezcano, angelogioacchino.delregno, rafael, amitk,
	rui.zhang, matthias.bgg, robh+dt, krzysztof.kozlowski+dt, rdunlap,
	ye.xingchen, p.zabel
  Cc: linux-pm, linux-kernel, linux-arm-kernel, linux-mediatek,
	devicetree, khilman, james.lo, rex-bc.chen, error27

From: Balsam CHIHI <bchihi@baylibre.com>

Replace memcpy 2 bytes by sizeof(int) bytes of LVTS calibration data.

Reported-by: Dan Carpenter <error27@gmail.com>
Signed-off-by: Balsam CHIHI <bchihi@baylibre.com>
---
Rebased on top of thermal/linux-next
base-commit: 6828e402d06f7c574430b61c05db784cd847b19f

Original email :
Hello Balsam CHIHI,

The patch f5f633b18234: "thermal/drivers/mediatek: Add the Low
Voltage Thermal Sensor driver" from Feb 9, 2023, leads to the
following Smatch static checker warning:

        drivers/thermal/mediatek/lvts_thermal.c:562 lvts_calibration_init()
        warn: not copying enough bytes for '&lvts_ctrl->calibration[i]' (4 vs 2 bytes)

drivers/thermal/mediatek/lvts_thermal.c
    555 static int lvts_calibration_init(struct device *dev, struct lvts_ctrl *lvts_ctrl,
    556                                         const struct lvts_ctrl_data *lvts_ctrl_data,
    557                                         u8 *efuse_calibration)
    558 {
    559         int i;
    560
    561         for (i = 0; i < lvts_ctrl_data->num_lvts_sensor; i++)
--> 562                 memcpy(&lvts_ctrl->calibration[i],
    563                        efuse_calibration + lvts_ctrl_data->cal_offset[i], 2);
                                                                                  ^
This is copying an array of known ints to a u32 array.  It should copy
sizeof(int) instead of 2.  It only works because the data you're on
little endian and the data is small.

    564
    565         return 0;
    566 }

regards,
dan carpenter
---
---
 drivers/thermal/mediatek/lvts_thermal.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c
index ddfdcbcf6d86..b505c6b49031 100644
--- a/drivers/thermal/mediatek/lvts_thermal.c
+++ b/drivers/thermal/mediatek/lvts_thermal.c
@@ -575,7 +575,7 @@ static int lvts_calibration_init(struct device *dev, struct lvts_ctrl *lvts_ctrl
 
 	for (i = 0; i < lvts_ctrl_data->num_lvts_sensor; i++)
 		memcpy(&lvts_ctrl->calibration[i],
-		       efuse_calibration + lvts_ctrl_data->cal_offset[i], 2);
+		       efuse_calibration + lvts_ctrl_data->cal_offset[i], sizeof(int));
 
 	return 0;
 }

base-commit: 6828e402d06f7c574430b61c05db784cd847b19f
prerequisite-patch-id: 73be949bd16979769e5b94905b244dcee4a8f687
prerequisite-patch-id: d23d83a946e5b876ef01a717fd51b07df1fa08dd
prerequisite-patch-id: d67f2455eef1c4a9ecc460dbf3c2e3ad47d213ec
prerequisite-patch-id: 9076e9b3bd3cc411b7b80344211364db5f0cca17
prerequisite-patch-id: e220d6ae26786f524c249588433f02e5f5f906ad
prerequisite-patch-id: b407d2998e57678952128b3a4bac92a379132b09
prerequisite-patch-id: fbb9212ce8c3530da17d213f56fa334ce4fa1b2b
prerequisite-patch-id: 5db9eed2659028cf4419f2de3d093af7df6c2dad
prerequisite-patch-id: a83c00c628605d1c8fbe1d97074f9f28efb1bcfc
prerequisite-patch-id: 56a245620a4f8238cf1ba3844dc348de3db33845
prerequisite-patch-id: 7df24b0bf11129ddd3356eacf192cc3fdb2bcded
prerequisite-patch-id: 3213ca70cb5b26d54a7137ff40ca8cd2a795c414
prerequisite-patch-id: 6c2202e85215d1c7e8ab16a6b85922e994c68d9b
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 59+ messages in thread

end of thread, other threads:[~2023-03-09 12:37 UTC | newest]

Thread overview: 59+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-24 13:17 [PATCH v11 0/6] Add LVTS thermal architecture bchihi
2023-01-24 13:17 ` [PATCH v11 1/6] thermal/drivers/mediatek: Relocate driver to mediatek folder bchihi
2023-01-24 15:37   ` AngeloGioacchino Del Regno
2023-01-25 15:02     ` Balsam CHIHI
2023-01-24 13:17 ` [PATCH v11 2/6] dt-bindings/thermal/mediatek: Add LVTS thermal controllers dt-binding definition bchihi
2023-01-25 11:14   ` Daniel Lezcano
2023-01-25 20:35     ` Rob Herring
2023-01-25 21:13       ` Daniel Lezcano
2023-01-25 20:34   ` Rob Herring
2023-01-26 10:33     ` Balsam CHIHI
2023-01-26 16:10   ` [PATCH v12 2/6] dt-bindings: thermal: mediatek: " bchihi
2023-01-27 22:10     ` Daniel Lezcano
2023-01-28 10:50       ` Krzysztof Kozlowski
2023-01-30 10:49         ` Balsam CHIHI
2023-01-28 10:48     ` Krzysztof Kozlowski
2023-01-30 10:40       ` Balsam CHIHI
2023-01-30 11:18         ` Matthias Brugger
2023-01-30 12:19           ` Balsam CHIHI
2023-01-30 16:07             ` Matthias Brugger
2023-01-31 16:53         ` Krzysztof Kozlowski
2023-01-31 17:01           ` Daniel Lezcano
2023-01-31 14:04     ` [PATCH v3] dt-bindings: thermal: mediatek: Add LVTS thermal controllers bchihi
2023-02-01  7:46       ` Krzysztof Kozlowski
2023-02-01 13:34         ` Balsam CHIHI
2023-02-01 13:37           ` Krzysztof Kozlowski
2023-02-01 13:56             ` Balsam CHIHI
2023-03-07 13:42     ` [PATCH] thermal/drivers/mediatek/lvts_thermal: fix memcpy's number of bytes in lvts_calibration_init() bchihi
2023-03-08  9:10       ` AngeloGioacchino Del Regno
2023-03-09 12:37         ` Dan Carpenter
2023-01-24 13:17 ` [PATCH v11 3/6] arm64/dts/mt8195: Add efuse node to mt8195 bchihi
2023-01-25 14:25   ` Matthias Brugger
2023-01-25 15:04     ` Balsam CHIHI
2023-01-24 13:17 ` [PATCH v11 4/6] thermal/drivers/mediatek: Add the Low Voltage Thermal Sensor driver bchihi
2023-01-24 15:31   ` AngeloGioacchino Del Regno
2023-01-25 15:06     ` Balsam CHIHI
2023-01-31 15:38   ` [PATCH v12] thermal: drivers: mediatek: " bchihi
2023-02-01  3:09     ` kernel test robot
2023-02-01  7:47       ` Krzysztof Kozlowski
2023-02-01 15:14         ` Balsam CHIHI
2023-02-01  7:55     ` Krzysztof Kozlowski
2023-02-01 16:46       ` Balsam CHIHI
2023-02-01 16:59         ` Matthias Brugger
2023-02-03 10:35           ` Balsam CHIHI
2023-02-01 17:12         ` Krzysztof Kozlowski
2023-02-03 11:06           ` Balsam CHIHI
2023-02-06 14:07       ` Daniel Lezcano
2023-02-06 14:30         ` Krzysztof Kozlowski
2023-02-06 14:38           ` Daniel Lezcano
2023-02-06 14:32         ` Balsam CHIHI
2023-01-24 13:17 ` [PATCH v11 5/6] arm64/dts/mt8195: Add thermal zones and thermal nodes bchihi
2023-01-24 15:36   ` AngeloGioacchino Del Regno
2023-01-25 15:10     ` Balsam CHIHI
2023-01-25 19:09       ` Matthias Brugger
2023-01-26  9:43         ` Balsam CHIHI
2023-01-31 15:37   ` [PATCH v12] arm64: dts: mediatek: mt8195: " bchihi
2023-01-24 13:17 ` [PATCH v11 6/6] arm64/dts/mt8195: Add temperature mitigation threshold bchihi
2023-01-24 15:36   ` AngeloGioacchino Del Regno
  -- strict thread matches above, loose matches on Subject: below --
2023-03-07 13:51 [PATCH] thermal/drivers/mediatek/lvts_thermal: fix memcpy's number of bytes in lvts_calibration_init() bchihi
2023-03-08 15:55 ` Balsam CHIHI

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox