xref: /linux/drivers/platform/x86/lenovo/wmi-capdata.h (revision 4c2cd91bff6371b58e672e8791c3bfa70c1b821f)
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/bitfield.h>
10 #include <linux/types.h>
11 
12 #define LWMI_SUPP_VALID		BIT(0)
13 #define LWMI_SUPP_GET		BIT(1)
14 #define LWMI_SUPP_SET		BIT(2)
15 
16 #define LWMI_ATTR_DEV_ID_MASK	GENMASK(31, 24)
17 #define LWMI_ATTR_FEAT_ID_MASK	GENMASK(23, 16)
18 #define LWMI_ATTR_MODE_ID_MASK	GENMASK(15, 8)
19 #define LWMI_ATTR_TYPE_ID_MASK	GENMASK(7, 0)
20 
21 #define LWMI_DEVICE_ID_FAN	0x04
22 
23 #define LWMI_TYPE_ID_NONE 0x00
24 
25 struct component_match;
26 struct device;
27 struct cd_list;
28 
29 struct capdata00 {
30 	u32 id;
31 	u32 supported;
32 	u32 default_value;
33 };
34 
35 struct capdata01 {
36 	u32 id;
37 	u32 supported;
38 	u32 default_value;
39 	u32 step;
40 	u32 min_value;
41 	u32 max_value;
42 };
43 
44 struct capdata_fan {
45 	u32 id;
46 	u32 min_rpm;
47 	u32 max_rpm;
48 };
49 
50 typedef void (*cd_list_cb_t)(struct device *master_dev, struct cd_list *cd_list);
51 
52 struct lwmi_cd_binder {
53 	struct cd_list *cd00_list;
54 	struct cd_list *cd01_list;
55 	/*
56 	 * May be called during or after the bind callback.
57 	 * Will be called with NULL if capdata_fan does not exist.
58 	 * The pointer is only valid in the callback; never keep it for later use!
59 	 */
60 	cd_list_cb_t cd_fan_list_cb;
61 };
62 
63 /**
64  * lwmi_attr_id() - Formats a capability data attribute ID
65  * @dev_id: The u8 corresponding to the device ID.
66  * @feat_id: The u8 corresponding to the feature ID on the device.
67  * @mode_id: The u8 corresponding to the wmi-gamezone mode for set/get.
68  * @type_id: The u8 corresponding to the sub-device.
69  *
70  * Return: encoded capability data attribute ID.
71  */
lwmi_attr_id(u8 dev_id,u8 feat_id,u8 mode_id,u8 type_id)72 static inline u32 lwmi_attr_id(u8 dev_id, u8 feat_id, u8 mode_id, u8 type_id)
73 {
74 	return (FIELD_PREP(LWMI_ATTR_DEV_ID_MASK, dev_id)   |
75 		FIELD_PREP(LWMI_ATTR_FEAT_ID_MASK, feat_id) |
76 		FIELD_PREP(LWMI_ATTR_MODE_ID_MASK, mode_id) |
77 		FIELD_PREP(LWMI_ATTR_TYPE_ID_MASK, type_id));
78 }
79 
80 void lwmi_cd_match_add_all(struct device *master, struct component_match **matchptr);
81 int lwmi_cd00_get_data(struct cd_list *list, u32 attribute_id, struct capdata00 *output);
82 int lwmi_cd01_get_data(struct cd_list *list, u32 attribute_id, struct capdata01 *output);
83 int lwmi_cd_fan_get_data(struct cd_list *list, u32 attribute_id, struct capdata_fan *output);
84 
85 #endif /* !_LENOVO_WMI_CAPDATA_H_ */
86