Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

i2c: designware: Add AMD PSP I2C bus support

Implement an I2C controller sharing mechanism between the host (kernel)
and PSP co-processor on some platforms equipped with AMD Cezanne SoC.

On these platforms we need to implement "software" i2c arbitration.
Default arbitration owner is PSP and kernel asks for acquire as well
as inform about release of the i2c bus via mailbox mechanism.

+---------+
<- ACQUIRE | |
+---------| CPU |\
| | | \ +----------+ SDA
| +---------+ \ | |-------
MAILBOX +--> | I2C-DW | SCL
| +---------+ | |-------
| | | +----------+
+---------| PSP |
<- ACK | |
+---------+

+---------+
<- RELEASE | |
+---------| CPU |
| | | +----------+ SDA
| +---------+ | |-------
MAILBOX +--> | I2C-DW | SCL
| +---------+ / | |-------
| | | / +----------+
+---------| PSP |/
<- ACK | |
+---------+

The solution is similar to i2c-designware-baytrail.c implementation, where
we are using a generic i2c-designware-* driver with a small "wrapper".

In contrary to baytrail semaphore implementation, beside internal
acquire_lock() and release_lock() methods we are also applying quirks to
lock_bus() and unlock_bus() global adapter methods. With this in place
all i2c clients drivers may lock i2c bus for a desired number of i2c
transactions (e.g. write-wait-read) without being aware of that such bus
is shared with another entity.

Modify i2c_dw_probe_lock_support() to select correct semaphore
implementation at runtime, since now we have more than one available.

Configure new matching ACPI ID "AMDI0019" and register
ARBITRATION_SEMAPHORE flag in order to distinguish setup with PSP
arbitration.

Add myself as a reviewer for I2C DesignWare in order to help with reviewing
and testing possible changes touching new i2c-designware-amdpsp.c module.

Signed-off-by: Jan Dabros <jsd@semihalf.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Tested-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
[wsa: removed unneeded blank line and curly braces]
Signed-off-by: Wolfram Sang <wsa@kernel.org>

authored by

Jan Dabros and committed by
Wolfram Sang
78d5e9e2 6960331d

