From patchwork Tue Jan 31 12:37:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Binbin Zhou X-Patchwork-Id: 649447 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6E19C38142 for ; Tue, 31 Jan 2023 12:37:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231431AbjAaMhg (ORCPT ); Tue, 31 Jan 2023 07:37:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231224AbjAaMhd (ORCPT ); Tue, 31 Jan 2023 07:37:33 -0500 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C6BDD4B483; Tue, 31 Jan 2023 04:37:25 -0800 (PST) Received: from loongson.cn (unknown [112.20.108.204]) by gateway (Coremail) with SMTP id _____8AxX+uEC9ljjIkKAA--.21685S3; Tue, 31 Jan 2023 20:37:24 +0800 (CST) Received: from localhost.localdomain (unknown [112.20.108.204]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxWL2BC9ljNH4lAA--.8399S2; Tue, 31 Jan 2023 20:37:22 +0800 (CST) From: Binbin Zhou To: Wolfram Sang , Wolfram Sang , Andy Shevchenko , Mika Westerberg , linux-i2c@vger.kernel.org Cc: loongarch@lists.linux.dev, devicetree@vger.kernel.org, Huacai Chen , WANG Xuerui , Andy Shevchenko , Arnd Bergmann , Rob Herring , Krzysztof Kozlowski , Jianmin Lv , Peibao Liu , Binbin Zhou Subject: [PATCH V11 0/3] i2c: ls2x: Add support for the Loongson-2K/LS7A I2C controller Date: Tue, 31 Jan 2023 20:37:29 +0800 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Y6xIIjxv20xvE14v26r1I 6r4UMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWUJVW8JwCI42IY6xAIw20EY4v20xvaj40_Jr 0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVWUJVW8JbIY CTnIWIevJa73UjIFyTuYvjxU4SoGDUUUU Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Hi all: This patch series adds support for the I2C module found on various Loongson systems with the Loongson-2K SoC or the Loongson LS7A bridge chip. For now, the I2C driver is suitable for DT-based or ACPI-based systems. I have tested on Loongson-3A5000LA+LS7A1000/LS7A2000, Loongson-2K1000LA and Loongson-2K0500. Thanks. Changes since V10: - Drop patch #1 "i2c: gpio: Add support on ACPI-based system", since it has been applied yet. - patch(2/3) - module_platform_driver() replaces subsys_initcall(). Changes since V9: - patch (1/4) - dev->of_node replaced by dev_fwnode() in i2c_gpio_probe(); - Add device_set_node(); - Add Tested-by tag. - patch (3/4) - Add Reviewed-by tag. Changes since V8: - patch (3/4) - Refactor the error handling process of the ls2x_i2c_xfer_one(); - Split comment and code. Changes since V7: - patch (3/4) - I2C_LS2X should be added to the Kconfig/Makefile in Latin alphabetical order. - To avoid repeated type conversions, 'struct ls2x_i2c_priv *priv' replaces 'struct i2c_adapter *adap' as a function parameter, e.g. ls2x_i2c_start(); - Refactor ls2x_i2c_stop() with readb_poll_timeout(), mainly with LS2X_SR_BUSY to indicate the status (success/timeout) of the stop command; - Remove extra parentheses; - For consistency, the variable 'r' in ls2x_i2c_probe() is renamed to 'ret'. Changes since V6: - patch (1/4) - Add Reviewed-by tag. - patch (3/4) - GPL-2.0 -> GPL-2.0-only; - Add property.h; - writew() should be used to operate I2C_LS2X_PRER, and drop the suffix of I2C_LS2X_PRER_LO/I2C_LS2X_PRER_HI; - Drop ls2x_i2c_priv->dev, for it can be completely replaced by 'adapter.dev.parent'; - Reasonable return value handling in ls2x_i2c_xfer_one(); - Dropping the I2C_M_STOP flag judgment, the stop parameter of ls2x_i2c_xfer_one() represents the last msg; - Add comments for subsys_initcall(); - Code formatting, such as dropping unnecessary blank lines. Changes since V5: - patch (1/4) - Add property.h. - patch (3/4) - Put the ls2x_i2c_reginit() in front of irq requst; - Refact ls2x_i2c_adjust_bus_speed: discard the magic value of the divider register and LS2X_I2C_FREQ_STD is used to calculate the frequency; - Drop useless parameters: priv->suspended, and also disable I2C interrupts during suspend; - Drop ls2x_i2c_remove(), for the adapter will be auto deleted on driver detach; - Drop MODULE_ALIAS; - Code formatting, such as alignment. Thanks Andy for your comments. Changes since V4: - patch (1/4) - Drop unneeded headers: of.h; - xxx_props -> xxx_properties. - patch (2/4) - Add interrupt headers to fix syntax error found by Rob. - patch (3/4) - Drop atmoic loop in ls2x_i2c_master_xfer(), I have tested it on the appropriate environment with no problems; - Define the corresponding bits in I2C_LS2X_CTR to avoid magic numbers; - dev_get_drvdata() is used to get ls2x_i2c_priv() in ls2x_i2c_suspend(); - i2c_add_adapter() -> devm_i2c_add_adapter(); - SET_SYSTEM_SLEEP_PM_OPS() -> DEFINE_RUNTIME_DEV_PM_OPS(); - Code formatting, such as alignment. Details: https://lore.kernel.org/all/Y4e%2F6KewuHjAluSZ@smile.fi.intel.com/ Changes since V3: - Addressed all review comments from v3 - Change the changelog text to make it clearer (1/5); - Fix some minor bugs, such as formatting issues (2/5); - Fix some formatting issues (3/5); - Deep refactoring of code for clarity (4/5). Details: https://lore.kernel.org/all/Y4S2cnlAm3YYvZ8E@smile.fi.intel.com/ Thanks to all for their suggestions. Changes since V2: - Addressed all review comments from v2 - Drop of_match_ptr() in i2c-gpio to avoid potential unused warnings (1/5); - Introduce i2c_gpio_get_props() function as the generic interface to get i2c-gpio props from DT or ACPI table (2/5); - Refact ls2x i2c code, similar to removing excessive goto tags (4/5). Thanks to Andy and Mika for their suggestions. Changes since V1: - Remove the function of getting the static i2c bus number from ACPI "_UID"; - Fix build warning from kernel test robot. Binbin Zhou (3): dt-bindings: i2c: Add Loongson LS2X I2C controller i2c: ls2x: Add driver for Loongson-2K/LS7A I2C controller LoongArch: Enable LS2X I2C in loongson3_defconfig .../bindings/i2c/loongson,ls2x-i2c.yaml | 51 +++ arch/loongarch/configs/loongson3_defconfig | 1 + drivers/i2c/busses/Kconfig | 11 + drivers/i2c/busses/Makefile | 1 + drivers/i2c/busses/i2c-ls2x.c | 370 ++++++++++++++++++ 5 files changed, 434 insertions(+) create mode 100644 Documentation/devicetree/bindings/i2c/loongson,ls2x-i2c.yaml create mode 100644 drivers/i2c/busses/i2c-ls2x.c