From: Yicong Yang <yangyicong@hisilicon.com>
To: <jarkko.nikula@linux.intel.com>,
<andriy.shevchenko@linux.intel.com>,
<mika.westerberg@linux.intel.com>, <wsa@kernel.org>,
<linux-i2c@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Cc: <yangyicong@hisilicon.com>, <prime.zeng@hisilicon.com>,
<linuxarm@huawei.com>
Subject: [PATCH 1/2] i2c: hisi: Add generic GPIO bus recovery support
Date: Tue, 25 Jan 2022 20:49:29 +0800 [thread overview]
Message-ID: <20220125124930.50369-2-yangyicong@hisilicon.com> (raw)
In-Reply-To: <20220125124930.50369-1-yangyicong@hisilicon.com>
Add generic GPIO bus recovery support for i2c-hisi driver
by registering the recovery information with core provided
i2c_generic_scl_recovery() method.
As the SCL/SDA pins are multiplexed with GPIO, we need to
switch the pins mux to GPIO before recovery and switch back
after recovery. It's implemented by the ACPI method in
the i2c_bus_recovery_info->{prepare,unprepare}_recovery()
method.
Signed-off-by: Yicong Yang <yangyicong@hisilicon.com>
---
drivers/i2c/busses/i2c-hisi.c | 78 +++++++++++++++++++++++++++++++++++
1 file changed, 78 insertions(+)
diff --git a/drivers/i2c/busses/i2c-hisi.c b/drivers/i2c/busses/i2c-hisi.c
index acf394812061..ffc495f426e9 100644
--- a/drivers/i2c/busses/i2c-hisi.c
+++ b/drivers/i2c/busses/i2c-hisi.c
@@ -5,9 +5,11 @@
* Copyright (c) 2021 HiSilicon Technologies Co., Ltd.
*/
+#include <linux/acpi.h>
#include <linux/bits.h>
#include <linux/bitfield.h>
#include <linux/completion.h>
+#include <linux/gpio/consumer.h>
#include <linux/i2c.h>
#include <linux/interrupt.h>
#include <linux/io.h>
@@ -106,6 +108,9 @@ struct hisi_i2c_controller {
struct i2c_timings t;
u32 clk_rate_khz;
u32 spk_len;
+
+ /* Bus recovery method */
+ struct i2c_bus_recovery_info rinfo;
};
static void hisi_i2c_enable_int(struct hisi_i2c_controller *ctlr, u32 mask)
@@ -424,6 +429,77 @@ static void hisi_i2c_configure_bus(struct hisi_i2c_controller *ctlr)
writel(reg, ctlr->iobase + HISI_I2C_FIFO_CTRL);
}
+#ifdef CONFIG_ACPI
+#define HISI_I2C_PIN_MUX_METHOD "PMUX"
+
+/**
+ * i2c_dw_acpi_pin_mux_change - Change the I2C controller's pin mux through ACPI
+ * @dev: device owns the SCL/SDA pin
+ * @to_gpio: true to switch to GPIO, false to switch to SCL/SDA
+ *
+ * The function invokes the specific ACPI method "PMUX" for changing the
+ * pin mux of I2C controller between SCL/SDA and GPIO in order to help on
+ * the generic GPIO recovery process.
+ */
+static void i2c_hisi_pin_mux_change(struct device *dev, bool to_gpio)
+{
+ acpi_handle handle = ACPI_HANDLE(dev);
+ struct acpi_object_list arg_list;
+ unsigned long long data;
+ union acpi_object arg;
+
+ arg.type = ACPI_TYPE_INTEGER;
+ arg.integer.value = to_gpio;
+ arg_list.count = 1;
+ arg_list.pointer = &arg;
+
+ acpi_evaluate_integer(handle, HISI_I2C_PIN_MUX_METHOD, &arg_list, &data);
+}
+
+static void i2c_hisi_prepare_recovery(struct i2c_adapter *adap)
+{
+ struct hisi_i2c_controller *ctlr = i2c_get_adapdata(adap);
+
+ i2c_hisi_pin_mux_change(ctlr->dev, true);
+}
+
+static void i2c_hisi_unprepare_recovery(struct i2c_adapter *adap)
+{
+ struct hisi_i2c_controller *ctlr = i2c_get_adapdata(adap);
+
+ i2c_hisi_pin_mux_change(ctlr->dev, false);
+}
+
+static void hisi_i2c_init_recovery_info(struct hisi_i2c_controller *ctlr)
+{
+ struct i2c_bus_recovery_info *rinfo = &ctlr->rinfo;
+ struct acpi_device *adev = ACPI_COMPANION(ctlr->dev);
+ struct gpio_desc *gpio;
+
+ if (!acpi_has_method(adev->handle, HISI_I2C_PIN_MUX_METHOD))
+ return;
+
+ gpio = devm_gpiod_get_optional(ctlr->dev, "scl", GPIOD_OUT_HIGH);
+ if (IS_ERR_OR_NULL(gpio))
+ return;
+
+ rinfo->scl_gpiod = gpio;
+
+ gpio = devm_gpiod_get_optional(ctlr->dev, "sda", GPIOD_IN);
+ if (IS_ERR(gpio))
+ return;
+
+ rinfo->sda_gpiod = gpio;
+ rinfo->recover_bus = i2c_generic_scl_recovery;
+ rinfo->prepare_recovery = i2c_hisi_prepare_recovery;
+ rinfo->unprepare_recovery = i2c_hisi_unprepare_recovery;
+
+ ctlr->adapter.bus_recovery_info = rinfo;
+}
+#else
+static inline void hisi_i2c_init_recovery_info(struct hisi_i2c_controller *ctlr) { }
+#endif /* CONFIG_ACPI */
+
static int hisi_i2c_probe(struct platform_device *pdev)
{
struct hisi_i2c_controller *ctlr;
@@ -473,6 +549,8 @@ static int hisi_i2c_probe(struct platform_device *pdev)
adapter->dev.parent = dev;
i2c_set_adapdata(adapter, ctlr);
+ hisi_i2c_init_recovery_info(ctlr);
+
ret = devm_i2c_add_adapter(dev, adapter);
if (ret)
return ret;
--
2.24.0
next prev parent reply other threads:[~2022-01-25 12:54 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-25 12:49 [PATCH 0/2] Add I2C bus recovery support on Kunpeng 920/930 Yicong Yang
2022-01-25 12:49 ` Yicong Yang [this message]
2022-02-07 11:17 ` [PATCH 1/2] i2c: hisi: Add generic GPIO bus recovery support Andy Shevchenko
2022-02-07 11:20 ` Andy Shevchenko
2022-02-08 2:15 ` Yicong Yang
2022-02-09 12:12 ` Andy Shevchenko
2022-01-25 12:49 ` [PATCH 2/2] i2c: designware: Add ACPI assisted " Yicong Yang
2022-02-07 7:37 ` [PATCH 0/2] Add I2C bus recovery support on Kunpeng 920/930 Yicong Yang
2022-02-07 11:21 ` 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=20220125124930.50369-2-yangyicong@hisilicon.com \
--to=yangyicong@hisilicon.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=jarkko.nikula@linux.intel.com \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxarm@huawei.com \
--cc=mika.westerberg@linux.intel.com \
--cc=prime.zeng@hisilicon.com \
--cc=wsa@kernel.org \
/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
all inboxes | Powered by JetHome®