From patchwork Tue Jan 3 07:00:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Binbin Zhou X-Patchwork-Id: 638932 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 AE926C54EBE for ; Tue, 3 Jan 2023 07:00:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236865AbjACHAu (ORCPT ); Tue, 3 Jan 2023 02:00:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236876AbjACHAq (ORCPT ); Tue, 3 Jan 2023 02:00:46 -0500 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EDAE6DE86; Mon, 2 Jan 2023 23:00:42 -0800 (PST) Received: from loongson.cn (unknown [112.20.108.31]) by gateway (Coremail) with SMTP id _____8Dx_+uZ0rNjZxEKAA--.21960S3; Tue, 03 Jan 2023 15:00:41 +0800 (CST) Received: from localhost.localdomain (unknown [112.20.108.31]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxTuSV0rNjSb0SAA--.59328S2; Tue, 03 Jan 2023 15:00:38 +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 , Binbin Zhou Subject: [PATCH V9 0/4] i2c: ls2x: Add support for the Loongson-2K/LS7A I2C controller Date: Tue, 3 Jan 2023 15:00:44 +0800 Message-Id: X-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cVAFwI0_ JFI_Gr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE42xK8VAvwI8IcIk0rV WUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r1j6r4U YxBIdaVFxhVjvjDU0xZFpf9x07j5o7tUUUUU= 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 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 (4): i2c: gpio: Add support on ACPI-based system 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-gpio.c | 28 +- drivers/i2c/busses/i2c-ls2x.c | 381 ++++++++++++++++++ 6 files changed, 463 insertions(+), 10 deletions(-) create mode 100644 Documentation/devicetree/bindings/i2c/loongson,ls2x-i2c.yaml create mode 100644 drivers/i2c/busses/i2c-ls2x.c