Skip to content

Commit 482c84e

Browse files
superm1herbertx
authored andcommitted
i2c: designware: Add doorbell support for Mendocino
Mendocino and later platform don't use the platform feature mailbox for communication for I2C arbitration, they rely upon ringing a doorbell. Detect the platform by the device ID of the root port and choose the appropriate method. Link: https://lore.kernel.org/linux-i2c/20220916131854.687371-3-jsd@semihalf.com/ Signed-off-by: Mario Limonciello <mario.limonciello@amd.com> Acked-by: Jarkko Nikula <jarkko.nikula@linux.intel.com> Reviewed-by: Mark Hasemeyer <markhas@chromium.org> Tested-by: Mark Hasemeyer <markhas@chromium.org> Acked-by: Wolfram Sang <wsa@kernel.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 440da73 commit 482c84e

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

drivers/i2c/busses/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ config I2C_DESIGNWARE_AMDPSP
568568
bool "AMD PSP I2C semaphore support"
569569
depends on ACPI
570570
depends on CRYPTO_DEV_SP_PSP
571+
depends on PCI
571572
depends on I2C_DESIGNWARE_PLATFORM
572573
depends on (I2C_DESIGNWARE_PLATFORM=y && CRYPTO_DEV_CCP_DD=y) || \
573574
(I2C_DESIGNWARE_PLATFORM=m && CRYPTO_DEV_CCP_DD)

drivers/i2c/busses/i2c-designware-amdpsp.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: GPL-2.0
22

33
#include <linux/i2c.h>
4+
#include <linux/pci.h>
45
#include <linux/psp-platform-access.h>
56
#include <linux/psp.h>
67
#include <linux/workqueue.h>
@@ -32,6 +33,8 @@ static u32 psp_i2c_access_count;
3233
static bool psp_i2c_mbox_fail;
3334
static struct device *psp_i2c_dev;
3435

36+
static int (*_psp_send_i2c_req)(struct psp_i2c_req *req);
37+
3538
/* Helper to verify status returned by PSP */
3639
static int check_i2c_req_sts(struct psp_i2c_req *req)
3740
{
@@ -72,6 +75,17 @@ static int psp_send_i2c_req_cezanne(struct psp_i2c_req *req)
7275
return ret;
7376
}
7477

78+
static int psp_send_i2c_req_doorbell(struct psp_i2c_req *req)
79+
{
80+
int ret;
81+
82+
ret = psp_ring_platform_doorbell(req->type, &req->hdr.status);
83+
if (ret == -EIO)
84+
return check_i2c_req_sts(req);
85+
86+
return ret;
87+
}
88+
7589
static int psp_send_i2c_req(enum psp_i2c_req_type i2c_req_type)
7690
{
7791
struct psp_i2c_req *req;
@@ -87,7 +101,7 @@ static int psp_send_i2c_req(enum psp_i2c_req_type i2c_req_type)
87101
req->type = i2c_req_type;
88102

89103
start = jiffies;
90-
ret = read_poll_timeout(psp_send_i2c_req_cezanne, status,
104+
ret = read_poll_timeout(_psp_send_i2c_req, status,
91105
(status != -EBUSY),
92106
PSP_I2C_REQ_RETRY_DELAY_US,
93107
PSP_I2C_REQ_RETRY_CNT * PSP_I2C_REQ_RETRY_DELAY_US,
@@ -262,6 +276,8 @@ static const struct i2c_lock_operations i2c_dw_psp_lock_ops = {
262276

263277
int i2c_dw_amdpsp_probe_lock_support(struct dw_i2c_dev *dev)
264278
{
279+
struct pci_dev *rdev;
280+
265281
if (!IS_REACHABLE(CONFIG_CRYPTO_DEV_CCP_DD))
266282
return -ENODEV;
267283

@@ -275,6 +291,14 @@ int i2c_dw_amdpsp_probe_lock_support(struct dw_i2c_dev *dev)
275291
if (psp_i2c_dev)
276292
return -EEXIST;
277293

294+
/* Cezanne uses platform mailbox, Mendocino and later use doorbell */
295+
rdev = pci_get_domain_bus_and_slot(0, 0, PCI_DEVFN(0, 0));
296+
if (rdev->device == 0x1630)
297+
_psp_send_i2c_req = psp_send_i2c_req_cezanne;
298+
else
299+
_psp_send_i2c_req = psp_send_i2c_req_doorbell;
300+
pci_dev_put(rdev);
301+
278302
if (psp_check_platform_access_status())
279303
return -EPROBE_DEFER;
280304

0 commit comments

Comments
 (0)