xref: /openbmc/linux/drivers/i2c/busses/i2c-designware-baytrail.c (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
115c566fcSAndy Shevchenko // SPDX-License-Identifier: GPL-2.0
2894acb2fSDavid Box /*
324d3fdc8SAndy Shevchenko  * Intel BayTrail PMIC I2C bus semaphore implementation
4894acb2fSDavid Box  * Copyright (c) 2014, Intel Corporation.
5894acb2fSDavid Box  */
6894acb2fSDavid Box #include <linux/device.h>
7894acb2fSDavid Box #include <linux/acpi.h>
8894acb2fSDavid Box #include <linux/i2c.h>
9894acb2fSDavid Box #include <linux/interrupt.h>
10c8e043e6SAndy Shevchenko 
11894acb2fSDavid Box #include <asm/iosf_mbi.h>
12c8e043e6SAndy Shevchenko 
13894acb2fSDavid Box #include "i2c-designware-core.h"
14894acb2fSDavid Box 
i2c_dw_baytrail_probe_lock_support(struct dw_i2c_dev * dev)15*78d5e9e2SJan Dabros int i2c_dw_baytrail_probe_lock_support(struct dw_i2c_dev *dev)
16894acb2fSDavid Box {
17894acb2fSDavid Box 	acpi_status status;
18894acb2fSDavid Box 	unsigned long long shared_host = 0;
19894acb2fSDavid Box 	acpi_handle handle;
20894acb2fSDavid Box 
21*78d5e9e2SJan Dabros 	if (!dev)
22*78d5e9e2SJan Dabros 		return -ENODEV;
23894acb2fSDavid Box 
24894acb2fSDavid Box 	handle = ACPI_HANDLE(dev->dev);
25894acb2fSDavid Box 	if (!handle)
26*78d5e9e2SJan Dabros 		return -ENODEV;
27894acb2fSDavid Box 
28894acb2fSDavid Box 	status = acpi_evaluate_integer(handle, "_SEM", NULL, &shared_host);
29894acb2fSDavid Box 	if (ACPI_FAILURE(status))
30*78d5e9e2SJan Dabros 		return -ENODEV;
31894acb2fSDavid Box 
32e234ed2fSHans de Goede 	if (!shared_host)
33*78d5e9e2SJan Dabros 		return -ENODEV;
34e234ed2fSHans de Goede 
35e234ed2fSHans de Goede 	if (!iosf_mbi_available())
36e234ed2fSHans de Goede 		return -EPROBE_DEFER;
37e234ed2fSHans de Goede 
38894acb2fSDavid Box 	dev_info(dev->dev, "I2C bus managed by PUNIT\n");
398afb4680SHans de Goede 	dev->acquire_lock = iosf_mbi_block_punit_i2c_access;
408afb4680SHans de Goede 	dev->release_lock = iosf_mbi_unblock_punit_i2c_access;
419cbeeca0SHans de Goede 	dev->shared_with_punit = true;
42894acb2fSDavid Box 
43894acb2fSDavid Box 	return 0;
44894acb2fSDavid Box }
45