+490 -12
+1
MAINTAINERS
··· 18660 18660 M: Jarkko Nikula <jarkko.nikula@linux.intel.com> 18661 18661 R: Andy Shevchenko <andriy.shevchenko@linux.intel.com> 18662 18662 R: Mika Westerberg <mika.westerberg@linux.intel.com> 18663 + R: Jan Dabros <jsd@semihalf.com> 18663 18664 L: linux-i2c@vger.kernel.org 18664 18665 S: Maintained 18665 18666 F: drivers/i2c/busses/i2c-designware-*
+4 -3
drivers/acpi/acpi_apd.c
··· 232 232 /* Generic apd devices */ 233 233 #ifdef CONFIG_X86_AMD_PLATFORM_DEVICE 234 234 { "AMD0010", APD_ADDR(cz_i2c_desc) }, 235 - { "AMDI0010", APD_ADDR(wt_i2c_desc) }, 236 235 { "AMD0020", APD_ADDR(cz_uart_desc) }, 237 - { "AMDI0020", APD_ADDR(cz_uart_desc) }, 238 - { "AMDI0022", APD_ADDR(cz_uart_desc) }, 239 236 { "AMD0030", }, 240 237 { "AMD0040", APD_ADDR(fch_misc_desc)}, 238 + { "AMDI0010", APD_ADDR(wt_i2c_desc) }, 239 + { "AMDI0019", APD_ADDR(wt_i2c_desc) }, 240 + { "AMDI0020", APD_ADDR(cz_uart_desc) }, 241 + { "AMDI0022", APD_ADDR(cz_uart_desc) }, 241 242 { "HYGO0010", APD_ADDR(wt_i2c_desc) }, 242 243 #endif 243 244 #ifdef CONFIG_ARM64
+11
drivers/i2c/busses/Kconfig
··· 553 553 This driver can also be built as a module. If so, the module 554 554 will be called i2c-designware-platform. 555 555 556 + config I2C_DESIGNWARE_AMDPSP 557 + bool "AMD PSP I2C semaphore support" 558 + depends on X86_MSR 559 + depends on ACPI 560 + depends on I2C_DESIGNWARE_PLATFORM 561 + help 562 + This driver enables managed host access to the selected I2C bus shared 563 + between AMD CPU and AMD PSP. 564 + 565 + You should say Y if running on an AMD system equipped with the PSP. 566 + 556 567 config I2C_DESIGNWARE_BAYTRAIL 557 568 bool "Intel Baytrail I2C semaphore support" 558 569 depends on ACPI
+1
drivers/i2c/busses/Makefile
··· 54 54 i2c-designware-core-$(CONFIG_I2C_DESIGNWARE_SLAVE) += i2c-designware-slave.o 55 55 obj-$(CONFIG_I2C_DESIGNWARE_PLATFORM) += i2c-designware-platform.o 56 56 i2c-designware-platform-y := i2c-designware-platdrv.o 57 + i2c-designware-platform-$(CONFIG_I2C_DESIGNWARE_AMDPSP) += i2c-designware-amdpsp.o 57 58 i2c-designware-platform-$(CONFIG_I2C_DESIGNWARE_BAYTRAIL) += i2c-designware-baytrail.o 58 59 obj-$(CONFIG_I2C_DESIGNWARE_PCI) += i2c-designware-pci.o 59 60 i2c-designware-pci-y := i2c-designware-pcidrv.o
+392
drivers/i2c/busses/i2c-designware-amdpsp.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + 3 + #include <linux/bitfield.h> 4 + #include <linux/bits.h> 5 + #include <linux/i2c.h> 6 + #include <linux/io-64-nonatomic-lo-hi.h> 7 + #include <linux/psp-sev.h> 8 + #include <linux/types.h> 9 + 10 + #include <asm/msr.h> 11 + 12 + #include "i2c-designware-core.h" 13 + 14 + #define MSR_AMD_PSP_ADDR 0xc00110a2 15 + #define PSP_MBOX_OFFSET 0x10570 16 + #define PSP_CMD_TIMEOUT_US (500 * USEC_PER_MSEC) 17 + 18 + #define PSP_I2C_REQ_BUS_CMD 0x64 19 + #define PSP_I2C_REQ_RETRY_CNT 10 20 + #define PSP_I2C_REQ_RETRY_DELAY_US (50 * USEC_PER_MSEC) 21 + #define PSP_I2C_REQ_STS_OK 0x0 22 + #define PSP_I2C_REQ_STS_BUS_BUSY 0x1 23 + #define PSP_I2C_REQ_STS_INV_PARAM 0x3 24 + 25 + #define PSP_MBOX_FIELDS_STS GENMASK(15, 0) 26 + #define PSP_MBOX_FIELDS_CMD GENMASK(23, 16) 27 + #define PSP_MBOX_FIELDS_RESERVED GENMASK(29, 24) 28 + #define PSP_MBOX_FIELDS_RECOVERY BIT(30) 29 + #define PSP_MBOX_FIELDS_READY BIT(31) 30 + 31 + struct psp_req_buffer_hdr { 32 + u32 total_size; 33 + u32 status; 34 + }; 35 + 36 + enum psp_i2c_req_type { 37 + PSP_I2C_REQ_ACQUIRE, 38 + PSP_I2C_REQ_RELEASE, 39 + PSP_I2C_REQ_MAX 40 + }; 41 + 42 + struct psp_i2c_req { 43 + struct psp_req_buffer_hdr hdr; 44 + enum psp_i2c_req_type type; 45 + }; 46 + 47 + struct psp_mbox { 48 + u32 cmd_fields; 49 + u64 i2c_req_addr; 50 + } __packed; 51 + 52 + static DEFINE_MUTEX(psp_i2c_access_mutex); 53 + static unsigned long psp_i2c_sem_acquired; 54 + static void __iomem *mbox_iomem; 55 + static u32 psp_i2c_access_count; 56 + static bool psp_i2c_mbox_fail; 57 + static struct device *psp_i2c_dev; 58 + 59 + /* 60 + * Implementation of PSP-x86 i2c-arbitration mailbox introduced for AMD Cezanne 61 + * family of SoCs. 62 + */ 63 + 64 + static int psp_get_mbox_addr(unsigned long *mbox_addr) 65 + { 66 + unsigned long long psp_mmio; 67 + 68 + if (rdmsrl_safe(MSR_AMD_PSP_ADDR, &psp_mmio)) 69 + return -EIO; 70 + 71 + *mbox_addr = (unsigned long)(psp_mmio + PSP_MBOX_OFFSET); 72 + 73 + return 0; 74 + } 75 + 76 + static int psp_mbox_probe(void) 77 + { 78 + unsigned long mbox_addr; 79 + int ret; 80 + 81 + ret = psp_get_mbox_addr(&mbox_addr); 82 + if (ret) 83 + return ret; 84 + 85 + mbox_iomem = ioremap(mbox_addr, sizeof(struct psp_mbox)); 86 + if (!mbox_iomem) 87 + return -ENOMEM; 88 + 89 + return 0; 90 + } 91 + 92 + /* Recovery field should be equal 0 to start sending commands */ 93 + static int psp_check_mbox_recovery(struct psp_mbox __iomem *mbox) 94 + { 95 + u32 tmp; 96 + 97 + tmp = readl(&mbox->cmd_fields); 98 + 99 + return FIELD_GET(PSP_MBOX_FIELDS_RECOVERY, tmp); 100 + } 101 + 102 + static int psp_wait_cmd(struct psp_mbox __iomem *mbox) 103 + { 104 + u32 tmp, expected; 105 + 106 + /* Expect mbox_cmd to be cleared and ready bit to be set by PSP */ 107 + expected = FIELD_PREP(PSP_MBOX_FIELDS_READY, 1); 108 + 109 + /* 110 + * Check for readiness of PSP mailbox in a tight loop in order to 111 + * process further as soon as command was consumed. 112 + */ 113 + return readl_poll_timeout(&mbox->cmd_fields, tmp, (tmp == expected), 114 + 0, PSP_CMD_TIMEOUT_US); 115 + } 116 + 117 + /* Status equal to 0 means that PSP succeed processing command */ 118 + static u32 psp_check_mbox_sts(struct psp_mbox __iomem *mbox) 119 + { 120 + u32 cmd_reg; 121 + 122 + cmd_reg = readl(&mbox->cmd_fields); 123 + 124 + return FIELD_GET(PSP_MBOX_FIELDS_STS, cmd_reg); 125 + } 126 + 127 + static int psp_send_cmd(struct psp_i2c_req *req) 128 + { 129 + struct psp_mbox __iomem *mbox = mbox_iomem; 130 + phys_addr_t req_addr; 131 + u32 cmd_reg; 132 + 133 + if (psp_check_mbox_recovery(mbox)) 134 + return -EIO; 135 + 136 + if (psp_wait_cmd(mbox)) 137 + return -EBUSY; 138 + 139 + /* 140 + * Fill mailbox with address of command-response buffer, which will be 141 + * used for sending i2c requests as well as reading status returned by 142 + * PSP. Use physical address of buffer, since PSP will map this region. 143 + */ 144 + req_addr = __psp_pa((void *)req); 145 + writeq(req_addr, &mbox->i2c_req_addr); 146 + 147 + /* Write command register to trigger processing */ 148 + cmd_reg = FIELD_PREP(PSP_MBOX_FIELDS_CMD, PSP_I2C_REQ_BUS_CMD); 149 + writel(cmd_reg, &mbox->cmd_fields); 150 + 151 + if (psp_wait_cmd(mbox)) 152 + return -ETIMEDOUT; 153 + 154 + if (psp_check_mbox_sts(mbox)) 155 + return -EIO; 156 + 157 + return 0; 158 + } 159 + 160 + /* Helper to verify status returned by PSP */ 161 + static int check_i2c_req_sts(struct psp_i2c_req *req) 162 + { 163 + int status; 164 + 165 + status = readl(&req->hdr.status); 166 + 167 + switch (status) { 168 + case PSP_I2C_REQ_STS_OK: 169 + return 0; 170 + case PSP_I2C_REQ_STS_BUS_BUSY: 171 + return -EBUSY; 172 + case PSP_I2C_REQ_STS_INV_PARAM: 173 + default: 174 + return -EIO; 175 + }; 176 + } 177 + 178 + static int psp_send_check_i2c_req(struct psp_i2c_req *req) 179 + { 180 + /* 181 + * Errors in x86-PSP i2c-arbitration protocol may occur at two levels: 182 + * 1. mailbox communication - PSP is not operational or some IO errors 183 + * with basic communication had happened; 184 + * 2. i2c-requests - PSP refuses to grant i2c arbitration to x86 for too 185 + * long. 186 + * In order to distinguish between these two in error handling code, all 187 + * errors on the first level (returned by psp_send_cmd) are shadowed by 188 + * -EIO. 189 + */ 190 + if (psp_send_cmd(req)) 191 + return -EIO; 192 + 193 + return check_i2c_req_sts(req); 194 + } 195 + 196 + static int psp_send_i2c_req(enum psp_i2c_req_type i2c_req_type) 197 + { 198 + struct psp_i2c_req *req; 199 + unsigned long start; 200 + int status, ret; 201 + 202 + /* Allocate command-response buffer */ 203 + req = kzalloc(sizeof(*req), GFP_KERNEL); 204 + if (!req) 205 + return -ENOMEM; 206 + 207 + req->hdr.total_size = sizeof(*req); 208 + req->type = i2c_req_type; 209 + 210 + start = jiffies; 211 + ret = read_poll_timeout(psp_send_check_i2c_req, status, 212 + (status != -EBUSY), 213 + PSP_I2C_REQ_RETRY_DELAY_US, 214 + PSP_I2C_REQ_RETRY_CNT * PSP_I2C_REQ_RETRY_DELAY_US, 215 + 0, req); 216 + if (ret) 217 + goto cleanup; 218 + 219 + ret = status; 220 + if (ret) 221 + goto cleanup; 222 + 223 + dev_dbg(psp_i2c_dev, "Request accepted by PSP after %ums\n", 224 + jiffies_to_msecs(jiffies - start)); 225 + 226 + cleanup: 227 + kfree(req); 228 + return ret; 229 + } 230 + 231 + static int psp_acquire_i2c_bus(void) 232 + { 233 + int status; 234 + 235 + mutex_lock(&psp_i2c_access_mutex); 236 + 237 + /* Return early if mailbox malfunctioned */ 238 + if (psp_i2c_mbox_fail) 239 + goto cleanup; 240 + 241 + /* 242 + * Simply increment usage counter and return if PSP semaphore was 243 + * already taken by kernel. 244 + */ 245 + if (psp_i2c_access_count) { 246 + psp_i2c_access_count++; 247 + goto cleanup; 248 + }; 249 + 250 + status = psp_send_i2c_req(PSP_I2C_REQ_ACQUIRE); 251 + if (status) { 252 + if (status == -ETIMEDOUT) 253 + dev_err(psp_i2c_dev, "Timed out waiting for PSP to release I2C bus\n"); 254 + else 255 + dev_err(psp_i2c_dev, "PSP communication error\n"); 256 + 257 + dev_err(psp_i2c_dev, "Assume i2c bus is for exclusive host usage\n"); 258 + psp_i2c_mbox_fail = true; 259 + goto cleanup; 260 + } 261 + 262 + psp_i2c_sem_acquired = jiffies; 263 + psp_i2c_access_count++; 264 + 265 + /* 266 + * In case of errors with PSP arbitrator psp_i2c_mbox_fail variable is 267 + * set above. As a consequence consecutive calls to acquire will bypass 268 + * communication with PSP. At any case i2c bus is granted to the caller, 269 + * thus always return success. 270 + */ 271 + cleanup: 272 + mutex_unlock(&psp_i2c_access_mutex); 273 + return 0; 274 + } 275 + 276 + static void psp_release_i2c_bus(void) 277 + { 278 + int status; 279 + 280 + mutex_lock(&psp_i2c_access_mutex); 281 + 282 + /* Return early if mailbox was malfunctional */ 283 + if (psp_i2c_mbox_fail) 284 + goto cleanup; 285 + 286 + /* 287 + * If we are last owner of PSP semaphore, need to release aribtration 288 + * via mailbox. 289 + */ 290 + psp_i2c_access_count--; 291 + if (psp_i2c_access_count) 292 + goto cleanup; 293 + 294 + /* Send a release command to PSP */ 295 + status = psp_send_i2c_req(PSP_I2C_REQ_RELEASE); 296 + if (status) { 297 + if (status == -ETIMEDOUT) 298 + dev_err(psp_i2c_dev, "Timed out waiting for PSP to acquire I2C bus\n"); 299 + else 300 + dev_err(psp_i2c_dev, "PSP communication error\n"); 301 + 302 + dev_err(psp_i2c_dev, "Assume i2c bus is for exclusive host usage\n"); 303 + psp_i2c_mbox_fail = true; 304 + goto cleanup; 305 + } 306 + 307 + dev_dbg(psp_i2c_dev, "PSP semaphore held for %ums\n", 308 + jiffies_to_msecs(jiffies - psp_i2c_sem_acquired)); 309 + 310 + cleanup: 311 + mutex_unlock(&psp_i2c_access_mutex); 312 + } 313 + 314 + /* 315 + * Locking methods are based on the default implementation from 316 + * drivers/i2c/i2c-core-base.c, but with psp acquire and release operations 317 + * added. With this in place we can ensure that i2c clients on the bus shared 318 + * with psp are able to lock HW access to the bus for arbitrary number of 319 + * operations - that is e.g. write-wait-read. 320 + */ 321 + static void i2c_adapter_dw_psp_lock_bus(struct i2c_adapter *adapter, 322 + unsigned int flags) 323 + { 324 + psp_acquire_i2c_bus(); 325 + rt_mutex_lock_nested(&adapter->bus_lock, i2c_adapter_depth(adapter)); 326 + } 327 + 328 + static int i2c_adapter_dw_psp_trylock_bus(struct i2c_adapter *adapter, 329 + unsigned int flags) 330 + { 331 + int ret; 332 + 333 + ret = rt_mutex_trylock(&adapter->bus_lock); 334 + if (ret) 335 + return ret; 336 + 337 + psp_acquire_i2c_bus(); 338 + 339 + return ret; 340 + } 341 + 342 + static void i2c_adapter_dw_psp_unlock_bus(struct i2c_adapter *adapter, 343 + unsigned int flags) 344 + { 345 + psp_release_i2c_bus(); 346 + rt_mutex_unlock(&adapter->bus_lock); 347 + } 348 + 349 + static const struct i2c_lock_operations i2c_dw_psp_lock_ops = { 350 + .lock_bus = i2c_adapter_dw_psp_lock_bus, 351 + .trylock_bus = i2c_adapter_dw_psp_trylock_bus, 352 + .unlock_bus = i2c_adapter_dw_psp_unlock_bus, 353 + }; 354 + 355 + int i2c_dw_amdpsp_probe_lock_support(struct dw_i2c_dev *dev) 356 + { 357 + int ret; 358 + 359 + if (!dev) 360 + return -ENODEV; 361 + 362 + if (!(dev->flags & ARBITRATION_SEMAPHORE)) 363 + return -ENODEV; 364 + 365 + /* Allow to bind only one instance of a driver */ 366 + if (psp_i2c_dev) 367 + return -EEXIST; 368 + 369 + psp_i2c_dev = dev->dev; 370 + 371 + ret = psp_mbox_probe(); 372 + if (ret) 373 + return ret; 374 + 375 + dev_info(psp_i2c_dev, "I2C bus managed by AMD PSP\n"); 376 + 377 + /* 378 + * Install global locking callbacks for adapter as well as internal i2c 379 + * controller locks. 380 + */ 381 + dev->adapter.lock_ops = &i2c_dw_psp_lock_ops; 382 + dev->acquire_lock = psp_acquire_i2c_bus; 383 + dev->release_lock = psp_release_i2c_bus; 384 + 385 + return 0; 386 + } 387 + 388 + /* Unmap area used as a mailbox with PSP */ 389 + void i2c_dw_amdpsp_remove_lock_support(struct dw_i2c_dev *dev) 390 + { 391 + iounmap(mbox_iomem); 392 + }
+6 -6
drivers/i2c/busses/i2c-designware-baytrail.c
··· 12 12 13 13 #include "i2c-designware-core.h" 14 14 15 - int i2c_dw_probe_lock_support(struct dw_i2c_dev *dev) 15 + int i2c_dw_baytrail_probe_lock_support(struct dw_i2c_dev *dev) 16 16 { 17 17 acpi_status status; 18 18 unsigned long long shared_host = 0; 19 19 acpi_handle handle; 20 20 21 - if (!dev || !dev->dev) 22 - return 0; 21 + if (!dev) 22 + return -ENODEV; 23 23 24 24 handle = ACPI_HANDLE(dev->dev); 25 25 if (!handle) 26 - return 0; 26 + return -ENODEV; 27 27 28 28 status = acpi_evaluate_integer(handle, "_SEM", NULL, &shared_host); 29 29 if (ACPI_FAILURE(status)) 30 - return 0; 30 + return -ENODEV; 31 31 32 32 if (!shared_host) 33 - return 0; 33 + return -ENODEV; 34 34 35 35 if (!iosf_mbi_available()) 36 36 return -EPROBE_DEFER;
+15 -3
drivers/i2c/busses/i2c-designware-core.h
··· 227 227 * @hs_lcnt: high speed LCNT value 228 228 * @acquire_lock: function to acquire a hardware lock on the bus 229 229 * @release_lock: function to release a hardware lock on the bus 230 + * @semaphore_idx: Index of table with semaphore type attached to the bus. It's 231 + * -1 if there is no semaphore. 230 232 * @shared_with_punit: true if this bus is shared with the SoCs PUNIT 231 233 * @disable: function to disable the controller 232 234 * @disable_int: function to disable all interrupts ··· 287 285 u16 hs_lcnt; 288 286 int (*acquire_lock)(void); 289 287 void (*release_lock)(void); 288 + int semaphore_idx; 290 289 bool shared_with_punit; 291 290 void (*disable)(struct dw_i2c_dev *dev); 292 291 void (*disable_int)(struct dw_i2c_dev *dev); ··· 300 297 301 298 #define ACCESS_INTR_MASK BIT(0) 302 299 #define ACCESS_NO_IRQ_SUSPEND BIT(1) 300 + #define ARBITRATION_SEMAPHORE BIT(2) 303 301 304 302 #define MODEL_MSCC_OCELOT BIT(8) 305 303 #define MODEL_BAIKAL_BT1 BIT(9) ··· 313 309 */ 314 310 #define AMD_UCSI_INTR_REG 0x474 315 311 #define AMD_UCSI_INTR_EN 0xd 312 + 313 + struct i2c_dw_semaphore_callbacks { 314 + int (*probe)(struct dw_i2c_dev *dev); 315 + void (*remove)(struct dw_i2c_dev *dev); 316 + }; 316 317 317 318 int i2c_dw_init_regmap(struct dw_i2c_dev *dev); 318 319 u32 i2c_dw_scl_hcnt(u32 ic_clk, u32 tSYMBOL, u32 tf, int cond, int offset); ··· 379 370 } 380 371 381 372 #if IS_ENABLED(CONFIG_I2C_DESIGNWARE_BAYTRAIL) 382 - extern int i2c_dw_probe_lock_support(struct dw_i2c_dev *dev); 383 - #else 384 - static inline int i2c_dw_probe_lock_support(struct dw_i2c_dev *dev) { return 0; } 373 + int i2c_dw_baytrail_probe_lock_support(struct dw_i2c_dev *dev); 374 + #endif 375 + 376 + #if IS_ENABLED(CONFIG_I2C_DESIGNWARE_AMDPSP) 377 + int i2c_dw_amdpsp_probe_lock_support(struct dw_i2c_dev *dev); 378 + void i2c_dw_amdpsp_remove_lock_support(struct dw_i2c_dev *dev); 385 379 #endif 386 380 387 381 int i2c_dw_validate_speed(struct dw_i2c_dev *dev);
+60
drivers/i2c/busses/i2c-designware-platdrv.c
··· 50 50 { "808622C1", ACCESS_NO_IRQ_SUSPEND }, 51 51 { "AMD0010", ACCESS_INTR_MASK }, 52 52 { "AMDI0010", ACCESS_INTR_MASK }, 53 + { "AMDI0019", ACCESS_INTR_MASK | ARBITRATION_SEMAPHORE }, 53 54 { "AMDI0510", 0 }, 54 55 { "APMC0D0F", 0 }, 55 56 { "HISI02A1", 0 }, ··· 205 204 { } /* terminate list */ 206 205 }; 207 206 207 + static const struct i2c_dw_semaphore_callbacks i2c_dw_semaphore_cb_table[] = { 208 + #ifdef CONFIG_I2C_DESIGNWARE_BAYTRAIL 209 + { 210 + .probe = i2c_dw_baytrail_probe_lock_support, 211 + }, 212 + #endif 213 + #ifdef CONFIG_I2C_DESIGNWARE_AMDPSP 214 + { 215 + .probe = i2c_dw_amdpsp_probe_lock_support, 216 + .remove = i2c_dw_amdpsp_remove_lock_support, 217 + }, 218 + #endif 219 + {} 220 + }; 221 + 222 + static int i2c_dw_probe_lock_support(struct dw_i2c_dev *dev) 223 + { 224 + const struct i2c_dw_semaphore_callbacks *ptr; 225 + int i = 0; 226 + int ret; 227 + 228 + ptr = i2c_dw_semaphore_cb_table; 229 + 230 + dev->semaphore_idx = -1; 231 + 232 + while (ptr->probe) { 233 + ret = ptr->probe(dev); 234 + if (ret) { 235 + /* 236 + * If there is no semaphore device attached to this 237 + * controller, we shouldn't abort general i2c_controller 238 + * probe. 239 + */ 240 + if (ret != -ENODEV) 241 + return ret; 242 + 243 + i++; 244 + ptr++; 245 + continue; 246 + } 247 + 248 + dev->semaphore_idx = i; 249 + break; 250 + } 251 + 252 + return 0; 253 + } 254 + 255 + static void i2c_dw_remove_lock_support(struct dw_i2c_dev *dev) 256 + { 257 + if (dev->semaphore_idx < 0) 258 + return; 259 + 260 + if (i2c_dw_semaphore_cb_table[dev->semaphore_idx].remove) 261 + i2c_dw_semaphore_cb_table[dev->semaphore_idx].remove(dev); 262 + } 263 + 208 264 static int dw_i2c_plat_probe(struct platform_device *pdev) 209 265 { 210 266 struct i2c_adapter *adap; ··· 391 333 pm_runtime_dont_use_autosuspend(&pdev->dev); 392 334 pm_runtime_put_sync(&pdev->dev); 393 335 dw_i2c_plat_pm_cleanup(dev); 336 + 337 + i2c_dw_remove_lock_support(dev); 394 338 395 339 reset_control_assert(dev->rst); 396 340