summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean Rhodes <sean@starlabs.systems>2024-01-23 15:10:59 +0000
committerFelix Held <felix-coreboot@felixheld.de>2024-02-21 19:56:56 +0000
commitbba6a21625a744899581364a627e3ffd6d6cda5b (patch)
tree59a3efcba7eabd3929e257d23e1fafd127ba4df7
parent7ae2e2840d57060a27859086a076087389e39b77 (diff)
downloadcoreboot-bba6a21625a744899581364a627e3ffd6d6cda5b.tar.gz
coreboot-bba6a21625a744899581364a627e3ffd6d6cda5b.tar.bz2
coreboot-bba6a21625a744899581364a627e3ffd6d6cda5b.zip
i2c/drivers/generic: Add support for including a rotation matrix
The Rotation Matrix allows the specification of a 3x3 matrix representing the orientation of devices, such as accelerometers. Each value in the matrix can be one of -1, 0, or 1, indicating the transformation applied to the device's axes. It is expected by Linux and required for the OS to interpret the data from the device correctly. It is used by various drivers, mainly in `iio/accel`. It was tested on Ubuntu, by rotating the device and verifying the orientation was correct. Signed-off-by: Sean Rhodes <sean@starlabs.systems> Change-Id: Id4a940d999a0e300a6fe21269f18bab6e3c0523c Reviewed-on: https://review.coreboot.org/c/coreboot/+/80179 Reviewed-by: Matt DeVillier <matt.devillier@gmail.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Felix Held <felix-coreboot@felixheld.de>
-rw-r--r--src/drivers/i2c/generic/chip.h13
-rw-r--r--src/drivers/i2c/generic/generic.c19
2 files changed, 32 insertions, 0 deletions
diff --git a/src/drivers/i2c/generic/chip.h b/src/drivers/i2c/generic/chip.h
index 8e13ffc7bb85..227cb61e1811 100644
--- a/src/drivers/i2c/generic/chip.h
+++ b/src/drivers/i2c/generic/chip.h
@@ -69,6 +69,19 @@ struct drivers_i2c_generic_config {
/* Delay to be inserted after enabling stop. */
unsigned int stop_off_delay_ms;
+ /*
+ * The Rotation Matrix' allows specifying a 3x3 matrix representing
+ * the orientation of devices, such as accelerometers. Each value in
+ * the matrix can be one of -1, 0, or 1, indicating the transformation
+ * applied to the device's axes.
+ *
+ * It is expected by linux and required for the OS to correctly interpret
+ * the data from the device.
+ */
+ bool has_rotation_matrix;
+ int rotation_matrix[9];
+
+
/* Generic properties for exporting device-specific data to the OS */
struct acpi_dp property_list[MAX_GENERIC_PROPERTY_LIST];
int property_count;
diff --git a/src/drivers/i2c/generic/generic.c b/src/drivers/i2c/generic/generic.c
index 2a4acb242f48..03018eed555f 100644
--- a/src/drivers/i2c/generic/generic.c
+++ b/src/drivers/i2c/generic/generic.c
@@ -160,6 +160,25 @@ void i2c_generic_fill_ssdt(const struct device *dev,
acpi_device_add_power_res(&power_res_params);
}
+ /* Rotation Matrix */
+ if (config->has_rotation_matrix) {
+ acpigen_write_method("ROTM", 0);
+ acpigen_write_package(3);
+
+ for (int i = 0; i < 3; i++) {
+ char matrix_row[12];
+ snprintf(matrix_row, sizeof(matrix_row), "%d %d %d",
+ config->rotation_matrix[i * 3 + 0],
+ config->rotation_matrix[i * 3 + 1],
+ config->rotation_matrix[i * 3 + 2]);
+
+ acpigen_write_string(matrix_row);
+ }
+
+ acpigen_pop_len();
+ acpigen_pop_len();
+ }
+
/* Callback if any. */
if (callback)
callback(dev);