From patchwork Mon Mar 4 22:17:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 13581317 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8D58679F2; Mon, 4 Mar 2024 22:17:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.15.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709590665; cv=none; b=MwweOR4cRZUj09xChYd65GC8V8sXN/e47Acgc4WvROioYize9NEzdu10v9wt04xwDEQthm4//EKALsz9IVrtFQXdOFcWdIk7v+m7Yfv+iSWZ9lwtP5C3g+zfBKmE/at5F6QvwfiSy9+NKFx8IZLDj9sc8cxUOIB8DYNZaVKPbL8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709590665; c=relaxed/simple; bh=VlKZ9o+29/hqwaDeqpj4LAI4vgvn2/j6rxxZkLe2GW8=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=oE4CVVCNfkl1cZ8LZuhgdHcJYA6+H6i4DovmBBvpqNh4SvaEeIKH8XWg+5bKrCnHaE1ftoUYq/rhhY1yzi2ywU8g2LV3e9xH7pKlt2Bq+IIN9rprcRsJiusxvnHyA5cPGXTKuVen1xgpNq0avwKVcpiEMa901T4SCAmH4ZxKbFI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de; spf=pass smtp.mailfrom=gmx.de; dkim=pass (2048-bit key) header.d=gmx.de header.i=w_armin@gmx.de header.b=Sf8XJOJh; arc=none smtp.client-ip=212.227.15.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmx.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmx.de header.i=w_armin@gmx.de header.b="Sf8XJOJh" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1709590655; x=1710195455; i=w_armin@gmx.de; bh=VlKZ9o+29/hqwaDeqpj4LAI4vgvn2/j6rxxZkLe2GW8=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date; b=Sf8XJOJhNAbkpyCTeruVMgLTUarPwlB7X3g0xz7YC4I2kk2qodNOu1MSmEVUQ8Wa +ZGLg3QjgGLW4JLSUqgXcSx8ON55CC5ugw+k6HCnPEzjYNqZ7ueeDhFlxP+nFSN2R w3J3fxA7wHY66LodeFOe9czQZxSnNqNvLVlrgPAkM2PUiy7YKRXGn3ZDuJvbi/nyJ oI2nJFWLsDn/7z0LZjO42JsNsKXxjDgww/nWs6CeO/FTOAHOIXyigYt4OOVPx1fGB BntZOfFero7qrXk6cOWsHo2yX2t8TCpJ/1zASgPUjgoaCIVLn2cD422taScfljCSR 18/6HMvRGIk8Tf1OmA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from mx-amd-b650.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MulqD-1qqGfE2T1X-00rmzD; Mon, 04 Mar 2024 23:17:35 +0100 From: Armin Wolf To: hdegoede@redhat.com, ilpo.jarvinen@linux.intel.com Cc: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] platform/x86: wmi: Support reading/writing 16 bit EC values Date: Mon, 4 Mar 2024 23:17:31 +0100 Message-Id: <20240304221732.39272-1-W_Armin@gmx.de> X-Mailer: git-send-email 2.39.2 Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME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bntNefeRM56G5N9couJxcb0J2rIrYsuIZB2lUsCopdjQw+L dKucIy6Rf50vDOFKycz5d3q92uolBZsKHF78SmrcGdVkk= The ACPI EC address space handler currently only supports reading/writing 8 bit values. Some firmware implementations however want to access for example 16 bit values, which is prefectly legal according to the ACPI spec. Add support for reading/writing such values. Tested on a Dell Inspiron 3505 and a Asus Prime B650-Plus. Signed-off-by: Armin Wolf Reviewed-by: Hans de Goede --- drivers/platform/x86/wmi.c | 44 +++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 10 deletions(-) -- 2.39.2 diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c index 1920e115da89..900e0e52a5fa 100644 --- a/drivers/platform/x86/wmi.c +++ b/drivers/platform/x86/wmi.c @@ -1153,6 +1153,32 @@ static int parse_wdg(struct device *wmi_bus_dev, struct platform_device *pdev) return 0; } +static int ec_read_multiple(u8 address, u8 *buffer, size_t bytes) +{ + int i, ret; + + for (i = 0; i < bytes; i++) { + ret = ec_read(address + i, &buffer[i]); + if (ret < 0) + return ret; + } + + return 0; +} + +static int ec_write_multiple(u8 address, u8 *buffer, size_t bytes) +{ + int i, ret; + + for (i = 0; i < bytes; i++) { + ret = ec_write(address + i, buffer[i]); + if (ret < 0) + return ret; + } + + return 0; +} + /* * WMI can have EmbeddedControl access regions. In which case, we just want to * hand these off to the EC driver. @@ -1162,27 +1188,25 @@ acpi_wmi_ec_space_handler(u32 function, acpi_physical_address address, u32 bits, u64 *value, void *handler_context, void *region_context) { - int result = 0; - u8 temp = 0; + int bytes = bits / 8; + int ret; - if ((address > 0xFF) || !value) + if (address > 0xFF || !value) return AE_BAD_PARAMETER; - if (function != ACPI_READ && function != ACPI_WRITE) + if (bytes > sizeof(*value)) return AE_BAD_PARAMETER; - if (bits != 8) + if (function != ACPI_READ && function != ACPI_WRITE) return AE_BAD_PARAMETER; if (function == ACPI_READ) { - result = ec_read(address, &temp); - *value = temp; + ret = ec_read_multiple(address, (u8 *)value, bytes); } else { - temp = 0xff & *value; - result = ec_write(address, temp); + ret = ec_write_multiple(address, (u8 *)value, bytes); } - switch (result) { + switch (ret) { case -EINVAL: return AE_BAD_PARAMETER; case -ENODEV: