Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  * Asus PC WMI hotkey driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * Copyright(C) 2010 Intel Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  * Copyright(C) 2010-2011 Corentin Chary <corentin.chary@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  * Portions based on wistron_btns.c:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  * Copyright (C) 2005 Miloslav Trmac <mitr@volny.cz>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  * Copyright (C) 2005 Bernhard Rosenkraenzer <bero@arklinux.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  * Copyright (C) 2005 Dmitry Torokhov <dtor@mail.ru>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #include <linux/input/sparse-keymap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) #include <linux/fb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) #include <linux/backlight.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) #include <linux/leds.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) #include <linux/rfkill.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) #include <linux/pci_hotplug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) #include <linux/power_supply.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) #include <linux/hwmon.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) #include <linux/hwmon-sysfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) #include <linux/platform_data/x86/asus-wmi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) #include <linux/dmi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) #include <linux/units.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) #include <acpi/battery.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) #include <acpi/video.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) #include "asus-wmi.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) MODULE_AUTHOR("Corentin Chary <corentin.chary@gmail.com>, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) 	      "Yong Wang <yong.y.wang@intel.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) MODULE_DESCRIPTION("Asus Generic WMI Driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) #define to_asus_wmi_driver(pdrv)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) 	(container_of((pdrv), struct asus_wmi_driver, platform_driver))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) #define ASUS_WMI_MGMT_GUID	"97845ED0-4E6D-11DE-8A39-0800200C9A66"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) #define NOTIFY_BRNUP_MIN		0x11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) #define NOTIFY_BRNUP_MAX		0x1f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) #define NOTIFY_BRNDOWN_MIN		0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) #define NOTIFY_BRNDOWN_MAX		0x2e
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) #define NOTIFY_FNLOCK_TOGGLE		0x4e
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) #define NOTIFY_KBD_DOCK_CHANGE		0x75
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) #define NOTIFY_KBD_BRTUP		0xc4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) #define NOTIFY_KBD_BRTDWN		0xc5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) #define NOTIFY_KBD_BRTTOGGLE		0xc7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) #define NOTIFY_KBD_FBM			0x99
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) #define NOTIFY_KBD_TTP			0xae
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) #define ASUS_WMI_FNLOCK_BIOS_DISABLED	BIT(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) #define ASUS_FAN_DESC			"cpu_fan"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) #define ASUS_FAN_MFUN			0x13
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) #define ASUS_FAN_SFUN_READ		0x06
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) #define ASUS_FAN_SFUN_WRITE		0x07
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) /* Based on standard hwmon pwmX_enable values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) #define ASUS_FAN_CTRL_FULLSPEED		0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) #define ASUS_FAN_CTRL_MANUAL		1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) #define ASUS_FAN_CTRL_AUTO		2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) #define ASUS_FAN_BOOST_MODE_NORMAL		0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) #define ASUS_FAN_BOOST_MODE_OVERBOOST		1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) #define ASUS_FAN_BOOST_MODE_OVERBOOST_MASK	0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) #define ASUS_FAN_BOOST_MODE_SILENT		2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) #define ASUS_FAN_BOOST_MODE_SILENT_MASK		0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) #define ASUS_FAN_BOOST_MODES_MASK		0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) #define ASUS_THROTTLE_THERMAL_POLICY_DEFAULT	0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) #define ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) #define ASUS_THROTTLE_THERMAL_POLICY_SILENT	2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) #define USB_INTEL_XUSB2PR		0xD0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) #define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI	0x9c31
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) #define ASUS_ACPI_UID_ASUSWMI		"ASUSWMI"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) #define ASUS_ACPI_UID_ATK		"ATK"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) #define WMI_EVENT_QUEUE_SIZE		0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) #define WMI_EVENT_QUEUE_END		0x1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) #define WMI_EVENT_MASK			0xFFFF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) /* The WMI hotkey event value is always the same. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) #define WMI_EVENT_VALUE_ATK		0xFF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) #define WMI_EVENT_MASK			0xFFFF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) static const char * const ashs_ids[] = { "ATK4001", "ATK4002", NULL };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) static bool ashs_present(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 	int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 	while (ashs_ids[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 		if (acpi_dev_found(ashs_ids[i++]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 			return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) struct bios_args {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 	u32 arg0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 	u32 arg1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 	u32 arg2; /* At least TUF Gaming series uses 3 dword input buffer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 	u32 arg4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 	u32 arg5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125)  * Struct that's used for all methods called via AGFN. Naming is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126)  * identically to the AML code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) struct agfn_args {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 	u16 mfun; /* probably "Multi-function" to be called */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 	u16 sfun; /* probably "Sub-function" to be called */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 	u16 len;  /* size of the hole struct, including subfunction fields */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 	u8 stas;  /* not used by now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 	u8 err;   /* zero on success */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) /* struct used for calling fan read and write methods */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) struct agfn_fan_args {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 	struct agfn_args agfn;	/* common fields */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 	u8 fan;			/* fan number: 0: set auto mode 1: 1st fan */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 	u32 speed;		/* read: RPM/100 - write: 0-255 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144)  * <platform>/    - debugfs root directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145)  *   dev_id      - current dev_id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146)  *   ctrl_param  - current ctrl_param
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147)  *   method_id   - current method_id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148)  *   devs        - call DEVS(dev_id, ctrl_param) and print result
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149)  *   dsts        - call DSTS(dev_id)  and print result
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150)  *   call        - call method_id(dev_id, ctrl_param) and print result
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) struct asus_wmi_debug {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 	struct dentry *root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 	u32 method_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 	u32 dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 	u32 ctrl_param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) struct asus_rfkill {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 	struct asus_wmi *asus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 	struct rfkill *rfkill;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 	u32 dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) enum fan_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 	FAN_TYPE_NONE = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 	FAN_TYPE_AGFN,		/* deprecated on newer platforms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 	FAN_TYPE_SPEC83,	/* starting in Spec 8.3, use CPU_FAN_CTRL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) struct asus_wmi {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 	int dsts_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 	int spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 	int sfun;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 	bool wmi_event_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 	struct input_dev *inputdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 	struct backlight_device *backlight_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 	struct platform_device *platform_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 	struct led_classdev wlan_led;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 	int wlan_led_wk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 	struct led_classdev tpd_led;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 	int tpd_led_wk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 	struct led_classdev kbd_led;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 	int kbd_led_wk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 	struct led_classdev lightbar_led;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 	int lightbar_led_wk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 	struct workqueue_struct *led_workqueue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 	struct work_struct tpd_led_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 	struct work_struct wlan_led_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 	struct work_struct lightbar_led_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 	struct asus_rfkill wlan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 	struct asus_rfkill bluetooth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 	struct asus_rfkill wimax;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 	struct asus_rfkill wwan3g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 	struct asus_rfkill gps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 	struct asus_rfkill uwb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 	enum fan_type fan_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 	int fan_pwm_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 	int agfn_pwm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 	bool fan_boost_mode_available;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 	u8 fan_boost_mode_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 	u8 fan_boost_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 	bool throttle_thermal_policy_available;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 	u8 throttle_thermal_policy_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 	// The RSOC controls the maximum charging percentage.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 	bool battery_rsoc_available;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	struct hotplug_slot hotplug_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 	struct mutex hotplug_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 	struct mutex wmi_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 	struct workqueue_struct *hotplug_workqueue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 	struct work_struct hotplug_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 	bool fnlock_locked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 	struct asus_wmi_debug debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 	struct asus_wmi_driver *driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) /* WMI ************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) static int asus_wmi_evaluate_method3(u32 method_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 		u32 arg0, u32 arg1, u32 arg2, u32 *retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	struct bios_args args = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 		.arg0 = arg0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 		.arg1 = arg1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 		.arg2 = arg2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 	struct acpi_buffer input = { (acpi_size) sizeof(args), &args };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 	struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 	union acpi_object *obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 	u32 tmp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 	status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID, 0, method_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 				     &input, &output);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 	if (ACPI_FAILURE(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 	obj = (union acpi_object *)output.pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 	if (obj && obj->type == ACPI_TYPE_INTEGER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 		tmp = (u32) obj->integer.value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 	if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 		*retval = tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 	kfree(obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 	if (tmp == ASUS_WMI_UNSUPPORTED_METHOD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) int asus_wmi_evaluate_method(u32 method_id, u32 arg0, u32 arg1, u32 *retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 	return asus_wmi_evaluate_method3(method_id, arg0, arg1, 0, retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) EXPORT_SYMBOL_GPL(asus_wmi_evaluate_method);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) static int asus_wmi_evaluate_method_agfn(const struct acpi_buffer args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 	struct acpi_buffer input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 	u64 phys_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 	u32 retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 	u32 status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 	 * Copy to dma capable address otherwise memory corruption occurs as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 	 * bios has to be able to access it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 	input.pointer = kmemdup(args.pointer, args.length, GFP_DMA | GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 	input.length = args.length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 	if (!input.pointer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 	phys_addr = virt_to_phys(input.pointer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 	status = asus_wmi_evaluate_method(ASUS_WMI_METHODID_AGFN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 					phys_addr, 0, &retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 	if (!status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 		memcpy(args.pointer, input.pointer, args.length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 	kfree(input.pointer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 	if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 		return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) static int asus_wmi_get_devstate(struct asus_wmi *asus, u32 dev_id, u32 *retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 	return asus_wmi_evaluate_method(asus->dsts_id, dev_id, 0, retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) static int asus_wmi_set_devstate(u32 dev_id, u32 ctrl_param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 				 u32 *retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 	return asus_wmi_evaluate_method(ASUS_WMI_METHODID_DEVS, dev_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 					ctrl_param, retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) /* Helper for special devices with magic return codes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) static int asus_wmi_get_devstate_bits(struct asus_wmi *asus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 				      u32 dev_id, u32 mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 	u32 retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 	err = asus_wmi_get_devstate(asus, dev_id, &retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 	if (!(retval & ASUS_WMI_DSTS_PRESENCE_BIT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 	if (mask == ASUS_WMI_DSTS_STATUS_BIT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 		if (retval & ASUS_WMI_DSTS_UNKNOWN_BIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 			return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 	return retval & mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) static int asus_wmi_get_devstate_simple(struct asus_wmi *asus, u32 dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 	return asus_wmi_get_devstate_bits(asus, dev_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 					  ASUS_WMI_DSTS_STATUS_BIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) static bool asus_wmi_dev_is_present(struct asus_wmi *asus, u32 dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 	u32 retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 	int status = asus_wmi_get_devstate(asus, dev_id, &retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 	return status == 0 && (retval & ASUS_WMI_DSTS_PRESENCE_BIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) /* Input **********************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) static int asus_wmi_input_init(struct asus_wmi *asus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 	int err, result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 	asus->inputdev = input_allocate_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 	if (!asus->inputdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 	asus->inputdev->name = asus->driver->input_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 	asus->inputdev->phys = asus->driver->input_phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 	asus->inputdev->id.bustype = BUS_HOST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 	asus->inputdev->dev.parent = &asus->platform_device->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 	set_bit(EV_REP, asus->inputdev->evbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 	err = sparse_keymap_setup(asus->inputdev, asus->driver->keymap, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 		goto err_free_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 	if (asus->driver->quirks->use_kbd_dock_devid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 		result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_KBD_DOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 		if (result >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 			input_set_capability(asus->inputdev, EV_SW, SW_TABLET_MODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 			input_report_switch(asus->inputdev, SW_TABLET_MODE, !result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 		} else if (result != -ENODEV) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 			pr_err("Error checking for keyboard-dock: %d\n", result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 	err = input_register_device(asus->inputdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 		goto err_free_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) err_free_dev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 	input_free_device(asus->inputdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) static void asus_wmi_input_exit(struct asus_wmi *asus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 	if (asus->inputdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 		input_unregister_device(asus->inputdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 	asus->inputdev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) /* Battery ********************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) /* The battery maximum charging percentage */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) static int charge_end_threshold;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) static ssize_t charge_control_end_threshold_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 						  struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 						  const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 	int value, ret, rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 	ret = kstrtouint(buf, 10, &value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 	if (value < 0 || value > 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 	ret = asus_wmi_set_devstate(ASUS_WMI_DEVID_RSOC, value, &rv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 	if (rv != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 	/* There isn't any method in the DSDT to read the threshold, so we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 	 * save the threshold.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 	charge_end_threshold = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) static ssize_t charge_control_end_threshold_show(struct device *device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 						 struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 						 char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 	return sprintf(buf, "%d\n", charge_end_threshold);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) static DEVICE_ATTR_RW(charge_control_end_threshold);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) static int asus_wmi_battery_add(struct power_supply *battery)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	/* The WMI method does not provide a way to specific a battery, so we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	 * just assume it is the first battery.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 	 * Note: On some newer ASUS laptops (Zenbook UM431DA), the primary/first
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 	 * battery is named BATT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 	if (strcmp(battery->desc->name, "BAT0") != 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	    strcmp(battery->desc->name, "BAT1") != 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 	    strcmp(battery->desc->name, "BATC") != 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 	    strcmp(battery->desc->name, "BATT") != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 	if (device_create_file(&battery->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 	    &dev_attr_charge_control_end_threshold))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 	/* The charge threshold is only reset when the system is power cycled,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 	 * and we can't get the current threshold so let set it to 100% when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 	 * a battery is added.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 	asus_wmi_set_devstate(ASUS_WMI_DEVID_RSOC, 100, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 	charge_end_threshold = 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) static int asus_wmi_battery_remove(struct power_supply *battery)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 	device_remove_file(&battery->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 			   &dev_attr_charge_control_end_threshold);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) static struct acpi_battery_hook battery_hook = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 	.add_battery = asus_wmi_battery_add,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 	.remove_battery = asus_wmi_battery_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 	.name = "ASUS Battery Extension",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) static void asus_wmi_battery_init(struct asus_wmi *asus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 	asus->battery_rsoc_available = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 	if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_RSOC)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 		asus->battery_rsoc_available = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 		battery_hook_register(&battery_hook);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) static void asus_wmi_battery_exit(struct asus_wmi *asus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 	if (asus->battery_rsoc_available)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 		battery_hook_unregister(&battery_hook);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) /* LEDs ***********************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496)  * These functions actually update the LED's, and are called from a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497)  * workqueue. By doing this as separate work rather than when the LED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498)  * subsystem asks, we avoid messing with the Asus ACPI stuff during a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499)  * potentially bad time, such as a timer interrupt.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) static void tpd_led_update(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 	int ctrl_param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 	struct asus_wmi *asus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 	asus = container_of(work, struct asus_wmi, tpd_led_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 	ctrl_param = asus->tpd_led_wk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 	asus_wmi_set_devstate(ASUS_WMI_DEVID_TOUCHPAD_LED, ctrl_param, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) static void tpd_led_set(struct led_classdev *led_cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 			enum led_brightness value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 	struct asus_wmi *asus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 	asus = container_of(led_cdev, struct asus_wmi, tpd_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 	asus->tpd_led_wk = !!value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 	queue_work(asus->led_workqueue, &asus->tpd_led_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) static int read_tpd_led_state(struct asus_wmi *asus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 	return asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_TOUCHPAD_LED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) static enum led_brightness tpd_led_get(struct led_classdev *led_cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 	struct asus_wmi *asus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 	asus = container_of(led_cdev, struct asus_wmi, tpd_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 	return read_tpd_led_state(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) static void kbd_led_update(struct asus_wmi *asus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 	int ctrl_param = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 	ctrl_param = 0x80 | (asus->kbd_led_wk & 0x7F);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 	asus_wmi_set_devstate(ASUS_WMI_DEVID_KBD_BACKLIGHT, ctrl_param, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) static int kbd_led_read(struct asus_wmi *asus, int *level, int *env)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 	 * bits 0-2: level
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 	 * bit 7: light on/off
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 	 * bit 8-10: environment (0: dark, 1: normal, 2: light)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 	 * bit 17: status unknown
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 	retval = asus_wmi_get_devstate_bits(asus, ASUS_WMI_DEVID_KBD_BACKLIGHT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 					    0xFFFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 	/* Unknown status is considered as off */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 	if (retval == 0x8000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 		retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 	if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 	if (level)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 		*level = retval & 0x7F;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 	if (env)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 		*env = (retval >> 8) & 0x7F;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) static void do_kbd_led_set(struct led_classdev *led_cdev, int value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 	struct asus_wmi *asus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 	int max_level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	asus = container_of(led_cdev, struct asus_wmi, kbd_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 	max_level = asus->kbd_led.max_brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 	asus->kbd_led_wk = clamp_val(value, 0, max_level);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 	kbd_led_update(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) static void kbd_led_set(struct led_classdev *led_cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 			enum led_brightness value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 	/* Prevent disabling keyboard backlight on module unregister */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 	if (led_cdev->flags & LED_UNREGISTERING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 	do_kbd_led_set(led_cdev, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) static void kbd_led_set_by_kbd(struct asus_wmi *asus, enum led_brightness value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 	struct led_classdev *led_cdev = &asus->kbd_led;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 	do_kbd_led_set(led_cdev, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 	led_classdev_notify_brightness_hw_changed(led_cdev, asus->kbd_led_wk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) static enum led_brightness kbd_led_get(struct led_classdev *led_cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 	struct asus_wmi *asus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 	int retval, value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 	asus = container_of(led_cdev, struct asus_wmi, kbd_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 	retval = kbd_led_read(asus, &value, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 	if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 	return value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) static int wlan_led_unknown_state(struct asus_wmi *asus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 	u32 result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 	asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_WIRELESS_LED, &result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 	return result & ASUS_WMI_DSTS_UNKNOWN_BIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) static void wlan_led_update(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 	int ctrl_param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 	struct asus_wmi *asus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 	asus = container_of(work, struct asus_wmi, wlan_led_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 	ctrl_param = asus->wlan_led_wk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 	asus_wmi_set_devstate(ASUS_WMI_DEVID_WIRELESS_LED, ctrl_param, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) static void wlan_led_set(struct led_classdev *led_cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 			 enum led_brightness value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 	struct asus_wmi *asus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 	asus = container_of(led_cdev, struct asus_wmi, wlan_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 	asus->wlan_led_wk = !!value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 	queue_work(asus->led_workqueue, &asus->wlan_led_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) static enum led_brightness wlan_led_get(struct led_classdev *led_cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 	struct asus_wmi *asus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 	u32 result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 	asus = container_of(led_cdev, struct asus_wmi, wlan_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 	asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_WIRELESS_LED, &result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 	return result & ASUS_WMI_DSTS_BRIGHTNESS_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) static void lightbar_led_update(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 	struct asus_wmi *asus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 	int ctrl_param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 	asus = container_of(work, struct asus_wmi, lightbar_led_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 	ctrl_param = asus->lightbar_led_wk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 	asus_wmi_set_devstate(ASUS_WMI_DEVID_LIGHTBAR, ctrl_param, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) static void lightbar_led_set(struct led_classdev *led_cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 			     enum led_brightness value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 	struct asus_wmi *asus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 	asus = container_of(led_cdev, struct asus_wmi, lightbar_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 	asus->lightbar_led_wk = !!value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 	queue_work(asus->led_workqueue, &asus->lightbar_led_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) static enum led_brightness lightbar_led_get(struct led_classdev *led_cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 	struct asus_wmi *asus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 	u32 result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 	asus = container_of(led_cdev, struct asus_wmi, lightbar_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 	asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_LIGHTBAR, &result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 	return result & ASUS_WMI_DSTS_LIGHTBAR_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) static void asus_wmi_led_exit(struct asus_wmi *asus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 	led_classdev_unregister(&asus->kbd_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 	led_classdev_unregister(&asus->tpd_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 	led_classdev_unregister(&asus->wlan_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 	led_classdev_unregister(&asus->lightbar_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 	if (asus->led_workqueue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 		destroy_workqueue(asus->led_workqueue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) static int asus_wmi_led_init(struct asus_wmi *asus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 	int rv = 0, led_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 	asus->led_workqueue = create_singlethread_workqueue("led_workqueue");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 	if (!asus->led_workqueue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 	if (read_tpd_led_state(asus) >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 		INIT_WORK(&asus->tpd_led_work, tpd_led_update);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 		asus->tpd_led.name = "asus::touchpad";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 		asus->tpd_led.brightness_set = tpd_led_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 		asus->tpd_led.brightness_get = tpd_led_get;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 		asus->tpd_led.max_brightness = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 		rv = led_classdev_register(&asus->platform_device->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 					   &asus->tpd_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 		if (rv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 	if (!kbd_led_read(asus, &led_val, NULL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 		asus->kbd_led_wk = led_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 		asus->kbd_led.name = "asus::kbd_backlight";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 		asus->kbd_led.flags = LED_BRIGHT_HW_CHANGED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 		asus->kbd_led.brightness_set = kbd_led_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 		asus->kbd_led.brightness_get = kbd_led_get;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 		asus->kbd_led.max_brightness = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 		rv = led_classdev_register(&asus->platform_device->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 					   &asus->kbd_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 		if (rv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 	if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_WIRELESS_LED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 			&& (asus->driver->quirks->wapf > 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 		INIT_WORK(&asus->wlan_led_work, wlan_led_update);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 		asus->wlan_led.name = "asus::wlan";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 		asus->wlan_led.brightness_set = wlan_led_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 		if (!wlan_led_unknown_state(asus))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 			asus->wlan_led.brightness_get = wlan_led_get;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 		asus->wlan_led.flags = LED_CORE_SUSPENDRESUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 		asus->wlan_led.max_brightness = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 		asus->wlan_led.default_trigger = "asus-wlan";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 		rv = led_classdev_register(&asus->platform_device->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 					   &asus->wlan_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 		if (rv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 	if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_LIGHTBAR)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 		INIT_WORK(&asus->lightbar_led_work, lightbar_led_update);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 		asus->lightbar_led.name = "asus::lightbar";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 		asus->lightbar_led.brightness_set = lightbar_led_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 		asus->lightbar_led.brightness_get = lightbar_led_get;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 		asus->lightbar_led.max_brightness = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 		rv = led_classdev_register(&asus->platform_device->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 					   &asus->lightbar_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 	if (rv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 		asus_wmi_led_exit(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) /* RF *************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778)  * PCI hotplug (for wlan rfkill)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) static bool asus_wlan_rfkill_blocked(struct asus_wmi *asus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 	int result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_WLAN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 	if (result < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 	return !result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) static void asus_rfkill_hotplug(struct asus_wmi *asus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 	struct pci_dev *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 	struct pci_bus *bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 	bool blocked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 	bool absent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 	u32 l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 	mutex_lock(&asus->wmi_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 	blocked = asus_wlan_rfkill_blocked(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 	mutex_unlock(&asus->wmi_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 	mutex_lock(&asus->hotplug_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 	pci_lock_rescan_remove();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 	if (asus->wlan.rfkill)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 		rfkill_set_sw_state(asus->wlan.rfkill, blocked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 	if (asus->hotplug_slot.ops) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 		bus = pci_find_bus(0, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 		if (!bus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 			pr_warn("Unable to find PCI bus 1?\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 			goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 		if (pci_bus_read_config_dword(bus, 0, PCI_VENDOR_ID, &l)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 			pr_err("Unable to read PCI config space?\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 			goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 		absent = (l == 0xffffffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 		if (blocked != absent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 			pr_warn("BIOS says wireless lan is %s, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 				"but the pci device is %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 				blocked ? "blocked" : "unblocked",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 				absent ? "absent" : "present");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 			pr_warn("skipped wireless hotplug as probably "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 				"inappropriate for this model\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 			goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 		if (!blocked) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 			dev = pci_get_slot(bus, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 			if (dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 				/* Device already present */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 				pci_dev_put(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 				goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 			dev = pci_scan_single_device(bus, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 			if (dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 				pci_bus_assign_resources(bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 				pci_bus_add_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 			dev = pci_get_slot(bus, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 			if (dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 				pci_stop_and_remove_bus_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 				pci_dev_put(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 	pci_unlock_rescan_remove();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 	mutex_unlock(&asus->hotplug_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) static void asus_rfkill_notify(acpi_handle handle, u32 event, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 	struct asus_wmi *asus = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 	if (event != ACPI_NOTIFY_BUS_CHECK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 	 * We can't call directly asus_rfkill_hotplug because most
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 	 * of the time WMBC is still being executed and not reetrant.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 	 * There is currently no way to tell ACPICA that  we want this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 	 * method to be serialized, we schedule a asus_rfkill_hotplug
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 	 * call later, in a safer context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 	queue_work(asus->hotplug_workqueue, &asus->hotplug_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) static int asus_register_rfkill_notifier(struct asus_wmi *asus, char *node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 	acpi_handle handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 	status = acpi_get_handle(NULL, node, &handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	if (ACPI_FAILURE(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 	status = acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 					     asus_rfkill_notify, asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 	if (ACPI_FAILURE(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 		pr_warn("Failed to register notify on %s\n", node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) static void asus_unregister_rfkill_notifier(struct asus_wmi *asus, char *node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 	acpi_status status = AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 	acpi_handle handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 	status = acpi_get_handle(NULL, node, &handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 	if (ACPI_FAILURE(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 	status = acpi_remove_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 					    asus_rfkill_notify);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 	if (ACPI_FAILURE(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 		pr_err("Error removing rfkill notify handler %s\n", node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) static int asus_get_adapter_status(struct hotplug_slot *hotplug_slot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 				   u8 *value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 	struct asus_wmi *asus = container_of(hotplug_slot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 					     struct asus_wmi, hotplug_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 	int result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_WLAN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 	if (result < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 		return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 	*value = !!result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) static const struct hotplug_slot_ops asus_hotplug_slot_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 	.get_adapter_status = asus_get_adapter_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 	.get_power_status = asus_get_adapter_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) static void asus_hotplug_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 	struct asus_wmi *asus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 	asus = container_of(work, struct asus_wmi, hotplug_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 	asus_rfkill_hotplug(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) static int asus_setup_pci_hotplug(struct asus_wmi *asus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 	int ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 	struct pci_bus *bus = pci_find_bus(0, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 	if (!bus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 		pr_err("Unable to find wifi PCI bus\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 	asus->hotplug_workqueue =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	    create_singlethread_workqueue("hotplug_workqueue");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 	if (!asus->hotplug_workqueue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 		goto error_workqueue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 	INIT_WORK(&asus->hotplug_work, asus_hotplug_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 	asus->hotplug_slot.ops = &asus_hotplug_slot_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 	ret = pci_hp_register(&asus->hotplug_slot, bus, 0, "asus-wifi");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 		pr_err("Unable to register hotplug slot - %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 		goto error_register;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) error_register:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 	asus->hotplug_slot.ops = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 	destroy_workqueue(asus->hotplug_workqueue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) error_workqueue:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967)  * Rfkill devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) static int asus_rfkill_set(void *data, bool blocked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 	struct asus_rfkill *priv = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 	u32 ctrl_param = !blocked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 	u32 dev_id = priv->dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 	 * If the user bit is set, BIOS can't set and record the wlan status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 	 * it will report the value read from id ASUS_WMI_DEVID_WLAN_LED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 	 * while we query the wlan status through WMI(ASUS_WMI_DEVID_WLAN).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 	 * So, we have to record wlan status in id ASUS_WMI_DEVID_WLAN_LED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 	 * while setting the wlan status through WMI.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 	 * This is also the behavior that windows app will do.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 	if ((dev_id == ASUS_WMI_DEVID_WLAN) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 	     priv->asus->driver->wlan_ctrl_by_user)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 		dev_id = ASUS_WMI_DEVID_WLAN_LED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 	return asus_wmi_set_devstate(dev_id, ctrl_param, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) static void asus_rfkill_query(struct rfkill *rfkill, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 	struct asus_rfkill *priv = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 	result = asus_wmi_get_devstate_simple(priv->asus, priv->dev_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 	if (result < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 	rfkill_set_sw_state(priv->rfkill, !result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) static int asus_rfkill_wlan_set(void *data, bool blocked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 	struct asus_rfkill *priv = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 	struct asus_wmi *asus = priv->asus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	 * This handler is enabled only if hotplug is enabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 	 * In this case, the asus_wmi_set_devstate() will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 	 * trigger a wmi notification and we need to wait
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 	 * this call to finish before being able to call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 	 * any wmi method
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 	mutex_lock(&asus->wmi_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 	ret = asus_rfkill_set(data, blocked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 	mutex_unlock(&asus->wmi_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) static const struct rfkill_ops asus_rfkill_wlan_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 	.set_block = asus_rfkill_wlan_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 	.query = asus_rfkill_query,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) static const struct rfkill_ops asus_rfkill_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 	.set_block = asus_rfkill_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 	.query = asus_rfkill_query,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) static int asus_new_rfkill(struct asus_wmi *asus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 			   struct asus_rfkill *arfkill,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 			   const char *name, enum rfkill_type type, int dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 	int result = asus_wmi_get_devstate_simple(asus, dev_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 	struct rfkill **rfkill = &arfkill->rfkill;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 	if (result < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 		return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 	arfkill->dev_id = dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 	arfkill->asus = asus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 	if (dev_id == ASUS_WMI_DEVID_WLAN &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 	    asus->driver->quirks->hotplug_wireless)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 		*rfkill = rfkill_alloc(name, &asus->platform_device->dev, type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 				       &asus_rfkill_wlan_ops, arfkill);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 		*rfkill = rfkill_alloc(name, &asus->platform_device->dev, type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 				       &asus_rfkill_ops, arfkill);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 	if (!*rfkill)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 	if ((dev_id == ASUS_WMI_DEVID_WLAN) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 			(asus->driver->quirks->wapf > 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 		rfkill_set_led_trigger_name(*rfkill, "asus-wlan");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 	rfkill_init_sw_state(*rfkill, !result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 	result = rfkill_register(*rfkill);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 	if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 		rfkill_destroy(*rfkill);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 		*rfkill = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 		return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) static void asus_wmi_rfkill_exit(struct asus_wmi *asus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 	if (asus->driver->wlan_ctrl_by_user && ashs_present())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 	asus_unregister_rfkill_notifier(asus, "\\_SB.PCI0.P0P5");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 	asus_unregister_rfkill_notifier(asus, "\\_SB.PCI0.P0P6");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 	asus_unregister_rfkill_notifier(asus, "\\_SB.PCI0.P0P7");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 	if (asus->wlan.rfkill) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 		rfkill_unregister(asus->wlan.rfkill);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 		rfkill_destroy(asus->wlan.rfkill);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 		asus->wlan.rfkill = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 	 * Refresh pci hotplug in case the rfkill state was changed after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 	 * asus_unregister_rfkill_notifier()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 	asus_rfkill_hotplug(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 	if (asus->hotplug_slot.ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 		pci_hp_deregister(&asus->hotplug_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 	if (asus->hotplug_workqueue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 		destroy_workqueue(asus->hotplug_workqueue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 	if (asus->bluetooth.rfkill) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 		rfkill_unregister(asus->bluetooth.rfkill);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 		rfkill_destroy(asus->bluetooth.rfkill);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 		asus->bluetooth.rfkill = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 	if (asus->wimax.rfkill) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 		rfkill_unregister(asus->wimax.rfkill);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 		rfkill_destroy(asus->wimax.rfkill);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 		asus->wimax.rfkill = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 	if (asus->wwan3g.rfkill) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 		rfkill_unregister(asus->wwan3g.rfkill);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 		rfkill_destroy(asus->wwan3g.rfkill);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 		asus->wwan3g.rfkill = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 	if (asus->gps.rfkill) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 		rfkill_unregister(asus->gps.rfkill);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 		rfkill_destroy(asus->gps.rfkill);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 		asus->gps.rfkill = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 	if (asus->uwb.rfkill) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 		rfkill_unregister(asus->uwb.rfkill);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 		rfkill_destroy(asus->uwb.rfkill);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 		asus->uwb.rfkill = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) static int asus_wmi_rfkill_init(struct asus_wmi *asus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 	int result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 	mutex_init(&asus->hotplug_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 	mutex_init(&asus->wmi_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 	result = asus_new_rfkill(asus, &asus->wlan, "asus-wlan",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 				 RFKILL_TYPE_WLAN, ASUS_WMI_DEVID_WLAN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 	if (result && result != -ENODEV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 		goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 	result = asus_new_rfkill(asus, &asus->bluetooth,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 				 "asus-bluetooth", RFKILL_TYPE_BLUETOOTH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 				 ASUS_WMI_DEVID_BLUETOOTH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 	if (result && result != -ENODEV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 		goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 	result = asus_new_rfkill(asus, &asus->wimax, "asus-wimax",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 				 RFKILL_TYPE_WIMAX, ASUS_WMI_DEVID_WIMAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 	if (result && result != -ENODEV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 		goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 	result = asus_new_rfkill(asus, &asus->wwan3g, "asus-wwan3g",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 				 RFKILL_TYPE_WWAN, ASUS_WMI_DEVID_WWAN3G);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 	if (result && result != -ENODEV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 		goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 	result = asus_new_rfkill(asus, &asus->gps, "asus-gps",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 				 RFKILL_TYPE_GPS, ASUS_WMI_DEVID_GPS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 	if (result && result != -ENODEV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 		goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 	result = asus_new_rfkill(asus, &asus->uwb, "asus-uwb",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 				 RFKILL_TYPE_UWB, ASUS_WMI_DEVID_UWB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 	if (result && result != -ENODEV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 		goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 	if (!asus->driver->quirks->hotplug_wireless)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 		goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 	result = asus_setup_pci_hotplug(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 	 * If we get -EBUSY then something else is handling the PCI hotplug -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 	 * don't fail in this case
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 	if (result == -EBUSY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 		result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 	asus_register_rfkill_notifier(asus, "\\_SB.PCI0.P0P5");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 	asus_register_rfkill_notifier(asus, "\\_SB.PCI0.P0P6");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 	asus_register_rfkill_notifier(asus, "\\_SB.PCI0.P0P7");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 	 * Refresh pci hotplug in case the rfkill state was changed during
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 	 * setup.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 	asus_rfkill_hotplug(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 	if (result && result != -ENODEV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 		asus_wmi_rfkill_exit(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 	if (result == -ENODEV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 		result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) /* Quirks *********************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) static void asus_wmi_set_xusb2pr(struct asus_wmi *asus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 	struct pci_dev *xhci_pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 	u32 orig_ports_available;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 	u32 ports_available = asus->driver->quirks->xusb2pr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 	xhci_pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 			PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 			NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 	if (!xhci_pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 	pci_read_config_dword(xhci_pdev, USB_INTEL_XUSB2PR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 				&orig_ports_available);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 	pci_write_config_dword(xhci_pdev, USB_INTEL_XUSB2PR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 				cpu_to_le32(ports_available));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 	pr_info("set USB_INTEL_XUSB2PR old: 0x%04x, new: 0x%04x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 			orig_ports_available, ports_available);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220)  * Some devices dont support or have borcken get_als method
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221)  * but still support set method.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) static void asus_wmi_set_als(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 	asus_wmi_set_devstate(ASUS_WMI_DEVID_ALS_ENABLE, 1, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) /* Hwmon device ***************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) static int asus_agfn_fan_speed_read(struct asus_wmi *asus, int fan,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 					  int *speed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 	struct agfn_fan_args args = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 		.agfn.len = sizeof(args),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 		.agfn.mfun = ASUS_FAN_MFUN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 		.agfn.sfun = ASUS_FAN_SFUN_READ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 		.fan = fan,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 		.speed = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 	struct acpi_buffer input = { (acpi_size) sizeof(args), &args };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 	int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 	if (fan != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 	status = asus_wmi_evaluate_method_agfn(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 	if (status || args.agfn.err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 		return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 	if (speed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 		*speed = args.speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) static int asus_agfn_fan_speed_write(struct asus_wmi *asus, int fan,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 				     int *speed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 	struct agfn_fan_args args = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 		.agfn.len = sizeof(args),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 		.agfn.mfun = ASUS_FAN_MFUN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 		.agfn.sfun = ASUS_FAN_SFUN_WRITE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 		.fan = fan,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 		.speed = speed ?  *speed : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 	struct acpi_buffer input = { (acpi_size) sizeof(args), &args };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 	int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 	/* 1: for setting 1st fan's speed 0: setting auto mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 	if (fan != 1 && fan != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 	status = asus_wmi_evaluate_method_agfn(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 	if (status || args.agfn.err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 		return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 	if (speed && fan == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 		asus->agfn_pwm = *speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286)  * Check if we can read the speed of one fan. If true we assume we can also
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287)  * control it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) static bool asus_wmi_has_agfn_fan(struct asus_wmi *asus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 	int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 	int speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 	u32 value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 	status = asus_agfn_fan_speed_read(asus, 1, &speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 	if (status != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 	status = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_FAN_CTRL, &value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 	if (status != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 	 * We need to find a better way, probably using sfun,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 	 * bits or spec ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 	 * Currently we disable it if:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 	 * - ASUS_WMI_UNSUPPORTED_METHOD is returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 	 * - reverved bits are non-zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 	 * - sfun and presence bit are not set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 	return !(value == ASUS_WMI_UNSUPPORTED_METHOD || value & 0xFFF80000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 		 || (!asus->sfun && !(value & ASUS_WMI_DSTS_PRESENCE_BIT)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) static int asus_fan_set_auto(struct asus_wmi *asus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 	int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 	u32 retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 	switch (asus->fan_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 	case FAN_TYPE_SPEC83:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 		status = asus_wmi_set_devstate(ASUS_WMI_DEVID_CPU_FAN_CTRL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 					       0, &retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 		if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 			return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 		if (retval != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) 			return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 	case FAN_TYPE_AGFN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 		status = asus_agfn_fan_speed_write(asus, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 		if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) 			return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 		return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) static ssize_t pwm1_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 			       struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 			       char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 	struct asus_wmi *asus = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 	int value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 	/* If we already set a value then just return it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 	if (asus->agfn_pwm >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 		return sprintf(buf, "%d\n", asus->agfn_pwm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 	 * If we haven't set already set a value through the AGFN interface,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 	 * we read a current value through the (now-deprecated) FAN_CTRL device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 	err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_FAN_CTRL, &value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 	value &= 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) 	if (value == 1) /* Low Speed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 		value = 85;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) 	else if (value == 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 		value = 170;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 	else if (value == 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 		value = 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) 	else if (value) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 		pr_err("Unknown fan speed %#x\n", value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) 		value = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) 	return sprintf(buf, "%d\n", value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) static ssize_t pwm1_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) 				     struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 				     const char *buf, size_t count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 	struct asus_wmi *asus = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 	int value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 	int state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 	ret = kstrtouint(buf, 10, &value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) 	value = clamp(value, 0, 255);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) 	state = asus_agfn_fan_speed_write(asus, 1, &value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) 	if (state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) 		pr_warn("Setting fan speed failed: %d\n", state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 		asus->fan_pwm_mode = ASUS_FAN_CTRL_MANUAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) static ssize_t fan1_input_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 					struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) 					char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 	struct asus_wmi *asus = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 	int value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) 	switch (asus->fan_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) 	case FAN_TYPE_SPEC83:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 		ret = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_CPU_FAN_CTRL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) 					    &value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) 		if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) 		value &= 0xffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) 	case FAN_TYPE_AGFN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) 		/* no speed readable on manual mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) 		if (asus->fan_pwm_mode == ASUS_FAN_CTRL_MANUAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) 			return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) 		ret = asus_agfn_fan_speed_read(asus, 1, &value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) 			pr_warn("reading fan speed failed: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) 			return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 		return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) 	return sprintf(buf, "%d\n", value < 0 ? -1 : value*100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) static ssize_t pwm1_enable_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 						 struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) 						 char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) 	struct asus_wmi *asus = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) 	 * Just read back the cached pwm mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) 	 * For the CPU_FAN device, the spec indicates that we should be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) 	 * able to read the device status and consult bit 19 to see if we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) 	 * are in Full On or Automatic mode. However, this does not work
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) 	 * in practice on X532FL at least (the bit is always 0) and there's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) 	 * also nothing in the DSDT to indicate that this behaviour exists.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) 	return sprintf(buf, "%d\n", asus->fan_pwm_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) static ssize_t pwm1_enable_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) 						  struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) 						  const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) 	struct asus_wmi *asus = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) 	int status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) 	int state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) 	int value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) 	u32 retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) 	ret = kstrtouint(buf, 10, &state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) 	if (asus->fan_type == FAN_TYPE_SPEC83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) 		switch (state) { /* standard documented hwmon values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) 		case ASUS_FAN_CTRL_FULLSPEED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) 			value = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) 		case ASUS_FAN_CTRL_AUTO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) 			value = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) 		ret = asus_wmi_set_devstate(ASUS_WMI_DEVID_CPU_FAN_CTRL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) 					    value, &retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) 		if (retval != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) 			return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) 	} else if (asus->fan_type == FAN_TYPE_AGFN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) 		switch (state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) 		case ASUS_FAN_CTRL_MANUAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) 		case ASUS_FAN_CTRL_AUTO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) 			status = asus_fan_set_auto(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) 			if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) 				return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) 	asus->fan_pwm_mode = state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) static ssize_t fan1_label_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) 					  struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) 					  char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) 	return sprintf(buf, "%s\n", ASUS_FAN_DESC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) static ssize_t asus_hwmon_temp1(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) 				struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) 				char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) 	struct asus_wmi *asus = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) 	u32 value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) 	err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_THERMAL_CTRL, &value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) 	return sprintf(buf, "%ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) 		       deci_kelvin_to_millicelsius(value & 0xFFFF));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) /* Fan1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) static DEVICE_ATTR_RW(pwm1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) static DEVICE_ATTR_RW(pwm1_enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) static DEVICE_ATTR_RO(fan1_input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) static DEVICE_ATTR_RO(fan1_label);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) /* Temperature */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) static DEVICE_ATTR(temp1_input, S_IRUGO, asus_hwmon_temp1, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) static struct attribute *hwmon_attributes[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) 	&dev_attr_pwm1.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) 	&dev_attr_pwm1_enable.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) 	&dev_attr_fan1_input.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) 	&dev_attr_fan1_label.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) 	&dev_attr_temp1_input.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) 	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) static umode_t asus_hwmon_sysfs_is_visible(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) 					  struct attribute *attr, int idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) 	struct device *dev = container_of(kobj, struct device, kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) 	struct asus_wmi *asus = dev_get_drvdata(dev->parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) 	u32 value = ASUS_WMI_UNSUPPORTED_METHOD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) 	if (attr == &dev_attr_pwm1.attr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) 		if (asus->fan_type != FAN_TYPE_AGFN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) 	} else if (attr == &dev_attr_fan1_input.attr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) 	    || attr == &dev_attr_fan1_label.attr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) 	    || attr == &dev_attr_pwm1_enable.attr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) 		if (asus->fan_type == FAN_TYPE_NONE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) 	} else if (attr == &dev_attr_temp1_input.attr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) 		int err = asus_wmi_get_devstate(asus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) 						ASUS_WMI_DEVID_THERMAL_CTRL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) 						&value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) 			return 0; /* can't return negative here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) 		 * If the temperature value in deci-Kelvin is near the absolute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) 		 * zero temperature, something is clearly wrong
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) 		if (value == 0 || value == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) 	return attr->mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) static const struct attribute_group hwmon_attribute_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) 	.is_visible = asus_hwmon_sysfs_is_visible,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) 	.attrs = hwmon_attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) __ATTRIBUTE_GROUPS(hwmon_attribute);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) static int asus_wmi_hwmon_init(struct asus_wmi *asus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) 	struct device *dev = &asus->platform_device->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) 	struct device *hwmon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) 	hwmon = devm_hwmon_device_register_with_groups(dev, "asus", asus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) 			hwmon_attribute_groups);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) 	if (IS_ERR(hwmon)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) 		pr_err("Could not register asus hwmon device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) 		return PTR_ERR(hwmon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) static int asus_wmi_fan_init(struct asus_wmi *asus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) 	asus->fan_type = FAN_TYPE_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) 	asus->agfn_pwm = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) 	if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_CPU_FAN_CTRL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) 		asus->fan_type = FAN_TYPE_SPEC83;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) 	else if (asus_wmi_has_agfn_fan(asus))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) 		asus->fan_type = FAN_TYPE_AGFN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) 	if (asus->fan_type == FAN_TYPE_NONE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) 	asus_fan_set_auto(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) 	asus->fan_pwm_mode = ASUS_FAN_CTRL_AUTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) /* Fan mode *******************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) static int fan_boost_mode_check_present(struct asus_wmi *asus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) 	u32 result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) 	asus->fan_boost_mode_available = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) 	err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_FAN_BOOST_MODE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) 				    &result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) 		if (err == -ENODEV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) 	if ((result & ASUS_WMI_DSTS_PRESENCE_BIT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) 			(result & ASUS_FAN_BOOST_MODES_MASK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) 		asus->fan_boost_mode_available = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) 		asus->fan_boost_mode_mask = result & ASUS_FAN_BOOST_MODES_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) static int fan_boost_mode_write(struct asus_wmi *asus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) 	u8 value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) 	u32 retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) 	value = asus->fan_boost_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) 	pr_info("Set fan boost mode: %u\n", value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) 	err = asus_wmi_set_devstate(ASUS_WMI_DEVID_FAN_BOOST_MODE, value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) 				    &retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) 		pr_warn("Failed to set fan boost mode: %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) 	if (retval != 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) 		pr_warn("Failed to set fan boost mode (retval): 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) 			retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) static int fan_boost_mode_switch_next(struct asus_wmi *asus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) 	u8 mask = asus->fan_boost_mode_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) 	if (asus->fan_boost_mode == ASUS_FAN_BOOST_MODE_NORMAL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) 		if (mask & ASUS_FAN_BOOST_MODE_OVERBOOST_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) 			asus->fan_boost_mode = ASUS_FAN_BOOST_MODE_OVERBOOST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) 		else if (mask & ASUS_FAN_BOOST_MODE_SILENT_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) 			asus->fan_boost_mode = ASUS_FAN_BOOST_MODE_SILENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) 	} else if (asus->fan_boost_mode == ASUS_FAN_BOOST_MODE_OVERBOOST) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) 		if (mask & ASUS_FAN_BOOST_MODE_SILENT_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) 			asus->fan_boost_mode = ASUS_FAN_BOOST_MODE_SILENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) 			asus->fan_boost_mode = ASUS_FAN_BOOST_MODE_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) 		asus->fan_boost_mode = ASUS_FAN_BOOST_MODE_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) 	return fan_boost_mode_write(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) static ssize_t fan_boost_mode_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) 				   struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) 	struct asus_wmi *asus = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) 	return scnprintf(buf, PAGE_SIZE, "%d\n", asus->fan_boost_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) static ssize_t fan_boost_mode_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) 				    struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) 				    const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) 	u8 new_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) 	struct asus_wmi *asus = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) 	u8 mask = asus->fan_boost_mode_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) 	result = kstrtou8(buf, 10, &new_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) 	if (result < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) 		pr_warn("Trying to store invalid value\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) 		return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) 	if (new_mode == ASUS_FAN_BOOST_MODE_OVERBOOST) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) 		if (!(mask & ASUS_FAN_BOOST_MODE_OVERBOOST_MASK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) 	} else if (new_mode == ASUS_FAN_BOOST_MODE_SILENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) 		if (!(mask & ASUS_FAN_BOOST_MODE_SILENT_MASK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) 	} else if (new_mode != ASUS_FAN_BOOST_MODE_NORMAL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) 	asus->fan_boost_mode = new_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) 	fan_boost_mode_write(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) // Fan boost mode: 0 - normal, 1 - overboost, 2 - silent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) static DEVICE_ATTR_RW(fan_boost_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) /* Throttle thermal policy ****************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) static int throttle_thermal_policy_check_present(struct asus_wmi *asus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) 	u32 result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) 	asus->throttle_thermal_policy_available = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) 	err = asus_wmi_get_devstate(asus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) 				    ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) 				    &result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) 		if (err == -ENODEV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) 	if (result & ASUS_WMI_DSTS_PRESENCE_BIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) 		asus->throttle_thermal_policy_available = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) static int throttle_thermal_policy_write(struct asus_wmi *asus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) 	u8 value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) 	u32 retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) 	value = asus->throttle_thermal_policy_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) 	err = asus_wmi_set_devstate(ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) 				    value, &retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) 		pr_warn("Failed to set throttle thermal policy: %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) 	if (retval != 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) 		pr_warn("Failed to set throttle thermal policy (retval): 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) 			retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) static int throttle_thermal_policy_set_default(struct asus_wmi *asus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) 	if (!asus->throttle_thermal_policy_available)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) 	asus->throttle_thermal_policy_mode = ASUS_THROTTLE_THERMAL_POLICY_DEFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) 	return throttle_thermal_policy_write(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) static int throttle_thermal_policy_switch_next(struct asus_wmi *asus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) 	u8 new_mode = asus->throttle_thermal_policy_mode + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) 	if (new_mode > ASUS_THROTTLE_THERMAL_POLICY_SILENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) 		new_mode = ASUS_THROTTLE_THERMAL_POLICY_DEFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) 	asus->throttle_thermal_policy_mode = new_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) 	return throttle_thermal_policy_write(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) static ssize_t throttle_thermal_policy_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) 				   struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) 	struct asus_wmi *asus = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) 	u8 mode = asus->throttle_thermal_policy_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) 	return scnprintf(buf, PAGE_SIZE, "%d\n", mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) static ssize_t throttle_thermal_policy_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) 				    struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) 				    const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) 	u8 new_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) 	struct asus_wmi *asus = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) 	result = kstrtou8(buf, 10, &new_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) 	if (result < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) 		return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) 	if (new_mode > ASUS_THROTTLE_THERMAL_POLICY_SILENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) 	asus->throttle_thermal_policy_mode = new_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) 	throttle_thermal_policy_write(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) // Throttle thermal policy: 0 - default, 1 - overboost, 2 - silent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) static DEVICE_ATTR_RW(throttle_thermal_policy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) /* Backlight ******************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) static int read_backlight_power(struct asus_wmi *asus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) 	if (asus->driver->quirks->store_backlight_power)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) 		ret = !asus->driver->panel_power;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) 		ret = asus_wmi_get_devstate_simple(asus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) 						   ASUS_WMI_DEVID_BACKLIGHT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) 	return ret ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) static int read_brightness_max(struct asus_wmi *asus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) 	u32 retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) 	err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_BRIGHTNESS, &retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) 	retval = retval & ASUS_WMI_DSTS_MAX_BRIGTH_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) 	retval >>= 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) 	if (!retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) static int read_brightness(struct backlight_device *bd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) 	struct asus_wmi *asus = bl_get_data(bd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) 	u32 retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) 	err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_BRIGHTNESS, &retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) 	return retval & ASUS_WMI_DSTS_BRIGHTNESS_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) static u32 get_scalar_command(struct backlight_device *bd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) 	struct asus_wmi *asus = bl_get_data(bd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) 	u32 ctrl_param = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) 	if ((asus->driver->brightness < bd->props.brightness) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) 	    bd->props.brightness == bd->props.max_brightness)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) 		ctrl_param = 0x00008001;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) 	else if ((asus->driver->brightness > bd->props.brightness) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) 		 bd->props.brightness == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) 		ctrl_param = 0x00008000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) 	asus->driver->brightness = bd->props.brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) 	return ctrl_param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) static int update_bl_status(struct backlight_device *bd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) 	struct asus_wmi *asus = bl_get_data(bd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) 	u32 ctrl_param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) 	int power, err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) 	power = read_backlight_power(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) 	if (power != -ENODEV && bd->props.power != power) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) 		ctrl_param = !!(bd->props.power == FB_BLANK_UNBLANK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) 		err = asus_wmi_set_devstate(ASUS_WMI_DEVID_BACKLIGHT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) 					    ctrl_param, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) 		if (asus->driver->quirks->store_backlight_power)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) 			asus->driver->panel_power = bd->props.power;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) 		/* When using scalar brightness, updating the brightness
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) 		 * will mess with the backlight power */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) 		if (asus->driver->quirks->scalar_panel_brightness)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) 	if (asus->driver->quirks->scalar_panel_brightness)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) 		ctrl_param = get_scalar_command(bd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) 		ctrl_param = bd->props.brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) 	err = asus_wmi_set_devstate(ASUS_WMI_DEVID_BRIGHTNESS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) 				    ctrl_param, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) static const struct backlight_ops asus_wmi_bl_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) 	.get_brightness = read_brightness,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) 	.update_status = update_bl_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) static int asus_wmi_backlight_notify(struct asus_wmi *asus, int code)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) 	struct backlight_device *bd = asus->backlight_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) 	int old = bd->props.brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) 	int new = old;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) 	if (code >= NOTIFY_BRNUP_MIN && code <= NOTIFY_BRNUP_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) 		new = code - NOTIFY_BRNUP_MIN + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) 	else if (code >= NOTIFY_BRNDOWN_MIN && code <= NOTIFY_BRNDOWN_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) 		new = code - NOTIFY_BRNDOWN_MIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) 	bd->props.brightness = new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) 	backlight_update_status(bd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) 	backlight_force_update(bd, BACKLIGHT_UPDATE_HOTKEY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) 	return old;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) static int asus_wmi_backlight_init(struct asus_wmi *asus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) 	struct backlight_device *bd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) 	struct backlight_properties props;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) 	int max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) 	int power;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) 	max = read_brightness_max(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) 	if (max < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) 		return max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) 	power = read_backlight_power(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) 	if (power == -ENODEV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) 		power = FB_BLANK_UNBLANK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) 	else if (power < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) 		return power;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) 	memset(&props, 0, sizeof(struct backlight_properties));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) 	props.type = BACKLIGHT_PLATFORM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) 	props.max_brightness = max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) 	bd = backlight_device_register(asus->driver->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) 				       &asus->platform_device->dev, asus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) 				       &asus_wmi_bl_ops, &props);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) 	if (IS_ERR(bd)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) 		pr_err("Could not register backlight device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) 		return PTR_ERR(bd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) 	asus->backlight_device = bd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) 	if (asus->driver->quirks->store_backlight_power)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) 		asus->driver->panel_power = power;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) 	bd->props.brightness = read_brightness(bd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) 	bd->props.power = power;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) 	backlight_update_status(bd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) 	asus->driver->brightness = bd->props.brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) static void asus_wmi_backlight_exit(struct asus_wmi *asus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) 	backlight_device_unregister(asus->backlight_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) 	asus->backlight_device = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) static int is_display_toggle(int code)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) 	/* display toggle keys */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) 	if ((code >= 0x61 && code <= 0x67) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) 	    (code >= 0x8c && code <= 0x93) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) 	    (code >= 0xa0 && code <= 0xa7) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) 	    (code >= 0xd0 && code <= 0xd5))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) /* Fn-lock ********************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) static bool asus_wmi_has_fnlock_key(struct asus_wmi *asus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) 	u32 result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) 	asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_FNLOCK, &result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) 	return (result & ASUS_WMI_DSTS_PRESENCE_BIT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) 		!(result & ASUS_WMI_FNLOCK_BIOS_DISABLED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) static void asus_wmi_fnlock_update(struct asus_wmi *asus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) 	int mode = asus->fnlock_locked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) 	asus_wmi_set_devstate(ASUS_WMI_DEVID_FNLOCK, mode, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) /* WMI events *****************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) static int asus_wmi_get_event_code(u32 value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) 	struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) 	union acpi_object *obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) 	int code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) 	status = wmi_get_event_data(value, &response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) 	if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) 		pr_warn("Failed to get WMI notify code: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) 				acpi_format_exception(status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) 	obj = (union acpi_object *)response.pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) 	if (obj && obj->type == ACPI_TYPE_INTEGER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) 		code = (int)(obj->integer.value & WMI_EVENT_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) 		code = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) 	kfree(obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) 	return code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) static void asus_wmi_handle_event_code(int code, struct asus_wmi *asus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) 	unsigned int key_value = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) 	bool autorelease = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) 	int result, orig_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) 	orig_code = code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) 	if (asus->driver->key_filter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) 		asus->driver->key_filter(asus->driver, &code, &key_value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) 					 &autorelease);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) 		if (code == ASUS_WMI_KEY_IGNORE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) 	if (code >= NOTIFY_BRNUP_MIN && code <= NOTIFY_BRNUP_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) 		code = ASUS_WMI_BRN_UP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) 	else if (code >= NOTIFY_BRNDOWN_MIN && code <= NOTIFY_BRNDOWN_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) 		code = ASUS_WMI_BRN_DOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) 	if (code == ASUS_WMI_BRN_DOWN || code == ASUS_WMI_BRN_UP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) 		if (acpi_video_get_backlight_type() == acpi_backlight_vendor) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) 			asus_wmi_backlight_notify(asus, orig_code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) 	if (code == NOTIFY_KBD_BRTUP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) 		kbd_led_set_by_kbd(asus, asus->kbd_led_wk + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) 	if (code == NOTIFY_KBD_BRTDWN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) 		kbd_led_set_by_kbd(asus, asus->kbd_led_wk - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) 	if (code == NOTIFY_KBD_BRTTOGGLE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) 		if (asus->kbd_led_wk == asus->kbd_led.max_brightness)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) 			kbd_led_set_by_kbd(asus, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) 			kbd_led_set_by_kbd(asus, asus->kbd_led_wk + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) 	if (code == NOTIFY_FNLOCK_TOGGLE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) 		asus->fnlock_locked = !asus->fnlock_locked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) 		asus_wmi_fnlock_update(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) 	if (asus->driver->quirks->use_kbd_dock_devid && code == NOTIFY_KBD_DOCK_CHANGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) 		result = asus_wmi_get_devstate_simple(asus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) 						      ASUS_WMI_DEVID_KBD_DOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) 		if (result >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) 			input_report_switch(asus->inputdev, SW_TABLET_MODE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) 					    !result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) 			input_sync(asus->inputdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) 	if (asus->fan_boost_mode_available && code == NOTIFY_KBD_FBM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) 		fan_boost_mode_switch_next(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) 	if (asus->throttle_thermal_policy_available && code == NOTIFY_KBD_TTP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) 		throttle_thermal_policy_switch_next(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) 	if (is_display_toggle(code) && asus->driver->quirks->no_display_toggle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) 	if (!sparse_keymap_report_event(asus->inputdev, code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) 					key_value, autorelease))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) 		pr_info("Unknown key %x pressed\n", code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) static void asus_wmi_notify(u32 value, void *context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) 	struct asus_wmi *asus = context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) 	int code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) 	for (i = 0; i < WMI_EVENT_QUEUE_SIZE + 1; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) 		code = asus_wmi_get_event_code(value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) 		if (code < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) 			pr_warn("Failed to get notify code: %d\n", code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) 		if (code == WMI_EVENT_QUEUE_END || code == WMI_EVENT_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) 		asus_wmi_handle_event_code(code, asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) 		 * Double check that queue is present:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) 		 * ATK (with queue) uses 0xff, ASUSWMI (without) 0xd2.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) 		if (!asus->wmi_event_queue || value != WMI_EVENT_VALUE_ATK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) 	pr_warn("Failed to process event queue, last code: 0x%x\n", code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) static int asus_wmi_notify_queue_flush(struct asus_wmi *asus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) 	int code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) 	for (i = 0; i < WMI_EVENT_QUEUE_SIZE + 1; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) 		code = asus_wmi_get_event_code(WMI_EVENT_VALUE_ATK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) 		if (code < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) 			pr_warn("Failed to get event during flush: %d\n", code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) 			return code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) 		if (code == WMI_EVENT_QUEUE_END || code == WMI_EVENT_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) 	pr_warn("Failed to flush event queue\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) 	return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) /* Sysfs **********************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) static ssize_t store_sys_wmi(struct asus_wmi *asus, int devid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) 			     const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) 	u32 retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) 	int err, value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) 	value = asus_wmi_get_devstate_simple(asus, devid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) 	if (value < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) 		return value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) 	err = kstrtoint(buf, 0, &value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) 	err = asus_wmi_set_devstate(devid, value, &retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) static ssize_t show_sys_wmi(struct asus_wmi *asus, int devid, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) 	int value = asus_wmi_get_devstate_simple(asus, devid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) 	if (value < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) 		return value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) 	return sprintf(buf, "%d\n", value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) #define ASUS_WMI_CREATE_DEVICE_ATTR(_name, _mode, _cm)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) 	static ssize_t show_##_name(struct device *dev,			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) 				    struct device_attribute *attr,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) 				    char *buf)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) 	{								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) 		struct asus_wmi *asus = dev_get_drvdata(dev);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238) 		return show_sys_wmi(asus, _cm, buf);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) 	}								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) 	static ssize_t store_##_name(struct device *dev,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) 				     struct device_attribute *attr,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) 				     const char *buf, size_t count)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) 	{								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) 		struct asus_wmi *asus = dev_get_drvdata(dev);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) 		return store_sys_wmi(asus, _cm, buf, count);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) 	}								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248) 	static struct device_attribute dev_attr_##_name = {		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249) 		.attr = {						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250) 			.name = __stringify(_name),			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) 			.mode = _mode },				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252) 		.show   = show_##_name,					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) 		.store  = store_##_name,				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) ASUS_WMI_CREATE_DEVICE_ATTR(touchpad, 0644, ASUS_WMI_DEVID_TOUCHPAD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) ASUS_WMI_CREATE_DEVICE_ATTR(camera, 0644, ASUS_WMI_DEVID_CAMERA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) ASUS_WMI_CREATE_DEVICE_ATTR(cardr, 0644, ASUS_WMI_DEVID_CARDREADER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) ASUS_WMI_CREATE_DEVICE_ATTR(lid_resume, 0644, ASUS_WMI_DEVID_LID_RESUME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260) ASUS_WMI_CREATE_DEVICE_ATTR(als_enable, 0644, ASUS_WMI_DEVID_ALS_ENABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) static ssize_t cpufv_store(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) 			   const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265) 	int value, rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267) 	rv = kstrtoint(buf, 0, &value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) 	if (rv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269) 		return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) 	if (value < 0 || value > 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274) 	rv = asus_wmi_evaluate_method(ASUS_WMI_METHODID_CFVS, value, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275) 	if (rv < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) 		return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281) static DEVICE_ATTR_WO(cpufv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) static struct attribute *platform_attributes[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) 	&dev_attr_cpufv.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285) 	&dev_attr_camera.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) 	&dev_attr_cardr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287) 	&dev_attr_touchpad.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288) 	&dev_attr_lid_resume.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) 	&dev_attr_als_enable.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290) 	&dev_attr_fan_boost_mode.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) 	&dev_attr_throttle_thermal_policy.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) 	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) static umode_t asus_sysfs_is_visible(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) 				    struct attribute *attr, int idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) 	struct device *dev = container_of(kobj, struct device, kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) 	struct asus_wmi *asus = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) 	bool ok = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301) 	int devid = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) 	if (attr == &dev_attr_camera.attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) 		devid = ASUS_WMI_DEVID_CAMERA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) 	else if (attr == &dev_attr_cardr.attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) 		devid = ASUS_WMI_DEVID_CARDREADER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) 	else if (attr == &dev_attr_touchpad.attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) 		devid = ASUS_WMI_DEVID_TOUCHPAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309) 	else if (attr == &dev_attr_lid_resume.attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) 		devid = ASUS_WMI_DEVID_LID_RESUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) 	else if (attr == &dev_attr_als_enable.attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312) 		devid = ASUS_WMI_DEVID_ALS_ENABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) 	else if (attr == &dev_attr_fan_boost_mode.attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) 		ok = asus->fan_boost_mode_available;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315) 	else if (attr == &dev_attr_throttle_thermal_policy.attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) 		ok = asus->throttle_thermal_policy_available;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) 	if (devid != -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) 		ok = !(asus_wmi_get_devstate_simple(asus, devid) < 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) 	return ok ? attr->mode : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) static const struct attribute_group platform_attribute_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) 	.is_visible = asus_sysfs_is_visible,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) 	.attrs = platform_attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) static void asus_wmi_sysfs_exit(struct platform_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) 	sysfs_remove_group(&device->dev.kobj, &platform_attribute_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) static int asus_wmi_sysfs_init(struct platform_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) 	return sysfs_create_group(&device->dev.kobj, &platform_attribute_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) /* Platform device ************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) static int asus_wmi_platform_init(struct asus_wmi *asus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343) 	struct device *dev = &asus->platform_device->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) 	char *wmi_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) 	int rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347) 	/* INIT enable hotkeys on some models */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348) 	if (!asus_wmi_evaluate_method(ASUS_WMI_METHODID_INIT, 0, 0, &rv))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) 		pr_info("Initialization: %#x\n", rv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351) 	/* We don't know yet what to do with this version... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) 	if (!asus_wmi_evaluate_method(ASUS_WMI_METHODID_SPEC, 0, 0x9, &rv)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) 		pr_info("BIOS WMI version: %d.%d\n", rv >> 16, rv & 0xFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) 		asus->spec = rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) 	 * The SFUN method probably allows the original driver to get the list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) 	 * of features supported by a given model. For now, 0x0100 or 0x0800
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) 	 * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361) 	 * The significance of others is yet to be found.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) 	if (!asus_wmi_evaluate_method(ASUS_WMI_METHODID_SFUN, 0, 0, &rv)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) 		pr_info("SFUN value: %#x\n", rv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) 		asus->sfun = rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369) 	 * Eee PC and Notebooks seems to have different method_id for DSTS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) 	 * but it may also be related to the BIOS's SPEC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371) 	 * Note, on most Eeepc, there is no way to check if a method exist
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) 	 * or note, while on notebooks, they returns 0xFFFFFFFE on failure,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373) 	 * but once again, SPEC may probably be used for that kind of things.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) 	 * Additionally at least TUF Gaming series laptops return nothing for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) 	 * unknown methods, so the detection in this way is not possible.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378) 	 * There is strong indication that only ACPI WMI devices that have _UID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) 	 * equal to "ASUSWMI" use DCTS whereas those with "ATK" use DSTS.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) 	wmi_uid = wmi_get_acpi_device_uid(ASUS_WMI_MGMT_GUID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) 	if (!wmi_uid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385) 	if (!strcmp(wmi_uid, ASUS_ACPI_UID_ASUSWMI)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) 		dev_info(dev, "Detected ASUSWMI, use DCTS\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) 		asus->dsts_id = ASUS_WMI_METHODID_DCTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) 		dev_info(dev, "Detected %s, not ASUSWMI, use DSTS\n", wmi_uid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390) 		asus->dsts_id = ASUS_WMI_METHODID_DSTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394) 	 * Some devices can have multiple event codes stored in a queue before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) 	 * the module load if it was unloaded intermittently after calling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396) 	 * the INIT method (enables event handling). The WMI notify handler is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) 	 * expected to retrieve all event codes until a retrieved code equals
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) 	 * queue end marker (One or Ones). Old codes are flushed from the queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399) 	 * upon module load. Not enabling this when it should be has minimal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400) 	 * visible impact so fall back if anything goes wrong.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402) 	wmi_uid = wmi_get_acpi_device_uid(asus->driver->event_guid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) 	if (wmi_uid && !strcmp(wmi_uid, ASUS_ACPI_UID_ATK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404) 		dev_info(dev, "Detected ATK, enable event queue\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406) 		if (!asus_wmi_notify_queue_flush(asus))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407) 			asus->wmi_event_queue = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410) 	/* CWAP allow to define the behavior of the Fn+F2 key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411) 	 * this method doesn't seems to be present on Eee PCs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412) 	if (asus->driver->quirks->wapf >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413) 		asus_wmi_set_devstate(ASUS_WMI_DEVID_CWAP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414) 				      asus->driver->quirks->wapf, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419) /* debugfs ********************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421) struct asus_wmi_debugfs_node {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422) 	struct asus_wmi *asus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423) 	char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424) 	int (*show) (struct seq_file *m, void *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427) static int show_dsts(struct seq_file *m, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429) 	struct asus_wmi *asus = m->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431) 	u32 retval = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) 	err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) 	seq_printf(m, "DSTS(%#x) = %#x\n", asus->debug.dev_id, retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) static int show_devs(struct seq_file *m, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444) 	struct asus_wmi *asus = m->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) 	u32 retval = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) 	err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449) 				    &retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453) 	seq_printf(m, "DEVS(%#x, %#x) = %#x\n", asus->debug.dev_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) 		   asus->debug.ctrl_param, retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459) static int show_call(struct seq_file *m, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461) 	struct asus_wmi *asus = m->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462) 	struct bios_args args = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463) 		.arg0 = asus->debug.dev_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) 		.arg1 = asus->debug.ctrl_param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) 	struct acpi_buffer input = { (acpi_size) sizeof(args), &args };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) 	struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468) 	union acpi_object *obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471) 	status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472) 				     0, asus->debug.method_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473) 				     &input, &output);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475) 	if (ACPI_FAILURE(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) 	obj = (union acpi_object *)output.pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) 	if (obj && obj->type == ACPI_TYPE_INTEGER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480) 		seq_printf(m, "%#x(%#x, %#x) = %#x\n", asus->debug.method_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481) 			   asus->debug.dev_id, asus->debug.ctrl_param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482) 			   (u32) obj->integer.value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484) 		seq_printf(m, "%#x(%#x, %#x) = t:%d\n", asus->debug.method_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) 			   asus->debug.dev_id, asus->debug.ctrl_param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486) 			   obj ? obj->type : -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) 	kfree(obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493) static struct asus_wmi_debugfs_node asus_wmi_debug_files[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494) 	{NULL, "devs", show_devs},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495) 	{NULL, "dsts", show_dsts},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) 	{NULL, "call", show_call},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) static int asus_wmi_debugfs_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501) 	struct asus_wmi_debugfs_node *node = inode->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503) 	return single_open(file, node->show, node->asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506) static const struct file_operations asus_wmi_debugfs_io_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507) 	.owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508) 	.open = asus_wmi_debugfs_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509) 	.read = seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510) 	.llseek = seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511) 	.release = single_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514) static void asus_wmi_debugfs_exit(struct asus_wmi *asus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516) 	debugfs_remove_recursive(asus->debug.root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519) static void asus_wmi_debugfs_init(struct asus_wmi *asus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523) 	asus->debug.root = debugfs_create_dir(asus->driver->name, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525) 	debugfs_create_x32("method_id", S_IRUGO | S_IWUSR, asus->debug.root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526) 			   &asus->debug.method_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528) 	debugfs_create_x32("dev_id", S_IRUGO | S_IWUSR, asus->debug.root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529) 			   &asus->debug.dev_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531) 	debugfs_create_x32("ctrl_param", S_IRUGO | S_IWUSR, asus->debug.root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532) 			   &asus->debug.ctrl_param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534) 	for (i = 0; i < ARRAY_SIZE(asus_wmi_debug_files); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535) 		struct asus_wmi_debugfs_node *node = &asus_wmi_debug_files[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537) 		node->asus = asus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538) 		debugfs_create_file(node->name, S_IFREG | S_IRUGO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539) 				    asus->debug.root, node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540) 				    &asus_wmi_debugfs_io_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544) /* Init / exit ****************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546) static int asus_wmi_add(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548) 	struct platform_driver *pdrv = to_platform_driver(pdev->dev.driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549) 	struct asus_wmi_driver *wdrv = to_asus_wmi_driver(pdrv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550) 	struct asus_wmi *asus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551) 	const char *chassis_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552) 	acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554) 	u32 result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556) 	asus = kzalloc(sizeof(struct asus_wmi), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557) 	if (!asus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560) 	asus->driver = wdrv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561) 	asus->platform_device = pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562) 	wdrv->platform_device = pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563) 	platform_set_drvdata(asus->platform_device, asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565) 	if (wdrv->detect_quirks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566) 		wdrv->detect_quirks(asus->driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568) 	err = asus_wmi_platform_init(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570) 		goto fail_platform;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572) 	err = fan_boost_mode_check_present(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574) 		goto fail_fan_boost_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576) 	err = throttle_thermal_policy_check_present(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578) 		goto fail_throttle_thermal_policy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580) 		throttle_thermal_policy_set_default(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582) 	err = asus_wmi_sysfs_init(asus->platform_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584) 		goto fail_sysfs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586) 	err = asus_wmi_input_init(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588) 		goto fail_input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590) 	err = asus_wmi_fan_init(asus); /* probably no problems on error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592) 	err = asus_wmi_hwmon_init(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594) 		goto fail_hwmon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596) 	err = asus_wmi_led_init(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598) 		goto fail_leds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2600) 	asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_WLAN, &result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2601) 	if (result & (ASUS_WMI_DSTS_PRESENCE_BIT | ASUS_WMI_DSTS_USER_BIT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2602) 		asus->driver->wlan_ctrl_by_user = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604) 	if (!(asus->driver->wlan_ctrl_by_user && ashs_present())) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605) 		err = asus_wmi_rfkill_init(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607) 			goto fail_rfkill;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610) 	if (asus->driver->quirks->wmi_force_als_set)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611) 		asus_wmi_set_als();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613) 	/* Some Asus desktop boards export an acpi-video backlight interface,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614) 	   stop this from showing up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2615) 	chassis_type = dmi_get_system_info(DMI_CHASSIS_TYPE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2616) 	if (chassis_type && !strcmp(chassis_type, "3"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2617) 		acpi_video_set_dmi_backlight_type(acpi_backlight_vendor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2619) 	if (asus->driver->quirks->wmi_backlight_power)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2620) 		acpi_video_set_dmi_backlight_type(acpi_backlight_vendor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2621) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2622) 	if (asus->driver->quirks->wmi_backlight_native)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2623) 		acpi_video_set_dmi_backlight_type(acpi_backlight_native);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2624) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2625) 	if (asus->driver->quirks->xusb2pr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2626) 		asus_wmi_set_xusb2pr(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2628) 	if (acpi_video_get_backlight_type() == acpi_backlight_vendor) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2629) 		err = asus_wmi_backlight_init(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2630) 		if (err && err != -ENODEV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2631) 			goto fail_backlight;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2632) 	} else if (asus->driver->quirks->wmi_backlight_set_devstate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2633) 		err = asus_wmi_set_devstate(ASUS_WMI_DEVID_BACKLIGHT, 2, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2635) 	if (asus_wmi_has_fnlock_key(asus)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2636) 		asus->fnlock_locked = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2637) 		asus_wmi_fnlock_update(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2638) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2639) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2640) 	status = wmi_install_notify_handler(asus->driver->event_guid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2641) 					    asus_wmi_notify, asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2642) 	if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2643) 		pr_err("Unable to register notify handler - %d\n", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2644) 		err = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2645) 		goto fail_wmi_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2646) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2647) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2648) 	asus_wmi_battery_init(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2649) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2650) 	asus_wmi_debugfs_init(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2651) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2652) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2653) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2654) fail_wmi_handler:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2655) 	asus_wmi_backlight_exit(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2656) fail_backlight:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2657) 	asus_wmi_rfkill_exit(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2658) fail_rfkill:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2659) 	asus_wmi_led_exit(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2660) fail_leds:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2661) fail_hwmon:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2662) 	asus_wmi_input_exit(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2663) fail_input:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2664) 	asus_wmi_sysfs_exit(asus->platform_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2665) fail_sysfs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2666) fail_throttle_thermal_policy:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2667) fail_fan_boost_mode:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2668) fail_platform:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2669) 	kfree(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2670) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2671) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2672) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2673) static int asus_wmi_remove(struct platform_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2674) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2675) 	struct asus_wmi *asus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2677) 	asus = platform_get_drvdata(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2678) 	wmi_remove_notify_handler(asus->driver->event_guid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2679) 	asus_wmi_backlight_exit(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2680) 	asus_wmi_input_exit(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2681) 	asus_wmi_led_exit(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2682) 	asus_wmi_rfkill_exit(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2683) 	asus_wmi_debugfs_exit(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2684) 	asus_wmi_sysfs_exit(asus->platform_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2685) 	asus_fan_set_auto(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2686) 	asus_wmi_battery_exit(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2687) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2688) 	kfree(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2689) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2690) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2692) /* Platform driver - hibernate/resume callbacks *******************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2693) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2694) static int asus_hotk_thaw(struct device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2695) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2696) 	struct asus_wmi *asus = dev_get_drvdata(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2698) 	if (asus->wlan.rfkill) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2699) 		bool wlan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2700) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2701) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2702) 		 * Work around bios bug - acpi _PTS turns off the wireless led
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2703) 		 * during suspend.  Normally it restores it on resume, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2704) 		 * we should kick it ourselves in case hibernation is aborted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2705) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2706) 		wlan = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_WLAN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2707) 		asus_wmi_set_devstate(ASUS_WMI_DEVID_WLAN, wlan, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2708) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2709) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2710) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2711) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2713) static int asus_hotk_resume(struct device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2714) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2715) 	struct asus_wmi *asus = dev_get_drvdata(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2716) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2717) 	if (!IS_ERR_OR_NULL(asus->kbd_led.dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2718) 		kbd_led_update(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2720) 	if (asus_wmi_has_fnlock_key(asus))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2721) 		asus_wmi_fnlock_update(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2722) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2723) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2724) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2725) static int asus_hotk_restore(struct device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2726) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2727) 	struct asus_wmi *asus = dev_get_drvdata(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2728) 	int bl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2730) 	/* Refresh both wlan rfkill state and pci hotplug */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2731) 	if (asus->wlan.rfkill)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2732) 		asus_rfkill_hotplug(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2733) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2734) 	if (asus->bluetooth.rfkill) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2735) 		bl = !asus_wmi_get_devstate_simple(asus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2736) 						   ASUS_WMI_DEVID_BLUETOOTH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2737) 		rfkill_set_sw_state(asus->bluetooth.rfkill, bl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2738) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2739) 	if (asus->wimax.rfkill) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2740) 		bl = !asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_WIMAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2741) 		rfkill_set_sw_state(asus->wimax.rfkill, bl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2742) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2743) 	if (asus->wwan3g.rfkill) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2744) 		bl = !asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_WWAN3G);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2745) 		rfkill_set_sw_state(asus->wwan3g.rfkill, bl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2746) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2747) 	if (asus->gps.rfkill) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2748) 		bl = !asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_GPS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2749) 		rfkill_set_sw_state(asus->gps.rfkill, bl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2750) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2751) 	if (asus->uwb.rfkill) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2752) 		bl = !asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_UWB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2753) 		rfkill_set_sw_state(asus->uwb.rfkill, bl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2754) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2755) 	if (!IS_ERR_OR_NULL(asus->kbd_led.dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2756) 		kbd_led_update(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2757) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2758) 	if (asus_wmi_has_fnlock_key(asus))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2759) 		asus_wmi_fnlock_update(asus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2760) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2761) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2762) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2763) static const struct dev_pm_ops asus_pm_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2764) 	.thaw = asus_hotk_thaw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2765) 	.restore = asus_hotk_restore,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2766) 	.resume = asus_hotk_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2767) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2768) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2769) /* Registration ***************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2770) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2771) static int asus_wmi_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2772) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2773) 	struct platform_driver *pdrv = to_platform_driver(pdev->dev.driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2774) 	struct asus_wmi_driver *wdrv = to_asus_wmi_driver(pdrv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2775) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2777) 	if (!wmi_has_guid(ASUS_WMI_MGMT_GUID)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2778) 		pr_warn("ASUS Management GUID not found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2779) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2780) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2781) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2782) 	if (wdrv->event_guid && !wmi_has_guid(wdrv->event_guid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2783) 		pr_warn("ASUS Event GUID not found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2784) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2785) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2786) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2787) 	if (wdrv->probe) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2788) 		ret = wdrv->probe(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2789) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2790) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2791) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2792) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2793) 	return asus_wmi_add(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2794) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2795) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2796) static bool used;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2797) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2798) int __init_or_module asus_wmi_register_driver(struct asus_wmi_driver *driver)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2799) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2800) 	struct platform_driver *platform_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2801) 	struct platform_device *platform_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2802) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2803) 	if (used)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2804) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2805) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2806) 	platform_driver = &driver->platform_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2807) 	platform_driver->remove = asus_wmi_remove;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2808) 	platform_driver->driver.owner = driver->owner;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2809) 	platform_driver->driver.name = driver->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2810) 	platform_driver->driver.pm = &asus_pm_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2811) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2812) 	platform_device = platform_create_bundle(platform_driver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2813) 						 asus_wmi_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2814) 						 NULL, 0, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2815) 	if (IS_ERR(platform_device))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2816) 		return PTR_ERR(platform_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2817) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2818) 	used = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2819) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2820) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2821) EXPORT_SYMBOL_GPL(asus_wmi_register_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2822) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2823) void asus_wmi_unregister_driver(struct asus_wmi_driver *driver)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2824) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2825) 	platform_device_unregister(driver->platform_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2826) 	platform_driver_unregister(&driver->platform_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2827) 	used = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2828) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2829) EXPORT_SYMBOL_GPL(asus_wmi_unregister_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2830) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2831) static int __init asus_wmi_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2832) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2833) 	pr_info("ASUS WMI generic driver loaded\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2834) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2835) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2836) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2837) static void __exit asus_wmi_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2838) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2839) 	pr_info("ASUS WMI generic driver unloaded\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2840) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2841) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2842) module_init(asus_wmi_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2843) module_exit(asus_wmi_exit);