summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/ABI/testing/sysfs-platform-intel-ifs17
-rw-r--r--Documentation/ABI/testing/sysfs-platform-mellanox-bootctl7
-rw-r--r--MAINTAINERS15
-rw-r--r--arch/x86/include/asm/msr-index.h2
-rw-r--r--drivers/platform/mellanox/mlxbf-bootctl.c87
-rw-r--r--drivers/platform/mellanox/mlxbf-bootctl.h6
-rw-r--r--drivers/platform/olpc/olpc-xo175-ec.c1
-rw-r--r--drivers/platform/surface/surface_aggregator_registry.c2
-rw-r--r--drivers/platform/surface/surface_aggregator_tabletsw.c180
-rw-r--r--drivers/platform/x86/Kconfig42
-rw-r--r--drivers/platform/x86/Makefile5
-rw-r--r--drivers/platform/x86/acer-wmi.c5
-rw-r--r--drivers/platform/x86/acerhdf.c2
-rw-r--r--drivers/platform/x86/adv_swbutton.c6
-rw-r--r--drivers/platform/x86/amd/Kconfig2
-rw-r--r--drivers/platform/x86/amd/hsmp.c6
-rw-r--r--drivers/platform/x86/amd/pmc.c170
-rw-r--r--drivers/platform/x86/amd/pmf/Kconfig1
-rw-r--r--drivers/platform/x86/amd/pmf/core.c27
-rw-r--r--drivers/platform/x86/amilo-rfkill.c5
-rw-r--r--drivers/platform/x86/apple-gmux.c404
-rw-r--r--drivers/platform/x86/barco-p50-gpio.c6
-rw-r--r--drivers/platform/x86/classmate-laptop.c2
-rw-r--r--drivers/platform/x86/compal-laptop.c8
-rw-r--r--drivers/platform/x86/dell/dcdbas.c6
-rw-r--r--drivers/platform/x86/dell/dell-laptop.c42
-rw-r--r--drivers/platform/x86/dell/dell-smbios.h2
-rw-r--r--drivers/platform/x86/dell/dell-smo8800.c5
-rw-r--r--drivers/platform/x86/hp/hp_accel.c5
-rw-r--r--drivers/platform/x86/hp/tc1100-wmi.c6
-rw-r--r--drivers/platform/x86/huawei-wmi.c6
-rw-r--r--drivers/platform/x86/ideapad-laptop.c141
-rw-r--r--drivers/platform/x86/ideapad-laptop.h152
-rw-r--r--drivers/platform/x86/intel/Kconfig10
-rw-r--r--drivers/platform/x86/intel/Makefile2
-rw-r--r--drivers/platform/x86/intel/bxtwc_tmu.c5
-rw-r--r--drivers/platform/x86/intel/bytcrc_pwrsrc.c181
-rw-r--r--drivers/platform/x86/intel/chtdc_ti_pwrbtn.c5
-rw-r--r--drivers/platform/x86/intel/chtwc_int33fe.c6
-rw-r--r--drivers/platform/x86/intel/hid.c10
-rw-r--r--drivers/platform/x86/intel/ifs/core.c81
-rw-r--r--drivers/platform/x86/intel/ifs/ifs.h68
-rw-r--r--drivers/platform/x86/intel/ifs/load.c9
-rw-r--r--drivers/platform/x86/intel/ifs/runtest.c94
-rw-r--r--drivers/platform/x86/intel/ifs/sysfs.c21
-rw-r--r--drivers/platform/x86/intel/int0002_vgpio.c5
-rw-r--r--drivers/platform/x86/intel/int1092/intel_sar.c5
-rw-r--r--drivers/platform/x86/intel/int3472/discrete.c6
-rw-r--r--drivers/platform/x86/intel/mrfld_pwrbtn.c5
-rw-r--r--drivers/platform/x86/intel/pmc/core.c5
-rw-r--r--drivers/platform/x86/intel/pmc/mtl.c31
-rw-r--r--drivers/platform/x86/intel/pmt/class.c6
-rw-r--r--drivers/platform/x86/intel/pmt/crashlog.c1
-rw-r--r--drivers/platform/x86/intel/pmt/telemetry.c3
-rw-r--r--drivers/platform/x86/intel/sdsi.c2
-rw-r--r--drivers/platform/x86/intel/speed_select_if/Kconfig4
-rw-r--r--drivers/platform/x86/intel/speed_select_if/Makefile2
-rw-r--r--drivers/platform/x86/intel/speed_select_if/isst_if_common.c47
-rw-r--r--drivers/platform/x86/intel/speed_select_if/isst_if_common.h8
-rw-r--r--drivers/platform/x86/intel/speed_select_if/isst_tpmi.c72
-rw-r--r--drivers/platform/x86/intel/speed_select_if/isst_tpmi_core.c1440
-rw-r--r--drivers/platform/x86/intel/speed_select_if/isst_tpmi_core.h18
-rw-r--r--drivers/platform/x86/intel/telemetry/pltdrv.c5
-rw-r--r--drivers/platform/x86/intel/uncore-frequency/uncore-frequency.c7
-rw-r--r--drivers/platform/x86/intel/vbtn.c10
-rw-r--r--drivers/platform/x86/intel/vsec.c75
-rw-r--r--drivers/platform/x86/intel/vsec.h9
-rw-r--r--drivers/platform/x86/lenovo-ymc.c187
-rw-r--r--drivers/platform/x86/msi-ec.c897
-rw-r--r--drivers/platform/x86/msi-ec.h122
-rw-r--r--drivers/platform/x86/pcengines-apuv2.c1
-rw-r--r--drivers/platform/x86/peaq-wmi.c128
-rw-r--r--drivers/platform/x86/samsung-q10.c6
-rw-r--r--drivers/platform/x86/serial-multi-instantiate.c6
-rw-r--r--drivers/platform/x86/sony-laptop.c2
-rw-r--r--drivers/platform/x86/think-lmi.c49
-rw-r--r--drivers/platform/x86/thinkpad_acpi.c16
-rw-r--r--drivers/platform/x86/wmi.c6
-rw-r--r--drivers/platform/x86/x86-android-tablets.c1803
-rw-r--r--drivers/platform/x86/x86-android-tablets/Kconfig21
-rw-r--r--drivers/platform/x86/x86-android-tablets/Makefile9
-rw-r--r--drivers/platform/x86/x86-android-tablets/asus.c325
-rw-r--r--drivers/platform/x86/x86-android-tablets/core.c391
-rw-r--r--drivers/platform/x86/x86-android-tablets/dmi.c165
-rw-r--r--drivers/platform/x86/x86-android-tablets/lenovo.c679
-rw-r--r--drivers/platform/x86/x86-android-tablets/other.c522
-rw-r--r--drivers/platform/x86/x86-android-tablets/shared-psy-info.c100
-rw-r--r--drivers/platform/x86/x86-android-tablets/shared-psy-info.h32
-rw-r--r--drivers/platform/x86/x86-android-tablets/x86-android-tablets.h108
-rw-r--r--drivers/platform/x86/xo1-rfkill.c5
-rw-r--r--drivers/video/backlight/Kconfig1
-rw-r--r--drivers/video/backlight/apple_bl.c31
-rw-r--r--include/linux/apple-gmux.h72
-rw-r--r--include/linux/apple_bl.h27
-rw-r--r--include/uapi/linux/isst_if.h303
-rw-r--r--tools/power/x86/intel-speed-select/Build2
-rw-r--r--tools/power/x86/intel-speed-select/isst-config.c769
-rw-r--r--tools/power/x86/intel-speed-select/isst-core-mbox.c1066
-rw-r--r--tools/power/x86/intel-speed-select/isst-core-tpmi.c787
-rw-r--r--tools/power/x86/intel-speed-select/isst-core.c846
-rw-r--r--tools/power/x86/intel-speed-select/isst-daemon.c38
-rw-r--r--tools/power/x86/intel-speed-select/isst-display.c245
-rw-r--r--tools/power/x86/intel-speed-select/isst.h96
103 files changed, 9613 insertions, 3881 deletions
diff --git a/Documentation/ABI/testing/sysfs-platform-intel-ifs b/Documentation/ABI/testing/sysfs-platform-intel-ifs
index 55991983d0d0..41b4d5b1e21c 100644
--- a/Documentation/ABI/testing/sysfs-platform-intel-ifs
+++ b/Documentation/ABI/testing/sysfs-platform-intel-ifs
@@ -1,3 +1,7 @@
+Device instance to test mapping
+intel_ifs_0 -> Scan Test
+intel_ifs_1 -> Array BIST test
+
What: /sys/devices/virtual/misc/intel_ifs_<N>/run_test
Date: Nov 16 2022
KernelVersion: 6.2
@@ -8,6 +12,7 @@ Description: Write <cpu#> to trigger IFS test for one online core.
completes the test for the core containing that thread.
Example: to test the core containing cpu5: echo 5 >
/sys/devices/virtual/misc/intel_ifs_<N>/run_test
+Devices: all
What: /sys/devices/virtual/misc/intel_ifs_<N>/status
Date: Nov 16 2022
@@ -15,21 +20,25 @@ KernelVersion: 6.2
Contact: "Jithu Joseph" <jithu.joseph@intel.com>
Description: The status of the last test. It can be one of "pass", "fail"
or "untested".
+Devices: all
What: /sys/devices/virtual/misc/intel_ifs_<N>/details
Date: Nov 16 2022
KernelVersion: 6.2
Contact: "Jithu Joseph" <jithu.joseph@intel.com>
Description: Additional information regarding the last test. The details file reports
- the hex value of the SCAN_STATUS MSR. Note that the error_code field
+ the hex value of the STATUS MSR for this test. Note that the error_code field
may contain driver defined software code not defined in the Intel SDM.
+Devices: all
What: /sys/devices/virtual/misc/intel_ifs_<N>/image_version
Date: Nov 16 2022
KernelVersion: 6.2
Contact: "Jithu Joseph" <jithu.joseph@intel.com>
-Description: Version (hexadecimal) of loaded IFS binary image. If no scan image
- is loaded reports "none".
+Description: Version (hexadecimal) of loaded IFS test image. If no test image
+ is loaded reports "none". Only present for device instances where a test image
+ is applicable.
+Devices: intel_ifs_0
What: /sys/devices/virtual/misc/intel_ifs_<N>/current_batch
Date: Nov 16 2022
@@ -39,3 +48,5 @@ Description: Write a number less than or equal to 0xff to load an IFS test image
The number written treated as the 2 digit suffix in the following file name:
/lib/firmware/intel/ifs_<N>/ff-mm-ss-02x.scan
Reading the file will provide the suffix of the currently loaded IFS test image.
+ This file is present only for device instances where a test image is applicable.
+Devices: intel_ifs_0
diff --git a/Documentation/ABI/testing/sysfs-platform-mellanox-bootctl b/Documentation/ABI/testing/sysfs-platform-mellanox-bootctl
index e79ca22e2f45..9b99a81babb1 100644
--- a/Documentation/ABI/testing/sysfs-platform-mellanox-bootctl
+++ b/Documentation/ABI/testing/sysfs-platform-mellanox-bootctl
@@ -68,3 +68,10 @@ Description:
Wasted burnt and invalid
Invalid not burnt but marked as valid (error state).
======= ===============================================
+
+What: /sys/bus/platform/devices/MLNXBF04:00/bootfifo
+Date: Apr 2023
+KernelVersion: 6.4
+Contact: "Liming Sun <limings@nvidia.com>"
+Description:
+ The file used to access the BlueField boot fifo.
diff --git a/MAINTAINERS b/MAINTAINERS
index bd28bbdb3c09..79c521bf1e95 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -14148,6 +14148,13 @@ S: Odd Fixes
F: Documentation/devicetree/bindings/net/ieee802154/mrf24j40.txt
F: drivers/net/ieee802154/mrf24j40.c
+MSI EC DRIVER
+M: Nikita Kravets <teackot@gmail.com>
+L: platform-driver-x86@vger.kernel.org
+S: Maintained
+W: https://github.com/BeardOverflow/msi-ec
+F: drivers/platform/x86/msi-ec.*
+
MSI LAPTOP SUPPORT
M: "Lee, Chun-Yi" <jlee@suse.com>
L: platform-driver-x86@vger.kernel.org
@@ -16330,12 +16337,6 @@ S: Maintained
F: crypto/pcrypt.c
F: include/crypto/pcrypt.h
-PEAQ WMI HOTKEYS DRIVER
-M: Hans de Goede <hdegoede@redhat.com>
-L: platform-driver-x86@vger.kernel.org
-S: Maintained
-F: drivers/platform/x86/peaq-wmi.c
-
PECI HARDWARE MONITORING DRIVERS
M: Iwona Winiarska <iwona.winiarska@intel.com>
L: linux-hwmon@vger.kernel.org
@@ -22725,7 +22726,7 @@ M: Hans de Goede <hdegoede@redhat.com>
L: platform-driver-x86@vger.kernel.org
S: Maintained
T: git git://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git
-F: drivers/platform/x86/x86-android-tablets.c
+F: drivers/platform/x86/x86-android-tablets/
X86 PLATFORM DRIVERS
M: Hans de Goede <hdegoede@redhat.com>
diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h
index ad35355ee43e..3aedae61af4f 100644
--- a/arch/x86/include/asm/msr-index.h
+++ b/arch/x86/include/asm/msr-index.h
@@ -206,6 +206,8 @@
/* Abbreviated from Intel SDM name IA32_INTEGRITY_CAPABILITIES */
#define MSR_INTEGRITY_CAPS 0x000002d9
+#define MSR_INTEGRITY_CAPS_ARRAY_BIST_BIT 2
+#define MSR_INTEGRITY_CAPS_ARRAY_BIST BIT(MSR_INTEGRITY_CAPS_ARRAY_BIST_BIT)
#define MSR_INTEGRITY_CAPS_PERIODIC_BIST_BIT 4
#define MSR_INTEGRITY_CAPS_PERIODIC_BIST BIT(MSR_INTEGRITY_CAPS_PERIODIC_BIST_BIT)
diff --git a/drivers/platform/mellanox/mlxbf-bootctl.c b/drivers/platform/mellanox/mlxbf-bootctl.c
index 1c7a288b59a5..1bad1d278672 100644
--- a/drivers/platform/mellanox/mlxbf-bootctl.c
+++ b/drivers/platform/mellanox/mlxbf-bootctl.c
@@ -10,6 +10,7 @@
#include <linux/acpi.h>
#include <linux/arm-smccc.h>
+#include <linux/delay.h>
#include <linux/module.h>
#include <linux/platform_device.h>
@@ -44,6 +45,10 @@ static const char * const mlxbf_bootctl_lifecycle_states[] = {
[3] = "RMA",
};
+/* Mapped pointer for RSH_BOOT_FIFO_DATA and RSH_BOOT_FIFO_COUNT register. */
+static void __iomem *mlxbf_rsh_boot_data;
+static void __iomem *mlxbf_rsh_boot_cnt;
+
/* ARM SMC call which is atomic and no need for lock. */
static int mlxbf_bootctl_smc(unsigned int smc_op, int smc_arg)
{
@@ -244,11 +249,29 @@ static ssize_t secure_boot_fuse_state_show(struct device *dev,
return buf_len;
}
+static ssize_t fw_reset_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ unsigned long key;
+ int err;
+
+ err = kstrtoul(buf, 16, &key);
+ if (err)
+ return err;
+
+ if (mlxbf_bootctl_smc(MLXBF_BOOTCTL_FW_RESET, key) < 0)
+ return -EINVAL;
+
+ return count;
+}
+
static DEVICE_ATTR_RW(post_reset_wdog);
static DEVICE_ATTR_RW(reset_action);
static DEVICE_ATTR_RW(second_reset_action);
static DEVICE_ATTR_RO(lifecycle_state);
static DEVICE_ATTR_RO(secure_boot_fuse_state);
+static DEVICE_ATTR_WO(fw_reset);
static struct attribute *mlxbf_bootctl_attrs[] = {
&dev_attr_post_reset_wdog.attr,
@@ -256,6 +279,7 @@ static struct attribute *mlxbf_bootctl_attrs[] = {
&dev_attr_second_reset_action.attr,
&dev_attr_lifecycle_state.attr,
&dev_attr_secure_boot_fuse_state.attr,
+ &dev_attr_fw_reset.attr,
NULL
};
@@ -268,6 +292,45 @@ static const struct acpi_device_id mlxbf_bootctl_acpi_ids[] = {
MODULE_DEVICE_TABLE(acpi, mlxbf_bootctl_acpi_ids);
+static ssize_t mlxbf_bootctl_bootfifo_read(struct file *filp,
+ struct kobject *kobj,
+ struct bin_attribute *bin_attr,
+ char *buf, loff_t pos,
+ size_t count)
+{
+ unsigned long timeout = msecs_to_jiffies(500);
+ unsigned long expire = jiffies + timeout;
+ u64 data, cnt = 0;
+ char *p = buf;
+
+ while (count >= sizeof(data)) {
+ /* Give up reading if no more data within 500ms. */
+ if (!cnt) {
+ cnt = readq(mlxbf_rsh_boot_cnt);
+ if (!cnt) {
+ if (time_after(jiffies, expire))
+ break;
+ usleep_range(10, 50);
+ continue;
+ }
+ }
+
+ data = readq(mlxbf_rsh_boot_data);
+ memcpy(p, &data, sizeof(data));
+ count -= sizeof(data);
+ p += sizeof(data);
+ cnt--;
+ expire = jiffies + timeout;
+ }
+
+ return p - buf;
+}
+
+static struct bin_attribute mlxbf_bootctl_bootfifo_sysfs_attr = {
+ .attr = { .name = "bootfifo", .mode = 0400 },
+ .read = mlxbf_bootctl_bootfifo_read,
+};
+
static bool mlxbf_bootctl_guid_match(const guid_t *guid,
const struct arm_smccc_res *res)
{
@@ -285,6 +348,16 @@ static int mlxbf_bootctl_probe(struct platform_device *pdev)
guid_t guid;
int ret;
+ /* Get the resource of the bootfifo data register. */
+ mlxbf_rsh_boot_data = devm_platform_ioremap_resource(pdev, 0);
+ if (IS_ERR(mlxbf_rsh_boot_data))
+ return PTR_ERR(mlxbf_rsh_boot_data);
+
+ /* Get the resource of the bootfifo counter register. */
+ mlxbf_rsh_boot_cnt = devm_platform_ioremap_resource(pdev, 1);
+ if (IS_ERR(mlxbf_rsh_boot_cnt))
+ return PTR_ERR(mlxbf_rsh_boot_cnt);
+
/* Ensure we have the UUID we expect for this service. */
arm_smccc_smc(MLXBF_BOOTCTL_SIP_SVC_UID, 0, 0, 0, 0, 0, 0, 0, &res);
guid_parse(mlxbf_bootctl_svc_uuid_str, &guid);
@@ -302,11 +375,25 @@ static int mlxbf_bootctl_probe(struct platform_device *pdev)
if (ret < 0)
dev_warn(&pdev->dev, "Unable to reset the EMMC boot mode\n");
+ ret = sysfs_create_bin_file(&pdev->dev.kobj,
+ &mlxbf_bootctl_bootfifo_sysfs_attr);
+ if (ret)
+ pr_err("Unable to create bootfifo sysfs file, error %d\n", ret);
+
+ return ret;
+}
+
+static int mlxbf_bootctl_remove(struct platform_device *pdev)
+{
+ sysfs_remove_bin_file(&pdev->dev.kobj,
+ &mlxbf_bootctl_bootfifo_sysfs_attr);
+
return 0;
}
static struct platform_driver mlxbf_bootctl_driver = {
.probe = mlxbf_bootctl_probe,
+ .remove = mlxbf_bootctl_remove,
.driver = {
.name = "mlxbf-bootctl",
.dev_groups = mlxbf_bootctl_groups,
diff --git a/drivers/platform/mellanox/mlxbf-bootctl.h b/drivers/platform/mellanox/mlxbf-bootctl.h
index 148fdb43b435..b48243f60a59 100644
--- a/drivers/platform/mellanox/mlxbf-bootctl.h
+++ b/drivers/platform/mellanox/mlxbf-bootctl.h
@@ -75,6 +75,12 @@
#define MLXBF_BOOTCTL_GET_DIMM_INFO 0x82000008
+/*
+ * Initiate Firmware Reset via TYU. This might be invoked during the reset
+ * flow in isolation mode.
+ */
+#define MLXBF_BOOTCTL_FW_RESET 0x8200000D
+
/* SMC function IDs for SiP Service queries */
#define MLXBF_BOOTCTL_SIP_SVC_CALL_COUNT 0x8200ff00
#define MLXBF_BOOTCTL_SIP_SVC_UID 0x8200ff01
diff --git a/drivers/platform/olpc/olpc-xo175-ec.c b/drivers/platform/olpc/olpc-xo175-ec.c
index 4823bd2819f6..62ccbcb15c74 100644
--- a/drivers/platform/olpc/olpc-xo175-ec.c
+++ b/drivers/platform/olpc/olpc-xo175-ec.c
@@ -746,6 +746,7 @@ static struct spi_driver olpc_xo175_ec_spi_driver = {
.of_match_table = olpc_xo175_ec_of_match,
.pm = &olpc_xo175_ec_pm_ops,
},
+ .id_table = olpc_xo175_ec_id_table,
.probe = olpc_xo175_ec_probe,
.remove = olpc_xo175_ec_remove,
};
diff --git a/drivers/platform/surface/surface_aggregator_registry.c b/drivers/platform/surface/surface_aggregator_registry.c
index 296f72d52e6a..0fe5be539652 100644
--- a/drivers/platform/surface/surface_aggregator_registry.c
+++ b/drivers/platform/surface/surface_aggregator_registry.c
@@ -305,7 +305,7 @@ static const struct software_node *ssam_node_group_sp9[] = {
&ssam_node_bat_ac,
&ssam_node_bat_main,
&ssam_node_tmp_pprof,
- /* TODO: Tablet mode switch (via POS subsystem) */
+ &ssam_node_pos_tablet_switch,
&ssam_node_hid_kip_keyboard,
&ssam_node_hid_kip_penstash,
&ssam_node_hid_kip_touchpad,
diff --git a/drivers/platform/surface/surface_aggregator_tabletsw.c b/drivers/platform/surface/surface_aggregator_tabletsw.c
index 9fed800c7cc0..8f52b62d1c19 100644
--- a/drivers/platform/surface/surface_aggregator_tabletsw.c
+++ b/drivers/platform/surface/surface_aggregator_tabletsw.c
@@ -20,16 +20,23 @@
struct ssam_tablet_sw;
+struct ssam_tablet_sw_state {
+ u32 source;
+ u32 state;
+};
+
struct ssam_tablet_sw_ops {
- int (*get_state)(struct ssam_tablet_sw *sw, u32 *state);
- const char *(*state_name)(struct ssam_tablet_sw *sw, u32 state);
- bool (*state_is_tablet_mode)(struct ssam_tablet_sw *sw, u32 state);
+ int (*get_state)(struct ssam_tablet_sw *sw, struct ssam_tablet_sw_state *state);
+ const char *(*state_name)(struct ssam_tablet_sw *sw,
+ const struct ssam_tablet_sw_state *state);
+ bool (*state_is_tablet_mode)(struct ssam_tablet_sw *sw,
+ const struct ssam_tablet_sw_state *state);
};
struct ssam_tablet_sw {
struct ssam_device *sdev;
- u32 state;
+ struct ssam_tablet_sw_state state;
struct work_struct update_work;
struct input_dev *mode_switch;
@@ -45,9 +52,11 @@ struct ssam_tablet_sw_desc {
struct {
u32 (*notify)(struct ssam_event_notifier *nf, const struct ssam_event *event);
- int (*get_state)(struct ssam_tablet_sw *sw, u32 *state);
- const char *(*state_name)(struct ssam_tablet_sw *sw, u32 state);
- bool (*state_is_tablet_mode)(struct ssam_tablet_sw *sw, u32 state);
+ int (*get_state)(struct ssam_tablet_sw *sw, struct ssam_tablet_sw_state *state);
+ const char *(*state_name)(struct ssam_tablet_sw *sw,
+ const struct ssam_tablet_sw_state *state);
+ bool (*state_is_tablet_mode)(struct ssam_tablet_sw *sw,
+ const struct ssam_tablet_sw_state *state);
} ops;
struct {
@@ -61,7 +70,7 @@ struct ssam_tablet_sw_desc {
static ssize_t state_show(struct device *dev, struct device_attribute *attr, char *buf)
{
struct ssam_tablet_sw *sw = dev_get_drvdata(dev);
- const char *state = sw->ops.state_name(sw, sw->state);
+ const char *state = sw->ops.state_name(sw, &sw->state);
return sysfs_emit(buf, "%s\n", state);
}
@@ -79,19 +88,19 @@ static const struct attribute_group ssam_tablet_sw_group = {
static void ssam_tablet_sw_update_workfn(struct work_struct *work)
{
struct ssam_tablet_sw *sw = container_of(work, struct ssam_tablet_sw, update_work);
+ struct ssam_tablet_sw_state state;
int tablet, status;
- u32 state;
status = sw->ops.get_state(sw, &state);
if (status)
return;
- if (sw->state == state)
+ if (sw->state.source == state.source && sw->state.state == state.state)
return;
sw->state = state;
/* Send SW_TABLET_MODE event. */
- tablet = sw->ops.state_is_tablet_mode(sw, state);
+ tablet = sw->ops.state_is_tablet_mode(sw, &state);
input_report_switch(sw->mode_switch, SW_TABLET_MODE, tablet);
input_sync(sw->mode_switch);
}
@@ -146,7 +155,7 @@ static int ssam_tablet_sw_probe(struct ssam_device *sdev)
sw->mode_switch->id.bustype = BUS_HOST;
sw->mode_switch->dev.parent = &sdev->dev;
- tablet = sw->ops.state_is_tablet_mode(sw, sw->state);
+ tablet = sw->ops.state_is_tablet_mode(sw, &sw->state);
input_set_capability(sw->mode_switch, EV_SW, SW_TABLET_MODE);
input_report_switch(sw->mode_switch, SW_TABLET_MODE, tablet);
@@ -203,9 +212,10 @@ enum ssam_kip_cover_state {
SSAM_KIP_COVER_STATE_FOLDED_BACK = 0x05,
};
-static const char *ssam_kip_cover_state_name(struct ssam_tablet_sw *sw, u32 state)
+static const char *ssam_kip_cover_state_name(struct ssam_tablet_sw *sw,
+ const struct ssam_tablet_sw_state *state)
{
- switch (state) {
+ switch (state->state) {
case SSAM_KIP_COVER_STATE_DISCONNECTED:
return "disconnected";
@@ -222,14 +232,15 @@ static const char *ssam_kip_cover_state_name(struct ssam_tablet_sw *sw, u32 stat
return "folded-back";
default:
- dev_warn(&sw->sdev->dev, "unknown KIP cover state: %u\n", state);
+ dev_warn(&sw->sdev->dev, "unknown KIP cover state: %u\n", state->state);
return "<unknown>";
}
}
-static bool ssam_kip_cover_state_is_tablet_mode(struct ssam_tablet_sw *sw, u32 state)
+static bool ssam_kip_cover_state_is_tablet_mode(struct ssam_tablet_sw *sw,
+ const struct ssam_tablet_sw_state *state)
{
- switch (state) {
+ switch (state->state) {
case SSAM_KIP_COVER_STATE_DISCONNECTED:
case SSAM_KIP_COVER_STATE_FOLDED_CANVAS:
case SSAM_KIP_COVER_STATE_FOLDED_BACK:
@@ -240,7 +251,7 @@ static bool ssam_kip_cover_state_is_tablet_mode(struct ssam_tablet_sw *sw, u32 s
return false;
default:
- dev_warn(&sw->sdev->dev, "unknown KIP cover state: %d\n", sw->state);
+ dev_warn(&sw->sdev->dev, "unknown KIP cover state: %d\n", state->state);
return true;
}
}
@@ -252,7 +263,7 @@ SSAM_DEFINE_SYNC_REQUEST_R(__ssam_kip_get_cover_state, u8, {
.instance_id = 0x00,
});
-static int ssam_kip_get_cover_state(struct ssam_tablet_sw *sw, u32 *state)
+static int ssam_kip_get_cover_state(struct ssam_tablet_sw *sw, struct ssam_tablet_sw_state *state)
{
int status;
u8 raw;
@@ -263,7 +274,8 @@ static int ssam_kip_get_cover_state(struct ssam_tablet_sw *sw, u32 *state)
return status;
}
- *state = raw;
+ state->source = 0; /* Unused for KIP switch. */
+ state->state = raw;
return 0;
}
@@ -312,11 +324,24 @@ MODULE_PARM_DESC(tablet_mode_in_slate_state, "Enable tablet mode in slate device
#define SSAM_EVENT_POS_CID_POSTURE_CHANGED 0x03
#define SSAM_POS_MAX_SOURCES 4
-enum ssam_pos_state {
- SSAM_POS_POSTURE_LID_CLOSED = 0x00,
- SSAM_POS_POSTURE_LAPTOP = 0x01,
- SSAM_POS_POSTURE_SLATE = 0x02,
- SSAM_POS_POSTURE_TABLET = 0x03,
+enum ssam_pos_source_id {
+ SSAM_POS_SOURCE_COVER = 0x00,
+ SSAM_POS_SOURCE_SLS = 0x03,
+};
+
+enum ssam_pos_state_cover {
+ SSAM_POS_COVER_DISCONNECTED = 0x01,
+ SSAM_POS_COVER_CLOSED = 0x02,
+ SSAM_POS_COVER_LAPTOP = 0x03,
+ SSAM_POS_COVER_FOLDED_CANVAS = 0x04,
+ SSAM_POS_COVER_FOLDED_BACK = 0x05,
+};
+
+enum ssam_pos_state_sls {
+ SSAM_POS_SLS_LID_CLOSED = 0x00,
+ SSAM_POS_SLS_LAPTOP = 0x01,
+ SSAM_POS_SLS_SLATE = 0x02,
+ SSAM_POS_SLS_TABLET = 0x03,
};
struct ssam_sources_list {
@@ -324,42 +349,116 @@ struct ssam_sources_list {
__le32 id[SSAM_POS_MAX_SOURCES];
} __packed;
-static const char *ssam_pos_state_name(struct ssam_tablet_sw *sw, u32 state)
+static const char *ssam_pos_state_name_cover(struct ssam_tablet_sw *sw, u32 state)
+{
+ switch (state) {
+ case SSAM_POS_COVER_DISCONNECTED:
+ return "disconnected";
+
+ case SSAM_POS_COVER_CLOSED:
+ return "closed";
+
+ case SSAM_POS_COVER_LAPTOP:
+ return "laptop";
+
+ case SSAM_POS_COVER_FOLDED_CANVAS:
+ return "folded-canvas";
+
+ case SSAM_POS_COVER_FOLDED_BACK:
+ return "folded-back";
+
+ default:
+ dev_warn(&sw->sdev->dev, "unknown device posture for type-cover: %u\n", state);
+ return "<unknown>";
+ }
+}
+
+static const char *ssam_pos_state_name_sls(struct ssam_tablet_sw *sw, u32 state)
{
switch (state) {
- case SSAM_POS_POSTURE_LID_CLOSED:
+ case SSAM_POS_SLS_LID_CLOSED:
return "closed";
- case SSAM_POS_POSTURE_LAPTOP:
+ case SSAM_POS_SLS_LAPTOP:
return "laptop";
- case SSAM_POS_POSTURE_SLATE:
+ case SSAM_POS_SLS_SLATE:
return "slate";
- case SSAM_POS_POSTURE_TABLET:
+ case SSAM_POS_SLS_TABLET:
return "tablet";
default:
- dev_warn(&sw->sdev->dev, "unknown device posture: %u\n", state);
+ dev_warn(&sw->sdev->dev, "unknown device posture for SLS: %u\n", state);
return "<unknown>";
}
}
-static bool ssam_pos_state_is_tablet_mode(struct ssam_tablet_sw *sw, u32 state)
+static const char *ssam_pos_state_name(struct ssam_tablet_sw *sw,
+ const struct ssam_tablet_sw_state *state)
+{
+ switch (state->source) {
+ case SSAM_POS_SOURCE_COVER:
+ return ssam_pos_state_name_cover(sw, state->state);
+
+ case SSAM_POS_SOURCE_SLS:
+ return ssam_pos_state_name_sls(sw, state->state);
+
+ default:
+ dev_warn(&sw->sdev->dev, "unknown device posture source: %u\n", state->source);
+ return "<unknown>";
+ }
+}
+
+static bool ssam_pos_state_is_tablet_mode_cover(struct ssam_tablet_sw *sw, u32 state)
{
switch (state) {
- case SSAM_POS_POSTURE_LAPTOP:
- case SSAM_POS_POSTURE_LID_CLOSED:
+ case SSAM_POS_COVER_DISCONNECTED:
+ case SSAM_POS_COVER_FOLDED_CANVAS:
+ case SSAM_POS_COVER_FOLDED_BACK:
+ return true;
+
+ case SSAM_POS_COVER_CLOSED:
+ case SSAM_POS_COVER_LAPTOP:
return false;
- case SSAM_POS_POSTURE_SLATE:
+ default:
+ dev_warn(&sw->sdev->dev, "unknown device posture for type-cover: %u\n", state);
+ return true;
+ }
+}
+
+static bool ssam_pos_state_is_tablet_mode_sls(struct ssam_tablet_sw *sw, u32 state)
+{
+ switch (state) {
+ case SSAM_POS_SLS_LAPTOP:
+ case SSAM_POS_SLS_LID_CLOSED:
+ return false;
+
+ case SSAM_POS_SLS_SLATE:
return tablet_mode_in_slate_state;
- case SSAM_POS_POSTURE_TABLET:
+ case SSAM_POS_SLS_TABLET:
return true;
default:
- dev_warn(&sw->sdev->dev, "unknown device posture: %u\n", state);
+ dev_warn(&sw->sdev->dev, "unknown device posture for SLS: %u\n", state);
+ return true;
+ }
+}
+
+static bool ssam_pos_state_is_tablet_mode(struct ssam_tablet_sw *sw,
+ const struct ssam_tablet_sw_state *state)
+{
+ switch (state->source) {
+ case SSAM_POS_SOURCE_COVER:
+ return ssam_pos_state_is_tablet_mode_cover(sw, state->state);
+
+ case SSAM_POS_SOURCE_SLS:
+ return ssam_pos_state_is_tablet_mode_sls(sw, state->state);
+
+ default:
+ dev_warn(&sw->sdev->dev, "unknown device posture source: %u\n", state->source);
return true;
}
}
@@ -450,9 +549,10 @@ static int ssam_pos_get_posture_for_source(struct ssam_tablet_sw *sw, u32 source
return 0;
}
-static int ssam_pos_get_posture(struct ssam_tablet_sw *sw, u32 *state)
+static int ssam_pos_get_posture(struct ssam_tablet_sw *sw, struct ssam_tablet_sw_state *state)
{
u32 source_id;
+ u32 source_state;
int status;
status = ssam_pos_get_source(sw, &source_id);
@@ -461,13 +561,15 @@ static int ssam_pos_get_posture(struct ssam_tablet_sw *sw, u32 *state)
return status;
}
- status = ssam_pos_get_posture_for_source(sw, source_id, state);
+ status = ssam_pos_get_posture_for_source(sw, source_id, &source_state);
if (status) {
dev_err(&sw->sdev->dev, "failed to get posture value for source %u: %d\n",
source_id, status);
return status;
}
+ state->source = source_id;
+ state->state = source_state;
return 0;
}
diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index 4a01b315e0a9..22052031c719 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -84,13 +84,6 @@ config MXM_WMI
MXM is a standard for laptop graphics cards, the WMI interface
is required for switchable nvidia graphics machines
-config PEAQ_WMI
- tristate "PEAQ 2-in-1 WMI hotkey driver"
- depends on ACPI_WMI
- depends on INPUT
- help
- Say Y here if you want to support WMI-based hotkeys on PEAQ 2-in-1s.
-
config NVIDIA_WMI_EC_BACKLIGHT
tristate "EC Backlight Driver for Hybrid Graphics Notebook Systems"
depends on ACPI_VIDEO
@@ -213,7 +206,6 @@ config APPLE_GMUX
depends on ACPI && PCI
depends on PNP
depends on BACKLIGHT_CLASS_DEVICE
- depends on BACKLIGHT_APPLE=n || BACKLIGHT_APPLE
help
This driver provides support for the gmux device found on many
Apple laptops, which controls the display mux for the hybrid
@@ -469,6 +461,15 @@ config IDEAPAD_LAPTOP
This is a driver for Lenovo IdeaPad netbooks contains drivers for
rfkill switch, hotkey, fan control and backlight control.
+config LENOVO_YMC
+ tristate "Lenovo Yoga Tablet Mode Control"
+ depends on ACPI_WMI
+ depends on INPUT
+ select INPUT_SPARSEKMAP
+ help
+ This driver maps the Tablet Mode Control switch to SW_TABLET_MODE input
+ events for Lenovo Yoga notebooks.
+
config SENSORS_HDAPS
tristate "Thinkpad Hard Drive Active Protection System (hdaps)"
depends on INPUT
@@ -643,6 +644,14 @@ config THINKPAD_LMI
source "drivers/platform/x86/intel/Kconfig"
+config MSI_EC
+ tristate "MSI EC Extras"
+ depends on ACPI
+ depends on ACPI_BATTERY
+ help
+ This driver allows various MSI laptops' functionalities to be
+ controlled from userspace, including battery charge threshold.
+
config MSI_LAPTOP
tristate "MSI Laptop Extras"
depends on ACPI
@@ -978,22 +987,7 @@ config TOUCHSCREEN_DMI
the OS-image for the device. This option supplies the missing info.
Enable this for x86 tablets with Silead or Chipone touchscreens.
-config X86_ANDROID_TABLETS
- tristate "X86 Android tablet support"
- depends on I2C && SPI && SERIAL_DEV_BUS && ACPI && EFI && GPIOLIB
- help
- X86 tablets which ship with Android as (part of) the factory image
- typically have various problems with their DSDTs. The factory kernels
- shipped on these devices typically have device addresses and GPIOs
- hardcoded in the kernel, rather than specified in their DSDT.
-
- With the DSDT containing a random collection of devices which may or
- may not actually be present. This driver contains various fixes for
- such tablets, including instantiating kernel devices for devices which
- are missing from the DSDT.
-
- If you have a x86 Android tablet say Y or M here, for a generic x86
- distro config say M here.
+source "drivers/platform/x86/x86-android-tablets/Kconfig"
config FW_ATTR_CLASS
tristate
diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile
index 1d3d1b02541b..2cafe51ec4d8 100644
--- a/drivers/platform/x86/Makefile
+++ b/drivers/platform/x86/Makefile
@@ -12,7 +12,6 @@ obj-$(CONFIG_WMI_BMOF) += wmi-bmof.o
obj-$(CONFIG_HUAWEI_WMI) += huawei-wmi.o
obj-$(CONFIG_MXM_WMI) += mxm-wmi.o
obj-$(CONFIG_NVIDIA_WMI_EC_BACKLIGHT) += nvidia-wmi-ec-backlight.o
-obj-$(CONFIG_PEAQ_WMI) += peaq-wmi.o
obj-$(CONFIG_XIAOMI_WMI) += xiaomi-wmi.o
obj-$(CONFIG_GIGABYTE_WMI) += gigabyte-wmi.o
obj-$(CONFIG_YOGABOOK_WMI) += lenovo-yogabook-wmi.o
@@ -63,6 +62,7 @@ obj-$(CONFIG_UV_SYSFS) += uv_sysfs.o
# IBM Thinkpad and Lenovo
obj-$(CONFIG_IBM_RTL) += ibm_rtl.o
obj-$(CONFIG_IDEAPAD_LAPTOP) += ideapad-laptop.o
+obj-$(CONFIG_LENOVO_YMC) += lenovo-ymc.o
obj-$(CONFIG_SENSORS_HDAPS) += hdaps.o
obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.o
obj-$(CONFIG_THINKPAD_LMI) += think-lmi.o
@@ -71,6 +71,7 @@ obj-$(CONFIG_THINKPAD_LMI) += think-lmi.o
obj-y += intel/
# MSI
+obj-$(CONFIG_MSI_EC) += msi-ec.o
obj-$(CONFIG_MSI_LAPTOP) += msi-laptop.o
obj-$(CONFIG_MSI_WMI) += msi-wmi.o
@@ -112,7 +113,7 @@ obj-$(CONFIG_SERIAL_MULTI_INSTANTIATE) += serial-multi-instantiate.o
obj-$(CONFIG_MLX_PLATFORM) += mlx-platform.o
obj-$(CONFIG_TOUCHSCREEN_DMI) += touchscreen_dmi.o
obj-$(CONFIG_WIRELESS_HOTKEY) += wireless-hotkey.o
-obj-$(CONFIG_X86_ANDROID_TABLETS) += x86-android-tablets.o
+obj-$(CONFIG_X86_ANDROID_TABLETS) += x86-android-tablets/
# Intel uncore drivers
obj-$(CONFIG_INTEL_IPS) += intel_ips.o
diff --git a/drivers/platform/x86/acer-wmi.c b/drivers/platform/x86/acer-wmi.c
index ee67efdd5499..377a0becd1a1 100644
--- a/drivers/platform/x86/acer-wmi.c
+++ b/drivers/platform/x86/acer-wmi.c
@@ -2258,7 +2258,7 @@ error_mailled:
return err;
}
-static int acer_platform_remove(struct platform_device *device)
+static void acer_platform_remove(struct platform_device *device)
{
if (has_cap(ACER_CAP_MAILLED))
acer_led_exit();
@@ -2266,7 +2266,6 @@ static int acer_platform_remove(struct platform_device *device)
acer_backlight_exit();
acer_rfkill_exit();
- return 0;
}
#ifdef CONFIG_PM_SLEEP
@@ -2334,7 +2333,7 @@ static struct platform_driver acer_platform_driver = {
.pm = &acer_pm,
},
.probe = acer_platform_probe,
- .remove = acer_platform_remove,
+ .remove_new = acer_platform_remove,
.shutdown = acer_platform_shutdown,
};
diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c
index a48638ad2a8a..ec8cc780b822 100644
--- a/drivers/platform/x86/acerhdf.c
+++ b/drivers/platform/x86/acerhdf.c
@@ -341,7 +341,7 @@ static void acerhdf_check_param(struct thermal_zone_device *thermal)
pr_err("fanoff temperature (%d) is above fanon temperature (%d), clamping to %d\n",
fanoff, fanon, fanon);
fanoff = fanon;
- };
+ }
trips[0].temperature = fanon;
trips[0].hysteresis = fanon - fanoff;
diff --git a/drivers/platform/x86/adv_swbutton.c b/drivers/platform/x86/adv_swbutton.c
index 38693b735c87..6b23ba78e028 100644
--- a/drivers/platform/x86/adv_swbutton.c
+++ b/drivers/platform/x86/adv_swbutton.c
@@ -90,14 +90,12 @@ static int adv_swbutton_probe(struct platform_device *device)
return 0;
}
-static int adv_swbutton_remove(struct platform_device *device)
+static void adv_swbutton_remove(struct platform_device *device)
{
acpi_handle handle = ACPI_HANDLE(&device->dev);
acpi_remove_notify_handler(handle, ACPI_DEVICE_NOTIFY,
adv_swbutton_notify);
-
- return 0;
}
static const struct acpi_device_id button_device_ids[] = {
@@ -112,7 +110,7 @@ static struct platform_driver adv_swbutton_driver = {
.acpi_match_table = button_device_ids,
},
.probe = adv_swbutton_probe,
- .remove = adv_swbutton_remove,
+ .remove_new = adv_swbutton_remove,
};
module_platform_driver(adv_swbutton_driver);
diff --git a/drivers/platform/x86/amd/Kconfig b/drivers/platform/x86/amd/Kconfig
index 2ce8cb2170df..d9685aef0887 100644
--- a/drivers/platform/x86/amd/Kconfig
+++ b/drivers/platform/x86/amd/Kconfig
@@ -7,7 +7,7 @@ source "drivers/platform/x86/amd/pmf/Kconfig"
config AMD_PMC
tristate "AMD SoC PMC driver"
- depends on ACPI && PCI && RTC_CLASS
+ depends on ACPI && PCI && RTC_CLASS && AMD_NB
select SERIO
help
The driver provides support for AMD Power Management Controller
diff --git a/drivers/platform/x86/amd/hsmp.c b/drivers/platform/x86/amd/hsmp.c
index 521c6a229362..31382ef52efb 100644
--- a/drivers/platform/x86/amd/hsmp.c
+++ b/drivers/platform/x86/amd/hsmp.c
@@ -340,16 +340,14 @@ static int hsmp_pltdrv_probe(struct platform_device *pdev)
return misc_register(&hsmp_device);
}
-static int hsmp_pltdrv_remove(struct platform_device *pdev)
+static void hsmp_pltdrv_remove(struct platform_device *pdev)
{
misc_deregister(&hsmp_device);
-
- return 0;
}
static struct platform_driver amd_hsmp_driver = {
.probe = hsmp_pltdrv_probe,
- .remove = hsmp_pltdrv_remove,
+ .remove_new = hsmp_pltdrv_remove,
.driver = {
.name = DRIVER_NAME,
},
diff --git a/drivers/platform/x86/amd/pmc.c b/drivers/platform/x86/amd/pmc.c
index 2edaae04a691..5a935db80fab 100644
--- a/drivers/platform/x86/amd/pmc.c
+++ b/drivers/platform/x86/amd/pmc.c
@@ -10,6 +10,7 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+#include <asm/amd_nb.h>
#include <linux/acpi.h>
#include <linux/bitfield.h>
#include <linux/bits.h>
@@ -37,8 +38,6 @@
#define AMD_PMC_SCRATCH_REG_YC 0xD14
/* STB Registers */
-#define AMD_PMC_STB_INDEX_ADDRESS 0xF8
-#define AMD_PMC_STB_INDEX_DATA 0xFC
#define AMD_PMC_STB_PMI_0 0x03E30600
#define AMD_PMC_STB_S2IDLE_PREPARE 0xC6000001
#define AMD_PMC_STB_S2IDLE_RESTORE 0xC6000002
@@ -56,8 +55,6 @@
#define S2D_TELEMETRY_DRAMBYTES_MAX 0x1000000
/* Base address of SMU for mapping physical address to virtual address */
-#define AMD_PMC_SMU_INDEX_ADDRESS 0xB8
-#define AMD_PMC_SMU_INDEX_DATA 0xBC
#define AMD_PMC_MAPPING_SIZE 0x01000
#define AMD_PMC_BASE_ADDR_OFFSET 0x10000
#define AMD_PMC_BASE_ADDR_LO 0x13B102E8
@@ -97,6 +94,7 @@
#define AMD_CPU_ID_YC 0x14B5
#define AMD_CPU_ID_CB 0x14D8
#define AMD_CPU_ID_PS 0x14E8
+#define AMD_CPU_ID_SP 0x14A4
#define PMC_MSG_DELAY_MIN_US 50
#define RESPONSE_REGISTER_LOOP_MAX 20000
@@ -268,6 +266,7 @@ static int amd_pmc_stb_debugfs_open_v2(struct inode *inode, struct file *filp)
dev->msg_port = 0;
if (ret) {
dev_err(dev->dev, "error: S2D_NUM_SAMPLES not supported : %d\n", ret);
+ kfree(buf);
return ret;
}
@@ -342,33 +341,6 @@ static int amd_pmc_setup_smu_logging(struct amd_pmc_dev *dev)
return 0;
}
-static int amd_pmc_idlemask_read(struct amd_pmc_dev *pdev, struct device *dev,
- struct seq_file *s)
-{
- u32 val;
-
- switch (pdev->cpu_id) {
- case AMD_CPU_ID_CZN:
- val = amd_pmc_reg_read(pdev, AMD_PMC_SCRATCH_REG_CZN);
- break;
- case AMD_CPU_ID_YC:
- case AMD_CPU_ID_CB:
- case AMD_CPU_ID_PS:
- val = amd_pmc_reg_read(pdev, AMD_PMC_SCRATCH_REG_YC);
- break;
- default:
- return -EINVAL;
- }
-
- if (dev)
- dev_dbg(pdev->dev, "SMU idlemask s0i3: 0x%x\n", val);
-
- if (s)
- seq_printf(s, "SMU idlemask : 0x%x\n", val);
-
- return 0;
-}
-
static int get_metrics_table(struct amd_pmc_dev *pdev, struct smu_metrics *table)
{
if (!pdev->smu_virt_addr) {
@@ -403,6 +375,9 @@ static int amd_pmc_get_smu_version(struct amd_pmc_dev *dev)
int rc;
u32 val;
+ if (dev->cpu_id == AMD_CPU_ID_PCO)
+ return -ENODEV;
+
rc = amd_pmc_send_cmd(dev, 0, &val, SMU_MSG_GETSMUVERSION, 1);
if (rc)
return rc;
@@ -449,12 +424,31 @@ static ssize_t smu_program_show(struct device *d, struct device_attribute *attr,
static DEVICE_ATTR_RO(smu_fw_version);
static DEVICE_ATTR_RO(smu_program);
+static umode_t pmc_attr_is_visible(struct kobject *kobj, struct attribute *attr, int idx)
+{
+ struct device *dev = kobj_to_dev(kobj);
+ struct amd_pmc_dev *pdev = dev_get_drvdata(dev);
+
+ if (pdev->cpu_id == AMD_CPU_ID_PCO)
+ return 0;
+ return 0444;
+}
+
static struct attribute *pmc_attrs[] = {
&dev_attr_smu_fw_version.attr,
&dev_attr_smu_program.attr,
NULL,
};
-ATTRIBUTE_GROUPS(pmc);
+
+static struct attribute_group pmc_attr_group = {
+ .attrs = pmc_attrs,
+ .is_visible = pmc_attr_is_visible,
+};
+
+static const struct attribute_group *pmc_groups[] = {
+ &pmc_attr_group,
+ NULL,
+};
static int smu_fw_info_show(struct seq_file *s, void *unused)
{
@@ -521,28 +515,47 @@ static int s0ix_stats_show(struct seq_file *s, void *unused)
}
DEFINE_SHOW_ATTRIBUTE(s0ix_stats);
-static int amd_pmc_idlemask_show(struct seq_file *s, void *unused)
+static int amd_pmc_idlemask_read(struct amd_pmc_dev *pdev, struct device *dev,
+ struct seq_file *s)
{
- struct amd_pmc_dev *dev = s->private;
+ u32 val;
int rc;
- /* we haven't yet read SMU version */
- if (!dev->major) {
- rc = amd_pmc_get_smu_version(dev);
- if (rc)
- return rc;
+ switch (pdev->cpu_id) {
+ case AMD_CPU_ID_CZN:
+ /* we haven't yet read SMU version */
+ if (!pdev->major) {
+ rc = amd_pmc_get_smu_version(pdev);
+ if (rc)
+ return rc;
+ }
+ if (pdev->major > 56 || (pdev->major >= 55 && pdev->minor >= 37))
+ val = amd_pmc_reg_read(pdev, AMD_PMC_SCRATCH_REG_CZN);
+ else
+ return -EINVAL;
+ break;
+ case AMD_CPU_ID_YC:
+ case AMD_CPU_ID_CB:
+ case AMD_CPU_ID_PS:
+ val = amd_pmc_reg_read(pdev, AMD_PMC_SCRATCH_REG_YC);
+ break;
+ default:
+ return -EINVAL;
}
- if (dev->major > 56 || (dev->major >= 55 && dev->minor >= 37)) {
- rc = amd_pmc_idlemask_read(dev, NULL, s);
- if (rc)
- return rc;
- } else {
- seq_puts(s, "Unsupported SMU version for Idlemask\n");
- }
+ if (dev)
+ dev_dbg(pdev->dev, "SMU idlemask s0i3: 0x%x\n", val);
+
+ if (s)
+ seq_printf(s, "SMU idlemask : 0x%x\n", val);
return 0;
}
+
+static int amd_pmc_idlemask_show(struct seq_file *s, void *unused)
+{
+ return amd_pmc_idlemask_read(s->private, NULL, s);
+}
DEFINE_SHOW_ATTRIBUTE(amd_pmc_idlemask);
static void amd_pmc_dbgfs_unregister(struct amd_pmc_dev *dev)
@@ -812,6 +825,14 @@ static void amd_pmc_s2idle_check(void)
dev_err(pdev->dev, "error writing to STB: %d\n", rc);
}
+static int amd_pmc_dump_data(struct amd_pmc_dev *pdev)
+{
+ if (pdev->cpu_id == AMD_CPU_ID_PCO)
+ return -ENODEV;
+
+ return amd_pmc_send_cmd(pdev, 0, NULL, SMU_MSG_LOG_DUMP_DATA, 0);
+}
+
static void amd_pmc_s2idle_restore(void)
{
struct amd_pmc_dev *pdev = &pmc;
@@ -824,7 +845,7 @@ static void amd_pmc_s2idle_restore(void)
dev_err(pdev->dev, "resume failed: %d\n", rc);
/* Let SMU know that we are looking for stats */
- amd_pmc_send_cmd(pdev, 0, NULL, SMU_MSG_LOG_DUMP_DATA, 0);
+ amd_pmc_dump_data(pdev);
rc = amd_pmc_write_stb(pdev, AMD_PMC_STB_S2IDLE_RESTORE);
if (rc)
@@ -840,7 +861,7 @@ static struct acpi_s2idle_dev_ops amd_pmc_s2idle_dev_ops = {
.restore = amd_pmc_s2idle_restore,
};
-static int __maybe_unused amd_pmc_suspend_handler(struct device *dev)
+static int amd_pmc_suspend_handler(struct device *dev)
{
struct amd_pmc_dev *pdev = dev_get_drvdata(dev);
@@ -866,6 +887,7 @@ static const struct pci_device_id pmc_pci_ids[] = {
{ PCI_DEVICE(PCI_VENDOR_ID_AMD, AMD_CPU_ID_RN) },
{ PCI_DEVICE(PCI_VENDOR_ID_AMD, AMD_CPU_ID_PCO) },
{ PCI_DEVICE(PCI_VENDOR_ID_AMD, AMD_CPU_ID_RV) },
+ { PCI_DEVICE(PCI_VENDOR_ID_AMD, AMD_CPU_ID_SP) },
{ }
};
@@ -902,17 +924,9 @@ static int amd_pmc_write_stb(struct amd_pmc_dev *dev, u32 data)
{
int err;
- err = pci_write_config_dword(dev->rdev, AMD_PMC_STB_INDEX_ADDRESS, AMD_PMC_STB_PMI_0);
+ err = amd_smn_write(0, AMD_PMC_STB_PMI_0, data);
if (err) {
- dev_err(dev->dev, "failed to write addr in stb: 0x%X\n",
- AMD_PMC_STB_INDEX_ADDRESS);
- return pcibios_err_to_errno(err);
- }
-
- err = pci_write_config_dword(dev->rdev, AMD_PMC_STB_INDEX_DATA, data);
- if (err) {
- dev_err(dev->dev, "failed to write data in stb: 0x%X\n",
- AMD_PMC_STB_INDEX_DATA);
+ dev_err(dev->dev, "failed to write data in stb: 0x%X\n", AMD_PMC_STB_PMI_0);
return pcibios_err_to_errno(err);
}
@@ -923,18 +937,10 @@ static int amd_pmc_read_stb(struct amd_pmc_dev *dev, u32 *buf)
{
int i, err;
- err = pci_write_config_dword(dev->rdev, AMD_PMC_STB_INDEX_ADDRESS, AMD_PMC_STB_PMI_0);
- if (err) {
- dev_err(dev->dev, "error writing addr to stb: 0x%X\n",
- AMD_PMC_STB_INDEX_ADDRESS);
- return pcibios_err_to_errno(err);
- }
-
for (i = 0; i < FIFO_SIZE; i++) {
- err = pci_read_config_dword(dev->rdev, AMD_PMC_STB_INDEX_DATA, buf++);
+ err = amd_smn_read(0, AMD_PMC_STB_PMI_0, buf++);
if (err) {
- dev_err(dev->dev, "error reading data from stb: 0x%X\n",
- AMD_PMC_STB_INDEX_DATA);
+ dev_err(dev->dev, "error reading data from stb: 0x%X\n", AMD_PMC_STB_PMI_0);
return pcibios_err_to_errno(err);
}
}
@@ -960,31 +966,26 @@ static int amd_pmc_probe(struct platform_device *pdev)
}
dev->cpu_id = rdev->device;
- dev->rdev = rdev;
- err = pci_write_config_dword(rdev, AMD_PMC_SMU_INDEX_ADDRESS, AMD_PMC_BASE_ADDR_LO);
- if (err) {
- dev_err(dev->dev, "error writing to 0x%x\n", AMD_PMC_SMU_INDEX_ADDRESS);
- err = pcibios_err_to_errno(err);
+
+ if (dev->cpu_id == AMD_CPU_ID_SP) {
+ dev_warn_once(dev->dev, "S0i3 is not supported on this hardware\n");
+ err = -ENODEV;
goto err_pci_dev_put;
}
- err = pci_read_config_dword(rdev, AMD_PMC_SMU_INDEX_DATA, &val);
+ dev->rdev = rdev;
+ err = amd_smn_read(0, AMD_PMC_BASE_ADDR_LO, &val);
if (err) {
+ dev_err(dev->dev, "error reading 0x%x\n", AMD_PMC_BASE_ADDR_LO);
err = pcibios_err_to_errno(err);
goto err_pci_dev_put;
}
base_addr_lo = val & AMD_PMC_BASE_ADDR_HI_MASK;
- err = pci_write_config_dword(rdev, AMD_PMC_SMU_INDEX_ADDRESS, AMD_PMC_BASE_ADDR_HI);
- if (err) {
- dev_err(dev->dev, "error writing to 0x%x\n", AMD_PMC_SMU_INDEX_ADDRESS);
- err = pcibios_err_to_errno(err);
- goto err_pci_dev_put;
- }
-
- err = pci_read_config_dword(rdev, AMD_PMC_SMU_INDEX_DATA, &val);
+ err = amd_smn_read(0, AMD_PMC_BASE_ADDR_HI, &val);
if (err) {
+ dev_err(dev->dev, "error reading 0x%x\n", AMD_PMC_BASE_ADDR_HI);
err = pcibios_err_to_errno(err);
goto err_pci_dev_put;
}
@@ -1022,7 +1023,7 @@ err_pci_dev_put:
return err;
}
-static int amd_pmc_remove(struct platform_device *pdev)
+static void amd_pmc_remove(struct platform_device *pdev)
{
struct amd_pmc_dev *dev = platform_get_drvdata(pdev);
@@ -1031,7 +1032,6 @@ static int amd_pmc_remove(struct platform_device *pdev)
amd_pmc_dbgfs_unregister(dev);
pci_dev_put(dev->rdev);
mutex_destroy(&dev->lock);
- return 0;
}
static const struct acpi_device_id amd_pmc_acpi_ids[] = {
@@ -1054,7 +1054,7 @@ static struct platform_driver amd_pmc_driver = {
.pm = pm_sleep_ptr(&amd_pmc_pm),
},
.probe = amd_pmc_probe,
- .remove = amd_pmc_remove,
+ .remove_new = amd_pmc_remove,
};
module_platform_driver(amd_pmc_driver);
diff --git a/drivers/platform/x86/amd/pmf/Kconfig b/drivers/platform/x86/amd/pmf/Kconfig
index 6d89528c3177..d87986adf91e 100644
--- a/drivers/platform/x86/amd/pmf/Kconfig
+++ b/drivers/platform/x86/amd/pmf/Kconfig
@@ -7,6 +7,7 @@ config AMD_PMF
tristate "AMD Platform Management Framework"
depends on ACPI && PCI
depends on POWER_SUPPLY
+ depends on AMD_NB
select ACPI_PLATFORM_PROFILE
help
This driver provides support for the AMD Platform Management Framework.
diff --git a/drivers/platform/x86/amd/pmf/core.c b/drivers/platform/x86/amd/pmf/core.c
index da23639071d7..d5bb775dadcf 100644
--- a/drivers/platform/x86/amd/pmf/core.c
+++ b/drivers/platform/x86/amd/pmf/core.c
@@ -8,6 +8,7 @@
* Author: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
*/
+#include <asm/amd_nb.h>
#include <linux/debugfs.h>
#include <linux/iopoll.h>
#include <linux/module.h>
@@ -22,8 +23,6 @@
#define AMD_PMF_REGISTER_ARGUMENT 0xA58
/* Base address of SMU for mapping physical address to virtual address */
-#define AMD_PMF_SMU_INDEX_ADDRESS 0xB8
-#define AMD_PMF_SMU_INDEX_DATA 0xBC
#define AMD_PMF_MAPPING_SIZE 0x01000
#define AMD_PMF_BASE_ADDR_OFFSET 0x10000
#define AMD_PMF_BASE_ADDR_LO 0x13B102E8
@@ -348,30 +347,19 @@ static int amd_pmf_probe(struct platform_device *pdev)
}
dev->cpu_id = rdev->device;
- err = pci_write_config_dword(rdev, AMD_PMF_SMU_INDEX_ADDRESS, AMD_PMF_BASE_ADDR_LO);
- if (err) {
- dev_err(dev->dev, "error writing to 0x%x\n", AMD_PMF_SMU_INDEX_ADDRESS);
- pci_dev_put(rdev);
- return pcibios_err_to_errno(err);
- }
- err = pci_read_config_dword(rdev, AMD_PMF_SMU_INDEX_DATA, &val);
+ err = amd_smn_read(0, AMD_PMF_BASE_ADDR_LO, &val);
if (err) {
+ dev_err(dev->dev, "error in reading from 0x%x\n", AMD_PMF_BASE_ADDR_LO);
pci_dev_put(rdev);
return pcibios_err_to_errno(err);
}
base_addr_lo = val & AMD_PMF_BASE_ADDR_HI_MASK;
- err = pci_write_config_dword(rdev, AMD_PMF_SMU_INDEX_ADDRESS, AMD_PMF_BASE_ADDR_HI);
- if (err) {
- dev_err(dev->dev, "error writing to 0x%x\n", AMD_PMF_SMU_INDEX_ADDRESS);
- pci_dev_put(rdev);
- return pcibios_err_to_errno(err);
- }
-
- err = pci_read_config_dword(rdev, AMD_PMF_SMU_INDEX_DATA, &val);
+ err = amd_smn_read(0, AMD_PMF_BASE_ADDR_HI, &val);
if (err) {
+ dev_err(dev->dev, "error in reading from 0x%x\n", AMD_PMF_BASE_ADDR_HI);
pci_dev_put(rdev);
return pcibios_err_to_errno(err);
}
@@ -402,7 +390,7 @@ static int amd_pmf_probe(struct platform_device *pdev)
return 0;
}
-static int amd_pmf_remove(struct platform_device *pdev)
+static void amd_pmf_remove(struct platform_device *pdev)
{
struct amd_pmf_dev *dev = platform_get_drvdata(pdev);
@@ -413,7 +401,6 @@ static int amd_pmf_remove(struct platform_device *pdev)
mutex_destroy(&dev->lock);
mutex_destroy(&dev->update_mutex);
kfree(dev->buf);
- return 0;
}
static const struct attribute_group *amd_pmf_driver_groups[] = {
@@ -428,7 +415,7 @@ static struct platform_driver amd_pmf_driver = {
.dev_groups = amd_pmf_driver_groups,
},
.probe = amd_pmf_probe,
- .remove = amd_pmf_remove,
+ .remove_new = amd_pmf_remove,
};
module_platform_driver(amd_pmf_driver);
diff --git a/drivers/platform/x86/amilo-rfkill.c b/drivers/platform/x86/amilo-rfkill.c
index 3e313c4d538d..efcf909786a5 100644
--- a/drivers/platform/x86/amilo-rfkill.c
+++ b/drivers/platform/x86/amilo-rfkill.c
@@ -124,11 +124,10 @@ fail:
return rc;
}
-static int amilo_rfkill_remove(struct platform_device *device)
+static void amilo_rfkill_remove(struct platform_device *device)
{
rfkill_unregister(amilo_rfkill_dev);
rfkill_destroy(amilo_rfkill_dev);
- return 0;
}
static struct platform_driver amilo_rfkill_driver = {
@@ -136,7 +135,7 @@ static struct platform_driver amilo_rfkill_driver = {
.name = KBUILD_MODNAME,
},
.probe = amilo_rfkill_probe,
- .remove = amilo_rfkill_remove,
+ .remove_new = amilo_rfkill_remove,
};
static int __init amilo_rfkill_init(void)
diff --git a/drivers/platform/x86/apple-gmux.c b/drivers/platform/x86/apple-gmux.c
index 9333f82cfa8a..e02b4aea4f1e 100644
--- a/drivers/platform/x86/apple-gmux.c
+++ b/drivers/platform/x86/apple-gmux.c
@@ -5,6 +5,7 @@
* Copyright (C) Canonical Ltd. <seth.forshee@canonical.com>
* Copyright (C) 2010-2012 Andreas Heider <andreas@meetr.de>
* Copyright (C) 2015 Lukas Wunner <lukas@wunner.de>
+ * Copyright (C) 2023 Orlando Chamberlain <orlandoch.dev@gmail.com>
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
@@ -15,38 +16,51 @@
#include <linux/backlight.h>
#include <linux/acpi.h>
#include <linux/pnp.h>
-#include <linux/apple_bl.h>
#include <linux/apple-gmux.h>
#include <linux/slab.h>
#include <linux/delay.h>
#include <linux/pci.h>
#include <linux/vga_switcheroo.h>
+#include <linux/debugfs.h>
+#include <acpi/video.h>
#include <asm/io.h>
/**
* DOC: Overview
*
* gmux is a microcontroller built into the MacBook Pro to support dual GPUs:
- * A `Lattice XP2`_ on pre-retinas, a `Renesas R4F2113`_ on retinas.
+ * A `Lattice XP2`_ on pre-retinas, a `Renesas R4F2113`_ on pre-T2 retinas.
+ *
+ * On T2 Macbooks, the gmux is part of the T2 Coprocessor's SMC. The SMC has
+ * an I2C connection to a `NXP PCAL6524` GPIO expander, which enables/disables
+ * the voltage regulators of the discrete GPU, drives the display panel power,
+ * and has a GPIO to switch the eDP mux. The Intel CPU can interact with
+ * gmux through MMIO, similar to how the main SMC interface is controlled.
*
* (The MacPro6,1 2013 also has a gmux, however it is unclear why since it has
* dual GPUs but no built-in display.)
*
* gmux is connected to the LPC bus of the southbridge. Its I/O ports are
* accessed differently depending on the microcontroller: Driver functions
- * to access a pre-retina gmux are infixed ``_pio_``, those for a retina gmux
- * are infixed ``_index_``.
+ * to access a pre-retina gmux are infixed ``_pio_``, those for a pre-T2
+ * retina gmux are infixed ``_index_``, and those on T2 Macs are infixed
+ * with ``_mmio_``.
*
* .. _Lattice XP2:
* http://www.latticesemi.com/en/Products/FPGAandCPLD/LatticeXP2.aspx
* .. _Renesas R4F2113:
* http://www.renesas.com/products/mpumcu/h8s/h8s2100/h8s2113/index.jsp
+ * .. _NXP PCAL6524:
+ * https://www.nxp.com/docs/en/data-sheet/PCAL6524.pdf
*/
+struct apple_gmux_config;
+
struct apple_gmux_data {
+ u8 __iomem *iomem_base;
unsigned long iostart;
unsigned long iolen;
- bool indexed;
+ const struct apple_gmux_config *config;
struct mutex index_lock;
struct backlight_device *bdev;
@@ -60,10 +74,26 @@ struct apple_gmux_data {
enum vga_switcheroo_client_id switch_state_external;
enum vga_switcheroo_state power_state;
struct completion powerchange_done;
+
+ /* debugfs data */
+ u8 selected_port;
+ struct dentry *debug_dentry;
};
static struct apple_gmux_data *apple_gmux_data;
+struct apple_gmux_config {
+ u8 (*read8)(struct apple_gmux_data *gmux_data, int port);
+ void (*write8)(struct apple_gmux_data *gmux_data, int port, u8 val);
+ u32 (*read32)(struct apple_gmux_data *gmux_data, int port);
+ void (*write32)(struct apple_gmux_data *gmux_data, int port, u32 val);
+ const struct vga_switcheroo_handler *gmux_handler;
+ enum vga_switcheroo_handler_flags_t handler_flags;
+ unsigned long resource_type;
+ bool read_version_as_u32;
+ char *name;
+};
+
#define GMUX_INTERRUPT_ENABLE 0xff
#define GMUX_INTERRUPT_DISABLE 0x00
@@ -193,37 +223,98 @@ static void gmux_index_write32(struct apple_gmux_data *gmux_data, int port,
mutex_unlock(&gmux_data->index_lock);
}
+static int gmux_mmio_wait(struct apple_gmux_data *gmux_data)
+{
+ int i = 200;
+ u8 gwr = ioread8(gmux_data->iomem_base + GMUX_MMIO_COMMAND_SEND);
+
+ while (i && gwr) {
+ gwr = ioread8(gmux_data->iomem_base + GMUX_MMIO_COMMAND_SEND);
+ udelay(100);
+ i--;
+ }
+
+ return !!i;
+}
+
+static u8 gmux_mmio_read8(struct apple_gmux_data *gmux_data, int port)
+{
+ u8 val;
+
+ mutex_lock(&gmux_data->index_lock);
+ gmux_mmio_wait(gmux_data);
+ iowrite8((port & 0xff), gmux_data->iomem_base + GMUX_MMIO_PORT_SELECT);
+ iowrite8(GMUX_MMIO_READ | sizeof(val),
+ gmux_data->iomem_base + GMUX_MMIO_COMMAND_SEND);
+ gmux_mmio_wait(gmux_data);
+ val = ioread8(gmux_data->iomem_base);
+ mutex_unlock(&gmux_data->index_lock);
+
+ return val;
+}
+
+static void gmux_mmio_write8(struct apple_gmux_data *gmux_data, int port,
+ u8 val)
+{
+ mutex_lock(&gmux_data->index_lock);
+ gmux_mmio_wait(gmux_data);
+ iowrite8(val, gmux_data->iomem_base);
+
+ iowrite8(port & 0xff, gmux_data->iomem_base + GMUX_MMIO_PORT_SELECT);
+ iowrite8(GMUX_MMIO_WRITE | sizeof(val),
+ gmux_data->iomem_base + GMUX_MMIO_COMMAND_SEND);
+
+ gmux_mmio_wait(gmux_data);
+ mutex_unlock(&gmux_data->index_lock);
+}
+
+static u32 gmux_mmio_read32(struct apple_gmux_data *gmux_data, int port)
+{
+ u32 val;
+
+ mutex_lock(&gmux_data->index_lock);
+ gmux_mmio_wait(gmux_data);
+ iowrite8((port & 0xff), gmux_data->iomem_base + GMUX_MMIO_PORT_SELECT);
+ iowrite8(GMUX_MMIO_READ | sizeof(val),
+ gmux_data->iomem_base + GMUX_MMIO_COMMAND_SEND);
+ gmux_mmio_wait(gmux_data);
+ val = be32_to_cpu(ioread32(gmux_data->iomem_base));
+ mutex_unlock(&gmux_data->index_lock);
+
+ return val;
+}
+
+static void gmux_mmio_write32(struct apple_gmux_data *gmux_data, int port,
+ u32 val)
+{
+ mutex_lock(&gmux_data->index_lock);
+ iowrite32(cpu_to_be32(val), gmux_data->iomem_base);
+ iowrite8(port & 0xff, gmux_data->iomem_base + GMUX_MMIO_PORT_SELECT);
+ iowrite8(GMUX_MMIO_WRITE | sizeof(val),
+ gmux_data->iomem_base + GMUX_MMIO_COMMAND_SEND);
+ gmux_mmio_wait(gmux_data);
+ mutex_unlock(&gmux_data->index_lock);
+}
+
static u8 gmux_read8(struct apple_gmux_data *gmux_data, int port)
{
- if (gmux_data->indexed)
- return gmux_index_read8(gmux_data, port);
- else
- return gmux_pio_read8(gmux_data, port);
+ return gmux_data->config->read8(gmux_data, port);
}
static void gmux_write8(struct apple_gmux_data *gmux_data, int port, u8 val)
{
- if (gmux_data->indexed)
- gmux_index_write8(gmux_data, port, val);
- else
- gmux_pio_write8(gmux_data, port, val);
+ return gmux_data->config->write8(gmux_data, port, val);
}
static u32 gmux_read32(struct apple_gmux_data *gmux_data, int port)
{
- if (gmux_data->indexed)
- return gmux_index_read32(gmux_data, port);
- else
- return gmux_pio_read32(gmux_data, port);
+ return gmux_data->config->read32(gmux_data, port);
}
static void gmux_write32(struct apple_gmux_data *gmux_data, int port,
u32 val)
{
- if (gmux_data->indexed)
- gmux_index_write32(gmux_data, port, val);
- else
- gmux_pio_write32(gmux_data, port, val);
+ return gmux_data->config->write32(gmux_data, port, val);
}
/**
@@ -233,8 +324,8 @@ static void gmux_write32(struct apple_gmux_data *gmux_data, int port,
* the GPU. On dual GPU MacBook Pros by contrast, either GPU may be suspended
* to conserve energy. Hence the PWM signal needs to be generated by a separate
* backlight driver which is controlled by gmux. The earliest generation
- * MBP5 2008/09 uses a `TI LP8543`_ backlight driver. All newer models
- * use a `TI LP8545`_.
+ * MBP5 2008/09 uses a `TI LP8543`_ backlight driver. Newer models
+ * use a `TI LP8545`_ or a TI LP8548.
*
* .. _TI LP8543: https://www.ti.com/lit/ds/symlink/lp8543.pdf
* .. _TI LP8545: https://www.ti.com/lit/ds/symlink/lp8545.pdf
@@ -298,8 +389,8 @@ static const struct backlight_ops gmux_bl_ops = {
* connecting it either to the discrete GPU or the Thunderbolt controller.
* Oddly enough, while the full port is no longer switchable, AUX and HPD
* are still switchable by way of an `NXP CBTL03062`_ (on pre-retinas
- * MBP8 2011 and MBP9 2012) or two `TI TS3DS10224`_ (on retinas) under the
- * control of gmux. Since the integrated GPU is missing the main link,
+ * MBP8 2011 and MBP9 2012) or two `TI TS3DS10224`_ (on pre-t2 retinas) under
+ * the control of gmux. Since the integrated GPU is missing the main link,
* external displays appear to it as phantoms which fail to link-train.
*
* gmux receives the HPD signal of all display connectors and sends an
@@ -346,10 +437,10 @@ static void gmux_read_switch_state(struct apple_gmux_data *gmux_data)
else
gmux_data->switch_state_ddc = VGA_SWITCHEROO_DIS;
- if (gmux_read8(gmux_data, GMUX_PORT_SWITCH_DISPLAY) == 2)
- gmux_data->switch_state_display = VGA_SWITCHEROO_IGD;
- else
+ if (gmux_read8(gmux_data, GMUX_PORT_SWITCH_DISPLAY) & 1)
gmux_data->switch_state_display = VGA_SWITCHEROO_DIS;
+ else
+ gmux_data->switch_state_display = VGA_SWITCHEROO_IGD;
if (gmux_read8(gmux_data, GMUX_PORT_SWITCH_EXTERNAL) == 2)
gmux_data->switch_state_external = VGA_SWITCHEROO_IGD;
@@ -463,27 +554,79 @@ static enum vga_switcheroo_client_id gmux_get_client_id(struct pci_dev *pdev)
return VGA_SWITCHEROO_DIS;
}
-static const struct vga_switcheroo_handler gmux_handler_indexed = {
+static const struct vga_switcheroo_handler gmux_handler_no_ddc = {
.switchto = gmux_switchto,
.power_state = gmux_set_power_state,
.get_client_id = gmux_get_client_id,
};
-static const struct vga_switcheroo_handler gmux_handler_classic = {
+static const struct vga_switcheroo_handler gmux_handler_ddc = {
.switchto = gmux_switchto,
.switch_ddc = gmux_switch_ddc,
.power_state = gmux_set_power_state,
.get_client_id = gmux_get_client_id,
};
+static const struct apple_gmux_config apple_gmux_pio = {
+ .read8 = &gmux_pio_read8,
+ .write8 = &gmux_pio_write8,
+ .read32 = &gmux_pio_read32,
+ .write32 = &gmux_pio_write32,
+ .gmux_handler = &gmux_handler_ddc,
+ .handler_flags = VGA_SWITCHEROO_CAN_SWITCH_DDC,
+ .resource_type = IORESOURCE_IO,
+ .read_version_as_u32 = false,
+ .name = "classic"
+};
+
+static const struct apple_gmux_config apple_gmux_index = {
+ .read8 = &gmux_index_read8,
+ .write8 = &gmux_index_write8,
+ .read32 = &gmux_index_read32,
+ .write32 = &gmux_index_write32,
+ .gmux_handler = &gmux_handler_no_ddc,
+ .handler_flags = VGA_SWITCHEROO_NEEDS_EDP_CONFIG,
+ .resource_type = IORESOURCE_IO,
+ .read_version_as_u32 = true,
+ .name = "indexed"
+};
+
+static const struct apple_gmux_config apple_gmux_mmio = {
+ .read8 = &gmux_mmio_read8,
+ .write8 = &gmux_mmio_write8,
+ .read32 = &gmux_mmio_read32,
+ .write32 = &gmux_mmio_write32,
+ .gmux_handler = &gmux_handler_no_ddc,
+ .handler_flags = VGA_SWITCHEROO_NEEDS_EDP_CONFIG,
+ .resource_type = IORESOURCE_MEM,
+ .read_version_as_u32 = true,
+ .name = "T2"
+};
+
+
/**
* DOC: Interrupt
*
* gmux is also connected to a GPIO pin of the southbridge and thereby is able
- * to trigger an ACPI GPE. On the MBP5 2008/09 it's GPIO pin 22 of the Nvidia
- * MCP79, on all following generations it's GPIO pin 6 of the Intel PCH.
+ * to trigger an ACPI GPE. ACPI name GMGP holds this GPIO pin's number. On the
+ * MBP5 2008/09 it's GPIO pin 22 of the Nvidia MCP79, on following generations
+ * it's GPIO pin 6 of the Intel PCH, on MMIO gmux's it's pin 21.
+ *
* The GPE merely signals that an interrupt occurred, the actual type of event
* is identified by reading a gmux register.
+ *
+ * In addition to the GMGP name, gmux's ACPI device also has two methods GMSP
+ * and GMLV. GMLV likely means "GMUX Level", and reads the value of the GPIO,
+ * while GMSP likely means "GMUX Set Polarity", and seems to write to the GPIO's
+ * value. On newer Macbooks (This was introduced with or sometime before the
+ * MacBookPro14,3), the ACPI GPE method differentiates between the OS type: On
+ * Darwin, only a notification is signaled, whereas on other OSes, the GPIO's
+ * value is read and then inverted.
+ *
+ * Because Linux masquerades as Darwin, it ends up in the notification-only code
+ * path. On MMIO gmux's, this seems to lead to us being unable to clear interrupts,
+ * unless we call GMSP(0). Without this, there is a flood of status=0 interrupts
+ * that can't be cleared. This issue seems to be unique to MMIO gmux's.
*/
static inline void gmux_disable_interrupts(struct apple_gmux_data *gmux_data)
@@ -510,6 +653,9 @@ static void gmux_clear_interrupts(struct apple_gmux_data *gmux_data)
/* to clear interrupts write back current status */
status = gmux_interrupt_get_status(gmux_data);
gmux_write8(gmux_data, GMUX_PORT_INTERRUPT_STATUS, status);
+ /* Prevent flood of status=0 interrupts */
+ if (gmux_data->config == &apple_gmux_mmio)
+ acpi_execute_simple_method(gmux_data->dhandle, "GMSP", 0);
}
static void gmux_notify_handler(acpi_handle device, u32 value, void *context)
@@ -529,6 +675,80 @@ static void gmux_notify_handler(acpi_handle device, u32 value, void *context)
complete(&gmux_data->powerchange_done);
}
+/**
+ * DOC: Debugfs Interface
+ *
+ * gmux ports can be accessed from userspace as a debugfs interface. For example:
+ *
+ * # echo 4 > /sys/kernel/debug/apple_gmux/selected_port
+ * # cat /sys/kernel/debug/apple_gmux/selected_port_data | xxd -p
+ * 00000005
+ *
+ * Reads 4 bytes from port 4 (GMUX_PORT_VERSION_MAJOR).
+ *
+ * 1 and 4 byte writes are also allowed.
+ */
+
+static ssize_t gmux_selected_port_data_write(struct file *file,
+ const char __user *userbuf, size_t count, loff_t *ppos)
+{
+ struct apple_gmux_data *gmux_data = file->private_data;
+
+ if (*ppos)
+ return -EINVAL;
+
+ if (count == 1) {
+ u8 data;
+
+ if (copy_from_user(&data, userbuf, 1))
+ return -EFAULT;
+
+ gmux_write8(gmux_data, gmux_data->selected_port, data);
+ } else if (count == 4) {
+ u32 data;
+
+ if (copy_from_user(&data, userbuf, 4))
+ return -EFAULT;
+
+ gmux_write32(gmux_data, gmux_data->selected_port, data);
+ } else
+ return -EINVAL;
+
+ return count;
+}
+
+static ssize_t gmux_selected_port_data_read(struct file *file,
+ char __user *userbuf, size_t count, loff_t *ppos)
+{
+ struct apple_gmux_data *gmux_data = file->private_data;
+ u32 data;
+
+ data = gmux_read32(gmux_data, gmux_data->selected_port);
+
+ return simple_read_from_buffer(userbuf, count, ppos, &data, sizeof(data));
+}
+
+static const struct file_operations gmux_port_data_ops = {
+ .open = simple_open,
+ .write = gmux_selected_port_data_write,
+ .read = gmux_selected_port_data_read
+};
+
+static void gmux_init_debugfs(struct apple_gmux_data *gmux_data)
+{
+ gmux_data->debug_dentry = debugfs_create_dir(KBUILD_MODNAME, NULL);
+
+ debugfs_create_u8("selected_port", 0644, gmux_data->debug_dentry,
+ &gmux_data->selected_port);
+ debugfs_create_file("selected_port_data", 0644, gmux_data->debug_dentry,
+ gmux_data, &gmux_port_data_ops);
+}
+
+static void gmux_fini_debugfs(struct apple_gmux_data *gmux_data)
+{
+ debugfs_remove_recursive(gmux_data->debug_dentry);
+}
+
static int gmux_suspend(struct device *dev)
{
struct pnp_dev *pnp = to_pnp_dev(dev);
@@ -560,18 +780,19 @@ static int gmux_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)
struct apple_gmux_data *gmux_data;
struct resource *res;
struct backlight_properties props;
- struct backlight_device *bdev;
+ struct backlight_device *bdev = NULL;
u8 ver_major, ver_minor, ver_release;
+ bool register_bdev = true;
int ret = -ENXIO;
acpi_status status;
unsigned long long gpe;
- bool indexed = false;
+ enum apple_gmux_type type;
u32 version;
if (apple_gmux_data)
return -EBUSY;
- if (!apple_gmux_detect(pnp, &indexed)) {
+ if (!apple_gmux_detect(pnp, &type)) {
pr_info("gmux device not present\n");
return -ENODEV;
}
@@ -581,6 +802,35 @@ static int gmux_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)
return -ENOMEM;
pnp_set_drvdata(pnp, gmux_data);
+ switch (type) {
+ case APPLE_GMUX_TYPE_MMIO:
+ gmux_data->config = &apple_gmux_mmio;
+ mutex_init(&gmux_data->index_lock);
+
+ res = pnp_get_resource(pnp, IORESOURCE_MEM, 0);
+ gmux_data->iostart = res->start;
+ /* Although the ACPI table only allocates 8 bytes, we need 16. */
+ gmux_data->iolen = 16;
+ if (!request_mem_region(gmux_data->iostart, gmux_data->iolen,
+ "Apple gmux")) {
+ pr_err("gmux I/O already in use\n");
+ goto err_free;
+ }
+ gmux_data->iomem_base = ioremap(gmux_data->iostart, gmux_data->iolen);
+ if (!gmux_data->iomem_base) {
+ pr_err("couldn't remap gmux mmio region");
+ goto err_release;
+ }
+ goto get_version;
+ case APPLE_GMUX_TYPE_INDEXED:
+ gmux_data->config = &apple_gmux_index;
+ mutex_init(&gmux_data->index_lock);
+ break;
+ case APPLE_GMUX_TYPE_PIO:
+ gmux_data->config = &apple_gmux_pio;
+ break;
+ }
+
res = pnp_get_resource(pnp, IORESOURCE_IO, 0);
gmux_data->iostart = res->start;
gmux_data->iolen = resource_size(res);
@@ -591,9 +841,8 @@ static int gmux_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)
goto err_free;
}
- if (indexed) {
- mutex_init(&gmux_data->index_lock);
- gmux_data->indexed = true;
+get_version:
+ if (gmux_data->config->read_version_as_u32) {
version = gmux_read32(gmux_data, GMUX_PORT_VERSION_MAJOR);
ver_major = (version >> 24) & 0xff;
ver_minor = (version >> 16) & 0xff;
@@ -604,39 +853,36 @@ static int gmux_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)
ver_release = gmux_read8(gmux_data, GMUX_PORT_VERSION_RELEASE);
}
pr_info("Found gmux version %d.%d.%d [%s]\n", ver_major, ver_minor,
- ver_release, (gmux_data->indexed ? "indexed" : "classic"));
+ ver_release, gmux_data->config->name);
memset(&props, 0, sizeof(props));
props.type = BACKLIGHT_PLATFORM;
props.max_brightness = gmux_read32(gmux_data, GMUX_PORT_MAX_BRIGHTNESS);
- /*
- * Currently it's assumed that the maximum brightness is less than
- * 2^24 for compatibility with old gmux versions. Cap the max
- * brightness at this value, but print a warning if the hardware
- * reports something higher so that it can be fixed.
- */
- if (WARN_ON(props.max_brightness > GMUX_MAX_BRIGHTNESS))
- props.max_brightness = GMUX_MAX_BRIGHTNESS;
-
- bdev = backlight_device_register("gmux_backlight", &pnp->dev,
- gmux_data, &gmux_bl_ops, &props);
- if (IS_ERR(bdev)) {
- ret = PTR_ERR(bdev);
- goto err_release;
- }
-
- gmux_data->bdev = bdev;
- bdev->props.brightness = gmux_get_brightness(bdev);
- backlight_update_status(bdev);
+#if IS_REACHABLE(CONFIG_ACPI_VIDEO)
+ register_bdev = acpi_video_get_backlight_type() == acpi_backlight_apple_gmux;
+#endif
+ if (register_bdev) {
+ /*
+ * Currently it's assumed that the maximum brightness is less than
+ * 2^24 for compatibility with old gmux versions. Cap the max
+ * brightness at this value, but print a warning if the hardware
+ * reports something higher so that it can be fixed.
+ */
+ if (WARN_ON(props.max_brightness > GMUX_MAX_BRIGHTNESS))
+ props.max_brightness = GMUX_MAX_BRIGHTNESS;
+
+ bdev = backlight_device_register("gmux_backlight", &pnp->dev,
+ gmux_data, &gmux_bl_ops, &props);
+ if (IS_ERR(bdev)) {
+ ret = PTR_ERR(bdev);
+ goto err_unmap;
+ }
- /*
- * The backlight situation on Macs is complicated. If the gmux is
- * present it's the best choice, because it always works for
- * backlight control and supports more levels than other options.
- * Disable the other backlight choices.
- */
- apple_bl_unregister();
+ gmux_data->bdev = bdev;
+ bdev->props.brightness = gmux_get_brightness(bdev);
+ backlight_update_status(bdev);
+ }
gmux_data->power_state = VGA_SWITCHEROO_ON;
@@ -690,21 +936,18 @@ static int gmux_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)
/*
* Retina MacBook Pros cannot switch the panel's AUX separately
* and need eDP pre-calibration. They are distinguishable from
- * pre-retinas by having an "indexed" gmux.
+ * pre-retinas by having an "indexed" or "T2" gmux.
*
* Pre-retina MacBook Pros can switch the panel's DDC separately.
*/
- if (gmux_data->indexed)
- ret = vga_switcheroo_register_handler(&gmux_handler_indexed,
- VGA_SWITCHEROO_NEEDS_EDP_CONFIG);
- else
- ret = vga_switcheroo_register_handler(&gmux_handler_classic,
- VGA_SWITCHEROO_CAN_SWITCH_DDC);
+ ret = vga_switcheroo_register_handler(gmux_data->config->gmux_handler,
+ gmux_data->config->handler_flags);
if (ret) {
pr_err("Failed to register vga_switcheroo handler\n");
goto err_register_handler;
}
+ gmux_init_debugfs(gmux_data);
return 0;
err_register_handler:
@@ -719,8 +962,14 @@ err_enable_gpe:
&gmux_notify_handler);
err_notify:
backlight_device_unregister(bdev);
+err_unmap:
+ if (gmux_data->iomem_base)
+ iounmap(gmux_data->iomem_base);
err_release:
- release_region(gmux_data->iostart, gmux_data->iolen);
+ if (gmux_data->config->resource_type == IORESOURCE_MEM)
+ release_mem_region(gmux_data->iostart, gmux_data->iolen);
+ else
+ release_region(gmux_data->iostart, gmux_data->iolen);
err_free:
kfree(gmux_data);
return ret;
@@ -730,6 +979,7 @@ static void gmux_remove(struct pnp_dev *pnp)
{
struct apple_gmux_data *gmux_data = pnp_get_drvdata(pnp);
+ gmux_fini_debugfs(gmux_data);
vga_switcheroo_unregister_handler();
gmux_disable_interrupts(gmux_data);
if (gmux_data->gpe >= 0) {
@@ -741,11 +991,13 @@ static void gmux_remove(struct pnp_dev *pnp)
backlight_device_unregister(gmux_data->bdev);
- release_region(gmux_data->iostart, gmux_data->iolen);
+ if (gmux_data->iomem_base) {
+ iounmap(gmux_data->iomem_base);
+ release_mem_region(gmux_data->iostart, gmux_data->iolen);
+ } else
+ release_region(gmux_data->iostart, gmux_data->iolen);
apple_gmux_data = NULL;
kfree(gmux_data);
-
- apple_bl_register();
}
static const struct pnp_device_id gmux_device_ids[] = {
diff --git a/drivers/platform/x86/barco-p50-gpio.c b/drivers/platform/x86/barco-p50-gpio.c
index 8dd672339485..af566f712057 100644
--- a/drivers/platform/x86/barco-p50-gpio.c
+++ b/drivers/platform/x86/barco-p50-gpio.c
@@ -370,7 +370,7 @@ err_leds:
return ret;
}
-static int p50_gpio_remove(struct platform_device *pdev)
+static void p50_gpio_remove(struct platform_device *pdev)
{
struct p50_gpio *p50 = platform_get_drvdata(pdev);
@@ -378,8 +378,6 @@ static int p50_gpio_remove(struct platform_device *pdev)
platform_device_unregister(p50->leds_pdev);
gpiod_remove_lookup_table(&p50_gpio_led_table);
-
- return 0;
}
static struct platform_driver p50_gpio_driver = {
@@ -387,7 +385,7 @@ static struct platform_driver p50_gpio_driver = {
.name = DRIVER_NAME,
},
.probe = p50_gpio_probe,
- .remove = p50_gpio_remove,
+ .remove_new = p50_gpio_remove,
};
/* Board setup */
diff --git a/drivers/platform/x86/classmate-laptop.c b/drivers/platform/x86/classmate-laptop.c
index 8b6a14611859..2edaea2492df 100644
--- a/drivers/platform/x86/classmate-laptop.c
+++ b/drivers/platform/x86/classmate-laptop.c
@@ -1134,7 +1134,7 @@ static void cmpc_exit(void)
module_init(cmpc_init);
module_exit(cmpc_exit);
-static const struct acpi_device_id cmpc_device_ids[] = {
+static const struct acpi_device_id cmpc_device_ids[] __maybe_unused = {
{CMPC_ACCEL_HID, 0},
{CMPC_ACCEL_HID_V4, 0},
{CMPC_TABLET_HID, 0},
diff --git a/drivers/platform/x86/compal-laptop.c b/drivers/platform/x86/compal-laptop.c
index e10d2f64dfad..61c745490d71 100644
--- a/drivers/platform/x86/compal-laptop.c
+++ b/drivers/platform/x86/compal-laptop.c
@@ -1003,12 +1003,12 @@ remove:
return err;
}
-static int compal_remove(struct platform_device *pdev)
+static void compal_remove(struct platform_device *pdev)
{
struct compal_data *data;
if (!extra_features)
- return 0;
+ return;
pr_info("Unloading: resetting fan control to motherboard\n");
pwm_disable_control();
@@ -1017,8 +1017,6 @@ static int compal_remove(struct platform_device *pdev)
power_supply_unregister(data->psy);
sysfs_remove_group(&pdev->dev.kobj, &compal_platform_attr_group);
-
- return 0;
}
static struct platform_driver compal_driver = {
@@ -1026,7 +1024,7 @@ static struct platform_driver compal_driver = {
.name = DRIVER_NAME,
},
.probe = compal_probe,
- .remove = compal_remove,
+ .remove_new = compal_remove,
};
static int __init compal_init(void)
diff --git a/drivers/platform/x86/dell/dcdbas.c b/drivers/platform/x86/dell/dcdbas.c
index 0ecb7b164750..76787369d7fa 100644
--- a/drivers/platform/x86/dell/dcdbas.c
+++ b/drivers/platform/x86/dell/dcdbas.c
@@ -698,12 +698,10 @@ static int dcdbas_probe(struct platform_device *dev)
return 0;
}
-static int dcdbas_remove(struct platform_device *dev)
+static void dcdbas_remove(struct platform_device *dev)
{
unregister_reboot_notifier(&dcdbas_reboot_nb);
sysfs_remove_group(&dev->dev.kobj, &dcdbas_attr_group);
-
- return 0;
}
static struct platform_driver dcdbas_driver = {
@@ -711,7 +709,7 @@ static struct platform_driver dcdbas_driver = {
.name = DRIVER_NAME,
},
.probe = dcdbas_probe,
- .remove = dcdbas_remove,
+ .remove_new = dcdbas_remove,
};
static const struct platform_device_info dcdbas_dev_info __initconst = {
diff --git a/drivers/platform/x86/dell/dell-laptop.c b/drivers/platform/x86/dell/dell-laptop.c
index e92c3ad06d69..6586438356de 100644
--- a/drivers/platform/x86/dell/dell-laptop.c
+++ b/drivers/platform/x86/dell/dell-laptop.c
@@ -97,6 +97,7 @@ static struct rfkill *bluetooth_rfkill;
static struct rfkill *wwan_rfkill;
static bool force_rfkill;
static bool micmute_led_registered;
+static bool mute_led_registered;
module_param(force_rfkill, bool, 0444);
MODULE_PARM_DESC(force_rfkill, "enable rfkill on non whitelisted models");
@@ -2177,6 +2178,34 @@ static struct led_classdev micmute_led_cdev = {
.default_trigger = "audio-micmute",
};
+static int mute_led_set(struct led_classdev *led_cdev,
+ enum led_brightness brightness)
+{
+ struct calling_interface_buffer buffer;
+ struct calling_interface_token *token;
+ int state = brightness != LED_OFF;
+
+ if (state == 0)
+ token = dell_smbios_find_token(GLOBAL_MUTE_DISABLE);
+ else
+ token = dell_smbios_find_token(GLOBAL_MUTE_ENABLE);
+
+ if (!token)
+ return -ENODEV;
+
+ dell_fill_request(&buffer, token->location, token->value, 0, 0);
+ dell_send_request(&buffer, CLASS_TOKEN_WRITE, SELECT_TOKEN_STD);
+
+ return 0;
+}
+
+static struct led_classdev mute_led_cdev = {
+ .name = "platform::mute",
+ .max_brightness = 1,
+ .brightness_set_blocking = mute_led_set,
+ .default_trigger = "audio-mute",
+};
+
static int __init dell_init(void)
{
struct calling_interface_token *token;
@@ -2230,6 +2259,15 @@ static int __init dell_init(void)
micmute_led_registered = true;
}
+ if (dell_smbios_find_token(GLOBAL_MUTE_DISABLE) &&
+ dell_smbios_find_token(GLOBAL_MUTE_ENABLE)) {
+ mute_led_cdev.brightness = ledtrig_audio_get(LED_AUDIO_MUTE);
+ ret = led_classdev_register(&platform_device->dev, &mute_led_cdev);
+ if (ret < 0)
+ goto fail_backlight;
+ mute_led_registered = true;
+ }
+
if (acpi_video_get_backlight_type() != acpi_backlight_vendor)
return 0;
@@ -2277,6 +2315,8 @@ fail_get_brightness:
fail_backlight:
if (micmute_led_registered)
led_classdev_unregister(&micmute_led_cdev);
+ if (mute_led_registered)
+ led_classdev_unregister(&mute_led_cdev);
fail_led:
dell_cleanup_rfkill();
fail_rfkill:
@@ -2299,6 +2339,8 @@ static void __exit dell_exit(void)
backlight_device_unregister(dell_backlight_device);
if (micmute_led_registered)
led_classdev_unregister(&micmute_led_cdev);
+ if (mute_led_registered)
+ led_classdev_unregister(&mute_led_cdev);
dell_cleanup_rfkill();
if (platform_device) {
platform_device_unregister(platform_device);
diff --git a/drivers/platform/x86/dell/dell-smbios.h b/drivers/platform/x86/dell/dell-smbios.h
index 75fa8ea0476d..eb341bf000c6 100644
--- a/drivers/platform/x86/dell/dell-smbios.h
+++ b/drivers/platform/x86/dell/dell-smbios.h
@@ -34,6 +34,8 @@
#define KBD_LED_AUTO_100_TOKEN 0x02F6
#define GLOBAL_MIC_MUTE_ENABLE 0x0364
#define GLOBAL_MIC_MUTE_DISABLE 0x0365
+#define GLOBAL_MUTE_ENABLE 0x058C
+#define GLOBAL_MUTE_DISABLE 0x058D
struct notifier_block;
diff --git a/drivers/platform/x86/dell/dell-smo8800.c b/drivers/platform/x86/dell/dell-smo8800.c
index 8d6b7a83cf24..f7ec17c56833 100644
--- a/drivers/platform/x86/dell/dell-smo8800.c
+++ b/drivers/platform/x86/dell/dell-smo8800.c
@@ -154,14 +154,13 @@ error:
return err;
}
-static int smo8800_remove(struct platform_device *device)
+static void smo8800_remove(struct platform_device *device)
{
struct smo8800_device *smo8800 = platform_get_drvdata(device);
free_irq(smo8800->irq, smo8800);
misc_deregister(&smo8800->miscdev);
dev_dbg(&device->dev, "device /dev/freefall unregistered\n");
- return 0;
}
/* NOTE: Keep this list in sync with drivers/i2c/busses/i2c-i801.c */
@@ -180,7 +179,7 @@ MODULE_DEVICE_TABLE(acpi, smo8800_ids);
static struct platform_driver smo8800_driver = {
.probe = smo8800_probe,
- .remove = smo8800_remove,
+ .remove_new = smo8800_remove,
.driver = {
.name = DRIVER_NAME,
.acpi_match_table = smo8800_ids,
diff --git a/drivers/platform/x86/hp/hp_accel.c b/drivers/platform/x86/hp/hp_accel.c
index 6477591747cf..52535576772a 100644
--- a/drivers/platform/x86/hp/hp_accel.c
+++ b/drivers/platform/x86/hp/hp_accel.c
@@ -342,7 +342,7 @@ static int lis3lv02d_probe(struct platform_device *device)
return ret;
}
-static int lis3lv02d_remove(struct platform_device *device)
+static void lis3lv02d_remove(struct platform_device *device)
{
i8042_remove_filter(hp_accel_i8042_filter);
lis3lv02d_joystick_disable(&lis3_dev);
@@ -352,7 +352,6 @@ static int lis3lv02d_remove(struct platform_device *device)
flush_work(&hpled_led.work);
lis3lv02d_remove_fs(&lis3_dev);
- return 0;
}
static int __maybe_unused lis3lv02d_suspend(struct device *dev)
@@ -373,7 +372,7 @@ static SIMPLE_DEV_PM_OPS(hp_accel_pm, lis3lv02d_suspend, lis3lv02d_resume);
/* For the HP MDPS aka 3D Driveguard */
static struct platform_driver lis3lv02d_driver = {
.probe = lis3lv02d_probe,
- .remove = lis3lv02d_remove,
+ .remove_new = lis3lv02d_remove,
.driver = {
.name = "hp_accel",
.pm = &hp_accel_pm,
diff --git a/drivers/platform/x86/hp/tc1100-wmi.c b/drivers/platform/x86/hp/tc1100-wmi.c
index ded26213c420..5298b0f6804f 100644
--- a/drivers/platform/x86/hp/tc1100-wmi.c
+++ b/drivers/platform/x86/hp/tc1100-wmi.c
@@ -170,11 +170,9 @@ static int __init tc1100_probe(struct platform_device *device)
}
-static int tc1100_remove(struct platform_device *device)
+static void tc1100_remove(struct platform_device *device)
{
sysfs_remove_group(&device->dev.kobj, &tc1100_attribute_group);
-
- return 0;
}
#ifdef CONFIG_PM
@@ -223,7 +221,7 @@ static struct platform_driver tc1100_driver = {
.pm = &tc1100_pm_ops,
#endif
},
- .remove = tc1100_remove,
+ .remove_new = tc1100_remove,
};
static int __init tc1100_init(void)
diff --git a/drivers/platform/x86/huawei-wmi.c b/drivers/platform/x86/huawei-wmi.c
index 2df1b2d5e3ea..70e5c4c0574d 100644
--- a/drivers/platform/x86/huawei-wmi.c
+++ b/drivers/platform/x86/huawei-wmi.c
@@ -830,7 +830,7 @@ static int huawei_wmi_probe(struct platform_device *pdev)
return 0;
}
-static int huawei_wmi_remove(struct platform_device *pdev)
+static void huawei_wmi_remove(struct platform_device *pdev)
{
const struct wmi_device_id *guid = huawei_wmi_events_id_table;
@@ -846,8 +846,6 @@ static int huawei_wmi_remove(struct platform_device *pdev)
huawei_wmi_battery_exit(&pdev->dev);
huawei_wmi_fn_lock_exit(&pdev->dev);
}
-
- return 0;
}
static struct platform_driver huawei_wmi_driver = {
@@ -855,7 +853,7 @@ static struct platform_driver huawei_wmi_driver = {
.name = "huawei-wmi",
},
.probe = huawei_wmi_probe,
- .remove = huawei_wmi_remove,
+ .remove_new = huawei_wmi_remove,
};
static __init int huawei_wmi_init(void)
diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c
index 959ec3c5f376..d2fee9a3e239 100644
--- a/drivers/platform/x86/ideapad-laptop.c
+++ b/drivers/platform/x86/ideapad-laptop.c
@@ -20,7 +20,6 @@
#include <linux/init.h>
#include <linux/input.h>
#include <linux/input/sparse-keymap.h>
-#include <linux/jiffies.h>
#include <linux/kernel.h>
#include <linux/leds.h>
#include <linux/module.h>
@@ -31,6 +30,7 @@
#include <linux/sysfs.h>
#include <linux/types.h>
#include <linux/wmi.h>
+#include "ideapad-laptop.h"
#include <acpi/video.h>
@@ -85,33 +85,6 @@ enum {
SALS_FNLOCK_OFF = 0xf,
};
-enum {
- VPCCMD_R_VPC1 = 0x10,
- VPCCMD_R_BL_MAX,
- VPCCMD_R_BL,
- VPCCMD_W_BL,
- VPCCMD_R_WIFI,
- VPCCMD_W_WIFI,
- VPCCMD_R_BT,
- VPCCMD_W_BT,
- VPCCMD_R_BL_POWER,
- VPCCMD_R_NOVO,
- VPCCMD_R_VPC2,
- VPCCMD_R_TOUCHPAD,
- VPCCMD_W_TOUCHPAD,
- VPCCMD_R_CAMERA,
- VPCCMD_W_CAMERA,
- VPCCMD_R_3G,
- VPCCMD_W_3G,
- VPCCMD_R_ODD, /* 0x21 */
- VPCCMD_W_FAN,
- VPCCMD_R_RF,
- VPCCMD_W_RF,
- VPCCMD_R_FAN = 0x2B,
- VPCCMD_R_SPECIAL_BUTTONS = 0x31,
- VPCCMD_W_BL_POWER = 0x33,
-};
-
struct ideapad_dytc_priv {
enum platform_profile_option current_profile;
struct platform_profile_handler pprof;
@@ -227,7 +200,6 @@ static void ideapad_shared_exit(struct ideapad_private *priv)
/*
* ACPI Helpers
*/
-#define IDEAPAD_EC_TIMEOUT 200 /* in ms */
static int eval_int(acpi_handle handle, const char *name, unsigned long *res)
{
@@ -270,116 +242,11 @@ static int exec_sals(acpi_handle handle, unsigned long arg)
return exec_simple_method(handle, "SALS", arg);
}
-static int eval_int_with_arg(acpi_handle handle, const char *name, unsigned long arg, unsigned long *res)
-{
- struct acpi_object_list params;
- unsigned long long result;
- union acpi_object in_obj;
- acpi_status status;
-
- params.count = 1;
- params.pointer = &in_obj;
- in_obj.type = ACPI_TYPE_INTEGER;
- in_obj.integer.value = arg;
-
- status = acpi_evaluate_integer(handle, (char *)name, &params, &result);
- if (ACPI_FAILURE(status))
- return -EIO;
-
- if (res)
- *res = result;
-
- return 0;
-}
-
static int eval_dytc(acpi_handle handle, unsigned long cmd, unsigned long *res)
{
return eval_int_with_arg(handle, "DYTC", cmd, res);
}
-static int eval_vpcr(acpi_handle handle, unsigned long cmd, unsigned long *res)
-{
- return eval_int_with_arg(handle, "VPCR", cmd, res);
-}
-
-static int eval_vpcw(acpi_handle handle, unsigned long cmd, unsigned long data)
-{
- struct acpi_object_list params;
- union acpi_object in_obj[2];
- acpi_status status;
-
- params.count = 2;
- params.pointer = in_obj;
- in_obj[0].type = ACPI_TYPE_INTEGER;
- in_obj[0].integer.value = cmd;
- in_obj[1].type = ACPI_TYPE_INTEGER;
- in_obj[1].integer.value = data;
-
- status = acpi_evaluate_object(handle, "VPCW", &params, NULL);
- if (ACPI_FAILURE(status))
- return -EIO;
-
- return 0;
-}
-
-static int read_ec_data(acpi_handle handle, unsigned long cmd, unsigned long *data)
-{
- unsigned long end_jiffies, val;
- int err;
-
- err = eval_vpcw(handle, 1, cmd);
- if (err)
- return err;
-
- end_jiffies = jiffies + msecs_to_jiffies(IDEAPAD_EC_TIMEOUT) + 1;
-
- while (time_before(jiffies, end_jiffies)) {
- schedule();
-
- err = eval_vpcr(handle, 1, &val);
- if (err)
- return err;
-
- if (val == 0)
- return eval_vpcr(handle, 0, data);
- }
-
- acpi_handle_err(handle, "timeout in %s\n", __func__);
-
- return -ETIMEDOUT;
-}
-
-static int write_ec_cmd(acpi_handle handle, unsigned long cmd, unsigned long data)
-{
- unsigned long end_jiffies, val;
- int err;
-
- err = eval_vpcw(handle, 0, data);
- if (err)
- return err;
-
- err = eval_vpcw(handle, 1, cmd);
- if (err)
- return err;
-
- end_jiffies = jiffies + msecs_to_jiffies(IDEAPAD_EC_TIMEOUT) + 1;
-
- while (time_before(jiffies, end_jiffies)) {
- schedule();
-
- err = eval_vpcr(handle, 1, &val);
- if (err)
- return err;
-
- if (val == 0)
- return 0;
- }
-
- acpi_handle_err(handle, "timeout in %s\n", __func__);
-
- return -ETIMEDOUT;
-}
-
/*
* debugfs
*/
@@ -1918,7 +1785,7 @@ input_failed:
return err;
}
-static int ideapad_acpi_remove(struct platform_device *pdev)
+static void ideapad_acpi_remove(struct platform_device *pdev)
{
struct ideapad_private *priv = dev_get_drvdata(&pdev->dev);
int i;
@@ -1939,8 +1806,6 @@ static int ideapad_acpi_remove(struct platform_device *pdev)
ideapad_input_exit(priv);
ideapad_debugfs_exit(priv);
ideapad_sysfs_exit(priv);
-
- return 0;
}
#ifdef CONFIG_PM_SLEEP
@@ -1967,7 +1832,7 @@ MODULE_DEVICE_TABLE(acpi, ideapad_device_ids);
static struct platform_driver ideapad_acpi_driver = {
.probe = ideapad_acpi_add,
- .remove = ideapad_acpi_remove,
+ .remove_new = ideapad_acpi_remove,
.driver = {
.name = "ideapad_acpi",
.pm = &ideapad_pm,
diff --git a/drivers/platform/x86/ideapad-laptop.h b/drivers/platform/x86/ideapad-laptop.h
new file mode 100644
index 000000000000..4498a96de597
--- /dev/null
+++ b/drivers/platform/x86/ideapad-laptop.h
@@ -0,0 +1,152 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * ideapad-laptop.h - Lenovo IdeaPad ACPI Extras
+ *
+ * Copyright © 2010 Intel Corporation
+ * Copyright © 2010 David Woodhouse <dwmw2@infradead.org>
+ */
+
+#ifndef _IDEAPAD_LAPTOP_H_
+#define _IDEAPAD_LAPTOP_H_
+
+#include <linux/acpi.h>
+#include <linux/jiffies.h>
+#include <linux/errno.h>
+
+enum {
+ VPCCMD_R_VPC1 = 0x10,
+ VPCCMD_R_BL_MAX,
+ VPCCMD_R_BL,
+ VPCCMD_W_BL,
+ VPCCMD_R_WIFI,
+ VPCCMD_W_WIFI,
+ VPCCMD_R_BT,
+ VPCCMD_W_BT,
+ VPCCMD_R_BL_POWER,
+ VPCCMD_R_NOVO,
+ VPCCMD_R_VPC2,
+ VPCCMD_R_TOUCHPAD,
+ VPCCMD_W_TOUCHPAD,
+ VPCCMD_R_CAMERA,
+ VPCCMD_W_CAMERA,
+ VPCCMD_R_3G,
+ VPCCMD_W_3G,
+ VPCCMD_R_ODD, /* 0x21 */
+ VPCCMD_W_FAN,
+ VPCCMD_R_RF,
+ VPCCMD_W_RF,
+ VPCCMD_W_YMC = 0x2A,
+ VPCCMD_R_FAN = 0x2B,
+ VPCCMD_R_SPECIAL_BUTTONS = 0x31,
+ VPCCMD_W_BL_POWER = 0x33,
+};
+
+static inline int eval_int_with_arg(acpi_handle handle, const char *name, unsigned long arg, unsigned long *res)
+{
+ struct acpi_object_list params;
+ unsigned long long result;
+ union acpi_object in_obj;
+ acpi_status status;
+
+ params.count = 1;
+ params.pointer = &in_obj;
+ in_obj.type = ACPI_TYPE_INTEGER;
+ in_obj.integer.value = arg;
+
+ status = acpi_evaluate_integer(handle, (char *)name, &params, &result);
+ if (ACPI_FAILURE(status))
+ return -EIO;
+
+ if (res)
+ *res = result;
+
+ return 0;
+}
+
+static inline int eval_vpcr(acpi_handle handle, unsigned long cmd, unsigned long *res)
+{
+ return eval_int_with_arg(handle, "VPCR", cmd, res);
+}
+
+static inline int eval_vpcw(acpi_handle handle, unsigned long cmd, unsigned long data)
+{
+ struct acpi_object_list params;
+ union acpi_object in_obj[2];
+ acpi_status status;
+
+ params.count = 2;
+ params.pointer = in_obj;
+ in_obj[0].type = ACPI_TYPE_INTEGER;
+ in_obj[0].integer.value = cmd;
+ in_obj[1].type = ACPI_TYPE_INTEGER;
+ in_obj[1].integer.value = data;
+
+ status = acpi_evaluate_object(handle, "VPCW", &params, NULL);
+ if (ACPI_FAILURE(status))
+ return -EIO;
+
+ return 0;
+}
+
+#define IDEAPAD_EC_TIMEOUT 200 /* in ms */
+
+static inline int read_ec_data(acpi_handle handle, unsigned long cmd, unsigned long *data)
+{
+ unsigned long end_jiffies, val;
+ int err;
+
+ err = eval_vpcw(handle, 1, cmd);
+ if (err)
+ return err;
+
+ end_jiffies = jiffies + msecs_to_jiffies(IDEAPAD_EC_TIMEOUT) + 1;
+
+ while (time_before(jiffies, end_jiffies)) {
+ schedule();
+
+ err = eval_vpcr(handle, 1, &val);
+ if (err)
+ return err;
+
+ if (val == 0)
+ return eval_vpcr(handle, 0, data);
+ }
+
+ acpi_handle_err(handle, "timeout in %s\n", __func__);
+
+ return -ETIMEDOUT;
+}
+
+static inline int write_ec_cmd(acpi_handle handle, unsigned long cmd, unsigned long data)
+{
+ unsigned long end_jiffies, val;
+ int err;
+
+ err = eval_vpcw(handle, 0, data);
+ if (err)
+ return err;
+
+ err = eval_vpcw(handle, 1, cmd);
+ if (err)
+ return err;
+
+ end_jiffies = jiffies + msecs_to_jiffies(IDEAPAD_EC_TIMEOUT) + 1;
+
+ while (time_before(jiffies, end_jiffies)) {
+ schedule();
+
+ err = eval_vpcr(handle, 1, &val);
+ if (err)
+ return err;
+
+ if (val == 0)
+ return 0;
+ }
+
+ acpi_handle_err(handle, "timeout in %s\n", __func__);
+
+ return -ETIMEDOUT;
+}
+
+#undef IDEAPAD_EC_TIMEOUT
+#endif /* !_IDEAPAD_LAPTOP_H_ */
diff --git a/drivers/platform/x86/intel/Kconfig b/drivers/platform/x86/intel/Kconfig
index bbbd9e54e9ee..e9dc0c021029 100644
--- a/drivers/platform/x86/intel/Kconfig
+++ b/drivers/platform/x86/intel/Kconfig
@@ -80,6 +80,16 @@ config INTEL_BXTWC_PMIC_TMU
This driver enables the alarm wakeup functionality in the TMU unit of
Whiskey Cove PMIC.
+config INTEL_BYTCRC_PWRSRC
+ tristate "Intel Bay Trail Crystal Cove power source driver"
+ depends on INTEL_SOC_PMIC
+ help
+ This option adds a power source driver for Crystal Cove PMICs
+ on Intel Bay Trail devices.
+
+ To compile this driver as a module, choose M here: the module
+ will be called intel_bytcrc_pwrsrc.
+
config INTEL_CHTDC_TI_PWRBTN
tristate "Intel Cherry Trail Dollar Cove TI power button driver"
depends on INTEL_SOC_PMIC_CHTDC_TI
diff --git a/drivers/platform/x86/intel/Makefile b/drivers/platform/x86/intel/Makefile
index 411df4040427..c1d5fe05e3f3 100644
--- a/drivers/platform/x86/intel/Makefile
+++ b/drivers/platform/x86/intel/Makefile
@@ -38,6 +38,8 @@ intel_bxtwc_tmu-y := bxtwc_tmu.o
obj-$(CONFIG_INTEL_BXTWC_PMIC_TMU) += intel_bxtwc_tmu.o
intel_crystal_cove_charger-y := crystal_cove_charger.o
obj-$(CONFIG_X86_ANDROID_TABLETS) += intel_crystal_cove_charger.o
+intel_bytcrc_pwrsrc-y := bytcrc_pwrsrc.o
+obj-$(CONFIG_INTEL_BYTCRC_PWRSRC) += intel_bytcrc_pwrsrc.o
intel_chtdc_ti_pwrbtn-y := chtdc_ti_pwrbtn.o
obj-$(CONFIG_INTEL_CHTDC_TI_PWRBTN) += intel_chtdc_ti_pwrbtn.o
intel_chtwc_int33fe-y := chtwc_int33fe.o
diff --git a/drivers/platform/x86/intel/bxtwc_tmu.c b/drivers/platform/x86/intel/bxtwc_tmu.c
index 7ccf583649e6..d0e2a3c293b0 100644
--- a/drivers/platform/x86/intel/bxtwc_tmu.c
+++ b/drivers/platform/x86/intel/bxtwc_tmu.c
@@ -89,7 +89,7 @@ static int bxt_wcove_tmu_probe(struct platform_device *pdev)
return 0;
}
-static int bxt_wcove_tmu_remove(struct platform_device *pdev)
+static void bxt_wcove_tmu_remove(struct platform_device *pdev)
{
struct wcove_tmu *wctmu = platform_get_drvdata(pdev);
unsigned int val;
@@ -101,7 +101,6 @@ static int bxt_wcove_tmu_remove(struct platform_device *pdev)
regmap_read(wctmu->regmap, BXTWC_MTMUIRQ_REG, &val);
regmap_write(wctmu->regmap, BXTWC_MTMUIRQ_REG,
val | BXTWC_TMU_ALRM_MASK);
- return 0;
}
#ifdef CONFIG_PM_SLEEP
@@ -132,7 +131,7 @@ MODULE_DEVICE_TABLE(platform, bxt_wcove_tmu_id_table);
static struct platform_driver bxt_wcove_tmu_driver = {
.probe = bxt_wcove_tmu_probe,
- .remove = bxt_wcove_tmu_remove,
+ .remove_new = bxt_wcove_tmu_remove,
.driver = {
.name = "bxt_wcove_tmu",
.pm = &bxtwc_tmu_pm_ops,
diff --git a/drivers/platform/x86/intel/bytcrc_pwrsrc.c b/drivers/platform/x86/intel/bytcrc_pwrsrc.c
new file mode 100644
index 000000000000..8a022b90d12d
--- /dev/null
+++ b/drivers/platform/x86/intel/bytcrc_pwrsrc.c
@@ -0,0 +1,181 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Power-source driver for Bay Trail Crystal Cove PMIC
+ *
+ * Copyright (c) 2023 Hans de Goede <hdegoede@redhat.com>
+ *
+ * Based on intel_crystalcove_pwrsrc.c from Android kernel sources, which is:
+ * Copyright (C) 2013 Intel Corporation
+ */
+
+#include <linux/debugfs.h>
+#include <linux/mfd/intel_soc_pmic.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+
+#define CRYSTALCOVE_SPWRSRC_REG 0x1E
+#define CRYSTALCOVE_RESETSRC0_REG 0x20
+#define CRYSTALCOVE_RESETSRC1_REG 0x21
+#define CRYSTALCOVE_WAKESRC_REG 0x22
+
+struct crc_pwrsrc_data {
+ struct regmap *regmap;
+ struct dentry *debug_dentry;
+ unsigned int resetsrc0;
+ unsigned int resetsrc1;
+ unsigned int wakesrc;
+};
+
+static const char * const pwrsrc_pwrsrc_info[] = {
+ /* bit 0 */ "USB",
+ /* bit 1 */ "DC in",
+ /* bit 2 */ "Battery",
+ NULL,
+};
+
+static const char * const pwrsrc_resetsrc0_info[] = {
+ /* bit 0 */ "SOC reporting a thermal event",
+ /* bit 1 */ "critical PMIC temperature",
+ /* bit 2 */ "critical system temperature",
+ /* bit 3 */ "critical battery temperature",
+ /* bit 4 */ "VSYS under voltage",
+ /* bit 5 */ "VSYS over voltage",
+ /* bit 6 */ "battery removal",
+ NULL,
+};
+
+static const char * const pwrsrc_resetsrc1_info[] = {
+ /* bit 0 */ "VCRIT threshold",
+ /* bit 1 */ "BATID reporting battery removal",
+ /* bit 2 */ "user pressing the power button",
+ NULL,
+};
+
+static const char * const pwrsrc_wakesrc_info[] = {
+ /* bit 0 */ "user pressing the power button",
+ /* bit 1 */ "a battery insertion",
+ /* bit 2 */ "a USB charger insertion",
+ /* bit 3 */ "an adapter insertion",
+ NULL,
+};
+
+static void crc_pwrsrc_log(struct seq_file *seq, const char *prefix,
+ const char * const *info, unsigned int reg_val)
+{
+ int i;
+
+ for (i = 0; info[i]; i++) {
+ if (reg_val & BIT(i))
+ seq_printf(seq, "%s by %s\n", prefix, info[i]);
+ }
+}
+
+static int pwrsrc_show(struct seq_file *seq, void *unused)
+{
+ struct crc_pwrsrc_data *data = seq->private;
+ unsigned int reg_val;
+ int ret;
+
+ ret = regmap_read(data->regmap, CRYSTALCOVE_SPWRSRC_REG, &reg_val);
+ if (ret)
+ return ret;
+
+ crc_pwrsrc_log(seq, "System powered", pwrsrc_pwrsrc_info, reg_val);
+ return 0;
+}
+
+static int resetsrc_show(struct seq_file *seq, void *unused)
+{
+ struct crc_pwrsrc_data *data = seq->private;
+
+ crc_pwrsrc_log(seq, "Last shutdown caused", pwrsrc_resetsrc0_info, data->resetsrc0);
+ crc_pwrsrc_log(seq, "Last shutdown caused", pwrsrc_resetsrc1_info, data->resetsrc1);
+ return 0;
+}
+
+static int wakesrc_show(struct seq_file *seq, void *unused)
+{
+ struct crc_pwrsrc_data *data = seq->private;
+
+ crc_pwrsrc_log(seq, "Last wake caused", pwrsrc_wakesrc_info, data->wakesrc);
+ return 0;
+}
+
+DEFINE_SHOW_ATTRIBUTE(pwrsrc);
+DEFINE_SHOW_ATTRIBUTE(resetsrc);
+DEFINE_SHOW_ATTRIBUTE(wakesrc);
+
+static int crc_pwrsrc_read_and_clear(struct crc_pwrsrc_data *data,
+ unsigned int reg, unsigned int *val)
+{
+ int ret;
+
+ ret = regmap_read(data->regmap, reg, val);
+ if (ret)
+ return ret;
+
+ return regmap_write(data->regmap, reg, *val);
+}
+
+static int crc_pwrsrc_probe(struct platform_device *pdev)
+{
+ struct intel_soc_pmic *pmic = dev_get_drvdata(pdev->dev.parent);
+ struct crc_pwrsrc_data *data;
+ int ret;
+
+ data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
+ if (!data)
+ return -ENOMEM;
+
+ data->regmap = pmic->regmap;
+
+ /*
+ * Read + clear resetsrc0/1 and wakesrc now, so that they get
+ * cleared even if the debugfs interface is never used.
+ *
+ * Properly clearing the wakesrc is important, leaving bit 0 of it
+ * set turns reboot into poweroff on some tablets.
+ */
+ ret = crc_pwrsrc_read_and_clear(data, CRYSTALCOVE_RESETSRC0_REG, &data->resetsrc0);
+ if (ret)
+ return ret;
+
+ ret = crc_pwrsrc_read_and_clear(data, CRYSTALCOVE_RESETSRC1_REG, &data->resetsrc1);
+ if (ret)
+ return ret;
+
+ ret = crc_pwrsrc_read_and_clear(data, CRYSTALCOVE_WAKESRC_REG, &data->wakesrc);
+ if (ret)
+ return ret;
+
+ data->debug_dentry = debugfs_create_dir(KBUILD_MODNAME, NULL);
+ debugfs_create_file("pwrsrc", 0444, data->debug_dentry, data, &pwrsrc_fops);
+ debugfs_create_file("resetsrc", 0444, data->debug_dentry, data, &resetsrc_fops);
+ debugfs_create_file("wakesrc", 0444, data->debug_dentry, data, &wakesrc_fops);
+
+ platform_set_drvdata(pdev, data);
+ return 0;
+}
+
+static int crc_pwrsrc_remove(struct platform_device *pdev)
+{
+ struct crc_pwrsrc_data *data = platform_get_drvdata(pdev);
+
+ debugfs_remove_recursive(data->debug_dentry);
+ return 0;
+}
+
+static struct platform_driver crc_pwrsrc_driver = {
+ .probe = crc_pwrsrc_probe,
+ .remove = crc_pwrsrc_remove,
+ .driver = {
+ .name = "crystal_cove_pwrsrc",
+ },
+};
+module_platform_driver(crc_pwrsrc_driver);
+
+MODULE_ALIAS("platform:crystal_cove_pwrsrc");
+MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>");
+MODULE_DESCRIPTION("Power-source driver for Bay Trail Crystal Cove PMIC");
+MODULE_LICENSE("GPL");
diff --git a/drivers/platform/x86/intel/chtdc_ti_pwrbtn.c b/drivers/platform/x86/intel/chtdc_ti_pwrbtn.c
index 9606a994af22..615f8d1a0c68 100644
--- a/drivers/platform/x86/intel/chtdc_ti_pwrbtn.c
+++ b/drivers/platform/x86/intel/chtdc_ti_pwrbtn.c
@@ -67,11 +67,10 @@ static int chtdc_ti_pwrbtn_probe(struct platform_device *pdev)
return 0;
}
-static int chtdc_ti_pwrbtn_remove(struct platform_device *pdev)
+static void chtdc_ti_pwrbtn_remove(struct platform_device *pdev)
{
dev_pm_clear_wake_irq(&pdev->dev);
device_init_wakeup(&pdev->dev, false);
- return 0;
}
static const struct platform_device_id chtdc_ti_pwrbtn_id_table[] = {
@@ -85,7 +84,7 @@ static struct platform_driver chtdc_ti_pwrbtn_driver = {
.name = KBUILD_MODNAME,
},
.probe = chtdc_ti_pwrbtn_probe,
- .remove = chtdc_ti_pwrbtn_remove,
+ .remove_new = chtdc_ti_pwrbtn_remove,
.id_table = chtdc_ti_pwrbtn_id_table,
};
module_platform_driver(chtdc_ti_pwrbtn_driver);
diff --git a/drivers/platform/x86/intel/chtwc_int33fe.c b/drivers/platform/x86/intel/chtwc_int33fe.c
index 2c9a7d52be07..848baecc1bb0 100644
--- a/drivers/platform/x86/intel/chtwc_int33fe.c
+++ b/drivers/platform/x86/intel/chtwc_int33fe.c
@@ -405,7 +405,7 @@ out_remove_nodes:
return ret;
}
-static int cht_int33fe_typec_remove(struct platform_device *pdev)
+static void cht_int33fe_typec_remove(struct platform_device *pdev)
{
struct cht_int33fe_data *data = platform_get_drvdata(pdev);
@@ -414,8 +414,6 @@ static int cht_int33fe_typec_remove(struct platform_device *pdev)
i2c_unregister_device(data->battery_fg);
cht_int33fe_remove_nodes(data);
-
- return 0;
}
static const struct acpi_device_id cht_int33fe_acpi_ids[] = {
@@ -429,7 +427,7 @@ static struct platform_driver cht_int33fe_typec_driver = {
.acpi_match_table = ACPI_PTR(cht_int33fe_acpi_ids),
},
.probe = cht_int33fe_typec_probe,
- .remove = cht_int33fe_typec_remove,
+ .remove_new = cht_int33fe_typec_remove,
};
module_platform_driver(cht_int33fe_typec_driver);
diff --git a/drivers/platform/x86/intel/hid.c b/drivers/platform/x86/intel/hid.c
index b6c06b37862e..5632bd3c534a 100644
--- a/drivers/platform/x86/intel/hid.c
+++ b/drivers/platform/x86/intel/hid.c
@@ -720,7 +720,7 @@ err_remove_notify:
return err;
}
-static int intel_hid_remove(struct platform_device *device)
+static void intel_hid_remove(struct platform_device *device)
{
acpi_handle handle = ACPI_HANDLE(&device->dev);
@@ -728,12 +728,6 @@ static int intel_hid_remove(struct platform_device *device)
acpi_remove_notify_handler(handle, ACPI_DEVICE_NOTIFY, notify_handler);
intel_hid_set_enable(&device->dev, false);
intel_button_array_enable(&device->dev, false);
-
- /*
- * Even if we failed to shut off the event stream, we can still
- * safely detach from the device.
- */
- return 0;
}
static struct platform_driver intel_hid_pl_driver = {
@@ -743,7 +737,7 @@ static struct platform_driver intel_hid_pl_driver = {
.pm = &intel_hid_pl_pm_ops,
},
.probe = intel_hid_probe,
- .remove = intel_hid_remove,
+ .remove_new = intel_hid_remove,
};
/*
diff --git a/drivers/platform/x86/intel/ifs/core.c b/drivers/platform/x86/intel/ifs/core.c
index 206a617c2e02..306f886b52d2 100644
--- a/drivers/platform/x86/intel/ifs/core.c
+++ b/drivers/platform/x86/intel/ifs/core.c
@@ -16,27 +16,63 @@
static const struct x86_cpu_id ifs_cpu_ids[] __initconst = {
X86_MATCH(SAPPHIRERAPIDS_X),
+ X86_MATCH(EMERALDRAPIDS_X),
{}
};
MODULE_DEVICE_TABLE(x86cpu, ifs_cpu_ids);
-static struct ifs_device ifs_device = {
- .data = {
- .integrity_cap_bit = MSR_INTEGRITY_CAPS_PERIODIC_BIST_BIT,
- .test_num = 0,
+ATTRIBUTE_GROUPS(plat_ifs);
+ATTRIBUTE_GROUPS(plat_ifs_array);
+
+bool *ifs_pkg_auth;
+
+static const struct ifs_test_caps scan_test = {
+ .integrity_cap_bit = MSR_INTEGRITY_CAPS_PERIODIC_BIST_BIT,
+ .test_num = IFS_TYPE_SAF,
+};
+
+static const struct ifs_test_caps array_test = {
+ .integrity_cap_bit = MSR_INTEGRITY_CAPS_ARRAY_BIST_BIT,
+ .test_num = IFS_TYPE_ARRAY_BIST,
+};
+
+static struct ifs_device ifs_devices[] = {
+ [IFS_TYPE_SAF] = {
+ .test_caps = &scan_test,
+ .misc = {
+ .name = "intel_ifs_0",
+ .minor = MISC_DYNAMIC_MINOR,
+ .groups = plat_ifs_groups,
+ },
},
- .misc = {
- .name = "intel_ifs_0",
- .nodename = "intel_ifs/0",
- .minor = MISC_DYNAMIC_MINOR,
+ [IFS_TYPE_ARRAY_BIST] = {
+ .test_caps = &array_test,
+ .misc = {
+ .name = "intel_ifs_1",
+ .minor = MISC_DYNAMIC_MINOR,
+ .groups = plat_ifs_array_groups,
+ },
},
};
+#define IFS_NUMTESTS ARRAY_SIZE(ifs_devices)
+
+static void ifs_cleanup(void)
+{
+ int i;
+
+ for (i = 0; i < IFS_NUMTESTS; i++) {
+ if (ifs_devices[i].misc.this_device)
+ misc_deregister(&ifs_devices[i].misc);
+ }
+ kfree(ifs_pkg_auth);
+}
+
static int __init ifs_init(void)
{
const struct x86_cpu_id *m;
u64 msrval;
- int ret;
+ int i, ret;
m = x86_match_cpu(ifs_cpu_ids);
if (!m)
@@ -51,28 +87,27 @@ static int __init ifs_init(void)
if (rdmsrl_safe(MSR_INTEGRITY_CAPS, &msrval))
return -ENODEV;
- ifs_device.misc.groups = ifs_get_groups();
-
- if (!(msrval & BIT(ifs_device.data.integrity_cap_bit)))
- return -ENODEV;
-
- ifs_device.data.pkg_auth = kmalloc_array(topology_max_packages(), sizeof(bool), GFP_KERNEL);
- if (!ifs_device.data.pkg_auth)
+ ifs_pkg_auth = kmalloc_array(topology_max_packages(), sizeof(bool), GFP_KERNEL);
+ if (!ifs_pkg_auth)
return -ENOMEM;
- ret = misc_register(&ifs_device.misc);
- if (ret) {
- kfree(ifs_device.data.pkg_auth);
- return ret;
+ for (i = 0; i < IFS_NUMTESTS; i++) {
+ if (!(msrval & BIT(ifs_devices[i].test_caps->integrity_cap_bit)))
+ continue;
+ ret = misc_register(&ifs_devices[i].misc);
+ if (ret)
+ goto err_exit;
}
-
return 0;
+
+err_exit:
+ ifs_cleanup();
+ return ret;
}
static void __exit ifs_exit(void)
{
- misc_deregister(&ifs_device.misc);
- kfree(ifs_device.data.pkg_auth);
+ ifs_cleanup();
}
module_init(ifs_init);
diff --git a/drivers/platform/x86/intel/ifs/ifs.h b/drivers/platform/x86/intel/ifs/ifs.h
index 046e39304fd5..93191855890f 100644
--- a/drivers/platform/x86/intel/ifs/ifs.h
+++ b/drivers/platform/x86/intel/ifs/ifs.h
@@ -17,7 +17,7 @@
* In Field Scan (IFS) is a hardware feature to run circuit level tests on
* a CPU core to detect problems that are not caught by parity or ECC checks.
* Future CPUs will support more than one type of test which will show up
- * with a new platform-device instance-id, for now only .0 is exposed.
+ * with a new platform-device instance-id.
*
*
* IFS Image
@@ -25,7 +25,10 @@
*
* Intel provides a firmware file containing the scan tests via
* github [#f1]_. Similar to microcode there is a separate file for each
- * family-model-stepping.
+ * family-model-stepping. IFS Images are not applicable for some test types.
+ * Wherever applicable the sysfs directory would provide a "current_batch" file
+ * (see below) for loading the image.
+ *
*
* IFS Image Loading
* -----------------
@@ -35,7 +38,7 @@
* SHA hashes for the test. Then the tests themselves. Status MSRs provide
* feedback on the success/failure of these steps.
*
- * The test files are kept in a fixed location: /lib/firmware/intel/ifs_0/
+ * The test files are kept in a fixed location: /lib/firmware/intel/ifs_<n>/
* For e.g if there are 3 test files, they would be named in the following
* fashion:
* ff-mm-ss-01.scan
@@ -47,7 +50,7 @@
* (e.g 1, 2 or 3 in the above scenario) into the curent_batch file.
* To load ff-mm-ss-02.scan, the following command can be used::
*
- * # echo 2 > /sys/devices/virtual/misc/intel_ifs_0/current_batch
+ * # echo 2 > /sys/devices/virtual/misc/intel_ifs_<n>/current_batch
*
* The above file can also be read to know the currently loaded image.
*
@@ -69,16 +72,16 @@
* to migrate those applications to other cores before running a core test.
* It may also be necessary to redirect interrupts to other CPUs.
*
- * In all cases reading the SCAN_STATUS MSR provides details on what
+ * In all cases reading the corresponding test's STATUS MSR provides details on what
* happened. The driver makes the value of this MSR visible to applications
* via the "details" file (see below). Interrupted tests may be restarted.
*
- * The IFS driver provides sysfs interfaces via /sys/devices/virtual/misc/intel_ifs_0/
+ * The IFS driver provides sysfs interfaces via /sys/devices/virtual/misc/intel_ifs_<n>/
* to control execution:
*
* Test a specific core::
*
- * # echo <cpu#> > /sys/devices/virtual/misc/intel_ifs_0/run_test
+ * # echo <cpu#> > /sys/devices/virtual/misc/intel_ifs_<n>/run_test
*
* when HT is enabled any of the sibling cpu# can be specified to test
* its corresponding physical core. Since the tests are per physical core,
@@ -87,21 +90,21 @@
*
* For e.g. to test core corresponding to cpu5
*
- * # echo 5 > /sys/devices/virtual/misc/intel_ifs_0/run_test
+ * # echo 5 > /sys/devices/virtual/misc/intel_ifs_<n>/run_test
*
* Results of the last test is provided in /sys::
*
- * $ cat /sys/devices/virtual/misc/intel_ifs_0/status
+ * $ cat /sys/devices/virtual/misc/intel_ifs_<n>/status
* pass
*
* Status can be one of pass, fail, untested
*
* Additional details of the last test is provided by the details file::
*
- * $ cat /sys/devices/virtual/misc/intel_ifs_0/details
+ * $ cat /sys/devices/virtual/misc/intel_ifs_<n>/details
* 0x8081
*
- * The details file reports the hex value of the SCAN_STATUS MSR.
+ * The details file reports the hex value of the test specific status MSR.
* Hardware defined error codes are documented in volume 4 of the Intel
* Software Developer's Manual but the error_code field may contain one of
* the following driver defined software codes:
@@ -127,6 +130,7 @@
#include <linux/device.h>
#include <linux/miscdevice.h>
+#define MSR_ARRAY_BIST 0x00000105
#define MSR_COPY_SCAN_HASHES 0x000002c2
#define MSR_SCAN_HASHES_STATUS 0x000002c3
#define MSR_AUTHENTICATE_AND_COPY_CHUNK 0x000002c4
@@ -137,6 +141,9 @@
#define SCAN_TEST_PASS 1
#define SCAN_TEST_FAIL 2
+#define IFS_TYPE_SAF 0
+#define IFS_TYPE_ARRAY_BIST 1
+
/* MSR_SCAN_HASHES_STATUS bit fields */
union ifs_scan_hashes_status {
u64 data;
@@ -189,6 +196,17 @@ union ifs_status {
};
};
+/* MSR_ARRAY_BIST bit fields */
+union ifs_array {
+ u64 data;
+ struct {
+ u32 array_bitmask;
+ u16 array_bank;
+ u16 rsvd :15;
+ u16 ctrl_result :1;
+ };
+};
+
/*
* Driver populated error-codes
* 0xFD: Test timed out before completing all the chunks.
@@ -197,22 +215,22 @@ union ifs_status {
#define IFS_SW_TIMEOUT 0xFD
#define IFS_SW_PARTIAL_COMPLETION 0xFE
+struct ifs_test_caps {
+ int integrity_cap_bit;
+ int test_num;
+};
+
/**
* struct ifs_data - attributes related to intel IFS driver
- * @integrity_cap_bit: MSR_INTEGRITY_CAPS bit enumerating this test
* @loaded_version: stores the currently loaded ifs image version.
- * @pkg_auth: array of bool storing per package auth status
* @loaded: If a valid test binary has been loaded into the memory
* @loading_error: Error occurred on another CPU while loading image
* @valid_chunks: number of chunks which could be validated.
* @status: it holds simple status pass/fail/untested
* @scan_details: opaque scan status code from h/w
* @cur_batch: number indicating the currently loaded test file
- * @test_num: number indicating the test type
*/
struct ifs_data {
- int integrity_cap_bit;
- bool *pkg_auth;
int loaded_version;
bool loaded;
bool loading_error;
@@ -220,7 +238,6 @@ struct ifs_data {
int status;
u64 scan_details;
u32 cur_batch;
- int test_num;
};
struct ifs_work {
@@ -229,7 +246,8 @@ struct ifs_work {
};
struct ifs_device {
- struct ifs_data data;
+ const struct ifs_test_caps *test_caps;
+ struct ifs_data rw_data;
struct miscdevice misc;
};
@@ -238,11 +256,21 @@ static inline struct ifs_data *ifs_get_data(struct device *dev)
struct miscdevice *m = dev_get_drvdata(dev);
struct ifs_device *d = container_of(m, struct ifs_device, misc);
- return &d->data;
+ return &d->rw_data;
+}
+
+static inline const struct ifs_test_caps *ifs_get_test_caps(struct device *dev)
+{
+ struct miscdevice *m = dev_get_drvdata(dev);
+ struct ifs_device *d = container_of(m, struct ifs_device, misc);
+
+ return d->test_caps;
}
+extern bool *ifs_pkg_auth;
int ifs_load_firmware(struct device *dev);
int do_core_test(int cpu, struct device *dev);
-const struct attribute_group **ifs_get_groups(void);
+extern struct attribute *plat_ifs_attrs[];
+extern struct attribute *plat_ifs_array_attrs[];
#endif
diff --git a/drivers/platform/x86/intel/ifs/load.c b/drivers/platform/x86/intel/ifs/load.c
index c5c24e6fdc43..61dffb4c8a1d 100644
--- a/drivers/platform/x86/intel/ifs/load.c
+++ b/drivers/platform/x86/intel/ifs/load.c
@@ -192,7 +192,7 @@ static int scan_chunks_sanity_check(struct device *dev)
struct ifs_work local_work;
int curr_pkg, cpu, ret;
- memset(ifsd->pkg_auth, 0, (topology_max_packages() * sizeof(bool)));
+ memset(ifs_pkg_auth, 0, (topology_max_packages() * sizeof(bool)));
ret = validate_ifs_metadata(dev);
if (ret)
return ret;
@@ -204,7 +204,7 @@ static int scan_chunks_sanity_check(struct device *dev)
cpus_read_lock();
for_each_online_cpu(cpu) {
curr_pkg = topology_physical_package_id(cpu);
- if (ifsd->pkg_auth[curr_pkg])
+ if (ifs_pkg_auth[curr_pkg])
continue;
reinit_completion(&ifs_done);
local_work.dev = dev;
@@ -215,7 +215,7 @@ static int scan_chunks_sanity_check(struct device *dev)
ret = -EIO;
goto out;
}
- ifsd->pkg_auth[curr_pkg] = 1;
+ ifs_pkg_auth[curr_pkg] = 1;
}
ret = 0;
out:
@@ -257,13 +257,14 @@ static int image_sanity_check(struct device *dev, const struct microcode_header_
*/
int ifs_load_firmware(struct device *dev)
{
+ const struct ifs_test_caps *test = ifs_get_test_caps(dev);
struct ifs_data *ifsd = ifs_get_data(dev);
const struct firmware *fw;
char scan_path[64];
int ret = -EINVAL;
snprintf(scan_path, sizeof(scan_path), "intel/ifs_%d/%02x-%02x-%02x-%02x.scan",
- ifsd->test_num, boot_cpu_data.x86, boot_cpu_data.x86_model,
+ test->test_num, boot_cpu_data.x86, boot_cpu_data.x86_model,
boot_cpu_data.x86_stepping, ifsd->cur_batch);
ret = request_firmware_direct(&fw, scan_path, dev);
diff --git a/drivers/platform/x86/intel/ifs/runtest.c b/drivers/platform/x86/intel/ifs/runtest.c
index 0bfd8fcdd7e8..1061eb7ec399 100644
--- a/drivers/platform/x86/intel/ifs/runtest.c
+++ b/drivers/platform/x86/intel/ifs/runtest.c
@@ -229,6 +229,85 @@ static void ifs_test_core(int cpu, struct device *dev)
}
}
+#define SPINUNIT 100 /* 100 nsec */
+static atomic_t array_cpus_out;
+
+/*
+ * Simplified cpu sibling rendezvous loop based on microcode loader __wait_for_cpus()
+ */
+static void wait_for_sibling_cpu(atomic_t *t, long long timeout)
+{
+ int cpu = smp_processor_id();
+ const struct cpumask *smt_mask = cpu_smt_mask(cpu);
+ int all_cpus = cpumask_weight(smt_mask);
+
+ atomic_inc(t);
+ while (atomic_read(t) < all_cpus) {
+ if (timeout < SPINUNIT)
+ return;
+ ndelay(SPINUNIT);
+ timeout -= SPINUNIT;
+ touch_nmi_watchdog();
+ }
+}
+
+static int do_array_test(void *data)
+{
+ union ifs_array *command = data;
+ int cpu = smp_processor_id();
+ int first;
+
+ /*
+ * Only one logical CPU on a core needs to trigger the Array test via MSR write.
+ */
+ first = cpumask_first(cpu_smt_mask(cpu));
+
+ if (cpu == first) {
+ wrmsrl(MSR_ARRAY_BIST, command->data);
+ /* Pass back the result of the test */
+ rdmsrl(MSR_ARRAY_BIST, command->data);
+ }
+
+ /* Tests complete faster if the sibling is spinning here */
+ wait_for_sibling_cpu(&array_cpus_out, NSEC_PER_SEC);
+
+ return 0;
+}
+
+static void ifs_array_test_core(int cpu, struct device *dev)
+{
+ union ifs_array command = {};
+ bool timed_out = false;
+ struct ifs_data *ifsd;
+ unsigned long timeout;
+
+ ifsd = ifs_get_data(dev);
+
+ command.array_bitmask = ~0U;
+ timeout = jiffies + HZ / 2;
+
+ do {
+ if (time_after(jiffies, timeout)) {
+ timed_out = true;
+ break;
+ }
+ atomic_set(&array_cpus_out, 0);
+ stop_core_cpuslocked(cpu, do_array_test, &command);
+
+ if (command.ctrl_result)
+ break;
+ } while (command.array_bitmask);
+
+ ifsd->scan_details = command.data;
+
+ if (command.ctrl_result)
+ ifsd->status = SCAN_TEST_FAIL;
+ else if (timed_out || command.array_bitmask)
+ ifsd->status = SCAN_NOT_TESTED;
+ else
+ ifsd->status = SCAN_TEST_PASS;
+}
+
/*
* Initiate per core test. It wakes up work queue threads on the target cpu and
* its sibling cpu. Once all sibling threads wake up, the scan test gets executed and
@@ -236,6 +315,8 @@ static void ifs_test_core(int cpu, struct device *dev)
*/
int do_core_test(int cpu, struct device *dev)
{
+ const struct ifs_test_caps *test = ifs_get_test_caps(dev);
+ struct ifs_data *ifsd = ifs_get_data(dev);
int ret = 0;
/* Prevent CPUs from being taken offline during the scan test */
@@ -247,7 +328,18 @@ int do_core_test(int cpu, struct device *dev)
goto out;
}
- ifs_test_core(cpu, dev);
+ switch (test->test_num) {
+ case IFS_TYPE_SAF:
+ if (!ifsd->loaded)
+ return -EPERM;
+ ifs_test_core(cpu, dev);
+ break;
+ case IFS_TYPE_ARRAY_BIST:
+ ifs_array_test_core(cpu, dev);
+ break;
+ default:
+ return -EINVAL;
+ }
out:
cpus_read_unlock();
return ret;
diff --git a/drivers/platform/x86/intel/ifs/sysfs.c b/drivers/platform/x86/intel/ifs/sysfs.c
index ee636a76b083..d856d6b8fc03 100644
--- a/drivers/platform/x86/intel/ifs/sysfs.c
+++ b/drivers/platform/x86/intel/ifs/sysfs.c
@@ -64,7 +64,6 @@ static ssize_t run_test_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
- struct ifs_data *ifsd = ifs_get_data(dev);
unsigned int cpu;
int rc;
@@ -75,10 +74,7 @@ static ssize_t run_test_store(struct device *dev,
if (down_interruptible(&ifs_sem))
return -EINTR;
- if (!ifsd->loaded)
- rc = -EPERM;
- else
- rc = do_core_test(cpu, dev);
+ rc = do_core_test(cpu, dev);
up(&ifs_sem);
@@ -141,7 +137,7 @@ static ssize_t image_version_show(struct device *dev,
static DEVICE_ATTR_RO(image_version);
/* global scan sysfs attributes */
-static struct attribute *plat_ifs_attrs[] = {
+struct attribute *plat_ifs_attrs[] = {
&dev_attr_details.attr,
&dev_attr_status.attr,
&dev_attr_run_test.attr,
@@ -150,9 +146,10 @@ static struct attribute *plat_ifs_attrs[] = {
NULL
};
-ATTRIBUTE_GROUPS(plat_ifs);
-
-const struct attribute_group **ifs_get_groups(void)
-{
- return plat_ifs_groups;
-}
+/* global array sysfs attributes */
+struct attribute *plat_ifs_array_attrs[] = {
+ &dev_attr_details.attr,
+ &dev_attr_status.attr,
+ &dev_attr_run_test.attr,
+ NULL
+};
diff --git a/drivers/platform/x86/intel/int0002_vgpio.c b/drivers/platform/x86/intel/int0002_vgpio.c
index 97cfbc520a02..b6708bab7c53 100644
--- a/drivers/platform/x86/intel/int0002_vgpio.c
+++ b/drivers/platform/x86/intel/int0002_vgpio.c
@@ -223,11 +223,10 @@ static int int0002_probe(struct platform_device *pdev)
return 0;
}
-static int int0002_remove(struct platform_device *pdev)
+static void int0002_remove(struct platform_device *pdev)
{
device_init_wakeup(&pdev->dev, false);
acpi_unregister_wakeup_handler(int0002_check_wake, NULL);
- return 0;
}
static int int0002_suspend(struct device *dev)
@@ -273,7 +272,7 @@ static struct platform_driver int0002_driver = {
.pm = &int0002_pm_ops,
},
.probe = int0002_probe,
- .remove = int0002_remove,
+ .remove_new = int0002_remove,
};
module_platform_driver(int0002_driver);
diff --git a/drivers/platform/x86/intel/int1092/intel_sar.c b/drivers/platform/x86/intel/int1092/intel_sar.c
index 352fc4596494..6246c066ade2 100644
--- a/drivers/platform/x86/intel/int1092/intel_sar.c
+++ b/drivers/platform/x86/intel/int1092/intel_sar.c
@@ -292,7 +292,7 @@ r_free:
return result;
}
-static int sar_remove(struct platform_device *device)
+static void sar_remove(struct platform_device *device)
{
struct wwan_sar_context *context = dev_get_drvdata(&device->dev);
int reg;
@@ -304,12 +304,11 @@ static int sar_remove(struct platform_device *device)
kfree(context->config_data[reg].device_mode_info);
kfree(context);
- return 0;
}
static struct platform_driver sar_driver = {
.probe = sar_probe,
- .remove = sar_remove,
+ .remove_new = sar_remove,
.driver = {
.name = DRVNAME,
.acpi_match_table = ACPI_PTR(sar_device_ids)
diff --git a/drivers/platform/x86/intel/int3472/discrete.c b/drivers/platform/x86/intel/int3472/discrete.c
index f064da74f50a..ef020e23e596 100644
--- a/drivers/platform/x86/intel/int3472/discrete.c
+++ b/drivers/platform/x86/intel/int3472/discrete.c
@@ -317,7 +317,7 @@ static int skl_int3472_parse_crs(struct int3472_discrete_device *int3472)
return 0;
}
-static int skl_int3472_discrete_remove(struct platform_device *pdev)
+static void skl_int3472_discrete_remove(struct platform_device *pdev)
{
struct int3472_discrete_device *int3472 = platform_get_drvdata(pdev);
@@ -326,8 +326,6 @@ static int skl_int3472_discrete_remove(struct platform_device *pdev)
skl_int3472_unregister_clock(int3472);
skl_int3472_unregister_pled(int3472);
skl_int3472_unregister_regulator(int3472);
-
- return 0;
}
static int skl_int3472_discrete_probe(struct platform_device *pdev)
@@ -392,7 +390,7 @@ static struct platform_driver int3472_discrete = {
.acpi_match_table = int3472_device_id,
},
.probe = skl_int3472_discrete_probe,
- .remove = skl_int3472_discrete_remove,
+ .remove_new = skl_int3472_discrete_remove,
};
module_platform_driver(int3472_discrete);
diff --git a/drivers/platform/x86/intel/mrfld_pwrbtn.c b/drivers/platform/x86/intel/mrfld_pwrbtn.c
index d58fea51747e..549a3f586f3b 100644
--- a/drivers/platform/x86/intel/mrfld_pwrbtn.c
+++ b/drivers/platform/x86/intel/mrfld_pwrbtn.c
@@ -78,13 +78,12 @@ static int mrfld_pwrbtn_probe(struct platform_device *pdev)
return 0;
}
-static int mrfld_pwrbtn_remove(struct platform_device *pdev)
+static void mrfld_pwrbtn_remove(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
dev_pm_clear_wake_irq(dev);
device_init_wakeup(dev, false);
- return 0;
}
static const struct platform_device_id mrfld_pwrbtn_id_table[] = {
@@ -98,7 +97,7 @@ static struct platform_driver mrfld_pwrbtn_driver = {
.name = "mrfld_bcove_pwrbtn",
},
.probe = mrfld_pwrbtn_probe,
- .remove = mrfld_pwrbtn_remove,
+ .remove_new = mrfld_pwrbtn_remove,
.id_table = mrfld_pwrbtn_id_table,
};
module_platform_driver(mrfld_pwrbtn_driver);
diff --git a/drivers/platform/x86/intel/pmc/core.c b/drivers/platform/x86/intel/pmc/core.c
index b9591969e0fa..61ca7c37fb02 100644
--- a/drivers/platform/x86/intel/pmc/core.c
+++ b/drivers/platform/x86/intel/pmc/core.c
@@ -1160,7 +1160,7 @@ static int pmc_core_probe(struct platform_device *pdev)
return 0;
}
-static int pmc_core_remove(struct platform_device *pdev)
+static void pmc_core_remove(struct platform_device *pdev)
{
struct pmc_dev *pmcdev = platform_get_drvdata(pdev);
@@ -1168,7 +1168,6 @@ static int pmc_core_remove(struct platform_device *pdev)
platform_set_drvdata(pdev, NULL);
mutex_destroy(&pmcdev->lock);
iounmap(pmcdev->regbase);
- return 0;
}
static bool warn_on_s0ix_failures;
@@ -1275,7 +1274,7 @@ static struct platform_driver pmc_core_driver = {
.dev_groups = pmc_dev_groups,
},
.probe = pmc_core_probe,
- .remove = pmc_core_remove,
+ .remove_new = pmc_core_remove,
};
module_platform_driver(pmc_core_driver);
diff --git a/drivers/platform/x86/intel/pmc/mtl.c b/drivers/platform/x86/intel/pmc/mtl.c
index eeb3bd8c2502..e8cc156412ce 100644
--- a/drivers/platform/x86/intel/pmc/mtl.c
+++ b/drivers/platform/x86/intel/pmc/mtl.c
@@ -8,6 +8,7 @@
*
*/
+#include <linux/pci.h>
#include "core.h"
const struct pmc_reg_map mtl_reg_map = {
@@ -45,8 +46,38 @@ void mtl_core_configure(struct pmc_dev *pmcdev)
pmc_core_send_ltr_ignore(pmcdev, 3);
}
+#define MTL_GNA_PCI_DEV 0x7e4c
+#define MTL_IPU_PCI_DEV 0x7d19
+#define MTL_VPU_PCI_DEV 0x7d1d
+static void mtl_set_device_d3(unsigned int device)
+{
+ struct pci_dev *pcidev;
+
+ pcidev = pci_get_device(PCI_VENDOR_ID_INTEL, device, NULL);
+ if (pcidev) {
+ if (!device_trylock(&pcidev->dev)) {
+ pci_dev_put(pcidev);
+ return;
+ }
+ if (!pcidev->dev.driver) {
+ dev_info(&pcidev->dev, "Setting to D3hot\n");
+ pci_set_power_state(pcidev, PCI_D3hot);
+ }
+ device_unlock(&pcidev->dev);
+ pci_dev_put(pcidev);
+ }
+}
+
void mtl_core_init(struct pmc_dev *pmcdev)
{
pmcdev->map = &mtl_reg_map;
pmcdev->core_configure = mtl_core_configure;
+
+ /*
+ * Set power state of select devices that do not have drivers to D3
+ * so that they do not block Package C entry.
+ */
+ mtl_set_device_d3(MTL_GNA_PCI_DEV);
+ mtl_set_device_d3(MTL_IPU_PCI_DEV);
+ mtl_set_device_d3(MTL_VPU_PCI_DEV);
}
diff --git a/drivers/platform/x86/intel/pmt/class.c b/drivers/platform/x86/intel/pmt/class.c
index 46598dcb634a..0b96d75f5924 100644
--- a/drivers/platform/x86/intel/pmt/class.c
+++ b/drivers/platform/x86/intel/pmt/class.c
@@ -33,7 +33,7 @@ bool intel_pmt_is_early_client_hw(struct device *dev)
*/
return !!(ivdev->info->quirks & VSEC_QUIRK_EARLY_HW);
}
-EXPORT_SYMBOL_GPL(intel_pmt_is_early_client_hw);
+EXPORT_SYMBOL_NS_GPL(intel_pmt_is_early_client_hw, INTEL_PMT);
static inline int
pmt_memcpy64_fromio(void *to, const u64 __iomem *from, size_t count)
@@ -327,7 +327,7 @@ int intel_pmt_dev_create(struct intel_pmt_entry *entry, struct intel_pmt_namespa
return intel_pmt_dev_register(entry, ns, dev);
}
-EXPORT_SYMBOL_GPL(intel_pmt_dev_create);
+EXPORT_SYMBOL_NS_GPL(intel_pmt_dev_create, INTEL_PMT);
void intel_pmt_dev_destroy(struct intel_pmt_entry *entry,
struct intel_pmt_namespace *ns)
@@ -343,7 +343,7 @@ void intel_pmt_dev_destroy(struct intel_pmt_entry *entry,
device_unregister(dev);
xa_erase(ns->xa, entry->devid);
}
-EXPORT_SYMBOL_GPL(intel_pmt_dev_destroy);
+EXPORT_SYMBOL_NS_GPL(intel_pmt_dev_destroy, INTEL_PMT);
static int __init pmt_class_init(void)
{
diff --git a/drivers/platform/x86/intel/pmt/crashlog.c b/drivers/platform/x86/intel/pmt/crashlog.c
index ace1239bc0a0..bbb3d61d09f4 100644
--- a/drivers/platform/x86/intel/pmt/crashlog.c
+++ b/drivers/platform/x86/intel/pmt/crashlog.c
@@ -328,3 +328,4 @@ module_exit(pmt_crashlog_exit);
MODULE_AUTHOR("Alexander Duyck <alexander.h.duyck@linux.intel.com>");
MODULE_DESCRIPTION("Intel PMT Crashlog driver");
MODULE_LICENSE("GPL v2");
+MODULE_IMPORT_NS(INTEL_PMT);
diff --git a/drivers/platform/x86/intel/pmt/telemetry.c b/drivers/platform/x86/intel/pmt/telemetry.c
index 5e4009c05ecf..39cbc87cc28a 100644
--- a/drivers/platform/x86/intel/pmt/telemetry.c
+++ b/drivers/platform/x86/intel/pmt/telemetry.c
@@ -78,7 +78,7 @@ static int pmt_telem_header_decode(struct intel_pmt_entry *entry,
* reserved for future use. They have zero size. Do not fail
* probe for these. Just ignore them.
*/
- if (header->size == 0)
+ if (header->size == 0 || header->access_type == 0xF)
return 1;
return 0;
@@ -160,3 +160,4 @@ module_exit(pmt_telem_exit);
MODULE_AUTHOR("David E. Box <david.e.box@linux.intel.com>");
MODULE_DESCRIPTION("Intel PMT Telemetry driver");
MODULE_LICENSE("GPL v2");
+MODULE_IMPORT_NS(INTEL_PMT);
diff --git a/drivers/platform/x86/intel/sdsi.c b/drivers/platform/x86/intel/sdsi.c
index 9e0ea2cdd704..556e7c6dbb05 100644
--- a/drivers/platform/x86/intel/sdsi.c
+++ b/drivers/platform/x86/intel/sdsi.c
@@ -49,7 +49,7 @@
#define SDSI_MBOX_CMD_SUCCESS 0x40
#define SDSI_MBOX_CMD_TIMEOUT 0x80
-#define MBOX_TIMEOUT_US 2000
+#define MBOX_TIMEOUT_US 500000
#define MBOX_TIMEOUT_ACQUIRE_US 1000
#define MBOX_POLLING_PERIOD_US 100
#define MBOX_ACQUIRE_NUM_RETRIES 5
diff --git a/drivers/platform/x86/intel/speed_select_if/Kconfig b/drivers/platform/x86/intel/speed_select_if/Kconfig
index ce3e3dc076d2..4eb3ad299db0 100644
--- a/drivers/platform/x86/intel/speed_select_if/Kconfig
+++ b/drivers/platform/x86/intel/speed_select_if/Kconfig
@@ -2,8 +2,12 @@ menu "Intel Speed Select Technology interface support"
depends on PCI
depends on X86_64 || COMPILE_TEST
+config INTEL_SPEED_SELECT_TPMI
+ tristate
+
config INTEL_SPEED_SELECT_INTERFACE
tristate "Intel(R) Speed Select Technology interface drivers"
+ select INTEL_SPEED_SELECT_TPMI if INTEL_TPMI
help
This config enables the Intel(R) Speed Select Technology interface
drivers. The Intel(R) speed select technology features are non
diff --git a/drivers/platform/x86/intel/speed_select_if/Makefile b/drivers/platform/x86/intel/speed_select_if/Makefile
index 856076206f35..1d878a36d0ab 100644
--- a/drivers/platform/x86/intel/speed_select_if/Makefile
+++ b/drivers/platform/x86/intel/speed_select_if/Makefile
@@ -8,3 +8,5 @@ obj-$(CONFIG_INTEL_SPEED_SELECT_INTERFACE) += isst_if_common.o
obj-$(CONFIG_INTEL_SPEED_SELECT_INTERFACE) += isst_if_mmio.o
obj-$(CONFIG_INTEL_SPEED_SELECT_INTERFACE) += isst_if_mbox_pci.o
obj-$(CONFIG_INTEL_SPEED_SELECT_INTERFACE) += isst_if_mbox_msr.o
+obj-$(CONFIG_INTEL_SPEED_SELECT_TPMI) += isst_tpmi_core.o
+obj-$(CONFIG_INTEL_SPEED_SELECT_TPMI) += isst_tpmi.o
diff --git a/drivers/platform/x86/intel/speed_select_if/isst_if_common.c b/drivers/platform/x86/intel/speed_select_if/isst_if_common.c
index 0954a04623ed..e0572a29212e 100644
--- a/drivers/platform/x86/intel/speed_select_if/isst_if_common.c
+++ b/drivers/platform/x86/intel/speed_select_if/isst_if_common.c
@@ -19,9 +19,13 @@
#include <linux/uaccess.h>
#include <uapi/linux/isst_if.h>
+#include <asm/cpu_device_id.h>
+#include <asm/intel-family.h>
+
#include "isst_if_common.h"
#define MSR_THREAD_ID_INFO 0x53
+#define MSR_PM_LOGICAL_ID 0x54
#define MSR_CPU_BUS_NUMBER 0x128
static struct isst_if_cmd_cb punit_callbacks[ISST_IF_DEV_MAX];
@@ -31,6 +35,7 @@ static int punit_msr_white_list[] = {
MSR_CONFIG_TDP_CONTROL,
MSR_TURBO_RATIO_LIMIT1,
MSR_TURBO_RATIO_LIMIT2,
+ MSR_PM_LOGICAL_ID,
};
struct isst_valid_cmd_ranges {
@@ -73,6 +78,8 @@ struct isst_cmd {
u32 param;
};
+static bool isst_hpm_support;
+
static DECLARE_HASHTABLE(isst_hash, 8);
static DEFINE_MUTEX(isst_hash_lock);
@@ -262,11 +269,13 @@ bool isst_if_mbox_cmd_set_req(struct isst_if_mbox_cmd *cmd)
}
EXPORT_SYMBOL_GPL(isst_if_mbox_cmd_set_req);
+static int isst_if_api_version;
+
static int isst_if_get_platform_info(void __user *argp)
{
struct isst_if_platform_info info;
- info.api_version = ISST_IF_API_VERSION;
+ info.api_version = isst_if_api_version;
info.driver_version = ISST_IF_DRIVER_VERSION;
info.max_cmds_per_ioctl = ISST_IF_CMD_LIMIT;
info.mbox_supported = punit_callbacks[ISST_IF_DEV_MBOX].registered;
@@ -409,11 +418,20 @@ static int isst_if_cpu_online(unsigned int cpu)
isst_cpu_info[cpu].pci_dev[1] = _isst_if_get_pci_dev(cpu, 1, 30, 1);
}
+ if (isst_hpm_support) {
+
+ ret = rdmsrl_safe(MSR_PM_LOGICAL_ID, &data);
+ if (!ret)
+ goto set_punit_id;
+ }
+
ret = rdmsrl_safe(MSR_THREAD_ID_INFO, &data);
if (ret) {
isst_cpu_info[cpu].punit_cpu_id = -1;
return ret;
}
+
+set_punit_id:
isst_cpu_info[cpu].punit_cpu_id = data;
isst_restore_msr_local(cpu);
@@ -588,6 +606,7 @@ static long isst_if_def_ioctl(struct file *file, unsigned int cmd,
struct isst_if_cmd_cb cmd_cb;
struct isst_if_cmd_cb *cb;
long ret = -ENOTTY;
+ int i;
switch (cmd) {
case ISST_IF_GET_PLATFORM_INFO:
@@ -616,6 +635,16 @@ static long isst_if_def_ioctl(struct file *file, unsigned int cmd,
ret = isst_if_exec_multi_cmd(argp, &cmd_cb);
break;
default:
+ for (i = 0; i < ISST_IF_DEV_MAX; ++i) {
+ struct isst_if_cmd_cb *cb = &punit_callbacks[i];
+ int ret;
+
+ if (cb->def_ioctl) {
+ ret = cb->def_ioctl(file, cmd, arg);
+ if (!ret)
+ return ret;
+ }
+ }
break;
}
@@ -691,6 +720,12 @@ static struct miscdevice isst_if_char_driver = {
.fops = &isst_if_char_driver_ops,
};
+static const struct x86_cpu_id hpm_cpu_ids[] = {
+ X86_MATCH_INTEL_FAM6_MODEL(GRANITERAPIDS_X, NULL),
+ X86_MATCH_INTEL_FAM6_MODEL(SIERRAFOREST_X, NULL),
+ {}
+};
+
static int isst_misc_reg(void)
{
mutex_lock(&punit_misc_dev_reg_lock);
@@ -698,6 +733,12 @@ static int isst_misc_reg(void)
goto unlock_exit;
if (!misc_usage_count) {
+ const struct x86_cpu_id *id;
+
+ id = x86_match_cpu(hpm_cpu_ids);
+ if (id)
+ isst_hpm_support = true;
+
misc_device_ret = isst_if_cpu_info_init();
if (misc_device_ret)
goto unlock_exit;
@@ -756,6 +797,10 @@ int isst_if_cdev_register(int device_type, struct isst_if_cmd_cb *cb)
mutex_unlock(&punit_misc_dev_open_lock);
return -EAGAIN;
}
+ if (!cb->api_version)
+ cb->api_version = ISST_IF_API_VERSION;
+ if (cb->api_version > isst_if_api_version)
+ isst_if_api_version = cb->api_version;
memcpy(&punit_callbacks[device_type], cb, sizeof(*cb));
punit_callbacks[device_type].registered = 1;
mutex_unlock(&punit_misc_dev_open_lock);
diff --git a/drivers/platform/x86/intel/speed_select_if/isst_if_common.h b/drivers/platform/x86/intel/speed_select_if/isst_if_common.h
index 35ff506b402e..1004f2c9cca8 100644
--- a/drivers/platform/x86/intel/speed_select_if/isst_if_common.h
+++ b/drivers/platform/x86/intel/speed_select_if/isst_if_common.h
@@ -30,7 +30,8 @@
#define ISST_IF_DEV_MBOX 0
#define ISST_IF_DEV_MMIO 1
-#define ISST_IF_DEV_MAX 2
+#define ISST_IF_DEV_TPMI 2
+#define ISST_IF_DEV_MAX 3
/**
* struct isst_if_cmd_cb - Used to register a IOCTL handler
@@ -40,6 +41,7 @@
* @offset: Offset to the first valid member in command structure.
* This will be the offset of the start of the command
* after command count field
+ * @api_version: API version supported for this target. 0, if none.
* @owner: Registered module owner
* @cmd_callback: Callback function to handle IOCTL. The callback has the
* command pointer with data for command. There is a pointer
@@ -47,6 +49,8 @@
* response to user ioctl buffer. The "resume" argument
* can be used to avoid storing the command for replay
* during system resume
+ * @def_ioctl: Default IOCTL handler callback, if there is no match in
+ * the existing list of IOCTL handled by the common handler.
*
* This structure is used to register an handler for IOCTL. To avoid
* code duplication common code handles all the IOCTL command read/write
@@ -57,8 +61,10 @@ struct isst_if_cmd_cb {
int registered;
int cmd_size;
int offset;
+ int api_version;
struct module *owner;
long (*cmd_callback)(u8 *ptr, int *write_only, int resume);
+ long (*def_ioctl)(struct file *file, unsigned int cmd, unsigned long arg);
};
/* Internal interface functions */
diff --git a/drivers/platform/x86/intel/speed_select_if/isst_tpmi.c b/drivers/platform/x86/intel/speed_select_if/isst_tpmi.c
new file mode 100644
index 000000000000..17972191538a
--- /dev/null
+++ b/drivers/platform/x86/intel/speed_select_if/isst_tpmi.c
@@ -0,0 +1,72 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * isst_tpmi.c: SST TPMI interface
+ *
+ * Copyright (c) 2023, Intel Corporation.
+ * All Rights Reserved.
+ *
+ */
+
+#include <linux/auxiliary_bus.h>
+#include <linux/module.h>
+#include <linux/intel_tpmi.h>
+
+#include "isst_tpmi_core.h"
+
+static int intel_sst_probe(struct auxiliary_device *auxdev, const struct auxiliary_device_id *id)
+{
+ int ret;
+
+ ret = tpmi_sst_init();
+ if (ret)
+ return ret;
+
+ ret = tpmi_sst_dev_add(auxdev);
+ if (ret)
+ tpmi_sst_exit();
+
+ return ret;
+}
+
+static void intel_sst_remove(struct auxiliary_device *auxdev)
+{
+ tpmi_sst_dev_remove(auxdev);
+ tpmi_sst_exit();
+}
+
+static int intel_sst_suspend(struct device *dev)
+{
+ tpmi_sst_dev_suspend(to_auxiliary_dev(dev));
+
+ return 0;
+}
+
+static int intel_sst_resume(struct device *dev)
+{
+ tpmi_sst_dev_resume(to_auxiliary_dev(dev));
+
+ return 0;
+}
+
+static DEFINE_SIMPLE_DEV_PM_OPS(intel_sst_pm, intel_sst_suspend, intel_sst_resume);
+
+static const struct auxiliary_device_id intel_sst_id_table[] = {
+ { .name = "intel_vsec.tpmi-sst" },
+ {}
+};
+MODULE_DEVICE_TABLE(auxiliary, intel_sst_id_table);
+
+static struct auxiliary_driver intel_sst_aux_driver = {
+ .id_table = intel_sst_id_table,
+ .remove = intel_sst_remove,
+ .probe = intel_sst_probe,
+ .driver = {
+ .pm = pm_sleep_ptr(&intel_sst_pm),
+ },
+};
+
+module_auxiliary_driver(intel_sst_aux_driver);
+
+MODULE_IMPORT_NS(INTEL_TPMI_SST);
+MODULE_DESCRIPTION("Intel TPMI SST Driver");
+MODULE_LICENSE("GPL");
diff --git a/drivers/platform/x86/intel/speed_select_if/isst_tpmi_core.c b/drivers/platform/x86/intel/speed_select_if/isst_tpmi_core.c
new file mode 100644
index 000000000000..664d2ee60385
--- /dev/null
+++ b/drivers/platform/x86/intel/speed_select_if/isst_tpmi_core.c
@@ -0,0 +1,1440 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * isst_tpmi.c: SST TPMI interface core
+ *
+ * Copyright (c) 2023, Intel Corporation.
+ * All Rights Reserved.
+ *
+ * This information will be useful to understand flows:
+ * In the current generation of platforms, TPMI is supported via OOB
+ * PCI device. This PCI device has one instance per CPU package.
+ * There is a unique TPMI ID for SST. Each TPMI ID also has multiple
+ * entries, representing per power domain information.
+ *
+ * There is one dev file for complete SST information and control same as the
+ * prior generation of hardware. User spaces don't need to know how the
+ * information is presented by the hardware. The TPMI core module implements
+ * the hardware mapping.
+ */
+
+#include <linux/auxiliary_bus.h>
+#include <linux/delay.h>
+#include <linux/intel_tpmi.h>
+#include <linux/fs.h>
+#include <linux/io.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <uapi/linux/isst_if.h>
+
+#include "isst_tpmi_core.h"
+#include "isst_if_common.h"
+
+/* Supported SST hardware version by this driver */
+#define ISST_HEADER_VERSION 1
+
+/*
+ * Used to indicate if value read from MMIO needs to get multiplied
+ * to get to a standard unit or not.
+ */
+#define SST_MUL_FACTOR_NONE 1
+
+/* Define 100 as a scaling factor frequency ratio to frequency conversion */
+#define SST_MUL_FACTOR_FREQ 100
+
+/* All SST regs are 64 bit size */
+#define SST_REG_SIZE 8
+
+/**
+ * struct sst_header - SST main header
+ * @interface_version: Version number for this interface
+ * @cap_mask: Bitmask of the supported sub features. 1=the sub feature is enabled.
+ * 0=disabled.
+ * Bit[8]= SST_CP enable (1), disable (0)
+ * bit[9]= SST_PP enable (1), disable (0)
+ * other bits are reserved for future use
+ * @cp_offset: Qword (8 bytes) offset to the SST_CP register bank
+ * @pp_offset: Qword (8 bytes) offset to the SST_PP register bank
+ * @reserved: Reserved for future use
+ *
+ * This register allows SW to discover SST capability and the offsets to SST-CP
+ * and SST-PP register banks.
+ */
+struct sst_header {
+ u8 interface_version;
+ u8 cap_mask;
+ u8 cp_offset;
+ u8 pp_offset;
+ u32 reserved;
+} __packed;
+
+/**
+ * struct cp_header - SST-CP (core-power) header
+ * @feature_id: 0=SST-CP, 1=SST-PP, 2=SST-BF, 3=SST-TF
+ * @feature_rev: Interface Version number for this SST feature
+ * @ratio_unit: Frequency ratio unit. 00: 100MHz. All others are reserved
+ * @reserved: Reserved for future use
+ *
+ * This structure is used store SST-CP header. This is packed to the same
+ * format as defined in the specifications.
+ */
+struct cp_header {
+ u64 feature_id :4;
+ u64 feature_rev :8;
+ u64 ratio_unit :2;
+ u64 reserved :50;
+} __packed;
+
+/**
+ * struct pp_header - SST-PP (Perf profile) header
+ * @feature_id: 0=SST-CP, 1=SST-PP, 2=SST-BF, 3=SST-TF
+ * @feature_rev: Interface Version number for this SST feature
+ * @level_en_mask: SST-PP level enable/disable fuse mask
+ * @allowed_level_mask: Allowed level mask used for dynamic config level switching
+ * @reserved0: Reserved for future use
+ * @ratio_unit: Frequency ratio unit. 00: 100MHz. All others are reserved
+ * @block_size: Size of PP block in Qword unit (8 bytes)
+ * @dynamic_switch: If set (1), dynamic switching of SST PP is supported
+ * @memory_ratio_unit: Memory Controller frequency ratio unit. 00: 100MHz, others reserved
+ * @reserved1: Reserved for future use
+ *
+ * This structure is used store SST-PP header. This is packed to the same
+ * format as defined in the specifications.
+ */
+struct pp_header {
+ u64 feature_id :4;
+ u64 feature_rev :8;
+ u64 level_en_mask :8;
+ u64 allowed_level_mask :8;
+ u64 reserved0 :4;
+ u64 ratio_unit :2;
+ u64 block_size :8;
+ u64 dynamic_switch :1;
+ u64 memory_ratio_unit :2;
+ u64 reserved1 :19;
+} __packed;
+
+/**
+ * struct feature_offset - Offsets to SST-PP features
+ * @pp_offset: Qword offset within PP level for the SST_PP register bank
+ * @bf_offset: Qword offset within PP level for the SST_BF register bank
+ * @tf_offset: Qword offset within PP level for the SST_TF register bank
+ * @reserved: Reserved for future use
+ *
+ * This structure is used store offsets for SST features in the register bank.
+ * This is packed to the same format as defined in the specifications.
+ */
+struct feature_offset {
+ u64 pp_offset :8;
+ u64 bf_offset :8;
+ u64 tf_offset :8;
+ u64 reserved :40;
+} __packed;
+
+/**
+ * struct levels_offset - Offsets to each SST PP level
+ * @sst_pp_level0_offset: Qword offset to the register block of PP level 0
+ * @sst_pp_level1_offset: Qword offset to the register block of PP level 1
+ * @sst_pp_level2_offset: Qword offset to the register block of PP level 2
+ * @sst_pp_level3_offset: Qword offset to the register block of PP level 3
+ * @sst_pp_level4_offset: Qword offset to the register block of PP level 4
+ * @reserved: Reserved for future use
+ *
+ * This structure is used store offsets of SST PP levels in the register bank.
+ * This is packed to the same format as defined in the specifications.
+ */
+struct levels_offset {
+ u64 sst_pp_level0_offset :8;
+ u64 sst_pp_level1_offset :8;
+ u64 sst_pp_level2_offset :8;
+ u64 sst_pp_level3_offset :8;
+ u64 sst_pp_level4_offset :8;
+ u64 reserved :24;
+} __packed;
+
+/**
+ * struct pp_control_offset - Offsets for SST PP controls
+ * @perf_level: A SST-PP level that SW intends to switch to
+ * @perf_level_lock: SST-PP level select lock. 0 - unlocked. 1 - locked till next reset
+ * @resvd0: Reserved for future use
+ * @current_state: Bit mask to control the enable(1)/disable(0) state of each feature
+ * of the current PP level, bit 0 = BF, bit 1 = TF, bit 2-7 = reserved
+ * @reserved: Reserved for future use
+ *
+ * This structure is used store offsets of SST PP controls in the register bank.
+ * This is packed to the same format as defined in the specifications.
+ */
+struct pp_control_offset {
+ u64 perf_level :3;
+ u64 perf_level_lock :1;
+ u64 resvd0 :4;
+ u64 current_state :8;
+ u64 reserved :48;
+} __packed;
+
+/**
+ * struct pp_status_offset - Offsets for SST PP status fields
+ * @sst_pp_level: Returns the current SST-PP level
+ * @sst_pp_lock: Returns the lock bit setting of perf_level_lock in pp_control_offset
+ * @error_type: Returns last error of SST-PP level change request. 0: no error,
+ * 1: level change not allowed, others: reserved
+ * @feature_state: Bit mask to indicate the enable(1)/disable(0) state of each feature of the
+ * current PP level. bit 0 = BF, bit 1 = TF, bit 2-7 reserved
+ * @reserved0: Reserved for future use
+ * @feature_error_type: Returns last error of the specific feature. Three error_type bits per
+ * feature. i.e. ERROR_TYPE[2:0] for BF, ERROR_TYPE[5:3] for TF, etc.
+ * 0x0: no error, 0x1: The specific feature is not supported by the hardware.
+ * 0x2-0x6: Reserved. 0x7: feature state change is not allowed.
+ * @reserved1: Reserved for future use
+ *
+ * This structure is used store offsets of SST PP status in the register bank.
+ * This is packed to the same format as defined in the specifications.
+ */
+struct pp_status_offset {
+ u64 sst_pp_level :3;
+ u64 sst_pp_lock :1;
+ u64 error_type :4;
+ u64 feature_state :8;
+ u64 reserved0 :16;
+ u64 feature_error_type : 24;
+ u64 reserved1 :8;
+} __packed;
+
+/**
+ * struct perf_level - Used to store perf level and mmio offset
+ * @mmio_offset: mmio offset for a perf level
+ * @level: perf level for this offset
+ *
+ * This structure is used store final mmio offset of each perf level from the
+ * SST base mmio offset.
+ */
+struct perf_level {
+ int mmio_offset;
+ int level;
+};
+
+/**
+ * struct tpmi_per_power_domain_info - Store per power_domain SST info
+ * @package_id: Package id for this power_domain
+ * @power_domain_id: Power domain id, Each entry from the SST-TPMI instance is a power_domain.
+ * @max_level: Max possible PP level possible for this power_domain
+ * @ratio_unit: Ratio unit for converting to MHz
+ * @avx_levels: Number of AVX levels
+ * @pp_block_size: Block size from PP header
+ * @sst_header: Store SST header for this power_domain
+ * @cp_header: Store SST-CP header for this power_domain
+ * @pp_header: Store SST-PP header for this power_domain
+ * @perf_levels: Pointer to each perf level to map level to mmio offset
+ * @feature_offsets: Store feature offsets for each PP-level
+ * @control_offset: Store the control offset for each PP-level
+ * @status_offset: Store the status offset for each PP-level
+ * @sst_base: Mapped SST base IO memory
+ * @auxdev: Auxiliary device instance enumerated this instance
+ * @saved_sst_cp_control: Save SST-CP control configuration to store restore for suspend/resume
+ * @saved_clos_configs: Save SST-CP CLOS configuration to store restore for suspend/resume
+ * @saved_clos_assocs: Save SST-CP CLOS association to store restore for suspend/resume
+ * @saved_pp_control: Save SST-PP control information to store restore for suspend/resume
+ *
+ * This structure is used store complete SST information for a power_domain. This information
+ * is used to read/write request for any SST IOCTL. Each physical CPU package can have multiple
+ * power_domains. Each power domain describes its own SST information and has its own controls.
+ */
+struct tpmi_per_power_domain_info {
+ int package_id;
+ int power_domain_id;
+ int max_level;
+ int ratio_unit;
+ int avx_levels;
+ int pp_block_size;
+ struct sst_header sst_header;
+ struct cp_header cp_header;
+ struct pp_header pp_header;
+ struct perf_level *perf_levels;
+ struct feature_offset feature_offsets;
+ struct pp_control_offset control_offset;
+ struct pp_status_offset status_offset;
+ void __iomem *sst_base;
+ struct auxiliary_device *auxdev;
+ u64 saved_sst_cp_control;
+ u64 saved_clos_configs[4];
+ u64 saved_clos_assocs[4];
+ u64 saved_pp_control;
+};
+
+/**
+ * struct tpmi_sst_struct - Store sst info for a package
+ * @package_id: Package id for this aux device instance
+ * @number_of_power_domains: Number of power_domains pointed by power_domain_info pointer
+ * @power_domain_info: Pointer to power domains information
+ *
+ * This structure is used store full SST information for a package.
+ * Each package has a unique OOB PCI device, which enumerates TPMI.
+ * Each Package will have multiple power_domains.
+ */
+struct tpmi_sst_struct {
+ int package_id;
+ int number_of_power_domains;
+ struct tpmi_per_power_domain_info *power_domain_info;
+};
+
+/**
+ * struct tpmi_sst_common_struct - Store all SST instances
+ * @max_index: Maximum instances currently present
+ * @sst_inst: Pointer to per package instance
+ *
+ * Stores every SST Package instance.
+ */
+struct tpmi_sst_common_struct {
+ int max_index;
+ struct tpmi_sst_struct **sst_inst;
+};
+
+/*
+ * Each IOCTL request is processed under this lock. Also used to protect
+ * registration functions and common data structures.
+ */
+static DEFINE_MUTEX(isst_tpmi_dev_lock);
+
+/* Usage count to track, number of TPMI SST instances registered to this core. */
+static int isst_core_usage_count;
+
+/* Stores complete SST information for every package and power_domain */
+static struct tpmi_sst_common_struct isst_common;
+
+#define SST_MAX_AVX_LEVELS 3
+
+#define SST_PP_OFFSET_0 8
+#define SST_PP_OFFSET_1 16
+#define SST_PP_OFFSET_SIZE 8
+
+static int sst_add_perf_profiles(struct auxiliary_device *auxdev,
+ struct tpmi_per_power_domain_info *pd_info,
+ int levels)
+{
+ u64 perf_level_offsets;
+ int i;
+
+ pd_info->perf_levels = devm_kcalloc(&auxdev->dev, levels,
+ sizeof(struct perf_level),
+ GFP_KERNEL);
+ if (!pd_info->perf_levels)
+ return 0;
+
+ pd_info->ratio_unit = pd_info->pp_header.ratio_unit;
+ pd_info->avx_levels = SST_MAX_AVX_LEVELS;
+ pd_info->pp_block_size = pd_info->pp_header.block_size;
+
+ /* Read PP Offset 0: Get feature offset with PP level */
+ *((u64 *)&pd_info->feature_offsets) = readq(pd_info->sst_base +
+ pd_info->sst_header.pp_offset +
+ SST_PP_OFFSET_0);
+
+ perf_level_offsets = readq(pd_info->sst_base + pd_info->sst_header.pp_offset +
+ SST_PP_OFFSET_1);
+
+ for (i = 0; i < levels; ++i) {
+ u64 offset;
+
+ offset = perf_level_offsets & (0xffULL << (i * SST_PP_OFFSET_SIZE));
+ offset >>= (i * 8);
+ offset &= 0xff;
+ offset *= 8; /* Convert to byte from QWORD offset */
+ pd_info->perf_levels[i].mmio_offset = pd_info->sst_header.pp_offset + offset;
+ }
+
+ return 0;
+}
+
+static int sst_main(struct auxiliary_device *auxdev, struct tpmi_per_power_domain_info *pd_info)
+{
+ int i, mask, levels;
+
+ *((u64 *)&pd_info->sst_header) = readq(pd_info->sst_base);
+ pd_info->sst_header.cp_offset *= 8;
+ pd_info->sst_header.pp_offset *= 8;
+
+ if (pd_info->sst_header.interface_version != ISST_HEADER_VERSION) {
+ dev_err(&auxdev->dev, "SST: Unsupported version:%x\n",
+ pd_info->sst_header.interface_version);
+ return -ENODEV;
+ }
+
+ /* Read SST CP Header */
+ *((u64 *)&pd_info->cp_header) = readq(pd_info->sst_base + pd_info->sst_header.cp_offset);
+
+ /* Read PP header */
+ *((u64 *)&pd_info->pp_header) = readq(pd_info->sst_base + pd_info->sst_header.pp_offset);
+
+ /* Force level_en_mask level 0 */
+ pd_info->pp_header.level_en_mask |= 0x01;
+
+ mask = 0x01;
+ levels = 0;
+ for (i = 0; i < 8; ++i) {
+ if (pd_info->pp_header.level_en_mask & mask)
+ levels = i;
+ mask <<= 1;
+ }
+ pd_info->max_level = levels;
+ sst_add_perf_profiles(auxdev, pd_info, levels + 1);
+
+ return 0;
+}
+
+/*
+ * Map a package and power_domain id to SST information structure unique for a power_domain.
+ * The caller should call under isst_tpmi_dev_lock.
+ */
+static struct tpmi_per_power_domain_info *get_instance(int pkg_id, int power_domain_id)
+{
+ struct tpmi_per_power_domain_info *power_domain_info;
+ struct tpmi_sst_struct *sst_inst;
+
+ if (pkg_id < 0 || pkg_id > isst_common.max_index ||
+ pkg_id >= topology_max_packages())
+ return NULL;
+
+ sst_inst = isst_common.sst_inst[pkg_id];
+ if (!sst_inst)
+ return NULL;
+
+ if (power_domain_id < 0 || power_domain_id >= sst_inst->number_of_power_domains)
+ return NULL;
+
+ power_domain_info = &sst_inst->power_domain_info[power_domain_id];
+
+ if (power_domain_info && !power_domain_info->sst_base)
+ return NULL;
+
+ return power_domain_info;
+}
+
+static bool disable_dynamic_sst_features(void)
+{
+ u64 value;
+
+ rdmsrl(MSR_PM_ENABLE, value);
+ return !(value & 0x1);
+}
+
+#define _read_cp_info(name_str, name, offset, start, width, mult_factor)\
+{\
+ u64 val, mask;\
+ \
+ val = readq(power_domain_info->sst_base + power_domain_info->sst_header.cp_offset +\
+ (offset));\
+ mask = GENMASK_ULL((start + width - 1), start);\
+ val &= mask; \
+ val >>= start;\
+ name = (val * mult_factor);\
+}
+
+#define _write_cp_info(name_str, name, offset, start, width, div_factor)\
+{\
+ u64 val, mask;\
+ \
+ val = readq(power_domain_info->sst_base +\
+ power_domain_info->sst_header.cp_offset + (offset));\
+ mask = GENMASK_ULL((start + width - 1), start);\
+ val &= ~mask;\
+ val |= (name / div_factor) << start;\
+ writeq(val, power_domain_info->sst_base + power_domain_info->sst_header.cp_offset +\
+ (offset));\
+}
+
+#define SST_CP_CONTROL_OFFSET 8
+#define SST_CP_STATUS_OFFSET 16
+
+#define SST_CP_ENABLE_START 0
+#define SST_CP_ENABLE_WIDTH 1
+
+#define SST_CP_PRIORITY_TYPE_START 1
+#define SST_CP_PRIORITY_TYPE_WIDTH 1
+
+static long isst_if_core_power_state(void __user *argp)
+{
+ struct tpmi_per_power_domain_info *power_domain_info;
+ struct isst_core_power core_power;
+
+ if (disable_dynamic_sst_features())
+ return -EFAULT;
+
+ if (copy_from_user(&core_power, argp, sizeof(core_power)))
+ return -EFAULT;
+
+ power_domain_info = get_instance(core_power.socket_id, core_power.power_domain_id);
+ if (!power_domain_info)
+ return -EINVAL;
+
+ if (core_power.get_set) {
+ _write_cp_info("cp_enable", core_power.enable, SST_CP_CONTROL_OFFSET,
+ SST_CP_ENABLE_START, SST_CP_ENABLE_WIDTH, SST_MUL_FACTOR_NONE)
+ _write_cp_info("cp_prio_type", core_power.priority_type, SST_CP_CONTROL_OFFSET,
+ SST_CP_PRIORITY_TYPE_START, SST_CP_PRIORITY_TYPE_WIDTH,
+ SST_MUL_FACTOR_NONE)
+ } else {
+ /* get */
+ _read_cp_info("cp_enable", core_power.enable, SST_CP_STATUS_OFFSET,
+ SST_CP_ENABLE_START, SST_CP_ENABLE_WIDTH, SST_MUL_FACTOR_NONE)
+ _read_cp_info("cp_prio_type", core_power.priority_type, SST_CP_STATUS_OFFSET,
+ SST_CP_PRIORITY_TYPE_START, SST_CP_PRIORITY_TYPE_WIDTH,
+ SST_MUL_FACTOR_NONE)
+ core_power.supported = !!(power_domain_info->sst_header.cap_mask & BIT(0));
+ if (copy_to_user(argp, &core_power, sizeof(core_power)))
+ return -EFAULT;
+ }
+
+ return 0;
+}
+
+#define SST_CLOS_CONFIG_0_OFFSET 24
+
+#define SST_CLOS_CONFIG_PRIO_START 4
+#define SST_CLOS_CONFIG_PRIO_WIDTH 4
+
+#define SST_CLOS_CONFIG_MIN_START 8
+#define SST_CLOS_CONFIG_MIN_WIDTH 8
+
+#define SST_CLOS_CONFIG_MAX_START 16
+#define SST_CLOS_CONFIG_MAX_WIDTH 8
+
+static long isst_if_clos_param(void __user *argp)
+{
+ struct tpmi_per_power_domain_info *power_domain_info;
+ struct isst_clos_param clos_param;
+
+ if (copy_from_user(&clos_param, argp, sizeof(clos_param)))
+ return -EFAULT;
+
+ power_domain_info = get_instance(clos_param.socket_id, clos_param.power_domain_id);
+ if (!power_domain_info)
+ return -EINVAL;
+
+ if (clos_param.get_set) {
+ _write_cp_info("clos.min_freq", clos_param.min_freq_mhz,
+ (SST_CLOS_CONFIG_0_OFFSET + clos_param.clos * SST_REG_SIZE),
+ SST_CLOS_CONFIG_MIN_START, SST_CLOS_CONFIG_MIN_WIDTH,
+ SST_MUL_FACTOR_FREQ);
+ _write_cp_info("clos.max_freq", clos_param.max_freq_mhz,
+ (SST_CLOS_CONFIG_0_OFFSET + clos_param.clos * SST_REG_SIZE),
+ SST_CLOS_CONFIG_MAX_START, SST_CLOS_CONFIG_MAX_WIDTH,
+ SST_MUL_FACTOR_FREQ);
+ _write_cp_info("clos.prio", clos_param.prop_prio,
+ (SST_CLOS_CONFIG_0_OFFSET + clos_param.clos * SST_REG_SIZE),
+ SST_CLOS_CONFIG_PRIO_START, SST_CLOS_CONFIG_PRIO_WIDTH,
+ SST_MUL_FACTOR_NONE);
+ } else {
+ /* get */
+ _read_cp_info("clos.min_freq", clos_param.min_freq_mhz,
+ (SST_CLOS_CONFIG_0_OFFSET + clos_param.clos * SST_REG_SIZE),
+ SST_CLOS_CONFIG_MIN_START, SST_CLOS_CONFIG_MIN_WIDTH,
+ SST_MUL_FACTOR_FREQ)
+ _read_cp_info("clos.max_freq", clos_param.max_freq_mhz,
+ (SST_CLOS_CONFIG_0_OFFSET + clos_param.clos * SST_REG_SIZE),
+ SST_CLOS_CONFIG_MAX_START, SST_CLOS_CONFIG_MAX_WIDTH,
+ SST_MUL_FACTOR_FREQ)
+ _read_cp_info("clos.prio", clos_param.prop_prio,
+ (SST_CLOS_CONFIG_0_OFFSET + clos_param.clos * SST_REG_SIZE),
+ SST_CLOS_CONFIG_PRIO_START, SST_CLOS_CONFIG_PRIO_WIDTH,
+ SST_MUL_FACTOR_NONE)
+
+ if (copy_to_user(argp, &clos_param, sizeof(clos_param)))
+ return -EFAULT;
+ }
+
+ return 0;
+}
+
+#define SST_CLOS_ASSOC_0_OFFSET 56
+#define SST_CLOS_ASSOC_CPUS_PER_REG 16
+#define SST_CLOS_ASSOC_BITS_PER_CPU 4
+
+static long isst_if_clos_assoc(void __user *argp)
+{
+ struct isst_if_clos_assoc_cmds assoc_cmds;
+ unsigned char __user *ptr;
+ int i;
+
+ /* Each multi command has u16 command count as the first field */
+ if (copy_from_user(&assoc_cmds, argp, sizeof(assoc_cmds)))
+ return -EFAULT;
+
+ if (!assoc_cmds.cmd_count || assoc_cmds.cmd_count > ISST_IF_CMD_LIMIT)
+ return -EINVAL;
+
+ ptr = argp + offsetof(struct isst_if_clos_assoc_cmds, assoc_info);
+ for (i = 0; i < assoc_cmds.cmd_count; ++i) {
+ struct tpmi_per_power_domain_info *power_domain_info;
+ struct isst_if_clos_assoc clos_assoc;
+ int punit_id, punit_cpu_no, pkg_id;
+ struct tpmi_sst_struct *sst_inst;
+ int offset, shift, cpu;
+ u64 val, mask, clos;
+
+ if (copy_from_user(&clos_assoc, ptr, sizeof(clos_assoc)))
+ return -EFAULT;
+
+ if (clos_assoc.socket_id > topology_max_packages())
+ return -EINVAL;
+
+ cpu = clos_assoc.logical_cpu;
+ clos = clos_assoc.clos;
+
+ if (assoc_cmds.punit_cpu_map)
+ punit_cpu_no = cpu;
+ else
+ return -EOPNOTSUPP;
+
+ if (punit_cpu_no < 0)
+ return -EINVAL;
+
+ punit_id = clos_assoc.power_domain_id;
+ pkg_id = clos_assoc.socket_id;
+
+ sst_inst = isst_common.sst_inst[pkg_id];
+
+ if (clos_assoc.power_domain_id > sst_inst->number_of_power_domains)
+ return -EINVAL;
+
+ power_domain_info = &sst_inst->power_domain_info[punit_id];
+
+ offset = SST_CLOS_ASSOC_0_OFFSET +
+ (punit_cpu_no / SST_CLOS_ASSOC_CPUS_PER_REG) * SST_REG_SIZE;
+ shift = punit_cpu_no % SST_CLOS_ASSOC_CPUS_PER_REG;
+ shift *= SST_CLOS_ASSOC_BITS_PER_CPU;
+
+ val = readq(power_domain_info->sst_base +
+ power_domain_info->sst_header.cp_offset + offset);
+ if (assoc_cmds.get_set) {
+ mask = GENMASK_ULL((shift + SST_CLOS_ASSOC_BITS_PER_CPU - 1), shift);
+ val &= ~mask;
+ val |= (clos << shift);
+ writeq(val, power_domain_info->sst_base +
+ power_domain_info->sst_header.cp_offset + offset);
+ } else {
+ val >>= shift;
+ clos_assoc.clos = val & GENMASK(SST_CLOS_ASSOC_BITS_PER_CPU - 1, 0);
+ if (copy_to_user(ptr, &clos_assoc, sizeof(clos_assoc)))
+ return -EFAULT;
+ }
+
+ ptr += sizeof(clos_assoc);
+ }
+
+ return 0;
+}
+
+#define _read_pp_info(name_str, name, offset, start, width, mult_factor)\
+{\
+ u64 val, _mask;\
+ \
+ val = readq(power_domain_info->sst_base + power_domain_info->sst_header.pp_offset +\
+ (offset));\
+ _mask = GENMASK_ULL((start + width - 1), start);\
+ val &= _mask;\
+ val >>= start;\
+ name = (val * mult_factor);\
+}
+
+#define _write_pp_info(name_str, name, offset, start, width, div_factor)\
+{\
+ u64 val, _mask;\
+ \
+ val = readq(power_domain_info->sst_base + power_domain_info->sst_header.pp_offset +\
+ (offset));\
+ _mask = GENMASK((start + width - 1), start);\
+ val &= ~_mask;\
+ val |= (name / div_factor) << start;\
+ writeq(val, power_domain_info->sst_base + power_domain_info->sst_header.pp_offset +\
+ (offset));\
+}
+
+#define _read_bf_level_info(name_str, name, level, offset, start, width, mult_factor)\
+{\
+ u64 val, _mask;\
+ \
+ val = readq(power_domain_info->sst_base +\
+ power_domain_info->perf_levels[level].mmio_offset +\
+ (power_domain_info->feature_offsets.bf_offset * 8) + (offset));\
+ _mask = GENMASK_ULL((start + width - 1), start);\
+ val &= _mask; \
+ val >>= start;\
+ name = (val * mult_factor);\
+}
+
+#define _read_tf_level_info(name_str, name, level, offset, start, width, mult_factor)\
+{\
+ u64 val, _mask;\
+ \
+ val = readq(power_domain_info->sst_base +\
+ power_domain_info->perf_levels[level].mmio_offset +\
+ (power_domain_info->feature_offsets.tf_offset * 8) + (offset));\
+ _mask = GENMASK_ULL((start + width - 1), start);\
+ val &= _mask; \
+ val >>= start;\
+ name = (val * mult_factor);\
+}
+
+#define SST_PP_STATUS_OFFSET 32
+
+#define SST_PP_LEVEL_START 0
+#define SST_PP_LEVEL_WIDTH 3
+
+#define SST_PP_LOCK_START 3
+#define SST_PP_LOCK_WIDTH 1
+
+#define SST_PP_FEATURE_STATE_START 8
+#define SST_PP_FEATURE_STATE_WIDTH 8
+
+#define SST_BF_FEATURE_SUPPORTED_START 12
+#define SST_BF_FEATURE_SUPPORTED_WIDTH 1
+
+#define SST_TF_FEATURE_SUPPORTED_START 12
+#define SST_TF_FEATURE_SUPPORTED_WIDTH 1
+
+static int isst_if_get_perf_level(void __user *argp)
+{
+ struct isst_perf_level_info perf_level;
+ struct tpmi_per_power_domain_info *power_domain_info;
+
+ if (copy_from_user(&perf_level, argp, sizeof(perf_level)))
+ return -EFAULT;
+
+ power_domain_info = get_instance(perf_level.socket_id, perf_level.power_domain_id);
+ if (!power_domain_info)
+ return -EINVAL;
+
+ perf_level.max_level = power_domain_info->max_level;
+ perf_level.level_mask = power_domain_info->pp_header.allowed_level_mask;
+ perf_level.feature_rev = power_domain_info->pp_header.feature_rev;
+ _read_pp_info("current_level", perf_level.current_level, SST_PP_STATUS_OFFSET,
+ SST_PP_LEVEL_START, SST_PP_LEVEL_WIDTH, SST_MUL_FACTOR_NONE)
+ _read_pp_info("locked", perf_level.locked, SST_PP_STATUS_OFFSET,
+ SST_PP_LOCK_START, SST_PP_LEVEL_WIDTH, SST_MUL_FACTOR_NONE)
+ _read_pp_info("feature_state", perf_level.feature_state, SST_PP_STATUS_OFFSET,
+ SST_PP_FEATURE_STATE_START, SST_PP_FEATURE_STATE_WIDTH, SST_MUL_FACTOR_NONE)
+ perf_level.enabled = !!(power_domain_info->sst_header.cap_mask & BIT(1));
+
+ _read_bf_level_info("bf_support", perf_level.sst_bf_support, 0, 0,
+ SST_BF_FEATURE_SUPPORTED_START, SST_BF_FEATURE_SUPPORTED_WIDTH,
+ SST_MUL_FACTOR_NONE);
+ _read_tf_level_info("tf_support", perf_level.sst_tf_support, 0, 0,
+ SST_TF_FEATURE_SUPPORTED_START, SST_TF_FEATURE_SUPPORTED_WIDTH,
+ SST_MUL_FACTOR_NONE);
+
+ if (copy_to_user(argp, &perf_level, sizeof(perf_level)))
+ return -EFAULT;
+
+ return 0;
+}
+
+#define SST_PP_CONTROL_OFFSET 24
+#define SST_PP_LEVEL_CHANGE_TIME_MS 5
+#define SST_PP_LEVEL_CHANGE_RETRY_COUNT 3
+
+static int isst_if_set_perf_level(void __user *argp)
+{
+ struct isst_perf_level_control perf_level;
+ struct tpmi_per_power_domain_info *power_domain_info;
+ int level, retry = 0;
+
+ if (disable_dynamic_sst_features())
+ return -EFAULT;
+
+ if (copy_from_user(&perf_level, argp, sizeof(perf_level)))
+ return -EFAULT;
+
+ power_domain_info = get_instance(perf_level.socket_id, perf_level.power_domain_id);
+ if (!power_domain_info)
+ return -EINVAL;
+
+ if (!(power_domain_info->pp_header.allowed_level_mask & BIT(perf_level.level)))
+ return -EINVAL;
+
+ _read_pp_info("current_level", level, SST_PP_STATUS_OFFSET,
+ SST_PP_LEVEL_START, SST_PP_LEVEL_WIDTH, SST_MUL_FACTOR_NONE)
+
+ /* If the requested new level is same as the current level, reject */
+ if (perf_level.level == level)
+ return -EINVAL;
+
+ _write_pp_info("perf_level", perf_level.level, SST_PP_CONTROL_OFFSET,
+ SST_PP_LEVEL_START, SST_PP_LEVEL_WIDTH, SST_MUL_FACTOR_NONE)
+
+ /* It is possible that firmware is busy (although unlikely), so retry */
+ do {
+ /* Give time to FW to process */
+ msleep(SST_PP_LEVEL_CHANGE_TIME_MS);
+
+ _read_pp_info("current_level", level, SST_PP_STATUS_OFFSET,
+ SST_PP_LEVEL_START, SST_PP_LEVEL_WIDTH, SST_MUL_FACTOR_NONE)
+
+ /* Check if the new level is active */
+ if (perf_level.level == level)
+ break;
+
+ } while (retry++ < SST_PP_LEVEL_CHANGE_RETRY_COUNT);
+
+ /* If the level change didn't happen, return fault */
+ if (perf_level.level != level)
+ return -EFAULT;
+
+ /* Reset the feature state on level change */
+ _write_pp_info("perf_feature", 0, SST_PP_CONTROL_OFFSET,
+ SST_PP_FEATURE_STATE_START, SST_PP_FEATURE_STATE_WIDTH,
+ SST_MUL_FACTOR_NONE)
+
+ /* Give time to FW to process */
+ msleep(SST_PP_LEVEL_CHANGE_TIME_MS);
+
+ return 0;
+}
+
+static int isst_if_set_perf_feature(void __user *argp)
+{
+ struct isst_perf_feature_control perf_feature;
+ struct tpmi_per_power_domain_info *power_domain_info;
+
+ if (disable_dynamic_sst_features())
+ return -EFAULT;
+
+ if (copy_from_user(&perf_feature, argp, sizeof(perf_feature)))
+ return -EFAULT;
+
+ power_domain_info = get_instance(perf_feature.socket_id, perf_feature.power_domain_id);
+ if (!power_domain_info)
+ return -EINVAL;
+
+ _write_pp_info("perf_feature", perf_feature.feature, SST_PP_CONTROL_OFFSET,
+ SST_PP_FEATURE_STATE_START, SST_PP_FEATURE_STATE_WIDTH,
+ SST_MUL_FACTOR_NONE)
+
+ return 0;
+}
+
+#define _read_pp_level_info(name_str, name, level, offset, start, width, mult_factor)\
+{\
+ u64 val, _mask;\
+ \
+ val = readq(power_domain_info->sst_base +\
+ power_domain_info->perf_levels[level].mmio_offset +\
+ (power_domain_info->feature_offsets.pp_offset * 8) + (offset));\
+ _mask = GENMASK_ULL((start + width - 1), start);\
+ val &= _mask; \
+ val >>= start;\
+ name = (val * mult_factor);\
+}
+
+#define SST_PP_INFO_0_OFFSET 0
+#define SST_PP_INFO_1_OFFSET 8
+#define SST_PP_INFO_2_OFFSET 16
+#define SST_PP_INFO_3_OFFSET 24
+
+/* SST_PP_INFO_4_OFFSET to SST_PP_INFO_9_OFFSET are trl levels */
+#define SST_PP_INFO_4_OFFSET 32
+
+#define SST_PP_INFO_10_OFFSET 80
+#define SST_PP_INFO_11_OFFSET 88
+
+#define SST_PP_P1_SSE_START 0
+#define SST_PP_P1_SSE_WIDTH 8
+
+#define SST_PP_P1_AVX2_START 8
+#define SST_PP_P1_AVX2_WIDTH 8
+
+#define SST_PP_P1_AVX512_START 16
+#define SST_PP_P1_AVX512_WIDTH 8
+
+#define SST_PP_P1_AMX_START 24
+#define SST_PP_P1_AMX_WIDTH 8
+
+#define SST_PP_TDP_START 32
+#define SST_PP_TDP_WIDTH 15
+
+#define SST_PP_T_PROCHOT_START 47
+#define SST_PP_T_PROCHOT_WIDTH 8
+
+#define SST_PP_MAX_MEMORY_FREQ_START 55
+#define SST_PP_MAX_MEMORY_FREQ_WIDTH 7
+
+#define SST_PP_COOLING_TYPE_START 62
+#define SST_PP_COOLING_TYPE_WIDTH 2
+
+#define SST_PP_TRL_0_RATIO_0_START 0
+#define SST_PP_TRL_0_RATIO_0_WIDTH 8
+
+#define SST_PP_TRL_CORES_BUCKET_0_START 0
+#define SST_PP_TRL_CORES_BUCKET_0_WIDTH 8
+
+#define SST_PP_CORE_RATIO_P0_START 0
+#define SST_PP_CORE_RATIO_P0_WIDTH 8
+
+#define SST_PP_CORE_RATIO_P1_START 8
+#define SST_PP_CORE_RATIO_P1_WIDTH 8
+
+#define SST_PP_CORE_RATIO_PN_START 16
+#define SST_PP_CORE_RATIO_PN_WIDTH 8
+
+#define SST_PP_CORE_RATIO_PM_START 24
+#define SST_PP_CORE_RATIO_PM_WIDTH 8
+
+#define SST_PP_CORE_RATIO_P0_FABRIC_START 32
+#define SST_PP_CORE_RATIO_P0_FABRIC_WIDTH 8
+
+#define SST_PP_CORE_RATIO_P1_FABRIC_START 40
+#define SST_PP_CORE_RATIO_P1_FABRIC_WIDTH 8
+
+#define SST_PP_CORE_RATIO_PM_FABRIC_START 48
+#define SST_PP_CORE_RATIO_PM_FABRIC_WIDTH 8
+
+static int isst_if_get_perf_level_info(void __user *argp)
+{
+ struct isst_perf_level_data_info perf_level;
+ struct tpmi_per_power_domain_info *power_domain_info;
+ int i, j;
+
+ if (copy_from_user(&perf_level, argp, sizeof(perf_level)))
+ return -EFAULT;
+
+ power_domain_info = get_instance(perf_level.socket_id, perf_level.power_domain_id);
+ if (!power_domain_info)
+ return -EINVAL;
+
+ if (perf_level.level > power_domain_info->max_level)
+ return -EINVAL;
+
+ if (!(power_domain_info->pp_header.level_en_mask & BIT(perf_level.level)))
+ return -EINVAL;
+
+ _read_pp_level_info("tdp_ratio", perf_level.tdp_ratio, perf_level.level,
+ SST_PP_INFO_0_OFFSET, SST_PP_P1_SSE_START, SST_PP_P1_SSE_WIDTH,
+ SST_MUL_FACTOR_NONE)
+ _read_pp_level_info("base_freq_mhz", perf_level.base_freq_mhz, perf_level.level,
+ SST_PP_INFO_0_OFFSET, SST_PP_P1_SSE_START, SST_PP_P1_SSE_WIDTH,
+ SST_MUL_FACTOR_FREQ)
+ _read_pp_level_info("base_freq_avx2_mhz", perf_level.base_freq_avx2_mhz, perf_level.level,
+ SST_PP_INFO_0_OFFSET, SST_PP_P1_AVX2_START, SST_PP_P1_AVX2_WIDTH,
+ SST_MUL_FACTOR_FREQ)
+ _read_pp_level_info("base_freq_avx512_mhz", perf_level.base_freq_avx512_mhz,
+ perf_level.level, SST_PP_INFO_0_OFFSET, SST_PP_P1_AVX512_START,
+ SST_PP_P1_AVX512_WIDTH, SST_MUL_FACTOR_FREQ)
+ _read_pp_level_info("base_freq_amx_mhz", perf_level.base_freq_amx_mhz, perf_level.level,
+ SST_PP_INFO_0_OFFSET, SST_PP_P1_AMX_START, SST_PP_P1_AMX_WIDTH,
+ SST_MUL_FACTOR_FREQ)
+
+ _read_pp_level_info("thermal_design_power_w", perf_level.thermal_design_power_w,
+ perf_level.level, SST_PP_INFO_1_OFFSET, SST_PP_TDP_START,
+ SST_PP_TDP_WIDTH, SST_MUL_FACTOR_NONE)
+ perf_level.thermal_design_power_w /= 8; /* units are in 1/8th watt */
+ _read_pp_level_info("tjunction_max_c", perf_level.tjunction_max_c, perf_level.level,
+ SST_PP_INFO_1_OFFSET, SST_PP_T_PROCHOT_START, SST_PP_T_PROCHOT_WIDTH,
+ SST_MUL_FACTOR_NONE)
+ _read_pp_level_info("max_memory_freq_mhz", perf_level.max_memory_freq_mhz,
+ perf_level.level, SST_PP_INFO_1_OFFSET, SST_PP_MAX_MEMORY_FREQ_START,
+ SST_PP_MAX_MEMORY_FREQ_WIDTH, SST_MUL_FACTOR_FREQ)
+ _read_pp_level_info("cooling_type", perf_level.cooling_type, perf_level.level,
+ SST_PP_INFO_1_OFFSET, SST_PP_COOLING_TYPE_START,
+ SST_PP_COOLING_TYPE_WIDTH, SST_MUL_FACTOR_NONE)
+
+ for (i = 0; i < TRL_MAX_LEVELS; ++i) {
+ for (j = 0; j < TRL_MAX_BUCKETS; ++j)
+ _read_pp_level_info("trl*_bucket*_freq_mhz",
+ perf_level.trl_freq_mhz[i][j], perf_level.level,
+ SST_PP_INFO_4_OFFSET + (i * SST_PP_TRL_0_RATIO_0_WIDTH),
+ j * SST_PP_TRL_0_RATIO_0_WIDTH,
+ SST_PP_TRL_0_RATIO_0_WIDTH,
+ SST_MUL_FACTOR_FREQ);
+ }
+
+ for (i = 0; i < TRL_MAX_BUCKETS; ++i)
+ _read_pp_level_info("bucket*_core_count", perf_level.bucket_core_counts[i],
+ perf_level.level, SST_PP_INFO_10_OFFSET,
+ SST_PP_TRL_CORES_BUCKET_0_WIDTH * i,
+ SST_PP_TRL_CORES_BUCKET_0_WIDTH, SST_MUL_FACTOR_NONE)
+
+ perf_level.max_buckets = TRL_MAX_BUCKETS;
+ perf_level.max_trl_levels = TRL_MAX_LEVELS;
+
+ _read_pp_level_info("p0_freq_mhz", perf_level.p0_freq_mhz, perf_level.level,
+ SST_PP_INFO_11_OFFSET, SST_PP_CORE_RATIO_P0_START,
+ SST_PP_CORE_RATIO_P0_WIDTH, SST_MUL_FACTOR_FREQ)
+ _read_pp_level_info("p1_freq_mhz", perf_level.p1_freq_mhz, perf_level.level,
+ SST_PP_INFO_11_OFFSET, SST_PP_CORE_RATIO_P1_START,
+ SST_PP_CORE_RATIO_P1_WIDTH, SST_MUL_FACTOR_FREQ)
+ _read_pp_level_info("pn_freq_mhz", perf_level.pn_freq_mhz, perf_level.level,
+ SST_PP_INFO_11_OFFSET, SST_PP_CORE_RATIO_PN_START,
+ SST_PP_CORE_RATIO_PN_WIDTH, SST_MUL_FACTOR_FREQ)
+ _read_pp_level_info("pm_freq_mhz", perf_level.pm_freq_mhz, perf_level.level,
+ SST_PP_INFO_11_OFFSET, SST_PP_CORE_RATIO_PM_START,
+ SST_PP_CORE_RATIO_PM_WIDTH, SST_MUL_FACTOR_FREQ)
+ _read_pp_level_info("p0_fabric_freq_mhz", perf_level.p0_fabric_freq_mhz,
+ perf_level.level, SST_PP_INFO_11_OFFSET,
+ SST_PP_CORE_RATIO_P0_FABRIC_START,
+ SST_PP_CORE_RATIO_P0_FABRIC_WIDTH, SST_MUL_FACTOR_FREQ)
+ _read_pp_level_info("p1_fabric_freq_mhz", perf_level.p1_fabric_freq_mhz,
+ perf_level.level, SST_PP_INFO_11_OFFSET,
+ SST_PP_CORE_RATIO_P1_FABRIC_START,
+ SST_PP_CORE_RATIO_P1_FABRIC_WIDTH, SST_MUL_FACTOR_FREQ)
+ _read_pp_level_info("pm_fabric_freq_mhz", perf_level.pm_fabric_freq_mhz,
+ perf_level.level, SST_PP_INFO_11_OFFSET,
+ SST_PP_CORE_RATIO_PM_FABRIC_START,
+ SST_PP_CORE_RATIO_PM_FABRIC_WIDTH, SST_MUL_FACTOR_FREQ)
+
+ if (copy_to_user(argp, &perf_level, sizeof(perf_level)))
+ return -EFAULT;
+
+ return 0;
+}
+
+#define SST_PP_FUSED_CORE_COUNT_START 0
+#define SST_PP_FUSED_CORE_COUNT_WIDTH 8
+
+#define SST_PP_RSLVD_CORE_COUNT_START 8
+#define SST_PP_RSLVD_CORE_COUNT_WIDTH 8
+
+#define SST_PP_RSLVD_CORE_MASK_START 0
+#define SST_PP_RSLVD_CORE_MASK_WIDTH 64
+
+static int isst_if_get_perf_level_mask(void __user *argp)
+{
+ static struct isst_perf_level_cpu_mask cpumask;
+ struct tpmi_per_power_domain_info *power_domain_info;
+ u64 mask;
+
+ if (copy_from_user(&cpumask, argp, sizeof(cpumask)))
+ return -EFAULT;
+
+ power_domain_info = get_instance(cpumask.socket_id, cpumask.power_domain_id);
+ if (!power_domain_info)
+ return -EINVAL;
+
+ _read_pp_level_info("mask", mask, cpumask.level, SST_PP_INFO_2_OFFSET,
+ SST_PP_RSLVD_CORE_MASK_START, SST_PP_RSLVD_CORE_MASK_WIDTH,
+ SST_MUL_FACTOR_NONE)
+
+ cpumask.mask = mask;
+
+ if (!cpumask.punit_cpu_map)
+ return -EOPNOTSUPP;
+
+ if (copy_to_user(argp, &cpumask, sizeof(cpumask)))
+ return -EFAULT;
+
+ return 0;
+}
+
+#define SST_BF_INFO_0_OFFSET 0
+#define SST_BF_INFO_1_OFFSET 8
+
+#define SST_BF_P1_HIGH_START 13
+#define SST_BF_P1_HIGH_WIDTH 8
+
+#define SST_BF_P1_LOW_START 21
+#define SST_BF_P1_LOW_WIDTH 8
+
+#define SST_BF_T_PROHOT_START 38
+#define SST_BF_T_PROHOT_WIDTH 8
+
+#define SST_BF_TDP_START 46
+#define SST_BF_TDP_WIDTH 15
+
+static int isst_if_get_base_freq_info(void __user *argp)
+{
+ static struct isst_base_freq_info base_freq;
+ struct tpmi_per_power_domain_info *power_domain_info;
+
+ if (copy_from_user(&base_freq, argp, sizeof(base_freq)))
+ return -EFAULT;
+
+ power_domain_info = get_instance(base_freq.socket_id, base_freq.power_domain_id);
+ if (!power_domain_info)
+ return -EINVAL;
+
+ if (base_freq.level > power_domain_info->max_level)
+ return -EINVAL;
+
+ _read_bf_level_info("p1_high", base_freq.high_base_freq_mhz, base_freq.level,
+ SST_BF_INFO_0_OFFSET, SST_BF_P1_HIGH_START, SST_BF_P1_HIGH_WIDTH,
+ SST_MUL_FACTOR_FREQ)
+ _read_bf_level_info("p1_low", base_freq.low_base_freq_mhz, base_freq.level,
+ SST_BF_INFO_0_OFFSET, SST_BF_P1_LOW_START, SST_BF_P1_LOW_WIDTH,
+ SST_MUL_FACTOR_FREQ)
+ _read_bf_level_info("BF-TJ", base_freq.tjunction_max_c, base_freq.level,
+ SST_BF_INFO_0_OFFSET, SST_BF_T_PROHOT_START, SST_BF_T_PROHOT_WIDTH,
+ SST_MUL_FACTOR_NONE)
+ _read_bf_level_info("BF-tdp", base_freq.thermal_design_power_w, base_freq.level,
+ SST_BF_INFO_0_OFFSET, SST_BF_TDP_START, SST_BF_TDP_WIDTH,
+ SST_MUL_FACTOR_NONE)
+ base_freq.thermal_design_power_w /= 8; /*unit = 1/8th watt*/
+
+ if (copy_to_user(argp, &base_freq, sizeof(base_freq)))
+ return -EFAULT;
+
+ return 0;
+}
+
+#define P1_HI_CORE_MASK_START 0
+#define P1_HI_CORE_MASK_WIDTH 64
+
+static int isst_if_get_base_freq_mask(void __user *argp)
+{
+ static struct isst_perf_level_cpu_mask cpumask;
+ struct tpmi_per_power_domain_info *power_domain_info;
+ u64 mask;
+
+ if (copy_from_user(&cpumask, argp, sizeof(cpumask)))
+ return -EFAULT;
+
+ power_domain_info = get_instance(cpumask.socket_id, cpumask.power_domain_id);
+ if (!power_domain_info)
+ return -EINVAL;
+
+ _read_bf_level_info("BF-cpumask", mask, cpumask.level, SST_BF_INFO_1_OFFSET,
+ P1_HI_CORE_MASK_START, P1_HI_CORE_MASK_WIDTH,
+ SST_MUL_FACTOR_NONE)
+
+ cpumask.mask = mask;
+
+ if (!cpumask.punit_cpu_map)
+ return -EOPNOTSUPP;
+
+ if (copy_to_user(argp, &cpumask, sizeof(cpumask)))
+ return -EFAULT;
+
+ return 0;
+}
+
+static int isst_if_get_tpmi_instance_count(void __user *argp)
+{
+ struct isst_tpmi_instance_count tpmi_inst;
+ struct tpmi_sst_struct *sst_inst;
+ int i;
+
+ if (copy_from_user(&tpmi_inst, argp, sizeof(tpmi_inst)))
+ return -EFAULT;
+
+ if (tpmi_inst.socket_id >= topology_max_packages())
+ return -EINVAL;
+
+ tpmi_inst.count = isst_common.sst_inst[tpmi_inst.socket_id]->number_of_power_domains;
+
+ sst_inst = isst_common.sst_inst[tpmi_inst.socket_id];
+ tpmi_inst.valid_mask = 0;
+ for (i = 0; i < sst_inst->number_of_power_domains; ++i) {
+ struct tpmi_per_power_domain_info *pd_info;
+
+ pd_info = &sst_inst->power_domain_info[i];
+ if (pd_info->sst_base)
+ tpmi_inst.valid_mask |= BIT(i);
+ }
+
+ if (copy_to_user(argp, &tpmi_inst, sizeof(tpmi_inst)))
+ return -EFAULT;
+
+ return 0;
+}
+
+#define SST_TF_INFO_0_OFFSET 0
+#define SST_TF_INFO_1_OFFSET 8
+#define SST_TF_INFO_2_OFFSET 16
+
+#define SST_TF_MAX_LP_CLIP_RATIOS TRL_MAX_LEVELS
+
+#define SST_TF_LP_CLIP_RATIO_0_START 16
+#define SST_TF_LP_CLIP_RATIO_0_WIDTH 8
+
+#define SST_TF_RATIO_0_START 0
+#define SST_TF_RATIO_0_WIDTH 8
+
+#define SST_TF_NUM_CORE_0_START 0
+#define SST_TF_NUM_CORE_0_WIDTH 8
+
+static int isst_if_get_turbo_freq_info(void __user *argp)
+{
+ static struct isst_turbo_freq_info turbo_freq;
+ struct tpmi_per_power_domain_info *power_domain_info;
+ int i, j;
+
+ if (copy_from_user(&turbo_freq, argp, sizeof(turbo_freq)))
+ return -EFAULT;
+
+ power_domain_info = get_instance(turbo_freq.socket_id, turbo_freq.power_domain_id);
+ if (!power_domain_info)
+ return -EINVAL;
+
+ if (turbo_freq.level > power_domain_info->max_level)
+ return -EINVAL;
+
+ turbo_freq.max_buckets = TRL_MAX_BUCKETS;
+ turbo_freq.max_trl_levels = TRL_MAX_LEVELS;
+ turbo_freq.max_clip_freqs = SST_TF_MAX_LP_CLIP_RATIOS;
+
+ for (i = 0; i < turbo_freq.max_clip_freqs; ++i)
+ _read_tf_level_info("lp_clip*", turbo_freq.lp_clip_freq_mhz[i],
+ turbo_freq.level, SST_TF_INFO_0_OFFSET,
+ SST_TF_LP_CLIP_RATIO_0_START +
+ (i * SST_TF_LP_CLIP_RATIO_0_WIDTH),
+ SST_TF_LP_CLIP_RATIO_0_WIDTH, SST_MUL_FACTOR_FREQ)
+
+ for (i = 0; i < TRL_MAX_LEVELS; ++i) {
+ for (j = 0; j < TRL_MAX_BUCKETS; ++j)
+ _read_tf_level_info("cydn*_bucket_*_trl",
+ turbo_freq.trl_freq_mhz[i][j], turbo_freq.level,
+ SST_TF_INFO_2_OFFSET + (i * SST_TF_RATIO_0_WIDTH),
+ j * SST_TF_RATIO_0_WIDTH, SST_TF_RATIO_0_WIDTH,
+ SST_MUL_FACTOR_FREQ)
+ }
+
+ for (i = 0; i < TRL_MAX_BUCKETS; ++i)
+ _read_tf_level_info("bucket_*_core_count", turbo_freq.bucket_core_counts[i],
+ turbo_freq.level, SST_TF_INFO_1_OFFSET,
+ SST_TF_NUM_CORE_0_WIDTH * i, SST_TF_NUM_CORE_0_WIDTH,
+ SST_MUL_FACTOR_NONE)
+
+ if (copy_to_user(argp, &turbo_freq, sizeof(turbo_freq)))
+ return -EFAULT;
+
+ return 0;
+}
+
+static long isst_if_def_ioctl(struct file *file, unsigned int cmd,
+ unsigned long arg)
+{
+ void __user *argp = (void __user *)arg;
+ long ret = -ENOTTY;
+
+ mutex_lock(&isst_tpmi_dev_lock);
+ switch (cmd) {
+ case ISST_IF_COUNT_TPMI_INSTANCES:
+ ret = isst_if_get_tpmi_instance_count(argp);
+ break;
+ case ISST_IF_CORE_POWER_STATE:
+ ret = isst_if_core_power_state(argp);
+ break;
+ case ISST_IF_CLOS_PARAM:
+ ret = isst_if_clos_param(argp);
+ break;
+ case ISST_IF_CLOS_ASSOC:
+ ret = isst_if_clos_assoc(argp);
+ break;
+ case ISST_IF_PERF_LEVELS:
+ ret = isst_if_get_perf_level(argp);
+ break;
+ case ISST_IF_PERF_SET_LEVEL:
+ ret = isst_if_set_perf_level(argp);
+ break;
+ case ISST_IF_PERF_SET_FEATURE:
+ ret = isst_if_set_perf_feature(argp);
+ break;
+ case ISST_IF_GET_PERF_LEVEL_INFO:
+ ret = isst_if_get_perf_level_info(argp);
+ break;
+ case ISST_IF_GET_PERF_LEVEL_CPU_MASK:
+ ret = isst_if_get_perf_level_mask(argp);
+ break;
+ case ISST_IF_GET_BASE_FREQ_INFO:
+ ret = isst_if_get_base_freq_info(argp);
+ break;
+ case ISST_IF_GET_BASE_FREQ_CPU_MASK:
+ ret = isst_if_get_base_freq_mask(argp);
+ break;
+ case ISST_IF_GET_TURBO_FREQ_INFO:
+ ret = isst_if_get_turbo_freq_info(argp);
+ break;
+ default:
+ break;
+ }
+ mutex_unlock(&isst_tpmi_dev_lock);
+
+ return ret;
+}
+
+#define TPMI_SST_AUTO_SUSPEND_DELAY_MS 2000
+
+int tpmi_sst_dev_add(struct auxiliary_device *auxdev)
+{
+ struct intel_tpmi_plat_info *plat_info;
+ struct tpmi_sst_struct *tpmi_sst;
+ int i, ret, pkg = 0, inst = 0;
+ int num_resources;
+
+ plat_info = tpmi_get_platform_data(auxdev);
+ if (!plat_info) {
+ dev_err(&auxdev->dev, "No platform info\n");
+ return -EINVAL;
+ }
+
+ pkg = plat_info->package_id;
+ if (pkg >= topology_max_packages()) {
+ dev_err(&auxdev->dev, "Invalid package id :%x\n", pkg);
+ return -EINVAL;
+ }
+
+ if (isst_common.sst_inst[pkg])
+ return -EEXIST;
+
+ num_resources = tpmi_get_resource_count(auxdev);
+
+ if (!num_resources)
+ return -EINVAL;
+
+ tpmi_sst = devm_kzalloc(&auxdev->dev, sizeof(*tpmi_sst), GFP_KERNEL);
+ if (!tpmi_sst)
+ return -ENOMEM;
+
+ tpmi_sst->power_domain_info = devm_kcalloc(&auxdev->dev, num_resources,
+ sizeof(*tpmi_sst->power_domain_info),
+ GFP_KERNEL);
+ if (!tpmi_sst->power_domain_info)
+ return -ENOMEM;
+
+ tpmi_sst->number_of_power_domains = num_resources;
+
+ for (i = 0; i < num_resources; ++i) {
+ struct resource *res;
+
+ res = tpmi_get_resource_at_index(auxdev, i);
+ if (!res) {
+ tpmi_sst->power_domain_info[i].sst_base = NULL;
+ continue;
+ }
+
+ tpmi_sst->power_domain_info[i].package_id = pkg;
+ tpmi_sst->power_domain_info[i].power_domain_id = i;
+ tpmi_sst->power_domain_info[i].auxdev = auxdev;
+ tpmi_sst->power_domain_info[i].sst_base = devm_ioremap_resource(&auxdev->dev, res);
+ if (IS_ERR(tpmi_sst->power_domain_info[i].sst_base))
+ return PTR_ERR(tpmi_sst->power_domain_info[i].sst_base);
+
+ ret = sst_main(auxdev, &tpmi_sst->power_domain_info[i]);
+ if (ret) {
+ devm_iounmap(&auxdev->dev, tpmi_sst->power_domain_info[i].sst_base);
+ tpmi_sst->power_domain_info[i].sst_base = NULL;
+ continue;
+ }
+
+ ++inst;
+ }
+
+ if (!inst)
+ return -ENODEV;
+
+ tpmi_sst->package_id = pkg;
+ auxiliary_set_drvdata(auxdev, tpmi_sst);
+
+ mutex_lock(&isst_tpmi_dev_lock);
+ if (isst_common.max_index < pkg)
+ isst_common.max_index = pkg;
+ isst_common.sst_inst[pkg] = tpmi_sst;
+ mutex_unlock(&isst_tpmi_dev_lock);
+
+ return 0;
+}
+EXPORT_SYMBOL_NS_GPL(tpmi_sst_dev_add, INTEL_TPMI_SST);
+
+void tpmi_sst_dev_remove(struct auxiliary_device *auxdev)
+{
+ struct tpmi_sst_struct *tpmi_sst = auxiliary_get_drvdata(auxdev);
+
+ mutex_lock(&isst_tpmi_dev_lock);
+ isst_common.sst_inst[tpmi_sst->package_id] = NULL;
+ mutex_unlock(&isst_tpmi_dev_lock);
+}
+EXPORT_SYMBOL_NS_GPL(tpmi_sst_dev_remove, INTEL_TPMI_SST);
+
+void tpmi_sst_dev_suspend(struct auxiliary_device *auxdev)
+{
+ struct tpmi_sst_struct *tpmi_sst = auxiliary_get_drvdata(auxdev);
+ struct tpmi_per_power_domain_info *power_domain_info = tpmi_sst->power_domain_info;
+ void __iomem *cp_base;
+
+ cp_base = power_domain_info->sst_base + power_domain_info->sst_header.cp_offset;
+ power_domain_info->saved_sst_cp_control = readq(cp_base + SST_CP_CONTROL_OFFSET);
+
+ memcpy_fromio(power_domain_info->saved_clos_configs, cp_base + SST_CLOS_CONFIG_0_OFFSET,
+ sizeof(power_domain_info->saved_clos_configs));
+
+ memcpy_fromio(power_domain_info->saved_clos_assocs, cp_base + SST_CLOS_ASSOC_0_OFFSET,
+ sizeof(power_domain_info->saved_clos_assocs));
+
+ power_domain_info->saved_pp_control = readq(power_domain_info->sst_base +
+ power_domain_info->sst_header.pp_offset +
+ SST_PP_CONTROL_OFFSET);
+}
+EXPORT_SYMBOL_NS_GPL(tpmi_sst_dev_suspend, INTEL_TPMI_SST);
+
+void tpmi_sst_dev_resume(struct auxiliary_device *auxdev)
+{
+ struct tpmi_sst_struct *tpmi_sst = auxiliary_get_drvdata(auxdev);
+ struct tpmi_per_power_domain_info *power_domain_info = tpmi_sst->power_domain_info;
+ void __iomem *cp_base;
+
+ cp_base = power_domain_info->sst_base + power_domain_info->sst_header.cp_offset;
+ writeq(power_domain_info->saved_sst_cp_control, cp_base + SST_CP_CONTROL_OFFSET);
+
+ memcpy_toio(cp_base + SST_CLOS_CONFIG_0_OFFSET, power_domain_info->saved_clos_configs,
+ sizeof(power_domain_info->saved_clos_configs));
+
+ memcpy_toio(cp_base + SST_CLOS_ASSOC_0_OFFSET, power_domain_info->saved_clos_assocs,
+ sizeof(power_domain_info->saved_clos_assocs));
+
+ writeq(power_domain_info->saved_pp_control, power_domain_info->sst_base +
+ power_domain_info->sst_header.pp_offset + SST_PP_CONTROL_OFFSET);
+}
+EXPORT_SYMBOL_NS_GPL(tpmi_sst_dev_resume, INTEL_TPMI_SST);
+
+#define ISST_TPMI_API_VERSION 0x02
+
+int tpmi_sst_init(void)
+{
+ struct isst_if_cmd_cb cb;
+ int ret = 0;
+
+ mutex_lock(&isst_tpmi_dev_lock);
+
+ if (isst_core_usage_count) {
+ ++isst_core_usage_count;
+ goto init_done;
+ }
+
+ isst_common.sst_inst = kcalloc(topology_max_packages(),
+ sizeof(*isst_common.sst_inst),
+ GFP_KERNEL);
+ if (!isst_common.sst_inst) {
+ ret = -ENOMEM;
+ goto init_done;
+ }
+
+ memset(&cb, 0, sizeof(cb));
+ cb.cmd_size = sizeof(struct isst_if_io_reg);
+ cb.offset = offsetof(struct isst_if_io_regs, io_reg);
+ cb.cmd_callback = NULL;
+ cb.api_version = ISST_TPMI_API_VERSION;
+ cb.def_ioctl = isst_if_def_ioctl;
+ cb.owner = THIS_MODULE;
+ ret = isst_if_cdev_register(ISST_IF_DEV_TPMI, &cb);
+ if (ret)
+ kfree(isst_common.sst_inst);
+init_done:
+ mutex_unlock(&isst_tpmi_dev_lock);
+ return ret;
+}
+EXPORT_SYMBOL_NS_GPL(tpmi_sst_init, INTEL_TPMI_SST);
+
+void tpmi_sst_exit(void)
+{
+ mutex_lock(&isst_tpmi_dev_lock);
+ if (isst_core_usage_count)
+ --isst_core_usage_count;
+
+ if (!isst_core_usage_count) {
+ isst_if_cdev_unregister(ISST_IF_DEV_TPMI);
+ kfree(isst_common.sst_inst);
+ }
+ mutex_unlock(&isst_tpmi_dev_lock);
+}
+EXPORT_SYMBOL_NS_GPL(tpmi_sst_exit, INTEL_TPMI_SST);
+
+MODULE_IMPORT_NS(INTEL_TPMI);
+MODULE_IMPORT_NS(INTEL_TPMI_POWER_DOMAIN);
+
+MODULE_LICENSE("GPL");
diff --git a/drivers/platform/x86/intel/speed_select_if/isst_tpmi_core.h b/drivers/platform/x86/intel/speed_select_if/isst_tpmi_core.h
new file mode 100644
index 000000000000..900b483703f9
--- /dev/null
+++ b/drivers/platform/x86/intel/speed_select_if/isst_tpmi_core.h
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Intel Speed Select Interface: Drivers Internal defines
+ * Copyright (c) 2023, Intel Corporation.
+ * All rights reserved.
+ *
+ */
+
+#ifndef _ISST_TPMI_CORE_H
+#define _ISST_TPMI_CORE_H
+
+int tpmi_sst_init(void);
+void tpmi_sst_exit(void);
+int tpmi_sst_dev_add(struct auxiliary_device *auxdev);
+void tpmi_sst_dev_remove(struct auxiliary_device *auxdev);
+void tpmi_sst_dev_suspend(struct auxiliary_device *auxdev);
+void tpmi_sst_dev_resume(struct auxiliary_device *auxdev);
+#endif
diff --git a/drivers/platform/x86/intel/telemetry/pltdrv.c b/drivers/platform/x86/intel/telemetry/pltdrv.c
index 405dea87de6b..06311d0e9451 100644
--- a/drivers/platform/x86/intel/telemetry/pltdrv.c
+++ b/drivers/platform/x86/intel/telemetry/pltdrv.c
@@ -1156,15 +1156,14 @@ out:
return ret;
}
-static int telemetry_pltdrv_remove(struct platform_device *pdev)
+static void telemetry_pltdrv_remove(struct platform_device *pdev)
{
telemetry_clear_pltdata();
- return 0;
}
static struct platform_driver telemetry_soc_driver = {
.probe = telemetry_pltdrv_probe,
- .remove = telemetry_pltdrv_remove,
+ .remove_new = telemetry_pltdrv_remove,
.driver = {
.name = DRIVER_NAME,
},
diff --git a/drivers/platform/x86/intel/uncore-frequency/uncore-frequency.c b/drivers/platform/x86/intel/uncore-frequency/uncore-frequency.c
index 00ac7e381441..32e2515ee366 100644
--- a/drivers/platform/x86/intel/uncore-frequency/uncore-frequency.c
+++ b/drivers/platform/x86/intel/uncore-frequency/uncore-frequency.c
@@ -204,6 +204,13 @@ static const struct x86_cpu_id intel_uncore_cpu_ids[] = {
X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_D, NULL),
X86_MATCH_INTEL_FAM6_MODEL(SAPPHIRERAPIDS_X, NULL),
X86_MATCH_INTEL_FAM6_MODEL(EMERALDRAPIDS_X, NULL),
+ X86_MATCH_INTEL_FAM6_MODEL(ALDERLAKE, NULL),
+ X86_MATCH_INTEL_FAM6_MODEL(ALDERLAKE_L, NULL),
+ X86_MATCH_INTEL_FAM6_MODEL(RAPTORLAKE, NULL),
+ X86_MATCH_INTEL_FAM6_MODEL(RAPTORLAKE_P, NULL),
+ X86_MATCH_INTEL_FAM6_MODEL(RAPTORLAKE_S, NULL),
+ X86_MATCH_INTEL_FAM6_MODEL(METEORLAKE, NULL),
+ X86_MATCH_INTEL_FAM6_MODEL(METEORLAKE_L, NULL),
{}
};
MODULE_DEVICE_TABLE(x86cpu, intel_uncore_cpu_ids);
diff --git a/drivers/platform/x86/intel/vbtn.c b/drivers/platform/x86/intel/vbtn.c
index c5e4e35c8d20..6fa1735ad7a4 100644
--- a/drivers/platform/x86/intel/vbtn.c
+++ b/drivers/platform/x86/intel/vbtn.c
@@ -325,18 +325,12 @@ static int intel_vbtn_probe(struct platform_device *device)
return 0;
}
-static int intel_vbtn_remove(struct platform_device *device)
+static void intel_vbtn_remove(struct platform_device *device)
{
acpi_handle handle = ACPI_HANDLE(&device->dev);
device_init_wakeup(&device->dev, false);
acpi_remove_notify_handler(handle, ACPI_DEVICE_NOTIFY, notify_handler);
-
- /*
- * Even if we failed to shut off the event stream, we can still
- * safely detach from the device.
- */
- return 0;
}
static int intel_vbtn_pm_prepare(struct device *dev)
@@ -377,7 +371,7 @@ static struct platform_driver intel_vbtn_pl_driver = {
.pm = &intel_vbtn_pm_ops,
},
.probe = intel_vbtn_probe,
- .remove = intel_vbtn_remove,
+ .remove_new = intel_vbtn_remove,
};
static acpi_status __init
diff --git a/drivers/platform/x86/intel/vsec.c b/drivers/platform/x86/intel/vsec.c
index 2311c16cb975..c1f9e4471b28 100644
--- a/drivers/platform/x86/intel/vsec.c
+++ b/drivers/platform/x86/intel/vsec.c
@@ -67,14 +67,6 @@ enum intel_vsec_id {
VSEC_ID_TPMI = 66,
};
-static enum intel_vsec_id intel_vsec_allow_list[] = {
- VSEC_ID_TELEMETRY,
- VSEC_ID_WATCHER,
- VSEC_ID_CRASHLOG,
- VSEC_ID_SDSI,
- VSEC_ID_TPMI,
-};
-
static const char *intel_vsec_name(enum intel_vsec_id id)
{
switch (id) {
@@ -98,26 +90,19 @@ static const char *intel_vsec_name(enum intel_vsec_id id)
}
}
-static bool intel_vsec_allowed(u16 id)
-{
- int i;
-
- for (i = 0; i < ARRAY_SIZE(intel_vsec_allow_list); i++)
- if (intel_vsec_allow_list[i] == id)
- return true;
-
- return false;
-}
-
-static bool intel_vsec_disabled(u16 id, unsigned long quirks)
+static bool intel_vsec_supported(u16 id, unsigned long caps)
{
switch (id) {
+ case VSEC_ID_TELEMETRY:
+ return !!(caps & VSEC_CAP_TELEMETRY);
case VSEC_ID_WATCHER:
- return !!(quirks & VSEC_QUIRK_NO_WATCHER);
-
+ return !!(caps & VSEC_CAP_WATCHER);
case VSEC_ID_CRASHLOG:
- return !!(quirks & VSEC_QUIRK_NO_CRASHLOG);
-
+ return !!(caps & VSEC_CAP_CRASHLOG);
+ case VSEC_ID_SDSI:
+ return !!(caps & VSEC_CAP_SDSI);
+ case VSEC_ID_TPMI:
+ return !!(caps & VSEC_CAP_TPMI);
default:
return false;
}
@@ -169,11 +154,7 @@ int intel_vsec_add_aux(struct pci_dev *pdev, struct device *parent,
ret = auxiliary_device_init(auxdev);
if (ret < 0) {
- mutex_lock(&vsec_ida_lock);
- ida_free(intel_vsec_dev->ida, auxdev->id);
- mutex_unlock(&vsec_ida_lock);
- kfree(intel_vsec_dev->resource);
- kfree(intel_vsec_dev);
+ intel_vsec_dev_release(&auxdev->dev);
return ret;
}
@@ -206,7 +187,7 @@ static int intel_vsec_add_dev(struct pci_dev *pdev, struct intel_vsec_header *he
unsigned long quirks = info->quirks;
int i;
- if (!intel_vsec_allowed(header->id) || intel_vsec_disabled(header->id, quirks))
+ if (!intel_vsec_supported(header->id, info->caps))
return -EINVAL;
if (!header->num_entries) {
@@ -261,14 +242,14 @@ static int intel_vsec_add_dev(struct pci_dev *pdev, struct intel_vsec_header *he
static bool intel_vsec_walk_header(struct pci_dev *pdev,
struct intel_vsec_platform_info *info)
{
- struct intel_vsec_header **header = info->capabilities;
+ struct intel_vsec_header **header = info->headers;
bool have_devices = false;
int ret;
for ( ; *header; header++) {
ret = intel_vsec_add_dev(pdev, *header, info);
if (ret)
- dev_info(&pdev->dev, "Could not add device for DVSEC id %d\n",
+ dev_info(&pdev->dev, "Could not add device for VSEC id %d\n",
(*header)->id);
else
have_devices = true;
@@ -403,14 +384,8 @@ static int intel_vsec_pci_probe(struct pci_dev *pdev, const struct pci_device_id
return 0;
}
-/* TGL info */
-static const struct intel_vsec_platform_info tgl_info = {
- .quirks = VSEC_QUIRK_NO_WATCHER | VSEC_QUIRK_NO_CRASHLOG |
- VSEC_QUIRK_TABLE_SHIFT | VSEC_QUIRK_EARLY_HW,
-};
-
/* DG1 info */
-static struct intel_vsec_header dg1_telemetry = {
+static struct intel_vsec_header dg1_header = {
.length = 0x10,
.id = 2,
.num_entries = 1,
@@ -419,19 +394,31 @@ static struct intel_vsec_header dg1_telemetry = {
.offset = 0x466000,
};
-static struct intel_vsec_header *dg1_capabilities[] = {
- &dg1_telemetry,
+static struct intel_vsec_header *dg1_headers[] = {
+ &dg1_header,
NULL
};
static const struct intel_vsec_platform_info dg1_info = {
- .capabilities = dg1_capabilities,
+ .caps = VSEC_CAP_TELEMETRY,
+ .headers = dg1_headers,
.quirks = VSEC_QUIRK_NO_DVSEC | VSEC_QUIRK_EARLY_HW,
};
/* MTL info */
static const struct intel_vsec_platform_info mtl_info = {
- .quirks = VSEC_QUIRK_NO_WATCHER | VSEC_QUIRK_NO_CRASHLOG,
+ .caps = VSEC_CAP_TELEMETRY,
+};
+
+/* OOBMSM info */
+static const struct intel_vsec_platform_info oobmsm_info = {
+ .caps = VSEC_CAP_TELEMETRY | VSEC_CAP_SDSI | VSEC_CAP_TPMI,
+};
+
+/* TGL info */
+static const struct intel_vsec_platform_info tgl_info = {
+ .caps = VSEC_CAP_TELEMETRY,
+ .quirks = VSEC_QUIRK_TABLE_SHIFT | VSEC_QUIRK_EARLY_HW,
};
#define PCI_DEVICE_ID_INTEL_VSEC_ADL 0x467d
@@ -446,7 +433,7 @@ static const struct pci_device_id intel_vsec_pci_ids[] = {
{ PCI_DEVICE_DATA(INTEL, VSEC_DG1, &dg1_info) },
{ PCI_DEVICE_DATA(INTEL, VSEC_MTL_M, &mtl_info) },
{ PCI_DEVICE_DATA(INTEL, VSEC_MTL_S, &mtl_info) },
- { PCI_DEVICE_DATA(INTEL, VSEC_OOBMSM, &(struct intel_vsec_platform_info) {}) },
+ { PCI_DEVICE_DATA(INTEL, VSEC_OOBMSM, &oobmsm_info) },
{ PCI_DEVICE_DATA(INTEL, VSEC_RPL, &tgl_info) },
{ PCI_DEVICE_DATA(INTEL, VSEC_TGL, &tgl_info) },
{ }
diff --git a/drivers/platform/x86/intel/vsec.h b/drivers/platform/x86/intel/vsec.h
index ae8fe92c5595..0fd042c171ba 100644
--- a/drivers/platform/x86/intel/vsec.h
+++ b/drivers/platform/x86/intel/vsec.h
@@ -5,6 +5,12 @@
#include <linux/auxiliary_bus.h>
#include <linux/bits.h>
+#define VSEC_CAP_TELEMETRY BIT(0)
+#define VSEC_CAP_WATCHER BIT(1)
+#define VSEC_CAP_CRASHLOG BIT(2)
+#define VSEC_CAP_SDSI BIT(3)
+#define VSEC_CAP_TPMI BIT(4)
+
struct pci_dev;
struct resource;
@@ -27,7 +33,8 @@ enum intel_vsec_quirks {
/* Platform specific data */
struct intel_vsec_platform_info {
- struct intel_vsec_header **capabilities;
+ struct intel_vsec_header **headers;
+ unsigned long caps;
unsigned long quirks;
};
diff --git a/drivers/platform/x86/lenovo-ymc.c b/drivers/platform/x86/lenovo-ymc.c
new file mode 100644
index 000000000000..41676188b373
--- /dev/null
+++ b/drivers/platform/x86/lenovo-ymc.c
@@ -0,0 +1,187 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * lenovo-ymc.c - Lenovo Yoga Mode Control driver
+ *
+ * Copyright © 2022 Gergo Koteles <soyer@irl.hu>
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/acpi.h>
+#include <linux/dmi.h>
+#include <linux/input.h>
+#include <linux/input/sparse-keymap.h>
+#include <linux/wmi.h>
+#include "ideapad-laptop.h"
+
+#define LENOVO_YMC_EVENT_GUID "06129D99-6083-4164-81AD-F092F9D773A6"
+#define LENOVO_YMC_QUERY_GUID "09B0EE6E-C3FD-4243-8DA1-7911FF80BB8C"
+
+#define LENOVO_YMC_QUERY_INSTANCE 0
+#define LENOVO_YMC_QUERY_METHOD 0x01
+
+static bool ec_trigger __read_mostly;
+module_param(ec_trigger, bool, 0444);
+MODULE_PARM_DESC(ec_trigger, "Enable EC triggering work-around to force emitting tablet mode events");
+
+static const struct dmi_system_id ec_trigger_quirk_dmi_table[] = {
+ {
+ /* Lenovo Yoga 7 14ARB7 */
+ .matches = {
+ DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
+ DMI_MATCH(DMI_PRODUCT_NAME, "82QF"),
+ },
+ },
+ { }
+};
+
+struct lenovo_ymc_private {
+ struct input_dev *input_dev;
+ struct acpi_device *ec_acpi_dev;
+};
+
+static void lenovo_ymc_trigger_ec(struct wmi_device *wdev, struct lenovo_ymc_private *priv)
+{
+ int err;
+
+ if (!priv->ec_acpi_dev)
+ return;
+
+ err = write_ec_cmd(priv->ec_acpi_dev->handle, VPCCMD_W_YMC, 1);
+ if (err)
+ dev_warn(&wdev->dev, "Could not write YMC: %d\n", err);
+}
+
+static const struct key_entry lenovo_ymc_keymap[] = {
+ /* Laptop */
+ { KE_SW, 0x01, { .sw = { SW_TABLET_MODE, 0 } } },
+ /* Tablet */
+ { KE_SW, 0x02, { .sw = { SW_TABLET_MODE, 1 } } },
+ /* Drawing Board */
+ { KE_SW, 0x03, { .sw = { SW_TABLET_MODE, 1 } } },
+ /* Tent */
+ { KE_SW, 0x04, { .sw = { SW_TABLET_MODE, 1 } } },
+ { KE_END },
+};
+
+static void lenovo_ymc_notify(struct wmi_device *wdev, union acpi_object *data)
+{
+ struct lenovo_ymc_private *priv = dev_get_drvdata(&wdev->dev);
+ u32 input_val = 0;
+ struct acpi_buffer input = { sizeof(input_val), &input_val };
+ struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
+ union acpi_object *obj;
+ acpi_status status;
+ int code;
+
+ status = wmi_evaluate_method(LENOVO_YMC_QUERY_GUID,
+ LENOVO_YMC_QUERY_INSTANCE,
+ LENOVO_YMC_QUERY_METHOD,
+ &input, &output);
+
+ if (ACPI_FAILURE(status)) {
+ dev_warn(&wdev->dev,
+ "Failed to evaluate query method: %s\n",
+ acpi_format_exception(status));
+ return;
+ }
+
+ obj = output.pointer;
+
+ if (obj->type != ACPI_TYPE_INTEGER) {
+ dev_warn(&wdev->dev,
+ "WMI event data is not an integer\n");
+ goto free_obj;
+ }
+ code = obj->integer.value;
+
+ if (!sparse_keymap_report_event(priv->input_dev, code, 1, true))
+ dev_warn(&wdev->dev, "Unknown key %d pressed\n", code);
+
+free_obj:
+ kfree(obj);
+ lenovo_ymc_trigger_ec(wdev, priv);
+}
+
+static void acpi_dev_put_helper(void *p) { acpi_dev_put(p); }
+
+static int lenovo_ymc_probe(struct wmi_device *wdev, const void *ctx)
+{
+ struct lenovo_ymc_private *priv;
+ struct input_dev *input_dev;
+ int err;
+
+ ec_trigger |= dmi_check_system(ec_trigger_quirk_dmi_table);
+
+ priv = devm_kzalloc(&wdev->dev, sizeof(*priv), GFP_KERNEL);
+ if (!priv)
+ return -ENOMEM;
+
+ if (ec_trigger) {
+ pr_debug("Lenovo YMC enable EC triggering.\n");
+ priv->ec_acpi_dev = acpi_dev_get_first_match_dev("VPC2004", NULL, -1);
+
+ if (!priv->ec_acpi_dev) {
+ dev_err(&wdev->dev, "Could not find EC ACPI device.\n");
+ return -ENODEV;
+ }
+ err = devm_add_action_or_reset(&wdev->dev,
+ acpi_dev_put_helper, priv->ec_acpi_dev);
+ if (err) {
+ dev_err(&wdev->dev,
+ "Could not clean up EC ACPI device: %d\n", err);
+ return err;
+ }
+ }
+
+ input_dev = devm_input_allocate_device(&wdev->dev);
+ if (!input_dev)
+ return -ENOMEM;
+
+ input_dev->name = "Lenovo Yoga Tablet Mode Control switch";
+ input_dev->phys = LENOVO_YMC_EVENT_GUID "/input0";
+ input_dev->id.bustype = BUS_HOST;
+ input_dev->dev.parent = &wdev->dev;
+ err = sparse_keymap_setup(input_dev, lenovo_ymc_keymap, NULL);
+ if (err) {
+ dev_err(&wdev->dev,
+ "Could not set up input device keymap: %d\n", err);
+ return err;
+ }
+
+ err = input_register_device(input_dev);
+ if (err) {
+ dev_err(&wdev->dev,
+ "Could not register input device: %d\n", err);
+ return err;
+ }
+
+ priv->input_dev = input_dev;
+ dev_set_drvdata(&wdev->dev, priv);
+
+ /* Report the state for the first time on probe */
+ lenovo_ymc_trigger_ec(wdev, priv);
+ lenovo_ymc_notify(wdev, NULL);
+ return 0;
+}
+
+static const struct wmi_device_id lenovo_ymc_wmi_id_table[] = {
+ { .guid_string = LENOVO_YMC_EVENT_GUID },
+ { }
+};
+MODULE_DEVICE_TABLE(wmi, lenovo_ymc_wmi_id_table);
+
+static struct wmi_driver lenovo_ymc_driver = {
+ .driver = {
+ .name = "lenovo-ymc",
+ },
+ .id_table = lenovo_ymc_wmi_id_table,
+ .probe = lenovo_ymc_probe,
+ .notify = lenovo_ymc_notify,
+};
+
+module_wmi_driver(lenovo_ymc_driver);
+
+MODULE_AUTHOR("Gergo Koteles <soyer@irl.hu>");
+MODULE_DESCRIPTION("Lenovo Yoga Mode Control driver");
+MODULE_LICENSE("GPL");
diff --git a/drivers/platform/x86/msi-ec.c b/drivers/platform/x86/msi-ec.c
new file mode 100644
index 000000000000..ff93986e3d35
--- /dev/null
+++ b/drivers/platform/x86/msi-ec.c
@@ -0,0 +1,897 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+/*
+ * msi-ec: MSI laptops' embedded controller driver.
+ *
+ * This driver allows various MSI laptops' functionalities to be
+ * controlled from userspace.
+ *
+ * It contains EC memory configurations for different firmware versions
+ * and exports battery charge thresholds to userspace.
+ *
+ * Copyright (C) 2023 Jose Angel Pastrana <japp0005@red.ujaen.es>
+ * Copyright (C) 2023 Aakash Singh <mail@singhaakash.dev>
+ * Copyright (C) 2023 Nikita Kravets <teackot@gmail.com>
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include "msi-ec.h"
+
+#include <acpi/battery.h>
+#include <linux/acpi.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/seq_file.h>
+#include <linux/string.h>
+
+static const char *const SM_ECO_NAME = "eco";
+static const char *const SM_COMFORT_NAME = "comfort";
+static const char *const SM_SPORT_NAME = "sport";
+static const char *const SM_TURBO_NAME = "turbo";
+
+static const char *const FM_AUTO_NAME = "auto";
+static const char *const FM_SILENT_NAME = "silent";
+static const char *const FM_BASIC_NAME = "basic";
+static const char *const FM_ADVANCED_NAME = "advanced";
+
+static const char * const ALLOWED_FW_0[] __initconst = {
+ "14C1EMS1.012",
+ "14C1EMS1.101",
+ "14C1EMS1.102",
+ NULL
+};
+
+static struct msi_ec_conf CONF0 __initdata = {
+ .allowed_fw = ALLOWED_FW_0,
+ .charge_control = {
+ .address = 0xef,
+ .offset_start = 0x8a,
+ .offset_end = 0x80,
+ .range_min = 0x8a,
+ .range_max = 0xe4,
+ },
+ .webcam = {
+ .address = 0x2e,
+ .block_address = 0x2f,
+ .bit = 1,
+ },
+ .fn_super_swap = {
+ .address = 0xbf,
+ .bit = 4,
+ },
+ .cooler_boost = {
+ .address = 0x98,
+ .bit = 7,
+ },
+ .shift_mode = {
+ .address = 0xf2,
+ .modes = {
+ { SM_ECO_NAME, 0xc2 },
+ { SM_COMFORT_NAME, 0xc1 },
+ { SM_SPORT_NAME, 0xc0 },
+ MSI_EC_MODE_NULL
+ },
+ },
+ .super_battery = {
+ .address = MSI_EC_ADDR_UNKNOWN, // 0xd5 needs testing
+ },
+ .fan_mode = {
+ .address = 0xf4,
+ .modes = {
+ { FM_AUTO_NAME, 0x0d },
+ { FM_SILENT_NAME, 0x1d },
+ { FM_BASIC_NAME, 0x4d },
+ { FM_ADVANCED_NAME, 0x8d },
+ MSI_EC_MODE_NULL
+ },
+ },
+ .cpu = {
+ .rt_temp_address = 0x68,
+ .rt_fan_speed_address = 0x71,
+ .rt_fan_speed_base_min = 0x19,
+ .rt_fan_speed_base_max = 0x37,
+ .bs_fan_speed_address = 0x89,
+ .bs_fan_speed_base_min = 0x00,
+ .bs_fan_speed_base_max = 0x0f,
+ },
+ .gpu = {
+ .rt_temp_address = 0x80,
+ .rt_fan_speed_address = 0x89,
+ },
+ .leds = {
+ .micmute_led_address = 0x2b,
+ .mute_led_address = 0x2c,
+ .bit = 2,
+ },
+ .kbd_bl = {
+ .bl_mode_address = 0x2c, // ?
+ .bl_modes = { 0x00, 0x08 }, // ?
+ .max_mode = 1, // ?
+ .bl_state_address = 0xf3,
+ .state_base_value = 0x80,
+ .max_state = 3,
+ },
+};
+
+static const char * const ALLOWED_FW_1[] __initconst = {
+ "17F2EMS1.103",
+ "17F2EMS1.104",
+ "17F2EMS1.106",
+ "17F2EMS1.107",
+ NULL
+};
+
+static struct msi_ec_conf CONF1 __initdata = {
+ .allowed_fw = ALLOWED_FW_1,
+ .charge_control = {
+ .address = 0xef,
+ .offset_start = 0x8a,
+ .offset_end = 0x80,
+ .range_min = 0x8a,
+ .range_max = 0xe4,
+ },
+ .webcam = {
+ .address = 0x2e,
+ .block_address = 0x2f,
+ .bit = 1,
+ },
+ .fn_super_swap = {
+ .address = 0xbf,
+ .bit = 4,
+ },
+ .cooler_boost = {
+ .address = 0x98,
+ .bit = 7,
+ },
+ .shift_mode = {
+ .address = 0xf2,
+ .modes = {
+ { SM_ECO_NAME, 0xc2 },
+ { SM_COMFORT_NAME, 0xc1 },
+ { SM_SPORT_NAME, 0xc0 },
+ { SM_TURBO_NAME, 0xc4 },
+ MSI_EC_MODE_NULL
+ },
+ },
+ .super_battery = {
+ .address = MSI_EC_ADDR_UNKNOWN,
+ },
+ .fan_mode = {
+ .address = 0xf4,
+ .modes = {
+ { FM_AUTO_NAME, 0x0d },
+ { FM_BASIC_NAME, 0x4d },
+ { FM_ADVANCED_NAME, 0x8d },
+ MSI_EC_MODE_NULL
+ },
+ },
+ .cpu = {
+ .rt_temp_address = 0x68,
+ .rt_fan_speed_address = 0x71,
+ .rt_fan_speed_base_min = 0x19,
+ .rt_fan_speed_base_max = 0x37,
+ .bs_fan_speed_address = 0x89,
+ .bs_fan_speed_base_min = 0x00,
+ .bs_fan_speed_base_max = 0x0f,
+ },
+ .gpu = {
+ .rt_temp_address = 0x80,
+ .rt_fan_speed_address = 0x89,
+ },
+ .leds = {
+ .micmute_led_address = 0x2b,
+ .mute_led_address = 0x2c,
+ .bit = 2,
+ },
+ .kbd_bl = {
+ .bl_mode_address = 0x2c, // ?
+ .bl_modes = { 0x00, 0x08 }, // ?
+ .max_mode = 1, // ?
+ .bl_state_address = 0xf3,
+ .state_base_value = 0x80,
+ .max_state = 3,
+ },
+};
+
+static const char * const ALLOWED_FW_2[] __initconst = {
+ "1552EMS1.118",
+ NULL
+};
+
+static struct msi_ec_conf CONF2 __initdata = {
+ .allowed_fw = ALLOWED_FW_2,
+ .charge_control = {
+ .address = 0xd7,
+ .offset_start = 0x8a,
+ .offset_end = 0x80,
+ .range_min = 0x8a,
+ .range_max = 0xe4,
+ },
+ .webcam = {
+ .address = 0x2e,
+ .block_address = 0x2f,
+ .bit = 1,
+ },
+ .fn_super_swap = {
+ .address = 0xe8,
+ .bit = 4,
+ },
+ .cooler_boost = {
+ .address = 0x98,
+ .bit = 7,
+ },
+ .shift_mode = {
+ .address = 0xf2,
+ .modes = {
+ { SM_ECO_NAME, 0xc2 },
+ { SM_COMFORT_NAME, 0xc1 },
+ { SM_SPORT_NAME, 0xc0 },
+ MSI_EC_MODE_NULL
+ },
+ },
+ .super_battery = {
+ .address = 0xeb,
+ .mask = 0x0f,
+ },
+ .fan_mode = {
+ .address = 0xd4,
+ .modes = {
+ { FM_AUTO_NAME, 0x0d },
+ { FM_SILENT_NAME, 0x1d },
+ { FM_BASIC_NAME, 0x4d },
+ { FM_ADVANCED_NAME, 0x8d },
+ MSI_EC_MODE_NULL
+ },
+ },
+ .cpu = {
+ .rt_temp_address = 0x68,
+ .rt_fan_speed_address = 0x71,
+ .rt_fan_speed_base_min = 0x19,
+ .rt_fan_speed_base_max = 0x37,
+ .bs_fan_speed_address = 0x89,
+ .bs_fan_speed_base_min = 0x00,
+ .bs_fan_speed_base_max = 0x0f,
+ },
+ .gpu = {
+ .rt_temp_address = 0x80,
+ .rt_fan_speed_address = 0x89,
+ },
+ .leds = {
+ .micmute_led_address = 0x2c,
+ .mute_led_address = 0x2d,
+ .bit = 1,
+ },
+ .kbd_bl = {
+ .bl_mode_address = 0x2c, // ?
+ .bl_modes = { 0x00, 0x08 }, // ?
+ .max_mode = 1, // ?
+ .bl_state_address = 0xd3,
+ .state_base_value = 0x80,
+ .max_state = 3,
+ },
+};
+
+static const char * const ALLOWED_FW_3[] __initconst = {
+ "1592EMS1.111",
+ "E1592IMS.10C",
+ NULL
+};
+
+static struct msi_ec_conf CONF3 __initdata = {
+ .allowed_fw = ALLOWED_FW_3,
+ .charge_control = {
+ .address = 0xef,
+ .offset_start = 0x8a,
+ .offset_end = 0x80,
+ .range_min = 0x8a,
+ .range_max = 0xe4,
+ },
+ .webcam = {
+ .address = 0x2e,
+ .block_address = 0x2f,
+ .bit = 1,
+ },
+ .fn_super_swap = {
+ .address = 0xe8,
+ .bit = 4,
+ },
+ .cooler_boost = {
+ .address = 0x98,
+ .bit = 7,
+ },
+ .shift_mode = {
+ .address = 0xd2,
+ .modes = {
+ { SM_ECO_NAME, 0xc2 },
+ { SM_COMFORT_NAME, 0xc1 },
+ { SM_SPORT_NAME, 0xc0 },
+ MSI_EC_MODE_NULL
+ },
+ },
+ .super_battery = {
+ .address = 0xeb,
+ .mask = 0x0f,
+ },
+ .fan_mode = {
+ .address = 0xd4,
+ .modes = {
+ { FM_AUTO_NAME, 0x0d },
+ { FM_SILENT_NAME, 0x1d },
+ { FM_BASIC_NAME, 0x4d },
+ { FM_ADVANCED_NAME, 0x8d },
+ MSI_EC_MODE_NULL
+ },
+ },
+ .cpu = {
+ .rt_temp_address = 0x68,
+ .rt_fan_speed_address = 0xc9,
+ .rt_fan_speed_base_min = 0x19,
+ .rt_fan_speed_base_max = 0x37,
+ .bs_fan_speed_address = 0x89, // ?
+ .bs_fan_speed_base_min = 0x00,
+ .bs_fan_speed_base_max = 0x0f,
+ },
+ .gpu = {
+ .rt_temp_address = 0x80,
+ .rt_fan_speed_address = 0x89,
+ },
+ .leds = {
+ .micmute_led_address = 0x2b,
+ .mute_led_address = 0x2c,
+ .bit = 1,
+ },
+ .kbd_bl = {
+ .bl_mode_address = 0x2c, // ?
+ .bl_modes = { 0x00, 0x08 }, // ?
+ .max_mode = 1, // ?
+ .bl_state_address = 0xd3,
+ .state_base_value = 0x80,
+ .max_state = 3,
+ },
+};
+
+static const char * const ALLOWED_FW_4[] __initconst = {
+ "16V4EMS1.114",
+ NULL
+};
+
+static struct msi_ec_conf CONF4 __initdata = {
+ .allowed_fw = ALLOWED_FW_4,
+ .charge_control = {
+ .address = 0xd7,
+ .offset_start = 0x8a,
+ .offset_end = 0x80,
+ .range_min = 0x8a,
+ .range_max = 0xe4,
+ },
+ .webcam = {
+ .address = 0x2e,
+ .block_address = 0x2f,
+ .bit = 1,
+ },
+ .fn_super_swap = {
+ .address = MSI_EC_ADDR_UNKNOWN, // supported, but unknown
+ .bit = 4,
+ },
+ .cooler_boost = {
+ .address = 0x98,
+ .bit = 7,
+ },
+ .shift_mode = {
+ .address = 0xd2,
+ .modes = {
+ { SM_ECO_NAME, 0xc2 },
+ { SM_COMFORT_NAME, 0xc1 },
+ { SM_SPORT_NAME, 0xc0 },
+ MSI_EC_MODE_NULL
+ },
+ },
+ .super_battery = { // may be supported, but address is unknown
+ .address = MSI_EC_ADDR_UNKNOWN,
+ .mask = 0x0f,
+ },
+ .fan_mode = {
+ .address = 0xd4,
+ .modes = {
+ { FM_AUTO_NAME, 0x0d },
+ { FM_SILENT_NAME, 0x1d },
+ { FM_ADVANCED_NAME, 0x8d },
+ MSI_EC_MODE_NULL
+ },
+ },
+ .cpu = {
+ .rt_temp_address = 0x68, // needs testing
+ .rt_fan_speed_address = 0x71, // needs testing
+ .rt_fan_speed_base_min = 0x19,
+ .rt_fan_speed_base_max = 0x37,
+ .bs_fan_speed_address = MSI_EC_ADDR_UNKNOWN,
+ .bs_fan_speed_base_min = 0x00,
+ .bs_fan_speed_base_max = 0x0f,
+ },
+ .gpu = {
+ .rt_temp_address = 0x80,
+ .rt_fan_speed_address = MSI_EC_ADDR_UNKNOWN,
+ },
+ .leds = {
+ .micmute_led_address = MSI_EC_ADDR_UNKNOWN,
+ .mute_led_address = MSI_EC_ADDR_UNKNOWN,
+ .bit = 1,
+ },
+ .kbd_bl = {
+ .bl_mode_address = MSI_EC_ADDR_UNKNOWN, // ?
+ .bl_modes = { 0x00, 0x08 }, // ?
+ .max_mode = 1, // ?
+ .bl_state_address = MSI_EC_ADDR_UNSUPP, // 0xd3, not functional
+ .state_base_value = 0x80,
+ .max_state = 3,
+ },
+};
+
+static const char * const ALLOWED_FW_5[] __initconst = {
+ "158LEMS1.103",
+ "158LEMS1.105",
+ "158LEMS1.106",
+ NULL
+};
+
+static struct msi_ec_conf CONF5 __initdata = {
+ .allowed_fw = ALLOWED_FW_5,
+ .charge_control = {
+ .address = 0xef,
+ .offset_start = 0x8a,
+ .offset_end = 0x80,
+ .range_min = 0x8a,
+ .range_max = 0xe4,
+ },
+ .webcam = {
+ .address = 0x2e,
+ .block_address = 0x2f,
+ .bit = 1,
+ },
+ .fn_super_swap = { // todo: reverse
+ .address = 0xbf,
+ .bit = 4,
+ },
+ .cooler_boost = {
+ .address = 0x98,
+ .bit = 7,
+ },
+ .shift_mode = {
+ .address = 0xf2,
+ .modes = {
+ { SM_ECO_NAME, 0xc2 },
+ { SM_COMFORT_NAME, 0xc1 },
+ { SM_TURBO_NAME, 0xc4 },
+ MSI_EC_MODE_NULL
+ },
+ },
+ .super_battery = { // unsupported?
+ .address = MSI_EC_ADDR_UNKNOWN,
+ .mask = 0x0f,
+ },
+ .fan_mode = {
+ .address = 0xf4,
+ .modes = {
+ { FM_AUTO_NAME, 0x0d },
+ { FM_SILENT_NAME, 0x1d },
+ { FM_ADVANCED_NAME, 0x8d },
+ MSI_EC_MODE_NULL
+ },
+ },
+ .cpu = {
+ .rt_temp_address = 0x68, // needs testing
+ .rt_fan_speed_address = 0x71, // needs testing
+ .rt_fan_speed_base_min = 0x19,
+ .rt_fan_speed_base_max = 0x37,
+ .bs_fan_speed_address = MSI_EC_ADDR_UNSUPP,
+ .bs_fan_speed_base_min = 0x00,
+ .bs_fan_speed_base_max = 0x0f,
+ },
+ .gpu = {
+ .rt_temp_address = MSI_EC_ADDR_UNKNOWN,
+ .rt_fan_speed_address = MSI_EC_ADDR_UNKNOWN,
+ },
+ .leds = {
+ .micmute_led_address = 0x2b,
+ .mute_led_address = 0x2c,
+ .bit = 2,
+ },
+ .kbd_bl = {
+ .bl_mode_address = MSI_EC_ADDR_UNKNOWN, // ?
+ .bl_modes = { 0x00, 0x08 }, // ?
+ .max_mode = 1, // ?
+ .bl_state_address = MSI_EC_ADDR_UNSUPP, // 0xf3, not functional
+ .state_base_value = 0x80,
+ .max_state = 3,
+ },
+};
+
+static const char * const ALLOWED_FW_6[] __initconst = {
+ "1542EMS1.102",
+ "1542EMS1.104",
+ NULL
+};
+
+static struct msi_ec_conf CONF6 __initdata = {
+ .allowed_fw = ALLOWED_FW_6,
+ .charge_control = {
+ .address = 0xef,
+ .offset_start = 0x8a,
+ .offset_end = 0x80,
+ .range_min = 0x8a,
+ .range_max = 0xe4,
+ },
+ .webcam = {
+ .address = 0x2e,
+ .block_address = MSI_EC_ADDR_UNSUPP,
+ .bit = 1,
+ },
+ .fn_super_swap = {
+ .address = 0xbf, // todo: reverse
+ .bit = 4,
+ },
+ .cooler_boost = {
+ .address = 0x98,
+ .bit = 7,
+ },
+ .shift_mode = {
+ .address = 0xf2,
+ .modes = {
+ { SM_ECO_NAME, 0xc2 },
+ { SM_COMFORT_NAME, 0xc1 },
+ { SM_SPORT_NAME, 0xc0 },
+ { SM_TURBO_NAME, 0xc4 },
+ MSI_EC_MODE_NULL
+ },
+ },
+ .super_battery = {
+ .address = 0xd5,
+ .mask = 0x0f,
+ },
+ .fan_mode = {
+ .address = 0xf4,
+ .modes = {
+ { FM_AUTO_NAME, 0x0d },
+ { FM_SILENT_NAME, 0x1d },
+ { FM_ADVANCED_NAME, 0x8d },
+ MSI_EC_MODE_NULL
+ },
+ },
+ .cpu = {
+ .rt_temp_address = 0x68,
+ .rt_fan_speed_address = 0xc9,
+ .rt_fan_speed_base_min = 0x19,
+ .rt_fan_speed_base_max = 0x37,
+ .bs_fan_speed_address = MSI_EC_ADDR_UNSUPP,
+ .bs_fan_speed_base_min = 0x00,
+ .bs_fan_speed_base_max = 0x0f,
+ },
+ .gpu = {
+ .rt_temp_address = 0x80,
+ .rt_fan_speed_address = MSI_EC_ADDR_UNKNOWN,
+ },
+ .leds = {
+ .micmute_led_address = MSI_EC_ADDR_UNSUPP,
+ .mute_led_address = MSI_EC_ADDR_UNSUPP,
+ .bit = 2,
+ },
+ .kbd_bl = {
+ .bl_mode_address = MSI_EC_ADDR_UNKNOWN, // ?
+ .bl_modes = { 0x00, 0x08 }, // ?
+ .max_mode = 1, // ?
+ .bl_state_address = MSI_EC_ADDR_UNSUPP, // 0xf3, not functional
+ .state_base_value = 0x80,
+ .max_state = 3,
+ },
+};
+
+static const char * const ALLOWED_FW_7[] __initconst = {
+ "17FKEMS1.108",
+ "17FKEMS1.109",
+ "17FKEMS1.10A",
+ NULL
+};
+
+static struct msi_ec_conf CONF7 __initdata = {
+ .allowed_fw = ALLOWED_FW_7,
+ .charge_control = {
+ .address = 0xef,
+ .offset_start = 0x8a,
+ .offset_end = 0x80,
+ .range_min = 0x8a,
+ .range_max = 0xe4,
+ },
+ .webcam = {
+ .address = 0x2e,
+ .block_address = MSI_EC_ADDR_UNSUPP,
+ .bit = 1,
+ },
+ .fn_super_swap = {
+ .address = 0xbf, // needs testing
+ .bit = 4,
+ },
+ .cooler_boost = {
+ .address = 0x98,
+ .bit = 7,
+ },
+ .shift_mode = {
+ .address = 0xf2,
+ .modes = {
+ { SM_ECO_NAME, 0xc2 },
+ { SM_COMFORT_NAME, 0xc1 },
+ { SM_SPORT_NAME, 0xc0 },
+ { SM_TURBO_NAME, 0xc4 },
+ MSI_EC_MODE_NULL
+ },
+ },
+ .super_battery = {
+ .address = MSI_EC_ADDR_UNKNOWN, // 0xd5 but has its own wet of modes
+ .mask = 0x0f,
+ },
+ .fan_mode = {
+ .address = 0xf4,
+ .modes = {
+ { FM_AUTO_NAME, 0x0d }, // d may not be relevant
+ { FM_SILENT_NAME, 0x1d },
+ { FM_ADVANCED_NAME, 0x8d },
+ MSI_EC_MODE_NULL
+ },
+ },
+ .cpu = {
+ .rt_temp_address = 0x68,
+ .rt_fan_speed_address = 0xc9, // needs testing
+ .rt_fan_speed_base_min = 0x19,
+ .rt_fan_speed_base_max = 0x37,
+ .bs_fan_speed_address = MSI_EC_ADDR_UNSUPP,
+ .bs_fan_speed_base_min = 0x00,
+ .bs_fan_speed_base_max = 0x0f,
+ },
+ .gpu = {
+ .rt_temp_address = MSI_EC_ADDR_UNKNOWN,
+ .rt_fan_speed_address = MSI_EC_ADDR_UNKNOWN,
+ },
+ .leds = {
+ .micmute_led_address = MSI_EC_ADDR_UNSUPP,
+ .mute_led_address = 0x2c,
+ .bit = 2,
+ },
+ .kbd_bl = {
+ .bl_mode_address = MSI_EC_ADDR_UNKNOWN, // ?
+ .bl_modes = { 0x00, 0x08 }, // ?
+ .max_mode = 1, // ?
+ .bl_state_address = 0xf3,
+ .state_base_value = 0x80,
+ .max_state = 3,
+ },
+};
+
+static struct msi_ec_conf *CONFIGS[] __initdata = {
+ &CONF0,
+ &CONF1,
+ &CONF2,
+ &CONF3,
+ &CONF4,
+ &CONF5,
+ &CONF6,
+ &CONF7,
+ NULL
+};
+
+static struct msi_ec_conf conf; // current configuration
+
+/*
+ * Helper functions
+ */
+
+static int ec_read_seq(u8 addr, u8 *buf, u8 len)
+{
+ int result;
+
+ for (u8 i = 0; i < len; i++) {
+ result = ec_read(addr + i, buf + i);
+ if (result < 0)
+ return result;
+ }
+
+ return 0;
+}
+
+static int ec_get_firmware_version(u8 buf[MSI_EC_FW_VERSION_LENGTH + 1])
+{
+ int result;
+
+ memset(buf, 0, MSI_EC_FW_VERSION_LENGTH + 1);
+ result = ec_read_seq(MSI_EC_FW_VERSION_ADDRESS,
+ buf,
+ MSI_EC_FW_VERSION_LENGTH);
+ if (result < 0)
+ return result;
+
+ return MSI_EC_FW_VERSION_LENGTH + 1;
+}
+
+/*
+ * Sysfs power_supply subsystem
+ */
+
+static ssize_t charge_control_threshold_show(u8 offset,
+ struct device *device,
+ struct device_attribute *attr,
+ char *buf)
+{
+ u8 rdata;
+ int result;
+
+ result = ec_read(conf.charge_control.address, &rdata);
+ if (result < 0)
+ return result;
+
+ return sysfs_emit(buf, "%i\n", rdata - offset);
+}
+
+static ssize_t charge_control_threshold_store(u8 offset,
+ struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ u8 wdata;
+ int result;
+
+ result = kstrtou8(buf, 10, &wdata);
+ if (result < 0)
+ return result;
+
+ wdata += offset;
+ if (wdata < conf.charge_control.range_min ||
+ wdata > conf.charge_control.range_max)
+ return -EINVAL;
+
+ result = ec_write(conf.charge_control.address, wdata);
+ if (result < 0)
+ return result;
+
+ return count;
+}
+
+static ssize_t charge_control_start_threshold_show(struct device *device,
+ struct device_attribute *attr,
+ char *buf)
+{
+ return charge_control_threshold_show(conf.charge_control.offset_start,
+ device, attr, buf);
+}
+
+static ssize_t charge_control_start_threshold_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ return charge_control_threshold_store(conf.charge_control.offset_start,
+ dev, attr, buf, count);
+}
+
+static ssize_t charge_control_end_threshold_show(struct device *device,
+ struct device_attribute *attr,
+ char *buf)
+{
+ return charge_control_threshold_show(conf.charge_control.offset_end,
+ device, attr, buf);
+}
+
+static ssize_t charge_control_end_threshold_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ return charge_control_threshold_store(conf.charge_control.offset_end,
+ dev, attr, buf, count);
+}
+
+static DEVICE_ATTR_RW(charge_control_start_threshold);
+static DEVICE_ATTR_RW(charge_control_end_threshold);
+
+static struct attribute *msi_battery_attrs[] = {
+ &dev_attr_charge_control_start_threshold.attr,
+ &dev_attr_charge_control_end_threshold.attr,
+ NULL
+};
+
+ATTRIBUTE_GROUPS(msi_battery);
+
+static int msi_battery_add(struct power_supply *battery,
+ struct acpi_battery_hook *hook)
+{
+ return device_add_groups(&battery->dev, msi_battery_groups);
+}
+
+static int msi_battery_remove(struct power_supply *battery,
+ struct acpi_battery_hook *hook)
+{
+ device_remove_groups(&battery->dev, msi_battery_groups);
+ return 0;
+}
+
+static struct acpi_battery_hook battery_hook = {
+ .add_battery = msi_battery_add,
+ .remove_battery = msi_battery_remove,
+ .name = MSI_EC_DRIVER_NAME,
+};
+
+/*
+ * Module load/unload
+ */
+
+static const struct dmi_system_id msi_dmi_table[] __initconst __maybe_unused = {
+ {
+ .matches = {
+ DMI_MATCH(DMI_SYS_VENDOR, "MICRO-STAR INT"),
+ },
+ },
+ {
+ .matches = {
+ DMI_MATCH(DMI_SYS_VENDOR, "Micro-Star International"),
+ },
+ },
+ {}
+};
+MODULE_DEVICE_TABLE(dmi, msi_dmi_table);
+
+static int __init load_configuration(void)
+{
+ int result;
+
+ u8 fw_version[MSI_EC_FW_VERSION_LENGTH + 1];
+
+ /* get firmware version */
+ result = ec_get_firmware_version(fw_version);
+ if (result < 0)
+ return result;
+
+ /* load the suitable configuration, if exists */
+ for (int i = 0; CONFIGS[i]; i++) {
+ if (match_string(CONFIGS[i]->allowed_fw, -1, fw_version) != -EINVAL) {
+ conf = *CONFIGS[i];
+ conf.allowed_fw = NULL;
+ return 0;
+ }
+ }
+
+ /* config not found */
+
+ for (int i = 0; i < MSI_EC_FW_VERSION_LENGTH; i++) {
+ if (!isgraph(fw_version[i])) {
+ pr_warn("Unable to find a valid firmware version!\n");
+ return -EOPNOTSUPP;
+ }
+ }
+
+ pr_warn("Firmware version is not supported: '%s'\n", fw_version);
+ return -EOPNOTSUPP;
+}
+
+static int __init msi_ec_init(void)
+{
+ int result;
+
+ result = load_configuration();
+ if (result < 0)
+ return result;
+
+ battery_hook_register(&battery_hook);
+ return 0;
+}
+
+static void __exit msi_ec_exit(void)
+{
+ battery_hook_unregister(&battery_hook);
+}
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Jose Angel Pastrana <japp0005@red.ujaen.es>");
+MODULE_AUTHOR("Aakash Singh <mail@singhaakash.dev>");
+MODULE_AUTHOR("Nikita Kravets <teackot@gmail.com>");
+MODULE_DESCRIPTION("MSI Embedded Controller");
+
+module_init(msi_ec_init);
+module_exit(msi_ec_exit);
diff --git a/drivers/platform/x86/msi-ec.h b/drivers/platform/x86/msi-ec.h
new file mode 100644
index 000000000000..be3533dc9cc6
--- /dev/null
+++ b/drivers/platform/x86/msi-ec.h
@@ -0,0 +1,122 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+/*
+ * msi-ec: MSI laptops' embedded controller driver.
+ *
+ * Copyright (C) 2023 Jose Angel Pastrana <japp0005@red.ujaen.es>
+ * Copyright (C) 2023 Aakash Singh <mail@singhaakash.dev>
+ * Copyright (C) 2023 Nikita Kravets <teackot@gmail.com>
+ */
+
+#ifndef _MSI_EC_H_
+#define _MSI_EC_H_
+
+#include <linux/types.h>
+
+#define MSI_EC_DRIVER_NAME "msi-ec"
+
+#define MSI_EC_ADDR_UNKNOWN 0xff01 // unknown address
+#define MSI_EC_ADDR_UNSUPP 0xff01 // unsupported parameter
+
+// Firmware info addresses are universal
+#define MSI_EC_FW_VERSION_ADDRESS 0xa0
+#define MSI_EC_FW_DATE_ADDRESS 0xac
+#define MSI_EC_FW_TIME_ADDRESS 0xb4
+#define MSI_EC_FW_VERSION_LENGTH 12
+#define MSI_EC_FW_DATE_LENGTH 8
+#define MSI_EC_FW_TIME_LENGTH 8
+
+struct msi_ec_charge_control_conf {
+ int address;
+ int offset_start;
+ int offset_end;
+ int range_min;
+ int range_max;
+};
+
+struct msi_ec_webcam_conf {
+ int address;
+ int block_address;
+ int bit;
+};
+
+struct msi_ec_fn_super_swap_conf {
+ int address;
+ int bit;
+};
+
+struct msi_ec_cooler_boost_conf {
+ int address;
+ int bit;
+};
+
+#define MSI_EC_MODE_NULL { NULL, 0 }
+struct msi_ec_mode {
+ const char *name;
+ int value;
+};
+
+struct msi_ec_shift_mode_conf {
+ int address;
+ struct msi_ec_mode modes[5]; // fixed size for easier hard coding
+};
+
+struct msi_ec_super_battery_conf {
+ int address;
+ int mask;
+};
+
+struct msi_ec_fan_mode_conf {
+ int address;
+ struct msi_ec_mode modes[5]; // fixed size for easier hard coding
+};
+
+struct msi_ec_cpu_conf {
+ int rt_temp_address;
+ int rt_fan_speed_address; // realtime
+ int rt_fan_speed_base_min;
+ int rt_fan_speed_base_max;
+ int bs_fan_speed_address; // basic
+ int bs_fan_speed_base_min;
+ int bs_fan_speed_base_max;
+};
+
+struct msi_ec_gpu_conf {
+ int rt_temp_address;
+ int rt_fan_speed_address; // realtime
+};
+
+struct msi_ec_led_conf {
+ int micmute_led_address;
+ int mute_led_address;
+ int bit;
+};
+
+#define MSI_EC_KBD_BL_STATE_MASK 0x3
+struct msi_ec_kbd_bl_conf {
+ int bl_mode_address;
+ int bl_modes[2];
+ int max_mode;
+
+ int bl_state_address;
+ int state_base_value;
+ int max_state;
+};
+
+struct msi_ec_conf {
+ const char * const *allowed_fw;
+
+ struct msi_ec_charge_control_conf charge_control;
+ struct msi_ec_webcam_conf webcam;
+ struct msi_ec_fn_super_swap_conf fn_super_swap;
+ struct msi_ec_cooler_boost_conf cooler_boost;
+ struct msi_ec_shift_mode_conf shift_mode;
+ struct msi_ec_super_battery_conf super_battery;
+ struct msi_ec_fan_mode_conf fan_mode;
+ struct msi_ec_cpu_conf cpu;
+ struct msi_ec_gpu_conf gpu;
+ struct msi_ec_led_conf leds;
+ struct msi_ec_kbd_bl_conf kbd_bl;
+};
+
+#endif // _MSI_EC_H_
diff --git a/drivers/platform/x86/pcengines-apuv2.c b/drivers/platform/x86/pcengines-apuv2.c
index d063d91db9bc..3aa63b18a2e1 100644
--- a/drivers/platform/x86/pcengines-apuv2.c
+++ b/drivers/platform/x86/pcengines-apuv2.c
@@ -291,5 +291,4 @@ MODULE_AUTHOR("Enrico Weigelt, metux IT consult <info@metux.net>");
MODULE_DESCRIPTION("PC Engines APUv2/APUv3 board GPIO/LEDs/keys driver");
MODULE_LICENSE("GPL");
MODULE_DEVICE_TABLE(dmi, apu_gpio_dmi_table);
-MODULE_ALIAS("platform:pcengines-apuv2");
MODULE_SOFTDEP("pre: platform:" AMD_FCH_GPIO_DRIVER_NAME " platform:leds-gpio platform:gpio_keys_polled");
diff --git a/drivers/platform/x86/peaq-wmi.c b/drivers/platform/x86/peaq-wmi.c
deleted file mode 100644
index cf9c44c20a82..000000000000
--- a/drivers/platform/x86/peaq-wmi.c
+++ /dev/null
@@ -1,128 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-only
-/*
- * PEAQ 2-in-1 WMI hotkey driver
- * Copyright (C) 2017 Hans de Goede <hdegoede@redhat.com>
- */
-
-#include <linux/acpi.h>
-#include <linux/dmi.h>
-#include <linux/input.h>
-#include <linux/kernel.h>
-#include <linux/module.h>
-
-#define PEAQ_DOLBY_BUTTON_GUID "ABBC0F6F-8EA1-11D1-00A0-C90629100000"
-#define PEAQ_DOLBY_BUTTON_METHOD_ID 5
-#define PEAQ_POLL_INTERVAL_MS 250
-#define PEAQ_POLL_IGNORE_MS 500
-#define PEAQ_POLL_MAX_MS 1000
-
-MODULE_ALIAS("wmi:"PEAQ_DOLBY_BUTTON_GUID);
-
-static struct input_dev *peaq_poll_dev;
-
-/*
- * The Dolby button (yes really a Dolby button) causes an ACPI variable to get
- * set on both press and release. The WMI method checks and clears that flag.
- * So for a press + release we will get back One from the WMI method either once
- * (if polling after the release) or twice (polling between press and release).
- * We ignore events for 0.5s after the first event to avoid reporting 2 presses.
- */
-static void peaq_wmi_poll(struct input_dev *input_dev)
-{
- static unsigned long last_event_time;
- static bool had_events;
- union acpi_object obj;
- acpi_status status;
- u32 dummy = 0;
-
- struct acpi_buffer input = { sizeof(dummy), &dummy };
- struct acpi_buffer output = { sizeof(obj), &obj };
-
- status = wmi_evaluate_method(PEAQ_DOLBY_BUTTON_GUID, 0,
- PEAQ_DOLBY_BUTTON_METHOD_ID,
- &input, &output);
- if (ACPI_FAILURE(status))
- return;
-
- if (obj.type != ACPI_TYPE_INTEGER) {
- dev_err(&input_dev->dev,
- "Error WMBC did not return an integer\n");
- return;
- }
-
- if (!obj.integer.value)
- return;
-
- if (had_events && time_before(jiffies, last_event_time +
- msecs_to_jiffies(PEAQ_POLL_IGNORE_MS)))
- return;
-
- input_event(input_dev, EV_KEY, KEY_SOUND, 1);
- input_sync(input_dev);
- input_event(input_dev, EV_KEY, KEY_SOUND, 0);
- input_sync(input_dev);
-
- last_event_time = jiffies;
- had_events = true;
-}
-
-/* Some other devices (Shuttle XS35) use the same WMI GUID for other purposes */
-static const struct dmi_system_id peaq_dmi_table[] __initconst = {
- {
- .matches = {
- DMI_MATCH(DMI_SYS_VENDOR, "PEAQ"),
- DMI_MATCH(DMI_PRODUCT_NAME, "PEAQ PMM C1010 MD99187"),
- },
- },
- {}
-};
-
-static int __init peaq_wmi_init(void)
-{
- int err;
-
- /* WMI GUID is not unique, also check for a DMI match */
- if (!dmi_check_system(peaq_dmi_table))
- return -ENODEV;
-
- if (!wmi_has_guid(PEAQ_DOLBY_BUTTON_GUID))
- return -ENODEV;
-
- peaq_poll_dev = input_allocate_device();
- if (!peaq_poll_dev)
- return -ENOMEM;
-
- peaq_poll_dev->name = "PEAQ WMI hotkeys";
- peaq_poll_dev->phys = "wmi/input0";
- peaq_poll_dev->id.bustype = BUS_HOST;
- input_set_capability(peaq_poll_dev, EV_KEY, KEY_SOUND);
-
- err = input_setup_polling(peaq_poll_dev, peaq_wmi_poll);
- if (err)
- goto err_out;
-
- input_set_poll_interval(peaq_poll_dev, PEAQ_POLL_INTERVAL_MS);
- input_set_max_poll_interval(peaq_poll_dev, PEAQ_POLL_MAX_MS);
-
- err = input_register_device(peaq_poll_dev);
- if (err)
- goto err_out;
-
- return 0;
-
-err_out:
- input_free_device(peaq_poll_dev);
- return err;
-}
-
-static void __exit peaq_wmi_exit(void)
-{
- input_unregister_device(peaq_poll_dev);
-}
-
-module_init(peaq_wmi_init);
-module_exit(peaq_wmi_exit);
-
-MODULE_DESCRIPTION("PEAQ 2-in-1 WMI hotkey driver");
-MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>");
-MODULE_LICENSE("GPL");
diff --git a/drivers/platform/x86/samsung-q10.c b/drivers/platform/x86/samsung-q10.c
index 6eb08b539311..134e2c3d91ca 100644
--- a/drivers/platform/x86/samsung-q10.c
+++ b/drivers/platform/x86/samsung-q10.c
@@ -65,14 +65,12 @@ static int samsungq10_probe(struct platform_device *pdev)
return 0;
}
-static int samsungq10_remove(struct platform_device *pdev)
+static void samsungq10_remove(struct platform_device *pdev)
{
struct backlight_device *bd = platform_get_drvdata(pdev);
backlight_device_unregister(bd);
-
- return 0;
}
static struct platform_driver samsungq10_driver = {
@@ -80,7 +78,7 @@ static struct platform_driver samsungq10_driver = {
.name = KBUILD_MODNAME,
},
.probe = samsungq10_probe,
- .remove = samsungq10_remove,
+ .remove_new = samsungq10_remove,
};
static struct platform_device *samsungq10_device;
diff --git a/drivers/platform/x86/serial-multi-instantiate.c b/drivers/platform/x86/serial-multi-instantiate.c
index 5362f1a7b77c..cd25125b7923 100644
--- a/drivers/platform/x86/serial-multi-instantiate.c
+++ b/drivers/platform/x86/serial-multi-instantiate.c
@@ -265,13 +265,11 @@ static int smi_probe(struct platform_device *pdev)
}
}
-static int smi_remove(struct platform_device *pdev)
+static void smi_remove(struct platform_device *pdev)
{
struct smi *smi = platform_get_drvdata(pdev);
smi_devs_unregister(smi);
-
- return 0;
}
static const struct smi_node bsg1160_data = {
@@ -339,7 +337,7 @@ static struct platform_driver smi_driver = {
.acpi_match_table = smi_acpi_ids,
},
.probe = smi_probe,
- .remove = smi_remove,
+ .remove_new = smi_remove,
};
module_platform_driver(smi_driver);
diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
index 537d6a2d0781..9569f11dec8c 100644
--- a/drivers/platform/x86/sony-laptop.c
+++ b/drivers/platform/x86/sony-laptop.c
@@ -3287,7 +3287,7 @@ static void sony_nc_remove(struct acpi_device *device)
dprintk(SONY_NC_DRIVER_NAME " removed.\n");
}
-static const struct acpi_device_id sony_device_ids[] = {
+static const struct acpi_device_id sony_device_ids[] __maybe_unused = {
{SONY_NC_HID, 0},
{SONY_PIC_HID, 0},
{"", 0},
diff --git a/drivers/platform/x86/think-lmi.c b/drivers/platform/x86/think-lmi.c
index 78dc82bda4dd..1138f770149d 100644
--- a/drivers/platform/x86/think-lmi.c
+++ b/drivers/platform/x86/think-lmi.c
@@ -862,19 +862,18 @@ static umode_t auth_attr_is_visible(struct kobject *kobj,
struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
/* We only want to display level and index settings on HDD/NVMe */
- if ((attr == (struct attribute *)&auth_index) ||
- (attr == (struct attribute *)&auth_level)) {
+ if (attr == &auth_index.attr || attr == &auth_level.attr) {
if ((setting == tlmi_priv.pwd_hdd) || (setting == tlmi_priv.pwd_nvme))
return attr->mode;
return 0;
}
/* We only display certificates on Admin account, if supported */
- if ((attr == (struct attribute *)&auth_certificate) ||
- (attr == (struct attribute *)&auth_signature) ||
- (attr == (struct attribute *)&auth_save_signature) ||
- (attr == (struct attribute *)&auth_cert_thumb) ||
- (attr == (struct attribute *)&auth_cert_to_password)) {
+ if (attr == &auth_certificate.attr ||
+ attr == &auth_signature.attr ||
+ attr == &auth_save_signature.attr ||
+ attr == &auth_cert_thumb.attr ||
+ attr == &auth_cert_to_password.attr) {
if ((setting == tlmi_priv.pwd_admin) && tlmi_priv.certificate_support)
return attr->mode;
return 0;
@@ -1079,33 +1078,6 @@ static const struct attribute_group tlmi_attr_group = {
.attrs = tlmi_attrs,
};
-static ssize_t tlmi_attr_show(struct kobject *kobj, struct attribute *attr,
- char *buf)
-{
- struct kobj_attribute *kattr;
-
- kattr = container_of(attr, struct kobj_attribute, attr);
- if (kattr->show)
- return kattr->show(kobj, kattr, buf);
- return -EIO;
-}
-
-static ssize_t tlmi_attr_store(struct kobject *kobj, struct attribute *attr,
- const char *buf, size_t count)
-{
- struct kobj_attribute *kattr;
-
- kattr = container_of(attr, struct kobj_attribute, attr);
- if (kattr->store)
- return kattr->store(kobj, kattr, buf, count);
- return -EIO;
-}
-
-static const struct sysfs_ops tlmi_kobj_sysfs_ops = {
- .show = tlmi_attr_show,
- .store = tlmi_attr_store,
-};
-
static void tlmi_attr_setting_release(struct kobject *kobj)
{
struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
@@ -1123,12 +1095,12 @@ static void tlmi_pwd_setting_release(struct kobject *kobj)
static const struct kobj_type tlmi_attr_setting_ktype = {
.release = &tlmi_attr_setting_release,
- .sysfs_ops = &tlmi_kobj_sysfs_ops,
+ .sysfs_ops = &kobj_sysfs_ops,
};
static const struct kobj_type tlmi_pwd_setting_ktype = {
.release = &tlmi_pwd_setting_release,
- .sysfs_ops = &tlmi_kobj_sysfs_ops,
+ .sysfs_ops = &kobj_sysfs_ops,
};
static ssize_t pending_reboot_show(struct kobject *kobj, struct kobj_attribute *attr,
@@ -1385,7 +1357,6 @@ static struct tlmi_pwd_setting *tlmi_create_auth(const char *pwd_type,
static int tlmi_analyze(void)
{
- acpi_status status;
int i, ret;
if (wmi_has_guid(LENOVO_SET_BIOS_SETTINGS_GUID) &&
@@ -1422,8 +1393,8 @@ static int tlmi_analyze(void)
char *p;
tlmi_priv.setting[i] = NULL;
- status = tlmi_setting(i, &item, LENOVO_BIOS_SETTING_GUID);
- if (ACPI_FAILURE(status))
+ ret = tlmi_setting(i, &item, LENOVO_BIOS_SETTING_GUID);
+ if (ret)
break;
if (!item)
break;
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index 7191ff2625b1..6fe82f805ea8 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -11699,6 +11699,7 @@ static int __init thinkpad_acpi_module_init(void)
{
const struct dmi_system_id *dmi_id;
int ret, i;
+ acpi_object_type obj_type;
tpacpi_lifecycle = TPACPI_LIFE_INIT;
@@ -11724,6 +11725,21 @@ static int __init thinkpad_acpi_module_init(void)
TPACPI_ACPIHANDLE_INIT(ecrd);
TPACPI_ACPIHANDLE_INIT(ecwr);
+ /*
+ * Quirk: in some models (e.g. X380 Yoga), an object named ECRD
+ * exists, but it is a register, not a method.
+ */
+ if (ecrd_handle) {
+ acpi_get_type(ecrd_handle, &obj_type);
+ if (obj_type != ACPI_TYPE_METHOD)
+ ecrd_handle = NULL;
+ }
+ if (ecwr_handle) {
+ acpi_get_type(ecwr_handle, &obj_type);
+ if (obj_type != ACPI_TYPE_METHOD)
+ ecwr_handle = NULL;
+ }
+
tpacpi_wq = create_singlethread_workqueue(TPACPI_WORKQUEUE_NAME);
if (!tpacpi_wq) {
thinkpad_acpi_module_exit();
diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c
index 4fe7650dd014..d81319a502ef 100644
--- a/drivers/platform/x86/wmi.c
+++ b/drivers/platform/x86/wmi.c
@@ -1369,7 +1369,7 @@ static void acpi_wmi_notify_handler(acpi_handle handle, u32 event,
event, 0);
}
-static int acpi_wmi_remove(struct platform_device *device)
+static void acpi_wmi_remove(struct platform_device *device)
{
struct acpi_device *acpi_device = ACPI_COMPANION(&device->dev);
@@ -1379,8 +1379,6 @@ static int acpi_wmi_remove(struct platform_device *device)
ACPI_ADR_SPACE_EC, &acpi_wmi_ec_space_handler);
wmi_free_devices(acpi_device);
device_unregister(dev_get_drvdata(&device->dev));
-
- return 0;
}
static int acpi_wmi_probe(struct platform_device *device)
@@ -1468,7 +1466,7 @@ static struct platform_driver acpi_wmi_driver = {
.acpi_match_table = wmi_device_ids,
},
.probe = acpi_wmi_probe,
- .remove = acpi_wmi_remove,
+ .remove_new = acpi_wmi_remove,
};
static int __init acpi_wmi_init(void)
diff --git a/drivers/platform/x86/x86-android-tablets.c b/drivers/platform/x86/x86-android-tablets.c
deleted file mode 100644
index 111b007656fc..000000000000
--- a/drivers/platform/x86/x86-android-tablets.c
+++ /dev/null
@@ -1,1803 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0+
-/*
- * DMI based code to deal with broken DSDTs on X86 tablets which ship with
- * Android as (part of) the factory image. The factory kernels shipped on these
- * devices typically have a bunch of things hardcoded, rather than specified
- * in their DSDT.
- *
- * Copyright (C) 2021-2022 Hans de Goede <hdegoede@redhat.com>
- */
-
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-
-#include <linux/acpi.h>
-#include <linux/dmi.h>
-#include <linux/efi.h>
-#include <linux/gpio_keys.h>
-#include <linux/gpio/consumer.h>
-#include <linux/gpio/driver.h>
-#include <linux/gpio/machine.h>
-#include <linux/i2c.h>
-#include <linux/input.h>
-#include <linux/irq.h>
-#include <linux/irqdomain.h>
-#include <linux/module.h>
-#include <linux/mod_devicetable.h>
-#include <linux/pinctrl/consumer.h>
-#include <linux/pinctrl/machine.h>
-#include <linux/platform_data/lp855x.h>
-#include <linux/platform_device.h>
-#include <linux/power/bq24190_charger.h>
-#include <linux/reboot.h>
-#include <linux/rmi.h>
-#include <linux/serdev.h>
-#include <linux/spi/spi.h>
-#include <linux/string.h>
-/* For gpio_get_desc() which is EXPORT_SYMBOL_GPL() */
-#include "../../gpio/gpiolib.h"
-#include "../../gpio/gpiolib-acpi.h"
-
-/*
- * Helper code to get Linux IRQ numbers given a description of the IRQ source
- * (either IOAPIC index, or GPIO chip name + pin-number).
- */
-enum x86_acpi_irq_type {
- X86_ACPI_IRQ_TYPE_NONE,
- X86_ACPI_IRQ_TYPE_APIC,
- X86_ACPI_IRQ_TYPE_GPIOINT,
- X86_ACPI_IRQ_TYPE_PMIC,
-};
-
-struct x86_acpi_irq_data {
- char *chip; /* GPIO chip label (GPIOINT) or PMIC ACPI path (PMIC) */
- enum x86_acpi_irq_type type;
- enum irq_domain_bus_token domain;
- int index;
- int trigger; /* ACPI_EDGE_SENSITIVE / ACPI_LEVEL_SENSITIVE */
- int polarity; /* ACPI_ACTIVE_HIGH / ACPI_ACTIVE_LOW / ACPI_ACTIVE_BOTH */
-};
-
-static int gpiochip_find_match_label(struct gpio_chip *gc, void *data)
-{
- return gc->label && !strcmp(gc->label, data);
-}
-
-static int x86_android_tablet_get_gpiod(char *label, int pin, struct gpio_desc **desc)
-{
- struct gpio_desc *gpiod;
- struct gpio_chip *chip;
-
- chip = gpiochip_find(label, gpiochip_find_match_label);
- if (!chip) {
- pr_err("error cannot find GPIO chip %s\n", label);
- return -ENODEV;
- }
-
- gpiod = gpiochip_get_desc(chip, pin);
- if (IS_ERR(gpiod)) {
- pr_err("error %ld getting GPIO %s %d\n", PTR_ERR(gpiod), label, pin);
- return PTR_ERR(gpiod);
- }
-
- *desc = gpiod;
- return 0;
-}
-
-static int x86_acpi_irq_helper_get(const struct x86_acpi_irq_data *data)
-{
- struct irq_fwspec fwspec = { };
- struct irq_domain *domain;
- struct acpi_device *adev;
- struct gpio_desc *gpiod;
- unsigned int irq_type;
- acpi_handle handle;
- acpi_status status;
- int irq, ret;
-
- switch (data->type) {
- case X86_ACPI_IRQ_TYPE_APIC:
- /*
- * The DSDT may already reference the GSI in a device skipped by
- * acpi_quirk_skip_i2c_client_enumeration(). Unregister the GSI
- * to avoid EBUSY errors in this case.
- */
- acpi_unregister_gsi(data->index);
- irq = acpi_register_gsi(NULL, data->index, data->trigger, data->polarity);
- if (irq < 0)
- pr_err("error %d getting APIC IRQ %d\n", irq, data->index);
-
- return irq;
- case X86_ACPI_IRQ_TYPE_GPIOINT:
- /* Like acpi_dev_gpio_irq_get(), but without parsing ACPI resources */
- ret = x86_android_tablet_get_gpiod(data->chip, data->index, &gpiod);
- if (ret)
- return ret;
-
- irq = gpiod_to_irq(gpiod);
- if (irq < 0) {
- pr_err("error %d getting IRQ %s %d\n", irq, data->chip, data->index);
- return irq;
- }
-
- irq_type = acpi_dev_get_irq_type(data->trigger, data->polarity);
- if (irq_type != IRQ_TYPE_NONE && irq_type != irq_get_trigger_type(irq))
- irq_set_irq_type(irq, irq_type);
-
- return irq;
- case X86_ACPI_IRQ_TYPE_PMIC:
- status = acpi_get_handle(NULL, data->chip, &handle);
- if (ACPI_FAILURE(status)) {
- pr_err("error could not get %s handle\n", data->chip);
- return -ENODEV;
- }
-
- adev = acpi_fetch_acpi_dev(handle);
- if (!adev) {
- pr_err("error could not get %s adev\n", data->chip);
- return -ENODEV;
- }
-
- fwspec.fwnode = acpi_fwnode_handle(adev);
- domain = irq_find_matching_fwspec(&fwspec, data->domain);
- if (!domain) {
- pr_err("error could not find IRQ domain for %s\n", data->chip);
- return -ENODEV;
- }
-
- return irq_create_mapping(domain, data->index);
- default:
- return 0;
- }
-}
-
-struct x86_i2c_client_info {
- struct i2c_board_info board_info;
- char *adapter_path;
- struct x86_acpi_irq_data irq_data;
-};
-
-struct x86_serdev_info {
- const char *ctrl_hid;
- const char *ctrl_uid;
- const char *ctrl_devname;
- /*
- * ATM the serdev core only supports of or ACPI matching; and sofar all
- * Android x86 tablets DSDTs have usable serdev nodes, but sometimes
- * under the wrong controller. So we just tie the existing serdev ACPI
- * node to the right controller.
- */
- const char *serdev_hid;
-};
-
-struct x86_dev_info {
- char *invalid_aei_gpiochip;
- const char * const *modules;
- const struct software_node *bat_swnode;
- struct gpiod_lookup_table * const *gpiod_lookup_tables;
- const struct x86_i2c_client_info *i2c_client_info;
- const struct platform_device_info *pdev_info;
- const struct x86_serdev_info *serdev_info;
- int i2c_client_count;
- int pdev_count;
- int serdev_count;
- int (*init)(void);
- void (*exit)(void);
-};
-
-/* Generic / shared charger / battery settings */
-static const char * const tusb1211_chg_det_psy[] = { "tusb1211-charger-detect" };
-static const char * const bq24190_psy[] = { "bq24190-charger" };
-static const char * const bq25890_psy[] = { "bq25890-charger-0" };
-
-static const struct property_entry fg_bq24190_supply_props[] = {
- PROPERTY_ENTRY_STRING_ARRAY("supplied-from", bq24190_psy),
- { }
-};
-
-static const struct software_node fg_bq24190_supply_node = {
- .properties = fg_bq24190_supply_props,
-};
-
-static const struct property_entry fg_bq25890_supply_props[] = {
- PROPERTY_ENTRY_STRING_ARRAY("supplied-from", bq25890_psy),
- { }
-};
-
-static const struct software_node fg_bq25890_supply_node = {
- .properties = fg_bq25890_supply_props,
-};
-
-/* LiPo HighVoltage (max 4.35V) settings used by most devs with a HV bat. */
-static const struct property_entry generic_lipo_hv_4v35_battery_props[] = {
- PROPERTY_ENTRY_STRING("compatible", "simple-battery"),
- PROPERTY_ENTRY_STRING("device-chemistry", "lithium-ion"),
- PROPERTY_ENTRY_U32("precharge-current-microamp", 256000),
- PROPERTY_ENTRY_U32("charge-term-current-microamp", 128000),
- PROPERTY_ENTRY_U32("constant-charge-current-max-microamp", 1856000),
- PROPERTY_ENTRY_U32("constant-charge-voltage-max-microvolt", 4352000),
- PROPERTY_ENTRY_U32("factory-internal-resistance-micro-ohms", 150000),
- { }
-};
-
-static const struct software_node generic_lipo_hv_4v35_battery_node = {
- .properties = generic_lipo_hv_4v35_battery_props,
-};
-
-/* For enabling the bq24190 5V boost based on id-pin */
-static struct regulator_consumer_supply intel_int3496_consumer = {
- .supply = "vbus",
- .dev_name = "intel-int3496",
-};
-
-static const struct regulator_init_data bq24190_vbus_init_data = {
- .constraints = {
- .name = "bq24190_vbus",
- .valid_ops_mask = REGULATOR_CHANGE_STATUS,
- },
- .consumer_supplies = &intel_int3496_consumer,
- .num_consumer_supplies = 1,
-};
-
-static struct bq24190_platform_data bq24190_pdata = {
- .regulator_init_data = &bq24190_vbus_init_data,
-};
-
-static const char * const bq24190_modules[] __initconst = {
- "intel_crystal_cove_charger", /* For the bq24190 IRQ */
- "bq24190_charger", /* For the Vbus regulator for intel-int3496 */
- NULL
-};
-
-/* Generic pdevs array and gpio-lookups for micro USB ID pin handling */
-static const struct platform_device_info int3496_pdevs[] __initconst = {
- {
- /* For micro USB ID pin handling */
- .name = "intel-int3496",
- .id = PLATFORM_DEVID_NONE,
- },
-};
-
-static struct gpiod_lookup_table int3496_gpo2_pin22_gpios = {
- .dev_id = "intel-int3496",
- .table = {
- GPIO_LOOKUP("INT33FC:02", 22, "id", GPIO_ACTIVE_HIGH),
- { }
- },
-};
-
-/*
- * Advantech MICA-071
- * This is a standard Windows tablet, but it has an extra "quick launch" button
- * which is not described in the ACPI tables in anyway.
- * Use the x86-android-tablets infra to create a gpio-button device for this.
- */
-static struct gpio_keys_button advantech_mica_071_button = {
- .code = KEY_PROG1,
- /* .gpio gets filled in by advantech_mica_071_init() */
- .active_low = true,
- .desc = "prog1_key",
- .type = EV_KEY,
- .wakeup = false,
- .debounce_interval = 50,
-};
-
-static const struct gpio_keys_platform_data advantech_mica_071_button_pdata __initconst = {
- .buttons = &advantech_mica_071_button,
- .nbuttons = 1,
- .name = "prog1_key",
-};
-
-static const struct platform_device_info advantech_mica_071_pdevs[] __initconst = {
- {
- .name = "gpio-keys",
- .id = PLATFORM_DEVID_AUTO,
- .data = &advantech_mica_071_button_pdata,
- .size_data = sizeof(advantech_mica_071_button_pdata),
- },
-};
-
-static int __init advantech_mica_071_init(void)
-{
- struct gpio_desc *gpiod;
- int ret;
-
- ret = x86_android_tablet_get_gpiod("INT33FC:00", 2, &gpiod);
- if (ret < 0)
- return ret;
- advantech_mica_071_button.gpio = desc_to_gpio(gpiod);
-
- return 0;
-}
-
-static const struct x86_dev_info advantech_mica_071_info __initconst = {
- .pdev_info = advantech_mica_071_pdevs,
- .pdev_count = ARRAY_SIZE(advantech_mica_071_pdevs),
- .init = advantech_mica_071_init,
-};
-
-/* Asus ME176C and TF103C tablets shared data */
-static struct gpio_keys_button asus_me176c_tf103c_lid = {
- .code = SW_LID,
- /* .gpio gets filled in by asus_me176c_tf103c_init() */
- .active_low = true,
- .desc = "lid_sw",
- .type = EV_SW,
- .wakeup = true,
- .debounce_interval = 50,
-};
-
-static const struct gpio_keys_platform_data asus_me176c_tf103c_lid_pdata __initconst = {
- .buttons = &asus_me176c_tf103c_lid,
- .nbuttons = 1,
- .name = "lid_sw",
-};
-
-static const struct platform_device_info asus_me176c_tf103c_pdevs[] __initconst = {
- {
- .name = "gpio-keys",
- .id = PLATFORM_DEVID_AUTO,
- .data = &asus_me176c_tf103c_lid_pdata,
- .size_data = sizeof(asus_me176c_tf103c_lid_pdata),
- },
- {
- /* For micro USB ID pin handling */
- .name = "intel-int3496",
- .id = PLATFORM_DEVID_NONE,
- },
-};
-
-static int __init asus_me176c_tf103c_init(void)
-{
- struct gpio_desc *gpiod;
- int ret;
-
- ret = x86_android_tablet_get_gpiod("INT33FC:02", 12, &gpiod);
- if (ret < 0)
- return ret;
- asus_me176c_tf103c_lid.gpio = desc_to_gpio(gpiod);
-
- return 0;
-}
-
-
-/* Asus ME176C tablets have an Android factory img with everything hardcoded */
-static const char * const asus_me176c_accel_mount_matrix[] = {
- "-1", "0", "0",
- "0", "1", "0",
- "0", "0", "1"
-};
-
-static const struct property_entry asus_me176c_accel_props[] = {
- PROPERTY_ENTRY_STRING_ARRAY("mount-matrix", asus_me176c_accel_mount_matrix),
- { }
-};
-
-static const struct software_node asus_me176c_accel_node = {
- .properties = asus_me176c_accel_props,
-};
-
-static const struct property_entry asus_me176c_bq24190_props[] = {
- PROPERTY_ENTRY_STRING_ARRAY("supplied-from", tusb1211_chg_det_psy),
- PROPERTY_ENTRY_REF("monitored-battery", &generic_lipo_hv_4v35_battery_node),
- PROPERTY_ENTRY_U32("ti,system-minimum-microvolt", 3600000),
- PROPERTY_ENTRY_BOOL("omit-battery-class"),
- PROPERTY_ENTRY_BOOL("disable-reset"),
- { }
-};
-
-static const struct software_node asus_me176c_bq24190_node = {
- .properties = asus_me176c_bq24190_props,
-};
-
-static const struct property_entry asus_me176c_ug3105_props[] = {
- PROPERTY_ENTRY_STRING_ARRAY("supplied-from", bq24190_psy),
- PROPERTY_ENTRY_REF("monitored-battery", &generic_lipo_hv_4v35_battery_node),
- PROPERTY_ENTRY_U32("upisemi,rsns-microohm", 10000),
- { }
-};
-
-static const struct software_node asus_me176c_ug3105_node = {
- .properties = asus_me176c_ug3105_props,
-};
-
-static const struct x86_i2c_client_info asus_me176c_i2c_clients[] __initconst = {
- {
- /* bq24297 battery charger */
- .board_info = {
- .type = "bq24190",
- .addr = 0x6b,
- .dev_name = "bq24297",
- .swnode = &asus_me176c_bq24190_node,
- .platform_data = &bq24190_pdata,
- },
- .adapter_path = "\\_SB_.I2C1",
- .irq_data = {
- .type = X86_ACPI_IRQ_TYPE_PMIC,
- .chip = "\\_SB_.I2C7.PMIC",
- .domain = DOMAIN_BUS_WAKEUP,
- .index = 0,
- },
- }, {
- /* ug3105 battery monitor */
- .board_info = {
- .type = "ug3105",
- .addr = 0x70,
- .dev_name = "ug3105",
- .swnode = &asus_me176c_ug3105_node,
- },
- .adapter_path = "\\_SB_.I2C1",
- }, {
- /* ak09911 compass */
- .board_info = {
- .type = "ak09911",
- .addr = 0x0c,
- .dev_name = "ak09911",
- },
- .adapter_path = "\\_SB_.I2C5",
- }, {
- /* kxtj21009 accel */
- .board_info = {
- .type = "kxtj21009",
- .addr = 0x0f,
- .dev_name = "kxtj21009",
- .swnode = &asus_me176c_accel_node,
- },
- .adapter_path = "\\_SB_.I2C5",
- .irq_data = {
- .type = X86_ACPI_IRQ_TYPE_APIC,
- .index = 0x44,
- .trigger = ACPI_EDGE_SENSITIVE,
- .polarity = ACPI_ACTIVE_LOW,
- },
- }, {
- /* goodix touchscreen */
- .board_info = {
- .type = "GDIX1001:00",
- .addr = 0x14,
- .dev_name = "goodix_ts",
- },
- .adapter_path = "\\_SB_.I2C6",
- .irq_data = {
- .type = X86_ACPI_IRQ_TYPE_APIC,
- .index = 0x45,
- .trigger = ACPI_EDGE_SENSITIVE,
- .polarity = ACPI_ACTIVE_LOW,
- },
- },
-};
-
-static const struct x86_serdev_info asus_me176c_serdevs[] __initconst = {
- {
- .ctrl_hid = "80860F0A",
- .ctrl_uid = "2",
- .ctrl_devname = "serial0",
- .serdev_hid = "BCM2E3A",
- },
-};
-
-static struct gpiod_lookup_table asus_me176c_goodix_gpios = {
- .dev_id = "i2c-goodix_ts",
- .table = {
- GPIO_LOOKUP("INT33FC:00", 60, "reset", GPIO_ACTIVE_HIGH),
- GPIO_LOOKUP("INT33FC:02", 28, "irq", GPIO_ACTIVE_HIGH),
- { }
- },
-};
-
-static struct gpiod_lookup_table * const asus_me176c_gpios[] = {
- &int3496_gpo2_pin22_gpios,
- &asus_me176c_goodix_gpios,
- NULL
-};
-
-static const struct x86_dev_info asus_me176c_info __initconst = {
- .i2c_client_info = asus_me176c_i2c_clients,
- .i2c_client_count = ARRAY_SIZE(asus_me176c_i2c_clients),
- .pdev_info = asus_me176c_tf103c_pdevs,
- .pdev_count = ARRAY_SIZE(asus_me176c_tf103c_pdevs),
- .serdev_info = asus_me176c_serdevs,
- .serdev_count = ARRAY_SIZE(asus_me176c_serdevs),
- .gpiod_lookup_tables = asus_me176c_gpios,
- .bat_swnode = &generic_lipo_hv_4v35_battery_node,
- .modules = bq24190_modules,
- .invalid_aei_gpiochip = "INT33FC:02",
- .init = asus_me176c_tf103c_init,
-};
-
-/* Asus TF103C tablets have an Android factory img with everything hardcoded */
-static const char * const asus_tf103c_accel_mount_matrix[] = {
- "0", "-1", "0",
- "-1", "0", "0",
- "0", "0", "1"
-};
-
-static const struct property_entry asus_tf103c_accel_props[] = {
- PROPERTY_ENTRY_STRING_ARRAY("mount-matrix", asus_tf103c_accel_mount_matrix),
- { }
-};
-
-static const struct software_node asus_tf103c_accel_node = {
- .properties = asus_tf103c_accel_props,
-};
-
-static const struct property_entry asus_tf103c_touchscreen_props[] = {
- PROPERTY_ENTRY_STRING("compatible", "atmel,atmel_mxt_ts"),
- { }
-};
-
-static const struct software_node asus_tf103c_touchscreen_node = {
- .properties = asus_tf103c_touchscreen_props,
-};
-
-static const struct property_entry asus_tf103c_battery_props[] = {
- PROPERTY_ENTRY_STRING("compatible", "simple-battery"),
- PROPERTY_ENTRY_STRING("device-chemistry", "lithium-ion-polymer"),
- PROPERTY_ENTRY_U32("precharge-current-microamp", 256000),
- PROPERTY_ENTRY_U32("charge-term-current-microamp", 128000),
- PROPERTY_ENTRY_U32("constant-charge-current-max-microamp", 2048000),
- PROPERTY_ENTRY_U32("constant-charge-voltage-max-microvolt", 4208000),
- PROPERTY_ENTRY_U32("factory-internal-resistance-micro-ohms", 150000),
- { }
-};
-
-static const struct software_node asus_tf103c_battery_node = {
- .properties = asus_tf103c_battery_props,
-};
-
-static const struct property_entry asus_tf103c_bq24190_props[] = {
- PROPERTY_ENTRY_STRING_ARRAY("supplied-from", tusb1211_chg_det_psy),
- PROPERTY_ENTRY_REF("monitored-battery", &asus_tf103c_battery_node),
- PROPERTY_ENTRY_U32("ti,system-minimum-microvolt", 3600000),
- PROPERTY_ENTRY_BOOL("omit-battery-class"),
- PROPERTY_ENTRY_BOOL("disable-reset"),
- { }
-};
-
-static const struct software_node asus_tf103c_bq24190_node = {
- .properties = asus_tf103c_bq24190_props,
-};
-
-static const struct property_entry asus_tf103c_ug3105_props[] = {
- PROPERTY_ENTRY_STRING_ARRAY("supplied-from", bq24190_psy),
- PROPERTY_ENTRY_REF("monitored-battery", &asus_tf103c_battery_node),
- PROPERTY_ENTRY_U32("upisemi,rsns-microohm", 5000),
- { }
-};
-
-static const struct software_node asus_tf103c_ug3105_node = {
- .properties = asus_tf103c_ug3105_props,
-};
-
-static const struct x86_i2c_client_info asus_tf103c_i2c_clients[] __initconst = {
- {
- /* bq24297 battery charger */
- .board_info = {
- .type = "bq24190",
- .addr = 0x6b,
- .dev_name = "bq24297",
- .swnode = &asus_tf103c_bq24190_node,
- .platform_data = &bq24190_pdata,
- },
- .adapter_path = "\\_SB_.I2C1",
- .irq_data = {
- .type = X86_ACPI_IRQ_TYPE_PMIC,
- .chip = "\\_SB_.I2C7.PMIC",
- .domain = DOMAIN_BUS_WAKEUP,
- .index = 0,
- },
- }, {
- /* ug3105 battery monitor */
- .board_info = {
- .type = "ug3105",
- .addr = 0x70,
- .dev_name = "ug3105",
- .swnode = &asus_tf103c_ug3105_node,
- },
- .adapter_path = "\\_SB_.I2C1",
- }, {
- /* ak09911 compass */
- .board_info = {
- .type = "ak09911",
- .addr = 0x0c,
- .dev_name = "ak09911",
- },
- .adapter_path = "\\_SB_.I2C5",
- }, {
- /* kxtj21009 accel */
- .board_info = {
- .type = "kxtj21009",
- .addr = 0x0f,
- .dev_name = "kxtj21009",
- .swnode = &asus_tf103c_accel_node,
- },
- .adapter_path = "\\_SB_.I2C5",
- }, {
- /* atmel touchscreen */
- .board_info = {
- .type = "atmel_mxt_ts",
- .addr = 0x4a,
- .dev_name = "atmel_mxt_ts",
- .swnode = &asus_tf103c_touchscreen_node,
- },
- .adapter_path = "\\_SB_.I2C6",
- .irq_data = {
- .type = X86_ACPI_IRQ_TYPE_GPIOINT,
- .chip = "INT33FC:02",
- .index = 28,
- .trigger = ACPI_EDGE_SENSITIVE,
- .polarity = ACPI_ACTIVE_LOW,
- },
- },
-};
-
-static struct gpiod_lookup_table * const asus_tf103c_gpios[] = {
- &int3496_gpo2_pin22_gpios,
- NULL
-};
-
-static const struct x86_dev_info asus_tf103c_info __initconst = {
- .i2c_client_info = asus_tf103c_i2c_clients,
- .i2c_client_count = ARRAY_SIZE(asus_tf103c_i2c_clients),
- .pdev_info = asus_me176c_tf103c_pdevs,
- .pdev_count = ARRAY_SIZE(asus_me176c_tf103c_pdevs),
- .gpiod_lookup_tables = asus_tf103c_gpios,
- .bat_swnode = &asus_tf103c_battery_node,
- .modules = bq24190_modules,
- .invalid_aei_gpiochip = "INT33FC:02",
- .init = asus_me176c_tf103c_init,
-};
-
-/*
- * When booted with the BIOS set to Android mode the Chuwi Hi8 (CWI509) DSDT
- * contains a whole bunch of bogus ACPI I2C devices and is missing entries
- * for the touchscreen and the accelerometer.
- */
-static const struct property_entry chuwi_hi8_gsl1680_props[] = {
- PROPERTY_ENTRY_U32("touchscreen-size-x", 1665),
- PROPERTY_ENTRY_U32("touchscreen-size-y", 1140),
- PROPERTY_ENTRY_BOOL("touchscreen-swapped-x-y"),
- PROPERTY_ENTRY_BOOL("silead,home-button"),
- PROPERTY_ENTRY_STRING("firmware-name", "gsl1680-chuwi-hi8.fw"),
- { }
-};
-
-static const struct software_node chuwi_hi8_gsl1680_node = {
- .properties = chuwi_hi8_gsl1680_props,
-};
-
-static const char * const chuwi_hi8_mount_matrix[] = {
- "1", "0", "0",
- "0", "-1", "0",
- "0", "0", "1"
-};
-
-static const struct property_entry chuwi_hi8_bma250e_props[] = {
- PROPERTY_ENTRY_STRING_ARRAY("mount-matrix", chuwi_hi8_mount_matrix),
- { }
-};
-
-static const struct software_node chuwi_hi8_bma250e_node = {
- .properties = chuwi_hi8_bma250e_props,
-};
-
-static const struct x86_i2c_client_info chuwi_hi8_i2c_clients[] __initconst = {
- {
- /* Silead touchscreen */
- .board_info = {
- .type = "gsl1680",
- .addr = 0x40,
- .swnode = &chuwi_hi8_gsl1680_node,
- },
- .adapter_path = "\\_SB_.I2C4",
- .irq_data = {
- .type = X86_ACPI_IRQ_TYPE_APIC,
- .index = 0x44,
- .trigger = ACPI_EDGE_SENSITIVE,
- .polarity = ACPI_ACTIVE_HIGH,
- },
- }, {
- /* BMA250E accelerometer */
- .board_info = {
- .type = "bma250e",
- .addr = 0x18,
- .swnode = &chuwi_hi8_bma250e_node,
- },
- .adapter_path = "\\_SB_.I2C3",
- .irq_data = {
- .type = X86_ACPI_IRQ_TYPE_GPIOINT,
- .chip = "INT33FC:02",
- .index = 23,
- .trigger = ACPI_LEVEL_SENSITIVE,
- .polarity = ACPI_ACTIVE_HIGH,
- },
- },
-};
-
-static int __init chuwi_hi8_init(void)
-{
- /*
- * Avoid the acpi_unregister_gsi() call in x86_acpi_irq_helper_get()
- * breaking the touchscreen + logging various errors when the Windows
- * BIOS is used.
- */
- if (acpi_dev_present("MSSL0001", NULL, 1))
- return -ENODEV;
-
- return 0;
-}
-
-static const struct x86_dev_info chuwi_hi8_info __initconst = {
- .i2c_client_info = chuwi_hi8_i2c_clients,
- .i2c_client_count = ARRAY_SIZE(chuwi_hi8_i2c_clients),
- .init = chuwi_hi8_init,
-};
-
-#define CZC_EC_EXTRA_PORT 0x68
-#define CZC_EC_ANDROID_KEYS 0x63
-
-static int __init czc_p10t_init(void)
-{
- /*
- * The device boots up in "Windows 7" mode, when the home button sends a
- * Windows specific key sequence (Left Meta + D) and the second button
- * sends an unknown one while also toggling the Radio Kill Switch.
- * This is a surprising behavior when the second button is labeled "Back".
- *
- * The vendor-supplied Android-x86 build switches the device to a "Android"
- * mode by writing value 0x63 to the I/O port 0x68. This just seems to just
- * set bit 6 on address 0x96 in the EC region; switching the bit directly
- * seems to achieve the same result. It uses a "p10t_switcher" to do the
- * job. It doesn't seem to be able to do anything else, and no other use
- * of the port 0x68 is known.
- *
- * In the Android mode, the home button sends just a single scancode,
- * which can be handled in Linux userspace more reasonably and the back
- * button only sends a scancode without toggling the kill switch.
- * The scancode can then be mapped either to Back or RF Kill functionality
- * in userspace, depending on how the button is labeled on that particular
- * model.
- */
- outb(CZC_EC_ANDROID_KEYS, CZC_EC_EXTRA_PORT);
- return 0;
-}
-
-static const struct x86_dev_info czc_p10t __initconst = {
- .init = czc_p10t_init,
-};
-
-/* Lenovo Yoga Book X90F / X91F / X91L need manual instantiation of the fg client */
-static const struct x86_i2c_client_info lenovo_yogabook_x9x_i2c_clients[] __initconst = {
- {
- /* BQ27542 fuel-gauge */
- .board_info = {
- .type = "bq27542",
- .addr = 0x55,
- .dev_name = "bq27542",
- .swnode = &fg_bq25890_supply_node,
- },
- .adapter_path = "\\_SB_.PCI0.I2C1",
- },
-};
-
-static const struct x86_dev_info lenovo_yogabook_x9x_info __initconst = {
- .i2c_client_info = lenovo_yogabook_x9x_i2c_clients,
- .i2c_client_count = ARRAY_SIZE(lenovo_yogabook_x9x_i2c_clients),
-};
-
-/* Lenovo Yoga Tablet 2 1050F/L's Android factory img has everything hardcoded */
-static const struct property_entry lenovo_yoga_tab2_830_1050_bq24190_props[] = {
- PROPERTY_ENTRY_STRING_ARRAY("supplied-from", tusb1211_chg_det_psy),
- PROPERTY_ENTRY_REF("monitored-battery", &generic_lipo_hv_4v35_battery_node),
- PROPERTY_ENTRY_BOOL("omit-battery-class"),
- PROPERTY_ENTRY_BOOL("disable-reset"),
- { }
-};
-
-static const struct software_node lenovo_yoga_tab2_830_1050_bq24190_node = {
- .properties = lenovo_yoga_tab2_830_1050_bq24190_props,
-};
-
-/* This gets filled by lenovo_yoga_tab2_830_1050_init() */
-static struct rmi_device_platform_data lenovo_yoga_tab2_830_1050_rmi_pdata = { };
-
-static struct lp855x_platform_data lenovo_yoga_tab2_830_1050_lp8557_pdata = {
- .device_control = 0x86,
- .initial_brightness = 128,
-};
-
-static const struct x86_i2c_client_info lenovo_yoga_tab2_830_1050_i2c_clients[] __initconst = {
- {
- /* bq24292i battery charger */
- .board_info = {
- .type = "bq24190",
- .addr = 0x6b,
- .dev_name = "bq24292i",
- .swnode = &lenovo_yoga_tab2_830_1050_bq24190_node,
- .platform_data = &bq24190_pdata,
- },
- .adapter_path = "\\_SB_.I2C1",
- .irq_data = {
- .type = X86_ACPI_IRQ_TYPE_GPIOINT,
- .chip = "INT33FC:02",
- .index = 2,
- .trigger = ACPI_EDGE_SENSITIVE,
- .polarity = ACPI_ACTIVE_HIGH,
- },
- }, {
- /* BQ27541 fuel-gauge */
- .board_info = {
- .type = "bq27541",
- .addr = 0x55,
- .dev_name = "bq27541",
- .swnode = &fg_bq24190_supply_node,
- },
- .adapter_path = "\\_SB_.I2C1",
- }, {
- /* Synaptics RMI touchscreen */
- .board_info = {
- .type = "rmi4_i2c",
- .addr = 0x38,
- .dev_name = "rmi4_i2c",
- .platform_data = &lenovo_yoga_tab2_830_1050_rmi_pdata,
- },
- .adapter_path = "\\_SB_.I2C6",
- .irq_data = {
- .type = X86_ACPI_IRQ_TYPE_APIC,
- .index = 0x45,
- .trigger = ACPI_EDGE_SENSITIVE,
- .polarity = ACPI_ACTIVE_HIGH,
- },
- }, {
- /* LP8557 Backlight controller */
- .board_info = {
- .type = "lp8557",
- .addr = 0x2c,
- .dev_name = "lp8557",
- .platform_data = &lenovo_yoga_tab2_830_1050_lp8557_pdata,
- },
- .adapter_path = "\\_SB_.I2C3",
- },
-};
-
-static struct gpiod_lookup_table lenovo_yoga_tab2_830_1050_int3496_gpios = {
- .dev_id = "intel-int3496",
- .table = {
- GPIO_LOOKUP("INT33FC:02", 1, "mux", GPIO_ACTIVE_LOW),
- GPIO_LOOKUP("INT33FC:02", 24, "id", GPIO_ACTIVE_HIGH),
- { }
- },
-};
-
-#define LENOVO_YOGA_TAB2_830_1050_CODEC_NAME "spi-10WM5102:00"
-
-static struct gpiod_lookup_table lenovo_yoga_tab2_830_1050_codec_gpios = {
- .dev_id = LENOVO_YOGA_TAB2_830_1050_CODEC_NAME,
- .table = {
- GPIO_LOOKUP("gpio_crystalcove", 3, "reset", GPIO_ACTIVE_HIGH),
- GPIO_LOOKUP("INT33FC:01", 23, "wlf,ldoena", GPIO_ACTIVE_HIGH),
- GPIO_LOOKUP("arizona", 2, "wlf,spkvdd-ena", GPIO_ACTIVE_HIGH),
- GPIO_LOOKUP("arizona", 4, "wlf,micd-pol", GPIO_ACTIVE_LOW),
- { }
- },
-};
-
-static struct gpiod_lookup_table * const lenovo_yoga_tab2_830_1050_gpios[] = {
- &lenovo_yoga_tab2_830_1050_int3496_gpios,
- &lenovo_yoga_tab2_830_1050_codec_gpios,
- NULL
-};
-
-static int __init lenovo_yoga_tab2_830_1050_init(void);
-static void lenovo_yoga_tab2_830_1050_exit(void);
-
-static struct x86_dev_info lenovo_yoga_tab2_830_1050_info __initdata = {
- .i2c_client_info = lenovo_yoga_tab2_830_1050_i2c_clients,
- /* i2c_client_count gets set by lenovo_yoga_tab2_830_1050_init() */
- .pdev_info = int3496_pdevs,
- .pdev_count = ARRAY_SIZE(int3496_pdevs),
- .gpiod_lookup_tables = lenovo_yoga_tab2_830_1050_gpios,
- .bat_swnode = &generic_lipo_hv_4v35_battery_node,
- .modules = bq24190_modules,
- .invalid_aei_gpiochip = "INT33FC:02",
- .init = lenovo_yoga_tab2_830_1050_init,
- .exit = lenovo_yoga_tab2_830_1050_exit,
-};
-
-/*
- * The Lenovo Yoga Tablet 2 830 and 1050 (8" vs 10") versions use the same
- * mainboard, but they need some different treatment related to the display:
- * 1. The 830 uses a portrait LCD panel with a landscape touchscreen, requiring
- * the touchscreen driver to adjust the touch-coords to match the LCD.
- * 2. Both use an TI LP8557 LED backlight controller. On the 1050 the LP8557's
- * PWM input is connected to the PMIC's PWM output and everything works fine
- * with the defaults programmed into the LP8557 by the BIOS.
- * But on the 830 the LP8557's PWM input is connected to a PWM output coming
- * from the LCD panel's controller. The Android code has a hack in the i915
- * driver to write the non-standard DSI reg 0x9f with the desired backlight
- * level to set the duty-cycle of the LCD's PWM output.
- *
- * To avoid having to have a similar hack in the mainline kernel the LP8557
- * entry in lenovo_yoga_tab2_830_1050_i2c_clients instead just programs the
- * LP8557 to directly set the level, ignoring the PWM input. This means that
- * the LP8557 i2c_client should only be instantiated on the 830.
- */
-static int __init lenovo_yoga_tab2_830_1050_init_display(void)
-{
- struct gpio_desc *gpiod;
- int ret;
-
- /* Use PMIC GPIO 10 bootstrap pin to differentiate 830 vs 1050 */
- ret = x86_android_tablet_get_gpiod("gpio_crystalcove", 10, &gpiod);
- if (ret)
- return ret;
-
- ret = gpiod_get_value_cansleep(gpiod);
- if (ret) {
- pr_info("detected Lenovo Yoga Tablet 2 1050F/L\n");
- lenovo_yoga_tab2_830_1050_info.i2c_client_count =
- ARRAY_SIZE(lenovo_yoga_tab2_830_1050_i2c_clients) - 1;
- } else {
- pr_info("detected Lenovo Yoga Tablet 2 830F/L\n");
- lenovo_yoga_tab2_830_1050_rmi_pdata.sensor_pdata.axis_align.swap_axes = true;
- lenovo_yoga_tab2_830_1050_rmi_pdata.sensor_pdata.axis_align.flip_y = true;
- lenovo_yoga_tab2_830_1050_info.i2c_client_count =
- ARRAY_SIZE(lenovo_yoga_tab2_830_1050_i2c_clients);
- }
-
- return 0;
-}
-
-/* SUS (INT33FC:02) pin 6 needs to be configured as pmu_clk for the audio codec */
-static const struct pinctrl_map lenovo_yoga_tab2_830_1050_codec_pinctrl_map =
- PIN_MAP_MUX_GROUP(LENOVO_YOGA_TAB2_830_1050_CODEC_NAME, "codec_32khz_clk",
- "INT33FC:02", "pmu_clk2_grp", "pmu_clk");
-
-static struct pinctrl *lenovo_yoga_tab2_830_1050_codec_pinctrl;
-static struct sys_off_handler *lenovo_yoga_tab2_830_1050_sys_off_handler;
-
-static int __init lenovo_yoga_tab2_830_1050_init_codec(void)
-{
- struct device *codec_dev;
- struct pinctrl *pinctrl;
- int ret;
-
- codec_dev = bus_find_device_by_name(&spi_bus_type, NULL,
- LENOVO_YOGA_TAB2_830_1050_CODEC_NAME);
- if (!codec_dev) {
- pr_err("error cannot find %s device\n", LENOVO_YOGA_TAB2_830_1050_CODEC_NAME);
- return -ENODEV;
- }
-
- ret = pinctrl_register_mappings(&lenovo_yoga_tab2_830_1050_codec_pinctrl_map, 1);
- if (ret)
- goto err_put_device;
-
- pinctrl = pinctrl_get_select(codec_dev, "codec_32khz_clk");
- if (IS_ERR(pinctrl)) {
- ret = dev_err_probe(codec_dev, PTR_ERR(pinctrl), "selecting codec_32khz_clk\n");
- goto err_unregister_mappings;
- }
-
- /* We're done with the codec_dev now */
- put_device(codec_dev);
-
- lenovo_yoga_tab2_830_1050_codec_pinctrl = pinctrl;
- return 0;
-
-err_unregister_mappings:
- pinctrl_unregister_mappings(&lenovo_yoga_tab2_830_1050_codec_pinctrl_map);
-err_put_device:
- put_device(codec_dev);
- return ret;
-}
-
-/*
- * These tablet's DSDT does not set acpi_gbl_reduced_hardware, so acpi_power_off
- * gets used as pm_power_off handler. This causes "poweroff" on these tablets
- * to hang hard. Requiring pressing the powerbutton for 30 seconds *twice*
- * followed by a normal 3 second press to recover. Avoid this by doing an EFI
- * poweroff instead.
- */
-static int lenovo_yoga_tab2_830_1050_power_off(struct sys_off_data *data)
-{
- efi.reset_system(EFI_RESET_SHUTDOWN, EFI_SUCCESS, 0, NULL);
-
- return NOTIFY_DONE;
-}
-
-static int __init lenovo_yoga_tab2_830_1050_init(void)
-{
- int ret;
-
- ret = lenovo_yoga_tab2_830_1050_init_display();
- if (ret)
- return ret;
-
- ret = lenovo_yoga_tab2_830_1050_init_codec();
- if (ret)
- return ret;
-
- /* SYS_OFF_PRIO_FIRMWARE + 1 so that it runs before acpi_power_off */
- lenovo_yoga_tab2_830_1050_sys_off_handler =
- register_sys_off_handler(SYS_OFF_MODE_POWER_OFF, SYS_OFF_PRIO_FIRMWARE + 1,
- lenovo_yoga_tab2_830_1050_power_off, NULL);
- if (IS_ERR(lenovo_yoga_tab2_830_1050_sys_off_handler))
- return PTR_ERR(lenovo_yoga_tab2_830_1050_sys_off_handler);
-
- return 0;
-}
-
-static void lenovo_yoga_tab2_830_1050_exit(void)
-{
- unregister_sys_off_handler(lenovo_yoga_tab2_830_1050_sys_off_handler);
-
- if (lenovo_yoga_tab2_830_1050_codec_pinctrl) {
- pinctrl_put(lenovo_yoga_tab2_830_1050_codec_pinctrl);
- pinctrl_unregister_mappings(&lenovo_yoga_tab2_830_1050_codec_pinctrl_map);
- }
-}
-
-/* Lenovo Yoga Tab 3 Pro YT3-X90F */
-
-/*
- * There are 2 batteries, with 2 bq27500 fuel-gauges and 2 bq25892 chargers,
- * "bq25890-charger-1" is instantiated from: drivers/i2c/busses/i2c-cht-wc.c.
- */
-static const char * const lenovo_yt3_bq25892_0_suppliers[] = { "cht_wcove_pwrsrc" };
-static const char * const bq25890_1_psy[] = { "bq25890-charger-1" };
-
-static const struct property_entry fg_bq25890_1_supply_props[] = {
- PROPERTY_ENTRY_STRING_ARRAY("supplied-from", bq25890_1_psy),
- { }
-};
-
-static const struct software_node fg_bq25890_1_supply_node = {
- .properties = fg_bq25890_1_supply_props,
-};
-
-/* bq25892 charger settings for the flat lipo battery behind the screen */
-static const struct property_entry lenovo_yt3_bq25892_0_props[] = {
- PROPERTY_ENTRY_STRING_ARRAY("supplied-from", lenovo_yt3_bq25892_0_suppliers),
- PROPERTY_ENTRY_STRING("linux,power-supply-name", "bq25892-second-chrg"),
- PROPERTY_ENTRY_U32("linux,iinlim-percentage", 40),
- PROPERTY_ENTRY_BOOL("linux,skip-reset"),
- /* Values taken from Android Factory Image */
- PROPERTY_ENTRY_U32("ti,charge-current", 2048000),
- PROPERTY_ENTRY_U32("ti,battery-regulation-voltage", 4352000),
- PROPERTY_ENTRY_U32("ti,termination-current", 128000),
- PROPERTY_ENTRY_U32("ti,precharge-current", 128000),
- PROPERTY_ENTRY_U32("ti,minimum-sys-voltage", 3700000),
- PROPERTY_ENTRY_U32("ti,boost-voltage", 4998000),
- PROPERTY_ENTRY_U32("ti,boost-max-current", 500000),
- PROPERTY_ENTRY_BOOL("ti,use-ilim-pin"),
- { }
-};
-
-static const struct software_node lenovo_yt3_bq25892_0_node = {
- .properties = lenovo_yt3_bq25892_0_props,
-};
-
-static const struct x86_i2c_client_info lenovo_yt3_i2c_clients[] __initconst = {
- {
- /* bq27500 fuel-gauge for the flat lipo battery behind the screen */
- .board_info = {
- .type = "bq27500",
- .addr = 0x55,
- .dev_name = "bq27500_0",
- .swnode = &fg_bq25890_supply_node,
- },
- .adapter_path = "\\_SB_.PCI0.I2C1",
- }, {
- /* bq25892 charger for the flat lipo battery behind the screen */
- .board_info = {
- .type = "bq25892",
- .addr = 0x6b,
- .dev_name = "bq25892_0",
- .swnode = &lenovo_yt3_bq25892_0_node,
- },
- .adapter_path = "\\_SB_.PCI0.I2C1",
- .irq_data = {
- .type = X86_ACPI_IRQ_TYPE_GPIOINT,
- .chip = "INT33FF:01",
- .index = 5,
- .trigger = ACPI_EDGE_SENSITIVE,
- .polarity = ACPI_ACTIVE_LOW,
- },
- }, {
- /* bq27500 fuel-gauge for the round li-ion cells in the hinge */
- .board_info = {
- .type = "bq27500",
- .addr = 0x55,
- .dev_name = "bq27500_1",
- .swnode = &fg_bq25890_1_supply_node,
- },
- .adapter_path = "\\_SB_.PCI0.I2C2",
- }
-};
-
-static int __init lenovo_yt3_init(void)
-{
- struct gpio_desc *gpiod;
- int ret;
-
- /*
- * The "bq25892_0" charger IC has its /CE (Charge-Enable) and OTG pins
- * connected to GPIOs, rather then having them hardwired to the correct
- * values as is normally done.
- *
- * The bq25890_charger driver controls these through I2C, but this only
- * works if not overridden by the pins. Set these pins here:
- * 1. Set /CE to 0 to allow charging.
- * 2. Set OTG to 0 disable V5 boost output since the 5V boost output of
- * the main "bq25892_1" charger is used when necessary.
- */
-
- /* /CE pin */
- ret = x86_android_tablet_get_gpiod("INT33FF:02", 22, &gpiod);
- if (ret < 0)
- return ret;
-
- /*
- * The gpio_desc returned by x86_android_tablet_get_gpiod() is a "raw"
- * gpio_desc, that is there is no way to pass lookup-flags like
- * GPIO_ACTIVE_LOW. Set the GPIO to 0 here to enable charging since
- * the /CE pin is active-low, but not marked as such in the gpio_desc.
- */
- gpiod_set_value(gpiod, 0);
-
- /* OTG pin */
- ret = x86_android_tablet_get_gpiod("INT33FF:03", 19, &gpiod);
- if (ret < 0)
- return ret;
-
- gpiod_set_value(gpiod, 0);
-
- return 0;
-}
-
-static const struct x86_dev_info lenovo_yt3_info __initconst = {
- .i2c_client_info = lenovo_yt3_i2c_clients,
- .i2c_client_count = ARRAY_SIZE(lenovo_yt3_i2c_clients),
- .init = lenovo_yt3_init,
-};
-
-/* Medion Lifetab S10346 tablets have an Android factory img with everything hardcoded */
-static const char * const medion_lifetab_s10346_accel_mount_matrix[] = {
- "0", "1", "0",
- "1", "0", "0",
- "0", "0", "1"
-};
-
-static const struct property_entry medion_lifetab_s10346_accel_props[] = {
- PROPERTY_ENTRY_STRING_ARRAY("mount-matrix", medion_lifetab_s10346_accel_mount_matrix),
- { }
-};
-
-static const struct software_node medion_lifetab_s10346_accel_node = {
- .properties = medion_lifetab_s10346_accel_props,
-};
-
-/* Note the LCD panel is mounted upside down, this is correctly indicated in the VBT */
-static const struct property_entry medion_lifetab_s10346_touchscreen_props[] = {
- PROPERTY_ENTRY_BOOL("touchscreen-inverted-x"),
- PROPERTY_ENTRY_BOOL("touchscreen-swapped-x-y"),
- { }
-};
-
-static const struct software_node medion_lifetab_s10346_touchscreen_node = {
- .properties = medion_lifetab_s10346_touchscreen_props,
-};
-
-static const struct x86_i2c_client_info medion_lifetab_s10346_i2c_clients[] __initconst = {
- {
- /* kxtj21009 accel */
- .board_info = {
- .type = "kxtj21009",
- .addr = 0x0f,
- .dev_name = "kxtj21009",
- .swnode = &medion_lifetab_s10346_accel_node,
- },
- .adapter_path = "\\_SB_.I2C3",
- .irq_data = {
- .type = X86_ACPI_IRQ_TYPE_GPIOINT,
- .chip = "INT33FC:02",
- .index = 23,
- .trigger = ACPI_EDGE_SENSITIVE,
- .polarity = ACPI_ACTIVE_HIGH,
- },
- }, {
- /* goodix touchscreen */
- .board_info = {
- .type = "GDIX1001:00",
- .addr = 0x14,
- .dev_name = "goodix_ts",
- .swnode = &medion_lifetab_s10346_touchscreen_node,
- },
- .adapter_path = "\\_SB_.I2C4",
- .irq_data = {
- .type = X86_ACPI_IRQ_TYPE_APIC,
- .index = 0x44,
- .trigger = ACPI_EDGE_SENSITIVE,
- .polarity = ACPI_ACTIVE_LOW,
- },
- },
-};
-
-static struct gpiod_lookup_table medion_lifetab_s10346_goodix_gpios = {
- .dev_id = "i2c-goodix_ts",
- .table = {
- GPIO_LOOKUP("INT33FC:01", 26, "reset", GPIO_ACTIVE_HIGH),
- GPIO_LOOKUP("INT33FC:02", 3, "irq", GPIO_ACTIVE_HIGH),
- { }
- },
-};
-
-static struct gpiod_lookup_table * const medion_lifetab_s10346_gpios[] = {
- &medion_lifetab_s10346_goodix_gpios,
- NULL
-};
-
-static const struct x86_dev_info medion_lifetab_s10346_info __initconst = {
- .i2c_client_info = medion_lifetab_s10346_i2c_clients,
- .i2c_client_count = ARRAY_SIZE(medion_lifetab_s10346_i2c_clients),
- .gpiod_lookup_tables = medion_lifetab_s10346_gpios,
-};
-
-/* Nextbook Ares 8 tablets have an Android factory img with everything hardcoded */
-static const char * const nextbook_ares8_accel_mount_matrix[] = {
- "0", "-1", "0",
- "-1", "0", "0",
- "0", "0", "1"
-};
-
-static const struct property_entry nextbook_ares8_accel_props[] = {
- PROPERTY_ENTRY_STRING_ARRAY("mount-matrix", nextbook_ares8_accel_mount_matrix),
- { }
-};
-
-static const struct software_node nextbook_ares8_accel_node = {
- .properties = nextbook_ares8_accel_props,
-};
-
-static const struct property_entry nextbook_ares8_touchscreen_props[] = {
- PROPERTY_ENTRY_U32("touchscreen-size-x", 800),
- PROPERTY_ENTRY_U32("touchscreen-size-y", 1280),
- { }
-};
-
-static const struct software_node nextbook_ares8_touchscreen_node = {
- .properties = nextbook_ares8_touchscreen_props,
-};
-
-static const struct x86_i2c_client_info nextbook_ares8_i2c_clients[] __initconst = {
- {
- /* Freescale MMA8653FC accel */
- .board_info = {
- .type = "mma8653",
- .addr = 0x1d,
- .dev_name = "mma8653",
- .swnode = &nextbook_ares8_accel_node,
- },
- .adapter_path = "\\_SB_.I2C3",
- }, {
- /* FT5416DQ9 touchscreen controller */
- .board_info = {
- .type = "edt-ft5x06",
- .addr = 0x38,
- .dev_name = "ft5416",
- .swnode = &nextbook_ares8_touchscreen_node,
- },
- .adapter_path = "\\_SB_.I2C4",
- .irq_data = {
- .type = X86_ACPI_IRQ_TYPE_GPIOINT,
- .chip = "INT33FC:02",
- .index = 3,
- .trigger = ACPI_EDGE_SENSITIVE,
- .polarity = ACPI_ACTIVE_LOW,
- },
- },
-};
-
-static struct gpiod_lookup_table nextbook_ares8_int3496_gpios = {
- .dev_id = "intel-int3496",
- .table = {
- GPIO_LOOKUP("INT33FC:02", 1, "mux", GPIO_ACTIVE_HIGH),
- GPIO_LOOKUP("INT33FC:02", 18, "id", GPIO_ACTIVE_HIGH),
- { }
- },
-};
-
-static struct gpiod_lookup_table * const nextbook_ares8_gpios[] = {
- &nextbook_ares8_int3496_gpios,
- NULL
-};
-
-static const struct x86_dev_info nextbook_ares8_info __initconst = {
- .i2c_client_info = nextbook_ares8_i2c_clients,
- .i2c_client_count = ARRAY_SIZE(nextbook_ares8_i2c_clients),
- .pdev_info = int3496_pdevs,
- .pdev_count = ARRAY_SIZE(int3496_pdevs),
- .gpiod_lookup_tables = nextbook_ares8_gpios,
- .invalid_aei_gpiochip = "INT33FC:02",
-};
-
-/*
- * Whitelabel (sold as various brands) TM800A550L tablets.
- * These tablet's DSDT contains a whole bunch of bogus ACPI I2C devices
- * (removed through acpi_quirk_skip_i2c_client_enumeration()) and
- * the touchscreen fwnode has the wrong GPIOs.
- */
-static const char * const whitelabel_tm800a550l_accel_mount_matrix[] = {
- "-1", "0", "0",
- "0", "1", "0",
- "0", "0", "1"
-};
-
-static const struct property_entry whitelabel_tm800a550l_accel_props[] = {
- PROPERTY_ENTRY_STRING_ARRAY("mount-matrix", whitelabel_tm800a550l_accel_mount_matrix),
- { }
-};
-
-static const struct software_node whitelabel_tm800a550l_accel_node = {
- .properties = whitelabel_tm800a550l_accel_props,
-};
-
-static const struct property_entry whitelabel_tm800a550l_goodix_props[] = {
- PROPERTY_ENTRY_STRING("firmware-name", "gt912-tm800a550l.fw"),
- PROPERTY_ENTRY_STRING("goodix,config-name", "gt912-tm800a550l.cfg"),
- PROPERTY_ENTRY_U32("goodix,main-clk", 54),
- { }
-};
-
-static const struct software_node whitelabel_tm800a550l_goodix_node = {
- .properties = whitelabel_tm800a550l_goodix_props,
-};
-
-static const struct x86_i2c_client_info whitelabel_tm800a550l_i2c_clients[] __initconst = {
- {
- /* goodix touchscreen */
- .board_info = {
- .type = "GDIX1001:00",
- .addr = 0x14,
- .dev_name = "goodix_ts",
- .swnode = &whitelabel_tm800a550l_goodix_node,
- },
- .adapter_path = "\\_SB_.I2C2",
- .irq_data = {
- .type = X86_ACPI_IRQ_TYPE_APIC,
- .index = 0x44,
- .trigger = ACPI_EDGE_SENSITIVE,
- .polarity = ACPI_ACTIVE_HIGH,
- },
- }, {
- /* kxcj91008 accel */
- .board_info = {
- .type = "kxcj91008",
- .addr = 0x0f,
- .dev_name = "kxcj91008",
- .swnode = &whitelabel_tm800a550l_accel_node,
- },
- .adapter_path = "\\_SB_.I2C3",
- },
-};
-
-static struct gpiod_lookup_table whitelabel_tm800a550l_goodix_gpios = {
- .dev_id = "i2c-goodix_ts",
- .table = {
- GPIO_LOOKUP("INT33FC:01", 26, "reset", GPIO_ACTIVE_HIGH),
- GPIO_LOOKUP("INT33FC:02", 3, "irq", GPIO_ACTIVE_HIGH),
- { }
- },
-};
-
-static struct gpiod_lookup_table * const whitelabel_tm800a550l_gpios[] = {
- &whitelabel_tm800a550l_goodix_gpios,
- NULL
-};
-
-static const struct x86_dev_info whitelabel_tm800a550l_info __initconst = {
- .i2c_client_info = whitelabel_tm800a550l_i2c_clients,
- .i2c_client_count = ARRAY_SIZE(whitelabel_tm800a550l_i2c_clients),
- .gpiod_lookup_tables = whitelabel_tm800a550l_gpios,
-};
-
-/*
- * If the EFI bootloader is not Xiaomi's own signed Android loader, then the
- * Xiaomi Mi Pad 2 X86 tablet sets OSID in the DSDT to 1 (Windows), causing
- * a bunch of devices to be hidden.
- *
- * This takes care of instantiating the hidden devices manually.
- */
-static const struct x86_i2c_client_info xiaomi_mipad2_i2c_clients[] __initconst = {
- {
- /* BQ27520 fuel-gauge */
- .board_info = {
- .type = "bq27520",
- .addr = 0x55,
- .dev_name = "bq27520",
- .swnode = &fg_bq25890_supply_node,
- },
- .adapter_path = "\\_SB_.PCI0.I2C1",
- }, {
- /* KTD2026 RGB notification LED controller */
- .board_info = {
- .type = "ktd2026",
- .addr = 0x30,
- .dev_name = "ktd2026",
- },
- .adapter_path = "\\_SB_.PCI0.I2C3",
- },
-};
-
-static const struct x86_dev_info xiaomi_mipad2_info __initconst = {
- .i2c_client_info = xiaomi_mipad2_i2c_clients,
- .i2c_client_count = ARRAY_SIZE(xiaomi_mipad2_i2c_clients),
-};
-
-static const struct dmi_system_id x86_android_tablet_ids[] __initconst = {
- {
- /* Advantech MICA-071 */
- .matches = {
- DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Advantech"),
- DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "MICA-071"),
- },
- .driver_data = (void *)&advantech_mica_071_info,
- },
- {
- /* Asus MeMO Pad 7 ME176C */
- .matches = {
- DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
- DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "ME176C"),
- },
- .driver_data = (void *)&asus_me176c_info,
- },
- {
- /* Asus TF103C */
- .matches = {
- DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
- DMI_MATCH(DMI_PRODUCT_NAME, "TF103C"),
- },
- .driver_data = (void *)&asus_tf103c_info,
- },
- {
- /* Chuwi Hi8 (CWI509) */
- .matches = {
- DMI_MATCH(DMI_BOARD_VENDOR, "Hampoo"),
- DMI_MATCH(DMI_BOARD_NAME, "BYT-PA03C"),
- DMI_MATCH(DMI_SYS_VENDOR, "ilife"),
- DMI_MATCH(DMI_PRODUCT_NAME, "S806"),
- },
- .driver_data = (void *)&chuwi_hi8_info,
- },
- {
- /* CZC P10T */
- .ident = "CZC ODEON TPC-10 (\"P10T\")",
- .matches = {
- DMI_MATCH(DMI_SYS_VENDOR, "CZC"),
- DMI_MATCH(DMI_PRODUCT_NAME, "ODEON*TPC-10"),
- },
- .driver_data = (void *)&czc_p10t,
- },
- {
- /* CZC P10T variant */
- .ident = "ViewSonic ViewPad 10",
- .matches = {
- DMI_MATCH(DMI_SYS_VENDOR, "ViewSonic"),
- DMI_MATCH(DMI_PRODUCT_NAME, "VPAD10"),
- },
- .driver_data = (void *)&czc_p10t,
- },
- {
- /* Lenovo Yoga Book X90F / X91F / X91L */
- .matches = {
- /* Non exact match to match all versions */
- DMI_MATCH(DMI_PRODUCT_NAME, "Lenovo YB1-X9"),
- },
- .driver_data = (void *)&lenovo_yogabook_x9x_info,
- },
- {
- /*
- * Lenovo Yoga Tablet 2 830F/L or 1050F/L (The 8" and 10"
- * Lenovo Yoga Tablet 2 use the same mainboard)
- */
- .matches = {
- DMI_MATCH(DMI_SYS_VENDOR, "Intel Corp."),
- DMI_MATCH(DMI_PRODUCT_NAME, "VALLEYVIEW C0 PLATFORM"),
- DMI_MATCH(DMI_BOARD_NAME, "BYT-T FFD8"),
- /* Partial match on beginning of BIOS version */
- DMI_MATCH(DMI_BIOS_VERSION, "BLADE_21"),
- },
- .driver_data = (void *)&lenovo_yoga_tab2_830_1050_info,
- },
- {
- /* Lenovo Yoga Tab 3 Pro YT3-X90F */
- .matches = {
- DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
- DMI_MATCH(DMI_PRODUCT_NAME, "CHERRYVIEW D1 PLATFORM"),
- DMI_MATCH(DMI_PRODUCT_VERSION, "Blade3-10A-001"),
- },
- .driver_data = (void *)&lenovo_yt3_info,
- },
- {
- /* Medion Lifetab S10346 */
- .matches = {
- DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
- DMI_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
- /* Above strings are much too generic, also match on BIOS date */
- DMI_MATCH(DMI_BIOS_DATE, "10/22/2015"),
- },
- .driver_data = (void *)&medion_lifetab_s10346_info,
- },
- {
- /* Nextbook Ares 8 */
- .matches = {
- DMI_MATCH(DMI_SYS_VENDOR, "Insyde"),
- DMI_MATCH(DMI_PRODUCT_NAME, "M890BAP"),
- },
- .driver_data = (void *)&nextbook_ares8_info,
- },
- {
- /* Whitelabel (sold as various brands) TM800A550L */
- .matches = {
- DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
- DMI_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
- /* Above strings are too generic, also match on BIOS version */
- DMI_MATCH(DMI_BIOS_VERSION, "ZY-8-BI-PX4S70VTR400-X423B-005-D"),
- },
- .driver_data = (void *)&whitelabel_tm800a550l_info,
- },
- {
- /* Xiaomi Mi Pad 2 */
- .matches = {
- DMI_MATCH(DMI_SYS_VENDOR, "Xiaomi Inc"),
- DMI_MATCH(DMI_PRODUCT_NAME, "Mipad2"),
- },
- .driver_data = (void *)&xiaomi_mipad2_info,
- },
- { }
-};
-MODULE_DEVICE_TABLE(dmi, x86_android_tablet_ids);
-
-static int i2c_client_count;
-static int pdev_count;
-static int serdev_count;
-static struct i2c_client **i2c_clients;
-static struct platform_device **pdevs;
-static struct serdev_device **serdevs;
-static struct gpiod_lookup_table * const *gpiod_lookup_tables;
-static const struct software_node *bat_swnode;
-static void (*exit_handler)(void);
-
-static __init int x86_instantiate_i2c_client(const struct x86_dev_info *dev_info,
- int idx)
-{
- const struct x86_i2c_client_info *client_info = &dev_info->i2c_client_info[idx];
- struct i2c_board_info board_info = client_info->board_info;
- struct i2c_adapter *adap;
- acpi_handle handle;
- acpi_status status;
-
- board_info.irq = x86_acpi_irq_helper_get(&client_info->irq_data);
- if (board_info.irq < 0)
- return board_info.irq;
-
- status = acpi_get_handle(NULL, client_info->adapter_path, &handle);
- if (ACPI_FAILURE(status)) {
- pr_err("Error could not get %s handle\n", client_info->adapter_path);
- return -ENODEV;
- }
-
- adap = i2c_acpi_find_adapter_by_handle(handle);
- if (!adap) {
- pr_err("error could not get %s adapter\n", client_info->adapter_path);
- return -ENODEV;
- }
-
- i2c_clients[idx] = i2c_new_client_device(adap, &board_info);
- put_device(&adap->dev);
- if (IS_ERR(i2c_clients[idx]))
- return dev_err_probe(&adap->dev, PTR_ERR(i2c_clients[idx]),
- "creating I2C-client %d\n", idx);
-
- return 0;
-}
-
-static __init int x86_instantiate_serdev(const struct x86_serdev_info *info, int idx)
-{
- struct acpi_device *ctrl_adev, *serdev_adev;
- struct serdev_device *serdev;
- struct device *ctrl_dev;
- int ret = -ENODEV;
-
- ctrl_adev = acpi_dev_get_first_match_dev(info->ctrl_hid, info->ctrl_uid, -1);
- if (!ctrl_adev) {
- pr_err("error could not get %s/%s ctrl adev\n",
- info->ctrl_hid, info->ctrl_uid);
- return -ENODEV;
- }
-
- serdev_adev = acpi_dev_get_first_match_dev(info->serdev_hid, NULL, -1);
- if (!serdev_adev) {
- pr_err("error could not get %s serdev adev\n", info->serdev_hid);
- goto put_ctrl_adev;
- }
-
- /* get_first_physical_node() returns a weak ref, no need to put() it */
- ctrl_dev = acpi_get_first_physical_node(ctrl_adev);
- if (!ctrl_dev) {
- pr_err("error could not get %s/%s ctrl physical dev\n",
- info->ctrl_hid, info->ctrl_uid);
- goto put_serdev_adev;
- }
-
- /* ctrl_dev now points to the controller's parent, get the controller */
- ctrl_dev = device_find_child_by_name(ctrl_dev, info->ctrl_devname);
- if (!ctrl_dev) {
- pr_err("error could not get %s/%s %s ctrl dev\n",
- info->ctrl_hid, info->ctrl_uid, info->ctrl_devname);
- goto put_serdev_adev;
- }
-
- serdev = serdev_device_alloc(to_serdev_controller(ctrl_dev));
- if (!serdev) {
- ret = -ENOMEM;
- goto put_serdev_adev;
- }
-
- ACPI_COMPANION_SET(&serdev->dev, serdev_adev);
- acpi_device_set_enumerated(serdev_adev);
-
- ret = serdev_device_add(serdev);
- if (ret) {
- dev_err(&serdev->dev, "error %d adding serdev\n", ret);
- serdev_device_put(serdev);
- goto put_serdev_adev;
- }
-
- serdevs[idx] = serdev;
-
-put_serdev_adev:
- acpi_dev_put(serdev_adev);
-put_ctrl_adev:
- acpi_dev_put(ctrl_adev);
- return ret;
-}
-
-static void x86_android_tablet_cleanup(void)
-{
- int i;
-
- for (i = 0; i < serdev_count; i++) {
- if (serdevs[i])
- serdev_device_remove(serdevs[i]);
- }
-
- kfree(serdevs);
-
- for (i = 0; i < pdev_count; i++)
- platform_device_unregister(pdevs[i]);
-
- kfree(pdevs);
-
- for (i = 0; i < i2c_client_count; i++)
- i2c_unregister_device(i2c_clients[i]);
-
- kfree(i2c_clients);
-
- if (exit_handler)
- exit_handler();
-
- for (i = 0; gpiod_lookup_tables && gpiod_lookup_tables[i]; i++)
- gpiod_remove_lookup_table(gpiod_lookup_tables[i]);
-
- software_node_unregister(bat_swnode);
-}
-
-static __init int x86_android_tablet_init(void)
-{
- const struct x86_dev_info *dev_info;
- const struct dmi_system_id *id;
- struct gpio_chip *chip;
- int i, ret = 0;
-
- id = dmi_first_match(x86_android_tablet_ids);
- if (!id)
- return -ENODEV;
-
- dev_info = id->driver_data;
-
- /*
- * The broken DSDTs on these devices often also include broken
- * _AEI (ACPI Event Interrupt) handlers, disable these.
- */
- if (dev_info->invalid_aei_gpiochip) {
- chip = gpiochip_find(dev_info->invalid_aei_gpiochip,
- gpiochip_find_match_label);
- if (!chip) {
- pr_err("error cannot find GPIO chip %s\n", dev_info->invalid_aei_gpiochip);
- return -ENODEV;
- }
- acpi_gpiochip_free_interrupts(chip);
- }
-
- /*
- * Since this runs from module_init() it cannot use -EPROBE_DEFER,
- * instead pre-load any modules which are listed as requirements.
- */
- for (i = 0; dev_info->modules && dev_info->modules[i]; i++)
- request_module(dev_info->modules[i]);
-
- bat_swnode = dev_info->bat_swnode;
- if (bat_swnode) {
- ret = software_node_register(bat_swnode);
- if (ret)
- return ret;
- }
-
- gpiod_lookup_tables = dev_info->gpiod_lookup_tables;
- for (i = 0; gpiod_lookup_tables && gpiod_lookup_tables[i]; i++)
- gpiod_add_lookup_table(gpiod_lookup_tables[i]);
-
- if (dev_info->init) {
- ret = dev_info->init();
- if (ret < 0) {
- x86_android_tablet_cleanup();
- return ret;
- }
- exit_handler = dev_info->exit;
- }
-
- i2c_clients = kcalloc(dev_info->i2c_client_count, sizeof(*i2c_clients), GFP_KERNEL);
- if (!i2c_clients) {
- x86_android_tablet_cleanup();
- return -ENOMEM;
- }
-
- i2c_client_count = dev_info->i2c_client_count;
- for (i = 0; i < i2c_client_count; i++) {
- ret = x86_instantiate_i2c_client(dev_info, i);
- if (ret < 0) {
- x86_android_tablet_cleanup();
- return ret;
- }
- }
-
- pdevs = kcalloc(dev_info->pdev_count, sizeof(*pdevs), GFP_KERNEL);
- if (!pdevs) {
- x86_android_tablet_cleanup();
- return -ENOMEM;
- }
-
- pdev_count = dev_info->pdev_count;
- for (i = 0; i < pdev_count; i++) {
- pdevs[i] = platform_device_register_full(&dev_info->pdev_info[i]);
- if (IS_ERR(pdevs[i])) {
- x86_android_tablet_cleanup();
- return PTR_ERR(pdevs[i]);
- }
- }
-
- serdevs = kcalloc(dev_info->serdev_count, sizeof(*serdevs), GFP_KERNEL);
- if (!serdevs) {
- x86_android_tablet_cleanup();
- return -ENOMEM;
- }
-
- serdev_count = dev_info->serdev_count;
- for (i = 0; i < serdev_count; i++) {
- ret = x86_instantiate_serdev(&dev_info->serdev_info[i], i);
- if (ret < 0) {
- x86_android_tablet_cleanup();
- return ret;
- }
- }
-
- return 0;
-}
-
-module_init(x86_android_tablet_init);
-module_exit(x86_android_tablet_cleanup);
-
-MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>");
-MODULE_DESCRIPTION("X86 Android tablets DSDT fixups driver");
-MODULE_LICENSE("GPL");
diff --git a/drivers/platform/x86/x86-android-tablets/Kconfig b/drivers/platform/x86/x86-android-tablets/Kconfig
new file mode 100644
index 000000000000..6603461d4273
--- /dev/null
+++ b/drivers/platform/x86/x86-android-tablets/Kconfig
@@ -0,0 +1,21 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# X86 Android tablet support Kconfig
+#
+
+config X86_ANDROID_TABLETS
+ tristate "X86 Android tablet support"
+ depends on I2C && SPI && SERIAL_DEV_BUS && ACPI && EFI && GPIOLIB && PMIC_OPREGION
+ help
+ X86 tablets which ship with Android as (part of) the factory image
+ typically have various problems with their DSDTs. The factory kernels
+ shipped on these devices typically have device addresses and GPIOs
+ hardcoded in the kernel, rather than specified in their DSDT.
+
+ With the DSDT containing a random collection of devices which may or
+ may not actually be present. This driver contains various fixes for
+ such tablets, including instantiating kernel devices for devices which
+ are missing from the DSDT.
+
+ If you have a x86 Android tablet say Y or M here, for a generic x86
+ distro config say M here.
diff --git a/drivers/platform/x86/x86-android-tablets/Makefile b/drivers/platform/x86/x86-android-tablets/Makefile
new file mode 100644
index 000000000000..41ece5a37137
--- /dev/null
+++ b/drivers/platform/x86/x86-android-tablets/Makefile
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# X86 Android tablet support Makefile
+#
+
+obj-$(CONFIG_X86_ANDROID_TABLETS) += x86-android-tablets.o
+
+x86-android-tablets-y := core.o dmi.o shared-psy-info.o \
+ asus.o lenovo.o other.o
diff --git a/drivers/platform/x86/x86-android-tablets/asus.c b/drivers/platform/x86/x86-android-tablets/asus.c
new file mode 100644
index 000000000000..cfa038b44b43
--- /dev/null
+++ b/drivers/platform/x86/x86-android-tablets/asus.c
@@ -0,0 +1,325 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Board info for Asus X86 tablets which ship with Android as the factory image
+ * and which have broken DSDT tables. The factory kernels shipped on these
+ * devices typically have a bunch of things hardcoded, rather than specified
+ * in their DSDT.
+ *
+ * Copyright (C) 2021-2023 Hans de Goede <hdegoede@redhat.com>
+ */
+
+#include <linux/gpio/machine.h>
+#include <linux/input.h>
+#include <linux/platform_device.h>
+
+#include "shared-psy-info.h"
+#include "x86-android-tablets.h"
+
+/* Asus ME176C and TF103C tablets shared data */
+static struct gpiod_lookup_table int3496_gpo2_pin22_gpios = {
+ .dev_id = "intel-int3496",
+ .table = {
+ GPIO_LOOKUP("INT33FC:02", 22, "id", GPIO_ACTIVE_HIGH),
+ { }
+ },
+};
+
+static struct x86_gpio_button asus_me176c_tf103c_lid = {
+ .button = {
+ .code = SW_LID,
+ .active_low = true,
+ .desc = "lid_sw",
+ .type = EV_SW,
+ .wakeup = true,
+ .debounce_interval = 50,
+ },
+ .chip = "INT33FC:02",
+ .pin = 12,
+};
+
+/* Asus ME176C tablets have an Android factory img with everything hardcoded */
+static const char * const asus_me176c_accel_mount_matrix[] = {
+ "-1", "0", "0",
+ "0", "1", "0",
+ "0", "0", "1"
+};
+
+static const struct property_entry asus_me176c_accel_props[] = {
+ PROPERTY_ENTRY_STRING_ARRAY("mount-matrix", asus_me176c_accel_mount_matrix),
+ { }
+};
+
+static const struct software_node asus_me176c_accel_node = {
+ .properties = asus_me176c_accel_props,
+};
+
+static const struct property_entry asus_me176c_bq24190_props[] = {
+ PROPERTY_ENTRY_STRING_ARRAY_LEN("supplied-from", tusb1211_chg_det_psy, 1),
+ PROPERTY_ENTRY_REF("monitored-battery", &generic_lipo_hv_4v35_battery_node),
+ PROPERTY_ENTRY_U32("ti,system-minimum-microvolt", 3600000),
+ PROPERTY_ENTRY_BOOL("omit-battery-class"),
+ PROPERTY_ENTRY_BOOL("disable-reset"),
+ { }
+};
+
+static const struct software_node asus_me176c_bq24190_node = {
+ .properties = asus_me176c_bq24190_props,
+};
+
+static const struct property_entry asus_me176c_ug3105_props[] = {
+ PROPERTY_ENTRY_STRING_ARRAY_LEN("supplied-from", bq24190_psy, 1),
+ PROPERTY_ENTRY_REF("monitored-battery", &generic_lipo_hv_4v35_battery_node),
+ PROPERTY_ENTRY_U32("upisemi,rsns-microohm", 10000),
+ { }
+};
+
+static const struct software_node asus_me176c_ug3105_node = {
+ .properties = asus_me176c_ug3105_props,
+};
+
+static const struct x86_i2c_client_info asus_me176c_i2c_clients[] __initconst = {
+ {
+ /* bq24297 battery charger */
+ .board_info = {
+ .type = "bq24190",
+ .addr = 0x6b,
+ .dev_name = "bq24297",
+ .swnode = &asus_me176c_bq24190_node,
+ .platform_data = &bq24190_pdata,
+ },
+ .adapter_path = "\\_SB_.I2C1",
+ .irq_data = {
+ .type = X86_ACPI_IRQ_TYPE_PMIC,
+ .chip = "\\_SB_.I2C7.PMIC",
+ .domain = DOMAIN_BUS_WAKEUP,
+ .index = 0,
+ },
+ }, {
+ /* ug3105 battery monitor */
+ .board_info = {
+ .type = "ug3105",
+ .addr = 0x70,
+ .dev_name = "ug3105",
+ .swnode = &asus_me176c_ug3105_node,
+ },
+ .adapter_path = "\\_SB_.I2C1",
+ }, {
+ /* ak09911 compass */
+ .board_info = {
+ .type = "ak09911",
+ .addr = 0x0c,
+ .dev_name = "ak09911",
+ },
+ .adapter_path = "\\_SB_.I2C5",
+ }, {
+ /* kxtj21009 accel */
+ .board_info = {
+ .type = "kxtj21009",
+ .addr = 0x0f,
+ .dev_name = "kxtj21009",
+ .swnode = &asus_me176c_accel_node,
+ },
+ .adapter_path = "\\_SB_.I2C5",
+ .irq_data = {
+ .type = X86_ACPI_IRQ_TYPE_APIC,
+ .index = 0x44,
+ .trigger = ACPI_EDGE_SENSITIVE,
+ .polarity = ACPI_ACTIVE_LOW,
+ },
+ }, {
+ /* goodix touchscreen */
+ .board_info = {
+ .type = "GDIX1001:00",
+ .addr = 0x14,
+ .dev_name = "goodix_ts",
+ },
+ .adapter_path = "\\_SB_.I2C6",
+ .irq_data = {
+ .type = X86_ACPI_IRQ_TYPE_APIC,
+ .index = 0x45,
+ .trigger = ACPI_EDGE_SENSITIVE,
+ .polarity = ACPI_ACTIVE_LOW,
+ },
+ },
+};
+
+static const struct x86_serdev_info asus_me176c_serdevs[] __initconst = {
+ {
+ .ctrl_hid = "80860F0A",
+ .ctrl_uid = "2",
+ .ctrl_devname = "serial0",
+ .serdev_hid = "BCM2E3A",
+ },
+};
+
+static struct gpiod_lookup_table asus_me176c_goodix_gpios = {
+ .dev_id = "i2c-goodix_ts",
+ .table = {
+ GPIO_LOOKUP("INT33FC:00", 60, "reset", GPIO_ACTIVE_HIGH),
+ GPIO_LOOKUP("INT33FC:02", 28, "irq", GPIO_ACTIVE_HIGH),
+ { }
+ },
+};
+
+static struct gpiod_lookup_table * const asus_me176c_gpios[] = {
+ &int3496_gpo2_pin22_gpios,
+ &asus_me176c_goodix_gpios,
+ NULL
+};
+
+const struct x86_dev_info asus_me176c_info __initconst = {
+ .i2c_client_info = asus_me176c_i2c_clients,
+ .i2c_client_count = ARRAY_SIZE(asus_me176c_i2c_clients),
+ .pdev_info = int3496_pdevs,
+ .pdev_count = 1,
+ .serdev_info = asus_me176c_serdevs,
+ .serdev_count = ARRAY_SIZE(asus_me176c_serdevs),
+ .gpio_button = &asus_me176c_tf103c_lid,
+ .gpiod_lookup_tables = asus_me176c_gpios,
+ .bat_swnode = &generic_lipo_hv_4v35_battery_node,
+ .modules = bq24190_modules,
+ .invalid_aei_gpiochip = "INT33FC:02",
+};
+
+/* Asus TF103C tablets have an Android factory img with everything hardcoded */
+static const char * const asus_tf103c_accel_mount_matrix[] = {
+ "0", "-1", "0",
+ "-1", "0", "0",
+ "0", "0", "1"
+};
+
+static const struct property_entry asus_tf103c_accel_props[] = {
+ PROPERTY_ENTRY_STRING_ARRAY("mount-matrix", asus_tf103c_accel_mount_matrix),
+ { }
+};
+
+static const struct software_node asus_tf103c_accel_node = {
+ .properties = asus_tf103c_accel_props,
+};
+
+static const struct property_entry asus_tf103c_touchscreen_props[] = {
+ PROPERTY_ENTRY_STRING("compatible", "atmel,atmel_mxt_ts"),
+ { }
+};
+
+static const struct software_node asus_tf103c_touchscreen_node = {
+ .properties = asus_tf103c_touchscreen_props,
+};
+
+static const struct property_entry asus_tf103c_battery_props[] = {
+ PROPERTY_ENTRY_STRING("compatible", "simple-battery"),
+ PROPERTY_ENTRY_STRING("device-chemistry", "lithium-ion-polymer"),
+ PROPERTY_ENTRY_U32("precharge-current-microamp", 256000),
+ PROPERTY_ENTRY_U32("charge-term-current-microamp", 128000),
+ PROPERTY_ENTRY_U32("constant-charge-current-max-microamp", 2048000),
+ PROPERTY_ENTRY_U32("constant-charge-voltage-max-microvolt", 4208000),
+ PROPERTY_ENTRY_U32("factory-internal-resistance-micro-ohms", 150000),
+ { }
+};
+
+static const struct software_node asus_tf103c_battery_node = {
+ .properties = asus_tf103c_battery_props,
+};
+
+static const struct property_entry asus_tf103c_bq24190_props[] = {
+ PROPERTY_ENTRY_STRING_ARRAY_LEN("supplied-from", tusb1211_chg_det_psy, 1),
+ PROPERTY_ENTRY_REF("monitored-battery", &asus_tf103c_battery_node),
+ PROPERTY_ENTRY_U32("ti,system-minimum-microvolt", 3600000),
+ PROPERTY_ENTRY_BOOL("omit-battery-class"),
+ PROPERTY_ENTRY_BOOL("disable-reset"),
+ { }
+};
+
+static const struct software_node asus_tf103c_bq24190_node = {
+ .properties = asus_tf103c_bq24190_props,
+};
+
+static const struct property_entry asus_tf103c_ug3105_props[] = {
+ PROPERTY_ENTRY_STRING_ARRAY_LEN("supplied-from", bq24190_psy, 1),
+ PROPERTY_ENTRY_REF("monitored-battery", &asus_tf103c_battery_node),
+ PROPERTY_ENTRY_U32("upisemi,rsns-microohm", 5000),
+ { }
+};
+
+static const struct software_node asus_tf103c_ug3105_node = {
+ .properties = asus_tf103c_ug3105_props,
+};
+
+static const struct x86_i2c_client_info asus_tf103c_i2c_clients[] __initconst = {
+ {
+ /* bq24297 battery charger */
+ .board_info = {
+ .type = "bq24190",
+ .addr = 0x6b,
+ .dev_name = "bq24297",
+ .swnode = &asus_tf103c_bq24190_node,
+ .platform_data = &bq24190_pdata,
+ },
+ .adapter_path = "\\_SB_.I2C1",
+ .irq_data = {
+ .type = X86_ACPI_IRQ_TYPE_PMIC,
+ .chip = "\\_SB_.I2C7.PMIC",
+ .domain = DOMAIN_BUS_WAKEUP,
+ .index = 0,
+ },
+ }, {
+ /* ug3105 battery monitor */
+ .board_info = {
+ .type = "ug3105",
+ .addr = 0x70,
+ .dev_name = "ug3105",
+ .swnode = &asus_tf103c_ug3105_node,
+ },
+ .adapter_path = "\\_SB_.I2C1",
+ }, {
+ /* ak09911 compass */
+ .board_info = {
+ .type = "ak09911",
+ .addr = 0x0c,
+ .dev_name = "ak09911",
+ },
+ .adapter_path = "\\_SB_.I2C5",
+ }, {
+ /* kxtj21009 accel */
+ .board_info = {
+ .type = "kxtj21009",
+ .addr = 0x0f,
+ .dev_name = "kxtj21009",
+ .swnode = &asus_tf103c_accel_node,
+ },
+ .adapter_path = "\\_SB_.I2C5",
+ }, {
+ /* atmel touchscreen */
+ .board_info = {
+ .type = "atmel_mxt_ts",
+ .addr = 0x4a,
+ .dev_name = "atmel_mxt_ts",
+ .swnode = &asus_tf103c_touchscreen_node,
+ },
+ .adapter_path = "\\_SB_.I2C6",
+ .irq_data = {
+ .type = X86_ACPI_IRQ_TYPE_GPIOINT,
+ .chip = "INT33FC:02",
+ .index = 28,
+ .trigger = ACPI_EDGE_SENSITIVE,
+ .polarity = ACPI_ACTIVE_LOW,
+ },
+ },
+};
+
+static struct gpiod_lookup_table * const asus_tf103c_gpios[] = {
+ &int3496_gpo2_pin22_gpios,
+ NULL
+};
+
+const struct x86_dev_info asus_tf103c_info __initconst = {
+ .i2c_client_info = asus_tf103c_i2c_clients,
+ .i2c_client_count = ARRAY_SIZE(asus_tf103c_i2c_clients),
+ .pdev_info = int3496_pdevs,
+ .pdev_count = 1,
+ .gpio_button = &asus_me176c_tf103c_lid,
+ .gpiod_lookup_tables = asus_tf103c_gpios,
+ .bat_swnode = &asus_tf103c_battery_node,
+ .modules = bq24190_modules,
+ .invalid_aei_gpiochip = "INT33FC:02",
+};
diff --git a/drivers/platform/x86/x86-android-tablets/core.c b/drivers/platform/x86/x86-android-tablets/core.c
new file mode 100644
index 000000000000..245167674aa2
--- /dev/null
+++ b/drivers/platform/x86/x86-android-tablets/core.c
@@ -0,0 +1,391 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * DMI based code to deal with broken DSDTs on X86 tablets which ship with
+ * Android as (part of) the factory image. The factory kernels shipped on these
+ * devices typically have a bunch of things hardcoded, rather than specified
+ * in their DSDT.
+ *
+ * Copyright (C) 2021-2023 Hans de Goede <hdegoede@redhat.com>
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/acpi.h>
+#include <linux/dmi.h>
+#include <linux/gpio/driver.h>
+#include <linux/gpio/machine.h>
+#include <linux/irq.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/serdev.h>
+#include <linux/string.h>
+
+#include "x86-android-tablets.h"
+/* For gpiochip_get_desc() which is EXPORT_SYMBOL_GPL() */
+#include "../../../gpio/gpiolib.h"
+#include "../../../gpio/gpiolib-acpi.h"
+
+static int gpiochip_find_match_label(struct gpio_chip *gc, void *data)
+{
+ return gc->label && !strcmp(gc->label, data);
+}
+
+int x86_android_tablet_get_gpiod(const char *label, int pin, struct gpio_desc **desc)
+{
+ struct gpio_desc *gpiod;
+ struct gpio_chip *chip;
+
+ chip = gpiochip_find((void *)label, gpiochip_find_match_label);
+ if (!chip) {
+ pr_err("error cannot find GPIO chip %s\n", label);
+ return -ENODEV;
+ }
+
+ gpiod = gpiochip_get_desc(chip, pin);
+ if (IS_ERR(gpiod)) {
+ pr_err("error %ld getting GPIO %s %d\n", PTR_ERR(gpiod), label, pin);
+ return PTR_ERR(gpiod);
+ }
+
+ *desc = gpiod;
+ return 0;
+}
+
+int x86_acpi_irq_helper_get(const struct x86_acpi_irq_data *data)
+{
+ struct irq_fwspec fwspec = { };
+ struct irq_domain *domain;
+ struct acpi_device *adev;
+ struct gpio_desc *gpiod;
+ unsigned int irq_type;
+ acpi_handle handle;
+ acpi_status status;
+ int irq, ret;
+
+ switch (data->type) {
+ case X86_ACPI_IRQ_TYPE_APIC:
+ /*
+ * The DSDT may already reference the GSI in a device skipped by
+ * acpi_quirk_skip_i2c_client_enumeration(). Unregister the GSI
+ * to avoid EBUSY errors in this case.
+ */
+ acpi_unregister_gsi(data->index);
+ irq = acpi_register_gsi(NULL, data->index, data->trigger, data->polarity);
+ if (irq < 0)
+ pr_err("error %d getting APIC IRQ %d\n", irq, data->index);
+
+ return irq;
+ case X86_ACPI_IRQ_TYPE_GPIOINT:
+ /* Like acpi_dev_gpio_irq_get(), but without parsing ACPI resources */
+ ret = x86_android_tablet_get_gpiod(data->chip, data->index, &gpiod);
+ if (ret)
+ return ret;
+
+ irq = gpiod_to_irq(gpiod);
+ if (irq < 0) {
+ pr_err("error %d getting IRQ %s %d\n", irq, data->chip, data->index);
+ return irq;
+ }
+
+ irq_type = acpi_dev_get_irq_type(data->trigger, data->polarity);
+ if (irq_type != IRQ_TYPE_NONE && irq_type != irq_get_trigger_type(irq))
+ irq_set_irq_type(irq, irq_type);
+
+ return irq;
+ case X86_ACPI_IRQ_TYPE_PMIC:
+ status = acpi_get_handle(NULL, data->chip, &handle);
+ if (ACPI_FAILURE(status)) {
+ pr_err("error could not get %s handle\n", data->chip);
+ return -ENODEV;
+ }
+
+ adev = acpi_fetch_acpi_dev(handle);
+ if (!adev) {
+ pr_err("error could not get %s adev\n", data->chip);
+ return -ENODEV;
+ }
+
+ fwspec.fwnode = acpi_fwnode_handle(adev);
+ domain = irq_find_matching_fwspec(&fwspec, data->domain);
+ if (!domain) {
+ pr_err("error could not find IRQ domain for %s\n", data->chip);
+ return -ENODEV;
+ }
+
+ return irq_create_mapping(domain, data->index);
+ default:
+ return 0;
+ }
+}
+
+static int i2c_client_count;
+static int pdev_count;
+static int serdev_count;
+static struct i2c_client **i2c_clients;
+static struct platform_device **pdevs;
+static struct serdev_device **serdevs;
+static struct gpiod_lookup_table * const *gpiod_lookup_tables;
+static const struct software_node *bat_swnode;
+static void (*exit_handler)(void);
+
+static __init int x86_instantiate_i2c_client(const struct x86_dev_info *dev_info,
+ int idx)
+{
+ const struct x86_i2c_client_info *client_info = &dev_info->i2c_client_info[idx];
+ struct i2c_board_info board_info = client_info->board_info;
+ struct i2c_adapter *adap;
+ acpi_handle handle;
+ acpi_status status;
+
+ board_info.irq = x86_acpi_irq_helper_get(&client_info->irq_data);
+ if (board_info.irq < 0)
+ return board_info.irq;
+
+ status = acpi_get_handle(NULL, client_info->adapter_path, &handle);
+ if (ACPI_FAILURE(status)) {
+ pr_err("Error could not get %s handle\n", client_info->adapter_path);
+ return -ENODEV;
+ }
+
+ adap = i2c_acpi_find_adapter_by_handle(handle);
+ if (!adap) {
+ pr_err("error could not get %s adapter\n", client_info->adapter_path);
+ return -ENODEV;
+ }
+
+ i2c_clients[idx] = i2c_new_client_device(adap, &board_info);
+ put_device(&adap->dev);
+ if (IS_ERR(i2c_clients[idx]))
+ return dev_err_probe(&adap->dev, PTR_ERR(i2c_clients[idx]),
+ "creating I2C-client %d\n", idx);
+
+ return 0;
+}
+
+static __init int x86_instantiate_serdev(const struct x86_serdev_info *info, int idx)
+{
+ struct acpi_device *ctrl_adev, *serdev_adev;
+ struct serdev_device *serdev;
+ struct device *ctrl_dev;
+ int ret = -ENODEV;
+
+ ctrl_adev = acpi_dev_get_first_match_dev(info->ctrl_hid, info->ctrl_uid, -1);
+ if (!ctrl_adev) {
+ pr_err("error could not get %s/%s ctrl adev\n",
+ info->ctrl_hid, info->ctrl_uid);
+ return -ENODEV;
+ }
+
+ serdev_adev = acpi_dev_get_first_match_dev(info->serdev_hid, NULL, -1);
+ if (!serdev_adev) {
+ pr_err("error could not get %s serdev adev\n", info->serdev_hid);
+ goto put_ctrl_adev;
+ }
+
+ /* get_first_physical_node() returns a weak ref, no need to put() it */
+ ctrl_dev = acpi_get_first_physical_node(ctrl_adev);
+ if (!ctrl_dev) {
+ pr_err("error could not get %s/%s ctrl physical dev\n",
+ info->ctrl_hid, info->ctrl_uid);
+ goto put_serdev_adev;
+ }
+
+ /* ctrl_dev now points to the controller's parent, get the controller */
+ ctrl_dev = device_find_child_by_name(ctrl_dev, info->ctrl_devname);
+ if (!ctrl_dev) {
+ pr_err("error could not get %s/%s %s ctrl dev\n",
+ info->ctrl_hid, info->ctrl_uid, info->ctrl_devname);
+ goto put_serdev_adev;
+ }
+
+ serdev = serdev_device_alloc(to_serdev_controller(ctrl_dev));
+ if (!serdev) {
+ ret = -ENOMEM;
+ goto put_serdev_adev;
+ }
+
+ ACPI_COMPANION_SET(&serdev->dev, serdev_adev);
+ acpi_device_set_enumerated(serdev_adev);
+
+ ret = serdev_device_add(serdev);
+ if (ret) {
+ dev_err(&serdev->dev, "error %d adding serdev\n", ret);
+ serdev_device_put(serdev);
+ goto put_serdev_adev;
+ }
+
+ serdevs[idx] = serdev;
+
+put_serdev_adev:
+ acpi_dev_put(serdev_adev);
+put_ctrl_adev:
+ acpi_dev_put(ctrl_adev);
+ return ret;
+}
+
+static void x86_android_tablet_cleanup(void)
+{
+ int i;
+
+ for (i = 0; i < serdev_count; i++) {
+ if (serdevs[i])
+ serdev_device_remove(serdevs[i]);
+ }
+
+ kfree(serdevs);
+
+ for (i = 0; i < pdev_count; i++)
+ platform_device_unregister(pdevs[i]);
+
+ kfree(pdevs);
+
+ for (i = 0; i < i2c_client_count; i++)
+ i2c_unregister_device(i2c_clients[i]);
+
+ kfree(i2c_clients);
+
+ if (exit_handler)
+ exit_handler();
+
+ for (i = 0; gpiod_lookup_tables && gpiod_lookup_tables[i]; i++)
+ gpiod_remove_lookup_table(gpiod_lookup_tables[i]);
+
+ software_node_unregister(bat_swnode);
+}
+
+static __init int x86_android_tablet_init(void)
+{
+ const struct x86_dev_info *dev_info;
+ const struct dmi_system_id *id;
+ struct gpio_chip *chip;
+ int i, ret = 0;
+
+ id = dmi_first_match(x86_android_tablet_ids);
+ if (!id)
+ return -ENODEV;
+
+ dev_info = id->driver_data;
+
+ /*
+ * The broken DSDTs on these devices often also include broken
+ * _AEI (ACPI Event Interrupt) handlers, disable these.
+ */
+ if (dev_info->invalid_aei_gpiochip) {
+ chip = gpiochip_find(dev_info->invalid_aei_gpiochip,
+ gpiochip_find_match_label);
+ if (!chip) {
+ pr_err("error cannot find GPIO chip %s\n", dev_info->invalid_aei_gpiochip);
+ return -ENODEV;
+ }
+ acpi_gpiochip_free_interrupts(chip);
+ }
+
+ /*
+ * Since this runs from module_init() it cannot use -EPROBE_DEFER,
+ * instead pre-load any modules which are listed as requirements.
+ */
+ for (i = 0; dev_info->modules && dev_info->modules[i]; i++)
+ request_module(dev_info->modules[i]);
+
+ bat_swnode = dev_info->bat_swnode;
+ if (bat_swnode) {
+ ret = software_node_register(bat_swnode);
+ if (ret)
+ return ret;
+ }
+
+ gpiod_lookup_tables = dev_info->gpiod_lookup_tables;
+ for (i = 0; gpiod_lookup_tables && gpiod_lookup_tables[i]; i++)
+ gpiod_add_lookup_table(gpiod_lookup_tables[i]);
+
+ if (dev_info->init) {
+ ret = dev_info->init();
+ if (ret < 0) {
+ x86_android_tablet_cleanup();
+ return ret;
+ }
+ exit_handler = dev_info->exit;
+ }
+
+ i2c_clients = kcalloc(dev_info->i2c_client_count, sizeof(*i2c_clients), GFP_KERNEL);
+ if (!i2c_clients) {
+ x86_android_tablet_cleanup();
+ return -ENOMEM;
+ }
+
+ i2c_client_count = dev_info->i2c_client_count;
+ for (i = 0; i < i2c_client_count; i++) {
+ ret = x86_instantiate_i2c_client(dev_info, i);
+ if (ret < 0) {
+ x86_android_tablet_cleanup();
+ return ret;
+ }
+ }
+
+ /* + 1 to make space for (optional) gpio_keys_button pdev */
+ pdevs = kcalloc(dev_info->pdev_count + 1, sizeof(*pdevs), GFP_KERNEL);
+ if (!pdevs) {
+ x86_android_tablet_cleanup();
+ return -ENOMEM;
+ }
+
+ pdev_count = dev_info->pdev_count;
+ for (i = 0; i < pdev_count; i++) {
+ pdevs[i] = platform_device_register_full(&dev_info->pdev_info[i]);
+ if (IS_ERR(pdevs[i])) {
+ x86_android_tablet_cleanup();
+ return PTR_ERR(pdevs[i]);
+ }
+ }
+
+ serdevs = kcalloc(dev_info->serdev_count, sizeof(*serdevs), GFP_KERNEL);
+ if (!serdevs) {
+ x86_android_tablet_cleanup();
+ return -ENOMEM;
+ }
+
+ serdev_count = dev_info->serdev_count;
+ for (i = 0; i < serdev_count; i++) {
+ ret = x86_instantiate_serdev(&dev_info->serdev_info[i], i);
+ if (ret < 0) {
+ x86_android_tablet_cleanup();
+ return ret;
+ }
+ }
+
+ if (dev_info->gpio_button) {
+ struct gpio_keys_platform_data pdata = {
+ .buttons = &dev_info->gpio_button->button,
+ .nbuttons = 1,
+ };
+ struct gpio_desc *gpiod;
+
+ /* Get GPIO for the gpio-button */
+ ret = x86_android_tablet_get_gpiod(dev_info->gpio_button->chip,
+ dev_info->gpio_button->pin, &gpiod);
+ if (ret < 0) {
+ x86_android_tablet_cleanup();
+ return ret;
+ }
+
+ dev_info->gpio_button->button.gpio = desc_to_gpio(gpiod);
+
+ pdevs[pdev_count] = platform_device_register_data(NULL, "gpio-keys",
+ PLATFORM_DEVID_AUTO,
+ &pdata, sizeof(pdata));
+ if (IS_ERR(pdevs[pdev_count])) {
+ x86_android_tablet_cleanup();
+ return PTR_ERR(pdevs[pdev_count]);
+ }
+ pdev_count++;
+ }
+
+ return 0;
+}
+
+module_init(x86_android_tablet_init);
+module_exit(x86_android_tablet_cleanup);
+
+MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>");
+MODULE_DESCRIPTION("X86 Android tablets DSDT fixups driver");
+MODULE_LICENSE("GPL");
diff --git a/drivers/platform/x86/x86-android-tablets/dmi.c b/drivers/platform/x86/x86-android-tablets/dmi.c
new file mode 100644
index 000000000000..23e640b7003d
--- /dev/null
+++ b/drivers/platform/x86/x86-android-tablets/dmi.c
@@ -0,0 +1,165 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * DMI based code to deal with broken DSDTs on X86 tablets which ship with
+ * Android as (part of) the factory image. The factory kernels shipped on these
+ * devices typically have a bunch of things hardcoded, rather than specified
+ * in their DSDT.
+ *
+ * Copyright (C) 2021-2023 Hans de Goede <hdegoede@redhat.com>
+ */
+
+#include <linux/dmi.h>
+#include <linux/init.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+
+#include "x86-android-tablets.h"
+
+const struct dmi_system_id x86_android_tablet_ids[] __initconst = {
+ {
+ /* Acer Iconia One 7 B1-750 */
+ .matches = {
+ DMI_MATCH(DMI_SYS_VENDOR, "Insyde"),
+ DMI_MATCH(DMI_PRODUCT_NAME, "VESPA2"),
+ },
+ .driver_data = (void *)&acer_b1_750_info,
+ },
+ {
+ /* Advantech MICA-071 */
+ .matches = {
+ DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Advantech"),
+ DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "MICA-071"),
+ },
+ .driver_data = (void *)&advantech_mica_071_info,
+ },
+ {
+ /* Asus MeMO Pad 7 ME176C */
+ .matches = {
+ DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
+ DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "ME176C"),
+ },
+ .driver_data = (void *)&asus_me176c_info,
+ },
+ {
+ /* Asus TF103C */
+ .matches = {
+ DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
+ DMI_MATCH(DMI_PRODUCT_NAME, "TF103C"),
+ },
+ .driver_data = (void *)&asus_tf103c_info,
+ },
+ {
+ /* Chuwi Hi8 (CWI509) */
+ .matches = {
+ DMI_MATCH(DMI_BOARD_VENDOR, "Hampoo"),
+ DMI_MATCH(DMI_BOARD_NAME, "BYT-PA03C"),
+ DMI_MATCH(DMI_SYS_VENDOR, "ilife"),
+ DMI_MATCH(DMI_PRODUCT_NAME, "S806"),
+ },
+ .driver_data = (void *)&chuwi_hi8_info,
+ },
+ {
+ /* CZC P10T */
+ .ident = "CZC ODEON TPC-10 (\"P10T\")",
+ .matches = {
+ DMI_MATCH(DMI_SYS_VENDOR, "CZC"),
+ DMI_MATCH(DMI_PRODUCT_NAME, "ODEON*TPC-10"),
+ },
+ .driver_data = (void *)&czc_p10t,
+ },
+ {
+ /* CZC P10T variant */
+ .ident = "ViewSonic ViewPad 10",
+ .matches = {
+ DMI_MATCH(DMI_SYS_VENDOR, "ViewSonic"),
+ DMI_MATCH(DMI_PRODUCT_NAME, "VPAD10"),
+ },
+ .driver_data = (void *)&czc_p10t,
+ },
+ {
+ /* Lenovo Yoga Book X90F / X90L */
+ .matches = {
+ DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
+ DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "CHERRYVIEW D1 PLATFORM"),
+ DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "YETI-11"),
+ },
+ .driver_data = (void *)&lenovo_yogabook_x90_info,
+ },
+ {
+ /* Lenovo Yoga Book X91F / X91L */
+ .matches = {
+ /* Non exact match to match F + L versions */
+ DMI_MATCH(DMI_PRODUCT_NAME, "Lenovo YB1-X91"),
+ },
+ .driver_data = (void *)&lenovo_yogabook_x91_info,
+ },
+ {
+ /*
+ * Lenovo Yoga Tablet 2 830F/L or 1050F/L (The 8" and 10"
+ * Lenovo Yoga Tablet 2 use the same mainboard)
+ */
+ .matches = {
+ DMI_MATCH(DMI_SYS_VENDOR, "Intel Corp."),
+ DMI_MATCH(DMI_PRODUCT_NAME, "VALLEYVIEW C0 PLATFORM"),
+ DMI_MATCH(DMI_BOARD_NAME, "BYT-T FFD8"),
+ /* Partial match on beginning of BIOS version */
+ DMI_MATCH(DMI_BIOS_VERSION, "BLADE_21"),
+ },
+ .driver_data = (void *)&lenovo_yoga_tab2_830_1050_info,
+ },
+ {
+ /* Lenovo Yoga Tab 3 Pro YT3-X90F */
+ .matches = {
+ DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
+ DMI_MATCH(DMI_PRODUCT_NAME, "CHERRYVIEW D1 PLATFORM"),
+ DMI_MATCH(DMI_PRODUCT_VERSION, "Blade3-10A-001"),
+ },
+ .driver_data = (void *)&lenovo_yt3_info,
+ },
+ {
+ /* Medion Lifetab S10346 */
+ .matches = {
+ DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
+ DMI_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
+ /* Above strings are much too generic, also match on BIOS date */
+ DMI_MATCH(DMI_BIOS_DATE, "10/22/2015"),
+ },
+ .driver_data = (void *)&medion_lifetab_s10346_info,
+ },
+ {
+ /* Nextbook Ares 8 */
+ .matches = {
+ DMI_MATCH(DMI_SYS_VENDOR, "Insyde"),
+ DMI_MATCH(DMI_PRODUCT_NAME, "M890BAP"),
+ },
+ .driver_data = (void *)&nextbook_ares8_info,
+ },
+ {
+ /* Peaq C1010 */
+ .matches = {
+ DMI_MATCH(DMI_SYS_VENDOR, "PEAQ"),
+ DMI_MATCH(DMI_PRODUCT_NAME, "PEAQ PMM C1010 MD99187"),
+ },
+ .driver_data = (void *)&peaq_c1010_info,
+ },
+ {
+ /* Whitelabel (sold as various brands) TM800A550L */
+ .matches = {
+ DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
+ DMI_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
+ /* Above strings are too generic, also match on BIOS version */
+ DMI_MATCH(DMI_BIOS_VERSION, "ZY-8-BI-PX4S70VTR400-X423B-005-D"),
+ },
+ .driver_data = (void *)&whitelabel_tm800a550l_info,
+ },
+ {
+ /* Xiaomi Mi Pad 2 */
+ .matches = {
+ DMI_MATCH(DMI_SYS_VENDOR, "Xiaomi Inc"),
+ DMI_MATCH(DMI_PRODUCT_NAME, "Mipad2"),
+ },
+ .driver_data = (void *)&xiaomi_mipad2_info,
+ },
+ { }
+};
+MODULE_DEVICE_TABLE(dmi, x86_android_tablet_ids);
diff --git a/drivers/platform/x86/x86-android-tablets/lenovo.c b/drivers/platform/x86/x86-android-tablets/lenovo.c
new file mode 100644
index 000000000000..65cfccaa2894
--- /dev/null
+++ b/drivers/platform/x86/x86-android-tablets/lenovo.c
@@ -0,0 +1,679 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Board info for Lenovo X86 tablets which ship with Android as the factory image
+ * and which have broken DSDT tables. The factory kernels shipped on these
+ * devices typically have a bunch of things hardcoded, rather than specified
+ * in their DSDT.
+ *
+ * Copyright (C) 2021-2023 Hans de Goede <hdegoede@redhat.com>
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/efi.h>
+#include <linux/gpio/machine.h>
+#include <linux/mfd/intel_soc_pmic.h>
+#include <linux/pinctrl/consumer.h>
+#include <linux/pinctrl/machine.h>
+#include <linux/platform_data/lp855x.h>
+#include <linux/platform_device.h>
+#include <linux/reboot.h>
+#include <linux/rmi.h>
+#include <linux/spi/spi.h>
+
+#include "shared-psy-info.h"
+#include "x86-android-tablets.h"
+
+/*
+ * Various Lenovo models use a TI LP8557 LED backlight controller with its PWM
+ * input connected to a PWM output coming from the LCD panel's controller.
+ * The Android kernels have a hack in the i915 driver to write a non-standard
+ * panel specific DSI register to set the duty-cycle of the LCD's PWM output.
+ *
+ * To avoid having to have a similar hack in the mainline kernel program the
+ * LP8557 to directly set the level and use the lp855x_bl driver for control.
+ */
+static struct lp855x_platform_data lenovo_lp8557_pdata = {
+ .device_control = 0x86,
+ .initial_brightness = 128,
+};
+
+/* Lenovo Yoga Book X90F / X90L's Android factory img has everything hardcoded */
+
+static const struct property_entry lenovo_yb1_x90_wacom_props[] = {
+ PROPERTY_ENTRY_U32("hid-descr-addr", 0x0001),
+ PROPERTY_ENTRY_U32("post-reset-deassert-delay-ms", 150),
+ { }
+};
+
+static const struct software_node lenovo_yb1_x90_wacom_node = {
+ .properties = lenovo_yb1_x90_wacom_props,
+};
+
+/*
+ * The HiDeep IST940E touchscreen comes up in I2C-HID mode. The native protocol
+ * reports ABS_MT_PRESSURE and ABS_MT_TOUCH_MAJOR which are not reported in HID
+ * mode, so using native mode is preferred.
+ * It could alternatively be used in HID mode by changing the properties to:
+ * PROPERTY_ENTRY_U32("hid-descr-addr", 0x0020),
+ * PROPERTY_ENTRY_U32("post-reset-deassert-delay-ms", 120),
+ * and changing board_info.type to "hid-over-i2c".
+ */
+static const struct property_entry lenovo_yb1_x90_hideep_ts_props[] = {
+ PROPERTY_ENTRY_U32("touchscreen-size-x", 1200),
+ PROPERTY_ENTRY_U32("touchscreen-size-y", 1920),
+ PROPERTY_ENTRY_U32("touchscreen-max-pressure", 16384),
+ PROPERTY_ENTRY_BOOL("hideep,force-native-protocol"),
+ { }
+};
+
+static const struct software_node lenovo_yb1_x90_hideep_ts_node = {
+ .properties = lenovo_yb1_x90_hideep_ts_props,
+};
+
+static const struct x86_i2c_client_info lenovo_yb1_x90_i2c_clients[] __initconst = {
+ {
+ /* BQ27542 fuel-gauge */
+ .board_info = {
+ .type = "bq27542",
+ .addr = 0x55,
+ .dev_name = "bq27542",
+ .swnode = &fg_bq25890_supply_node,
+ },
+ .adapter_path = "\\_SB_.PCI0.I2C1",
+ }, {
+ /* Goodix Touchscreen in keyboard half */
+ .board_info = {
+ .type = "GDIX1001:00",
+ .addr = 0x14,
+ .dev_name = "goodix_ts",
+ },
+ .adapter_path = "\\_SB_.PCI0.I2C2",
+ .irq_data = {
+ .type = X86_ACPI_IRQ_TYPE_GPIOINT,
+ .chip = "INT33FF:01",
+ .index = 56,
+ .trigger = ACPI_EDGE_SENSITIVE,
+ .polarity = ACPI_ACTIVE_LOW,
+ },
+ }, {
+ /* Wacom Digitizer in keyboard half */
+ .board_info = {
+ .type = "hid-over-i2c",
+ .addr = 0x09,
+ .dev_name = "wacom",
+ .swnode = &lenovo_yb1_x90_wacom_node,
+ },
+ .adapter_path = "\\_SB_.PCI0.I2C4",
+ .irq_data = {
+ .type = X86_ACPI_IRQ_TYPE_GPIOINT,
+ .chip = "INT33FF:01",
+ .index = 49,
+ .trigger = ACPI_LEVEL_SENSITIVE,
+ .polarity = ACPI_ACTIVE_LOW,
+ },
+ }, {
+ /* LP8557 Backlight controller */
+ .board_info = {
+ .type = "lp8557",
+ .addr = 0x2c,
+ .dev_name = "lp8557",
+ .platform_data = &lenovo_lp8557_pdata,
+ },
+ .adapter_path = "\\_SB_.PCI0.I2C4",
+ }, {
+ /* HiDeep IST940E Touchscreen in display half */
+ .board_info = {
+ .type = "hideep_ts",
+ .addr = 0x6c,
+ .dev_name = "hideep_ts",
+ .swnode = &lenovo_yb1_x90_hideep_ts_node,
+ },
+ .adapter_path = "\\_SB_.PCI0.I2C6",
+ .irq_data = {
+ .type = X86_ACPI_IRQ_TYPE_GPIOINT,
+ .chip = "INT33FF:03",
+ .index = 77,
+ .trigger = ACPI_LEVEL_SENSITIVE,
+ .polarity = ACPI_ACTIVE_LOW,
+ },
+ },
+};
+
+static const struct platform_device_info lenovo_yb1_x90_pdevs[] __initconst = {
+ {
+ .name = "yogabook-touch-kbd-digitizer-switch",
+ .id = PLATFORM_DEVID_NONE,
+ },
+};
+
+static struct gpiod_lookup_table lenovo_yb1_x90_goodix_gpios = {
+ .dev_id = "i2c-goodix_ts",
+ .table = {
+ GPIO_LOOKUP("INT33FF:01", 53, "reset", GPIO_ACTIVE_HIGH),
+ GPIO_LOOKUP("INT33FF:01", 56, "irq", GPIO_ACTIVE_HIGH),
+ { }
+ },
+};
+
+static struct gpiod_lookup_table lenovo_yb1_x90_hideep_gpios = {
+ .dev_id = "i2c-hideep_ts",
+ .table = {
+ GPIO_LOOKUP("INT33FF:00", 7, "reset", GPIO_ACTIVE_LOW),
+ { }
+ },
+};
+
+static struct gpiod_lookup_table lenovo_yb1_x90_wacom_gpios = {
+ .dev_id = "i2c-wacom",
+ .table = {
+ GPIO_LOOKUP("INT33FF:00", 82, "reset", GPIO_ACTIVE_LOW),
+ { }
+ },
+};
+
+static struct gpiod_lookup_table * const lenovo_yb1_x90_gpios[] = {
+ &lenovo_yb1_x90_hideep_gpios,
+ &lenovo_yb1_x90_goodix_gpios,
+ &lenovo_yb1_x90_wacom_gpios,
+ NULL
+};
+
+static int __init lenovo_yb1_x90_init(void)
+{
+ /* Enable the regulators used by the touchscreens */
+
+ /* Vprog3B 3.0V used by the goodix touchscreen in the keyboard half */
+ intel_soc_pmic_exec_mipi_pmic_seq_element(0x6e, 0x9b, 0x02, 0xff);
+
+ /* Vprog4D 3.0V used by the HiDeep touchscreen in the display half */
+ intel_soc_pmic_exec_mipi_pmic_seq_element(0x6e, 0x9f, 0x02, 0xff);
+
+ /* Vprog5A 1.8V used by the HiDeep touchscreen in the display half */
+ intel_soc_pmic_exec_mipi_pmic_seq_element(0x6e, 0xa0, 0x02, 0xff);
+
+ /* Vprog5B 1.8V used by the goodix touchscreen in the keyboard half */
+ intel_soc_pmic_exec_mipi_pmic_seq_element(0x6e, 0xa1, 0x02, 0xff);
+
+ return 0;
+}
+
+const struct x86_dev_info lenovo_yogabook_x90_info __initconst = {
+ .i2c_client_info = lenovo_yb1_x90_i2c_clients,
+ .i2c_client_count = ARRAY_SIZE(lenovo_yb1_x90_i2c_clients),
+ .pdev_info = lenovo_yb1_x90_pdevs,
+ .pdev_count = ARRAY_SIZE(lenovo_yb1_x90_pdevs),
+ .gpiod_lookup_tables = lenovo_yb1_x90_gpios,
+ .init = lenovo_yb1_x90_init,
+};
+
+/* Lenovo Yoga Book X91F/L Windows tablet needs manual instantiation of the fg client */
+static const struct x86_i2c_client_info lenovo_yogabook_x91_i2c_clients[] __initconst = {
+ {
+ /* BQ27542 fuel-gauge */
+ .board_info = {
+ .type = "bq27542",
+ .addr = 0x55,
+ .dev_name = "bq27542",
+ .swnode = &fg_bq25890_supply_node,
+ },
+ .adapter_path = "\\_SB_.PCI0.I2C1",
+ },
+};
+
+const struct x86_dev_info lenovo_yogabook_x91_info __initconst = {
+ .i2c_client_info = lenovo_yogabook_x91_i2c_clients,
+ .i2c_client_count = ARRAY_SIZE(lenovo_yogabook_x91_i2c_clients),
+};
+
+/* Lenovo Yoga Tablet 2 1050F/L's Android factory img has everything hardcoded */
+static const struct property_entry lenovo_yoga_tab2_830_1050_bq24190_props[] = {
+ PROPERTY_ENTRY_STRING_ARRAY_LEN("supplied-from", tusb1211_chg_det_psy, 1),
+ PROPERTY_ENTRY_REF("monitored-battery", &generic_lipo_hv_4v35_battery_node),
+ PROPERTY_ENTRY_BOOL("omit-battery-class"),
+ PROPERTY_ENTRY_BOOL("disable-reset"),
+ { }
+};
+
+static const struct software_node lenovo_yoga_tab2_830_1050_bq24190_node = {
+ .properties = lenovo_yoga_tab2_830_1050_bq24190_props,
+};
+
+static struct x86_gpio_button lenovo_yoga_tab2_830_1050_lid = {
+ .button = {
+ .code = SW_LID,
+ .active_low = true,
+ .desc = "lid_sw",
+ .type = EV_SW,
+ .wakeup = true,
+ .debounce_interval = 50,
+ },
+ .chip = "INT33FC:02",
+ .pin = 26,
+};
+
+/* This gets filled by lenovo_yoga_tab2_830_1050_init() */
+static struct rmi_device_platform_data lenovo_yoga_tab2_830_1050_rmi_pdata = { };
+
+static struct x86_i2c_client_info lenovo_yoga_tab2_830_1050_i2c_clients[] __initdata = {
+ {
+ /*
+ * This must be the first entry because lenovo_yoga_tab2_830_1050_init()
+ * may update its swnode. LSM303DA accelerometer + magnetometer.
+ */
+ .board_info = {
+ .type = "lsm303d",
+ .addr = 0x1d,
+ .dev_name = "lsm303d",
+ },
+ .adapter_path = "\\_SB_.I2C5",
+ }, {
+ /* bq24292i battery charger */
+ .board_info = {
+ .type = "bq24190",
+ .addr = 0x6b,
+ .dev_name = "bq24292i",
+ .swnode = &lenovo_yoga_tab2_830_1050_bq24190_node,
+ .platform_data = &bq24190_pdata,
+ },
+ .adapter_path = "\\_SB_.I2C1",
+ .irq_data = {
+ .type = X86_ACPI_IRQ_TYPE_GPIOINT,
+ .chip = "INT33FC:02",
+ .index = 2,
+ .trigger = ACPI_EDGE_SENSITIVE,
+ .polarity = ACPI_ACTIVE_HIGH,
+ },
+ }, {
+ /* BQ27541 fuel-gauge */
+ .board_info = {
+ .type = "bq27541",
+ .addr = 0x55,
+ .dev_name = "bq27541",
+ .swnode = &fg_bq24190_supply_node,
+ },
+ .adapter_path = "\\_SB_.I2C1",
+ }, {
+ /* Synaptics RMI touchscreen */
+ .board_info = {
+ .type = "rmi4_i2c",
+ .addr = 0x38,
+ .dev_name = "rmi4_i2c",
+ .platform_data = &lenovo_yoga_tab2_830_1050_rmi_pdata,
+ },
+ .adapter_path = "\\_SB_.I2C6",
+ .irq_data = {
+ .type = X86_ACPI_IRQ_TYPE_APIC,
+ .index = 0x45,
+ .trigger = ACPI_EDGE_SENSITIVE,
+ .polarity = ACPI_ACTIVE_HIGH,
+ },
+ }, {
+ /* LP8557 Backlight controller */
+ .board_info = {
+ .type = "lp8557",
+ .addr = 0x2c,
+ .dev_name = "lp8557",
+ .platform_data = &lenovo_lp8557_pdata,
+ },
+ .adapter_path = "\\_SB_.I2C3",
+ },
+};
+
+static struct gpiod_lookup_table lenovo_yoga_tab2_830_1050_int3496_gpios = {
+ .dev_id = "intel-int3496",
+ .table = {
+ GPIO_LOOKUP("INT33FC:02", 1, "mux", GPIO_ACTIVE_LOW),
+ GPIO_LOOKUP("INT33FC:02", 24, "id", GPIO_ACTIVE_HIGH),
+ { }
+ },
+};
+
+#define LENOVO_YOGA_TAB2_830_1050_CODEC_NAME "spi-10WM5102:00"
+
+static struct gpiod_lookup_table lenovo_yoga_tab2_830_1050_codec_gpios = {
+ .dev_id = LENOVO_YOGA_TAB2_830_1050_CODEC_NAME,
+ .table = {
+ GPIO_LOOKUP("gpio_crystalcove", 3, "reset", GPIO_ACTIVE_HIGH),
+ GPIO_LOOKUP("INT33FC:01", 23, "wlf,ldoena", GPIO_ACTIVE_HIGH),
+ GPIO_LOOKUP("arizona", 2, "wlf,spkvdd-ena", GPIO_ACTIVE_HIGH),
+ GPIO_LOOKUP("arizona", 4, "wlf,micd-pol", GPIO_ACTIVE_LOW),
+ { }
+ },
+};
+
+static struct gpiod_lookup_table * const lenovo_yoga_tab2_830_1050_gpios[] = {
+ &lenovo_yoga_tab2_830_1050_int3496_gpios,
+ &lenovo_yoga_tab2_830_1050_codec_gpios,
+ NULL
+};
+
+static int __init lenovo_yoga_tab2_830_1050_init(void);
+static void lenovo_yoga_tab2_830_1050_exit(void);
+
+const struct x86_dev_info lenovo_yoga_tab2_830_1050_info __initconst = {
+ .i2c_client_info = lenovo_yoga_tab2_830_1050_i2c_clients,
+ .i2c_client_count = ARRAY_SIZE(lenovo_yoga_tab2_830_1050_i2c_clients),
+ .pdev_info = int3496_pdevs,
+ .pdev_count = 1,
+ .gpio_button = &lenovo_yoga_tab2_830_1050_lid,
+ .gpiod_lookup_tables = lenovo_yoga_tab2_830_1050_gpios,
+ .bat_swnode = &generic_lipo_hv_4v35_battery_node,
+ .modules = bq24190_modules,
+ .init = lenovo_yoga_tab2_830_1050_init,
+ .exit = lenovo_yoga_tab2_830_1050_exit,
+};
+
+/*
+ * The Lenovo Yoga Tablet 2 830 and 1050 (8" vs 10") versions use the same
+ * mainboard, but the 830 uses a portrait LCD panel with a landscape touchscreen,
+ * requiring the touchscreen driver to adjust the touch-coords to match the LCD.
+ * And requiring the accelerometer to have a mount-matrix set to correct for
+ * the 90° rotation of the LCD vs the frame.
+ */
+static const char * const lenovo_yoga_tab2_830_lms303d_mount_matrix[] = {
+ "0", "1", "0",
+ "-1", "0", "0",
+ "0", "0", "1"
+};
+
+static const struct property_entry lenovo_yoga_tab2_830_lms303d_props[] = {
+ PROPERTY_ENTRY_STRING_ARRAY("mount-matrix", lenovo_yoga_tab2_830_lms303d_mount_matrix),
+ { }
+};
+
+static const struct software_node lenovo_yoga_tab2_830_lms303d_node = {
+ .properties = lenovo_yoga_tab2_830_lms303d_props,
+};
+
+static int __init lenovo_yoga_tab2_830_1050_init_touchscreen(void)
+{
+ struct gpio_desc *gpiod;
+ int ret;
+
+ /* Use PMIC GPIO 10 bootstrap pin to differentiate 830 vs 1050 */
+ ret = x86_android_tablet_get_gpiod("gpio_crystalcove", 10, &gpiod);
+ if (ret)
+ return ret;
+
+ ret = gpiod_get_value_cansleep(gpiod);
+ if (ret) {
+ pr_info("detected Lenovo Yoga Tablet 2 1050F/L\n");
+ } else {
+ pr_info("detected Lenovo Yoga Tablet 2 830F/L\n");
+ lenovo_yoga_tab2_830_1050_rmi_pdata.sensor_pdata.axis_align.swap_axes = true;
+ lenovo_yoga_tab2_830_1050_rmi_pdata.sensor_pdata.axis_align.flip_y = true;
+ lenovo_yoga_tab2_830_1050_i2c_clients[0].board_info.swnode =
+ &lenovo_yoga_tab2_830_lms303d_node;
+ }
+
+ return 0;
+}
+
+/* SUS (INT33FC:02) pin 6 needs to be configured as pmu_clk for the audio codec */
+static const struct pinctrl_map lenovo_yoga_tab2_830_1050_codec_pinctrl_map =
+ PIN_MAP_MUX_GROUP(LENOVO_YOGA_TAB2_830_1050_CODEC_NAME, "codec_32khz_clk",
+ "INT33FC:02", "pmu_clk2_grp", "pmu_clk");
+
+static struct pinctrl *lenovo_yoga_tab2_830_1050_codec_pinctrl;
+static struct sys_off_handler *lenovo_yoga_tab2_830_1050_sys_off_handler;
+
+static int __init lenovo_yoga_tab2_830_1050_init_codec(void)
+{
+ struct device *codec_dev;
+ struct pinctrl *pinctrl;
+ int ret;
+
+ codec_dev = bus_find_device_by_name(&spi_bus_type, NULL,
+ LENOVO_YOGA_TAB2_830_1050_CODEC_NAME);
+ if (!codec_dev) {
+ pr_err("error cannot find %s device\n", LENOVO_YOGA_TAB2_830_1050_CODEC_NAME);
+ return -ENODEV;
+ }
+
+ ret = pinctrl_register_mappings(&lenovo_yoga_tab2_830_1050_codec_pinctrl_map, 1);
+ if (ret)
+ goto err_put_device;
+
+ pinctrl = pinctrl_get_select(codec_dev, "codec_32khz_clk");
+ if (IS_ERR(pinctrl)) {
+ ret = dev_err_probe(codec_dev, PTR_ERR(pinctrl), "selecting codec_32khz_clk\n");
+ goto err_unregister_mappings;
+ }
+
+ /* We're done with the codec_dev now */
+ put_device(codec_dev);
+
+ lenovo_yoga_tab2_830_1050_codec_pinctrl = pinctrl;
+ return 0;
+
+err_unregister_mappings:
+ pinctrl_unregister_mappings(&lenovo_yoga_tab2_830_1050_codec_pinctrl_map);
+err_put_device:
+ put_device(codec_dev);
+ return ret;
+}
+
+/*
+ * These tablet's DSDT does not set acpi_gbl_reduced_hardware, so acpi_power_off
+ * gets used as pm_power_off handler. This causes "poweroff" on these tablets
+ * to hang hard. Requiring pressing the powerbutton for 30 seconds *twice*
+ * followed by a normal 3 second press to recover. Avoid this by doing an EFI
+ * poweroff instead.
+ */
+static int lenovo_yoga_tab2_830_1050_power_off(struct sys_off_data *data)
+{
+ efi.reset_system(EFI_RESET_SHUTDOWN, EFI_SUCCESS, 0, NULL);
+
+ return NOTIFY_DONE;
+}
+
+static int __init lenovo_yoga_tab2_830_1050_init(void)
+{
+ int ret;
+
+ ret = lenovo_yoga_tab2_830_1050_init_touchscreen();
+ if (ret)
+ return ret;
+
+ ret = lenovo_yoga_tab2_830_1050_init_codec();
+ if (ret)
+ return ret;
+
+ /* SYS_OFF_PRIO_FIRMWARE + 1 so that it runs before acpi_power_off */
+ lenovo_yoga_tab2_830_1050_sys_off_handler =
+ register_sys_off_handler(SYS_OFF_MODE_POWER_OFF, SYS_OFF_PRIO_FIRMWARE + 1,
+ lenovo_yoga_tab2_830_1050_power_off, NULL);
+ if (IS_ERR(lenovo_yoga_tab2_830_1050_sys_off_handler))
+ return PTR_ERR(lenovo_yoga_tab2_830_1050_sys_off_handler);
+
+ return 0;
+}
+
+static void lenovo_yoga_tab2_830_1050_exit(void)
+{
+ unregister_sys_off_handler(lenovo_yoga_tab2_830_1050_sys_off_handler);
+
+ if (lenovo_yoga_tab2_830_1050_codec_pinctrl) {
+ pinctrl_put(lenovo_yoga_tab2_830_1050_codec_pinctrl);
+ pinctrl_unregister_mappings(&lenovo_yoga_tab2_830_1050_codec_pinctrl_map);
+ }
+}
+
+/* Lenovo Yoga Tab 3 Pro YT3-X90F */
+
+/*
+ * There are 2 batteries, with 2 bq27500 fuel-gauges and 2 bq25892 chargers,
+ * "bq25890-charger-1" is instantiated from: drivers/i2c/busses/i2c-cht-wc.c.
+ */
+static const char * const lenovo_yt3_bq25892_0_suppliers[] = { "cht_wcove_pwrsrc" };
+static const char * const bq25890_1_psy[] = { "bq25890-charger-1" };
+
+static const struct property_entry fg_bq25890_1_supply_props[] = {
+ PROPERTY_ENTRY_STRING_ARRAY("supplied-from", bq25890_1_psy),
+ { }
+};
+
+static const struct software_node fg_bq25890_1_supply_node = {
+ .properties = fg_bq25890_1_supply_props,
+};
+
+/* bq25892 charger settings for the flat lipo battery behind the screen */
+static const struct property_entry lenovo_yt3_bq25892_0_props[] = {
+ PROPERTY_ENTRY_STRING_ARRAY("supplied-from", lenovo_yt3_bq25892_0_suppliers),
+ PROPERTY_ENTRY_STRING("linux,power-supply-name", "bq25892-second-chrg"),
+ PROPERTY_ENTRY_U32("linux,iinlim-percentage", 40),
+ PROPERTY_ENTRY_BOOL("linux,skip-reset"),
+ /* Values taken from Android Factory Image */
+ PROPERTY_ENTRY_U32("ti,charge-current", 2048000),
+ PROPERTY_ENTRY_U32("ti,battery-regulation-voltage", 4352000),
+ PROPERTY_ENTRY_U32("ti,termination-current", 128000),
+ PROPERTY_ENTRY_U32("ti,precharge-current", 128000),
+ PROPERTY_ENTRY_U32("ti,minimum-sys-voltage", 3700000),
+ PROPERTY_ENTRY_U32("ti,boost-voltage", 4998000),
+ PROPERTY_ENTRY_U32("ti,boost-max-current", 500000),
+ PROPERTY_ENTRY_BOOL("ti,use-ilim-pin"),
+ { }
+};
+
+static const struct software_node lenovo_yt3_bq25892_0_node = {
+ .properties = lenovo_yt3_bq25892_0_props,
+};
+
+static const struct property_entry lenovo_yt3_hideep_ts_props[] = {
+ PROPERTY_ENTRY_U32("touchscreen-size-x", 1600),
+ PROPERTY_ENTRY_U32("touchscreen-size-y", 2560),
+ PROPERTY_ENTRY_U32("touchscreen-max-pressure", 255),
+ { }
+};
+
+static const struct software_node lenovo_yt3_hideep_ts_node = {
+ .properties = lenovo_yt3_hideep_ts_props,
+};
+
+static const struct x86_i2c_client_info lenovo_yt3_i2c_clients[] __initconst = {
+ {
+ /* bq27500 fuel-gauge for the flat lipo battery behind the screen */
+ .board_info = {
+ .type = "bq27500",
+ .addr = 0x55,
+ .dev_name = "bq27500_0",
+ .swnode = &fg_bq25890_supply_node,
+ },
+ .adapter_path = "\\_SB_.PCI0.I2C1",
+ }, {
+ /* bq25892 charger for the flat lipo battery behind the screen */
+ .board_info = {
+ .type = "bq25892",
+ .addr = 0x6b,
+ .dev_name = "bq25892_0",
+ .swnode = &lenovo_yt3_bq25892_0_node,
+ },
+ .adapter_path = "\\_SB_.PCI0.I2C1",
+ .irq_data = {
+ .type = X86_ACPI_IRQ_TYPE_GPIOINT,
+ .chip = "INT33FF:01",
+ .index = 5,
+ .trigger = ACPI_EDGE_SENSITIVE,
+ .polarity = ACPI_ACTIVE_LOW,
+ },
+ }, {
+ /* bq27500 fuel-gauge for the round li-ion cells in the hinge */
+ .board_info = {
+ .type = "bq27500",
+ .addr = 0x55,
+ .dev_name = "bq27500_1",
+ .swnode = &fg_bq25890_1_supply_node,
+ },
+ .adapter_path = "\\_SB_.PCI0.I2C2",
+ }, {
+ /* HiDeep IST520E Touchscreen */
+ .board_info = {
+ .type = "hideep_ts",
+ .addr = 0x6c,
+ .dev_name = "hideep_ts",
+ .swnode = &lenovo_yt3_hideep_ts_node,
+ },
+ .adapter_path = "\\_SB_.PCI0.I2C6",
+ .irq_data = {
+ .type = X86_ACPI_IRQ_TYPE_GPIOINT,
+ .chip = "INT33FF:03",
+ .index = 77,
+ .trigger = ACPI_LEVEL_SENSITIVE,
+ .polarity = ACPI_ACTIVE_LOW,
+ },
+ }, {
+ /* LP8557 Backlight controller */
+ .board_info = {
+ .type = "lp8557",
+ .addr = 0x2c,
+ .dev_name = "lp8557",
+ .platform_data = &lenovo_lp8557_pdata,
+ },
+ .adapter_path = "\\_SB_.PCI0.I2C1",
+ }
+};
+
+static int __init lenovo_yt3_init(void)
+{
+ struct gpio_desc *gpiod;
+ int ret;
+
+ /*
+ * The "bq25892_0" charger IC has its /CE (Charge-Enable) and OTG pins
+ * connected to GPIOs, rather then having them hardwired to the correct
+ * values as is normally done.
+ *
+ * The bq25890_charger driver controls these through I2C, but this only
+ * works if not overridden by the pins. Set these pins here:
+ * 1. Set /CE to 0 to allow charging.
+ * 2. Set OTG to 0 disable V5 boost output since the 5V boost output of
+ * the main "bq25892_1" charger is used when necessary.
+ */
+
+ /* /CE pin */
+ ret = x86_android_tablet_get_gpiod("INT33FF:02", 22, &gpiod);
+ if (ret < 0)
+ return ret;
+
+ /*
+ * The gpio_desc returned by x86_android_tablet_get_gpiod() is a "raw"
+ * gpio_desc, that is there is no way to pass lookup-flags like
+ * GPIO_ACTIVE_LOW. Set the GPIO to 0 here to enable charging since
+ * the /CE pin is active-low, but not marked as such in the gpio_desc.
+ */
+ gpiod_set_value(gpiod, 0);
+
+ /* OTG pin */
+ ret = x86_android_tablet_get_gpiod("INT33FF:03", 19, &gpiod);
+ if (ret < 0)
+ return ret;
+
+ gpiod_set_value(gpiod, 0);
+
+ /* Enable the regulators used by the touchscreen */
+ intel_soc_pmic_exec_mipi_pmic_seq_element(0x6e, 0x9b, 0x02, 0xff);
+ intel_soc_pmic_exec_mipi_pmic_seq_element(0x6e, 0xa0, 0x02, 0xff);
+
+ return 0;
+}
+
+static struct gpiod_lookup_table lenovo_yt3_hideep_gpios = {
+ .dev_id = "i2c-hideep_ts",
+ .table = {
+ GPIO_LOOKUP("INT33FF:00", 7, "reset", GPIO_ACTIVE_LOW),
+ { }
+ },
+};
+
+static struct gpiod_lookup_table * const lenovo_yt3_gpios[] = {
+ &lenovo_yt3_hideep_gpios,
+ NULL
+};
+
+const struct x86_dev_info lenovo_yt3_info __initconst = {
+ .i2c_client_info = lenovo_yt3_i2c_clients,
+ .i2c_client_count = ARRAY_SIZE(lenovo_yt3_i2c_clients),
+ .gpiod_lookup_tables = lenovo_yt3_gpios,
+ .init = lenovo_yt3_init,
+};
diff --git a/drivers/platform/x86/x86-android-tablets/other.c b/drivers/platform/x86/x86-android-tablets/other.c
new file mode 100644
index 000000000000..83cd7e16c84c
--- /dev/null
+++ b/drivers/platform/x86/x86-android-tablets/other.c
@@ -0,0 +1,522 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * DMI based code to deal with broken DSDTs on X86 tablets which ship with
+ * Android as (part of) the factory image. The factory kernels shipped on these
+ * devices typically have a bunch of things hardcoded, rather than specified
+ * in their DSDT.
+ *
+ * Copyright (C) 2021-2023 Hans de Goede <hdegoede@redhat.com>
+ */
+
+#include <linux/acpi.h>
+#include <linux/gpio/machine.h>
+#include <linux/input.h>
+#include <linux/platform_device.h>
+
+#include "shared-psy-info.h"
+#include "x86-android-tablets.h"
+
+/* Acer Iconia One 7 B1-750 has an Android factory img with everything hardcoded */
+static const char * const acer_b1_750_mount_matrix[] = {
+ "-1", "0", "0",
+ "0", "1", "0",
+ "0", "0", "1"
+};
+
+static const struct property_entry acer_b1_750_bma250e_props[] = {
+ PROPERTY_ENTRY_STRING_ARRAY("mount-matrix", acer_b1_750_mount_matrix),
+ { }
+};
+
+static const struct software_node acer_b1_750_bma250e_node = {
+ .properties = acer_b1_750_bma250e_props,
+};
+
+static const struct x86_i2c_client_info acer_b1_750_i2c_clients[] __initconst = {
+ {
+ /* Novatek NVT-ts touchscreen */
+ .board_info = {
+ .type = "NVT-ts",
+ .addr = 0x34,
+ .dev_name = "NVT-ts",
+ },
+ .adapter_path = "\\_SB_.I2C4",
+ .irq_data = {
+ .type = X86_ACPI_IRQ_TYPE_GPIOINT,
+ .chip = "INT33FC:02",
+ .index = 3,
+ .trigger = ACPI_EDGE_SENSITIVE,
+ .polarity = ACPI_ACTIVE_LOW,
+ },
+ }, {
+ /* BMA250E accelerometer */
+ .board_info = {
+ .type = "bma250e",
+ .addr = 0x18,
+ .swnode = &acer_b1_750_bma250e_node,
+ },
+ .adapter_path = "\\_SB_.I2C3",
+ .irq_data = {
+ .type = X86_ACPI_IRQ_TYPE_GPIOINT,
+ .chip = "INT33FC:02",
+ .index = 25,
+ .trigger = ACPI_LEVEL_SENSITIVE,
+ .polarity = ACPI_ACTIVE_HIGH,
+ },
+ },
+};
+
+static struct gpiod_lookup_table acer_b1_750_goodix_gpios = {
+ .dev_id = "i2c-NVT-ts",
+ .table = {
+ GPIO_LOOKUP("INT33FC:01", 26, "reset", GPIO_ACTIVE_LOW),
+ { }
+ },
+};
+
+static struct gpiod_lookup_table * const acer_b1_750_gpios[] = {
+ &acer_b1_750_goodix_gpios,
+ &int3496_reference_gpios,
+ NULL
+};
+
+const struct x86_dev_info acer_b1_750_info __initconst = {
+ .i2c_client_info = acer_b1_750_i2c_clients,
+ .i2c_client_count = ARRAY_SIZE(acer_b1_750_i2c_clients),
+ .pdev_info = int3496_pdevs,
+ .pdev_count = 1,
+ .gpiod_lookup_tables = acer_b1_750_gpios,
+};
+
+/*
+ * Advantech MICA-071
+ * This is a standard Windows tablet, but it has an extra "quick launch" button
+ * which is not described in the ACPI tables in anyway.
+ * Use the x86-android-tablets infra to create a gpio-button device for this.
+ */
+static struct x86_gpio_button advantech_mica_071_button = {
+ .button = {
+ .code = KEY_PROG1,
+ .active_low = true,
+ .desc = "prog1_key",
+ .type = EV_KEY,
+ .wakeup = false,
+ .debounce_interval = 50,
+ },
+ .chip = "INT33FC:00",
+ .pin = 2,
+};
+
+const struct x86_dev_info advantech_mica_071_info __initconst = {
+ .gpio_button = &advantech_mica_071_button,
+};
+
+/*
+ * When booted with the BIOS set to Android mode the Chuwi Hi8 (CWI509) DSDT
+ * contains a whole bunch of bogus ACPI I2C devices and is missing entries
+ * for the touchscreen and the accelerometer.
+ */
+static const struct property_entry chuwi_hi8_gsl1680_props[] = {
+ PROPERTY_ENTRY_U32("touchscreen-size-x", 1665),
+ PROPERTY_ENTRY_U32("touchscreen-size-y", 1140),
+ PROPERTY_ENTRY_BOOL("touchscreen-swapped-x-y"),
+ PROPERTY_ENTRY_BOOL("silead,home-button"),
+ PROPERTY_ENTRY_STRING("firmware-name", "gsl1680-chuwi-hi8.fw"),
+ { }
+};
+
+static const struct software_node chuwi_hi8_gsl1680_node = {
+ .properties = chuwi_hi8_gsl1680_props,
+};
+
+static const char * const chuwi_hi8_mount_matrix[] = {
+ "1", "0", "0",
+ "0", "-1", "0",
+ "0", "0", "1"
+};
+
+static const struct property_entry chuwi_hi8_bma250e_props[] = {
+ PROPERTY_ENTRY_STRING_ARRAY("mount-matrix", chuwi_hi8_mount_matrix),
+ { }
+};
+
+static const struct software_node chuwi_hi8_bma250e_node = {
+ .properties = chuwi_hi8_bma250e_props,
+};
+
+static const struct x86_i2c_client_info chuwi_hi8_i2c_clients[] __initconst = {
+ {
+ /* Silead touchscreen */
+ .board_info = {
+ .type = "gsl1680",
+ .addr = 0x40,
+ .swnode = &chuwi_hi8_gsl1680_node,
+ },
+ .adapter_path = "\\_SB_.I2C4",
+ .irq_data = {
+ .type = X86_ACPI_IRQ_TYPE_APIC,
+ .index = 0x44,
+ .trigger = ACPI_EDGE_SENSITIVE,
+ .polarity = ACPI_ACTIVE_HIGH,
+ },
+ }, {
+ /* BMA250E accelerometer */
+ .board_info = {
+ .type = "bma250e",
+ .addr = 0x18,
+ .swnode = &chuwi_hi8_bma250e_node,
+ },
+ .adapter_path = "\\_SB_.I2C3",
+ .irq_data = {
+ .type = X86_ACPI_IRQ_TYPE_GPIOINT,
+ .chip = "INT33FC:02",
+ .index = 23,
+ .trigger = ACPI_LEVEL_SENSITIVE,
+ .polarity = ACPI_ACTIVE_HIGH,
+ },
+ },
+};
+
+static int __init chuwi_hi8_init(void)
+{
+ /*
+ * Avoid the acpi_unregister_gsi() call in x86_acpi_irq_helper_get()
+ * breaking the touchscreen + logging various errors when the Windows
+ * BIOS is used.
+ */
+ if (acpi_dev_present("MSSL0001", NULL, 1))
+ return -ENODEV;
+
+ return 0;
+}
+
+const struct x86_dev_info chuwi_hi8_info __initconst = {
+ .i2c_client_info = chuwi_hi8_i2c_clients,
+ .i2c_client_count = ARRAY_SIZE(chuwi_hi8_i2c_clients),
+ .init = chuwi_hi8_init,
+};
+
+#define CZC_EC_EXTRA_PORT 0x68
+#define CZC_EC_ANDROID_KEYS 0x63
+
+static int __init czc_p10t_init(void)
+{
+ /*
+ * The device boots up in "Windows 7" mode, when the home button sends a
+ * Windows specific key sequence (Left Meta + D) and the second button
+ * sends an unknown one while also toggling the Radio Kill Switch.
+ * This is a surprising behavior when the second button is labeled "Back".
+ *
+ * The vendor-supplied Android-x86 build switches the device to a "Android"
+ * mode by writing value 0x63 to the I/O port 0x68. This just seems to just
+ * set bit 6 on address 0x96 in the EC region; switching the bit directly
+ * seems to achieve the same result. It uses a "p10t_switcher" to do the
+ * job. It doesn't seem to be able to do anything else, and no other use
+ * of the port 0x68 is known.
+ *
+ * In the Android mode, the home button sends just a single scancode,
+ * which can be handled in Linux userspace more reasonably and the back
+ * button only sends a scancode without toggling the kill switch.
+ * The scancode can then be mapped either to Back or RF Kill functionality
+ * in userspace, depending on how the button is labeled on that particular
+ * model.
+ */
+ outb(CZC_EC_ANDROID_KEYS, CZC_EC_EXTRA_PORT);
+ return 0;
+}
+
+const struct x86_dev_info czc_p10t __initconst = {
+ .init = czc_p10t_init,
+};
+
+/* Medion Lifetab S10346 tablets have an Android factory img with everything hardcoded */
+static const char * const medion_lifetab_s10346_accel_mount_matrix[] = {
+ "0", "1", "0",
+ "1", "0", "0",
+ "0", "0", "1"
+};
+
+static const struct property_entry medion_lifetab_s10346_accel_props[] = {
+ PROPERTY_ENTRY_STRING_ARRAY("mount-matrix", medion_lifetab_s10346_accel_mount_matrix),
+ { }
+};
+
+static const struct software_node medion_lifetab_s10346_accel_node = {
+ .properties = medion_lifetab_s10346_accel_props,
+};
+
+/* Note the LCD panel is mounted upside down, this is correctly indicated in the VBT */
+static const struct property_entry medion_lifetab_s10346_touchscreen_props[] = {
+ PROPERTY_ENTRY_BOOL("touchscreen-inverted-x"),
+ PROPERTY_ENTRY_BOOL("touchscreen-swapped-x-y"),
+ { }
+};
+
+static const struct software_node medion_lifetab_s10346_touchscreen_node = {
+ .properties = medion_lifetab_s10346_touchscreen_props,
+};
+
+static const struct x86_i2c_client_info medion_lifetab_s10346_i2c_clients[] __initconst = {
+ {
+ /* kxtj21009 accel */
+ .board_info = {
+ .type = "kxtj21009",
+ .addr = 0x0f,
+ .dev_name = "kxtj21009",
+ .swnode = &medion_lifetab_s10346_accel_node,
+ },
+ .adapter_path = "\\_SB_.I2C3",
+ .irq_data = {
+ .type = X86_ACPI_IRQ_TYPE_GPIOINT,
+ .chip = "INT33FC:02",
+ .index = 23,
+ .trigger = ACPI_EDGE_SENSITIVE,
+ .polarity = ACPI_ACTIVE_HIGH,
+ },
+ }, {
+ /* goodix touchscreen */
+ .board_info = {
+ .type = "GDIX1001:00",
+ .addr = 0x14,
+ .dev_name = "goodix_ts",
+ .swnode = &medion_lifetab_s10346_touchscreen_node,
+ },
+ .adapter_path = "\\_SB_.I2C4",
+ .irq_data = {
+ .type = X86_ACPI_IRQ_TYPE_APIC,
+ .index = 0x44,
+ .trigger = ACPI_EDGE_SENSITIVE,
+ .polarity = ACPI_ACTIVE_LOW,
+ },
+ },
+};
+
+static struct gpiod_lookup_table medion_lifetab_s10346_goodix_gpios = {
+ .dev_id = "i2c-goodix_ts",
+ .table = {
+ GPIO_LOOKUP("INT33FC:01", 26, "reset", GPIO_ACTIVE_HIGH),
+ GPIO_LOOKUP("INT33FC:02", 3, "irq", GPIO_ACTIVE_HIGH),
+ { }
+ },
+};
+
+static struct gpiod_lookup_table * const medion_lifetab_s10346_gpios[] = {
+ &medion_lifetab_s10346_goodix_gpios,
+ NULL
+};
+
+const struct x86_dev_info medion_lifetab_s10346_info __initconst = {
+ .i2c_client_info = medion_lifetab_s10346_i2c_clients,
+ .i2c_client_count = ARRAY_SIZE(medion_lifetab_s10346_i2c_clients),
+ .gpiod_lookup_tables = medion_lifetab_s10346_gpios,
+};
+
+/* Nextbook Ares 8 tablets have an Android factory img with everything hardcoded */
+static const char * const nextbook_ares8_accel_mount_matrix[] = {
+ "0", "-1", "0",
+ "-1", "0", "0",
+ "0", "0", "1"
+};
+
+static const struct property_entry nextbook_ares8_accel_props[] = {
+ PROPERTY_ENTRY_STRING_ARRAY("mount-matrix", nextbook_ares8_accel_mount_matrix),
+ { }
+};
+
+static const struct software_node nextbook_ares8_accel_node = {
+ .properties = nextbook_ares8_accel_props,
+};
+
+static const struct property_entry nextbook_ares8_touchscreen_props[] = {
+ PROPERTY_ENTRY_U32("touchscreen-size-x", 800),
+ PROPERTY_ENTRY_U32("touchscreen-size-y", 1280),
+ { }
+};
+
+static const struct software_node nextbook_ares8_touchscreen_node = {
+ .properties = nextbook_ares8_touchscreen_props,
+};
+
+static const struct x86_i2c_client_info nextbook_ares8_i2c_clients[] __initconst = {
+ {
+ /* Freescale MMA8653FC accel */
+ .board_info = {
+ .type = "mma8653",
+ .addr = 0x1d,
+ .dev_name = "mma8653",
+ .swnode = &nextbook_ares8_accel_node,
+ },
+ .adapter_path = "\\_SB_.I2C3",
+ }, {
+ /* FT5416DQ9 touchscreen controller */
+ .board_info = {
+ .type = "edt-ft5x06",
+ .addr = 0x38,
+ .dev_name = "ft5416",
+ .swnode = &nextbook_ares8_touchscreen_node,
+ },
+ .adapter_path = "\\_SB_.I2C4",
+ .irq_data = {
+ .type = X86_ACPI_IRQ_TYPE_GPIOINT,
+ .chip = "INT33FC:02",
+ .index = 3,
+ .trigger = ACPI_EDGE_SENSITIVE,
+ .polarity = ACPI_ACTIVE_LOW,
+ },
+ },
+};
+
+static struct gpiod_lookup_table * const nextbook_ares8_gpios[] = {
+ &int3496_reference_gpios,
+ NULL
+};
+
+const struct x86_dev_info nextbook_ares8_info __initconst = {
+ .i2c_client_info = nextbook_ares8_i2c_clients,
+ .i2c_client_count = ARRAY_SIZE(nextbook_ares8_i2c_clients),
+ .pdev_info = int3496_pdevs,
+ .pdev_count = 1,
+ .gpiod_lookup_tables = nextbook_ares8_gpios,
+ .invalid_aei_gpiochip = "INT33FC:02",
+};
+
+/*
+ * Peaq C1010
+ * This is a standard Windows tablet, but it has a special Dolby button.
+ * This button has a WMI interface, but that is broken. Instead of trying to
+ * use the broken WMI interface, instantiate a gpio_keys device for this.
+ */
+static struct x86_gpio_button peaq_c1010_button = {
+ .button = {
+ .code = KEY_SOUND,
+ .active_low = true,
+ .desc = "dolby_key",
+ .type = EV_KEY,
+ .wakeup = false,
+ .debounce_interval = 50,
+ },
+ .chip = "INT33FC:00",
+ .pin = 3,
+};
+
+const struct x86_dev_info peaq_c1010_info __initconst = {
+ .gpio_button = &peaq_c1010_button,
+ /*
+ * Move the ACPI event handler used by the broken WMI interface out of
+ * the way. This is the only event handler on INT33FC:00.
+ */
+ .invalid_aei_gpiochip = "INT33FC:00",
+};
+
+/*
+ * Whitelabel (sold as various brands) TM800A550L tablets.
+ * These tablet's DSDT contains a whole bunch of bogus ACPI I2C devices
+ * (removed through acpi_quirk_skip_i2c_client_enumeration()) and
+ * the touchscreen fwnode has the wrong GPIOs.
+ */
+static const char * const whitelabel_tm800a550l_accel_mount_matrix[] = {
+ "-1", "0", "0",
+ "0", "1", "0",
+ "0", "0", "1"
+};
+
+static const struct property_entry whitelabel_tm800a550l_accel_props[] = {
+ PROPERTY_ENTRY_STRING_ARRAY("mount-matrix", whitelabel_tm800a550l_accel_mount_matrix),
+ { }
+};
+
+static const struct software_node whitelabel_tm800a550l_accel_node = {
+ .properties = whitelabel_tm800a550l_accel_props,
+};
+
+static const struct property_entry whitelabel_tm800a550l_goodix_props[] = {
+ PROPERTY_ENTRY_STRING("firmware-name", "gt912-tm800a550l.fw"),
+ PROPERTY_ENTRY_STRING("goodix,config-name", "gt912-tm800a550l.cfg"),
+ PROPERTY_ENTRY_U32("goodix,main-clk", 54),
+ { }
+};
+
+static const struct software_node whitelabel_tm800a550l_goodix_node = {
+ .properties = whitelabel_tm800a550l_goodix_props,
+};
+
+static const struct x86_i2c_client_info whitelabel_tm800a550l_i2c_clients[] __initconst = {
+ {
+ /* goodix touchscreen */
+ .board_info = {
+ .type = "GDIX1001:00",
+ .addr = 0x14,
+ .dev_name = "goodix_ts",
+ .swnode = &whitelabel_tm800a550l_goodix_node,
+ },
+ .adapter_path = "\\_SB_.I2C2",
+ .irq_data = {
+ .type = X86_ACPI_IRQ_TYPE_APIC,
+ .index = 0x44,
+ .trigger = ACPI_EDGE_SENSITIVE,
+ .polarity = ACPI_ACTIVE_HIGH,
+ },
+ }, {
+ /* kxcj91008 accel */
+ .board_info = {
+ .type = "kxcj91008",
+ .addr = 0x0f,
+ .dev_name = "kxcj91008",
+ .swnode = &whitelabel_tm800a550l_accel_node,
+ },
+ .adapter_path = "\\_SB_.I2C3",
+ },
+};
+
+static struct gpiod_lookup_table whitelabel_tm800a550l_goodix_gpios = {
+ .dev_id = "i2c-goodix_ts",
+ .table = {
+ GPIO_LOOKUP("INT33FC:01", 26, "reset", GPIO_ACTIVE_HIGH),
+ GPIO_LOOKUP("INT33FC:02", 3, "irq", GPIO_ACTIVE_HIGH),
+ { }
+ },
+};
+
+static struct gpiod_lookup_table * const whitelabel_tm800a550l_gpios[] = {
+ &whitelabel_tm800a550l_goodix_gpios,
+ NULL
+};
+
+const struct x86_dev_info whitelabel_tm800a550l_info __initconst = {
+ .i2c_client_info = whitelabel_tm800a550l_i2c_clients,
+ .i2c_client_count = ARRAY_SIZE(whitelabel_tm800a550l_i2c_clients),
+ .gpiod_lookup_tables = whitelabel_tm800a550l_gpios,
+};
+
+/*
+ * If the EFI bootloader is not Xiaomi's own signed Android loader, then the
+ * Xiaomi Mi Pad 2 X86 tablet sets OSID in the DSDT to 1 (Windows), causing
+ * a bunch of devices to be hidden.
+ *
+ * This takes care of instantiating the hidden devices manually.
+ */
+static const struct x86_i2c_client_info xiaomi_mipad2_i2c_clients[] __initconst = {
+ {
+ /* BQ27520 fuel-gauge */
+ .board_info = {
+ .type = "bq27520",
+ .addr = 0x55,
+ .dev_name = "bq27520",
+ .swnode = &fg_bq25890_supply_node,
+ },
+ .adapter_path = "\\_SB_.PCI0.I2C1",
+ }, {
+ /* KTD2026 RGB notification LED controller */
+ .board_info = {
+ .type = "ktd2026",
+ .addr = 0x30,
+ .dev_name = "ktd2026",
+ },
+ .adapter_path = "\\_SB_.PCI0.I2C3",
+ },
+};
+
+const struct x86_dev_info xiaomi_mipad2_info __initconst = {
+ .i2c_client_info = xiaomi_mipad2_i2c_clients,
+ .i2c_client_count = ARRAY_SIZE(xiaomi_mipad2_i2c_clients),
+};
diff --git a/drivers/platform/x86/x86-android-tablets/shared-psy-info.c b/drivers/platform/x86/x86-android-tablets/shared-psy-info.c
new file mode 100644
index 000000000000..d2d0aa51bc3f
--- /dev/null
+++ b/drivers/platform/x86/x86-android-tablets/shared-psy-info.c
@@ -0,0 +1,100 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Shared psy info for X86 tablets which ship with Android as the factory image
+ * and which have broken DSDT tables. The factory kernels shipped on these
+ * devices typically have a bunch of things hardcoded, rather than specified
+ * in their DSDT.
+ *
+ * Copyright (C) 2021-2023 Hans de Goede <hdegoede@redhat.com>
+ */
+
+#include <linux/gpio/machine.h>
+#include <linux/platform_device.h>
+#include <linux/power/bq24190_charger.h>
+#include <linux/property.h>
+#include <linux/regulator/machine.h>
+
+#include "shared-psy-info.h"
+
+/* Generic / shared charger / battery settings */
+const char * const tusb1211_chg_det_psy[] = { "tusb1211-charger-detect" };
+const char * const bq24190_psy[] = { "bq24190-charger" };
+const char * const bq25890_psy[] = { "bq25890-charger-0" };
+
+static const struct property_entry fg_bq24190_supply_props[] = {
+ PROPERTY_ENTRY_STRING_ARRAY("supplied-from", bq24190_psy),
+ { }
+};
+
+const struct software_node fg_bq24190_supply_node = {
+ .properties = fg_bq24190_supply_props,
+};
+
+static const struct property_entry fg_bq25890_supply_props[] = {
+ PROPERTY_ENTRY_STRING_ARRAY("supplied-from", bq25890_psy),
+ { }
+};
+
+const struct software_node fg_bq25890_supply_node = {
+ .properties = fg_bq25890_supply_props,
+};
+
+/* LiPo HighVoltage (max 4.35V) settings used by most devs with a HV bat. */
+static const struct property_entry generic_lipo_hv_4v35_battery_props[] = {
+ PROPERTY_ENTRY_STRING("compatible", "simple-battery"),
+ PROPERTY_ENTRY_STRING("device-chemistry", "lithium-ion"),
+ PROPERTY_ENTRY_U32("precharge-current-microamp", 256000),
+ PROPERTY_ENTRY_U32("charge-term-current-microamp", 128000),
+ PROPERTY_ENTRY_U32("constant-charge-current-max-microamp", 1856000),
+ PROPERTY_ENTRY_U32("constant-charge-voltage-max-microvolt", 4352000),
+ PROPERTY_ENTRY_U32("factory-internal-resistance-micro-ohms", 150000),
+ { }
+};
+
+const struct software_node generic_lipo_hv_4v35_battery_node = {
+ .properties = generic_lipo_hv_4v35_battery_props,
+};
+
+/* For enabling the bq24190 5V boost based on id-pin */
+static struct regulator_consumer_supply intel_int3496_consumer = {
+ .supply = "vbus",
+ .dev_name = "intel-int3496",
+};
+
+static const struct regulator_init_data bq24190_vbus_init_data = {
+ .constraints = {
+ .name = "bq24190_vbus",
+ .valid_ops_mask = REGULATOR_CHANGE_STATUS,
+ },
+ .consumer_supplies = &intel_int3496_consumer,
+ .num_consumer_supplies = 1,
+};
+
+struct bq24190_platform_data bq24190_pdata = {
+ .regulator_init_data = &bq24190_vbus_init_data,
+};
+
+const char * const bq24190_modules[] __initconst = {
+ "intel_crystal_cove_charger", /* For the bq24190 IRQ */
+ "bq24190_charger", /* For the Vbus regulator for intel-int3496 */
+ NULL
+};
+
+/* Generic pdevs array and gpio-lookups for micro USB ID pin handling */
+const struct platform_device_info int3496_pdevs[] __initconst = {
+ {
+ /* For micro USB ID pin handling */
+ .name = "intel-int3496",
+ .id = PLATFORM_DEVID_NONE,
+ },
+};
+
+struct gpiod_lookup_table int3496_reference_gpios = {
+ .dev_id = "intel-int3496",
+ .table = {
+ GPIO_LOOKUP("INT33FC:01", 15, "vbus", GPIO_ACTIVE_HIGH),
+ GPIO_LOOKUP("INT33FC:02", 1, "mux", GPIO_ACTIVE_HIGH),
+ GPIO_LOOKUP("INT33FC:02", 18, "id", GPIO_ACTIVE_HIGH),
+ { }
+ },
+};
diff --git a/drivers/platform/x86/x86-android-tablets/shared-psy-info.h b/drivers/platform/x86/x86-android-tablets/shared-psy-info.h
new file mode 100644
index 000000000000..c2d2968cddc2
--- /dev/null
+++ b/drivers/platform/x86/x86-android-tablets/shared-psy-info.h
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * Shared psy info for X86 tablets which ship with Android as the factory image
+ * and which have broken DSDT tables. The factory kernels shipped on these
+ * devices typically have a bunch of things hardcoded, rather than specified
+ * in their DSDT.
+ *
+ * Copyright (C) 2021-2023 Hans de Goede <hdegoede@redhat.com>
+ */
+#ifndef __PDX86_SHARED_PSY_INFO_H
+#define __PDX86_SHARED_PSY_INFO_H
+
+struct bq24190_platform_data;
+struct gpiod_lookup_table;
+struct platform_device_info;
+struct software_node;
+
+extern const char * const tusb1211_chg_det_psy[];
+extern const char * const bq24190_psy[];
+extern const char * const bq25890_psy[];
+
+extern const struct software_node fg_bq24190_supply_node;
+extern const struct software_node fg_bq25890_supply_node;
+extern const struct software_node generic_lipo_hv_4v35_battery_node;
+
+extern struct bq24190_platform_data bq24190_pdata;
+extern const char * const bq24190_modules[];
+
+extern const struct platform_device_info int3496_pdevs[];
+extern struct gpiod_lookup_table int3496_reference_gpios;
+
+#endif
diff --git a/drivers/platform/x86/x86-android-tablets/x86-android-tablets.h b/drivers/platform/x86/x86-android-tablets/x86-android-tablets.h
new file mode 100644
index 000000000000..b6802d75dbdd
--- /dev/null
+++ b/drivers/platform/x86/x86-android-tablets/x86-android-tablets.h
@@ -0,0 +1,108 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * DMI based code to deal with broken DSDTs on X86 tablets which ship with
+ * Android as (part of) the factory image. The factory kernels shipped on these
+ * devices typically have a bunch of things hardcoded, rather than specified
+ * in their DSDT.
+ *
+ * Copyright (C) 2021-2023 Hans de Goede <hdegoede@redhat.com>
+ */
+#ifndef __PDX86_X86_ANDROID_TABLETS_H
+#define __PDX86_X86_ANDROID_TABLETS_H
+
+#include <linux/gpio_keys.h>
+#include <linux/i2c.h>
+#include <linux/irqdomain_defs.h>
+
+struct gpio_desc;
+struct gpiod_lookup_table;
+struct platform_device_info;
+struct software_node;
+
+/*
+ * Helpers to get Linux IRQ numbers given a description of the IRQ source
+ * (either IOAPIC index, or GPIO chip name + pin-number).
+ */
+enum x86_acpi_irq_type {
+ X86_ACPI_IRQ_TYPE_NONE,
+ X86_ACPI_IRQ_TYPE_APIC,
+ X86_ACPI_IRQ_TYPE_GPIOINT,
+ X86_ACPI_IRQ_TYPE_PMIC,
+};
+
+struct x86_acpi_irq_data {
+ char *chip; /* GPIO chip label (GPIOINT) or PMIC ACPI path (PMIC) */
+ enum x86_acpi_irq_type type;
+ enum irq_domain_bus_token domain;
+ int index;
+ int trigger; /* ACPI_EDGE_SENSITIVE / ACPI_LEVEL_SENSITIVE */
+ int polarity; /* ACPI_ACTIVE_HIGH / ACPI_ACTIVE_LOW / ACPI_ACTIVE_BOTH */
+};
+
+/* Structs to describe devices to instantiate */
+struct x86_i2c_client_info {
+ struct i2c_board_info board_info;
+ char *adapter_path;
+ struct x86_acpi_irq_data irq_data;
+};
+
+struct x86_serdev_info {
+ const char *ctrl_hid;
+ const char *ctrl_uid;
+ const char *ctrl_devname;
+ /*
+ * ATM the serdev core only supports of or ACPI matching; and sofar all
+ * Android x86 tablets DSDTs have usable serdev nodes, but sometimes
+ * under the wrong controller. So we just tie the existing serdev ACPI
+ * node to the right controller.
+ */
+ const char *serdev_hid;
+};
+
+struct x86_gpio_button {
+ struct gpio_keys_button button;
+ const char *chip;
+ int pin;
+};
+
+struct x86_dev_info {
+ char *invalid_aei_gpiochip;
+ const char * const *modules;
+ const struct software_node *bat_swnode;
+ struct gpiod_lookup_table * const *gpiod_lookup_tables;
+ const struct x86_i2c_client_info *i2c_client_info;
+ const struct platform_device_info *pdev_info;
+ const struct x86_serdev_info *serdev_info;
+ struct x86_gpio_button *gpio_button;
+ int i2c_client_count;
+ int pdev_count;
+ int serdev_count;
+ int (*init)(void);
+ void (*exit)(void);
+};
+
+int x86_android_tablet_get_gpiod(const char *label, int pin, struct gpio_desc **desc);
+int x86_acpi_irq_helper_get(const struct x86_acpi_irq_data *data);
+
+/*
+ * Extern declarations of x86_dev_info structs so there can be a single
+ * MODULE_DEVICE_TABLE(dmi, ...), while splitting the board descriptions.
+ */
+extern const struct x86_dev_info acer_b1_750_info;
+extern const struct x86_dev_info advantech_mica_071_info;
+extern const struct x86_dev_info asus_me176c_info;
+extern const struct x86_dev_info asus_tf103c_info;
+extern const struct x86_dev_info chuwi_hi8_info;
+extern const struct x86_dev_info czc_p10t;
+extern const struct x86_dev_info lenovo_yogabook_x90_info;
+extern const struct x86_dev_info lenovo_yogabook_x91_info;
+extern const struct x86_dev_info lenovo_yoga_tab2_830_1050_info;
+extern const struct x86_dev_info lenovo_yt3_info;
+extern const struct x86_dev_info medion_lifetab_s10346_info;
+extern const struct x86_dev_info nextbook_ares8_info;
+extern const struct x86_dev_info peaq_c1010_info;
+extern const struct x86_dev_info whitelabel_tm800a550l_info;
+extern const struct x86_dev_info xiaomi_mipad2_info;
+extern const struct dmi_system_id x86_android_tablet_ids[];
+
+#endif
diff --git a/drivers/platform/x86/xo1-rfkill.c b/drivers/platform/x86/xo1-rfkill.c
index cb3253c10ef3..e64d5646b4c7 100644
--- a/drivers/platform/x86/xo1-rfkill.c
+++ b/drivers/platform/x86/xo1-rfkill.c
@@ -56,12 +56,11 @@ static int xo1_rfkill_probe(struct platform_device *pdev)
return 0;
}
-static int xo1_rfkill_remove(struct platform_device *pdev)
+static void xo1_rfkill_remove(struct platform_device *pdev)
{
struct rfkill *rfk = platform_get_drvdata(pdev);
rfkill_unregister(rfk);
rfkill_destroy(rfk);
- return 0;
}
static struct platform_driver xo1_rfkill_driver = {
@@ -69,7 +68,7 @@ static struct platform_driver xo1_rfkill_driver = {
.name = "xo1-rfkill",
},
.probe = xo1_rfkill_probe,
- .remove = xo1_rfkill_remove,
+ .remove_new = xo1_rfkill_remove,
};
module_platform_driver(xo1_rfkill_driver);
diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig
index 4c33e971c0f0..51387b1ef012 100644
--- a/drivers/video/backlight/Kconfig
+++ b/drivers/video/backlight/Kconfig
@@ -285,6 +285,7 @@ config BACKLIGHT_MT6370
config BACKLIGHT_APPLE
tristate "Apple Backlight Driver"
depends on X86 && ACPI
+ depends on ACPI_VIDEO=n || ACPI_VIDEO
help
If you have an Intel-based Apple say Y to enable a driver for its
backlight.
diff --git a/drivers/video/backlight/apple_bl.c b/drivers/video/backlight/apple_bl.c
index e9e7acb577bf..aaa824437a2a 100644
--- a/drivers/video/backlight/apple_bl.c
+++ b/drivers/video/backlight/apple_bl.c
@@ -24,7 +24,7 @@
#include <linux/pci.h>
#include <linux/acpi.h>
#include <linux/atomic.h>
-#include <linux/apple_bl.h>
+#include <acpi/video.h>
static struct backlight_device *apple_backlight_device;
@@ -215,32 +215,21 @@ static struct acpi_driver apple_bl_driver = {
},
};
-static atomic_t apple_bl_registered = ATOMIC_INIT(0);
-
-int apple_bl_register(void)
-{
- if (atomic_xchg(&apple_bl_registered, 1) == 0)
- return acpi_bus_register_driver(&apple_bl_driver);
-
- return 0;
-}
-EXPORT_SYMBOL_GPL(apple_bl_register);
-
-void apple_bl_unregister(void)
-{
- if (atomic_xchg(&apple_bl_registered, 0) == 1)
- acpi_bus_unregister_driver(&apple_bl_driver);
-}
-EXPORT_SYMBOL_GPL(apple_bl_unregister);
-
static int __init apple_bl_init(void)
{
- return apple_bl_register();
+ /*
+ * Use ACPI video detection code to see if this driver should register
+ * or if another driver, e.g. the apple-gmux driver should be used.
+ */
+ if (acpi_video_get_backlight_type() != acpi_backlight_vendor)
+ return -ENODEV;
+
+ return acpi_bus_register_driver(&apple_bl_driver);
}
static void __exit apple_bl_exit(void)
{
- apple_bl_unregister();
+ acpi_bus_unregister_driver(&apple_bl_driver);
}
module_init(apple_bl_init);
diff --git a/include/linux/apple-gmux.h b/include/linux/apple-gmux.h
index 1f68b49bcd68..206d97ffda79 100644
--- a/include/linux/apple-gmux.h
+++ b/include/linux/apple-gmux.h
@@ -34,8 +34,20 @@
#define GMUX_PORT_READ 0xd0
#define GMUX_PORT_WRITE 0xd4
+#define GMUX_MMIO_PORT_SELECT 0x0e
+#define GMUX_MMIO_COMMAND_SEND 0x0f
+
+#define GMUX_MMIO_READ 0x00
+#define GMUX_MMIO_WRITE 0x40
+
#define GMUX_MIN_IO_LEN (GMUX_PORT_BRIGHTNESS + 4)
+enum apple_gmux_type {
+ APPLE_GMUX_TYPE_PIO,
+ APPLE_GMUX_TYPE_INDEXED,
+ APPLE_GMUX_TYPE_MMIO,
+};
+
#if IS_ENABLED(CONFIG_APPLE_GMUX)
static inline bool apple_gmux_is_indexed(unsigned long iostart)
{
@@ -52,11 +64,29 @@ static inline bool apple_gmux_is_indexed(unsigned long iostart)
return false;
}
+static inline bool apple_gmux_is_mmio(unsigned long iostart)
+{
+ u8 __iomem *iomem_base = ioremap(iostart, 16);
+ u8 val;
+
+ if (!iomem_base)
+ return false;
+
+ /*
+ * If this is 0xff, then gmux must not be present, as the gmux would
+ * reset it to 0x00, or it would be one of 0x1, 0x4, 0x41, 0x44 if a
+ * command is currently being processed.
+ */
+ val = ioread8(iomem_base + GMUX_MMIO_COMMAND_SEND);
+ iounmap(iomem_base);
+ return (val != 0xff);
+}
+
/**
* apple_gmux_detect() - detect if gmux is built into the machine
*
* @pnp_dev: Device to probe or NULL to use the first matching device
- * @indexed_ret: Returns (by reference) if the gmux is indexed or not
+ * @type_ret: Returns (by reference) the apple_gmux_type of the device
*
* Detect if a supported gmux device is present by actually probing it.
* This avoids the false positives returned on some models by
@@ -65,13 +95,13 @@ static inline bool apple_gmux_is_indexed(unsigned long iostart)
* Return: %true if a supported gmux ACPI device is detected and the kernel
* was configured with CONFIG_APPLE_GMUX, %false otherwise.
*/
-static inline bool apple_gmux_detect(struct pnp_dev *pnp_dev, bool *indexed_ret)
+static inline bool apple_gmux_detect(struct pnp_dev *pnp_dev, enum apple_gmux_type *type_ret)
{
u8 ver_major, ver_minor, ver_release;
struct device *dev = NULL;
struct acpi_device *adev;
struct resource *res;
- bool indexed = false;
+ enum apple_gmux_type type = APPLE_GMUX_TYPE_PIO;
bool ret = false;
if (!pnp_dev) {
@@ -88,24 +118,30 @@ static inline bool apple_gmux_detect(struct pnp_dev *pnp_dev, bool *indexed_ret)
}
res = pnp_get_resource(pnp_dev, IORESOURCE_IO, 0);
- if (!res || resource_size(res) < GMUX_MIN_IO_LEN)
- goto out;
-
- /*
- * Invalid version information may indicate either that the gmux
- * device isn't present or that it's a new one that uses indexed io.
- */
- ver_major = inb(res->start + GMUX_PORT_VERSION_MAJOR);
- ver_minor = inb(res->start + GMUX_PORT_VERSION_MINOR);
- ver_release = inb(res->start + GMUX_PORT_VERSION_RELEASE);
- if (ver_major == 0xff && ver_minor == 0xff && ver_release == 0xff) {
- indexed = apple_gmux_is_indexed(res->start);
- if (!indexed)
+ if (res && resource_size(res) >= GMUX_MIN_IO_LEN) {
+ /*
+ * Invalid version information may indicate either that the gmux
+ * device isn't present or that it's a new one that uses indexed io.
+ */
+ ver_major = inb(res->start + GMUX_PORT_VERSION_MAJOR);
+ ver_minor = inb(res->start + GMUX_PORT_VERSION_MINOR);
+ ver_release = inb(res->start + GMUX_PORT_VERSION_RELEASE);
+ if (ver_major == 0xff && ver_minor == 0xff && ver_release == 0xff) {
+ if (apple_gmux_is_indexed(res->start))
+ type = APPLE_GMUX_TYPE_INDEXED;
+ else
+ goto out;
+ }
+ } else {
+ res = pnp_get_resource(pnp_dev, IORESOURCE_MEM, 0);
+ if (res && apple_gmux_is_mmio(res->start))
+ type = APPLE_GMUX_TYPE_MMIO;
+ else
goto out;
}
- if (indexed_ret)
- *indexed_ret = indexed;
+ if (type_ret)
+ *type_ret = type;
ret = true;
out:
diff --git a/include/linux/apple_bl.h b/include/linux/apple_bl.h
deleted file mode 100644
index 445af2e3cc21..000000000000
--- a/include/linux/apple_bl.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/*
- * apple_bl exported symbols
- */
-
-#ifndef _LINUX_APPLE_BL_H
-#define _LINUX_APPLE_BL_H
-
-#if defined(CONFIG_BACKLIGHT_APPLE) || defined(CONFIG_BACKLIGHT_APPLE_MODULE)
-
-extern int apple_bl_register(void);
-extern void apple_bl_unregister(void);
-
-#else /* !CONFIG_BACKLIGHT_APPLE */
-
-static inline int apple_bl_register(void)
-{
- return 0;
-}
-
-static inline void apple_bl_unregister(void)
-{
-}
-
-#endif /* !CONFIG_BACKLIGHT_APPLE */
-
-#endif /* _LINUX_APPLE_BL_H */
diff --git a/include/uapi/linux/isst_if.h b/include/uapi/linux/isst_if.h
index ba078f8e9add..0df1a1c3caf4 100644
--- a/include/uapi/linux/isst_if.h
+++ b/include/uapi/linux/isst_if.h
@@ -163,10 +163,313 @@ struct isst_if_msr_cmds {
struct isst_if_msr_cmd msr_cmd[1];
};
+/**
+ * struct isst_core_power - Structure to get/set core_power feature
+ * @get_set: 0: Get, 1: Set
+ * @socket_id: Socket/package id
+ * @power_domain: Power Domain id
+ * @enable: Feature enable status
+ * @priority_type: Priority type for the feature (ordered/proportional)
+ *
+ * Structure to get/set core_power feature state using IOCTL
+ * ISST_IF_CORE_POWER_STATE.
+ */
+struct isst_core_power {
+ __u8 get_set;
+ __u8 socket_id;
+ __u8 power_domain_id;
+ __u8 enable;
+ __u8 supported;
+ __u8 priority_type;
+};
+
+/**
+ * struct isst_clos_param - Structure to get/set clos praram
+ * @get_set: 0: Get, 1: Set
+ * @socket_id: Socket/package id
+ * @power_domain: Power Domain id
+ * clos: Clos ID for the parameters
+ * min_freq_mhz: Minimum frequency in MHz
+ * max_freq_mhz: Maximum frequency in MHz
+ * prop_prio: Proportional priority from 0-15
+ *
+ * Structure to get/set per clos property using IOCTL
+ * ISST_IF_CLOS_PARAM.
+ */
+struct isst_clos_param {
+ __u8 get_set;
+ __u8 socket_id;
+ __u8 power_domain_id;
+ __u8 clos;
+ __u16 min_freq_mhz;
+ __u16 max_freq_mhz;
+ __u8 prop_prio;
+};
+
+/**
+ * struct isst_if_clos_assoc - Structure to assign clos to a CPU
+ * @socket_id: Socket/package id
+ * @power_domain: Power Domain id
+ * @logical_cpu: CPU number
+ * @clos: Clos ID to assign to the logical CPU
+ *
+ * Structure to get/set core_power feature.
+ */
+struct isst_if_clos_assoc {
+ __u8 socket_id;
+ __u8 power_domain_id;
+ __u16 logical_cpu;
+ __u16 clos;
+};
+
+/**
+ * struct isst_if_clos_assoc_cmds - Structure to assign clos to CPUs
+ * @cmd_count: Number of cmds (cpus) in this request
+ * @get_set: Request is for get or set
+ * @punit_cpu_map: Set to 1 if the CPU number is punit numbering not
+ * Linux CPU number
+ *
+ * Structure used to get/set associate CPUs to clos using IOCTL
+ * ISST_IF_CLOS_ASSOC.
+ */
+struct isst_if_clos_assoc_cmds {
+ __u16 cmd_count;
+ __u16 get_set;
+ __u16 punit_cpu_map;
+ struct isst_if_clos_assoc assoc_info[1];
+};
+
+/**
+ * struct isst_tpmi_instance_count - Get number of TPMI instances per socket
+ * @socket_id: Socket/package id
+ * @count: Number of instances
+ * @valid_mask: Mask of instances as there can be holes
+ *
+ * Structure used to get TPMI instances information using
+ * IOCTL ISST_IF_COUNT_TPMI_INSTANCES.
+ */
+struct isst_tpmi_instance_count {
+ __u8 socket_id;
+ __u8 count;
+ __u16 valid_mask;
+};
+
+/**
+ * struct isst_perf_level_info - Structure to get information on SST-PP levels
+ * @socket_id: Socket/package id
+ * @power_domain: Power Domain id
+ * @logical_cpu: CPU number
+ * @clos: Clos ID to assign to the logical CPU
+ * @max_level: Maximum performance level supported by the platform
+ * @feature_rev: The feature revision for SST-PP supported by the platform
+ * @level_mask: Mask of supported performance levels
+ * @current_level: Current performance level
+ * @feature_state: SST-BF and SST-TF (enabled/disabled) status at current level
+ * @locked: SST-PP performance level change is locked/unlocked
+ * @enabled: SST-PP feature is enabled or not
+ * @sst-tf_support: SST-TF support status at this level
+ * @sst-bf_support: SST-BF support status at this level
+ *
+ * Structure to get SST-PP details using IOCTL ISST_IF_PERF_LEVELS.
+ */
+struct isst_perf_level_info {
+ __u8 socket_id;
+ __u8 power_domain_id;
+ __u8 max_level;
+ __u8 feature_rev;
+ __u8 level_mask;
+ __u8 current_level;
+ __u8 feature_state;
+ __u8 locked;
+ __u8 enabled;
+ __u8 sst_tf_support;
+ __u8 sst_bf_support;
+};
+
+/**
+ * struct isst_perf_level_control - Structure to set SST-PP level
+ * @socket_id: Socket/package id
+ * @power_domain: Power Domain id
+ * @level: level to set
+ *
+ * Structure used change SST-PP level using IOCTL ISST_IF_PERF_SET_LEVEL.
+ */
+struct isst_perf_level_control {
+ __u8 socket_id;
+ __u8 power_domain_id;
+ __u8 level;
+};
+
+/**
+ * struct isst_perf_feature_control - Structure to activate SST-BF/SST-TF
+ * @socket_id: Socket/package id
+ * @power_domain: Power Domain id
+ * @feature: bit 0 = SST-BF state, bit 1 = SST-TF state
+ *
+ * Structure used to enable SST-BF/SST-TF using IOCTL ISST_IF_PERF_SET_FEATURE.
+ */
+struct isst_perf_feature_control {
+ __u8 socket_id;
+ __u8 power_domain_id;
+ __u8 feature;
+};
+
+#define TRL_MAX_BUCKETS 8
+#define TRL_MAX_LEVELS 6
+
+/**
+ * struct isst_perf_level_data_info - Structure to get SST-PP level details
+ * @socket_id: Socket/package id
+ * @power_domain: Power Domain id
+ * @level: SST-PP level for which caller wants to get information
+ * @tdp_ratio: TDP Ratio
+ * @base_freq_mhz: Base frequency in MHz
+ * @base_freq_avx2_mhz: AVX2 Base frequency in MHz
+ * @base_freq_avx512_mhz: AVX512 base frequency in MHz
+ * @base_freq_amx_mhz: AMX base frequency in MHz
+ * @thermal_design_power_w: Thermal design (TDP) power
+ * @tjunction_max_c: Max junction temperature
+ * @max_memory_freq_mhz: Max memory frequency in MHz
+ * @cooling_type: Type of cooling is used
+ * @p0_freq_mhz: core maximum frequency
+ * @p1_freq_mhz: Core TDP frequency
+ * @pn_freq_mhz: Core maximum efficiency frequency
+ * @pm_freq_mhz: Core minimum frequency
+ * @p0_fabric_freq_mhz: Fabric (Uncore) maximum frequency
+ * @p1_fabric_freq_mhz: Fabric (Uncore) TDP frequency
+ * @pn_fabric_freq_mhz: Fabric (Uncore) minimum efficiency frequency
+ * @pm_fabric_freq_mhz: Fabric (Uncore) minimum frequency
+ * @max_buckets: Maximum trl buckets
+ * @max_trl_levels: Maximum trl levels
+ * @bucket_core_counts[TRL_MAX_BUCKETS]: Number of cores per bucket
+ * @trl_freq_mhz[TRL_MAX_LEVELS][TRL_MAX_BUCKETS]: maximum frequency
+ * for a bucket and trl level
+ *
+ * Structure used to get information on frequencies and TDP for a SST-PP
+ * level using ISST_IF_GET_PERF_LEVEL_INFO.
+ */
+struct isst_perf_level_data_info {
+ __u8 socket_id;
+ __u8 power_domain_id;
+ __u16 level;
+ __u16 tdp_ratio;
+ __u16 base_freq_mhz;
+ __u16 base_freq_avx2_mhz;
+ __u16 base_freq_avx512_mhz;
+ __u16 base_freq_amx_mhz;
+ __u16 thermal_design_power_w;
+ __u16 tjunction_max_c;
+ __u16 max_memory_freq_mhz;
+ __u16 cooling_type;
+ __u16 p0_freq_mhz;
+ __u16 p1_freq_mhz;
+ __u16 pn_freq_mhz;
+ __u16 pm_freq_mhz;
+ __u16 p0_fabric_freq_mhz;
+ __u16 p1_fabric_freq_mhz;
+ __u16 pn_fabric_freq_mhz;
+ __u16 pm_fabric_freq_mhz;
+ __u16 max_buckets;
+ __u16 max_trl_levels;
+ __u16 bucket_core_counts[TRL_MAX_BUCKETS];
+ __u16 trl_freq_mhz[TRL_MAX_LEVELS][TRL_MAX_BUCKETS];
+};
+
+/**
+ * struct isst_perf_level_cpu_mask - Structure to get SST-PP level CPU mask
+ * @socket_id: Socket/package id
+ * @power_domain: Power Domain id
+ * @level: SST-PP level for which caller wants to get information
+ * @punit_cpu_map: Set to 1 if the CPU number is punit numbering not
+ * Linux CPU number. If 0 CPU buffer is copied to user space
+ * supplied cpu_buffer of size cpu_buffer_size. Punit
+ * cpu mask is copied to "mask" field.
+ * @mask: cpu mask for this PP level (punit CPU numbering)
+ * @cpu_buffer_size: size of cpu_buffer also used to return the copied CPU
+ * buffer size.
+ * @cpu_buffer: Buffer to copy CPU mask when punit_cpu_map is 0
+ *
+ * Structure used to get cpumask for a SST-PP level using
+ * IOCTL ISST_IF_GET_PERF_LEVEL_CPU_MASK. Also used to get CPU mask for
+ * IOCTL ISST_IF_GET_BASE_FREQ_CPU_MASK for SST-BF.
+ */
+struct isst_perf_level_cpu_mask {
+ __u8 socket_id;
+ __u8 power_domain_id;
+ __u8 level;
+ __u8 punit_cpu_map;
+ __u64 mask;
+ __u16 cpu_buffer_size;
+ __s8 cpu_buffer[1];
+};
+
+/**
+ * struct isst_base_freq_info - Structure to get SST-BF frequencies
+ * @socket_id: Socket/package id
+ * @power_domain: Power Domain id
+ * @level: SST-PP level for which caller wants to get information
+ * @high_base_freq_mhz: High priority CPU base frequency
+ * @low_base_freq_mhz: Low priority CPU base frequency
+ * @tjunction_max_c: Max junction temperature
+ * @thermal_design_power_w: Thermal design power in watts
+ *
+ * Structure used to get SST-BF information using
+ * IOCTL ISST_IF_GET_BASE_FREQ_INFO.
+ */
+struct isst_base_freq_info {
+ __u8 socket_id;
+ __u8 power_domain_id;
+ __u16 level;
+ __u16 high_base_freq_mhz;
+ __u16 low_base_freq_mhz;
+ __u16 tjunction_max_c;
+ __u16 thermal_design_power_w;
+};
+
+/**
+ * struct isst_turbo_freq_info - Structure to get SST-TF frequencies
+ * @socket_id: Socket/package id
+ * @power_domain: Power Domain id
+ * @level: SST-PP level for which caller wants to get information
+ * @max_clip_freqs: Maximum number of low priority core clipping frequencies
+ * @lp_clip_freq_mhz: Clip frequencies per trl level
+ * @bucket_core_counts: Maximum number of cores for a bucket
+ * @trl_freq_mhz: Frequencies per trl level for each bucket
+ *
+ * Structure used to get SST-TF information using
+ * IOCTL ISST_IF_GET_TURBO_FREQ_INFO.
+ */
+struct isst_turbo_freq_info {
+ __u8 socket_id;
+ __u8 power_domain_id;
+ __u16 level;
+ __u16 max_clip_freqs;
+ __u16 max_buckets;
+ __u16 max_trl_levels;
+ __u16 lp_clip_freq_mhz[TRL_MAX_LEVELS];
+ __u16 bucket_core_counts[TRL_MAX_BUCKETS];
+ __u16 trl_freq_mhz[TRL_MAX_LEVELS][TRL_MAX_BUCKETS];
+};
+
#define ISST_IF_MAGIC 0xFE
#define ISST_IF_GET_PLATFORM_INFO _IOR(ISST_IF_MAGIC, 0, struct isst_if_platform_info *)
#define ISST_IF_GET_PHY_ID _IOWR(ISST_IF_MAGIC, 1, struct isst_if_cpu_map *)
#define ISST_IF_IO_CMD _IOW(ISST_IF_MAGIC, 2, struct isst_if_io_regs *)
#define ISST_IF_MBOX_COMMAND _IOWR(ISST_IF_MAGIC, 3, struct isst_if_mbox_cmds *)
#define ISST_IF_MSR_COMMAND _IOWR(ISST_IF_MAGIC, 4, struct isst_if_msr_cmds *)
+
+#define ISST_IF_COUNT_TPMI_INSTANCES _IOR(ISST_IF_MAGIC, 5, struct isst_tpmi_instance_count *)
+#define ISST_IF_CORE_POWER_STATE _IOWR(ISST_IF_MAGIC, 6, struct isst_core_power *)
+#define ISST_IF_CLOS_PARAM _IOWR(ISST_IF_MAGIC, 7, struct isst_clos_param *)
+#define ISST_IF_CLOS_ASSOC _IOWR(ISST_IF_MAGIC, 8, struct isst_if_clos_assoc_cmds *)
+
+#define ISST_IF_PERF_LEVELS _IOWR(ISST_IF_MAGIC, 9, struct isst_perf_level_info *)
+#define ISST_IF_PERF_SET_LEVEL _IOW(ISST_IF_MAGIC, 10, struct isst_perf_level_control *)
+#define ISST_IF_PERF_SET_FEATURE _IOW(ISST_IF_MAGIC, 11, struct isst_perf_feature_control *)
+#define ISST_IF_GET_PERF_LEVEL_INFO _IOR(ISST_IF_MAGIC, 12, struct isst_perf_level_data_info *)
+#define ISST_IF_GET_PERF_LEVEL_CPU_MASK _IOR(ISST_IF_MAGIC, 13, struct isst_perf_level_cpu_mask *)
+#define ISST_IF_GET_BASE_FREQ_INFO _IOR(ISST_IF_MAGIC, 14, struct isst_base_freq_info *)
+#define ISST_IF_GET_BASE_FREQ_CPU_MASK _IOR(ISST_IF_MAGIC, 15, struct isst_perf_level_cpu_mask *)
+#define ISST_IF_GET_TURBO_FREQ_INFO _IOR(ISST_IF_MAGIC, 16, struct isst_turbo_freq_info *)
+
#endif
diff --git a/tools/power/x86/intel-speed-select/Build b/tools/power/x86/intel-speed-select/Build
index 81e36bd578b1..5a9637e1678c 100644
--- a/tools/power/x86/intel-speed-select/Build
+++ b/tools/power/x86/intel-speed-select/Build
@@ -1 +1 @@
-intel-speed-select-y += isst-config.o isst-core.o isst-display.o isst-daemon.o hfi-events.o
+intel-speed-select-y += isst-config.o isst-core.o isst-display.o isst-daemon.o hfi-events.o isst-core-mbox.o isst-core-tpmi.o
diff --git a/tools/power/x86/intel-speed-select/isst-config.c b/tools/power/x86/intel-speed-select/isst-config.c
index 55d0a35df41c..2ca0cedd418f 100644
--- a/tools/power/x86/intel-speed-select/isst-config.c
+++ b/tools/power/x86/intel-speed-select/isst-config.c
@@ -15,9 +15,9 @@ struct process_cmd_struct {
int arg;
};
-static const char *version_str = "v1.14";
+static const char *version_str = "v1.15";
-static const int supported_api_ver = 1;
+static const int supported_api_ver = 2;
static struct isst_if_platform_info isst_platform_info;
static char *progname;
static int debug_flag;
@@ -44,9 +44,7 @@ static int cmd_help;
static int force_online_offline;
static int auto_mode;
static int fact_enable_fail;
-
-static int mbox_delay;
-static int mbox_retries = 3;
+static int cgroupv2;
/* clos related */
static int current_clos = -1;
@@ -61,6 +59,7 @@ struct _cpu_map {
unsigned short core_id;
unsigned short pkg_id;
unsigned short die_id;
+ unsigned short punit_id;
unsigned short punit_cpu;
unsigned short punit_cpu_core;
unsigned short initialized;
@@ -79,6 +78,11 @@ FILE *get_output_file(void)
return outf;
}
+int is_debug_enabled(void)
+{
+ return debug_flag;
+}
+
void debug_printf(const char *format, ...)
{
va_list args;
@@ -110,12 +114,21 @@ int is_skx_based_platform(void)
int is_spr_platform(void)
{
- if (cpu_model == 0x8F || cpu_model == 0xCF)
+ if (cpu_model == 0x8F)
+ return 1;
+
+ return 0;
+}
+
+int is_emr_platform(void)
+{
+ if (cpu_model == 0xCF)
return 1;
return 0;
}
+
int is_icx_platform(void)
{
if (cpu_model == 0x6A || cpu_model == 0x6C)
@@ -163,6 +176,11 @@ static int update_cpu_model(void)
return 0;
}
+int api_version(void)
+{
+ return isst_platform_info.api_version;
+}
+
/* Open a file, and exit on failure */
static FILE *fopen_or_exit(const char *path, const char *mode)
{
@@ -378,6 +396,17 @@ static int get_physical_die_id(int cpu)
return ret;
}
+static int get_physical_punit_id(int cpu)
+{
+ if (cpu < 0)
+ return -1;
+
+ if (cpu_map && cpu_map[cpu].initialized)
+ return cpu_map[cpu].punit_id;
+
+ return -1;
+}
+
void set_isst_id(struct isst_id *id, int cpu)
{
id->cpu = cpu;
@@ -389,6 +418,10 @@ void set_isst_id(struct isst_id *id, int cpu)
id->die = get_physical_die_id(cpu);
if (id->die >= MAX_DIE_PER_PACKAGE)
id->die = -1;
+
+ id->punit = get_physical_punit_id(cpu);
+ if (id->punit >= MAX_PUNIT_PER_DIE)
+ id->punit = -1;
}
int is_cpu_in_power_domain(int cpu, struct isst_id *id)
@@ -397,7 +430,7 @@ int is_cpu_in_power_domain(int cpu, struct isst_id *id)
set_isst_id(&tid, cpu);
- if (id->pkg == tid.pkg && id->die == tid.die)
+ if (id->pkg == tid.pkg && id->die == tid.die && id->punit == tid.punit)
return 1;
return 0;
@@ -481,51 +514,59 @@ static void force_all_cpus_online(void)
unlink("/var/run/isst_cpu_topology.dat");
}
-void for_each_online_package_in_set(void (*callback)(struct isst_id *, void *, void *,
+void for_each_online_power_domain_in_set(void (*callback)(struct isst_id *, void *, void *,
void *, void *),
void *arg1, void *arg2, void *arg3,
void *arg4)
{
- int max_packages[MAX_PACKAGE_COUNT * MAX_PACKAGE_COUNT];
- int pkg_index = 0, i;
struct isst_id id;
+ int cpus[MAX_PACKAGE_COUNT][MAX_DIE_PER_PACKAGE][MAX_PUNIT_PER_DIE];
+ int valid_mask[MAX_PACKAGE_COUNT][MAX_DIE_PER_PACKAGE] = {0};
+ int i, j, k;
+
+ memset(cpus, -1, sizeof(cpus));
- memset(max_packages, 0xff, sizeof(max_packages));
for (i = 0; i < topo_max_cpus; ++i) {
- int j, online, pkg_id, die_id = 0, skip = 0;
+ int online;
if (!CPU_ISSET_S(i, present_cpumask_size, present_cpumask))
continue;
- if (i)
- online = parse_int_file(
- 1, "/sys/devices/system/cpu/cpu%d/online", i);
- else
- online =
- 1; /* online entry for CPU 0 needs some special configs */
- die_id = get_physical_die_id(i);
- if (die_id < 0)
- die_id = 0;
+ online = parse_int_file(
+ i != 0, "/sys/devices/system/cpu/cpu%d/online", i);
+ if (online < 0)
+ online = 1; /* online entry for CPU 0 needs some special configs */
- pkg_id = parse_int_file(0,
- "/sys/devices/system/cpu/cpu%d/topology/physical_package_id", i);
- if (pkg_id < 0)
+ if (!online)
continue;
- /* Create an unique id for package, die combination to store */
- pkg_id = (MAX_PACKAGE_COUNT * pkg_id + die_id);
+ set_isst_id(&id, i);
- for (j = 0; j < pkg_index; ++j) {
- if (max_packages[j] == pkg_id) {
- skip = 1;
- break;
- }
- }
+ if (id.pkg < 0 || id.die < 0 || id.punit < 0)
+ continue;
- set_isst_id(&id, i);
- if (!skip && online && callback) {
- callback(&id, arg1, arg2, arg3, arg4);
- max_packages[pkg_index++] = pkg_id;
+ valid_mask[id.pkg][id.die] = 1;
+
+ if (cpus[id.pkg][id.die][id.punit] == -1)
+ cpus[id.pkg][id.die][id.punit] = i;
+ }
+
+ for (i = 0; i < MAX_PACKAGE_COUNT; i++) {
+ for (j = 0; j < MAX_DIE_PER_PACKAGE; j++) {
+ /*
+ * Fix me:
+ * How to check a non-cpu die for a package/die with all cpu offlined?
+ */
+ if (!valid_mask[i][j])
+ continue;
+ for (k = 0; k < MAX_PUNIT_PER_DIE; k++) {
+ id.cpu = cpus[i][j][k];
+ id.pkg = i;
+ id.die = j;
+ id.punit = k;
+ if (isst_is_punit_valid(&id))
+ callback(&id, arg1, arg2, arg3, arg4);
+ }
}
}
}
@@ -610,7 +651,7 @@ void free_cpu_set(cpu_set_t *cpu_set)
CPU_FREE(cpu_set);
}
-static int cpu_cnt[MAX_PACKAGE_COUNT][MAX_DIE_PER_PACKAGE];
+static int cpu_cnt[MAX_PACKAGE_COUNT][MAX_DIE_PER_PACKAGE][MAX_PUNIT_PER_DIE];
int get_max_punit_core_id(struct isst_id *id)
{
@@ -632,10 +673,50 @@ int get_max_punit_core_id(struct isst_id *id)
int get_cpu_count(struct isst_id *id)
{
- if (id->pkg < 0 || id->die < 0)
+ if (id->pkg < 0 || id->die < 0 || id->punit < 0)
return 0;
- return cpu_cnt[id->pkg][id->die];
+ return cpu_cnt[id->pkg][id->die][id->punit];
+}
+
+static void update_punit_cpu_info(__u32 physical_cpu, struct _cpu_map *cpu_map)
+{
+ if (api_version() > 1) {
+ /*
+ * MSR 0x54 format
+ * [15:11] PM_DOMAIN_ID
+ * [10:3] MODULE_ID (aka IDI_AGENT_ID)
+ * [2:0] LP_ID (We don't care about these bits we only
+ * care die and core id
+ * For Atom:
+ * [2] Always 0
+ * [1:0] core ID within module
+ * For Core
+ * [2:1] Always 0
+ * [0] thread ID
+ */
+ cpu_map->punit_id = (physical_cpu >> 11) & 0x1f;
+ cpu_map->punit_cpu_core = (physical_cpu >> 3) & 0xff;
+ cpu_map->punit_cpu = physical_cpu & 0x7ff;
+ } else {
+ int punit_id;
+
+ /*
+ * MSR 0x53 format
+ * Format
+ * Bit 0 – thread ID
+ * Bit 8:1 – core ID
+ * Bit 13:9 – punit ID
+ */
+ cpu_map->punit_cpu = physical_cpu & 0x1ff;
+ cpu_map->punit_cpu_core = (cpu_map->punit_cpu >> 1); // shift to get core id
+ punit_id = (physical_cpu >> 9) & 0x1f;
+
+ if (punit_id >= MAX_PUNIT_PER_DIE)
+ punit_id = 0;
+
+ cpu_map->punit_id = punit_id;
+ }
}
static void create_cpu_map(void)
@@ -660,7 +741,7 @@ static void create_cpu_map(void)
for (i = 0; i < topo_max_cpus; ++i) {
char buffer[256];
- int pkg_id, die_id, core_id;
+ int pkg_id, die_id, core_id, punit_id;
/* check if CPU is online */
snprintf(buffer, sizeof(buffer),
@@ -682,31 +763,32 @@ static void create_cpu_map(void)
cpu_map[i].pkg_id = pkg_id;
cpu_map[i].die_id = die_id;
cpu_map[i].core_id = core_id;
- cpu_map[i].initialized = 1;
- cpu_cnt[pkg_id][die_id]++;
- if (fd < 0)
- continue;
- map.cmd_count = 1;
- map.cpu_map[0].logical_cpu = i;
- debug_printf(" map logical_cpu:%d\n",
- map.cpu_map[0].logical_cpu);
- if (ioctl(fd, ISST_IF_GET_PHY_ID, &map) == -1) {
- perror("ISST_IF_GET_PHY_ID");
- fprintf(outf, "Error: map logical_cpu:%d\n",
- map.cpu_map[0].logical_cpu);
- continue;
+ punit_id = 0;
+
+ if (fd >= 0) {
+ map.cmd_count = 1;
+ map.cpu_map[0].logical_cpu = i;
+ debug_printf(" map logical_cpu:%d\n",
+ map.cpu_map[0].logical_cpu);
+ if (ioctl(fd, ISST_IF_GET_PHY_ID, &map) == -1) {
+ perror("ISST_IF_GET_PHY_ID");
+ fprintf(outf, "Error: map logical_cpu:%d\n",
+ map.cpu_map[0].logical_cpu);
+ } else {
+ update_punit_cpu_info(map.cpu_map[0].physical_cpu, &cpu_map[i]);
+ }
}
- cpu_map[i].punit_cpu = map.cpu_map[0].physical_cpu;
- cpu_map[i].punit_cpu_core = (map.cpu_map[0].physical_cpu >>
- 1); // shift to get core id
+ cpu_map[i].initialized = 1;
+
+ cpu_cnt[pkg_id][die_id][punit_id]++;
debug_printf(
- "map logical_cpu:%d core: %d die:%d pkg:%d punit_cpu:%d punit_core:%d\n",
+ "map logical_cpu:%d core: %d die:%d pkg:%d punit:%d punit_cpu:%d punit_core:%d\n",
i, cpu_map[i].core_id, cpu_map[i].die_id,
- cpu_map[i].pkg_id, cpu_map[i].punit_cpu,
- cpu_map[i].punit_cpu_core);
+ cpu_map[i].pkg_id, cpu_map[i].punit_id,
+ cpu_map[i].punit_cpu, cpu_map[i].punit_cpu_core);
}
if (fd >= 0)
close(fd);
@@ -728,6 +810,9 @@ void set_cpu_mask_from_punit_coremask(struct isst_id *id, unsigned long long cor
{
int i, cnt = 0;
+ if (id->cpu < 0)
+ return;
+
*cpu_cnt = 0;
for (i = 0; i < 64; ++i) {
@@ -759,182 +844,135 @@ int find_phy_core_num(int logical_cpu)
return -EINVAL;
}
-static int isst_send_mmio_command(unsigned int cpu, unsigned int reg, int write,
- unsigned int *value)
+int use_cgroupv2(void)
{
- struct isst_if_io_regs io_regs;
- const char *pathname = "/dev/isst_interface";
- int cmd;
- int fd;
-
- debug_printf("mmio_cmd cpu:%d reg:%d write:%d\n", cpu, reg, write);
+ return cgroupv2;
+}
- fd = open(pathname, O_RDWR);
- if (fd < 0)
- err(-1, "%s open failed", pathname);
+int enable_cpuset_controller(void)
+{
+ int fd, ret;
- io_regs.req_count = 1;
- io_regs.io_reg[0].logical_cpu = cpu;
- io_regs.io_reg[0].reg = reg;
- cmd = ISST_IF_IO_CMD;
- if (write) {
- io_regs.io_reg[0].read_write = 1;
- io_regs.io_reg[0].value = *value;
- } else {
- io_regs.io_reg[0].read_write = 0;
+ fd = open("/sys/fs/cgroup/cgroup.subtree_control", O_RDWR, 0);
+ if (fd < 0) {
+ debug_printf("Can't activate cpuset controller\n");
+ debug_printf("Either you are not root user or CGroup v2 is not supported\n");
+ return fd;
}
- if (ioctl(fd, cmd, &io_regs) == -1) {
- if (errno == ENOTTY) {
- perror("ISST_IF_IO_COMMAND\n");
- fprintf(stderr, "Check presence of kernel modules: isst_if_mmio\n");
- exit(0);
- }
- fprintf(outf, "Error: mmio_cmd cpu:%d reg:%x read_write:%x\n",
- cpu, reg, write);
- } else {
- if (!write)
- *value = io_regs.io_reg[0].value;
+ ret = write(fd, " +cpuset", strlen(" +cpuset"));
+ close(fd);
- debug_printf(
- "mmio_cmd response: cpu:%d reg:%x rd_write:%x resp:%x\n",
- cpu, reg, write, *value);
+ if (ret == -1) {
+ debug_printf("Can't activate cpuset controller: Write failed\n");
+ return ret;
}
- close(fd);
-
return 0;
}
-int isst_send_mbox_command(unsigned int cpu, unsigned char command,
- unsigned char sub_command, unsigned int parameter,
- unsigned int req_data, unsigned int *resp)
+int isolate_cpus(struct isst_id *id, int mask_size, cpu_set_t *cpu_mask, int level)
{
- const char *pathname = "/dev/isst_interface";
- int fd, retry;
- struct isst_if_mbox_cmds mbox_cmds = { 0 };
-
- debug_printf(
- "mbox_send: cpu:%d command:%x sub_command:%x parameter:%x req_data:%x\n",
- cpu, command, sub_command, parameter, req_data);
+ int i, first, curr_index, index, ret, fd;
+ static char str[512], dir_name[64];
+ static char cpuset_cpus[128];
+ int str_len = sizeof(str);
+ DIR *dir;
- if (!is_skx_based_platform() && command == CONFIG_CLOS &&
- sub_command != CLOS_PM_QOS_CONFIG) {
- unsigned int value;
- int write = 0;
- int clos_id, core_id, ret = 0;
+ snprintf(dir_name, sizeof(dir_name), "/sys/fs/cgroup/%d-%d-%d", id->pkg, id->die, id->punit);
+ dir = opendir(dir_name);
+ if (!dir) {
+ ret = mkdir(dir_name, 0744);
+ if (ret) {
+ debug_printf("Can't create dir:%s errno:%d\n", dir_name, errno);
+ return ret;
+ }
+ }
+ closedir(dir);
- debug_printf("CPU %d\n", cpu);
+ if (!level) {
+ sprintf(cpuset_cpus, "%s/cpuset.cpus.partition", dir_name);
- if (parameter & BIT(MBOX_CMD_WRITE_BIT)) {
- value = req_data;
- write = 1;
+ fd = open(cpuset_cpus, O_RDWR, 0);
+ if (fd < 0) {
+ return fd;
}
- switch (sub_command) {
- case CLOS_PQR_ASSOC:
- core_id = parameter & 0xff;
- ret = isst_send_mmio_command(
- cpu, PQR_ASSOC_OFFSET + core_id * 4, write,
- &value);
- if (!ret && !write)
- *resp = value;
- break;
- case CLOS_PM_CLOS:
- clos_id = parameter & 0x03;
- ret = isst_send_mmio_command(
- cpu, PM_CLOS_OFFSET + clos_id * 4, write,
- &value);
- if (!ret && !write)
- *resp = value;
- break;
- case CLOS_STATUS:
- break;
- default:
- break;
+ ret = write(fd, "member", strlen("member"));
+ if (ret == -1) {
+ printf("Can't update to member\n");
+ return ret;
}
- return ret;
- }
- mbox_cmds.cmd_count = 1;
- mbox_cmds.mbox_cmd[0].logical_cpu = cpu;
- mbox_cmds.mbox_cmd[0].command = command;
- mbox_cmds.mbox_cmd[0].sub_command = sub_command;
- mbox_cmds.mbox_cmd[0].parameter = parameter;
- mbox_cmds.mbox_cmd[0].req_data = req_data;
+ return 0;
+ }
- if (mbox_delay)
- usleep(mbox_delay * 1000);
+ if (!CPU_COUNT_S(mask_size, cpu_mask)) {
+ return -1;
+ }
- fd = open(pathname, O_RDWR);
- if (fd < 0)
- err(-1, "%s open failed", pathname);
+ curr_index = 0;
+ first = 1;
+ str[0] = '\0';
+ for (i = 0; i < get_topo_max_cpus(); ++i) {
+ if (!is_cpu_in_power_domain(i, id))
+ continue;
- retry = mbox_retries;
+ if (CPU_ISSET_S(i, mask_size, cpu_mask))
+ continue;
- do {
- if (ioctl(fd, ISST_IF_MBOX_COMMAND, &mbox_cmds) == -1) {
- if (errno == ENOTTY) {
- perror("ISST_IF_MBOX_COMMAND\n");
- fprintf(stderr, "Check presence of kernel modules: isst_if_mbox_pci or isst_if_mbox_msr\n");
- exit(0);
- }
- debug_printf(
- "Error: mbox_cmd cpu:%d command:%x sub_command:%x parameter:%x req_data:%x errorno:%d\n",
- cpu, command, sub_command, parameter, req_data, errno);
- --retry;
- } else {
- *resp = mbox_cmds.mbox_cmd[0].resp_data;
- debug_printf(
- "mbox_cmd response: cpu:%d command:%x sub_command:%x parameter:%x req_data:%x resp:%x\n",
- cpu, command, sub_command, parameter, req_data, *resp);
- break;
+ if (!first) {
+ index = snprintf(&str[curr_index],
+ str_len - curr_index, ",");
+ curr_index += index;
+ if (curr_index >= str_len)
+ break;
}
- } while (retry);
+ index = snprintf(&str[curr_index], str_len - curr_index, "%d",
+ i);
+ curr_index += index;
+ if (curr_index >= str_len)
+ break;
+ first = 0;
+ }
- close(fd);
+ debug_printf("isolated CPUs list: package:%d curr_index:%d [%s]\n", id->pkg, curr_index ,str);
- if (!retry) {
- debug_printf("Failed mbox command even after retries\n");
- return -1;
+ snprintf(cpuset_cpus, sizeof(cpuset_cpus), "%s/cpuset.cpus", dir_name);
+ fd = open(cpuset_cpus, O_RDWR, 0);
+ if (fd < 0) {
+ return fd;
}
- return 0;
-}
-int isst_send_msr_command(unsigned int cpu, unsigned int msr, int write,
- unsigned long long *req_resp)
-{
- struct isst_if_msr_cmds msr_cmds;
- const char *pathname = "/dev/isst_interface";
- int fd;
+ ret = write(fd, str, strlen(str));
+ close(fd);
- fd = open(pathname, O_RDWR);
- if (fd < 0)
- err(-1, "%s open failed", pathname);
+ if (ret == -1) {
+ debug_printf("Can't activate cpuset controller: Write failed\n");
+ return ret;
+ }
- msr_cmds.cmd_count = 1;
- msr_cmds.msr_cmd[0].logical_cpu = cpu;
- msr_cmds.msr_cmd[0].msr = msr;
- msr_cmds.msr_cmd[0].read_write = write;
- if (write)
- msr_cmds.msr_cmd[0].data = *req_resp;
-
- if (ioctl(fd, ISST_IF_MSR_COMMAND, &msr_cmds) == -1) {
- perror("ISST_IF_MSR_COMMAND");
- fprintf(outf, "Error: msr_cmd cpu:%d msr:%x read_write:%d\n",
- cpu, msr, write);
- } else {
- if (!write)
- *req_resp = msr_cmds.msr_cmd[0].data;
+ snprintf(cpuset_cpus, sizeof(cpuset_cpus), "%s/cpuset.cpus.partition", dir_name);
- debug_printf(
- "msr_cmd response: cpu:%d msr:%x rd_write:%x resp:%llx %llx\n",
- cpu, msr, write, *req_resp, msr_cmds.msr_cmd[0].data);
+ fd = open(cpuset_cpus, O_RDWR, 0);
+ if (fd < 0) {
+ return fd;
+ }
+
+ ret = write(fd, "isolated", strlen("isolated"));
+ if (ret == -1) {
+ debug_printf("Can't update to isolated\n");
+ ret = write(fd, "root", strlen("root"));
+ if (ret == -1)
+ debug_printf("Can't update to root\n");
}
close(fd);
+ if (ret < 0)
+ return ret;
+
return 0;
}
@@ -943,6 +981,11 @@ static int isst_fill_platform_info(void)
const char *pathname = "/dev/isst_interface";
int fd;
+ if (is_clx_n_platform()) {
+ isst_platform_info.api_version = 1;
+ goto set_platform_ops;
+ }
+
fd = open(pathname, O_RDWR);
if (fd < 0)
err(-1, "%s open failed", pathname);
@@ -959,77 +1002,96 @@ static int isst_fill_platform_info(void)
printf("Incompatible API versions; Upgrade of tool is required\n");
return -1;
}
+
+set_platform_ops:
+ if (isst_set_platform_ops(isst_platform_info.api_version)) {
+ fprintf(stderr, "Failed to set platform callbacks\n");
+ exit(0);
+ }
return 0;
}
-static void isst_print_extended_platform_info(void)
+void get_isst_status(struct isst_id *id, void *arg1, void *arg2, void *arg3, void *arg4)
{
- int cp_state, cp_cap, fact_support = 0, pbf_support = 0;
- struct isst_pkg_ctdp_level_info ctdp_level;
struct isst_pkg_ctdp pkg_dev;
- int ret, i, j;
- FILE *filep;
- struct isst_id id;
-
- for (i = 0; i < 256; ++i) {
- char path[256];
-
- snprintf(path, sizeof(path),
- "/sys/devices/system/cpu/cpu%d/topology/thread_siblings", i);
- filep = fopen(path, "r");
- if (filep)
- break;
- }
+ struct isst_id *tid = (struct isst_id *)arg2;
+ int *mask = (int *)arg3;
+ int *max_level = (int *)arg4;
+ int j, ret;
- if (!filep)
+ /* Only check the first cpu power domain */
+ if (id->cpu < 0 || tid->cpu >= 0)
return;
- fclose(filep);
-
- set_isst_id(&id, i);
- ret = isst_get_ctdp_levels(&id, &pkg_dev);
+ ret = isst_get_ctdp_levels(id, &pkg_dev);
if (ret)
return;
- if (pkg_dev.enabled) {
- fprintf(outf, "Intel(R) SST-PP (feature perf-profile) is supported\n");
- } else {
- fprintf(outf, "Intel(R) SST-PP (feature perf-profile) is not supported\n");
- fprintf(outf, "Only performance level 0 (base level) is present\n");
- }
+ if (pkg_dev.enabled)
+ *mask |= BIT(0);
if (pkg_dev.locked)
- fprintf(outf, "TDP level change control is locked\n");
- else
- fprintf(outf, "TDP level change control is unlocked, max level: %d \n", pkg_dev.levels);
+ *mask |= BIT(1);
+
+ if (*max_level < pkg_dev.levels)
+ *max_level = pkg_dev.levels;
for (j = 0; j <= pkg_dev.levels; ++j) {
- ret = isst_get_ctdp_control(&id, j, &ctdp_level);
+ struct isst_pkg_ctdp_level_info ctdp_level;
+
+ ret = isst_get_ctdp_control(id, j, &ctdp_level);
if (ret)
continue;
- if (!fact_support && ctdp_level.fact_support)
- fact_support = 1;
+ if (ctdp_level.fact_support)
+ *mask |= BIT(2);
+
+ if (ctdp_level.pbf_support)
+ *mask |= BIT(3);
+ }
+
+ tid->cpu = id->cpu;
+ tid->pkg = id->pkg;
+ tid->die = id->die;
+ tid->punit = id->punit;
+}
+
+static void isst_print_extended_platform_info(void)
+{
+ int cp_state, cp_cap;
+ struct isst_id id;
+ int mask = 0, max_level = 0;
- if (!pbf_support && ctdp_level.pbf_support)
- pbf_support = 1;
+ id.cpu = -1;
+ for_each_online_power_domain_in_set(get_isst_status, NULL, &id, &mask, &max_level);
+
+ if (mask & BIT(0)) {
+ fprintf(outf, "Intel(R) SST-PP (feature perf-profile) is supported\n");
+ } else {
+ fprintf(outf, "Intel(R) SST-PP (feature perf-profile) is not supported\n");
+ fprintf(outf, "Only performance level 0 (base level) is present\n");
}
- if (fact_support)
+ if (mask & BIT(1))
+ fprintf(outf, "TDP level change control is locked\n");
+ else
+ fprintf(outf, "TDP level change control is unlocked, max level: %d\n", max_level);
+
+ if (mask & BIT(2))
fprintf(outf, "Intel(R) SST-TF (feature turbo-freq) is supported\n");
else
fprintf(outf, "Intel(R) SST-TF (feature turbo-freq) is not supported\n");
- if (pbf_support)
+ if (mask & BIT(3))
fprintf(outf, "Intel(R) SST-BF (feature base-freq) is supported\n");
else
fprintf(outf, "Intel(R) SST-BF (feature base-freq) is not supported\n");
- ret = isst_read_pm_config(&id, &cp_state, &cp_cap);
- if (ret) {
+ if (isst_read_pm_config(&id, &cp_state, &cp_cap)) {
fprintf(outf, "Intel(R) SST-CP (feature core-power) status is unknown\n");
return;
}
+
if (cp_cap)
fprintf(outf, "Intel(R) SST-CP (feature core-power) is supported\n");
else
@@ -1038,10 +1100,6 @@ static void isst_print_extended_platform_info(void)
static void isst_print_platform_information(void)
{
- struct isst_if_platform_info platform_info;
- const char *pathname = "/dev/isst_interface";
- int fd;
-
if (is_clx_n_platform()) {
fprintf(stderr, "\nThis option in not supported on this platform\n");
exit(0);
@@ -1051,25 +1109,15 @@ static void isst_print_platform_information(void)
set_max_cpu_num();
create_cpu_map();
- fd = open(pathname, O_RDWR);
- if (fd < 0)
- err(-1, "%s open failed", pathname);
-
- if (ioctl(fd, ISST_IF_GET_PLATFORM_INFO, &platform_info) == -1) {
- perror("ISST_IF_GET_PLATFORM_INFO");
- } else {
- fprintf(outf, "Platform: API version : %d\n",
- platform_info.api_version);
- fprintf(outf, "Platform: Driver version : %d\n",
- platform_info.driver_version);
- fprintf(outf, "Platform: mbox supported : %d\n",
- platform_info.mbox_supported);
- fprintf(outf, "Platform: mmio supported : %d\n",
- platform_info.mmio_supported);
- isst_print_extended_platform_info();
- }
-
- close(fd);
+ fprintf(outf, "Platform: API version : %d\n",
+ isst_platform_info.api_version);
+ fprintf(outf, "Platform: Driver version : %d\n",
+ isst_platform_info.driver_version);
+ fprintf(outf, "Platform: mbox supported : %d\n",
+ isst_platform_info.mbox_supported);
+ fprintf(outf, "Platform: mmio supported : %d\n",
+ isst_platform_info.mmio_supported);
+ isst_print_extended_platform_info();
exit(0);
}
@@ -1110,7 +1158,7 @@ static void exec_on_get_ctdp_cpu(struct isst_id *id, void *arg1, void *arg2, voi
exec_on_get_ctdp_cpu, isst_get_ctdp_##suffix, \
&ctdp, desc, &ctdp.object); \
else \
- for_each_online_package_in_set(exec_on_get_ctdp_cpu, \
+ for_each_online_power_domain_in_set(exec_on_get_ctdp_cpu, \
isst_get_ctdp_##suffix, \
&ctdp, desc, \
&ctdp.object); \
@@ -1314,92 +1362,91 @@ static void dump_isst_config(int arg)
if (max_target_cpus)
for_each_online_target_cpu_in_set(fn, NULL, NULL, NULL, NULL);
else
- for_each_online_package_in_set(fn, NULL, NULL, NULL, NULL);
+ for_each_online_power_domain_in_set(fn, NULL, NULL, NULL, NULL);
isst_ctdp_display_information_end(outf);
}
-static int set_uncore_min_max(struct isst_id *id, int max, int freq)
-{
- char buffer[128], freq_str[16];
- int fd, ret, len;
-
- if (max)
- snprintf(buffer, sizeof(buffer),
- "/sys/devices/system/cpu/intel_uncore_frequency/package_%02d_die_%02d/max_freq_khz", id->pkg, id->die);
- else
- snprintf(buffer, sizeof(buffer),
- "/sys/devices/system/cpu/intel_uncore_frequency/package_%02d_die_%02d/min_freq_khz", id->pkg, id->die);
-
- fd = open(buffer, O_WRONLY);
- if (fd < 0)
- return fd;
-
- snprintf(freq_str, sizeof(freq_str), "%d", freq);
- len = strlen(freq_str);
- ret = write(fd, freq_str, len);
- if (ret == -1) {
- close(fd);
- return ret;
- }
- close(fd);
-
- return 0;
-}
-
static void adjust_scaling_max_from_base_freq(int cpu);
static void set_tdp_level_for_cpu(struct isst_id *id, void *arg1, void *arg2, void *arg3,
void *arg4)
{
+ struct isst_pkg_ctdp pkg_dev;
int ret;
+ ret = isst_get_ctdp_levels(id, &pkg_dev);
+ if (ret) {
+ isst_display_error_info_message(1, "Get TDP level failed", 0, 0);
+ isst_ctdp_display_information_end(outf);
+ exit(1);
+ }
+
+ if (pkg_dev.current_level == tdp_level) {
+ debug_printf("TDP level already set. Skipped\n");
+ goto display_result;
+ }
+
ret = isst_set_tdp_level(id, tdp_level);
if (ret) {
isst_display_error_info_message(1, "Set TDP level failed", 0, 0);
isst_ctdp_display_information_end(outf);
exit(1);
- } else {
- isst_display_result(id, outf, "perf-profile", "set_tdp_level",
- ret);
- if (force_online_offline) {
- struct isst_pkg_ctdp_level_info ctdp_level;
-
- /* Wait for updated base frequencies */
- usleep(2000);
-
- /* Adjusting uncore freq */
- isst_get_uncore_p0_p1_info(id, tdp_level, &ctdp_level);
- if (ctdp_level.uncore_pm)
- set_uncore_min_max(id, 0, ctdp_level.uncore_pm * 100000);
-
- if (ctdp_level.uncore_p0)
- set_uncore_min_max(id, 1, ctdp_level.uncore_p0 * 100000);
-
- fprintf(stderr, "Option is set to online/offline\n");
- ctdp_level.core_cpumask_size =
- alloc_cpu_set(&ctdp_level.core_cpumask);
- ret = isst_get_coremask_info(id, tdp_level, &ctdp_level);
- if (ret) {
- isst_display_error_info_message(1, "Can't get coremask, online/offline option is ignored", 0, 0);
- return;
- }
- if (ctdp_level.cpu_count) {
- int i, max_cpus = get_topo_max_cpus();
- for (i = 0; i < max_cpus; ++i) {
- if (!is_cpu_in_power_domain(i, id))
- continue;
- if (CPU_ISSET_S(i, ctdp_level.core_cpumask_size, ctdp_level.core_cpumask)) {
- fprintf(stderr, "online cpu %d\n", i);
- set_cpu_online_offline(i, 1);
- adjust_scaling_max_from_base_freq(i);
- } else {
- fprintf(stderr, "offline cpu %d\n", i);
- set_cpu_online_offline(i, 0);
- }
+ }
+
+display_result:
+ isst_display_result(id, outf, "perf-profile", "set_tdp_level", ret);
+ if (force_online_offline && id->cpu >= 0) {
+ struct isst_pkg_ctdp_level_info ctdp_level;
+
+ /* Wait for updated base frequencies */
+ usleep(2000);
+
+ /* Adjusting uncore freq */
+ isst_adjust_uncore_freq(id, tdp_level, &ctdp_level);
+
+ fprintf(stderr, "Option is set to online/offline\n");
+ ctdp_level.core_cpumask_size =
+ alloc_cpu_set(&ctdp_level.core_cpumask);
+ ret = isst_get_coremask_info(id, tdp_level, &ctdp_level);
+ if (ret) {
+ isst_display_error_info_message(1, "Can't get coremask, online/offline option is ignored", 0, 0);
+ goto free_mask;
+ }
+
+ if (use_cgroupv2()) {
+ int ret;
+
+ fprintf(stderr, "Using cgroup v2 in lieu of online/offline\n");
+ ret = enable_cpuset_controller();
+ if (ret)
+ goto use_offline;
+
+ ret = isolate_cpus(id, ctdp_level.core_cpumask_size, ctdp_level.core_cpumask, tdp_level);
+ if (ret)
+ goto use_offline;
+
+ goto free_mask;
+ }
+
+use_offline:
+ if (ctdp_level.cpu_count) {
+ int i, max_cpus = get_topo_max_cpus();
+ for (i = 0; i < max_cpus; ++i) {
+ if (!is_cpu_in_power_domain(i, id))
+ continue;
+ if (CPU_ISSET_S(i, ctdp_level.core_cpumask_size, ctdp_level.core_cpumask)) {
+ fprintf(stderr, "online cpu %d\n", i);
+ set_cpu_online_offline(i, 1);
+ adjust_scaling_max_from_base_freq(i);
+ } else {
+ fprintf(stderr, "offline cpu %d\n", i);
+ set_cpu_online_offline(i, 0);
}
}
}
+free_mask:
+ free_cpu_set(ctdp_level.core_cpumask);
}
}
@@ -1425,7 +1472,7 @@ static void set_tdp_level(int arg)
for_each_online_target_cpu_in_set(set_tdp_level_for_cpu, NULL,
NULL, NULL, NULL);
else
- for_each_online_package_in_set(set_tdp_level_for_cpu, NULL,
+ for_each_online_power_domain_in_set(set_tdp_level_for_cpu, NULL,
NULL, NULL, NULL);
isst_ctdp_display_information_end(outf);
}
@@ -1463,7 +1510,7 @@ static void dump_pbf_config_for_cpu(struct isst_id *id, void *arg1, void *arg2,
exit(1);
} else {
isst_pbf_display_information(id, outf, tdp_level, &pbf_info);
- isst_get_pbf_info_complete(&pbf_info);
+ free_cpu_set(pbf_info.core_cpumask);
}
}
@@ -1494,7 +1541,7 @@ static void dump_pbf_config(int arg)
if (max_target_cpus)
for_each_online_target_cpu_in_set(fn, NULL, NULL, NULL, NULL);
else
- for_each_online_package_in_set(fn, NULL, NULL, NULL, NULL);
+ for_each_online_power_domain_in_set(fn, NULL, NULL, NULL, NULL);
isst_ctdp_display_information_end(outf);
}
@@ -1662,6 +1709,9 @@ static void set_scaling_min_to_cpuinfo_max(struct isst_id *id)
{
int i;
+ if (id->cpu < 0)
+ return;
+
for (i = 0; i < get_topo_max_cpus(); ++i) {
if (!is_cpu_in_power_domain(i, id))
continue;
@@ -1679,6 +1729,9 @@ static void set_scaling_min_to_cpuinfo_min(struct isst_id *id)
{
int i;
+ if (id->cpu < 0)
+ return;
+
for (i = 0; i < get_topo_max_cpus(); ++i) {
if (!is_cpu_in_power_domain(i, id))
continue;
@@ -1758,6 +1811,9 @@ static int set_pbf_core_power(struct isst_id *id)
struct isst_pkg_ctdp pkg_dev;
int ret;
+ if (id->cpu < 0)
+ return 0;
+
ret = isst_get_ctdp_levels(id, &pkg_dev);
if (ret) {
debug_printf("isst_get_ctdp_levels failed");
@@ -1900,7 +1956,7 @@ static void set_pbf_enable(int arg)
for_each_online_target_cpu_in_set(set_pbf_for_cpu, NULL, NULL,
NULL, &enable);
else
- for_each_online_package_in_set(set_pbf_for_cpu, NULL, NULL,
+ for_each_online_power_domain_in_set(set_pbf_for_cpu, NULL, NULL,
NULL, &enable);
isst_ctdp_display_information_end(outf);
}
@@ -1946,7 +2002,7 @@ static void dump_fact_config(int arg)
for_each_online_target_cpu_in_set(dump_fact_config_for_cpu,
NULL, NULL, NULL, NULL);
else
- for_each_online_package_in_set(dump_fact_config_for_cpu, NULL,
+ for_each_online_power_domain_in_set(dump_fact_config_for_cpu, NULL,
NULL, NULL, NULL);
isst_ctdp_display_information_end(outf);
}
@@ -2003,7 +2059,7 @@ static void set_fact_for_cpu(struct isst_id *id, void *arg1, void *arg2, void *a
struct isst_pkg_ctdp pkg_dev;
ret = isst_get_ctdp_levels(id, &pkg_dev);
- if (!ret)
+ if (!ret && id->cpu >= 0)
ret = isst_set_trl(id, fact_trl);
if (ret && auto_mode)
isst_pm_qos_config(id, 0, 0);
@@ -2055,7 +2111,7 @@ static void set_fact_enable(int arg)
for_each_online_target_cpu_in_set(set_fact_for_cpu, NULL, NULL,
NULL, &enable);
else
- for_each_online_package_in_set(set_fact_for_cpu, NULL, NULL,
+ for_each_online_power_domain_in_set(set_fact_for_cpu, NULL, NULL,
NULL, &enable);
isst_ctdp_display_information_end(outf);
@@ -2194,7 +2250,7 @@ static void set_clos_enable(int arg)
for_each_online_target_cpu_in_set(enable_clos_qos_config, NULL,
NULL, NULL, &enable);
else
- for_each_online_package_in_set(enable_clos_qos_config, NULL,
+ for_each_online_power_domain_in_set(enable_clos_qos_config, NULL,
NULL, NULL, &enable);
isst_ctdp_display_information_end(outf);
}
@@ -2205,6 +2261,9 @@ static void dump_clos_config_for_cpu(struct isst_id *id, void *arg1, void *arg2,
struct isst_clos_config clos_config;
int ret;
+ if (id->cpu < 0)
+ return;
+
ret = isst_pm_get_clos(id, current_clos, &clos_config);
if (ret)
isst_display_error_info_message(1, "isst_pm_get_clos failed", 0, 0);
@@ -2233,7 +2292,7 @@ static void dump_clos_config(int arg)
for_each_online_target_cpu_in_set(dump_clos_config_for_cpu,
NULL, NULL, NULL, NULL);
else
- for_each_online_package_in_set(dump_clos_config_for_cpu, NULL,
+ for_each_online_power_domain_in_set(dump_clos_config_for_cpu, NULL,
NULL, NULL, NULL);
isst_ctdp_display_information_end(outf);
}
@@ -2269,7 +2328,7 @@ static void dump_clos_info(int arg)
for_each_online_target_cpu_in_set(get_clos_info_for_cpu, NULL,
NULL, NULL, NULL);
else
- for_each_online_package_in_set(get_clos_info_for_cpu, NULL,
+ for_each_online_power_domain_in_set(get_clos_info_for_cpu, NULL,
NULL, NULL, NULL);
isst_ctdp_display_information_end(outf);
@@ -2281,6 +2340,9 @@ static void set_clos_config_for_cpu(struct isst_id *id, void *arg1, void *arg2,
struct isst_clos_config clos_config;
int ret;
+ if (id->cpu < 0)
+ return;
+
clos_config.epp = clos_epp;
clos_config.clos_prop_prio = clos_prop_prio;
clos_config.clos_min = clos_min;
@@ -2341,7 +2403,7 @@ static void set_clos_config(int arg)
for_each_online_target_cpu_in_set(set_clos_config_for_cpu, NULL,
NULL, NULL, NULL);
else
- for_each_online_package_in_set(set_clos_config_for_cpu, NULL,
+ for_each_online_power_domain_in_set(set_clos_config_for_cpu, NULL,
NULL, NULL, NULL);
isst_ctdp_display_information_end(outf);
}
@@ -2508,7 +2570,7 @@ static void process_trl(int arg)
for_each_online_target_cpu_in_set(get_set_trl, NULL,
NULL, NULL, &arg);
else
- for_each_online_package_in_set(get_set_trl, NULL,
+ for_each_online_power_domain_in_set(get_set_trl, NULL,
NULL, NULL, &arg);
isst_ctdp_display_information_end(outf);
}
@@ -2683,7 +2745,7 @@ static void parse_cmd_args(int argc, int start, char **argv)
break;
case 'd':
clos_desired = atoi(optarg);
- clos_desired /= DISP_FREQ_MULTIPLIER;
+ clos_desired /= isst_get_disp_freq_multiplier();
break;
case 'e':
clos_epp = atoi(optarg);
@@ -2694,11 +2756,11 @@ static void parse_cmd_args(int argc, int start, char **argv)
break;
case 'n':
clos_min = atoi(optarg);
- clos_min /= DISP_FREQ_MULTIPLIER;
+ clos_min /= isst_get_disp_freq_multiplier();
break;
case 'm':
clos_max = atoi(optarg);
- clos_max /= DISP_FREQ_MULTIPLIER;
+ clos_max /= isst_get_disp_freq_multiplier();
break;
case 'p':
clos_priority_type = atoi(optarg);
@@ -2882,6 +2944,7 @@ static void usage(void)
printf("\t[-b|--oob : Start a daemon to process HFI events for perf profile change from Out of Band agent.\n");
printf("\t[-n|--no-daemon : Don't run as daemon. By default --oob will turn on daemon mode\n");
printf("\t[-w|--delay : Delay for reading config level state change in OOB poll mode.\n");
+ printf("\t[-g|--cgroupv2 : Try to use cgroup v2 CPU isolation instead of CPU online/offline.\n");
printf("\nResult format\n");
printf("\tResult display uses a common format for each command:\n");
printf("\tResults are formatted in text/JSON with\n");
@@ -2918,6 +2981,7 @@ static void cmdline(int argc, char **argv)
int oob_mode = 0;
int poll_interval = -1;
int no_daemon = 0;
+ int mbox_delay = 0, mbox_retries = 3;
static struct option long_options[] = {
{ "all-cpus-online", no_argument, 0, 'a' },
@@ -2933,6 +2997,7 @@ static void cmdline(int argc, char **argv)
{ "oob", no_argument, 0, 'b' },
{ "no-daemon", no_argument, 0, 'n' },
{ "poll-interval", required_argument, 0, 'w' },
+ { "cgroupv2", required_argument, 0, 'g' },
{ 0, 0, 0, 0 }
};
@@ -2958,8 +3023,12 @@ static void cmdline(int argc, char **argv)
fclose(fp);
}
+ ret = isst_fill_platform_info();
+ if (ret)
+ goto out;
+
progname = argv[0];
- while ((opt = getopt_long_only(argc, argv, "+c:df:hio:vabw:n", long_options,
+ while ((opt = getopt_long_only(argc, argv, "+c:df:hio:vabw:ng", long_options,
&option_index)) != -1) {
switch (opt) {
case 'a':
@@ -3018,6 +3087,9 @@ static void cmdline(int argc, char **argv)
}
poll_interval = ret;
break;
+ case 'g':
+ cgroupv2 = 1;
+ break;
default:
usage();
}
@@ -3027,6 +3099,10 @@ static void cmdline(int argc, char **argv)
usage();
exit(0);
}
+
+ isst_update_platform_param(ISST_PARAM_MBOX_DELAY, mbox_delay);
+ isst_update_platform_param(ISST_PARAM_MBOX_RETRIES, mbox_retries);
+
set_max_cpu_num();
if (force_cpus_online)
force_all_cpus_online();
@@ -3044,9 +3120,6 @@ static void cmdline(int argc, char **argv)
}
if (!is_clx_n_platform()) {
- ret = isst_fill_platform_info();
- if (ret)
- goto out;
process_command(argc, argv, isst_help_cmds, isst_cmds);
} else {
process_command(argc, argv, clx_n_help_cmds, clx_n_cmds);
diff --git a/tools/power/x86/intel-speed-select/isst-core-mbox.c b/tools/power/x86/intel-speed-select/isst-core-mbox.c
new file mode 100644
index 000000000000..24bea57f4ff5
--- /dev/null
+++ b/tools/power/x86/intel-speed-select/isst-core-mbox.c
@@ -0,0 +1,1066 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Intel Speed Select -- Enumerate and control features for Mailbox Interface
+ * Copyright (c) 2023 Intel Corporation.
+ */
+#include "isst.h"
+
+static int mbox_delay;
+static int mbox_retries = 3;
+
+#define MAX_TRL_LEVELS_EMR 5
+
+static int mbox_get_disp_freq_multiplier(void)
+{
+ return DISP_FREQ_MULTIPLIER;
+}
+
+static int mbox_get_trl_max_levels(void)
+{
+ if (is_emr_platform())
+ return MAX_TRL_LEVELS_EMR;
+
+ return 3;
+}
+
+static char *mbox_get_trl_level_name(int level)
+{
+ if (is_emr_platform()) {
+ static char level_str[18];
+
+ if (level >= MAX_TRL_LEVELS_EMR)
+ return NULL;
+
+ snprintf(level_str, sizeof(level_str), "level-%d", level);
+ return level_str;
+ }
+
+ switch (level) {
+ case 0:
+ return "sse";
+ case 1:
+ return "avx2";
+ case 2:
+ return "avx512";
+ default:
+ return NULL;
+ }
+}
+
+static void mbox_update_platform_param(enum isst_platform_param param, int value)
+{
+ switch (param) {
+ case ISST_PARAM_MBOX_DELAY:
+ mbox_delay = value;
+ break;
+ case ISST_PARAM_MBOX_RETRIES:
+ mbox_retries = value;
+ break;
+ default:
+ break;
+ }
+}
+
+static int mbox_is_punit_valid(struct isst_id *id)
+{
+ if (id->cpu < 0)
+ return 0;
+
+ if (id->pkg < 0 || id->die < 0 || id->punit)
+ return 0;
+
+ return 1;
+}
+
+static int _send_mmio_command(unsigned int cpu, unsigned int reg, int write,
+ unsigned int *value)
+{
+ struct isst_if_io_regs io_regs;
+ const char *pathname = "/dev/isst_interface";
+ int cmd;
+ FILE *outf = get_output_file();
+ int fd;
+
+ debug_printf("mmio_cmd cpu:%d reg:%d write:%d\n", cpu, reg, write);
+
+ fd = open(pathname, O_RDWR);
+ if (fd < 0)
+ err(-1, "%s open failed", pathname);
+
+ io_regs.req_count = 1;
+ io_regs.io_reg[0].logical_cpu = cpu;
+ io_regs.io_reg[0].reg = reg;
+ cmd = ISST_IF_IO_CMD;
+ if (write) {
+ io_regs.io_reg[0].read_write = 1;
+ io_regs.io_reg[0].value = *value;
+ } else {
+ io_regs.io_reg[0].read_write = 0;
+ }
+
+ if (ioctl(fd, cmd, &io_regs) == -1) {
+ if (errno == ENOTTY) {
+ perror("ISST_IF_IO_COMMAND\n");
+ fprintf(stderr, "Check presence of kernel modules: isst_if_mmio\n");
+ exit(0);
+ }
+ fprintf(outf, "Error: mmio_cmd cpu:%d reg:%x read_write:%x\n",
+ cpu, reg, write);
+ } else {
+ if (!write)
+ *value = io_regs.io_reg[0].value;
+
+ debug_printf(
+ "mmio_cmd response: cpu:%d reg:%x rd_write:%x resp:%x\n",
+ cpu, reg, write, *value);
+ }
+
+ close(fd);
+
+ return 0;
+}
+
+int _send_mbox_command(unsigned int cpu, unsigned char command,
+ unsigned char sub_command, unsigned int parameter,
+ unsigned int req_data, unsigned int *resp)
+{
+ const char *pathname = "/dev/isst_interface";
+ int fd, retry;
+ struct isst_if_mbox_cmds mbox_cmds = { 0 };
+
+ debug_printf(
+ "mbox_send: cpu:%d command:%x sub_command:%x parameter:%x req_data:%x\n",
+ cpu, command, sub_command, parameter, req_data);
+
+ if (!is_skx_based_platform() && command == CONFIG_CLOS &&
+ sub_command != CLOS_PM_QOS_CONFIG) {
+ unsigned int value;
+ int write = 0;
+ int clos_id, core_id, ret = 0;
+
+ debug_printf("CPU %d\n", cpu);
+
+ if (parameter & BIT(MBOX_CMD_WRITE_BIT)) {
+ value = req_data;
+ write = 1;
+ }
+
+ switch (sub_command) {
+ case CLOS_PQR_ASSOC:
+ core_id = parameter & 0xff;
+ ret = _send_mmio_command(
+ cpu, PQR_ASSOC_OFFSET + core_id * 4, write,
+ &value);
+ if (!ret && !write)
+ *resp = value;
+ break;
+ case CLOS_PM_CLOS:
+ clos_id = parameter & 0x03;
+ ret = _send_mmio_command(
+ cpu, PM_CLOS_OFFSET + clos_id * 4, write,
+ &value);
+ if (!ret && !write)
+ *resp = value;
+ break;
+ case CLOS_STATUS:
+ break;
+ default:
+ break;
+ }
+ return ret;
+ }
+
+ mbox_cmds.cmd_count = 1;
+ mbox_cmds.mbox_cmd[0].logical_cpu = cpu;
+ mbox_cmds.mbox_cmd[0].command = command;
+ mbox_cmds.mbox_cmd[0].sub_command = sub_command;
+ mbox_cmds.mbox_cmd[0].parameter = parameter;
+ mbox_cmds.mbox_cmd[0].req_data = req_data;
+
+ if (mbox_delay)
+ usleep(mbox_delay * 1000);
+
+ fd = open(pathname, O_RDWR);
+ if (fd < 0)
+ err(-1, "%s open failed", pathname);
+
+ retry = mbox_retries;
+ do {
+ if (ioctl(fd, ISST_IF_MBOX_COMMAND, &mbox_cmds) == -1) {
+ if (errno == ENOTTY) {
+ perror("ISST_IF_MBOX_COMMAND\n");
+ fprintf(stderr, "Check presence of kernel modules: isst_if_mbox_pci or isst_if_mbox_msr\n");
+ exit(0);
+ }
+ debug_printf(
+ "Error: mbox_cmd cpu:%d command:%x sub_command:%x parameter:%x req_data:%x errorno:%d\n",
+ cpu, command, sub_command, parameter, req_data, errno);
+ --retry;
+ } else {
+ *resp = mbox_cmds.mbox_cmd[0].resp_data;
+ debug_printf(
+ "mbox_cmd response: cpu:%d command:%x sub_command:%x parameter:%x req_data:%x resp:%x\n",
+ cpu, command, sub_command, parameter, req_data, *resp);
+ break;
+ }
+ } while (retry);
+
+ close(fd);
+
+ if (!retry) {
+ debug_printf("Failed mbox command even after retries\n");
+ return -1;
+
+ }
+
+ return 0;
+}
+
+static int mbox_read_pm_config(struct isst_id *id, int *cp_state, int *cp_cap)
+{
+ unsigned int resp;
+ int ret;
+
+ ret = _send_mbox_command(id->cpu, READ_PM_CONFIG, PM_FEATURE, 0, 0,
+ &resp);
+ if (ret)
+ return ret;
+
+ debug_printf("cpu:%d READ_PM_CONFIG resp:%x\n", id->cpu, resp);
+
+ *cp_state = resp & BIT(16);
+ *cp_cap = resp & BIT(0) ? 1 : 0;
+
+ return 0;
+}
+
+static int mbox_get_config_levels(struct isst_id *id, struct isst_pkg_ctdp *pkg_dev)
+{
+ unsigned int resp;
+ int ret;
+
+ ret = _send_mbox_command(id->cpu, CONFIG_TDP,
+ CONFIG_TDP_GET_LEVELS_INFO, 0, 0, &resp);
+ if (ret) {
+ pkg_dev->levels = 0;
+ pkg_dev->locked = 1;
+ pkg_dev->current_level = 0;
+ pkg_dev->version = 0;
+ pkg_dev->enabled = 0;
+ return 0;
+ }
+
+ debug_printf("cpu:%d CONFIG_TDP_GET_LEVELS_INFO resp:%x\n", id->cpu, resp);
+
+ pkg_dev->version = resp & 0xff;
+ pkg_dev->levels = (resp >> 8) & 0xff;
+ pkg_dev->current_level = (resp >> 16) & 0xff;
+ pkg_dev->locked = !!(resp & BIT(24));
+ pkg_dev->enabled = !!(resp & BIT(31));
+
+ return 0;
+}
+
+static int mbox_get_ctdp_control(struct isst_id *id, int config_index,
+ struct isst_pkg_ctdp_level_info *ctdp_level)
+{
+ int cp_state, cp_cap;
+ unsigned int resp;
+ int ret;
+
+ ret = _send_mbox_command(id->cpu, CONFIG_TDP,
+ CONFIG_TDP_GET_TDP_CONTROL, 0,
+ config_index, &resp);
+ if (ret)
+ return ret;
+
+ ctdp_level->fact_support = resp & BIT(0);
+ ctdp_level->pbf_support = !!(resp & BIT(1));
+ ctdp_level->fact_enabled = !!(resp & BIT(16));
+ ctdp_level->pbf_enabled = !!(resp & BIT(17));
+
+ ret = isst_read_pm_config(id, &cp_state, &cp_cap);
+ if (ret) {
+ debug_printf("cpu:%d pm_config is not supported\n", id->cpu);
+ } else {
+ debug_printf("cpu:%d pm_config SST-CP state:%d cap:%d\n", id->cpu, cp_state, cp_cap);
+ ctdp_level->sst_cp_support = cp_cap;
+ ctdp_level->sst_cp_enabled = cp_state;
+ }
+
+ debug_printf(
+ "cpu:%d CONFIG_TDP_GET_TDP_CONTROL resp:%x fact_support:%d pbf_support: %d fact_enabled:%d pbf_enabled:%d\n",
+ id->cpu, resp, ctdp_level->fact_support, ctdp_level->pbf_support,
+ ctdp_level->fact_enabled, ctdp_level->pbf_enabled);
+
+ return 0;
+}
+
+static void _get_uncore_p0_p1_info(struct isst_id *id, int config_index,
+ struct isst_pkg_ctdp_level_info *ctdp_level)
+{
+ unsigned int resp;
+ int ret;
+
+ ctdp_level->uncore_pm = 0;
+ ctdp_level->uncore_p0 = 0;
+ ctdp_level->uncore_p1 = 0;
+
+ ret = _send_mbox_command(id->cpu, CONFIG_TDP,
+ CONFIG_TDP_GET_RATIO_INFO, 0,
+ (BIT(16) | config_index) , &resp);
+ if (ret) {
+ goto try_uncore_mbox;
+ }
+
+ ctdp_level->uncore_p0 = resp & GENMASK(7, 0);
+ ctdp_level->uncore_p1 = (resp & GENMASK(15, 8)) >> 8;
+ ctdp_level->uncore_pm = (resp & GENMASK(31, 24)) >> 24;
+
+ debug_printf(
+ "cpu:%d ctdp:%d CONFIG_TDP_GET_RATIO_INFO resp:%x uncore p0:%d uncore p1:%d uncore pm:%d\n",
+ id->cpu, config_index, resp, ctdp_level->uncore_p0, ctdp_level->uncore_p1,
+ ctdp_level->uncore_pm);
+
+ return;
+
+try_uncore_mbox:
+ ret = _send_mbox_command(id->cpu, CONFIG_TDP,
+ CONFIG_TDP_GET_UNCORE_P0_P1_INFO, 0,
+ config_index, &resp);
+ if (ret) {
+ ctdp_level->uncore_p0 = 0;
+ ctdp_level->uncore_p1 = 0;
+ return;
+ }
+
+ ctdp_level->uncore_p0 = resp & GENMASK(7, 0);
+ ctdp_level->uncore_p1 = (resp & GENMASK(15, 8)) >> 8;
+ debug_printf(
+ "cpu:%d ctdp:%d CONFIG_TDP_GET_UNCORE_P0_P1_INFO resp:%x uncore p0:%d uncore p1:%d\n",
+ id->cpu, config_index, resp, ctdp_level->uncore_p0,
+ ctdp_level->uncore_p1);
+}
+
+static int _set_uncore_min_max(struct isst_id *id, int max, int freq)
+{
+ char buffer[128], freq_str[16];
+ int fd, ret, len;
+
+ if (max)
+ snprintf(buffer, sizeof(buffer),
+ "/sys/devices/system/cpu/intel_uncore_frequency/package_%02d_die_%02d/max_freq_khz", id->pkg, id->die);
+ else
+ snprintf(buffer, sizeof(buffer),
+ "/sys/devices/system/cpu/intel_uncore_frequency/package_%02d_die_%02d/min_freq_khz", id->pkg, id->die);
+
+ fd = open(buffer, O_WRONLY);
+ if (fd < 0)
+ return fd;
+
+ snprintf(freq_str, sizeof(freq_str), "%d", freq);
+ len = strlen(freq_str);
+ ret = write(fd, freq_str, len);
+ if (ret == -1) {
+ close(fd);
+ return ret;
+ }
+ close(fd);
+
+ return 0;
+}
+
+static void mbox_adjust_uncore_freq(struct isst_id *id, int config_index,
+ struct isst_pkg_ctdp_level_info *ctdp_level)
+{
+ _get_uncore_p0_p1_info(id, config_index, ctdp_level);
+ if (ctdp_level->uncore_pm)
+ _set_uncore_min_max(id, 0, ctdp_level->uncore_pm * 100000);
+
+ if (ctdp_level->uncore_p0)
+ _set_uncore_min_max(id, 1, ctdp_level->uncore_p0 * 100000);
+}
+
+static void _get_p1_info(struct isst_id *id, int config_index,
+ struct isst_pkg_ctdp_level_info *ctdp_level)
+{
+ unsigned int resp;
+ int ret;
+ ret = _send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_GET_P1_INFO, 0,
+ config_index, &resp);
+ if (ret) {
+ ctdp_level->sse_p1 = 0;
+ ctdp_level->avx2_p1 = 0;
+ ctdp_level->avx512_p1 = 0;
+ return;
+ }
+
+ ctdp_level->sse_p1 = resp & GENMASK(7, 0);
+ ctdp_level->avx2_p1 = (resp & GENMASK(15, 8)) >> 8;
+ ctdp_level->avx512_p1 = (resp & GENMASK(23, 16)) >> 16;
+ ctdp_level->amx_p1 = (resp & GENMASK(31, 24)) >> 24;
+ debug_printf(
+ "cpu:%d ctdp:%d CONFIG_TDP_GET_P1_INFO resp:%x sse_p1:%d avx2_p1:%d avx512_p1:%d amx_p1:%d\n",
+ id->cpu, config_index, resp, ctdp_level->sse_p1,
+ ctdp_level->avx2_p1, ctdp_level->avx512_p1, ctdp_level->amx_p1);
+}
+
+static void _get_uncore_mem_freq(struct isst_id *id, int config_index,
+ struct isst_pkg_ctdp_level_info *ctdp_level)
+{
+ unsigned int resp;
+ int ret;
+
+ ret = _send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_GET_MEM_FREQ,
+ 0, config_index, &resp);
+ if (ret) {
+ ctdp_level->mem_freq = 0;
+ return;
+ }
+
+ ctdp_level->mem_freq = resp & GENMASK(7, 0);
+ if (is_spr_platform() || is_emr_platform()) {
+ ctdp_level->mem_freq *= 200;
+ } else if (is_icx_platform()) {
+ if (ctdp_level->mem_freq < 7) {
+ ctdp_level->mem_freq = (12 - ctdp_level->mem_freq) * 133.33 * 2 * 10;
+ ctdp_level->mem_freq /= 10;
+ if (ctdp_level->mem_freq % 10 > 5)
+ ctdp_level->mem_freq++;
+ } else {
+ ctdp_level->mem_freq = 0;
+ }
+ } else {
+ ctdp_level->mem_freq = 0;
+ }
+ debug_printf(
+ "cpu:%d ctdp:%d CONFIG_TDP_GET_MEM_FREQ resp:%x uncore mem_freq:%d\n",
+ id->cpu, config_index, resp, ctdp_level->mem_freq);
+}
+
+static int mbox_get_tdp_info(struct isst_id *id, int config_index,
+ struct isst_pkg_ctdp_level_info *ctdp_level)
+{
+ unsigned int resp;
+ int ret;
+
+ ret = _send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_GET_TDP_INFO,
+ 0, config_index, &resp);
+ if (ret) {
+ isst_display_error_info_message(1, "Invalid level, Can't get TDP information at level", 1, config_index);
+ return ret;
+ }
+
+ ctdp_level->pkg_tdp = resp & GENMASK(14, 0);
+ ctdp_level->tdp_ratio = (resp & GENMASK(23, 16)) >> 16;
+
+ debug_printf(
+ "cpu:%d ctdp:%d CONFIG_TDP_GET_TDP_INFO resp:%x tdp_ratio:%d pkg_tdp:%d\n",
+ id->cpu, config_index, resp, ctdp_level->tdp_ratio,
+ ctdp_level->pkg_tdp);
+
+ ret = _send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_GET_TJMAX_INFO,
+ 0, config_index, &resp);
+ if (ret)
+ return ret;
+
+ ctdp_level->t_proc_hot = resp & GENMASK(7, 0);
+
+ _get_uncore_p0_p1_info(id, config_index, ctdp_level);
+ _get_p1_info(id, config_index, ctdp_level);
+ _get_uncore_mem_freq(id, config_index, ctdp_level);
+
+ debug_printf(
+ "cpu:%d ctdp:%d CONFIG_TDP_GET_TJMAX_INFO resp:%x t_proc_hot:%d\n",
+ id->cpu, config_index, resp, ctdp_level->t_proc_hot);
+
+ return 0;
+}
+
+static int mbox_get_pwr_info(struct isst_id *id, int config_index,
+ struct isst_pkg_ctdp_level_info *ctdp_level)
+{
+ unsigned int resp;
+ int ret;
+
+ ret = _send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_GET_PWR_INFO,
+ 0, config_index, &resp);
+ if (ret)
+ return ret;
+
+ ctdp_level->pkg_max_power = resp & GENMASK(14, 0);
+ ctdp_level->pkg_min_power = (resp & GENMASK(30, 16)) >> 16;
+
+ debug_printf(
+ "cpu:%d ctdp:%d CONFIG_TDP_GET_PWR_INFO resp:%x pkg_max_power:%d pkg_min_power:%d\n",
+ id->cpu, config_index, resp, ctdp_level->pkg_max_power,
+ ctdp_level->pkg_min_power);
+
+ return 0;
+}
+
+static int mbox_get_coremask_info(struct isst_id *id, int config_index,
+ struct isst_pkg_ctdp_level_info *ctdp_level)
+{
+ unsigned int resp;
+ int i, ret;
+
+ ctdp_level->cpu_count = 0;
+ for (i = 0; i < 2; ++i) {
+ unsigned long long mask;
+ int cpu_count = 0;
+
+ ret = _send_mbox_command(id->cpu, CONFIG_TDP,
+ CONFIG_TDP_GET_CORE_MASK, 0,
+ (i << 8) | config_index, &resp);
+ if (ret)
+ return ret;
+
+ debug_printf(
+ "cpu:%d ctdp:%d mask:%d CONFIG_TDP_GET_CORE_MASK resp:%x\n",
+ id->cpu, config_index, i, resp);
+
+ mask = (unsigned long long)resp << (32 * i);
+ set_cpu_mask_from_punit_coremask(id, mask,
+ ctdp_level->core_cpumask_size,
+ ctdp_level->core_cpumask,
+ &cpu_count);
+ ctdp_level->cpu_count += cpu_count;
+ debug_printf("cpu:%d ctdp:%d mask:%d cpu count:%d\n", id->cpu,
+ config_index, i, ctdp_level->cpu_count);
+ }
+
+ return 0;
+}
+
+static int mbox_get_get_trl(struct isst_id *id, int level, int avx_level, int *trl)
+{
+ unsigned int req, resp;
+ int ret;
+
+ req = level | (avx_level << 16);
+ ret = _send_mbox_command(id->cpu, CONFIG_TDP,
+ CONFIG_TDP_GET_TURBO_LIMIT_RATIOS, 0, req,
+ &resp);
+ if (ret)
+ return ret;
+
+ debug_printf(
+ "cpu:%d CONFIG_TDP_GET_TURBO_LIMIT_RATIOS req:%x resp:%x\n",
+ id->cpu, req, resp);
+
+ trl[0] = resp & GENMASK(7, 0);
+ trl[1] = (resp & GENMASK(15, 8)) >> 8;
+ trl[2] = (resp & GENMASK(23, 16)) >> 16;
+ trl[3] = (resp & GENMASK(31, 24)) >> 24;
+
+ req = level | BIT(8) | (avx_level << 16);
+ ret = _send_mbox_command(id->cpu, CONFIG_TDP,
+ CONFIG_TDP_GET_TURBO_LIMIT_RATIOS, 0, req,
+ &resp);
+ if (ret)
+ return ret;
+
+ debug_printf("cpu:%d CONFIG_TDP_GET_TURBO_LIMIT req:%x resp:%x\n", id->cpu,
+ req, resp);
+
+ trl[4] = resp & GENMASK(7, 0);
+ trl[5] = (resp & GENMASK(15, 8)) >> 8;
+ trl[6] = (resp & GENMASK(23, 16)) >> 16;
+ trl[7] = (resp & GENMASK(31, 24)) >> 24;
+
+ return 0;
+}
+
+static int mbox_get_get_trls(struct isst_id *id, int level, struct isst_pkg_ctdp_level_info *ctdp_level)
+{
+ int trl_max_levels = isst_get_trl_max_levels();
+ int i, ret;
+
+ for (i = 0; i < trl_max_levels; i++) {
+ ret = mbox_get_get_trl(id, level, i, ctdp_level->trl_ratios[i]);
+ if (ret)
+ return ret;
+ }
+ return 0;
+}
+
+static int mbox_get_trl_bucket_info(struct isst_id *id, int level, unsigned long long *buckets_info)
+{
+ int ret;
+
+ debug_printf("cpu:%d bucket info via MSR\n", id->cpu);
+
+ *buckets_info = 0;
+
+ ret = isst_send_msr_command(id->cpu, 0x1ae, 0, buckets_info);
+ if (ret)
+ return ret;
+
+ debug_printf("cpu:%d bucket info via MSR successful 0x%llx\n", id->cpu,
+ *buckets_info);
+
+ return 0;
+}
+
+static int mbox_set_tdp_level(struct isst_id *id, int tdp_level)
+{
+ unsigned int resp;
+ int ret;
+
+
+ if (isst_get_config_tdp_lock_status(id)) {
+ isst_display_error_info_message(1, "TDP is locked", 0, 0);
+ return -1;
+
+ }
+
+ ret = _send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_SET_LEVEL, 0,
+ tdp_level, &resp);
+ if (ret) {
+ isst_display_error_info_message(1, "Set TDP level failed for level", 1, tdp_level);
+ return ret;
+ }
+
+ return 0;
+}
+
+static int mbox_get_pbf_info(struct isst_id *id, int level, struct isst_pbf_info *pbf_info)
+{
+ int max_punit_core, max_mask_index;
+ unsigned int req, resp;
+ int i, ret;
+
+ max_punit_core = get_max_punit_core_id(id);
+ max_mask_index = max_punit_core > 32 ? 2 : 1;
+
+ for (i = 0; i < max_mask_index; ++i) {
+ unsigned long long mask;
+ int count;
+
+ ret = _send_mbox_command(id->cpu, CONFIG_TDP,
+ CONFIG_TDP_PBF_GET_CORE_MASK_INFO,
+ 0, (i << 8) | level, &resp);
+ if (ret)
+ break;
+
+ debug_printf(
+ "cpu:%d CONFIG_TDP_PBF_GET_CORE_MASK_INFO resp:%x\n",
+ id->cpu, resp);
+
+ mask = (unsigned long long)resp << (32 * i);
+ set_cpu_mask_from_punit_coremask(id, mask,
+ pbf_info->core_cpumask_size,
+ pbf_info->core_cpumask,
+ &count);
+ }
+
+ req = level;
+ ret = _send_mbox_command(id->cpu, CONFIG_TDP,
+ CONFIG_TDP_PBF_GET_P1HI_P1LO_INFO, 0, req,
+ &resp);
+ if (ret)
+ return ret;
+
+ debug_printf("cpu:%d CONFIG_TDP_PBF_GET_P1HI_P1LO_INFO resp:%x\n", id->cpu,
+ resp);
+
+ pbf_info->p1_low = resp & 0xff;
+ pbf_info->p1_high = (resp & GENMASK(15, 8)) >> 8;
+
+ req = level;
+ ret = _send_mbox_command(
+ id->cpu, CONFIG_TDP, CONFIG_TDP_PBF_GET_TDP_INFO, 0, req, &resp);
+ if (ret)
+ return ret;
+
+ debug_printf("cpu:%d CONFIG_TDP_PBF_GET_TDP_INFO resp:%x\n", id->cpu, resp);
+
+ pbf_info->tdp = resp & 0xffff;
+
+ req = level;
+ ret = _send_mbox_command(
+ id->cpu, CONFIG_TDP, CONFIG_TDP_PBF_GET_TJ_MAX_INFO, 0, req, &resp);
+ if (ret)
+ return ret;
+
+ debug_printf("cpu:%d CONFIG_TDP_PBF_GET_TJ_MAX_INFO resp:%x\n", id->cpu,
+ resp);
+ pbf_info->t_control = (resp >> 8) & 0xff;
+ pbf_info->t_prochot = resp & 0xff;
+
+ return 0;
+}
+
+static int mbox_set_pbf_fact_status(struct isst_id *id, int pbf, int enable)
+{
+ struct isst_pkg_ctdp pkg_dev;
+ struct isst_pkg_ctdp_level_info ctdp_level;
+ int current_level;
+ unsigned int req = 0, resp;
+ int ret;
+
+ ret = isst_get_ctdp_levels(id, &pkg_dev);
+ if (ret)
+ debug_printf("cpu:%d No support for dynamic ISST\n", id->cpu);
+
+ current_level = pkg_dev.current_level;
+
+ ret = isst_get_ctdp_control(id, current_level, &ctdp_level);
+ if (ret)
+ return ret;
+
+ if (pbf) {
+ if (ctdp_level.fact_enabled)
+ req = BIT(16);
+
+ if (enable)
+ req |= BIT(17);
+ else
+ req &= ~BIT(17);
+ } else {
+
+ if (enable && !ctdp_level.sst_cp_enabled)
+ isst_display_error_info_message(0, "Make sure to execute before: core-power enable", 0, 0);
+
+ if (ctdp_level.pbf_enabled)
+ req = BIT(17);
+
+ if (enable)
+ req |= BIT(16);
+ else
+ req &= ~BIT(16);
+ }
+
+ ret = _send_mbox_command(id->cpu, CONFIG_TDP,
+ CONFIG_TDP_SET_TDP_CONTROL, 0, req, &resp);
+ if (ret)
+ return ret;
+
+ debug_printf("cpu:%d CONFIG_TDP_SET_TDP_CONTROL pbf/fact:%d req:%x\n",
+ id->cpu, pbf, req);
+
+ return 0;
+}
+
+static int _get_fact_bucket_info(struct isst_id *id, int level,
+ struct isst_fact_bucket_info *bucket_info)
+{
+ unsigned int resp;
+ int i, k, ret;
+
+ for (i = 0; i < 2; ++i) {
+ int j;
+
+ ret = _send_mbox_command(
+ id->cpu, CONFIG_TDP,
+ CONFIG_TDP_GET_FACT_HP_TURBO_LIMIT_NUMCORES, 0,
+ (i << 8) | level, &resp);
+ if (ret)
+ return ret;
+
+ debug_printf(
+ "cpu:%d CONFIG_TDP_GET_FACT_HP_TURBO_LIMIT_NUMCORES index:%d level:%d resp:%x\n",
+ id->cpu, i, level, resp);
+
+ for (j = 0; j < 4; ++j) {
+ bucket_info[j + (i * 4)].hp_cores =
+ (resp >> (j * 8)) & 0xff;
+ }
+ }
+
+ for (k = 0; k < 3; ++k) {
+ for (i = 0; i < 2; ++i) {
+ int j;
+
+ ret = _send_mbox_command(
+ id->cpu, CONFIG_TDP,
+ CONFIG_TDP_GET_FACT_HP_TURBO_LIMIT_RATIOS, 0,
+ (k << 16) | (i << 8) | level, &resp);
+ if (ret)
+ return ret;
+
+ debug_printf(
+ "cpu:%d CONFIG_TDP_GET_FACT_HP_TURBO_LIMIT_RATIOS index:%d level:%d avx:%d resp:%x\n",
+ id->cpu, i, level, k, resp);
+
+ for (j = 0; j < 4; ++j) {
+ bucket_info[j + (i * 4)].hp_ratios[k] =
+ (resp >> (j * 8)) & 0xff;
+ }
+ }
+ }
+
+ return 0;
+}
+
+static int mbox_get_fact_info(struct isst_id *id, int level, int fact_bucket, struct isst_fact_info *fact_info)
+{
+ unsigned int resp;
+ int j, ret, print;
+
+ ret = _send_mbox_command(id->cpu, CONFIG_TDP,
+ CONFIG_TDP_GET_FACT_LP_CLIPPING_RATIO, 0,
+ level, &resp);
+ if (ret)
+ return ret;
+
+ debug_printf("cpu:%d CONFIG_TDP_GET_FACT_LP_CLIPPING_RATIO resp:%x\n",
+ id->cpu, resp);
+
+ fact_info->lp_ratios[0] = resp & 0xff;
+ fact_info->lp_ratios[1] = (resp >> 8) & 0xff;
+ fact_info->lp_ratios[2] = (resp >> 16) & 0xff;
+
+ ret = _get_fact_bucket_info(id, level, fact_info->bucket_info);
+ if (ret)
+ return ret;
+
+ print = 0;
+ for (j = 0; j < ISST_FACT_MAX_BUCKETS; ++j) {
+ if (fact_bucket != 0xff && fact_bucket != j)
+ continue;
+
+ if (!fact_info->bucket_info[j].hp_cores)
+ break;
+
+ print = 1;
+ }
+ if (!print) {
+ isst_display_error_info_message(1, "Invalid bucket", 0, 0);
+ return -1;
+ }
+
+ return 0;
+}
+
+static int mbox_get_clos_information(struct isst_id *id, int *enable, int *type)
+{
+ unsigned int resp;
+ int ret;
+
+ ret = _send_mbox_command(id->cpu, CONFIG_CLOS, CLOS_PM_QOS_CONFIG, 0, 0,
+ &resp);
+ if (ret)
+ return ret;
+
+ debug_printf("cpu:%d CLOS_PM_QOS_CONFIG resp:%x\n", id->cpu, resp);
+
+ if (resp & BIT(1))
+ *enable = 1;
+ else
+ *enable = 0;
+
+ if (resp & BIT(2))
+ *type = 1;
+ else
+ *type = 0;
+
+ return 0;
+}
+
+static int _write_pm_config(struct isst_id *id, int cp_state)
+{
+ unsigned int req, resp;
+ int ret;
+
+ if (cp_state)
+ req = BIT(16);
+ else
+ req = 0;
+
+ ret = _send_mbox_command(id->cpu, WRITE_PM_CONFIG, PM_FEATURE, 0, req,
+ &resp);
+ if (ret)
+ return ret;
+
+ debug_printf("cpu:%d WRITE_PM_CONFIG resp:%x\n", id->cpu, resp);
+
+ return 0;
+}
+
+static int mbox_pm_qos_config(struct isst_id *id, int enable_clos, int priority_type)
+{
+ unsigned int req, resp;
+ int ret;
+
+ if (!enable_clos) {
+ struct isst_pkg_ctdp pkg_dev;
+ struct isst_pkg_ctdp_level_info ctdp_level;
+
+ ret = isst_get_ctdp_levels(id, &pkg_dev);
+ if (ret) {
+ debug_printf("isst_get_ctdp_levels\n");
+ return ret;
+ }
+
+ ret = isst_get_ctdp_control(id, pkg_dev.current_level,
+ &ctdp_level);
+ if (ret)
+ return ret;
+
+ if (ctdp_level.fact_enabled) {
+ isst_display_error_info_message(1, "Ignoring request, turbo-freq feature is still enabled", 0, 0);
+ return -EINVAL;
+ }
+ ret = _write_pm_config(id, 0);
+ if (ret)
+ isst_display_error_info_message(0, "WRITE_PM_CONFIG command failed, ignoring error", 0, 0);
+ } else {
+ ret = _write_pm_config(id, 1);
+ if (ret)
+ isst_display_error_info_message(0, "WRITE_PM_CONFIG command failed, ignoring error", 0, 0);
+ }
+
+ ret = _send_mbox_command(id->cpu, CONFIG_CLOS, CLOS_PM_QOS_CONFIG, 0, 0,
+ &resp);
+ if (ret) {
+ isst_display_error_info_message(1, "CLOS_PM_QOS_CONFIG command failed", 0, 0);
+ return ret;
+ }
+
+ debug_printf("cpu:%d CLOS_PM_QOS_CONFIG resp:%x\n", id->cpu, resp);
+
+ req = resp;
+
+ if (enable_clos)
+ req = req | BIT(1);
+ else
+ req = req & ~BIT(1);
+
+ if (priority_type > 1)
+ isst_display_error_info_message(1, "Invalid priority type: Changing type to ordered", 0, 0);
+
+ if (priority_type)
+ req = req | BIT(2);
+ else
+ req = req & ~BIT(2);
+
+ ret = _send_mbox_command(id->cpu, CONFIG_CLOS, CLOS_PM_QOS_CONFIG,
+ BIT(MBOX_CMD_WRITE_BIT), req, &resp);
+ if (ret)
+ return ret;
+
+ debug_printf("cpu:%d CLOS_PM_QOS_CONFIG priority type:%d req:%x\n", id->cpu,
+ priority_type, req);
+
+ return 0;
+}
+
+static int mbox_pm_get_clos(struct isst_id *id, int clos, struct isst_clos_config *clos_config)
+{
+ unsigned int resp;
+ int ret;
+
+ ret = _send_mbox_command(id->cpu, CONFIG_CLOS, CLOS_PM_CLOS, clos, 0,
+ &resp);
+ if (ret)
+ return ret;
+
+ clos_config->epp = resp & 0x0f;
+ clos_config->clos_prop_prio = (resp >> 4) & 0x0f;
+ clos_config->clos_min = (resp >> 8) & 0xff;
+ clos_config->clos_max = (resp >> 16) & 0xff;
+ clos_config->clos_desired = (resp >> 24) & 0xff;
+
+ return 0;
+}
+
+static int mbox_set_clos(struct isst_id *id, int clos, struct isst_clos_config *clos_config)
+{
+ unsigned int req, resp;
+ unsigned int param;
+ int ret;
+
+ req = clos_config->epp & 0x0f;
+ req |= (clos_config->clos_prop_prio & 0x0f) << 4;
+ req |= (clos_config->clos_min & 0xff) << 8;
+ req |= (clos_config->clos_max & 0xff) << 16;
+ req |= (clos_config->clos_desired & 0xff) << 24;
+
+ param = BIT(MBOX_CMD_WRITE_BIT) | clos;
+
+ ret = _send_mbox_command(id->cpu, CONFIG_CLOS, CLOS_PM_CLOS, param, req,
+ &resp);
+ if (ret)
+ return ret;
+
+ debug_printf("cpu:%d CLOS_PM_CLOS param:%x req:%x\n", id->cpu, param, req);
+
+ return 0;
+}
+
+static int mbox_clos_get_assoc_status(struct isst_id *id, int *clos_id)
+{
+ unsigned int resp;
+ unsigned int param;
+ int core_id, ret;
+
+ core_id = find_phy_core_num(id->cpu);
+ param = core_id;
+
+ ret = _send_mbox_command(id->cpu, CONFIG_CLOS, CLOS_PQR_ASSOC, param, 0,
+ &resp);
+ if (ret)
+ return ret;
+
+ debug_printf("cpu:%d CLOS_PQR_ASSOC param:%x resp:%x\n", id->cpu, param,
+ resp);
+ *clos_id = (resp >> 16) & 0x03;
+
+ return 0;
+}
+
+static int mbox_clos_associate(struct isst_id *id, int clos_id)
+{
+ unsigned int req, resp;
+ unsigned int param;
+ int core_id, ret;
+
+ req = (clos_id & 0x03) << 16;
+ core_id = find_phy_core_num(id->cpu);
+ param = BIT(MBOX_CMD_WRITE_BIT) | core_id;
+
+ ret = _send_mbox_command(id->cpu, CONFIG_CLOS, CLOS_PQR_ASSOC, param,
+ req, &resp);
+ if (ret)
+ return ret;
+
+ debug_printf("cpu:%d CLOS_PQR_ASSOC param:%x req:%x\n", id->cpu, param,
+ req);
+
+ return 0;
+}
+
+static struct isst_platform_ops mbox_ops = {
+ .get_disp_freq_multiplier = mbox_get_disp_freq_multiplier,
+ .get_trl_max_levels = mbox_get_trl_max_levels,
+ .get_trl_level_name = mbox_get_trl_level_name,
+ .update_platform_param = mbox_update_platform_param,
+ .is_punit_valid = mbox_is_punit_valid,
+ .read_pm_config = mbox_read_pm_config,
+ .get_config_levels = mbox_get_config_levels,
+ .get_ctdp_control = mbox_get_ctdp_control,
+ .get_tdp_info = mbox_get_tdp_info,
+ .get_pwr_info = mbox_get_pwr_info,
+ .get_coremask_info = mbox_get_coremask_info,
+ .get_get_trl = mbox_get_get_trl,
+ .get_get_trls = mbox_get_get_trls,
+ .get_trl_bucket_info = mbox_get_trl_bucket_info,
+ .set_tdp_level = mbox_set_tdp_level,
+ .get_pbf_info = mbox_get_pbf_info,
+ .set_pbf_fact_status = mbox_set_pbf_fact_status,
+ .get_fact_info = mbox_get_fact_info,
+ .adjust_uncore_freq = mbox_adjust_uncore_freq,
+ .get_clos_information = mbox_get_clos_information,
+ .pm_qos_config = mbox_pm_qos_config,
+ .pm_get_clos = mbox_pm_get_clos,
+ .set_clos = mbox_set_clos,
+ .clos_get_assoc_status = mbox_clos_get_assoc_status,
+ .clos_associate = mbox_clos_associate,
+};
+
+struct isst_platform_ops *mbox_get_platform_ops(void)
+{
+ return &mbox_ops;
+}
diff --git a/tools/power/x86/intel-speed-select/isst-core-tpmi.c b/tools/power/x86/intel-speed-select/isst-core-tpmi.c
new file mode 100644
index 000000000000..19caa9c78d41
--- /dev/null
+++ b/tools/power/x86/intel-speed-select/isst-core-tpmi.c
@@ -0,0 +1,787 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Intel Speed Select -- Enumerate and control features for TPMI Interface
+ * Copyright (c) 2022 Intel Corporation.
+ */
+
+#include <linux/isst_if.h>
+#include "isst.h"
+
+int tpmi_process_ioctl(int ioctl_no, void *info)
+{
+ const char *pathname = "/dev/isst_interface";
+ int fd;
+
+ if (is_debug_enabled()) {
+ debug_printf("Issue IOCTL: ");
+ switch (ioctl_no) {
+ case ISST_IF_CORE_POWER_STATE:
+ debug_printf("ISST_IF_CORE_POWER_STATE\n");
+ break;
+ case ISST_IF_CLOS_PARAM:
+ debug_printf("ISST_IF_CLOS_PARAM\n");
+ break;
+ case ISST_IF_CLOS_ASSOC:
+ debug_printf("ISST_IF_CLOS_ASSOC\n");
+ break;
+ case ISST_IF_PERF_LEVELS:
+ debug_printf("ISST_IF_PERF_LEVELS\n");
+ break;
+ case ISST_IF_PERF_SET_LEVEL:
+ debug_printf("ISST_IF_PERF_SET_LEVEL\n");
+ break;
+ case ISST_IF_PERF_SET_FEATURE:
+ debug_printf("ISST_IF_PERF_SET_FEATURE\n");
+ break;
+ case ISST_IF_GET_PERF_LEVEL_INFO:
+ debug_printf("ISST_IF_GET_PERF_LEVEL_INFO\n");
+ break;
+ case ISST_IF_GET_PERF_LEVEL_CPU_MASK:
+ debug_printf("ISST_IF_GET_PERF_LEVEL_CPU_MASK\n");
+ break;
+ case ISST_IF_GET_BASE_FREQ_INFO:
+ debug_printf("ISST_IF_GET_BASE_FREQ_INFO\n");
+ break;
+ case ISST_IF_GET_BASE_FREQ_CPU_MASK:
+ debug_printf("ISST_IF_GET_BASE_FREQ_CPU_MASK\n");
+ break;
+ case ISST_IF_GET_TURBO_FREQ_INFO:
+ debug_printf("ISST_IF_GET_TURBO_FREQ_INFO\n");
+ break;
+ case ISST_IF_COUNT_TPMI_INSTANCES:
+ debug_printf("ISST_IF_COUNT_TPMI_INSTANCES\n");
+ break;
+ default:
+ debug_printf("%d\n", ioctl_no);
+ break;
+ }
+ }
+
+ fd = open(pathname, O_RDWR);
+ if (fd < 0)
+ return -1;
+
+ if (ioctl(fd, ioctl_no, info) == -1) {
+ debug_printf("IOCTL %d Failed\n", ioctl_no);
+ close(fd);
+ return -1;
+ }
+
+ close(fd);
+
+ return 0;
+}
+
+static int tpmi_get_disp_freq_multiplier(void)
+{
+ return 1;
+}
+
+static int tpmi_get_trl_max_levels(void)
+{
+ return TRL_MAX_LEVELS;
+}
+
+static char *tpmi_get_trl_level_name(int level)
+{
+ switch (level) {
+ case 0:
+ return "level-0";
+ case 1:
+ return "level-1";
+ case 2:
+ return "level-2";
+ case 3:
+ return "level-3";
+ case 4:
+ return "level-4";
+ case 5:
+ return "level-5";
+ case 6:
+ return "level-6";
+ case 7:
+ return "level-7";
+ default:
+ return NULL;
+ }
+}
+
+
+static void tpmi_update_platform_param(enum isst_platform_param param, int value)
+{
+ /* No params need to be updated for now */
+}
+
+static int tpmi_is_punit_valid(struct isst_id *id)
+{
+ struct isst_tpmi_instance_count info;
+ int ret;
+
+ if (id->punit < 0)
+ return 0;
+
+ info.socket_id = id->pkg;
+ ret = tpmi_process_ioctl(ISST_IF_COUNT_TPMI_INSTANCES, &info);
+ if (ret == -1)
+ return 0;
+
+ if (info.valid_mask & BIT(id->punit))
+ return 1;
+
+ return 0;
+}
+
+static int tpmi_read_pm_config(struct isst_id *id, int *cp_state, int *cp_cap)
+{
+ struct isst_core_power info;
+ int ret;
+
+ info.get_set = 0;
+ info.socket_id = id->pkg;
+ info.power_domain_id = id->punit;
+ ret = tpmi_process_ioctl(ISST_IF_CORE_POWER_STATE, &info);
+ if (ret == -1)
+ return ret;
+
+ *cp_state = info.enable;
+ *cp_cap = info.supported;
+
+ return 0;
+}
+
+int tpmi_get_config_levels(struct isst_id *id, struct isst_pkg_ctdp *pkg_dev)
+{
+ struct isst_perf_level_info info;
+ int ret;
+
+ info.socket_id = id->pkg;
+ info.power_domain_id = id->punit;
+
+ ret = tpmi_process_ioctl(ISST_IF_PERF_LEVELS, &info);
+ if (ret == -1)
+ return ret;
+
+ pkg_dev->version = info.feature_rev;
+ pkg_dev->levels = info.max_level;
+ pkg_dev->locked = info.locked;
+ pkg_dev->current_level = info.current_level;
+ pkg_dev->locked = info.locked;
+ pkg_dev->enabled = info.enabled;
+
+ return 0;
+}
+
+static int tpmi_get_ctdp_control(struct isst_id *id, int config_index,
+ struct isst_pkg_ctdp_level_info *ctdp_level)
+{
+ struct isst_core_power core_power_info;
+ struct isst_perf_level_info info;
+ int level_mask;
+ int ret;
+
+ info.socket_id = id->pkg;
+ info.power_domain_id = id->punit;
+
+ ret = tpmi_process_ioctl(ISST_IF_PERF_LEVELS, &info);
+ if (ret == -1)
+ return -1;
+
+ if (config_index != 0xff)
+ level_mask = 1 << config_index;
+ else
+ level_mask = config_index;
+
+ if (!(info.level_mask & level_mask))
+ return -1;
+
+ ctdp_level->fact_support = info.sst_tf_support;
+ ctdp_level->pbf_support = info.sst_bf_support;
+ ctdp_level->fact_enabled = !!(info.feature_state & BIT(1));
+ ctdp_level->pbf_enabled = !!(info.feature_state & BIT(0));
+
+ core_power_info.get_set = 0;
+ core_power_info.socket_id = id->pkg;
+ core_power_info.power_domain_id = id->punit;
+
+ ret = tpmi_process_ioctl(ISST_IF_CORE_POWER_STATE, &core_power_info);
+ if (ret == -1)
+ return ret;
+
+ ctdp_level->sst_cp_support = core_power_info.supported;
+ ctdp_level->sst_cp_enabled = core_power_info.enable;
+
+ debug_printf
+ ("cpu:%d CONFIG_TDP_GET_TDP_CONTROL fact_support:%d pbf_support: %d fact_enabled:%d pbf_enabled:%d\n",
+ id->cpu, ctdp_level->fact_support, ctdp_level->pbf_support,
+ ctdp_level->fact_enabled, ctdp_level->pbf_enabled);
+
+ return 0;
+}
+
+static int tpmi_get_tdp_info(struct isst_id *id, int config_index,
+ struct isst_pkg_ctdp_level_info *ctdp_level)
+{
+ struct isst_perf_level_data_info info;
+ int ret;
+
+ info.socket_id = id->pkg;
+ info.power_domain_id = id->punit;
+ info.level = config_index;
+
+ ret = tpmi_process_ioctl(ISST_IF_GET_PERF_LEVEL_INFO, &info);
+ if (ret == -1)
+ return ret;
+
+ ctdp_level->pkg_tdp = info.thermal_design_power_w;
+ ctdp_level->tdp_ratio = info.tdp_ratio;
+ ctdp_level->sse_p1 = info.base_freq_mhz;
+ ctdp_level->avx2_p1 = info.base_freq_avx2_mhz;
+ ctdp_level->avx512_p1 = info.base_freq_avx512_mhz;
+ ctdp_level->amx_p1 = info.base_freq_amx_mhz;
+
+ ctdp_level->t_proc_hot = info.tjunction_max_c;
+ ctdp_level->mem_freq = info.max_memory_freq_mhz;
+ ctdp_level->cooling_type = info.cooling_type;
+
+ ctdp_level->uncore_p0 = info.p0_fabric_freq_mhz;
+ ctdp_level->uncore_p1 = info.p1_fabric_freq_mhz;
+ ctdp_level->uncore_pm = info.pm_fabric_freq_mhz;
+
+ debug_printf
+ ("cpu:%d ctdp:%d CONFIG_TDP_GET_TDP_INFO tdp_ratio:%d pkg_tdp:%d ctdp_level->t_proc_hot:%d\n",
+ id->cpu, config_index, ctdp_level->tdp_ratio, ctdp_level->pkg_tdp,
+ ctdp_level->t_proc_hot);
+
+ return 0;
+}
+
+static int tpmi_get_pwr_info(struct isst_id *id, int config_index,
+ struct isst_pkg_ctdp_level_info *ctdp_level)
+{
+ /* TBD */
+ ctdp_level->pkg_max_power = 0;
+ ctdp_level->pkg_min_power = 0;
+
+ debug_printf
+ ("cpu:%d ctdp:%d CONFIG_TDP_GET_PWR_INFO pkg_max_power:%d pkg_min_power:%d\n",
+ id->cpu, config_index, ctdp_level->pkg_max_power,
+ ctdp_level->pkg_min_power);
+
+ return 0;
+}
+
+int tpmi_get_coremask_info(struct isst_id *id, int config_index,
+ struct isst_pkg_ctdp_level_info *ctdp_level)
+{
+ struct isst_perf_level_cpu_mask info;
+ int ret, cpu_count;
+
+ info.socket_id = id->pkg;
+ info.power_domain_id = id->punit;
+ info.level = config_index;
+ info.punit_cpu_map = 1;
+
+ ret = tpmi_process_ioctl(ISST_IF_GET_PERF_LEVEL_CPU_MASK, &info);
+ if (ret == -1)
+ return ret;
+
+ set_cpu_mask_from_punit_coremask(id, info.mask,
+ ctdp_level->core_cpumask_size,
+ ctdp_level->core_cpumask, &cpu_count);
+ ctdp_level->cpu_count = cpu_count;
+
+ debug_printf("cpu:%d ctdp:%d core_mask ino cpu count:%d\n",
+ id->cpu, config_index, ctdp_level->cpu_count);
+
+ return 0;
+}
+
+static int tpmi_get_get_trls(struct isst_id *id, int config_index,
+ struct isst_pkg_ctdp_level_info *ctdp_level)
+{
+ struct isst_perf_level_data_info info;
+ int ret, i, j;
+
+ info.socket_id = id->pkg;
+ info.power_domain_id = id->punit;
+ info.level = config_index;
+
+ ret = tpmi_process_ioctl(ISST_IF_GET_PERF_LEVEL_INFO, &info);
+ if (ret == -1)
+ return ret;
+
+ if (info.max_buckets > TRL_MAX_BUCKETS)
+ info.max_buckets = TRL_MAX_BUCKETS;
+
+ if (info.max_trl_levels > TRL_MAX_LEVELS)
+ info.max_trl_levels = TRL_MAX_LEVELS;
+
+ for (i = 0; i < info.max_trl_levels; ++i)
+ for (j = 0; j < info.max_buckets; ++j)
+ ctdp_level->trl_ratios[i][j] = info.trl_freq_mhz[i][j];
+
+ return 0;
+}
+
+static int tpmi_get_get_trl(struct isst_id *id, int level, int config_index,
+ int *trl)
+{
+ struct isst_pkg_ctdp_level_info ctdp_level;
+ int ret, i;
+
+ ret = tpmi_get_get_trls(id, config_index, &ctdp_level);
+ if (ret)
+ return ret;
+
+ /* FIX ME: Just return for level 0 */
+ for (i = 0; i < 8; ++i)
+ trl[i] = ctdp_level.trl_ratios[0][i];
+
+ return 0;
+}
+
+static int tpmi_get_trl_bucket_info(struct isst_id *id, int config_index,
+ unsigned long long *buckets_info)
+{
+ struct isst_perf_level_data_info info;
+ unsigned char *mask = (unsigned char *)buckets_info;
+ int ret, i;
+
+ info.socket_id = id->pkg;
+ info.power_domain_id = id->punit;
+ info.level = config_index;
+
+ ret = tpmi_process_ioctl(ISST_IF_GET_PERF_LEVEL_INFO, &info);
+ if (ret == -1)
+ return ret;
+
+ if (info.max_buckets > TRL_MAX_BUCKETS)
+ info.max_buckets = TRL_MAX_BUCKETS;
+
+ for (i = 0; i < info.max_buckets; ++i)
+ mask[i] = info.bucket_core_counts[i];
+
+ debug_printf("cpu:%d TRL bucket info: 0x%llx\n", id->cpu,
+ *buckets_info);
+
+ return 0;
+}
+
+static int tpmi_set_tdp_level(struct isst_id *id, int tdp_level)
+{
+ struct isst_perf_level_control info;
+ int ret;
+
+ info.socket_id = id->pkg;
+ info.power_domain_id = id->punit;
+ info.level = tdp_level;
+
+ ret = tpmi_process_ioctl(ISST_IF_PERF_SET_LEVEL, &info);
+ if (ret == -1)
+ return ret;
+
+ return 0;
+}
+
+static int _pbf_get_coremask_info(struct isst_id *id, int config_index,
+ struct isst_pbf_info *pbf_info)
+{
+ struct isst_perf_level_cpu_mask info;
+ int ret, cpu_count;
+
+ info.socket_id = id->pkg;
+ info.power_domain_id = id->punit;
+ info.level = config_index;
+ info.punit_cpu_map = 1;
+
+ ret = tpmi_process_ioctl(ISST_IF_GET_BASE_FREQ_CPU_MASK, &info);
+ if (ret == -1)
+ return ret;
+
+ set_cpu_mask_from_punit_coremask(id, info.mask,
+ pbf_info->core_cpumask_size,
+ pbf_info->core_cpumask, &cpu_count);
+
+ debug_printf("cpu:%d ctdp:%d pbf core_mask info cpu count:%d\n",
+ id->cpu, config_index, cpu_count);
+
+ return 0;
+}
+
+static int tpmi_get_pbf_info(struct isst_id *id, int level,
+ struct isst_pbf_info *pbf_info)
+{
+ struct isst_base_freq_info info;
+ int ret;
+
+ info.socket_id = id->pkg;
+ info.power_domain_id = id->punit;
+ info.level = level;
+
+ ret = tpmi_process_ioctl(ISST_IF_GET_BASE_FREQ_INFO, &info);
+ if (ret == -1)
+ return ret;
+
+ pbf_info->p1_low = info.low_base_freq_mhz;
+ pbf_info->p1_high = info.high_base_freq_mhz;
+ pbf_info->tdp = info.thermal_design_power_w;
+ pbf_info->t_prochot = info.tjunction_max_c;
+
+ debug_printf("cpu:%d ctdp:%d pbf info:%d:%d:%d:%d\n",
+ id->cpu, level, pbf_info->p1_low, pbf_info->p1_high,
+ pbf_info->tdp, pbf_info->t_prochot);
+
+ return _pbf_get_coremask_info(id, level, pbf_info);
+}
+
+static int tpmi_set_pbf_fact_status(struct isst_id *id, int pbf, int enable)
+{
+ struct isst_pkg_ctdp pkg_dev;
+ struct isst_pkg_ctdp_level_info ctdp_level;
+ int current_level;
+ struct isst_perf_feature_control info;
+ int ret;
+
+ ret = isst_get_ctdp_levels(id, &pkg_dev);
+ if (ret)
+ debug_printf("cpu:%d No support for dynamic ISST\n", id->cpu);
+
+ current_level = pkg_dev.current_level;
+
+ ret = isst_get_ctdp_control(id, current_level, &ctdp_level);
+ if (ret)
+ return ret;
+
+ info.socket_id = id->pkg;
+ info.power_domain_id = id->punit;
+
+ info.feature = 0;
+
+ if (pbf) {
+ if (ctdp_level.fact_enabled)
+ info.feature |= BIT(1);
+
+ if (enable)
+ info.feature |= BIT(0);
+ else
+ info.feature &= ~BIT(0);
+ } else {
+
+ if (enable && !ctdp_level.sst_cp_enabled)
+ isst_display_error_info_message(0,
+ "Make sure to execute before: core-power enable",
+ 0, 0);
+
+ if (ctdp_level.pbf_enabled)
+ info.feature |= BIT(0);
+
+ if (enable)
+ info.feature |= BIT(1);
+ else
+ info.feature &= ~BIT(1);
+ }
+
+ ret = tpmi_process_ioctl(ISST_IF_PERF_SET_FEATURE, &info);
+ if (ret == -1)
+ return ret;
+
+ return 0;
+}
+
+static int tpmi_get_fact_info(struct isst_id *id, int level, int fact_bucket,
+ struct isst_fact_info *fact_info)
+{
+ struct isst_turbo_freq_info info;
+ int i, j;
+ int ret;
+
+ info.socket_id = id->pkg;
+ info.power_domain_id = id->punit;
+ info.level = level;
+
+ ret = tpmi_process_ioctl(ISST_IF_GET_TURBO_FREQ_INFO, &info);
+ if (ret == -1)
+ return ret;
+
+ for (i = 0; i < info.max_clip_freqs; ++i)
+ fact_info->lp_ratios[i] = info.lp_clip_freq_mhz[i];
+
+ if (info.max_buckets > TRL_MAX_BUCKETS)
+ info.max_buckets = TRL_MAX_BUCKETS;
+
+ if (info.max_trl_levels > TRL_MAX_LEVELS)
+ info.max_trl_levels = TRL_MAX_LEVELS;
+
+ for (i = 0; i < info.max_trl_levels; ++i) {
+ for (j = 0; j < info.max_buckets; ++j)
+ fact_info->bucket_info[j].hp_ratios[i] =
+ info.trl_freq_mhz[i][j];
+ }
+
+ for (i = 0; i < info.max_buckets; ++i)
+ fact_info->bucket_info[i].hp_cores = info.bucket_core_counts[i];
+
+ return 0;
+}
+
+static void _set_uncore_min_max(struct isst_id *id, int max, int freq)
+{
+ DIR *dir;
+ FILE *filep;
+ struct dirent *entry;
+ char buffer[512];
+ unsigned int tmp_id;
+ int ret;
+
+ dir = opendir("/sys/devices/system/cpu/intel_uncore_frequency/");
+ if (!dir)
+ return;
+
+ while ((entry = readdir(dir)) != NULL ) {
+ /* Check domain_id */
+ snprintf(buffer, sizeof(buffer),
+ "/sys/devices/system/cpu/intel_uncore_frequency/%s/domain_id", entry->d_name);
+
+ filep = fopen(buffer, "r");
+ if (!filep)
+ goto end;
+
+ ret = fscanf(filep, "%u", &tmp_id);
+ fclose(filep);
+ if (ret != 1)
+ goto end;
+
+ if (tmp_id != id->punit)
+ continue;
+
+ /* Check package_id */
+ snprintf(buffer, sizeof(buffer),
+ "/sys/devices/system/cpu/intel_uncore_frequency/%s/package_id", entry->d_name);
+
+ filep = fopen(buffer, "r");
+ if (!filep)
+ goto end;
+
+ ret = fscanf(filep, "%u", &tmp_id);
+ fclose(filep);
+
+ if (ret != 1)
+ goto end;
+
+ if (tmp_id != id->pkg)
+ continue;
+
+ /* Found the right sysfs path, adjust and quit */
+ if (max)
+ snprintf(buffer, sizeof(buffer),
+ "/sys/devices/system/cpu/intel_uncore_frequency/%s/max_freq_khz", entry->d_name);
+ else
+ snprintf(buffer, sizeof(buffer),
+ "/sys/devices/system/cpu/intel_uncore_frequency/%s/min_freq_khz", entry->d_name);
+
+ filep = fopen(buffer, "w");
+ if (!filep)
+ goto end;
+
+ fprintf(filep, "%d\n", freq);
+ fclose(filep);
+ break;
+ }
+
+end:
+ closedir(dir);
+}
+
+static void tpmi_adjust_uncore_freq(struct isst_id *id, int config_index,
+ struct isst_pkg_ctdp_level_info *ctdp_level)
+{
+ struct isst_perf_level_data_info info;
+ int ret;
+
+ info.socket_id = id->pkg;
+ info.power_domain_id = id->punit;
+ info.level = config_index;
+
+ ret = tpmi_process_ioctl(ISST_IF_GET_PERF_LEVEL_INFO, &info);
+ if (ret == -1)
+ return;
+
+ ctdp_level->uncore_p0 = info.p0_fabric_freq_mhz;
+ ctdp_level->uncore_p1 = info.p1_fabric_freq_mhz;
+ ctdp_level->uncore_pm = info.pm_fabric_freq_mhz;
+
+ if (ctdp_level->uncore_pm)
+ _set_uncore_min_max(id, 0, ctdp_level->uncore_pm * 100000);
+
+ if (ctdp_level->uncore_p0)
+ _set_uncore_min_max(id, 1, ctdp_level->uncore_p0 * 100000);
+
+ return;
+}
+
+static int tpmi_get_clos_information(struct isst_id *id, int *enable, int *type)
+{
+ struct isst_core_power info;
+ int ret;
+
+ info.get_set = 0;
+ info.socket_id = id->pkg;
+ info.power_domain_id = id->punit;
+ ret = tpmi_process_ioctl(ISST_IF_CORE_POWER_STATE, &info);
+ if (ret == -1)
+ return ret;
+
+ *enable = info.enable;
+ *type = info.priority_type;
+
+ return 0;
+}
+
+static int tpmi_pm_qos_config(struct isst_id *id, int enable_clos,
+ int priority_type)
+{
+ struct isst_core_power info;
+ int ret;
+
+ info.get_set = 1;
+ info.socket_id = id->pkg;
+ info.power_domain_id = id->punit;
+ info.enable = enable_clos;
+ info.priority_type = priority_type;
+ ret = tpmi_process_ioctl(ISST_IF_CORE_POWER_STATE, &info);
+ if (ret == -1)
+ return ret;
+
+ return 0;
+}
+
+int tpmi_pm_get_clos(struct isst_id *id, int clos,
+ struct isst_clos_config *clos_config)
+{
+ struct isst_clos_param info;
+ int ret;
+
+ info.get_set = 0;
+ info.socket_id = id->pkg;
+ info.power_domain_id = id->punit;
+ info.clos = clos;
+
+ ret = tpmi_process_ioctl(ISST_IF_CLOS_PARAM, &info);
+ if (ret == -1)
+ return ret;
+
+ clos_config->epp = 0;
+ clos_config->clos_prop_prio = info.prop_prio;
+ clos_config->clos_min = info.min_freq_mhz;
+ clos_config->clos_max = info.max_freq_mhz;
+ clos_config->clos_desired = 0;
+
+ debug_printf("cpu:%d clos:%d min:%d max:%d\n", id->cpu, clos,
+ clos_config->clos_min, clos_config->clos_max);
+
+ return 0;
+}
+
+int tpmi_set_clos(struct isst_id *id, int clos,
+ struct isst_clos_config *clos_config)
+{
+ struct isst_clos_param info;
+ int ret;
+
+ info.get_set = 1;
+ info.socket_id = id->pkg;
+ info.power_domain_id = id->punit;
+ info.clos = clos;
+ info.prop_prio = clos_config->clos_prop_prio;
+
+ info.min_freq_mhz = clos_config->clos_min;
+ info.max_freq_mhz = clos_config->clos_max;
+
+ if (info.min_freq_mhz <= 0xff)
+ info.min_freq_mhz *= 100;
+ if (info.max_freq_mhz <= 0xff)
+ info.max_freq_mhz *= 100;
+
+ ret = tpmi_process_ioctl(ISST_IF_CLOS_PARAM, &info);
+ if (ret == -1)
+ return ret;
+
+ debug_printf("set cpu:%d clos:%d min:%d max:%d\n", id->cpu, clos,
+ clos_config->clos_min, clos_config->clos_max);
+
+ return 0;
+}
+
+static int tpmi_clos_get_assoc_status(struct isst_id *id, int *clos_id)
+{
+ struct isst_if_clos_assoc_cmds assoc_cmds;
+ int ret;
+
+ assoc_cmds.cmd_count = 1;
+ assoc_cmds.get_set = 0;
+ assoc_cmds.punit_cpu_map = 1;
+ assoc_cmds.assoc_info[0].logical_cpu = find_phy_core_num(id->cpu);
+ assoc_cmds.assoc_info[0].socket_id = id->pkg;
+ assoc_cmds.assoc_info[0].power_domain_id = id->punit;
+
+ ret = tpmi_process_ioctl(ISST_IF_CLOS_ASSOC, &assoc_cmds);
+ if (ret == -1)
+ return ret;
+
+ *clos_id = assoc_cmds.assoc_info[0].clos;
+
+ return 0;
+}
+
+static int tpmi_clos_associate(struct isst_id *id, int clos_id)
+{
+ struct isst_if_clos_assoc_cmds assoc_cmds;
+ int ret;
+
+ assoc_cmds.cmd_count = 1;
+ assoc_cmds.get_set = 1;
+ assoc_cmds.punit_cpu_map = 1;
+ assoc_cmds.assoc_info[0].logical_cpu = find_phy_core_num(id->cpu);
+ assoc_cmds.assoc_info[0].clos = clos_id;
+ assoc_cmds.assoc_info[0].socket_id = id->pkg;
+ assoc_cmds.assoc_info[0].power_domain_id = id->punit;
+
+ ret = tpmi_process_ioctl(ISST_IF_CLOS_ASSOC, &assoc_cmds);
+ if (ret == -1)
+ return ret;
+
+ return 0;
+}
+
+static struct isst_platform_ops tpmi_ops = {
+ .get_disp_freq_multiplier = tpmi_get_disp_freq_multiplier,
+ .get_trl_max_levels = tpmi_get_trl_max_levels,
+ .get_trl_level_name = tpmi_get_trl_level_name,
+ .update_platform_param = tpmi_update_platform_param,
+ .is_punit_valid = tpmi_is_punit_valid,
+ .read_pm_config = tpmi_read_pm_config,
+ .get_config_levels = tpmi_get_config_levels,
+ .get_ctdp_control = tpmi_get_ctdp_control,
+ .get_tdp_info = tpmi_get_tdp_info,
+ .get_pwr_info = tpmi_get_pwr_info,
+ .get_coremask_info = tpmi_get_coremask_info,
+ .get_get_trl = tpmi_get_get_trl,
+ .get_get_trls = tpmi_get_get_trls,
+ .get_trl_bucket_info = tpmi_get_trl_bucket_info,
+ .set_tdp_level = tpmi_set_tdp_level,
+ .get_pbf_info = tpmi_get_pbf_info,
+ .set_pbf_fact_status = tpmi_set_pbf_fact_status,
+ .get_fact_info = tpmi_get_fact_info,
+ .adjust_uncore_freq = tpmi_adjust_uncore_freq,
+ .get_clos_information = tpmi_get_clos_information,
+ .pm_qos_config = tpmi_pm_qos_config,
+ .pm_get_clos = tpmi_pm_get_clos,
+ .set_clos = tpmi_set_clos,
+ .clos_get_assoc_status = tpmi_clos_get_assoc_status,
+ .clos_associate = tpmi_clos_associate,
+};
+
+struct isst_platform_ops *tpmi_get_platform_ops(void)
+{
+ return &tpmi_ops;
+}
diff --git a/tools/power/x86/intel-speed-select/isst-core.c b/tools/power/x86/intel-speed-select/isst-core.c
index 2bfc118c4b87..f55fef4c13a7 100644
--- a/tools/power/x86/intel-speed-select/isst-core.c
+++ b/tools/power/x86/intel-speed-select/isst-core.c
@@ -6,304 +6,141 @@
#include "isst.h"
-int isst_write_pm_config(struct isst_id *id, int cp_state)
-{
- unsigned int req, resp;
- int ret;
-
- if (cp_state)
- req = BIT(16);
- else
- req = 0;
-
- ret = isst_send_mbox_command(id->cpu, WRITE_PM_CONFIG, PM_FEATURE, 0, req,
- &resp);
- if (ret)
- return ret;
-
- debug_printf("cpu:%d WRITE_PM_CONFIG resp:%x\n", id->cpu, resp);
+static struct isst_platform_ops *isst_ops;
+
+#define CHECK_CB(_name) \
+ do { \
+ if (!isst_ops || !isst_ops->_name) { \
+ fprintf(stderr, "Invalid ops\n"); \
+ exit(0); \
+ } \
+ } while (0)
+
+int isst_set_platform_ops(int api_version)
+{
+ switch (api_version) {
+ case 1:
+ isst_ops = mbox_get_platform_ops();
+ break;
+ case 2:
+ isst_ops = tpmi_get_platform_ops();
+ break;
+ default:
+ isst_ops = NULL;
+ break;
+ }
+ if (!isst_ops)
+ return -1;
return 0;
}
-int isst_read_pm_config(struct isst_id *id, int *cp_state, int *cp_cap)
+void isst_update_platform_param(enum isst_platform_param param, int value)
{
- unsigned int resp;
- int ret;
-
- ret = isst_send_mbox_command(id->cpu, READ_PM_CONFIG, PM_FEATURE, 0, 0,
- &resp);
- if (ret)
- return ret;
-
- debug_printf("cpu:%d READ_PM_CONFIG resp:%x\n", id->cpu, resp);
+ CHECK_CB(update_platform_param);
- *cp_state = resp & BIT(16);
- *cp_cap = resp & BIT(0) ? 1 : 0;
-
- return 0;
+ isst_ops->update_platform_param(param, value);
}
-int isst_get_ctdp_levels(struct isst_id *id, struct isst_pkg_ctdp *pkg_dev)
+int isst_get_disp_freq_multiplier(void)
{
- unsigned int resp;
- int ret;
-
- ret = isst_send_mbox_command(id->cpu, CONFIG_TDP,
- CONFIG_TDP_GET_LEVELS_INFO, 0, 0, &resp);
- if (ret) {
- pkg_dev->levels = 0;
- pkg_dev->locked = 1;
- pkg_dev->current_level = 0;
- pkg_dev->version = 0;
- pkg_dev->enabled = 0;
- return 0;
- }
+ CHECK_CB(get_disp_freq_multiplier);
+ return isst_ops->get_disp_freq_multiplier();
+}
- debug_printf("cpu:%d CONFIG_TDP_GET_LEVELS_INFO resp:%x\n", id->cpu, resp);
+int isst_get_trl_max_levels(void)
+{
+ CHECK_CB(get_trl_max_levels);
+ return isst_ops->get_trl_max_levels();
+}
- pkg_dev->version = resp & 0xff;
- pkg_dev->levels = (resp >> 8) & 0xff;
- pkg_dev->current_level = (resp >> 16) & 0xff;
- pkg_dev->locked = !!(resp & BIT(24));
- pkg_dev->enabled = !!(resp & BIT(31));
+char *isst_get_trl_level_name(int level)
+{
+ CHECK_CB(get_trl_level_name);
+ return isst_ops->get_trl_level_name(level);
+}
- return 0;
+int isst_is_punit_valid(struct isst_id *id)
+{
+ CHECK_CB(is_punit_valid);
+ return isst_ops->is_punit_valid(id);
}
-int isst_get_ctdp_control(struct isst_id *id, int config_index,
- struct isst_pkg_ctdp_level_info *ctdp_level)
+int isst_send_msr_command(unsigned int cpu, unsigned int msr, int write,
+ unsigned long long *req_resp)
{
- int cp_state, cp_cap;
- unsigned int resp;
- int ret;
+ struct isst_if_msr_cmds msr_cmds;
+ const char *pathname = "/dev/isst_interface";
+ FILE *outf = get_output_file();
+ int fd;
- ret = isst_send_mbox_command(id->cpu, CONFIG_TDP,
- CONFIG_TDP_GET_TDP_CONTROL, 0,
- config_index, &resp);
- if (ret)
- return ret;
+ fd = open(pathname, O_RDWR);
+ if (fd < 0)
+ err(-1, "%s open failed", pathname);
- ctdp_level->fact_support = resp & BIT(0);
- ctdp_level->pbf_support = !!(resp & BIT(1));
- ctdp_level->fact_enabled = !!(resp & BIT(16));
- ctdp_level->pbf_enabled = !!(resp & BIT(17));
+ msr_cmds.cmd_count = 1;
+ msr_cmds.msr_cmd[0].logical_cpu = cpu;
+ msr_cmds.msr_cmd[0].msr = msr;
+ msr_cmds.msr_cmd[0].read_write = write;
+ if (write)
+ msr_cmds.msr_cmd[0].data = *req_resp;
- ret = isst_read_pm_config(id, &cp_state, &cp_cap);
- if (ret) {
- debug_printf("cpu:%d pm_config is not supported\n", id->cpu);
+ if (ioctl(fd, ISST_IF_MSR_COMMAND, &msr_cmds) == -1) {
+ perror("ISST_IF_MSR_COMMAND");
+ fprintf(outf, "Error: msr_cmd cpu:%d msr:%x read_write:%d\n",
+ cpu, msr, write);
} else {
- debug_printf("cpu:%d pm_config SST-CP state:%d cap:%d\n", id->cpu, cp_state, cp_cap);
- ctdp_level->sst_cp_support = cp_cap;
- ctdp_level->sst_cp_enabled = cp_state;
- }
-
- debug_printf(
- "cpu:%d CONFIG_TDP_GET_TDP_CONTROL resp:%x fact_support:%d pbf_support: %d fact_enabled:%d pbf_enabled:%d\n",
- id->cpu, resp, ctdp_level->fact_support, ctdp_level->pbf_support,
- ctdp_level->fact_enabled, ctdp_level->pbf_enabled);
-
- return 0;
-}
-
-int isst_get_tdp_info(struct isst_id *id, int config_index,
- struct isst_pkg_ctdp_level_info *ctdp_level)
-{
- unsigned int resp;
- int ret;
+ if (!write)
+ *req_resp = msr_cmds.msr_cmd[0].data;
- ret = isst_send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_GET_TDP_INFO,
- 0, config_index, &resp);
- if (ret) {
- isst_display_error_info_message(1, "Invalid level, Can't get TDP information at level", 1, config_index);
- return ret;
+ debug_printf(
+ "msr_cmd response: cpu:%d msr:%x rd_write:%x resp:%llx %llx\n",
+ cpu, msr, write, *req_resp, msr_cmds.msr_cmd[0].data);
}
- ctdp_level->pkg_tdp = resp & GENMASK(14, 0);
- ctdp_level->tdp_ratio = (resp & GENMASK(23, 16)) >> 16;
+ close(fd);
- debug_printf(
- "cpu:%d ctdp:%d CONFIG_TDP_GET_TDP_INFO resp:%x tdp_ratio:%d pkg_tdp:%d\n",
- id->cpu, config_index, resp, ctdp_level->tdp_ratio,
- ctdp_level->pkg_tdp);
return 0;
}
-int isst_get_pwr_info(struct isst_id *id, int config_index,
- struct isst_pkg_ctdp_level_info *ctdp_level)
+int isst_read_pm_config(struct isst_id *id, int *cp_state, int *cp_cap)
{
- unsigned int resp;
- int ret;
-
- ret = isst_send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_GET_PWR_INFO,
- 0, config_index, &resp);
- if (ret)
- return ret;
-
- ctdp_level->pkg_max_power = resp & GENMASK(14, 0);
- ctdp_level->pkg_min_power = (resp & GENMASK(30, 16)) >> 16;
-
- debug_printf(
- "cpu:%d ctdp:%d CONFIG_TDP_GET_PWR_INFO resp:%x pkg_max_power:%d pkg_min_power:%d\n",
- id->cpu, config_index, resp, ctdp_level->pkg_max_power,
- ctdp_level->pkg_min_power);
-
- return 0;
+ CHECK_CB(read_pm_config);
+ return isst_ops->read_pm_config(id, cp_state, cp_cap);
}
-void isst_get_uncore_p0_p1_info(struct isst_id *id, int config_index,
- struct isst_pkg_ctdp_level_info *ctdp_level)
+int isst_get_ctdp_levels(struct isst_id *id, struct isst_pkg_ctdp *pkg_dev)
{
- unsigned int resp;
- int ret;
-
- ctdp_level->uncore_pm = 0;
- ctdp_level->uncore_p0 = 0;
- ctdp_level->uncore_p1 = 0;
-
- ret = isst_send_mbox_command(id->cpu, CONFIG_TDP,
- CONFIG_TDP_GET_RATIO_INFO, 0,
- (BIT(16) | config_index), &resp);
- if (ret)
- goto try_uncore_mbox;
-
- ctdp_level->uncore_p0 = resp & GENMASK(7, 0);
- ctdp_level->uncore_p1 = (resp & GENMASK(15, 8)) >> 8;
- ctdp_level->uncore_pm = (resp & GENMASK(31, 24)) >> 24;
-
- debug_printf(
- "cpu:%d ctdp:%d CONFIG_TDP_GET_RATIO_INFO resp:%x uncore p0:%d uncore p1:%d uncore pm:%d\n",
- id->cpu, config_index, resp, ctdp_level->uncore_p0, ctdp_level->uncore_p1,
- ctdp_level->uncore_pm);
-
- return;
-
-try_uncore_mbox:
- ret = isst_send_mbox_command(id->cpu, CONFIG_TDP,
- CONFIG_TDP_GET_UNCORE_P0_P1_INFO, 0,
- config_index, &resp);
- if (ret) {
- ctdp_level->uncore_p0 = 0;
- ctdp_level->uncore_p1 = 0;
- return;
- }
-
- ctdp_level->uncore_p0 = resp & GENMASK(7, 0);
- ctdp_level->uncore_p1 = (resp & GENMASK(15, 8)) >> 8;
- debug_printf(
- "cpu:%d ctdp:%d CONFIG_TDP_GET_UNCORE_P0_P1_INFO resp:%x uncore p0:%d uncore p1:%d\n",
- id->cpu, config_index, resp, ctdp_level->uncore_p0,
- ctdp_level->uncore_p1);
+ CHECK_CB(get_config_levels);
+ return isst_ops->get_config_levels(id, pkg_dev);
}
-void isst_get_p1_info(struct isst_id *id, int config_index,
- struct isst_pkg_ctdp_level_info *ctdp_level)
+int isst_get_ctdp_control(struct isst_id *id, int config_index,
+ struct isst_pkg_ctdp_level_info *ctdp_level)
{
- unsigned int resp;
- int ret;
- ret = isst_send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_GET_P1_INFO, 0,
- config_index, &resp);
- if (ret) {
- ctdp_level->sse_p1 = 0;
- ctdp_level->avx2_p1 = 0;
- ctdp_level->avx512_p1 = 0;
- return;
- }
-
- ctdp_level->sse_p1 = resp & GENMASK(7, 0);
- ctdp_level->avx2_p1 = (resp & GENMASK(15, 8)) >> 8;
- ctdp_level->avx512_p1 = (resp & GENMASK(23, 16)) >> 16;
- debug_printf(
- "cpu:%d ctdp:%d CONFIG_TDP_GET_P1_INFO resp:%x sse_p1:%d avx2_p1:%d avx512_p1:%d\n",
- id->cpu, config_index, resp, ctdp_level->sse_p1,
- ctdp_level->avx2_p1, ctdp_level->avx512_p1);
+ CHECK_CB(get_ctdp_control);
+ return isst_ops->get_ctdp_control(id, config_index, ctdp_level);
}
-void isst_get_uncore_mem_freq(struct isst_id *id, int config_index,
- struct isst_pkg_ctdp_level_info *ctdp_level)
+int isst_get_tdp_info(struct isst_id *id, int config_index,
+ struct isst_pkg_ctdp_level_info *ctdp_level)
{
- unsigned int resp;
- int ret;
-
- ret = isst_send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_GET_MEM_FREQ,
- 0, config_index, &resp);
- if (ret) {
- ctdp_level->mem_freq = 0;
- return;
- }
-
- ctdp_level->mem_freq = resp & GENMASK(7, 0);
- if (is_spr_platform()) {
- ctdp_level->mem_freq *= 200;
- } else if (is_icx_platform()) {
- if (ctdp_level->mem_freq < 7) {
- ctdp_level->mem_freq = (12 - ctdp_level->mem_freq) * 133.33 * 2 * 10;
- ctdp_level->mem_freq /= 10;
- if (ctdp_level->mem_freq % 10 > 5)
- ctdp_level->mem_freq++;
- } else {
- ctdp_level->mem_freq = 0;
- }
- } else {
- ctdp_level->mem_freq = 0;
- }
- debug_printf(
- "cpu:%d ctdp:%d CONFIG_TDP_GET_MEM_FREQ resp:%x uncore mem_freq:%d\n",
- id->cpu, config_index, resp, ctdp_level->mem_freq);
+ CHECK_CB(get_tdp_info);
+ return isst_ops->get_tdp_info(id, config_index, ctdp_level);
}
-int isst_get_tjmax_info(struct isst_id *id, int config_index,
- struct isst_pkg_ctdp_level_info *ctdp_level)
+int isst_get_pwr_info(struct isst_id *id, int config_index,
+ struct isst_pkg_ctdp_level_info *ctdp_level)
{
- unsigned int resp;
- int ret;
-
- ret = isst_send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_GET_TJMAX_INFO,
- 0, config_index, &resp);
- if (ret)
- return ret;
-
- ctdp_level->t_proc_hot = resp & GENMASK(7, 0);
-
- debug_printf(
- "cpu:%d ctdp:%d CONFIG_TDP_GET_TJMAX_INFO resp:%x t_proc_hot:%d\n",
- id->cpu, config_index, resp, ctdp_level->t_proc_hot);
-
- return 0;
+ CHECK_CB(get_pwr_info);
+ return isst_ops->get_pwr_info(id, config_index, ctdp_level);
}
int isst_get_coremask_info(struct isst_id *id, int config_index,
struct isst_pkg_ctdp_level_info *ctdp_level)
{
- unsigned int resp;
- int i, ret;
-
- ctdp_level->cpu_count = 0;
- for (i = 0; i < 2; ++i) {
- unsigned long long mask;
- int cpu_count = 0;
-
- ret = isst_send_mbox_command(id->cpu, CONFIG_TDP,
- CONFIG_TDP_GET_CORE_MASK, 0,
- (i << 8) | config_index, &resp);
- if (ret)
- return ret;
-
- debug_printf(
- "cpu:%d ctdp:%d mask:%d CONFIG_TDP_GET_CORE_MASK resp:%x\n",
- id->cpu, config_index, i, resp);
-
- mask = (unsigned long long)resp << (32 * i);
- set_cpu_mask_from_punit_coremask(id, mask,
- ctdp_level->core_cpumask_size,
- ctdp_level->core_cpumask,
- &cpu_count);
- ctdp_level->cpu_count += cpu_count;
- debug_printf("cpu:%d ctdp:%d mask:%d cpu count:%d\n", id->cpu,
- config_index, i, ctdp_level->cpu_count);
- }
-
- return 0;
+ CHECK_CB(get_coremask_info);
+ return isst_ops->get_coremask_info(id, config_index, ctdp_level);
}
int isst_get_get_trl_from_msr(struct isst_id *id, int *trl)
@@ -329,89 +166,33 @@ int isst_get_get_trl_from_msr(struct isst_id *id, int *trl)
int isst_get_get_trl(struct isst_id *id, int level, int avx_level, int *trl)
{
- unsigned int req, resp;
- int ret;
-
- req = level | (avx_level << 16);
- ret = isst_send_mbox_command(id->cpu, CONFIG_TDP,
- CONFIG_TDP_GET_TURBO_LIMIT_RATIOS, 0, req,
- &resp);
- if (ret)
- return ret;
-
- debug_printf(
- "cpu:%d CONFIG_TDP_GET_TURBO_LIMIT_RATIOS req:%x resp:%x\n",
- id->cpu, req, resp);
-
- trl[0] = resp & GENMASK(7, 0);
- trl[1] = (resp & GENMASK(15, 8)) >> 8;
- trl[2] = (resp & GENMASK(23, 16)) >> 16;
- trl[3] = (resp & GENMASK(31, 24)) >> 24;
-
- req = level | BIT(8) | (avx_level << 16);
- ret = isst_send_mbox_command(id->cpu, CONFIG_TDP,
- CONFIG_TDP_GET_TURBO_LIMIT_RATIOS, 0, req,
- &resp);
- if (ret)
- return ret;
-
- debug_printf("cpu:%d CONFIG_TDP_GET_TURBO_LIMIT req:%x resp:%x\n", id->cpu,
- req, resp);
-
- trl[4] = resp & GENMASK(7, 0);
- trl[5] = (resp & GENMASK(15, 8)) >> 8;
- trl[6] = (resp & GENMASK(23, 16)) >> 16;
- trl[7] = (resp & GENMASK(31, 24)) >> 24;
-
- return 0;
+ CHECK_CB(get_get_trl);
+ return isst_ops->get_get_trl(id, level, avx_level, trl);
}
-int isst_get_trl_bucket_info(struct isst_id *id, unsigned long long *buckets_info)
+int isst_get_get_trls(struct isst_id *id, int level, struct isst_pkg_ctdp_level_info *ctdp_level)
{
- int ret;
-
- debug_printf("cpu:%d bucket info via MSR\n", id->cpu);
-
- *buckets_info = 0;
-
- ret = isst_send_msr_command(id->cpu, 0x1ae, 0, buckets_info);
- if (ret)
- return ret;
-
- debug_printf("cpu:%d bucket info via MSR successful 0x%llx\n", id->cpu,
- *buckets_info);
+ CHECK_CB(get_get_trls);
+ return isst_ops->get_get_trls(id, level, ctdp_level);
+}
- return 0;
+int isst_get_trl_bucket_info(struct isst_id *id, int level, unsigned long long *buckets_info)
+{
+ CHECK_CB(get_trl_bucket_info);
+ return isst_ops->get_trl_bucket_info(id, level, buckets_info);
}
int isst_set_tdp_level(struct isst_id *id, int tdp_level)
{
- unsigned int resp;
- int ret;
-
-
- if (isst_get_config_tdp_lock_status(id)) {
- isst_display_error_info_message(1, "TDP is locked", 0, 0);
- return -1;
-
- }
-
- ret = isst_send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_SET_LEVEL, 0,
- tdp_level, &resp);
- if (ret) {
- isst_display_error_info_message(1, "Set TDP level failed for level", 1, tdp_level);
- return ret;
- }
-
- return 0;
+ CHECK_CB(set_tdp_level);
+ return isst_ops->set_tdp_level(id, tdp_level);
}
int isst_get_pbf_info(struct isst_id *id, int level, struct isst_pbf_info *pbf_info)
{
struct isst_pkg_ctdp_level_info ctdp_level;
struct isst_pkg_ctdp pkg_dev;
- int i, ret, max_punit_core, max_mask_index;
- unsigned int req, resp;
+ int ret;
ret = isst_get_ctdp_levels(id, &pkg_dev);
if (ret) {
@@ -435,194 +216,23 @@ int isst_get_pbf_info(struct isst_id *id, int level, struct isst_pbf_info *pbf_i
pbf_info->core_cpumask_size = alloc_cpu_set(&pbf_info->core_cpumask);
- max_punit_core = get_max_punit_core_id(id);
- max_mask_index = max_punit_core > 32 ? 2 : 1;
-
- for (i = 0; i < max_mask_index; ++i) {
- unsigned long long mask;
- int count;
-
- ret = isst_send_mbox_command(id->cpu, CONFIG_TDP,
- CONFIG_TDP_PBF_GET_CORE_MASK_INFO,
- 0, (i << 8) | level, &resp);
- if (ret)
- break;
-
- debug_printf(
- "cpu:%d CONFIG_TDP_PBF_GET_CORE_MASK_INFO resp:%x\n",
- id->cpu, resp);
-
- mask = (unsigned long long)resp << (32 * i);
- set_cpu_mask_from_punit_coremask(id, mask,
- pbf_info->core_cpumask_size,
- pbf_info->core_cpumask,
- &count);
- }
-
- req = level;
- ret = isst_send_mbox_command(id->cpu, CONFIG_TDP,
- CONFIG_TDP_PBF_GET_P1HI_P1LO_INFO, 0, req,
- &resp);
- if (ret)
- return ret;
-
- debug_printf("cpu:%d CONFIG_TDP_PBF_GET_P1HI_P1LO_INFO resp:%x\n", id->cpu,
- resp);
-
- pbf_info->p1_low = resp & 0xff;
- pbf_info->p1_high = (resp & GENMASK(15, 8)) >> 8;
-
- req = level;
- ret = isst_send_mbox_command(
- id->cpu, CONFIG_TDP, CONFIG_TDP_PBF_GET_TDP_INFO, 0, req, &resp);
- if (ret)
- return ret;
-
- debug_printf("cpu:%d CONFIG_TDP_PBF_GET_TDP_INFO resp:%x\n", id->cpu, resp);
-
- pbf_info->tdp = resp & 0xffff;
-
- req = level;
- ret = isst_send_mbox_command(
- id->cpu, CONFIG_TDP, CONFIG_TDP_PBF_GET_TJ_MAX_INFO, 0, req, &resp);
- if (ret)
- return ret;
-
- debug_printf("cpu:%d CONFIG_TDP_PBF_GET_TJ_MAX_INFO resp:%x\n", id->cpu,
- resp);
- pbf_info->t_control = (resp >> 8) & 0xff;
- pbf_info->t_prochot = resp & 0xff;
-
- return 0;
-}
-
-void isst_get_pbf_info_complete(struct isst_pbf_info *pbf_info)
-{
- free_cpu_set(pbf_info->core_cpumask);
+ CHECK_CB(get_pbf_info);
+ return isst_ops->get_pbf_info(id, level, pbf_info);
}
int isst_set_pbf_fact_status(struct isst_id *id, int pbf, int enable)
{
- struct isst_pkg_ctdp pkg_dev;
- struct isst_pkg_ctdp_level_info ctdp_level;
- int current_level;
- unsigned int req = 0, resp;
- int ret;
-
- ret = isst_get_ctdp_levels(id, &pkg_dev);
- if (ret)
- debug_printf("cpu:%d No support for dynamic ISST\n", id->cpu);
-
- current_level = pkg_dev.current_level;
-
- ret = isst_get_ctdp_control(id, current_level, &ctdp_level);
- if (ret)
- return ret;
-
- if (pbf) {
- if (ctdp_level.fact_enabled)
- req = BIT(16);
-
- if (enable)
- req |= BIT(17);
- else
- req &= ~BIT(17);
- } else {
-
- if (enable && !ctdp_level.sst_cp_enabled)
- isst_display_error_info_message(0, "Make sure to execute before: core-power enable", 0, 0);
-
- if (ctdp_level.pbf_enabled)
- req = BIT(17);
-
- if (enable)
- req |= BIT(16);
- else
- req &= ~BIT(16);
- }
-
- ret = isst_send_mbox_command(id->cpu, CONFIG_TDP,
- CONFIG_TDP_SET_TDP_CONTROL, 0, req, &resp);
- if (ret)
- return ret;
-
- debug_printf("cpu:%d CONFIG_TDP_SET_TDP_CONTROL pbf/fact:%d req:%x\n",
- id->cpu, pbf, req);
-
- return 0;
+ CHECK_CB(set_pbf_fact_status);
+ return isst_ops->set_pbf_fact_status(id, pbf, enable);
}
-int isst_get_fact_bucket_info(struct isst_id *id, int level,
- struct isst_fact_bucket_info *bucket_info)
-{
- unsigned int resp;
- int i, k, ret;
-
- for (i = 0; i < 2; ++i) {
- int j;
-
- ret = isst_send_mbox_command(
- id->cpu, CONFIG_TDP,
- CONFIG_TDP_GET_FACT_HP_TURBO_LIMIT_NUMCORES, 0,
- (i << 8) | level, &resp);
- if (ret)
- return ret;
-
- debug_printf(
- "cpu:%d CONFIG_TDP_GET_FACT_HP_TURBO_LIMIT_NUMCORES index:%d level:%d resp:%x\n",
- id->cpu, i, level, resp);
-
- for (j = 0; j < 4; ++j) {
- bucket_info[j + (i * 4)].high_priority_cores_count =
- (resp >> (j * 8)) & 0xff;
- }
- }
-
- for (k = 0; k < 3; ++k) {
- for (i = 0; i < 2; ++i) {
- int j;
-
- ret = isst_send_mbox_command(
- id->cpu, CONFIG_TDP,
- CONFIG_TDP_GET_FACT_HP_TURBO_LIMIT_RATIOS, 0,
- (k << 16) | (i << 8) | level, &resp);
- if (ret)
- return ret;
-
- debug_printf(
- "cpu:%d CONFIG_TDP_GET_FACT_HP_TURBO_LIMIT_RATIOS index:%d level:%d avx:%d resp:%x\n",
- id->cpu, i, level, k, resp);
-
- for (j = 0; j < 4; ++j) {
- switch (k) {
- case 0:
- bucket_info[j + (i * 4)].sse_trl =
- (resp >> (j * 8)) & 0xff;
- break;
- case 1:
- bucket_info[j + (i * 4)].avx_trl =
- (resp >> (j * 8)) & 0xff;
- break;
- case 2:
- bucket_info[j + (i * 4)].avx512_trl =
- (resp >> (j * 8)) & 0xff;
- break;
- default:
- break;
- }
- }
- }
- }
- return 0;
-}
int isst_get_fact_info(struct isst_id *id, int level, int fact_bucket, struct isst_fact_info *fact_info)
{
struct isst_pkg_ctdp_level_info ctdp_level;
struct isst_pkg_ctdp pkg_dev;
- unsigned int resp;
- int j, ret, print;
+ int ret;
ret = isst_get_ctdp_levels(id, &pkg_dev);
if (ret) {
@@ -643,40 +253,8 @@ int isst_get_fact_info(struct isst_id *id, int level, int fact_bucket, struct is
isst_display_error_info_message(1, "turbo-freq feature is not present at this level", 1, level);
return -1;
}
-
- ret = isst_send_mbox_command(id->cpu, CONFIG_TDP,
- CONFIG_TDP_GET_FACT_LP_CLIPPING_RATIO, 0,
- level, &resp);
- if (ret)
- return ret;
-
- debug_printf("cpu:%d CONFIG_TDP_GET_FACT_LP_CLIPPING_RATIO resp:%x\n",
- id->cpu, resp);
-
- fact_info->lp_clipping_ratio_license_sse = resp & 0xff;
- fact_info->lp_clipping_ratio_license_avx2 = (resp >> 8) & 0xff;
- fact_info->lp_clipping_ratio_license_avx512 = (resp >> 16) & 0xff;
-
- ret = isst_get_fact_bucket_info(id, level, fact_info->bucket_info);
- if (ret)
- return ret;
-
- print = 0;
- for (j = 0; j < ISST_FACT_MAX_BUCKETS; ++j) {
- if (fact_bucket != 0xff && fact_bucket != j)
- continue;
-
- if (!fact_info->bucket_info[j].high_priority_cores_count)
- break;
-
- print = 1;
- }
- if (!print) {
- isst_display_error_info_message(1, "Invalid bucket", 0, 0);
- return -1;
- }
-
- return 0;
+ CHECK_CB(get_fact_info);
+ return isst_ops->get_fact_info(id, level, fact_bucket, fact_info);
}
int isst_get_trl(struct isst_id *id, unsigned long long *trl)
@@ -709,6 +287,9 @@ int isst_set_trl_from_current_tdp(struct isst_id *id, unsigned long long trl)
unsigned long long msr_trl;
int ret;
+ if (id->cpu < 0)
+ return 0;
+
if (trl) {
msr_trl = trl;
} else {
@@ -770,6 +351,13 @@ void isst_get_process_ctdp_complete(struct isst_id *id, struct isst_pkg_ctdp *pk
}
}
+void isst_adjust_uncore_freq(struct isst_id *id, int config_index,
+ struct isst_pkg_ctdp_level_info *ctdp_level)
+{
+ CHECK_CB(adjust_uncore_freq);
+ return isst_ops->adjust_uncore_freq(id, config_index, ctdp_level);
+}
+
int isst_get_process_ctdp(struct isst_id *id, int tdp_level, struct isst_pkg_ctdp *pkg_dev)
{
int i, ret, valid = 0;
@@ -838,8 +426,8 @@ int isst_get_process_ctdp(struct isst_id *id, int tdp_level, struct isst_pkg_ctd
ctdp_level->tdp_ratio = ctdp_level->sse_p1;
}
- isst_get_get_trl_from_msr(id, ctdp_level->trl_sse_active_cores);
- isst_get_trl_bucket_info(id, &ctdp_level->buckets_info);
+ isst_get_get_trl_from_msr(id, ctdp_level->trl_ratios[0]);
+ isst_get_trl_bucket_info(id, i, &ctdp_level->trl_cores);
continue;
}
@@ -851,38 +439,19 @@ int isst_get_process_ctdp(struct isst_id *id, int tdp_level, struct isst_pkg_ctd
if (ret)
return ret;
- ret = isst_get_tjmax_info(id, i, ctdp_level);
- if (ret)
- return ret;
-
ctdp_level->core_cpumask_size =
alloc_cpu_set(&ctdp_level->core_cpumask);
ret = isst_get_coremask_info(id, i, ctdp_level);
if (ret)
return ret;
- ret = isst_get_trl_bucket_info(id, &ctdp_level->buckets_info);
- if (ret)
- return ret;
-
- ret = isst_get_get_trl(id, i, 0,
- ctdp_level->trl_sse_active_cores);
+ ret = isst_get_trl_bucket_info(id, i, &ctdp_level->trl_cores);
if (ret)
return ret;
- ret = isst_get_get_trl(id, i, 1,
- ctdp_level->trl_avx_active_cores);
+ ret = isst_get_get_trls(id, i, ctdp_level);
if (ret)
return ret;
-
- ret = isst_get_get_trl(id, i, 2,
- ctdp_level->trl_avx_512_active_cores);
- if (ret)
- return ret;
-
- isst_get_uncore_p0_p1_info(id, i, ctdp_level);
- isst_get_p1_info(id, i, ctdp_level);
- isst_get_uncore_mem_freq(id, i, ctdp_level);
}
if (!valid)
@@ -893,178 +462,37 @@ int isst_get_process_ctdp(struct isst_id *id, int tdp_level, struct isst_pkg_ctd
int isst_clos_get_clos_information(struct isst_id *id, int *enable, int *type)
{
- unsigned int resp;
- int ret;
-
- ret = isst_send_mbox_command(id->cpu, CONFIG_CLOS, CLOS_PM_QOS_CONFIG, 0, 0,
- &resp);
- if (ret)
- return ret;
-
- debug_printf("cpu:%d CLOS_PM_QOS_CONFIG resp:%x\n", id->cpu, resp);
-
- if (resp & BIT(1))
- *enable = 1;
- else
- *enable = 0;
-
- if (resp & BIT(2))
- *type = 1;
- else
- *type = 0;
-
- return 0;
+ CHECK_CB(get_clos_information);
+ return isst_ops->get_clos_information(id, enable, type);
}
int isst_pm_qos_config(struct isst_id *id, int enable_clos, int priority_type)
{
- unsigned int req, resp;
- int ret;
-
- if (!enable_clos) {
- struct isst_pkg_ctdp pkg_dev;
- struct isst_pkg_ctdp_level_info ctdp_level;
-
- ret = isst_get_ctdp_levels(id, &pkg_dev);
- if (ret) {
- debug_printf("isst_get_ctdp_levels\n");
- return ret;
- }
-
- ret = isst_get_ctdp_control(id, pkg_dev.current_level,
- &ctdp_level);
- if (ret)
- return ret;
-
- if (ctdp_level.fact_enabled) {
- isst_display_error_info_message(1, "Ignoring request, turbo-freq feature is still enabled", 0, 0);
- return -EINVAL;
- }
- ret = isst_write_pm_config(id, 0);
- if (ret)
- isst_display_error_info_message(0, "WRITE_PM_CONFIG command failed, ignoring error", 0, 0);
- } else {
- ret = isst_write_pm_config(id, 1);
- if (ret)
- isst_display_error_info_message(0, "WRITE_PM_CONFIG command failed, ignoring error", 0, 0);
- }
-
- ret = isst_send_mbox_command(id->cpu, CONFIG_CLOS, CLOS_PM_QOS_CONFIG, 0, 0,
- &resp);
- if (ret) {
- isst_display_error_info_message(1, "CLOS_PM_QOS_CONFIG command failed", 0, 0);
- return ret;
- }
-
- debug_printf("cpu:%d CLOS_PM_QOS_CONFIG resp:%x\n", id->cpu, resp);
-
- req = resp;
-
- if (enable_clos)
- req = req | BIT(1);
- else
- req = req & ~BIT(1);
-
- if (priority_type > 1)
- isst_display_error_info_message(1, "Invalid priority type: Changing type to ordered", 0, 0);
-
- if (priority_type)
- req = req | BIT(2);
- else
- req = req & ~BIT(2);
-
- ret = isst_send_mbox_command(id->cpu, CONFIG_CLOS, CLOS_PM_QOS_CONFIG,
- BIT(MBOX_CMD_WRITE_BIT), req, &resp);
- if (ret)
- return ret;
-
- debug_printf("cpu:%d CLOS_PM_QOS_CONFIG priority type:%d req:%x\n", id->cpu,
- priority_type, req);
-
- return 0;
+ CHECK_CB(pm_qos_config);
+ return isst_ops->pm_qos_config(id, enable_clos, priority_type);
}
int isst_pm_get_clos(struct isst_id *id, int clos, struct isst_clos_config *clos_config)
{
- unsigned int resp;
- int ret;
-
- ret = isst_send_mbox_command(id->cpu, CONFIG_CLOS, CLOS_PM_CLOS, clos, 0,
- &resp);
- if (ret)
- return ret;
-
- clos_config->epp = resp & 0x0f;
- clos_config->clos_prop_prio = (resp >> 4) & 0x0f;
- clos_config->clos_min = (resp >> 8) & 0xff;
- clos_config->clos_max = (resp >> 16) & 0xff;
- clos_config->clos_desired = (resp >> 24) & 0xff;
-
- return 0;
+ CHECK_CB(pm_get_clos);
+ return isst_ops->pm_get_clos(id, clos, clos_config);
}
int isst_set_clos(struct isst_id *id, int clos, struct isst_clos_config *clos_config)
{
- unsigned int req, resp;
- unsigned int param;
- int ret;
-
- req = clos_config->epp & 0x0f;
- req |= (clos_config->clos_prop_prio & 0x0f) << 4;
- req |= (clos_config->clos_min & 0xff) << 8;
- req |= (clos_config->clos_max & 0xff) << 16;
- req |= (clos_config->clos_desired & 0xff) << 24;
-
- param = BIT(MBOX_CMD_WRITE_BIT) | clos;
-
- ret = isst_send_mbox_command(id->cpu, CONFIG_CLOS, CLOS_PM_CLOS, param, req,
- &resp);
- if (ret)
- return ret;
-
- debug_printf("cpu:%d CLOS_PM_CLOS param:%x req:%x\n", id->cpu, param, req);
-
- return 0;
+ CHECK_CB(set_clos);
+ return isst_ops->set_clos(id, clos, clos_config);
}
int isst_clos_get_assoc_status(struct isst_id *id, int *clos_id)
{
- unsigned int resp;
- unsigned int param;
- int core_id, ret;
-
- core_id = find_phy_core_num(id->cpu);
- param = core_id;
-
- ret = isst_send_mbox_command(id->cpu, CONFIG_CLOS, CLOS_PQR_ASSOC, param, 0,
- &resp);
- if (ret)
- return ret;
-
- debug_printf("cpu:%d CLOS_PQR_ASSOC param:%x resp:%x\n", id->cpu, param,
- resp);
- *clos_id = (resp >> 16) & 0x03;
-
- return 0;
+ CHECK_CB(clos_get_assoc_status);
+ return isst_ops->clos_get_assoc_status(id, clos_id);
}
int isst_clos_associate(struct isst_id *id, int clos_id)
{
- unsigned int req, resp;
- unsigned int param;
- int core_id, ret;
+ CHECK_CB(clos_associate);
+ return isst_ops->clos_associate(id, clos_id);
- req = (clos_id & 0x03) << 16;
- core_id = find_phy_core_num(id->cpu);
- param = BIT(MBOX_CMD_WRITE_BIT) | core_id;
-
- ret = isst_send_mbox_command(id->cpu, CONFIG_CLOS, CLOS_PQR_ASSOC, param,
- req, &resp);
- if (ret)
- return ret;
-
- debug_printf("cpu:%d CLOS_PQR_ASSOC param:%x req:%x\n", id->cpu, param,
- req);
-
- return 0;
}
diff --git a/tools/power/x86/intel-speed-select/isst-daemon.c b/tools/power/x86/intel-speed-select/isst-daemon.c
index c2290ef0e3af..12053fa43542 100644
--- a/tools/power/x86/intel-speed-select/isst-daemon.c
+++ b/tools/power/x86/intel-speed-select/isst-daemon.c
@@ -20,16 +20,17 @@
#include "isst.h"
-static int per_package_levels_info[MAX_PACKAGE_COUNT][MAX_DIE_PER_PACKAGE];
-static time_t per_package_levels_tm[MAX_PACKAGE_COUNT][MAX_DIE_PER_PACKAGE];
+static int per_package_levels_info[MAX_PACKAGE_COUNT][MAX_DIE_PER_PACKAGE][MAX_PUNIT_PER_DIE];
+static time_t per_package_levels_tm[MAX_PACKAGE_COUNT][MAX_DIE_PER_PACKAGE][MAX_PUNIT_PER_DIE];
static void init_levels(void)
{
- int i, j;
+ int i, j, k;
for (i = 0; i < MAX_PACKAGE_COUNT; ++i)
for (j = 0; j < MAX_DIE_PER_PACKAGE; ++j)
- per_package_levels_info[i][j] = -1;
+ for (k = 0; k < MAX_PUNIT_PER_DIE; ++k)
+ per_package_levels_info[i][j][k] = -1;
}
void process_level_change(struct isst_id *id)
@@ -39,16 +40,16 @@ void process_level_change(struct isst_id *id)
time_t tm;
int ret;
- if (id->pkg < 0 || id->die < 0) {
+ if (id->pkg < 0 || id->die < 0 || id->punit < 0) {
debug_printf("Invalid package/die info for cpu:%d\n", id->cpu);
return;
}
tm = time(NULL);
- if (tm - per_package_levels_tm[id->pkg][id->die] < 2)
+ if (tm - per_package_levels_tm[id->pkg][id->die][id->punit] < 2)
return;
- per_package_levels_tm[id->pkg][id->die] = tm;
+ per_package_levels_tm[id->pkg][id->die][id->punit] = tm;
ret = isst_get_ctdp_levels(id, &pkg_dev);
if (ret) {
@@ -64,14 +65,14 @@ void process_level_change(struct isst_id *id)
return;
}
- if (per_package_levels_info[id->pkg][id->die] == pkg_dev.current_level)
+ if (per_package_levels_info[id->pkg][id->die][id->punit] == pkg_dev.current_level)
return;
debug_printf("**Config level change for cpu:%d pkg:%d die:%d from %d to %d\n",
- id->cpu, id->pkg, id->die, per_package_levels_info[id->pkg][id->die],
+ id->cpu, id->pkg, id->die, per_package_levels_info[id->pkg][id->die][id->punit],
pkg_dev.current_level);
- per_package_levels_info[id->pkg][id->die] = pkg_dev.current_level;
+ per_package_levels_info[id->pkg][id->die][id->punit] = pkg_dev.current_level;
ctdp_level.core_cpumask_size =
alloc_cpu_set(&ctdp_level.core_cpumask);
@@ -82,6 +83,19 @@ void process_level_change(struct isst_id *id)
return;
}
+ if (use_cgroupv2()) {
+ int ret;
+
+ ret = enable_cpuset_controller();
+ if (ret)
+ goto use_offline;
+
+ isolate_cpus(id, ctdp_level.core_cpumask_size, ctdp_level.core_cpumask, pkg_dev.current_level);
+
+ goto free_mask;
+ }
+
+use_offline:
if (ctdp_level.cpu_count) {
int i, max_cpus = get_topo_max_cpus();
for (i = 0; i < max_cpus; ++i) {
@@ -96,7 +110,7 @@ void process_level_change(struct isst_id *id)
}
}
}
-
+free_mask:
free_cpu_set(ctdp_level.core_cpumask);
}
@@ -108,7 +122,7 @@ static void _poll_for_config_change(struct isst_id *id, void *arg1, void *arg2,
static void poll_for_config_change(void)
{
- for_each_online_package_in_set(_poll_for_config_change, NULL, NULL,
+ for_each_online_power_domain_in_set(_poll_for_config_change, NULL, NULL,
NULL, NULL);
}
diff --git a/tools/power/x86/intel-speed-select/isst-display.c b/tools/power/x86/intel-speed-select/isst-display.c
index 7feadac04a6f..0403d42ab1ba 100644
--- a/tools/power/x86/intel-speed-select/isst-display.c
+++ b/tools/power/x86/intel-speed-select/isst-display.c
@@ -169,21 +169,30 @@ static void format_and_print(FILE *outf, int level, char *header, char *value)
static int print_package_info(struct isst_id *id, FILE *outf)
{
char header[256];
+ int level = 1;
if (out_format_is_json()) {
- snprintf(header, sizeof(header), "package-%d:die-%d:cpu-%d",
- id->pkg, id->die, id->cpu);
- format_and_print(outf, 1, header, NULL);
+ if (api_version() > 1)
+ snprintf(header, sizeof(header), "package-%d:die-%d:powerdomain-%d:cpu-%d",
+ id->pkg, id->die, id->punit, id->cpu);
+ else
+ snprintf(header, sizeof(header), "package-%d:die-%d:cpu-%d",
+ id->pkg, id->die, id->cpu);
+ format_and_print(outf, level, header, NULL);
return 1;
}
snprintf(header, sizeof(header), "package-%d", id->pkg);
- format_and_print(outf, 1, header, NULL);
+ format_and_print(outf, level++, header, NULL);
snprintf(header, sizeof(header), "die-%d", id->die);
- format_and_print(outf, 2, header, NULL);
+ format_and_print(outf, level++, header, NULL);
+ if (api_version() > 1) {
+ snprintf(header, sizeof(header), "powerdomain-%d", id->punit);
+ format_and_print(outf, level++, header, NULL);
+ }
snprintf(header, sizeof(header), "cpu-%d", id->cpu);
- format_and_print(outf, 3, header, NULL);
+ format_and_print(outf, level, header, NULL);
- return 3;
+ return level;
}
static void _isst_pbf_display_information(struct isst_id *id, FILE *outf, int level,
@@ -198,7 +207,7 @@ static void _isst_pbf_display_information(struct isst_id *id, FILE *outf, int le
snprintf(header, sizeof(header), "high-priority-base-frequency(MHz)");
snprintf(value, sizeof(value), "%d",
- pbf_info->p1_high * DISP_FREQ_MULTIPLIER);
+ pbf_info->p1_high * isst_get_disp_freq_multiplier());
format_and_print(outf, disp_level + 1, header, value);
snprintf(header, sizeof(header), "high-priority-cpu-mask");
@@ -214,7 +223,7 @@ static void _isst_pbf_display_information(struct isst_id *id, FILE *outf, int le
snprintf(header, sizeof(header), "low-priority-base-frequency(MHz)");
snprintf(value, sizeof(value), "%d",
- pbf_info->p1_low * DISP_FREQ_MULTIPLIER);
+ pbf_info->p1_low * isst_get_disp_freq_multiplier());
format_and_print(outf, disp_level + 1, header, value);
if (is_clx_n_platform())
@@ -235,6 +244,7 @@ static void _isst_fact_display_information(struct isst_id *id, FILE *outf, int l
int base_level)
{
struct isst_fact_bucket_info *bucket_info = fact_info->bucket_info;
+ int trl_max_levels = isst_get_trl_max_levels();
char header[256];
char value[256];
int print = 0, j;
@@ -243,7 +253,8 @@ static void _isst_fact_display_information(struct isst_id *id, FILE *outf, int l
if (fact_bucket != 0xff && fact_bucket != j)
continue;
- if (!bucket_info[j].high_priority_cores_count)
+ /* core count must be valid for CPU power domain */
+ if (!bucket_info[j].hp_cores && id->cpu >= 0)
break;
print = 1;
@@ -256,10 +267,12 @@ static void _isst_fact_display_information(struct isst_id *id, FILE *outf, int l
snprintf(header, sizeof(header), "speed-select-turbo-freq-properties");
format_and_print(outf, base_level, header, NULL);
for (j = 0; j < ISST_FACT_MAX_BUCKETS; ++j) {
+ int i;
+
if (fact_bucket != 0xff && fact_bucket != j)
continue;
- if (!bucket_info[j].high_priority_cores_count)
+ if (!bucket_info[j].hp_cores)
break;
snprintf(header, sizeof(header), "bucket-%d", j);
@@ -267,75 +280,49 @@ static void _isst_fact_display_information(struct isst_id *id, FILE *outf, int l
snprintf(header, sizeof(header), "high-priority-cores-count");
snprintf(value, sizeof(value), "%d",
- bucket_info[j].high_priority_cores_count);
+ bucket_info[j].hp_cores);
format_and_print(outf, base_level + 2, header, value);
-
- if (fact_avx & 0x01) {
- snprintf(header, sizeof(header),
- "high-priority-max-frequency(MHz)");
- snprintf(value, sizeof(value), "%d",
- bucket_info[j].sse_trl * DISP_FREQ_MULTIPLIER);
- format_and_print(outf, base_level + 2, header, value);
- }
-
- if (fact_avx & 0x02) {
- snprintf(header, sizeof(header),
- "high-priority-max-avx2-frequency(MHz)");
- snprintf(value, sizeof(value), "%d",
- bucket_info[j].avx_trl * DISP_FREQ_MULTIPLIER);
- format_and_print(outf, base_level + 2, header, value);
- }
-
- if (fact_avx & 0x04) {
- snprintf(header, sizeof(header),
- "high-priority-max-avx512-frequency(MHz)");
+ for (i = 0; i < trl_max_levels; i++) {
+ if (!bucket_info[j].hp_ratios[i] || (fact_avx != 0xFF && !(fact_avx & (1 << i))))
+ continue;
+ if (i == 0 && api_version() == 1 && !is_emr_platform())
+ snprintf(header, sizeof(header),
+ "high-priority-max-frequency(MHz)");
+ else
+ snprintf(header, sizeof(header),
+ "high-priority-max-%s-frequency(MHz)", isst_get_trl_level_name(i));
snprintf(value, sizeof(value), "%d",
- bucket_info[j].avx512_trl *
- DISP_FREQ_MULTIPLIER);
+ bucket_info[j].hp_ratios[i] * isst_get_disp_freq_multiplier());
format_and_print(outf, base_level + 2, header, value);
}
}
snprintf(header, sizeof(header),
"speed-select-turbo-freq-clip-frequencies");
format_and_print(outf, base_level + 1, header, NULL);
- snprintf(header, sizeof(header), "low-priority-max-frequency(MHz)");
- snprintf(value, sizeof(value), "%d",
- fact_info->lp_clipping_ratio_license_sse *
- DISP_FREQ_MULTIPLIER);
- format_and_print(outf, base_level + 2, header, value);
- snprintf(header, sizeof(header),
- "low-priority-max-avx2-frequency(MHz)");
- snprintf(value, sizeof(value), "%d",
- fact_info->lp_clipping_ratio_license_avx2 *
- DISP_FREQ_MULTIPLIER);
- format_and_print(outf, base_level + 2, header, value);
- snprintf(header, sizeof(header),
- "low-priority-max-avx512-frequency(MHz)");
- snprintf(value, sizeof(value), "%d",
- fact_info->lp_clipping_ratio_license_avx512 *
- DISP_FREQ_MULTIPLIER);
- format_and_print(outf, base_level + 2, header, value);
+
+ for (j = 0; j < trl_max_levels; j++) {
+ if (!fact_info->lp_ratios[j])
+ continue;
+
+ /* No AVX level name for SSE to be consistent with previous formatting */
+ if (j == 0 && api_version() == 1 && !is_emr_platform())
+ snprintf(header, sizeof(header), "low-priority-max-frequency(MHz)");
+ else
+ snprintf(header, sizeof(header), "low-priority-max-%s-frequency(MHz)",
+ isst_get_trl_level_name(j));
+ snprintf(value, sizeof(value), "%d",
+ fact_info->lp_ratios[j] * isst_get_disp_freq_multiplier());
+ format_and_print(outf, base_level + 2, header, value);
+ }
}
void isst_ctdp_display_core_info(struct isst_id *id, FILE *outf, char *prefix,
unsigned int val, char *str0, char *str1)
{
- char header[256];
char value[256];
- int level = 1;
+ int level = print_package_info(id, outf);
- if (out_format_is_json()) {
- snprintf(header, sizeof(header), "package-%d:die-%d:cpu-%d",
- id->pkg, id->die, id->cpu);
- format_and_print(outf, level++, header, NULL);
- } else {
- snprintf(header, sizeof(header), "package-%d", id->pkg);
- format_and_print(outf, level++, header, NULL);
- snprintf(header, sizeof(header), "die-%d", id->die);
- format_and_print(outf, level++, header, NULL);
- snprintf(header, sizeof(header), "cpu-%d", id->cpu);
- format_and_print(outf, level++, header, NULL);
- }
+ level++;
if (str0 && !val)
snprintf(value, sizeof(value), "%s", str0);
@@ -354,6 +341,7 @@ void isst_ctdp_display_information(struct isst_id *id, FILE *outf, int tdp_level
char header[256];
char value[512];
static int level;
+ int trl_max_levels = isst_get_trl_max_levels();
int i;
if (pkg_dev->processed)
@@ -361,7 +349,7 @@ void isst_ctdp_display_information(struct isst_id *id, FILE *outf, int tdp_level
for (i = 0; i <= pkg_dev->levels; ++i) {
struct isst_pkg_ctdp_level_info *ctdp_level;
- int j;
+ int j, k;
ctdp_level = &pkg_dev->ctdp_level[i];
if (!ctdp_level->processed)
@@ -371,31 +359,33 @@ void isst_ctdp_display_information(struct isst_id *id, FILE *outf, int tdp_level
ctdp_level->level);
format_and_print(outf, level + 1, header, NULL);
- snprintf(header, sizeof(header), "cpu-count");
- j = get_cpu_count(id);
- snprintf(value, sizeof(value), "%d", j);
- format_and_print(outf, level + 2, header, value);
-
- j = CPU_COUNT_S(ctdp_level->core_cpumask_size,
- ctdp_level->core_cpumask);
- if (j) {
- snprintf(header, sizeof(header), "enable-cpu-count");
+ if (id->cpu >= 0) {
+ snprintf(header, sizeof(header), "cpu-count");
+ j = get_cpu_count(id);
snprintf(value, sizeof(value), "%d", j);
format_and_print(outf, level + 2, header, value);
- }
- if (ctdp_level->core_cpumask_size) {
- snprintf(header, sizeof(header), "enable-cpu-mask");
- printcpumask(sizeof(value), value,
- ctdp_level->core_cpumask_size,
- ctdp_level->core_cpumask);
- format_and_print(outf, level + 2, header, value);
+ j = CPU_COUNT_S(ctdp_level->core_cpumask_size,
+ ctdp_level->core_cpumask);
+ if (j) {
+ snprintf(header, sizeof(header), "enable-cpu-count");
+ snprintf(value, sizeof(value), "%d", j);
+ format_and_print(outf, level + 2, header, value);
+ }
- snprintf(header, sizeof(header), "enable-cpu-list");
- printcpulist(sizeof(value), value,
- ctdp_level->core_cpumask_size,
- ctdp_level->core_cpumask);
- format_and_print(outf, level + 2, header, value);
+ if (ctdp_level->core_cpumask_size) {
+ snprintf(header, sizeof(header), "enable-cpu-mask");
+ printcpumask(sizeof(value), value,
+ ctdp_level->core_cpumask_size,
+ ctdp_level->core_cpumask);
+ format_and_print(outf, level + 2, header, value);
+
+ snprintf(header, sizeof(header), "enable-cpu-list");
+ printcpulist(sizeof(value), value,
+ ctdp_level->core_cpumask_size,
+ ctdp_level->core_cpumask);
+ format_and_print(outf, level + 2, header, value);
+ }
}
snprintf(header, sizeof(header), "thermal-design-power-ratio");
@@ -406,41 +396,48 @@ void isst_ctdp_display_information(struct isst_id *id, FILE *outf, int tdp_level
if (!ctdp_level->sse_p1)
ctdp_level->sse_p1 = ctdp_level->tdp_ratio;
snprintf(value, sizeof(value), "%d",
- ctdp_level->sse_p1 * DISP_FREQ_MULTIPLIER);
+ ctdp_level->sse_p1 * isst_get_disp_freq_multiplier());
format_and_print(outf, level + 2, header, value);
if (ctdp_level->avx2_p1) {
snprintf(header, sizeof(header), "base-frequency-avx2(MHz)");
snprintf(value, sizeof(value), "%d",
- ctdp_level->avx2_p1 * DISP_FREQ_MULTIPLIER);
+ ctdp_level->avx2_p1 * isst_get_disp_freq_multiplier());
format_and_print(outf, level + 2, header, value);
}
if (ctdp_level->avx512_p1) {
snprintf(header, sizeof(header), "base-frequency-avx512(MHz)");
snprintf(value, sizeof(value), "%d",
- ctdp_level->avx512_p1 * DISP_FREQ_MULTIPLIER);
+ ctdp_level->avx512_p1 * isst_get_disp_freq_multiplier());
format_and_print(outf, level + 2, header, value);
}
if (ctdp_level->uncore_pm) {
snprintf(header, sizeof(header), "uncore-frequency-min(MHz)");
snprintf(value, sizeof(value), "%d",
- ctdp_level->uncore_pm * DISP_FREQ_MULTIPLIER);
+ ctdp_level->uncore_pm * isst_get_disp_freq_multiplier());
format_and_print(outf, level + 2, header, value);
}
if (ctdp_level->uncore_p0) {
snprintf(header, sizeof(header), "uncore-frequency-max(MHz)");
snprintf(value, sizeof(value), "%d",
- ctdp_level->uncore_p0 * DISP_FREQ_MULTIPLIER);
+ ctdp_level->uncore_p0 * isst_get_disp_freq_multiplier());
+ format_and_print(outf, level + 2, header, value);
+ }
+
+ if (ctdp_level->amx_p1) {
+ snprintf(header, sizeof(header), "base-frequency-amx(MHz)");
+ snprintf(value, sizeof(value), "%d",
+ ctdp_level->amx_p1 * isst_get_disp_freq_multiplier());
format_and_print(outf, level + 2, header, value);
}
if (ctdp_level->uncore_p1) {
snprintf(header, sizeof(header), "uncore-frequency-base(MHz)");
snprintf(value, sizeof(value), "%d",
- ctdp_level->uncore_p1 * DISP_FREQ_MULTIPLIER);
+ ctdp_level->uncore_p1 * isst_get_disp_freq_multiplier());
format_and_print(outf, level + 2, header, value);
}
@@ -451,6 +448,13 @@ void isst_ctdp_display_information(struct isst_id *id, FILE *outf, int tdp_level
format_and_print(outf, level + 2, header, value);
}
+ if (api_version() > 1) {
+ snprintf(header, sizeof(header), "cooling_type");
+ snprintf(value, sizeof(value), "%d",
+ ctdp_level->cooling_type);
+ format_and_print(outf, level + 2, header, value);
+ }
+
snprintf(header, sizeof(header),
"speed-select-turbo-freq");
if (ctdp_level->fact_support) {
@@ -505,54 +509,24 @@ void isst_ctdp_display_information(struct isst_id *id, FILE *outf, int tdp_level
format_and_print(outf, level + 2, header, value);
}
- snprintf(header, sizeof(header), "turbo-ratio-limits-sse");
- format_and_print(outf, level + 2, header, NULL);
- for (j = 0; j < 8; ++j) {
- snprintf(header, sizeof(header), "bucket-%d", j);
- format_and_print(outf, level + 3, header, NULL);
+ for (k = 0; k < trl_max_levels; k++) {
+ if (!ctdp_level->trl_ratios[k][0])
+ continue;
- snprintf(header, sizeof(header), "core-count");
- snprintf(value, sizeof(value), "%llu", (ctdp_level->buckets_info >> (j * 8)) & 0xff);
- format_and_print(outf, level + 4, header, value);
-
- snprintf(header, sizeof(header),
- "max-turbo-frequency(MHz)");
- snprintf(value, sizeof(value), "%d",
- ctdp_level->trl_sse_active_cores[j] *
- DISP_FREQ_MULTIPLIER);
- format_and_print(outf, level + 4, header, value);
- }
-
- if (ctdp_level->trl_avx_active_cores[0]) {
- snprintf(header, sizeof(header), "turbo-ratio-limits-avx2");
+ snprintf(header, sizeof(header), "turbo-ratio-limits-%s", isst_get_trl_level_name(k));
format_and_print(outf, level + 2, header, NULL);
- for (j = 0; j < 8; ++j) {
- snprintf(header, sizeof(header), "bucket-%d", j);
- format_and_print(outf, level + 3, header, NULL);
- snprintf(header, sizeof(header), "core-count");
- snprintf(value, sizeof(value), "%llu", (ctdp_level->buckets_info >> (j * 8)) & 0xff);
- format_and_print(outf, level + 4, header, value);
-
- snprintf(header, sizeof(header), "max-turbo-frequency(MHz)");
- snprintf(value, sizeof(value), "%d", ctdp_level->trl_avx_active_cores[j] * DISP_FREQ_MULTIPLIER);
- format_and_print(outf, level + 4, header, value);
- }
- }
-
- if (ctdp_level->trl_avx_512_active_cores[0]) {
- snprintf(header, sizeof(header), "turbo-ratio-limits-avx512");
- format_and_print(outf, level + 2, header, NULL);
for (j = 0; j < 8; ++j) {
snprintf(header, sizeof(header), "bucket-%d", j);
format_and_print(outf, level + 3, header, NULL);
snprintf(header, sizeof(header), "core-count");
- snprintf(value, sizeof(value), "%llu", (ctdp_level->buckets_info >> (j * 8)) & 0xff);
+
+ snprintf(value, sizeof(value), "%llu", (ctdp_level->trl_cores >> (j * 8)) & 0xff);
format_and_print(outf, level + 4, header, value);
snprintf(header, sizeof(header), "max-turbo-frequency(MHz)");
- snprintf(value, sizeof(value), "%d", ctdp_level->trl_avx_512_active_cores[j] * DISP_FREQ_MULTIPLIER);
+ snprintf(value, sizeof(value), "%d", ctdp_level->trl_ratios[k][j] * isst_get_disp_freq_multiplier());
format_and_print(outf, level + 4, header, value);
}
}
@@ -631,18 +605,18 @@ void isst_clos_display_information(struct isst_id *id, FILE *outf, int clos,
format_and_print(outf, level + 2, header, value);
snprintf(header, sizeof(header), "clos-min");
- snprintf(value, sizeof(value), "%d MHz", clos_config->clos_min * DISP_FREQ_MULTIPLIER);
+ snprintf(value, sizeof(value), "%d MHz", clos_config->clos_min * isst_get_disp_freq_multiplier());
format_and_print(outf, level + 2, header, value);
snprintf(header, sizeof(header), "clos-max");
- if (clos_config->clos_max == 0xff)
+ if ((clos_config->clos_max * isst_get_disp_freq_multiplier()) == 25500)
snprintf(value, sizeof(value), "Max Turbo frequency");
else
- snprintf(value, sizeof(value), "%d MHz", clos_config->clos_max * DISP_FREQ_MULTIPLIER);
+ snprintf(value, sizeof(value), "%d MHz", clos_config->clos_max * isst_get_disp_freq_multiplier());
format_and_print(outf, level + 2, header, value);
snprintf(header, sizeof(header), "clos-desired");
- snprintf(value, sizeof(value), "%d MHz", clos_config->clos_desired * DISP_FREQ_MULTIPLIER);
+ snprintf(value, sizeof(value), "%d MHz", clos_config->clos_desired * isst_get_disp_freq_multiplier());
format_and_print(outf, level + 2, header, value);
format_and_print(outf, level, NULL, NULL);
@@ -717,8 +691,7 @@ void isst_display_result(struct isst_id *id, FILE *outf, char *feature, char *cm
char value[256];
int level = 3;
- if (id->cpu >= 0)
- level = print_package_info(id, outf);
+ level = print_package_info(id, outf);
snprintf(header, sizeof(header), "%s", feature);
format_and_print(outf, level + 1, header, NULL);
diff --git a/tools/power/x86/intel-speed-select/isst.h b/tools/power/x86/intel-speed-select/isst.h
index 824876e31e23..54fc21575d56 100644
--- a/tools/power/x86/intel-speed-select/isst.h
+++ b/tools/power/x86/intel-speed-select/isst.h
@@ -28,6 +28,8 @@
#include <stdarg.h>
#include <sys/ioctl.h>
+#include <linux/isst_if.h>
+
#define BIT(x) (1 << (x))
#define BIT_ULL(nr) (1ULL << (nr))
#define GENMASK(h, l) (((~0UL) << (l)) & (~0UL >> (sizeof(long) * 8 - 1 - (h))))
@@ -77,29 +79,29 @@
#define DISP_FREQ_MULTIPLIER 100
-#define MAX_PACKAGE_COUNT 8
-#define MAX_DIE_PER_PACKAGE 2
+#define MAX_PACKAGE_COUNT 8
+#define MAX_DIE_PER_PACKAGE 2
+#define MAX_PUNIT_PER_DIE 8
/* Unified structure to specific a CPU or a Power Domain */
struct isst_id {
int cpu;
int pkg;
int die;
+ int punit;
};
struct isst_clos_config {
+ unsigned int clos_min;
+ unsigned int clos_max;
unsigned char epp;
unsigned char clos_prop_prio;
- unsigned char clos_min;
- unsigned char clos_max;
unsigned char clos_desired;
};
struct isst_fact_bucket_info {
- int high_priority_cores_count;
- int sse_trl;
- int avx_trl;
- int avx512_trl;
+ int hp_cores;
+ int hp_ratios[TRL_MAX_LEVELS];
};
struct isst_pbf_info {
@@ -117,9 +119,7 @@ struct isst_pbf_info {
#define ISST_TRL_MAX_ACTIVE_CORES 8
#define ISST_FACT_MAX_BUCKETS 8
struct isst_fact_info {
- int lp_clipping_ratio_license_sse;
- int lp_clipping_ratio_license_avx2;
- int lp_clipping_ratio_license_avx512;
+ int lp_ratios[TRL_MAX_LEVELS];
struct isst_fact_bucket_info bucket_info[ISST_FACT_MAX_BUCKETS];
};
@@ -143,20 +143,20 @@ struct isst_pkg_ctdp_level_info {
int pkg_max_power;
int fact;
int t_proc_hot;
+ int cooling_type;
int uncore_p0;
int uncore_p1;
int uncore_pm;
int sse_p1;
int avx2_p1;
int avx512_p1;
+ int amx_p1;
int mem_freq;
size_t core_cpumask_size;
cpu_set_t *core_cpumask;
int cpu_count;
- unsigned long long buckets_info;
- int trl_sse_active_cores[ISST_TRL_MAX_ACTIVE_CORES];
- int trl_avx_active_cores[ISST_TRL_MAX_ACTIVE_CORES];
- int trl_avx_512_active_cores[ISST_TRL_MAX_ACTIVE_CORES];
+ unsigned long long trl_cores; /* Buckets info */
+ int trl_ratios[TRL_MAX_LEVELS][ISST_TRL_MAX_ACTIVE_CORES];
int kobj_bucket_index;
int active_bucket;
int fact_max_index;
@@ -178,13 +178,48 @@ struct isst_pkg_ctdp {
struct isst_pkg_ctdp_level_info ctdp_level[ISST_MAX_TDP_LEVELS];
};
+enum isst_platform_param {
+ ISST_PARAM_MBOX_DELAY,
+ ISST_PARAM_MBOX_RETRIES,
+};
+
+struct isst_platform_ops {
+ int (*get_disp_freq_multiplier)(void);
+ int (*get_trl_max_levels)(void);
+ char *(*get_trl_level_name)(int level);
+ void (*update_platform_param)(enum isst_platform_param param, int value);
+ int (*is_punit_valid)(struct isst_id *id);
+ int (*read_pm_config)(struct isst_id *id, int *cp_state, int *cp_cap);
+ int (*get_config_levels)(struct isst_id *id, struct isst_pkg_ctdp *pkg_ctdp);
+ int (*get_ctdp_control)(struct isst_id *id, int config_index, struct isst_pkg_ctdp_level_info *ctdp_level);
+ int (*get_tdp_info)(struct isst_id *id, int config_index, struct isst_pkg_ctdp_level_info *ctdp_level);
+ int (*get_pwr_info)(struct isst_id *id, int config_index, struct isst_pkg_ctdp_level_info *ctdp_level);
+ int (*get_coremask_info)(struct isst_id *id, int config_index, struct isst_pkg_ctdp_level_info *ctdp_level);
+ int (*get_get_trl)(struct isst_id *id, int level, int avx_level, int *trl);
+ int (*get_get_trls)(struct isst_id *id, int level, struct isst_pkg_ctdp_level_info *ctdp_level);
+ int (*get_trl_bucket_info)(struct isst_id *id, int level, unsigned long long *buckets_info);
+ int (*set_tdp_level)(struct isst_id *id, int tdp_level);
+ int (*get_pbf_info)(struct isst_id *id, int level, struct isst_pbf_info *pbf_info);
+ int (*set_pbf_fact_status)(struct isst_id *id, int pbf, int enable);
+ int (*get_fact_info)(struct isst_id *id, int level, int fact_bucket, struct isst_fact_info *fact_info);
+ void (*adjust_uncore_freq)(struct isst_id *id, int config_index, struct isst_pkg_ctdp_level_info *ctdp_level);
+ int (*get_clos_information)(struct isst_id *id, int *enable, int *type);
+ int (*pm_qos_config)(struct isst_id *id, int enable_clos, int priority_type);
+ int (*pm_get_clos)(struct isst_id *id, int clos, struct isst_clos_config *clos_config);
+ int (*set_clos)(struct isst_id *id, int clos, struct isst_clos_config *clos_config);
+ int (*clos_get_assoc_status)(struct isst_id *id, int *clos_id);
+ int (*clos_associate)(struct isst_id *id, int clos_id);
+};
+
extern int is_cpu_in_power_domain(int cpu, struct isst_id *id);
extern int get_topo_max_cpus(void);
extern int get_cpu_count(struct isst_id *id);
extern int get_max_punit_core_id(struct isst_id *id);
+extern int api_version(void);
/* Common interfaces */
FILE *get_output_file(void);
+extern int is_debug_enabled(void);
extern void debug_printf(const char *format, ...);
extern int out_format_is_json(void);
extern void set_isst_id(struct isst_id *id, int cpu);
@@ -196,21 +231,22 @@ extern void set_cpu_mask_from_punit_coremask(struct isst_id *id,
size_t core_cpumask_size,
cpu_set_t *core_cpumask,
int *cpu_cnt);
-
-extern int isst_send_mbox_command(unsigned int cpu, unsigned char command,
- unsigned char sub_command,
- unsigned int write,
- unsigned int req_data, unsigned int *resp);
-
extern int isst_send_msr_command(unsigned int cpu, unsigned int command,
int write, unsigned long long *req_resp);
+extern int isst_set_platform_ops(int api_version);
+extern void isst_update_platform_param(enum isst_platform_param, int vale);
+extern int isst_get_disp_freq_multiplier(void);
+extern int isst_get_trl_max_levels(void);
+extern char *isst_get_trl_level_name(int level);
+extern int isst_is_punit_valid(struct isst_id *id);
+
extern int isst_get_ctdp_levels(struct isst_id *id, struct isst_pkg_ctdp *pkg_dev);
extern int isst_get_ctdp_control(struct isst_id *id, int config_index,
struct isst_pkg_ctdp_level_info *ctdp_level);
extern int isst_get_coremask_info(struct isst_id *id, int config_index,
struct isst_pkg_ctdp_level_info *ctdp_level);
-extern void isst_get_uncore_p0_p1_info(struct isst_id *id, int config_index,
+extern void isst_adjust_uncore_freq(struct isst_id *id, int config_index,
struct isst_pkg_ctdp_level_info *ctdp_level);
extern int isst_get_process_ctdp(struct isst_id *id, int tdp_level,
struct isst_pkg_ctdp *pkg_dev);
@@ -228,11 +264,8 @@ extern int isst_set_tdp_level(struct isst_id *id, int tdp_level);
extern int isst_set_pbf_fact_status(struct isst_id *id, int pbf, int enable);
extern int isst_get_pbf_info(struct isst_id *id, int level,
struct isst_pbf_info *pbf_info);
-extern void isst_get_pbf_info_complete(struct isst_pbf_info *pbf_info);
extern int isst_get_fact_info(struct isst_id *id, int level, int fact_bucket,
struct isst_fact_info *fact_info);
-extern int isst_get_fact_bucket_info(struct isst_id *id, int level,
- struct isst_fact_bucket_info *bucket_info);
extern void isst_fact_display_information(struct isst_id *id, FILE *outf, int level,
int fact_bucket, int fact_avx,
struct isst_fact_info *fact_info);
@@ -265,11 +298,12 @@ extern int isst_read_pm_config(struct isst_id *id, int *cp_state, int *cp_cap);
extern void isst_display_error_info_message(int error, char *msg, int arg_valid, int arg);
extern int is_skx_based_platform(void);
extern int is_spr_platform(void);
+extern int is_emr_platform(void);
extern int is_icx_platform(void);
extern void isst_trl_display_information(struct isst_id *id, FILE *outf, unsigned long long trl);
extern void set_cpu_online_offline(int cpu, int state);
-extern void for_each_online_package_in_set(void (*callback)(struct isst_id *, void *, void *,
+extern void for_each_online_power_domain_in_set(void (*callback)(struct isst_id *, void *, void *,
void *, void *),
void *arg1, void *arg2, void *arg3,
void *arg4);
@@ -277,4 +311,14 @@ extern int isst_daemon(int debug_mode, int poll_interval, int no_daemon);
extern void process_level_change(struct isst_id *id);
extern int hfi_main(void);
extern void hfi_exit(void);
+
+/* Interface specific callbacks */
+extern struct isst_platform_ops *mbox_get_platform_ops(void);
+extern struct isst_platform_ops *tpmi_get_platform_ops(void);
+
+/* Cgroup related interface */
+extern int enable_cpuset_controller(void);
+extern int isolate_cpus(struct isst_id *id, int mask_size, cpu_set_t *cpu_mask, int level);
+extern int use_cgroupv2(void);
+
#endif