Linux I2C development
 help / color / mirror / Atom feed
From: Mario Limonciello <mario.limonciello@amd.com>
To: "Jan Dąbroś" <jsd@semihalf.com>,
	"Grzegorz Bernacki" <gjb@semihalf.com>,
	Rijo-john.Thomas@amd.com, Thomas.Lendacky@amd.com,
	herbert@gondor.apana.org.au,
	"Jarkko Nikula" <jarkko.nikula@linux.intel.com>,
	"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
	"Mika Westerberg" <mika.westerberg@linux.intel.com>
Cc: Mario Limonciello <mario.limonciello@amd.com>,
	<linux-i2c@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: [PATCH v2 8/9] i2c: designware: Add doorbell support for Skyrim
Date: Thu, 2 Mar 2023 13:42:31 -0600	[thread overview]
Message-ID: <20230302194235.1724-9-mario.limonciello@amd.com> (raw)
In-Reply-To: <20230302194235.1724-1-mario.limonciello@amd.com>

Skyrim doesn't use the platform feature mailbox for communication
for I2C arbitration, it relies upon ringing a doorbell.

Add a new ACPI ID to use for Skyrim and when that ID is detected
use the doorbell instead.

Link: https://lore.kernel.org/linux-i2c/20220916131854.687371-3-jsd@semihalf.com/
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
v1->v2:
 * New patch
Note: This ACPI ID hasn't currently been reserved, but as Skyrim runs coreboot
it should be easy enough to modify the BIOS and test it out.
If this approach works and has general agreement it can be reserved.
---
 drivers/i2c/busses/i2c-designware-amdpsp.c  | 29 ++++++++++++++-------
 drivers/i2c/busses/i2c-designware-platdrv.c |  1 +
 2 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/drivers/i2c/busses/i2c-designware-amdpsp.c b/drivers/i2c/busses/i2c-designware-amdpsp.c
index 105584abcf8f..e1a4d3002c80 100644
--- a/drivers/i2c/busses/i2c-designware-amdpsp.c
+++ b/drivers/i2c/busses/i2c-designware-amdpsp.c
@@ -73,34 +73,44 @@ static int psp_send_check_i2c_req(struct psp_i2c_req *req)
 	return check_i2c_req_sts(req);
 }
 
-static int psp_send_i2c_req(enum psp_i2c_req_type i2c_req_type)
+static int psp_send_i2c_req_amdi0019(enum psp_i2c_req_type i2c_req_type)
 {
 	struct psp_i2c_req *req;
-	unsigned long start;
 	int status, ret;
 
 	/* Allocate command-response buffer */
 	req = kzalloc(sizeof(*req), GFP_KERNEL);
 	if (!req)
 		return -ENOMEM;
-
 	req->hdr.payload_size = sizeof(*req);
 	req->type = i2c_req_type;
-
-	start = jiffies;
 	ret = read_poll_timeout(psp_send_check_i2c_req, status,
 				(status != -EBUSY),
 				PSP_I2C_REQ_RETRY_DELAY_US,
 				PSP_I2C_REQ_RETRY_CNT * PSP_I2C_REQ_RETRY_DELAY_US,
 				0, req);
-	if (ret) {
+	kfree(req);
+
+	if (ret)
 		dev_err(psp_i2c_dev, "Timed out waiting for PSP to %s I2C bus\n",
 			(i2c_req_type == PSP_I2C_REQ_ACQUIRE) ?
 			"release" : "acquire");
-		goto cleanup;
-	}
 
-	ret = status;
+	return ret ? ret : status;
+}
+
+static int psp_send_i2c_req(enum psp_i2c_req_type i2c_req_type)
+{
+	const char *hid = acpi_device_hid(ACPI_COMPANION(psp_i2c_dev));
+	unsigned long start = jiffies;
+	int ret;
+
+	/* Use doorbell for Skyrim and mailbox for Cezanne */
+	if (!strcmp(hid, "AMDI0020"))
+		ret = psp_ring_platform_doorbell(i2c_req_type);
+	else
+		ret = psp_send_i2c_req_amdi0019(i2c_req_type);
+
 	if (ret) {
 		dev_err(psp_i2c_dev, "PSP communication error\n");
 		goto cleanup;
@@ -115,7 +125,6 @@ static int psp_send_i2c_req(enum psp_i2c_req_type i2c_req_type)
 		psp_i2c_mbox_fail = true;
 	}
 
-	kfree(req);
 	return ret;
 }
 
diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c
index 89ad88c54754..5ca71bda9ac2 100644
--- a/drivers/i2c/busses/i2c-designware-platdrv.c
+++ b/drivers/i2c/busses/i2c-designware-platdrv.c
@@ -51,6 +51,7 @@ static const struct acpi_device_id dw_i2c_acpi_match[] = {
 	{ "AMD0010", ACCESS_INTR_MASK },
 	{ "AMDI0010", ACCESS_INTR_MASK },
 	{ "AMDI0019", ACCESS_INTR_MASK | ARBITRATION_SEMAPHORE },
+	{ "AMDI0020", ACCESS_INTR_MASK | ARBITRATION_SEMAPHORE },
 	{ "AMDI0510", 0 },
 	{ "APMC0D0F", 0 },
 	{ "HISI02A1", 0 },
-- 
2.34.1


  parent reply	other threads:[~2023-03-02 19:44 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-02 19:42 [PATCH v2 0/9] Export platform features from ccp driver Mario Limonciello
2023-03-02 19:42 ` [PATCH v2 2/9] crypto: ccp: Add a header for multiple drivers to use `__psp_pa` Mario Limonciello
2023-03-02 19:42 ` [PATCH v2 3/9] crypto: ccp: Move some PSP mailbox bit definitions into common header Mario Limonciello
2023-03-03 10:36   ` Rijo Thomas
2023-03-02 19:42 ` [PATCH v2 6/9] i2c: designware: Use PCI PSP driver for communication Mario Limonciello
2023-03-02 19:42 ` Mario Limonciello [this message]
2023-03-03 12:00   ` [PATCH v2 8/9] i2c: designware: Add doorbell support for Skyrim Grzegorz Bernacki
2023-03-03 15:00     ` Limonciello, Mario
2023-03-06 11:37       ` Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230302194235.1724-9-mario.limonciello@amd.com \
    --to=mario.limonciello@amd.com \
    --cc=Rijo-john.Thomas@amd.com \
    --cc=Thomas.Lendacky@amd.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=gjb@semihalf.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=jarkko.nikula@linux.intel.com \
    --cc=jsd@semihalf.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mika.westerberg@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox