11a59d1b8SThomas Gleixner// SPDX-License-Identifier: GPL-2.0-or-later
299b38b4aSDave Airlie/*
399b38b4aSDave Airlie * MXM WMI driver
499b38b4aSDave Airlie *
599b38b4aSDave Airlie * Copyright(C) 2010 Red Hat.
699b38b4aSDave Airlie */
799b38b4aSDave Airlie#include <linux/kernel.h>
899b38b4aSDave Airlie#include <linux/module.h>
999b38b4aSDave Airlie#include <linux/init.h>
10475879d6SRashika Kheria#include <linux/mxm-wmi.h>
118b48463fSLv Zheng#include <linux/acpi.h>
1299b38b4aSDave Airlie
1399b38b4aSDave AirlieMODULE_AUTHOR("Dave Airlie");
1499b38b4aSDave AirlieMODULE_DESCRIPTION("MXM WMI Driver");
1599b38b4aSDave AirlieMODULE_LICENSE("GPL");
1699b38b4aSDave Airlie
1799b38b4aSDave Airlie#define MXM_WMMX_GUID "F6CB5C3C-9CAE-4EBD-B577-931EA32A2CC0"
1899b38b4aSDave Airlie
1999b38b4aSDave AirlieMODULE_ALIAS("wmi:"MXM_WMMX_GUID);
2099b38b4aSDave Airlie
2199b38b4aSDave Airlie#define MXM_WMMX_FUNC_MXDS 0x5344584D /* "MXDS" */
22000703f4SDave Airlie#define MXM_WMMX_FUNC_MXMX 0x53445344 /* "MXMX" */
2399b38b4aSDave Airlie
2499b38b4aSDave Airliestruct mxds_args {
2599b38b4aSDave Airlie	u32 func;
2699b38b4aSDave Airlie	u32 args;
2799b38b4aSDave Airlie	u32 xarg;
2899b38b4aSDave Airlie};
2999b38b4aSDave Airlie
3099b38b4aSDave Airlieint mxm_wmi_call_mxds(int adapter)
3199b38b4aSDave Airlie{
3299b38b4aSDave Airlie	struct mxds_args args = {
3399b38b4aSDave Airlie		.func = MXM_WMMX_FUNC_MXDS,
3499b38b4aSDave Airlie		.args = 0,
3599b38b4aSDave Airlie		.xarg = 1,
3699b38b4aSDave Airlie	};
3799b38b4aSDave Airlie	struct acpi_buffer input = { (acpi_size)sizeof(args), &args };
3899b38b4aSDave Airlie	struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
3999b38b4aSDave Airlie	acpi_status status;
4099b38b4aSDave Airlie
4199b38b4aSDave Airlie	printk("calling mux switch %d\n", adapter);
42000703f4SDave Airlie
43f85a43b9SPali Rohár	status = wmi_evaluate_method(MXM_WMMX_GUID, 0x0, adapter, &input,
4499b38b4aSDave Airlie				     &output);
4599b38b4aSDave Airlie
4699b38b4aSDave Airlie	if (ACPI_FAILURE(status))
4799b38b4aSDave Airlie		return status;
4899b38b4aSDave Airlie
4999b38b4aSDave Airlie	printk("mux switched %d\n", status);
5099b38b4aSDave Airlie	return 0;
5199b38b4aSDave Airlie
5299b38b4aSDave Airlie}
5399b38b4aSDave AirlieEXPORT_SYMBOL_GPL(mxm_wmi_call_mxds);
5499b38b4aSDave Airlie
55000703f4SDave Airlieint mxm_wmi_call_mxmx(int adapter)
56000703f4SDave Airlie{
57000703f4SDave Airlie	struct mxds_args args = {
58000703f4SDave Airlie		.func = MXM_WMMX_FUNC_MXMX,
59000703f4SDave Airlie		.args = 0,
60000703f4SDave Airlie		.xarg = 1,
61000703f4SDave Airlie	};
62000703f4SDave Airlie	struct acpi_buffer input = { (acpi_size)sizeof(args), &args };
63000703f4SDave Airlie	struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
64000703f4SDave Airlie	acpi_status status;
65000703f4SDave Airlie
66000703f4SDave Airlie	printk("calling mux switch %d\n", adapter);
67000703f4SDave Airlie
68f85a43b9SPali Rohár	status = wmi_evaluate_method(MXM_WMMX_GUID, 0x0, adapter, &input,
69000703f4SDave Airlie				     &output);
70000703f4SDave Airlie
71000703f4SDave Airlie	if (ACPI_FAILURE(status))
72000703f4SDave Airlie		return status;
73000703f4SDave Airlie
74000703f4SDave Airlie	printk("mux mutex set switched %d\n", status);
75000703f4SDave Airlie	return 0;
76000703f4SDave Airlie
77000703f4SDave Airlie}
78000703f4SDave AirlieEXPORT_SYMBOL_GPL(mxm_wmi_call_mxmx);
79000703f4SDave Airlie
8099b38b4aSDave Airliebool mxm_wmi_supported(void)
8199b38b4aSDave Airlie{
8299b38b4aSDave Airlie	bool guid_valid;
8399b38b4aSDave Airlie	guid_valid = wmi_has_guid(MXM_WMMX_GUID);
8499b38b4aSDave Airlie	return guid_valid;
8599b38b4aSDave Airlie}
8699b38b4aSDave AirlieEXPORT_SYMBOL_GPL(mxm_wmi_supported);
8799b38b4aSDave Airlie
8899b38b4aSDave Airliestatic int __init mxm_wmi_init(void)
8999b38b4aSDave Airlie{
9099b38b4aSDave Airlie	return 0;
9199b38b4aSDave Airlie}
9299b38b4aSDave Airlie
9399b38b4aSDave Airliestatic void __exit mxm_wmi_exit(void)
9499b38b4aSDave Airlie{
9599b38b4aSDave Airlie}
9699b38b4aSDave Airlie
9799b38b4aSDave Airliemodule_init(mxm_wmi_init);
9899b38b4aSDave Airliemodule_exit(mxm_wmi_exit);
99