aboutsummaryrefslogtreecommitdiff
path: root/SOURCES/rog-ally-gyro-fix.patch
diff options
context:
space:
mode:
authorJan200101 <sentrycraft123@gmail.com>2024-04-18 15:10:48 +0200
committerJan200101 <sentrycraft123@gmail.com>2024-04-18 15:10:48 +0200
commitbde575cbc9394d605daacfb57607ea423cfeb0e6 (patch)
tree2a02d07dc5cfd53c506a1295b1118815d6ac6018 /SOURCES/rog-ally-gyro-fix.patch
parentb73e8ba505265eec22cea48304a5a3bdb4a961aa (diff)
downloadkernel-fsync-bde575cbc9394d605daacfb57607ea423cfeb0e6.tar.gz
kernel-fsync-bde575cbc9394d605daacfb57607ea423cfeb0e6.zip
kernel 6.8.7
Diffstat (limited to 'SOURCES/rog-ally-gyro-fix.patch')
-rw-r--r--SOURCES/rog-ally-gyro-fix.patch276
1 files changed, 189 insertions, 87 deletions
diff --git a/SOURCES/rog-ally-gyro-fix.patch b/SOURCES/rog-ally-gyro-fix.patch
index b5f57cc..8416b43 100644
--- a/SOURCES/rog-ally-gyro-fix.patch
+++ b/SOURCES/rog-ally-gyro-fix.patch
@@ -1,120 +1,222 @@
-diff --git a/drivers/iio/accel/bmc150-accel-core.c b/drivers/iio/accel/bmc150-accel-core.c
-index 1105918..d665a6e 100644
---- a/drivers/iio/accel/bmc150-accel-core.c
-+++ b/drivers/iio/accel/bmc150-accel-core.c
-@@ -10,6 +10,7 @@
- #include <linux/delay.h>
- #include <linux/slab.h>
- #include <linux/acpi.h>
-+#include <linux/dmi.h>
- #include <linux/of_irq.h>
- #include <linux/pm.h>
- #include <linux/pm_runtime.h>
-@@ -1670,6 +1671,8 @@ int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq,
- struct iio_dev *indio_dev;
- int ret;
+From: Jonathan LoBue <jlobue10@gmail.com>
+
+Adds a description of the duplicate ACPI identifier issue
+between devices using bmc150 and bmi323.
+
+Tested-by: Hans de Goede <hdegoede@redhat.com>
+Reviewed-by: Hans de Goede <hdegoede@redhat.com>
+Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
+Co-developed-by: Luke D. Jones <luke@ljones.dev>
+Signed-off-by: Luke D. Jones <luke@ljones.dev>
+Co-developed-by: Denis Benato <benato.denis96@gmail.com>
+Signed-off-by: Denis Benato <benato.denis96@gmail.com>
+Co-developed-by: Antheas Kapenekakis <lkml@antheas.dev>
+Signed-off-by: Antheas Kapenekakis <lkml@antheas.dev>
+Signed-off-by: Jonathan LoBue <jlobue10@gmail.com>
+---
+ drivers/iio/accel/bmc150-accel-i2c.c | 13 +++++++++++++
+ 1 file changed, 13 insertions(+)
+
+diff --git a/drivers/iio/accel/bmc150-accel-i2c.c b/drivers/iio/accel/bmc150-accel-i2c.c
+index ee1ba134ad42..353271e23235 100644
+--- a/drivers/iio/accel/bmc150-accel-i2c.c
++++ b/drivers/iio/accel/bmc150-accel-i2c.c
+@@ -224,6 +224,19 @@ static const struct acpi_device_id bmc150_accel_acpi_match[] = {
+ {"BMA250E"},
+ {"BMC150A"},
+ {"BMI055A"},
++ /*
++ * The "BOSC0200" identifier used here is not unique to devices using
++ * bmc150. The same "BOSC0200" identifier is found in the ACPI tables of
++ * the ASUS ROG ALLY and Ayaneo AIR Plus which both use a Bosch BMI323
++ * chip. This creates a conflict with duplicate ACPI identifiers which
++ * multiple drivers want to use. Fortunately, when the bmc150 driver
++ * starts to load on the ASUS ROG ALLY, the chip ID check portion fails
++ * (correctly) because the chip IDs received (via i2c) are unique between
++ * bmc150 and bmi323 and a dmesg output similar to this:
++ * "bmc150_accel_i2c i2c-BOSC0200:00: Invalid chip 0" can be seen.
++ * This allows the bmi323 driver to take over for ASUS ROG ALLY, and
++ * other devices using the bmi323 chip.
++ */
+ {"BOSC0200"},
+ {"BSBA0150"},
+ {"DUAL250E"},
+From: Jonathan LoBue <jlobue10@gmail.com>
+
+Adds the ACPI match table for ASUS ROG ALLY to load the bmi323
+driver with an ACPI match of "BOSC0200", and a comment about duplicate
+ACPI identifiers between devices using the bmc150 and bmi323 chips.
+
+Tested-by: Hans de Goede <hdegoede@redhat.com>
+Reviewed-by: Hans de Goede <hdegoede@redhat.com>
+Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
+Co-developed-by: Luke D. Jones <luke@ljones.dev>
+Signed-off-by: Luke D. Jones <luke@ljones.dev>
+Co-developed-by: Denis Benato <benato.denis96@gmail.com>
+Signed-off-by: Denis Benato <benato.denis96@gmail.com>
+Co-developed-by: Antheas Kapenekakis <lkml@antheas.dev>
+Signed-off-by: Antheas Kapenekakis <lkml@antheas.dev>
+Signed-off-by: Jonathan LoBue <jlobue10@gmail.com>
+---
+ drivers/iio/imu/bmi323/bmi323_i2c.c | 20 ++++++++++++++++++++
+ 1 file changed, 20 insertions(+)
-+ if (dmi_match(DMI_BOARD_NAME, "RC71L") || (dmi_match(DMI_BOARD_NAME, "AB05-AMD") && dmi_match(DMI_PRODUCT_NAME, "AIR Plus")))
-+ return -ENODEV; // Abort loading bmc150 for ASUS ROG ALLY, Ayaneo Air Plus
- indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
- if (!indio_dev)
- return -ENOMEM;
diff --git a/drivers/iio/imu/bmi323/bmi323_i2c.c b/drivers/iio/imu/bmi323/bmi323_i2c.c
-index 20a8001..346ba2d 100644
+index 20a8001b9956..f7550503e47e 100644
--- a/drivers/iio/imu/bmi323/bmi323_i2c.c
+++ b/drivers/iio/imu/bmi323/bmi323_i2c.c
-@@ -5,6 +5,7 @@
- * Copyright (C) 2023, Jagath Jog J <jagathjog1996@gmail.com>
- */
-
-+#include <linux/acpi.h>
- #include <linux/i2c.h>
- #include <linux/mod_devicetable.h>
- #include <linux/module.h>
-@@ -93,6 +94,12 @@ static int bmi323_i2c_probe(struct i2c_client *i2c)
+@@ -93,6 +93,25 @@ static int bmi323_i2c_probe(struct i2c_client *i2c)
return bmi323_core_probe(dev);
}
+static const struct acpi_device_id bmi323_acpi_match[] = {
-+ {"BOSC0200"},
-+ { },
++ /*
++ * The "BOSC0200" identifier used here is not unique to bmi323 devices.
++ * The same "BOSC0200" identifier is found in the ACPI tables of devices
++ * using the bmc150 chip. This creates a conflict with duplicate ACPI
++ * identifiers which multiple drivers want to use. If a non-bmi323 device
++ * starts to load with this "BOSC0200" ACPI match here, then the chip
++ * ID check portion should fail because the chip IDs received (via i2c) are
++ * unique between bmc150 and bmi323 and the driver should relinquish the
++ * device. If and when a different driver (such as bmc150) starts to load
++ * with the "BOSC0200" ACPI match, a short reset should ensure that the
++ * device is not in a bad state during that driver initialization. This
++ * device reset does occur in both the bmi323 and bmc150 init sequences.
++ */
++ { "BOSC0200" },
++ { }
+};
+MODULE_DEVICE_TABLE(acpi, bmi323_acpi_match);
+
static const struct i2c_device_id bmi323_i2c_ids[] = {
{ "bmi323" },
{ }
-@@ -109,6 +116,7 @@ static struct i2c_driver bmi323_i2c_driver = {
+@@ -109,6 +128,7 @@ static struct i2c_driver bmi323_i2c_driver = {
.driver = {
.name = "bmi323",
.of_match_table = bmi323_of_i2c_match,
-+ .acpi_match_table = ACPI_PTR(bmi323_acpi_match),
++ .acpi_match_table = bmi323_acpi_match,
},
.probe = bmi323_i2c_probe,
.id_table = bmi323_i2c_ids,
-diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
-index d752e9c..b495dba 100644
---- a/drivers/iio/industrialio-core.c
-+++ b/drivers/iio/industrialio-core.c
-@@ -13,6 +13,7 @@
- #include <linux/cdev.h>
- #include <linux/debugfs.h>
+From: Jonathan LoBue <jlobue10@gmail.com>
+Date: Sun, 25 Feb 2024 14:43:01 -0800
+Subject: [PATCH] iio: imu: bmi323: Implement ACPI method ROTM for mount matrix
+
+Retrieve mount matrix from ACPI ROTM table.
+
+---
+ drivers/iio/imu/bmi323/bmi323_core.c | 79 ++++++++++++++++++++++++++--
+ 1 file changed, 76 insertions(+), 3 deletions(-)
+
+diff --git a/drivers/iio/imu/bmi323/bmi323_core.c b/drivers/iio/imu/bmi323/bmi323_core.c
+index 183af482828f..bb9f05183814 100644
+--- a/drivers/iio/imu/bmi323/bmi323_core.c
++++ b/drivers/iio/imu/bmi323/bmi323_core.c
+@@ -7,6 +7,7 @@
+ * Datasheet: https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmi323-ds000.pdf
+ */
+
++#include <linux/acpi.h>
+ #include <linux/bitfield.h>
+ #include <linux/cleanup.h>
#include <linux/device.h>
-+#include <linux/dmi.h>
- #include <linux/err.h>
- #include <linux/fs.h>
- #include <linux/idr.h>
-@@ -571,6 +572,14 @@ static const struct iio_mount_matrix iio_mount_idmatrix = {
- }
- };
-
-+static const struct iio_mount_matrix iio_mount_invert_x_matrix = {
-+ .rotation = {
-+ "-1", "0", "0",
-+ "0", "1", "0",
-+ "0", "0", "1"
+@@ -1997,6 +1998,76 @@ static int bmi323_set_bw(struct bmi323_data *data,
+ FIELD_PREP(BMI323_ACC_GYRO_CONF_BW_MSK, bw));
+ }
+
++static bool bmi323_acpi_orientation(struct device *dev,
++ struct iio_mount_matrix *orientation)
++{
++ struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
++ struct acpi_device *adev = ACPI_COMPANION(dev);
++ char *str;
++ union acpi_object *obj, *elements;
++ acpi_status status;
++ int i, j, val[3];
++ bool ret = false;
++
++ if (!acpi_has_method(adev->handle, "ROTM"))
++ return false;
++
++ status = acpi_evaluate_object(adev->handle, "ROTM", NULL, &buffer);
++ if (ACPI_FAILURE(status)) {
++ dev_err(dev, "Failed to get ACPI mount matrix: %d\n", status);
++ return false;
+ }
-+};
+
- static int iio_setup_mount_idmatrix(const struct device *dev,
- struct iio_mount_matrix *matrix)
- {
-@@ -579,6 +588,14 @@ static int iio_setup_mount_idmatrix(const struct device *dev,
- return 0;
- }
-
-+static int iio_setup_mount_invert_x_matrix(const struct device *dev,
-+ struct iio_mount_matrix *matrix)
++ obj = buffer.pointer;
++ if (obj->type != ACPI_TYPE_PACKAGE || obj->package.count != 3) {
++ dev_err(dev, "Unknown ACPI mount matrix package format\n");
++ goto out_free_buffer;
++ }
++
++ elements = obj->package.elements;
++ for (i = 0; i < 3; i++) {
++ if (elements[i].type != ACPI_TYPE_STRING) {
++ dev_err(dev, "Unknown ACPI mount matrix element format\n");
++ goto out_free_buffer;
++ }
++
++ str = elements[i].string.pointer;
++ if (sscanf(str, "%d %d %d", &val[0], &val[1], &val[2]) != 3) {
++ dev_err(dev, "Incorrect ACPI mount matrix string format\n");
++ goto out_free_buffer;
++ }
++
++ for (j = 0; j < 3; j++) {
++ switch (val[j]) {
++ case -1: str = "-1"; break;
++ case 0: str = "0"; break;
++ case 1: str = "1"; break;
++ default:
++ dev_err(dev, "Invalid value in ACPI mount matrix: %d\n", val[j]);
++ goto out_free_buffer;
++ }
++ orientation->rotation[i * 3 + j] = str;
++ }
++ }
++
++ ret = true;
++
++out_free_buffer:
++ kfree(buffer.pointer);
++ return ret;
++}
++
++static bool bmi323_apply_acpi_orientation(struct device *dev,
++ struct iio_mount_matrix *orientation)
+{
-+ *matrix = iio_mount_invert_x_matrix;
-+ dev_info(dev, "using inverted X-axis mounting matrix...\n");
-+ return 0;
++ struct acpi_device *adev = ACPI_COMPANION(dev);
++
++ if (adev)
++ return bmi323_acpi_orientation(dev, orientation);
++
++ return false;
+}
+
- ssize_t iio_show_mount_matrix(struct iio_dev *indio_dev, uintptr_t priv,
- const struct iio_chan_spec *chan, char *buf)
+ static int bmi323_init(struct bmi323_data *data)
{
-@@ -615,6 +632,8 @@ int iio_read_mount_matrix(struct device *dev, struct iio_mount_matrix *matrix)
- int err;
-
- err = device_property_read_string_array(dev, "mount-matrix", matrix->rotation, len);
-+ if (dmi_match(DMI_BOARD_NAME, "RC71L"))
-+ return iio_setup_mount_invert_x_matrix(dev, matrix);
- if (err == len)
- return 0;
-
+ int ret, val;
+@@ -2099,9 +2170,11 @@ int bmi323_core_probe(struct device *dev)
+ if (ret)
+ return -EINVAL;
+
+- ret = iio_read_mount_matrix(dev, &data->orientation);
+- if (ret)
+- return ret;
++ if (!bmi323_apply_acpi_orientation(dev, &data->orientation)) {
++ ret = iio_read_mount_matrix(dev, &data->orientation);
++ if (ret)
++ return ret;
++ }
+
+ indio_dev->name = "bmi323-imu";
+ indio_dev->info = &bmi323_info;
diff --git a/drivers/iio/imu/bmi323/bmi323_core.c b/drivers/iio/imu/bmi323/bmi323_core.c
index 0bd5ded..ded8596 100644
--- a/drivers/iio/imu/bmi323/bmi323_core.c
+++ b/drivers/iio/imu/bmi323/bmi323_core.c
-@@ -10,6 +10,7 @@
- #include <linux/bitfield.h>
- #include <linux/cleanup.h>
- #include <linux/device.h>
-+#include <linux/dmi.h>
- #include <linux/interrupt.h>
- #include <linux/minmax.h>
- #include <linux/module.h>
@@ -285,6 +286,9 @@ static const int bmi323_acc_gyro_odr[][2] = {
{ 200, 0 },
{ 400, 0 },
@@ -123,5 +225,5 @@ index 0bd5ded..ded8596 100644
+ { 3200, 0},
+ { 6400, 0},
};
-
+
static const int bmi323_acc_gyro_odrns[] = {