From patchwork Thu Oct 5 16:06:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dustin Howett X-Patchwork-Id: 13410302 Received: from mail-qv1-f41.google.com (mail-qv1-f41.google.com [209.85.219.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 223E030D17 for ; Thu, 5 Oct 2023 16:07:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=howett.net Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=howett.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=howett-net.20230601.gappssmtp.com header.i=@howett-net.20230601.gappssmtp.com header.b="U+3733Yr" Received: by mail-qv1-f41.google.com with SMTP id 6a1803df08f44-65af1037ca8so6022386d6.2 for ; Thu, 05 Oct 2023 09:07:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=howett-net.20230601.gappssmtp.com; s=20230601; t=1696522071; x=1697126871; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aIKhewsUzhXlGubPiW58tzOjf5y8/qBow8TkSh16ct0=; b=U+3733YrHwhV3S2LQUmguQ4zO3f/wlqBfxAVP17EJFLHnc1XPAwmnSo1LoawUUw/y9 KT5qE76hiloISwNkrITXApoeKxf7FDbWo4NfXbE24S0wGCdoU/lKiosm2P3sQY1kI3mV cNo7rvAp8BBOo/7Q1KKSwQDyCAdzhcUFg/sl0QzNsbH9JJhzMnTbGqcuTHqj7AZi3G8j vRLuovYcy5+JbOv37OVDy4fwrtxh/LiPb7orkmw+Ga6xt/bhlfbgkc1Ta5rHpxw+8c3H NQVNWtHWejRTsdfiEbXvhwJoVlp3RcVonuoF9SnqCdyzDUWCsnWWmi/nDAwA6XBMHJJh 1yEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696522071; x=1697126871; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aIKhewsUzhXlGubPiW58tzOjf5y8/qBow8TkSh16ct0=; b=iUMYDDsV3XBkGv7v1Z4qACa1bF1SaoN4/T0ST4+M6NR03YKhLWA1TgbaDja1TYim37 9o6ag/J/ClOn18cpuUF0Vph5BSZL99TfDkWyz73hweXNzlTfTHIIqHirxnx4dBm7XE+X tXS+1hxZl/zXMA0kx+TolOX13SLvN9etyn5BcMn1c02IIVd0CzGfnSFvuFVXL1fk1Ajz Sr//8DFCcKbLnEf9gVrO7EwMZbGYYLqxA2uImasy/bMQRt91ZJzkFBrkL/5wypamZMod lORbpdgBEcJkETitoDrn+5qfZY2aAZBMwjvMFMhFB6GbFtTrocz5A9EoEgjK2yz3enSV EGDg== X-Gm-Message-State: AOJu0YxtjtYa0Z79TZZhCOKMCB1shhn7cs9mo5ZR52d39CdbMGv/oJVd R2ZFfs1+gUdorZxTYfzG2SAhD4ABe5P6D7oYk6B6cw== X-Google-Smtp-Source: AGHT+IENbbnztfC5zYQ3C6sRr7dhQcz2+L/+nXUmgWY3mQBnPpTTm/XHG1yMc2sAaxngc1mlll/gjA== X-Received: by 2002:a05:6214:3209:b0:63d:2cc7:bef9 with SMTP id qj9-20020a056214320900b0063d2cc7bef9mr5264097qvb.37.1696522070956; Thu, 05 Oct 2023 09:07:50 -0700 (PDT) Received: from tycho.delfino.n.howett.net (99-107-94-179.lightspeed.stlsmo.sbcglobal.net. [99.107.94.179]) by smtp.googlemail.com with ESMTPSA id k3-20020a0cabc3000000b0063d5d173a51sm611422qvb.50.2023.10.05.09.07.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 09:07:50 -0700 (PDT) From: "Dustin L. Howett" To: Benson Leung , Guenter Roeck , chrome-platform@lists.linux.dev, Kieran Levin , Mario Limonciello Cc: "Dustin L. Howett" Subject: [PATCH v1 1/4] cros_ec_lpc: introduce cros_ec_lpc, a priv struct for the lpc device Date: Thu, 5 Oct 2023 11:06:59 -0500 Message-ID: <20231005160701.19987-3-dustin@howett.net> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231005160701.19987-1-dustin@howett.net> References: <20231005160701.19987-1-dustin@howett.net> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 cros_ec_lpc stores the MMIO port base for EC mapped memory. cros_ec_lpc_readmem uses this port base instead of hardcoding EC_LPC_ADDR_MEMMAP. Signed-off-by: Dustin L. Howett --- drivers/platform/chrome/cros_ec_lpc.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/drivers/platform/chrome/cros_ec_lpc.c b/drivers/platform/chrome/cros_ec_lpc.c index 500a61b093e4..477e22e31757 100644 --- a/drivers/platform/chrome/cros_ec_lpc.c +++ b/drivers/platform/chrome/cros_ec_lpc.c @@ -34,6 +34,14 @@ /* True if ACPI device is present */ static bool cros_ec_lpc_acpi_device_found; +/** + * struct cros_ec_lpc - LPC device-specific data + * @mmio_memory_base: The first I/O port addressing EC mapped memory. + */ +struct cros_ec_lpc { + u16 mmio_memory_base; +}; + /** * struct lpc_driver_ops - LPC driver operations * @read: Copy length bytes from EC address offset into buffer dest. Returns @@ -290,6 +298,7 @@ static int cros_ec_cmd_xfer_lpc(struct cros_ec_device *ec, static int cros_ec_lpc_readmem(struct cros_ec_device *ec, unsigned int offset, unsigned int bytes, void *dest) { + struct cros_ec_lpc *ec_lpc = ec->priv; int i = offset; char *s = dest; int cnt = 0; @@ -299,13 +308,13 @@ static int cros_ec_lpc_readmem(struct cros_ec_device *ec, unsigned int offset, /* fixed length */ if (bytes) { - cros_ec_lpc_ops.read(EC_LPC_ADDR_MEMMAP + offset, bytes, s); + cros_ec_lpc_ops.read(ec_lpc->mmio_memory_base + offset, bytes, s); return bytes; } /* string */ for (; i < EC_MEMMAP_SIZE; i++, s++) { - cros_ec_lpc_ops.read(EC_LPC_ADDR_MEMMAP + i, 1, s); + cros_ec_lpc_ops.read(ec_lpc->mmio_memory_base + i, 1, s); cnt++; if (!*s) break; @@ -353,9 +362,16 @@ static int cros_ec_lpc_probe(struct platform_device *pdev) struct acpi_device *adev; acpi_status status; struct cros_ec_device *ec_dev; + struct cros_ec_lpc *ec_lpc; u8 buf[2] = {}; int irq, ret; + ec_lpc = devm_kzalloc(dev, sizeof(*ec_lpc), GFP_KERNEL); + if (!ec_lpc) + return -ENOMEM; + + ec_lpc->mmio_memory_base = EC_LPC_ADDR_MEMMAP; + /* * The Framework Laptop (and possibly other non-ChromeOS devices) * only exposes the eight I/O ports that are required for the Microchip EC. @@ -380,7 +396,7 @@ static int cros_ec_lpc_probe(struct platform_device *pdev) cros_ec_lpc_ops.write = cros_ec_lpc_mec_write_bytes; cros_ec_lpc_ops.read(EC_LPC_ADDR_MEMMAP + EC_MEMMAP_ID, 2, buf); if (buf[0] != 'E' || buf[1] != 'C') { - if (!devm_request_region(dev, EC_LPC_ADDR_MEMMAP, EC_MEMMAP_SIZE, + if (!devm_request_region(dev, ec_lpc->mmio_memory_base, EC_MEMMAP_SIZE, dev_name(dev))) { dev_err(dev, "couldn't reserve memmap region\n"); return -EBUSY; @@ -389,7 +405,7 @@ static int cros_ec_lpc_probe(struct platform_device *pdev) /* Re-assign read/write operations for the non MEC variant */ cros_ec_lpc_ops.read = cros_ec_lpc_read_bytes; cros_ec_lpc_ops.write = cros_ec_lpc_write_bytes; - cros_ec_lpc_ops.read(EC_LPC_ADDR_MEMMAP + EC_MEMMAP_ID, 2, + cros_ec_lpc_ops.read(ec_lpc->mmio_memory_base + EC_MEMMAP_ID, 2, buf); if (buf[0] != 'E' || buf[1] != 'C') { dev_err(dev, "EC ID not detected\n"); @@ -423,6 +439,7 @@ static int cros_ec_lpc_probe(struct platform_device *pdev) ec_dev->din_size = sizeof(struct ec_host_response) + sizeof(struct ec_response_get_protocol_info); ec_dev->dout_size = sizeof(struct ec_host_request); + ec_dev->priv = (void *)ec_lpc; /* * Some boards do not have an IRQ allotted for cros_ec_lpc, From patchwork Thu Oct 5 16:07:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dustin Howett X-Patchwork-Id: 13410303 Received: from mail-qv1-f44.google.com (mail-qv1-f44.google.com [209.85.219.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B3B1D30D17 for ; Thu, 5 Oct 2023 16:07:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=howett.net Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=howett.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=howett-net.20230601.gappssmtp.com header.i=@howett-net.20230601.gappssmtp.com header.b="lCOTfvFQ" Received: by mail-qv1-f44.google.com with SMTP id 6a1803df08f44-65b0dad1f98so6532086d6.0 for ; Thu, 05 Oct 2023 09:07:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=howett-net.20230601.gappssmtp.com; s=20230601; t=1696522074; x=1697126874; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ehTvxGrcWJf2GK4o99VJ+trJtzmEICjcGVrEWrEqVaY=; b=lCOTfvFQOt+tIvI8OEOiDdJQSmhR06z7pgR2WkZ5yTztx6dhanei3UWcLIld++Ozw4 SeEX+Iz+6VVP/OM0MzR6PYX6PZr7gutm7/O/KKyixbMxpLDKX5D4fg82Z+sSvZSsnZNx ErozW+jCRKYIVHjDtfvjOkTUj6QUg+VGg1NDHEi8vkqn8Chmac7XJv2RFliaBUWin+lx KBfmeMscKuPE9BsKAyrHcZNlgr8z+EkZyQdPbw7on5ufDv1vEdGJ+B0NY6bYohpzBq8k 1+M4/ezM1NgD3N+MkV6BfLF++y0bs/F5Ovn+lxHinVESVw/EV/kyGW+3a/VXQ4QqBZU7 DyHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696522074; x=1697126874; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ehTvxGrcWJf2GK4o99VJ+trJtzmEICjcGVrEWrEqVaY=; b=JLcA6ynWlv+LlvlT+T8Cy9IcxvC83Orr6XsEfqMpkjx/Vu5NLxjKgyNQ1usMz/DigR pq//s8yPtaNTTAQVliHx5z1R/CQm2KAn3zAm8cbCuHFrLO/9QLv26iVHQpITAjVXPPKs X46cuPDdJ+E1ZU8Cb2VelCLTxP6PM4M90NRxC7Hze9ThLxuMP1bvx80F4gwEe17IvuNU PKgqBSRh2eNDckKYmDSWb0PwCDKd/n+dY1aZz9dS686gNKB3vhtfhKPOj4tTxEdtUh3i jLkv0QuGcKr/JrX07k10Lmd8hEGxz9H1mxuuMQp4YuwkwBK1UmReLm1+3nwDe7iFPTAS bDzw== X-Gm-Message-State: AOJu0YycbxPinPK1Or75h921ZS0+LForZFYEZ+2VZM+YSu57r1I7BBLt ClqJc9tjDtueh0HyW7yS7yUZZg== X-Google-Smtp-Source: AGHT+IHXnbsMFmV1xKigch6j93fZcdPPVsuNon2yqQpBMQzZpNCBWPEvX9o1ej3+mQyNPx2hLpRCJg== X-Received: by 2002:a0c:b347:0:b0:65b:26d4:7fb6 with SMTP id a7-20020a0cb347000000b0065b26d47fb6mr4877067qvf.4.1696522074498; Thu, 05 Oct 2023 09:07:54 -0700 (PDT) Received: from tycho.delfino.n.howett.net (99-107-94-179.lightspeed.stlsmo.sbcglobal.net. [99.107.94.179]) by smtp.googlemail.com with ESMTPSA id k3-20020a0cabc3000000b0063d5d173a51sm611422qvb.50.2023.10.05.09.07.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 09:07:54 -0700 (PDT) From: "Dustin L. Howett" To: Benson Leung , Guenter Roeck , chrome-platform@lists.linux.dev, Kieran Levin , Mario Limonciello Cc: "Dustin L. Howett" Subject: [PATCH v1 2/4] cros_ec_lpc: pass driver_data from DMI down to the device Date: Thu, 5 Oct 2023 11:07:00 -0500 Message-ID: <20231005160701.19987-4-dustin@howett.net> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231005160701.19987-1-dustin@howett.net> References: <20231005160701.19987-1-dustin@howett.net> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 lpc_driver_data will be stored in drvdata until probe is complete, at which point it will be replaced with an updated copy. Signed-off-by: Dustin L. Howett --- drivers/platform/chrome/cros_ec_lpc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/platform/chrome/cros_ec_lpc.c b/drivers/platform/chrome/cros_ec_lpc.c index 477e22e31757..ef7943e6a01d 100644 --- a/drivers/platform/chrome/cros_ec_lpc.c +++ b/drivers/platform/chrome/cros_ec_lpc.c @@ -615,14 +615,17 @@ static int __init cros_ec_lpc_init(void) { int ret; acpi_status status; + const struct dmi_system_id *dmi_match; status = acpi_get_devices(ACPI_DRV_NAME, cros_ec_lpc_parse_device, &cros_ec_lpc_acpi_device_found, NULL); if (ACPI_FAILURE(status)) pr_warn(DRV_NAME ": Looking for %s failed\n", ACPI_DRV_NAME); + dmi_match = dmi_first_match(cros_ec_lpc_dmi_table); + if (!cros_ec_lpc_acpi_device_found && - !dmi_check_system(cros_ec_lpc_dmi_table)) { + !dmi_match) { pr_err(DRV_NAME ": unsupported system.\n"); return -ENODEV; } @@ -635,6 +638,9 @@ static int __init cros_ec_lpc_init(void) } if (!cros_ec_lpc_acpi_device_found) { + /* Pass the DMI match's driver data down to the platform device */ + platform_set_drvdata(&cros_ec_lpc_device, dmi_match->driver_data); + /* Register the device, and it'll get hooked up automatically */ ret = platform_device_register(&cros_ec_lpc_device); if (ret) { From patchwork Thu Oct 5 16:07:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dustin Howett X-Patchwork-Id: 13410304 Received: from mail-ot1-f45.google.com (mail-ot1-f45.google.com [209.85.210.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 74DE134193 for ; Thu, 5 Oct 2023 16:07:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=howett.net Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=howett.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=howett-net.20230601.gappssmtp.com header.i=@howett-net.20230601.gappssmtp.com header.b="v83MEWeA" Received: by mail-ot1-f45.google.com with SMTP id 46e09a7af769-6c4b9e09521so746949a34.3 for ; Thu, 05 Oct 2023 09:07:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=howett-net.20230601.gappssmtp.com; s=20230601; t=1696522076; x=1697126876; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DB/63q7co6BElMzwEVr8DBbzrAtv1Y7+8+dwDw13/rU=; b=v83MEWeAMwHCG0wStM+CUvM1xRO3zv/Bq29y2NgGHNs6AaxQo7eebD5+oDWiWVBFot 8nPb7nh6SwRfbLc9b9f+VjcnbL4rni4vcmb3h4xd01TAHTYj8yo/41nIIZ6HMBmOKmwd lzVUVOKDXrPwSBS77ihS/5vzEmi1Oabhx2Jjj0ZNxY93bL6HJDjFfh1O3HKKke1aPL+f KXq/zH/MiYWLgNi0ZhLHUJvz3iNW5yz4z9j2POytSyOU056gMiyuAoOCtN8YvdbtP5n5 Qlu/Dd8UiX9sV5y7xmduzBnlzr8S1MhrI/ToUpIPQRnxHLQjFvrtYpF0qBiU2BiohtWR 6jOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696522076; x=1697126876; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DB/63q7co6BElMzwEVr8DBbzrAtv1Y7+8+dwDw13/rU=; b=kN9G3HMbJKJDzTs3TMPudiLbHiPtLWvwNgF095ryG3b6yQyEM/zj/UFaxgWaByMQeS xvm9ZUUNuSqaO4A3i6eQ7Ysq3GCUIFIZnRUSELrvbx++gkXZgOtNSDSPQs0Vx6+bMNho WH4R9WF5nauFm7eBseg6Cp0NN3yMBz9YaBvUMeWa6WKPdUxCLjixsHoqT3/QBnUi3M96 xz3inK6NfA6m8W2JfafyxamBJxWXI1xIMg68Sel1GcnArjeePtw2z+zOM4rsD2N+mEQx Qdxcn3cZsJz8rDTat3DOlZVM+5B1l1GvSjecwiVqClf5JzAKxBGl6loTWGq/pjp5vUdA FH8g== X-Gm-Message-State: AOJu0Yxod0Tu4k6XgEMgJnhuJFYOCWI+TSs+Daz/TWenlLo70NQDsz3N ot0O7RaAX7rMgUhlT0MBr3kzWw== X-Google-Smtp-Source: AGHT+IF7BGzIpAcXRZ9L1lRMxSA0PcKYIKfM0MAZ2Fsnukx6tQuLwfpqxRdStuyFiP9QPC3HZRFT3A== X-Received: by 2002:a9d:62d6:0:b0:6c4:c151:8ebe with SMTP id z22-20020a9d62d6000000b006c4c1518ebemr5819494otk.22.1696522076403; Thu, 05 Oct 2023 09:07:56 -0700 (PDT) Received: from tycho.delfino.n.howett.net (99-107-94-179.lightspeed.stlsmo.sbcglobal.net. [99.107.94.179]) by smtp.googlemail.com with ESMTPSA id k3-20020a0cabc3000000b0063d5d173a51sm611422qvb.50.2023.10.05.09.07.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 09:07:55 -0700 (PDT) From: "Dustin L. Howett" To: Benson Leung , Guenter Roeck , chrome-platform@lists.linux.dev, Kieran Levin , Mario Limonciello Cc: "Dustin L. Howett" Subject: [PATCH v1 3/4] cros_ec_lpc: add a quirks system, and propagate quirks from DMI Date: Thu, 5 Oct 2023 11:07:01 -0500 Message-ID: <20231005160701.19987-5-dustin@howett.net> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231005160701.19987-1-dustin@howett.net> References: <20231005160701.19987-1-dustin@howett.net> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Some devices ship a ChromeOS EC in a non-standard configuration; quirks allow cros_ec_lpc to account for these non-standard configurations. It supports the following quirks: - CROS_EC_LPC_QUIRK_REMAP_MEMORY: use a different port I/O base for MMIO to the EC's memory region - CROS_EC_LPC_QUIRK_SHORT_HOSTCMD_RESERVATION: only attempt to reserve 0xff (rather than 0x100) I/O ports for the host command region Signed-off-by: Dustin L. Howett --- drivers/platform/chrome/cros_ec_lpc.c | 41 ++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/drivers/platform/chrome/cros_ec_lpc.c b/drivers/platform/chrome/cros_ec_lpc.c index ef7943e6a01d..c06575625d2f 100644 --- a/drivers/platform/chrome/cros_ec_lpc.c +++ b/drivers/platform/chrome/cros_ec_lpc.c @@ -34,6 +34,27 @@ /* True if ACPI device is present */ static bool cros_ec_lpc_acpi_device_found; +/* If this quirk is enabled, the driver will only reserve 0xFF I/O ports + * (rather than 0x100) for the host command mapped memory region. + */ +#define CROS_EC_LPC_QUIRK_SHORT_HOSTCMD_RESERVATION BIT(0) +/* If this quirk is enabled, lpc_driver_data.quirk_mmio_memory_base will be used + * as the base port for EC mapped memory. + */ +#define CROS_EC_LPC_QUIRK_REMAP_MEMORY BIT(1) + +/** + * struct lpc_driver_data - driver data attached to a DMI device ID to indicate + * hardware quirks. + * @quirks: a bitfield composed of quirks from CROS_EC_LPC_QUIRK_* + * @quirk_mmio_memory_base: The first I/O port addressing EC mapped memory (used + * when quirks (...REMAP_MEMORY) is set. + */ +struct lpc_driver_data { + u32 quirks; + u16 quirk_mmio_memory_base; +}; + /** * struct cros_ec_lpc - LPC device-specific data * @mmio_memory_base: The first I/O port addressing EC mapped memory. @@ -363,14 +384,32 @@ static int cros_ec_lpc_probe(struct platform_device *pdev) acpi_status status; struct cros_ec_device *ec_dev; struct cros_ec_lpc *ec_lpc; + struct lpc_driver_data *driver_data; + int region1_size; u8 buf[2] = {}; int irq, ret; + u32 quirks = 0; ec_lpc = devm_kzalloc(dev, sizeof(*ec_lpc), GFP_KERNEL); if (!ec_lpc) return -ENOMEM; ec_lpc->mmio_memory_base = EC_LPC_ADDR_MEMMAP; + region1_size = EC_HOST_CMD_REGION_SIZE; + + driver_data = platform_get_drvdata(pdev); + if (driver_data) { + quirks = driver_data->quirks; + + if (quirks) + dev_warn(dev, "loaded with quirks %8.08x\n", quirks); + + if (quirks & CROS_EC_LPC_QUIRK_REMAP_MEMORY) + ec_lpc->mmio_memory_base = driver_data->quirk_mmio_memory_base; + + if (quirks & CROS_EC_LPC_QUIRK_SHORT_HOSTCMD_RESERVATION) + region1_size -= 1; + } /* * The Framework Laptop (and possibly other non-ChromeOS devices) @@ -420,7 +459,7 @@ static int cros_ec_lpc_probe(struct platform_device *pdev) return -EBUSY; } if (!devm_request_region(dev, EC_HOST_CMD_REGION1, - EC_HOST_CMD_REGION_SIZE, dev_name(dev))) { + region1_size, dev_name(dev))) { dev_err(dev, "couldn't reserve region1\n"); return -EBUSY; } From patchwork Thu Oct 5 16:07:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dustin Howett X-Patchwork-Id: 13410305 Received: from mail-oi1-f174.google.com (mail-oi1-f174.google.com [209.85.167.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D570A341A0 for ; Thu, 5 Oct 2023 16:07:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=howett.net Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=howett.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=howett-net.20230601.gappssmtp.com header.i=@howett-net.20230601.gappssmtp.com header.b="BeWT67ks" Received: by mail-oi1-f174.google.com with SMTP id 5614622812f47-3af609c4dfeso750999b6e.1 for ; Thu, 05 Oct 2023 09:07:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=howett-net.20230601.gappssmtp.com; s=20230601; t=1696522078; x=1697126878; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fKbLM1rnC24y2SybHOTvD4S16XjSJ/8+LSwsuGXtOa4=; b=BeWT67ksS5pLD+ji40GmP1kj7AQNxaII6/u6AgPheJbZhHGL8AHAOAz8kcAbfRAXP2 +rgVL06QJf5T/FcEZ+kc+N3oKls6Hn4zxP2WAghZrxJLZkP/ho19YZKGmfyKkRS/fUmT EqJD1P8bXsi4D1kcSQcXwR+AB1o8u/iqWZna/0SvCvu3/4b72WHCqbZahymWZzkmuYF5 kS2gI5ZpVBPLZaJEU9mg1O69DLYB1KwVk6XmMQ3CMneUU+e94f4TfoY5dcKDcLDPxOvb iZO9nVdsEYuLwnXupo8KMzQLbbR3+W+oPRpXeFroRtm/zcEBxcCtsap9/A2nZeQi4fgM cNgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696522078; x=1697126878; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fKbLM1rnC24y2SybHOTvD4S16XjSJ/8+LSwsuGXtOa4=; b=AgHZIpr+6owP0SseRZlQKXFK2bx+4XGP9/K/Q8JqbHjDHh023P/pd5KzlVHZlAR6IA TnhmF6iamNM6WEc3cBOliKJFanx0zEu4bjkpKslBOq8GoOUWzvpGCr/aNwqFrXWPFyAx YEgKsxYLG65Lp4JsjCeDeFNS2DgzxCYD0s3BP2jjRmxFaIqs5YQ2nnbTUb3pFyB88QHF WyBEa2+/NWjsAfRbmXXBZcK6ajRS7saulOdt78d4gO1bZCtJcKblQU8fbW0LqFWUHxDJ HnTS8sgyV5fL9FQfgWNlYDtgB+A4oQnyYov5SMM7jskkMw/WKAyUrDJToPD5pTDyUWxO cu6A== X-Gm-Message-State: AOJu0Yw/nn1MbpKLCPEFO4kp5xqbWcr1rBOXBwAt9A/1o1PCj7xReoG/ 4KDkfI+xBlhaAY8LSV/oHelolg== X-Google-Smtp-Source: AGHT+IEeLkzw0C8OpIY4CAQLonFaWJ2iYDTxeVtdkqB8NZHvSHTijtq3YcbUsYv1TaXqQtEYiS6+MQ== X-Received: by 2002:a05:6808:d52:b0:3a8:74bf:8977 with SMTP id w18-20020a0568080d5200b003a874bf8977mr6821402oik.56.1696522077896; Thu, 05 Oct 2023 09:07:57 -0700 (PDT) Received: from tycho.delfino.n.howett.net (99-107-94-179.lightspeed.stlsmo.sbcglobal.net. [99.107.94.179]) by smtp.googlemail.com with ESMTPSA id k3-20020a0cabc3000000b0063d5d173a51sm611422qvb.50.2023.10.05.09.07.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 09:07:57 -0700 (PDT) From: "Dustin L. Howett" To: Benson Leung , Guenter Roeck , chrome-platform@lists.linux.dev, Kieran Levin , Mario Limonciello Cc: "Dustin L. Howett" Subject: [PATCH v1 4/4] cros_ec_lpc: add quirks for the Framework Laptop Date: Thu, 5 Oct 2023 11:07:02 -0500 Message-ID: <20231005160701.19987-6-dustin@howett.net> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231005160701.19987-1-dustin@howett.net> References: <20231005160701.19987-1-dustin@howett.net> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The original Framework Laptop contains a Microchip EC, but the newer ones have switched to an NPCX EC which uses the standard linear MMIO protocol for host commands and EC memory. However, those newer Framework Laptops diverge from the standard ChromeOS EC in two important ways: 1. The ACPI table for PNP0C09 only claims I/O ports 0x800 to 0x8FE instead of the traditional 0x8FF 2. The MMIO region for EC memory begins at port 0xE00 rather than the traditional 0x900. cros_ec_lpc's quirks system addresses both of these issues. Signed-off-by: Dustin L. Howett --- drivers/platform/chrome/cros_ec_lpc.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/platform/chrome/cros_ec_lpc.c b/drivers/platform/chrome/cros_ec_lpc.c index c06575625d2f..66285c66ff22 100644 --- a/drivers/platform/chrome/cros_ec_lpc.c +++ b/drivers/platform/chrome/cros_ec_lpc.c @@ -537,6 +537,13 @@ static const struct acpi_device_id cros_ec_lpc_acpi_device_ids[] = { }; MODULE_DEVICE_TABLE(acpi, cros_ec_lpc_acpi_device_ids); +static const struct lpc_driver_data framework_laptop_lpc_driver_data __initconst = { + .quirks = + CROS_EC_LPC_QUIRK_REMAP_MEMORY | + CROS_EC_LPC_QUIRK_SHORT_HOSTCMD_RESERVATION, + .quirk_mmio_memory_base = 0xE00, +}; + static const struct dmi_system_id cros_ec_lpc_dmi_table[] __initconst = { { /* @@ -596,6 +603,7 @@ static const struct dmi_system_id cros_ec_lpc_dmi_table[] __initconst = { DMI_MATCH(DMI_SYS_VENDOR, "Framework"), DMI_MATCH(DMI_PRODUCT_NAME, "Laptop"), }, + .driver_data = (void *)&framework_laptop_lpc_driver_data, }, { /* sentinel */ } };