1 // SPDX-License-Identifier: LGPL-2.1+
2 // Copyright (C) 2022, Linaro Ltd - Daniel Lezcano <daniel.lezcano@linaro.org>
9 #include "thermal_nl.h"
11 static int handle_thermal_sample(struct nl_msg
*n
, void *arg
)
13 struct nlmsghdr
*nlh
= nlmsg_hdr(n
);
14 struct genlmsghdr
*genlhdr
= genlmsg_hdr(nlh
);
15 struct nlattr
*attrs
[THERMAL_GENL_ATTR_MAX
+ 1];
16 struct thermal_handler_param
*thp
= arg
;
17 struct thermal_handler
*th
= thp
->th
;
21 genlmsg_parse(nlh
, 0, attrs
, THERMAL_GENL_ATTR_MAX
, NULL
);
23 switch (genlhdr
->cmd
) {
25 case THERMAL_GENL_SAMPLING_TEMP
:
26 return th
->ops
->sampling
.tz_temp(
27 nla_get_u32(attrs
[THERMAL_GENL_ATTR_TZ_ID
]),
28 nla_get_u32(attrs
[THERMAL_GENL_ATTR_TZ_TEMP
]), arg
);
34 thermal_error_t
thermal_sampling_handle(struct thermal_handler
*th
, void *arg
)
36 struct thermal_handler_param thp
= { .th
= th
, .arg
= arg
};
41 if (nl_cb_set(th
->cb_sampling
, NL_CB_VALID
, NL_CB_CUSTOM
,
42 handle_thermal_sample
, &thp
))
45 return nl_recvmsgs(th
->sk_sampling
, th
->cb_sampling
);
48 int thermal_sampling_fd(struct thermal_handler
*th
)
53 return nl_socket_get_fd(th
->sk_sampling
);
56 thermal_error_t
thermal_sampling_exit(struct thermal_handler
*th
)
58 if (nl_unsubscribe_thermal(th
->sk_sampling
, th
->cb_sampling
,
59 THERMAL_GENL_SAMPLING_GROUP_NAME
))
62 nl_thermal_disconnect(th
->sk_sampling
, th
->cb_sampling
);
64 return THERMAL_SUCCESS
;
67 thermal_error_t
thermal_sampling_init(struct thermal_handler
*th
)
69 if (nl_thermal_connect(&th
->sk_sampling
, &th
->cb_sampling
))
72 if (nl_subscribe_thermal(th
->sk_sampling
, th
->cb_sampling
,
73 THERMAL_GENL_SAMPLING_GROUP_NAME
))
76 return THERMAL_SUCCESS
;