xref: /linux/drivers/platform/x86/lenovo/wmi-capdata.h (revision c17ee635fd3a482b2ad2bf5e269755c2eae5f25e)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 /* Copyright (C) 2025 Derek J. Clark <derekjohn.clark@gmail.com> */
4 
5 #ifndef _LENOVO_WMI_CAPDATA_H_
6 #define _LENOVO_WMI_CAPDATA_H_
7 
8 #include <linux/bits.h>
9 #include <linux/types.h>
10 
11 #define LWMI_SUPP_VALID		BIT(0)
12 #define LWMI_SUPP_GET		BIT(1)
13 #define LWMI_SUPP_SET		BIT(2)
14 
15 #define LWMI_ATTR_DEV_ID_MASK	GENMASK(31, 24)
16 #define LWMI_ATTR_FEAT_ID_MASK	GENMASK(23, 16)
17 #define LWMI_ATTR_MODE_ID_MASK	GENMASK(15, 8)
18 #define LWMI_ATTR_TYPE_ID_MASK	GENMASK(7, 0)
19 
20 #define LWMI_DEVICE_ID_FAN	0x04
21 
22 struct component_match;
23 struct device;
24 struct cd_list;
25 
26 struct capdata00 {
27 	u32 id;
28 	u32 supported;
29 	u32 default_value;
30 };
31 
32 struct capdata01 {
33 	u32 id;
34 	u32 supported;
35 	u32 default_value;
36 	u32 step;
37 	u32 min_value;
38 	u32 max_value;
39 };
40 
41 struct capdata_fan {
42 	u32 id;
43 	u32 min_rpm;
44 	u32 max_rpm;
45 };
46 
47 typedef void (*cd_list_cb_t)(struct device *master_dev, struct cd_list *cd_list);
48 
49 struct lwmi_cd_binder {
50 	struct cd_list *cd00_list;
51 	struct cd_list *cd01_list;
52 	/*
53 	 * May be called during or after the bind callback.
54 	 * Will be called with NULL if capdata_fan does not exist.
55 	 * The pointer is only valid in the callback; never keep it for later use!
56 	 */
57 	cd_list_cb_t cd_fan_list_cb;
58 };
59 
60 void lwmi_cd_match_add_all(struct device *master, struct component_match **matchptr);
61 int lwmi_cd00_get_data(struct cd_list *list, u32 attribute_id, struct capdata00 *output);
62 int lwmi_cd01_get_data(struct cd_list *list, u32 attribute_id, struct capdata01 *output);
63 int lwmi_cd_fan_get_data(struct cd_list *list, u32 attribute_id, struct capdata_fan *output);
64 
65 #endif /* !_LENOVO_WMI_CAPDATA_H_ */
66