1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  *  Common functions for kernel modules using Dell SMBIOS
4  *
5  *  Copyright (c) Red Hat <mjg@redhat.com>
6  *  Copyright (c) 2014 Gabriele Mazzotta <gabriele.mzt@gmail.com>
7  *  Copyright (c) 2014 Pali Rohár <pali@kernel.org>
8  *
9  *  Based on documentation in the libsmbios package:
10  *  Copyright (C) 2005-2014 Dell Inc.
11  */
12 
13 #ifndef _DELL_SMBIOS_H_
14 #define _DELL_SMBIOS_H_
15 
16 #include <linux/device.h>
17 #include <uapi/linux/wmi.h>
18 
19 /* Classes and selects used only in kernel drivers */
20 #define CLASS_KBD_BACKLIGHT 4
21 #define SELECT_KBD_BACKLIGHT 11
22 
23 /* Tokens used in kernel drivers, any of these
24  * should be filtered from userspace access
25  */
26 #define BRIGHTNESS_TOKEN	0x007d
27 #define KBD_LED_AC_TOKEN	0x0451
28 #define KBD_LED_OFF_TOKEN	0x01E1
29 #define KBD_LED_ON_TOKEN	0x01E2
30 #define KBD_LED_AUTO_TOKEN	0x01E3
31 #define KBD_LED_AUTO_25_TOKEN	0x02EA
32 #define KBD_LED_AUTO_50_TOKEN	0x02EB
33 #define KBD_LED_AUTO_75_TOKEN	0x02EC
34 #define KBD_LED_AUTO_100_TOKEN	0x02F6
35 #define GLOBAL_MIC_MUTE_ENABLE	0x0364
36 #define GLOBAL_MIC_MUTE_DISABLE	0x0365
37 #define GLOBAL_MUTE_ENABLE	0x058C
38 #define GLOBAL_MUTE_DISABLE	0x058D
39 
40 struct notifier_block;
41 
42 struct calling_interface_token {
43 	u16 tokenID;
44 	u16 location;
45 	union {
46 		u16 value;
47 		u16 stringlength;
48 	};
49 };
50 
51 struct calling_interface_structure {
52 	struct dmi_header header;
53 	u16 cmdIOAddress;
54 	u8 cmdIOCode;
55 	u32 supportedCmds;
56 	struct calling_interface_token tokens[];
57 } __packed;
58 
59 int dell_smbios_register_device(struct device *d, void *call_fn);
60 void dell_smbios_unregister_device(struct device *d);
61 
62 int dell_smbios_error(int value);
63 int dell_smbios_call_filter(struct device *d,
64 	struct calling_interface_buffer *buffer);
65 int dell_smbios_call(struct calling_interface_buffer *buffer);
66 
67 struct calling_interface_token *dell_smbios_find_token(int tokenid);
68 
69 enum dell_laptop_notifier_actions {
70 	DELL_LAPTOP_KBD_BACKLIGHT_BRIGHTNESS_CHANGED,
71 };
72 
73 int dell_laptop_register_notifier(struct notifier_block *nb);
74 int dell_laptop_unregister_notifier(struct notifier_block *nb);
75 void dell_laptop_call_notifier(unsigned long action, void *data);
76 
77 /* for the supported backends */
78 #ifdef CONFIG_DELL_SMBIOS_WMI
79 int init_dell_smbios_wmi(void);
80 void exit_dell_smbios_wmi(void);
81 #else /* CONFIG_DELL_SMBIOS_WMI */
init_dell_smbios_wmi(void)82 static inline int init_dell_smbios_wmi(void)
83 {
84 	return -ENODEV;
85 }
exit_dell_smbios_wmi(void)86 static inline void exit_dell_smbios_wmi(void)
87 {}
88 #endif /* CONFIG_DELL_SMBIOS_WMI */
89 
90 #ifdef CONFIG_DELL_SMBIOS_SMM
91 int init_dell_smbios_smm(void);
92 void exit_dell_smbios_smm(void);
93 #else /* CONFIG_DELL_SMBIOS_SMM */
init_dell_smbios_smm(void)94 static inline int init_dell_smbios_smm(void)
95 {
96 	return -ENODEV;
97 }
exit_dell_smbios_smm(void)98 static inline void exit_dell_smbios_smm(void)
99 {}
100 #endif /* CONFIG_DELL_SMBIOS_SMM */
101 
102 #endif /* _DELL_SMBIOS_H_ */
103