diff mbox series

[v2,4/5] platform/chrome: cros_ec_lpc: Add a new quirk for AML mutex

Message ID 20240603063834.5580-5-ben@jubnut.com (mailing list archive)
State Superseded
Headers show
Series platform/chrome: Fix MEC concurrency problems for Framework Laptop | expand

Commit Message

Ben Walsh June 3, 2024, 6:38 a.m. UTC
Add a new quirk "CROS_EC_LPC_QUIRK_AML_MUTEX" which provides the name
of an AML mutex to protect MEC memory access.

Signed-off-by: Ben Walsh <ben@jubnut.com>
---
 drivers/platform/chrome/cros_ec_lpc.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

Comments

Tzung-Bi Shih June 3, 2024, 9:31 a.m. UTC | #1
On Mon, Jun 03, 2024 at 07:38:33AM +0100, Ben Walsh wrote:
> @@ -484,6 +492,18 @@ static int cros_ec_lpc_probe(struct platform_device *pdev)
>  			}
>  			ACPI_COMPANION_SET(dev, adev);
>  		}
> +
> +		if (quirks & CROS_EC_LPC_QUIRK_AML_MUTEX) {
> +			const char *name
> +				= driver_data->quirk_aml_mutex_name;
> +			ret = cros_ec_lpc_mec_acpi_mutex(adev, name);

* Assuming the `adev = ACPI_COMPANION(dev);` didn't move in previous patch,
  `adev` here could be uninitialized.

* Also, it shouldn't rely on CROS_EC_LPC_QUIRK_ACPI_ID to set the `adev`.

To keep it simple, I would suggest to use ACPI_COMPANION() instead.
diff mbox series

Patch

diff --git a/drivers/platform/chrome/cros_ec_lpc.c b/drivers/platform/chrome/cros_ec_lpc.c
index c1c26a7ba6d4..60627c5a596b 100644
--- a/drivers/platform/chrome/cros_ec_lpc.c
+++ b/drivers/platform/chrome/cros_ec_lpc.c
@@ -44,6 +44,11 @@  static bool cros_ec_lpc_acpi_device_found;
  * the ACPI device.
  */
 #define CROS_EC_LPC_QUIRK_ACPI_ID                   BIT(1)
+/*
+ * Indicates that lpc_driver_data.quirk_aml_mutex_name should be used
+ * to find an AML mutex to protect access to Microchip EC.
+ */
+#define CROS_EC_LPC_QUIRK_AML_MUTEX                 BIT(2)
 
 /**
  * struct lpc_driver_data - driver data attached to a DMI device ID to indicate
@@ -52,11 +57,14 @@  static bool cros_ec_lpc_acpi_device_found;
  * @quirk_mmio_memory_base: The first I/O port addressing EC mapped memory (used
  *                          when quirk ...REMAP_MEMORY is set.)
  * @quirk_acpi_id: An ACPI HID to be used to find the ACPI device.
+ * @quirk_aml_mutex_name: The name of an AML mutex to be used to protect access
+ *                        to Microchip EC.
  */
 struct lpc_driver_data {
 	u32 quirks;
 	u16 quirk_mmio_memory_base;
 	const char *quirk_acpi_id;
+	const char *quirk_aml_mutex_name;
 };
 
 /**
@@ -484,6 +492,18 @@  static int cros_ec_lpc_probe(struct platform_device *pdev)
 			}
 			ACPI_COMPANION_SET(dev, adev);
 		}
+
+		if (quirks & CROS_EC_LPC_QUIRK_AML_MUTEX) {
+			const char *name
+				= driver_data->quirk_aml_mutex_name;
+			ret = cros_ec_lpc_mec_acpi_mutex(adev, name);
+			if (ret) {
+				dev_err(dev, "failed to get AML mutex '%s'", name);
+				return ret;
+			}
+
+			dev_info(dev, "got AML mutex '%s'", name);
+		}
 	}
 
 	/*