1
1
// SPDX-License-Identifier: GPL-2.0
2
2
3
3
#include <linux/i2c.h>
4
+ #include <linux/pci.h>
4
5
#include <linux/psp-platform-access.h>
5
6
#include <linux/psp.h>
6
7
#include <linux/workqueue.h>
@@ -32,6 +33,8 @@ static u32 psp_i2c_access_count;
32
33
static bool psp_i2c_mbox_fail ;
33
34
static struct device * psp_i2c_dev ;
34
35
36
+ static int (* _psp_send_i2c_req )(struct psp_i2c_req * req );
37
+
35
38
/* Helper to verify status returned by PSP */
36
39
static int check_i2c_req_sts (struct psp_i2c_req * req )
37
40
{
@@ -72,6 +75,17 @@ static int psp_send_i2c_req_cezanne(struct psp_i2c_req *req)
72
75
return ret ;
73
76
}
74
77
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
+
75
89
static int psp_send_i2c_req (enum psp_i2c_req_type i2c_req_type )
76
90
{
77
91
struct psp_i2c_req * req ;
@@ -87,7 +101,7 @@ static int psp_send_i2c_req(enum psp_i2c_req_type i2c_req_type)
87
101
req -> type = i2c_req_type ;
88
102
89
103
start = jiffies ;
90
- ret = read_poll_timeout (psp_send_i2c_req_cezanne , status ,
104
+ ret = read_poll_timeout (_psp_send_i2c_req , status ,
91
105
(status != - EBUSY ),
92
106
PSP_I2C_REQ_RETRY_DELAY_US ,
93
107
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 = {
262
276
263
277
int i2c_dw_amdpsp_probe_lock_support (struct dw_i2c_dev * dev )
264
278
{
279
+ struct pci_dev * rdev ;
280
+
265
281
if (!IS_REACHABLE (CONFIG_CRYPTO_DEV_CCP_DD ))
266
282
return - ENODEV ;
267
283
@@ -275,6 +291,14 @@ int i2c_dw_amdpsp_probe_lock_support(struct dw_i2c_dev *dev)
275
291
if (psp_i2c_dev )
276
292
return - EEXIST ;
277
293
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
+
278
302
if (psp_check_platform_access_status ())
279
303
return - EPROBE_DEFER ;
280
304
0 commit comments