thermal: max77851: Fix build for pre-Linux v6.1 kernels

The max77851 driver is failing to build for Linux kernels v5.16 to v6.0
and the following error is seen ...

 drivers/thermal/max77851_thermal.c:173:30: error: implicit declaration
 of function 'devm_thermal_of_zone_register'; did you mean
 'devm_thermal_zone_of_sensor_register'?
 [-Werror=implicit-function-declaration]
   thermal->tz_device = devm_thermal_of_zone_register(&pdev->dev, 0,
                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The function devm_thermal_of_zone_register() was introduced in Linux
kernel v6.1 and not v5.16.

Instead of relying on kernel version to determine if this function is
present using the conftest.sh script which checks the kernel that is
being compiled to see if this function is present or not. This is also
beneficial for working with 3rd party Linux kernels that may have
back-ported upstream changes into their kernel and so the kernel version
checks do not work either.

Bug 200749982

Change-Id: I8d5e70d2d39497d7f513c82cd3a45312b2bc016a
Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/2980925
This commit is contained in:
Jon Hunter
2023-09-18 14:33:18 +01:00
committed by mobile promotions
parent f6227e9c57
commit ed3fdebc33
3 changed files with 32 additions and 14 deletions

View File

@@ -4,6 +4,8 @@
* Junction temperature thermal driver for Maxim Max77851.
*/
#include <nvidia/conftest.h>
#include <linux/irq.h>
#include <linux/interrupt.h>
#include <linux/mfd/max77851.h>
@@ -13,7 +15,6 @@
#include <linux/regmap.h>
#include <linux/slab.h>
#include <linux/thermal.h>
#include <linux/version.h>
#include <linux/of_device.h>
@@ -43,16 +44,16 @@ struct max77851_therm_info {
int irq_tjalarm2;
};
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 16, 0)
static int max77851_thermal_read_temp(void *data, int *temp)
#else
#if defined(NV_DEVM_THERMAL_OF_ZONE_REGISTER_PRESENT)
static int max77851_thermal_read_temp(struct thermal_zone_device *data, int *temp)
#else
static int max77851_thermal_read_temp(void *data, int *temp)
#endif
{
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 16, 0)
struct max77851_therm_info *thermal = data;
#else
#if defined(NV_DEVM_THERMAL_OF_ZONE_REGISTER_PRESENT)
struct max77851_therm_info *thermal = data->devdata;
#else
struct max77851_therm_info *thermal = data;
#endif
unsigned int val;
int ret;
@@ -74,10 +75,10 @@ static int max77851_thermal_read_temp(struct thermal_zone_device *data, int *tem
return 0;
}
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 16, 0)
static const struct thermal_zone_of_device_ops max77851_thermal_ops = {
#else
#if defined(NV_DEVM_THERMAL_OF_ZONE_REGISTER_PRESENT)
static const struct thermal_zone_device_ops max77851_thermal_ops = {
#else
static const struct thermal_zone_of_device_ops max77851_thermal_ops = {
#endif
.get_temp = max77851_thermal_read_temp,
};
@@ -166,11 +167,11 @@ static int max77851_thermal_probe(struct platform_device *pdev)
max77851_thermal_init(thermal);
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 16, 0)
thermal->tz_device = devm_thermal_zone_of_sensor_register(&pdev->dev, 0,
#if defined(NV_DEVM_THERMAL_OF_ZONE_REGISTER_PRESENT)
thermal->tz_device = devm_thermal_of_zone_register(&pdev->dev, 0,
thermal, &max77851_thermal_ops);
#else
thermal->tz_device = devm_thermal_of_zone_register(&pdev->dev, 0,
thermal->tz_device = devm_thermal_zone_of_sensor_register(&pdev->dev, 0,
thermal, &max77851_thermal_ops);
#endif
if (IS_ERR(thermal->tz_device)) {

View File

@@ -88,7 +88,7 @@ endef
# provided by the module-specific Kbuild files.
#
NV_CONFTEST_FUNCTION_COMPILE_TESTS ?=
NV_CONFTEST_FUNCTION_COMPILE_TESTS += devm_thermal_of_zone_register
NV_CONFTEST_GENERIC_COMPILE_TESTS ?=
NV_CONFTEST_MACRO_COMPILE_TESTS ?=
NV_CONFTEST_SYMBOL_COMPILE_TESTS ?=

View File

@@ -6293,6 +6293,23 @@ compile_test() {
compile_check_conftest "$CODE" "NV_CRYPTO_PRESENT" "" "symbols"
;;
devm_thermal_of_zone_register)
#
# Determine whether devm_thermal_of_zone_register is present.
#
# devm_thermal_of_zone_register was added in commit 3fd6d6e2b4e8
# ("thermal/of: Rework the thermal device tree initialization") in
# v6.1 (2022-08-17)
#
CODE="
#include <linux/thermal.h>
void conftest_devm_thermal_of_zone_register(void) {
devm_thermal_of_zone_register();
}"
compile_check_conftest "$CODE" "NV_DEVM_THERMAL_OF_ZONE_REGISTER_PRESENT" "" "functions"
;;
# When adding a new conftest entry, please use the correct format for
# specifying the relevant upstream Linux kernel commit.
#