diff options
author | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2022-05-19 19:15:34 +0200 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2022-05-19 19:15:34 +0200 |
commit | c23b7517fe623d5812436682937a79ca0cc4cd39 (patch) | |
tree | f52f54e6a9f61818c8f32669e73280b8de04aa8f /tools/lib/thermal/sampling.c | |
parent | 7b145802ba545ecf9446ce6d67d6011b73dac0e0 (diff) | |
parent | ffcb2fc86eb7ebc9f5524525fb57e1cccfbd1fc0 (diff) |
Merge tag 'thermal-v5.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux
Pull thermal control material for 5.19-rc1 from Daniel Lezcano:
- Add the new k3 j72xx bangdap driver and the corresponding bindings (Keerthy)
- Fix the missing of_node_put() in the SC iMX driver at probe timer (Miaoqian Lin)
- Fix memory leak in __thermal_cooling_device_register() when device_register()
fails by calling thermal_cooling_device_destroy_sysfs() (Yang Yingliang)
- Add sc8180x and sc8280xp compatible string in the DT bindings and lMH support
for QCom tsens driver (Bjorn Andersson)
- Fix OTP Calibration Register values conforming to the documentation on RZ/G2L
and bindings documentation for RZ/G2UL (Biju Das)
- Fix type in kerneldoc description for __thermal_bind_params (Corentin Labbe)
- Remove unneeded semi colon in libthermal and tools thermal as reported by
cocci (Jiapeng Chong)
- Fix potential NULL dereference in sr_thermal_probe() on Broadcom platform
(Zheng Yongjun)
- Add thermal library and thermal tools to encapsulate the netlink into event
based callbacks (Daniel Lezcano)
- Add change mode ops for the thermal-of sensor (Manaf Meethalavalappu
Pallikunhi)
- Fix non negative value support by preventing the value to be clamp to zero
(Stefan Wahren)
- Add compatible string and DT bindings for MSM8960 tsens driver (Dmitry
Baryshkov)
- Add hwmon support for K3 driver (Massimiliano Minella)
- Refactor and add multiple generations support for QCom ADC driver (Jishnu
Prakash)
- Use platform_get_irq_optional() to get the interrupt on RCar driver and
document Document RZ/V2L bindings (Lad Prabhakar)
* tag 'thermal-v5.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux: (28 commits)
thermal: k3_j72xx_bandgap: Add the bandgap driver support
dt-bindings: thermal: k3-j72xx: Add VTM bindings documentation
thermal/drivers/imx_sc_thermal: Fix refcount leak in imx_sc_thermal_probe
thermal/core: Fix memory leak in __thermal_cooling_device_register()
dt-bindings: thermal: tsens: Add sc8280xp compatible
dt-bindings: thermal: lmh: Add Qualcomm sc8180x compatible
thermal/drivers/qcom/lmh: Add sc8180x compatible
thermal/drivers/rz2gl: Fix OTP Calibration Register values
dt-bindings: thermal: rzg2l-thermal: Document RZ/G2UL bindings
thermal: thermal_of: fix typo on __thermal_bind_params
tools/thermal: remove unneeded semicolon
tools/lib/thermal: remove unneeded semicolon
thermal/drivers/broadcom: Fix potential NULL dereference in sr_thermal_probe
tools/thermal: Add thermal daemon skeleton
tools/thermal: Add a temperature capture tool
tools/thermal: Add util library
tools/lib/thermal: Add a thermal library
thermal/drivers/thermal_of: Add change_mode ops support for thermal_of sensor
thermal/drivers/bcm2711: Don't clamp temperature at zero
thermal/drivers/tsens: Add compat string for the qcom,msm8960
...
Diffstat (limited to 'tools/lib/thermal/sampling.c')
-rw-r--r-- | tools/lib/thermal/sampling.c | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/tools/lib/thermal/sampling.c b/tools/lib/thermal/sampling.c new file mode 100644 index 000000000000..ee818f4e9654 --- /dev/null +++ b/tools/lib/thermal/sampling.c @@ -0,0 +1,75 @@ +// SPDX-License-Identifier: LGPL-2.1+ +// Copyright (C) 2022, Linaro Ltd - Daniel Lezcano <daniel.lezcano@linaro.org> +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +#include <thermal.h> +#include "thermal_nl.h" + +static int handle_thermal_sample(struct nl_msg *n, void *arg) +{ + struct nlmsghdr *nlh = nlmsg_hdr(n); + struct genlmsghdr *genlhdr = genlmsg_hdr(nlh); + struct nlattr *attrs[THERMAL_GENL_ATTR_MAX + 1]; + struct thermal_handler_param *thp = arg; + struct thermal_handler *th = thp->th; + + genlmsg_parse(nlh, 0, attrs, THERMAL_GENL_ATTR_MAX, NULL); + + switch (genlhdr->cmd) { + + case THERMAL_GENL_SAMPLING_TEMP: + return th->ops->sampling.tz_temp( + nla_get_u32(attrs[THERMAL_GENL_ATTR_TZ_ID]), + nla_get_u32(attrs[THERMAL_GENL_ATTR_TZ_TEMP]), arg); + default: + return THERMAL_ERROR; + } +} + +thermal_error_t thermal_sampling_handle(struct thermal_handler *th, void *arg) +{ + struct thermal_handler_param thp = { .th = th, .arg = arg }; + + if (!th) + return THERMAL_ERROR; + + if (nl_cb_set(th->cb_sampling, NL_CB_VALID, NL_CB_CUSTOM, + handle_thermal_sample, &thp)) + return THERMAL_ERROR; + + return nl_recvmsgs(th->sk_sampling, th->cb_sampling); +} + +int thermal_sampling_fd(struct thermal_handler *th) +{ + if (!th) + return -1; + + return nl_socket_get_fd(th->sk_sampling); +} + +thermal_error_t thermal_sampling_exit(struct thermal_handler *th) +{ + if (nl_unsubscribe_thermal(th->sk_sampling, th->cb_sampling, + THERMAL_GENL_EVENT_GROUP_NAME)) + return THERMAL_ERROR; + + nl_thermal_disconnect(th->sk_sampling, th->cb_sampling); + + return THERMAL_SUCCESS; +} + +thermal_error_t thermal_sampling_init(struct thermal_handler *th) +{ + if (nl_thermal_connect(&th->sk_sampling, &th->cb_sampling)) + return THERMAL_ERROR; + + if (nl_subscribe_thermal(th->sk_sampling, th->cb_sampling, + THERMAL_GENL_SAMPLING_GROUP_NAME)) + return THERMAL_ERROR; + + return THERMAL_SUCCESS; +} |