Skip to contentSkip to conversation

i2c: ls2x: Add support for the Loongson-2K/LS7A I2C controller

PATCH Applied Binbin Zhou 3 participants 7 messages Jan 31, 2023 – Feb 3, 2023

Subsystems (4)
lore
Share & tools
lore

Binbin Zhou

author maintainer
#0 lore raw

v11 cover i2c: ls2x: Add support for the Loongson-2K/LS7A I2C controller

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%[email protected]/

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/[email protected]/

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
Signature · 1 line
2.39.0
author maintainer
#1 lore raw

PATCH v11 1/3 dt-bindings: i2c: Add Loongson LS2X I2C controller

Add Loongson LS2X I2C controller binding with DT schema format using json-schema.

---
 .../bindings/i2c/loongson,ls2x-i2c.yaml       | 51 +++++++++++++++++++
 1 file changed, 51 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/i2c/loongson,ls2x-i2c.yaml
Documentation/devicetree/bindings/i2c/loongson,ls2x-i2c.yaml new file +51 -0
new file mode 100644
index 000000000000..67882ec6e06a
@@ -0,0 +1,51 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/i2c/loongson,ls2x-i2c.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Loongson LS2X I2C Controller
+
+maintainers:
+  - Binbin Zhou <[email protected]>
+
+allOf:
+  - $ref: /schemas/i2c/i2c-controller.yaml#
+
+properties:
+  compatible:
+    enum:
+      - loongson,ls2k-i2c
+      - loongson,ls7a-i2c
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - interrupts
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    i2c0: i2c@1fe21000 {
+        compatible = "loongson,ls2k-i2c";
+        reg = <0x1fe21000 0x8>;
+        interrupt-parent = <&extioiic>;
+        interrupts = <22 IRQ_TYPE_LEVEL_LOW>;
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        eeprom@57 {
+            compatible = "atmel,24c16";
+            reg = <0x57>;
+            pagesize = <16>;
+        };
+    };
Signature · 1 line
2.39.0
author maintainer
#3 lore raw

PATCH v11 2/3 i2c: ls2x: Add driver for Loongson-2K/LS7A I2C controller

In reply to Binbin Zhou

This I2C module is integrated into the Loongson-2K SoCs and Loongson LS7A bridge chip.

---
 drivers/i2c/busses/Kconfig    |  11 +
 drivers/i2c/busses/Makefile   |   1 +
 drivers/i2c/busses/i2c-ls2x.c | 370 ++++++++++++++++++++++++++++++++++
 3 files changed, 382 insertions(+)
 create mode 100644 drivers/i2c/busses/i2c-ls2x.c
drivers/i2c/busses/Kconfig +11 -0
index a7bfddf08fa7..c3ed15dae3df 100644
@@ -761,6 +761,17 @@ config I2C_LPC2K
 	  This driver can also be built as a module.  If so, the module
 	  will be called i2c-lpc2k.
 
+config I2C_LS2X
+	tristate "Loongson LS2X I2C adapter"
+	depends on MACH_LOONGSON64 || COMPILE_TEST
+	help
+	  If you say yes to this option, support will be included for the
+	  I2C interface on the Loongson-2K SoCs and Loongson LS7A bridge
+	  chip.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called i2c-ls2x.
+
 config I2C_MLXBF
         tristate "Mellanox BlueField I2C controller"
         depends on MELLANOX_PLATFORM && ARM64
drivers/i2c/busses/Makefile +1 -0
index e73cdb1d2b5a..0584fe160824 100644
@@ -77,6 +77,7 @@ obj-$(CONFIG_I2C_IOP3XX)	+= i2c-iop3xx.o
 obj-$(CONFIG_I2C_JZ4780)	+= i2c-jz4780.o
 obj-$(CONFIG_I2C_KEMPLD)	+= i2c-kempld.o
 obj-$(CONFIG_I2C_LPC2K)		+= i2c-lpc2k.o
+obj-$(CONFIG_I2C_LS2X)		+= i2c-ls2x.o
 obj-$(CONFIG_I2C_MESON)		+= i2c-meson.o
 obj-$(CONFIG_I2C_MICROCHIP_CORE)	+= i2c-microchip-corei2c.o
 obj-$(CONFIG_I2C_MPC)		+= i2c-mpc.o
drivers/i2c/busses/i2c-ls2x.c new file +370 -0

370 lines not on this page · raw message

Signature · 1 line
2.39.0
Applied
#4 lore raw

Re: [PATCH V11 2/3] i2c: ls2x: Add driver for Loongson-2K/LS7A I2C controller

Quoted 5 lines · Binbin Zhou

This I2C module is integrated into the Loongson-2K SoCs and Loongson LS7A bridge chip.

Applied to for-next, thank you and all the reviewers!

If you like to maintain the driver, please send an addition to the MAINTAINERS file in a seperate patch. That would be great!

#5 lore raw

Re: [PATCH V11 2/3] i2c: ls2x: Add driver for Loongson-2K/LS7A I2C controller

Quoted 5 lines · Wolfram Sang
Quoted 3 lines · Binbin Zhou

This I2C module is integrated into the Loongson-2K SoCs and Loongson LS7A bridge chip.

Quoted 8 lines
Quoted 2 lines

Applied to for-next, thank you and all the reviewers!

If you like to maintain the driver, please send an addition to the MAINTAINERS file in a seperate patch. That would be great!

Of course, I'd like to do that, and the patch is coming.

Thanks.
Binbin

author maintainer
#6 lore raw

PATCH v11 3/3 LoongArch: Enable LS2X I2C in loongson3_defconfig

In reply to Binbin Zhou

This is now supported, enable for Loongson-3 systems. Other systems are unaffected.

---
 arch/loongarch/configs/loongson3_defconfig | 1 +
 1 file changed, 1 insertion(+)
arch/loongarch/configs/loongson3_defconfig +1 -0
index cb52774c80e8..5677c4f8576e 100644
@@ -602,6 +602,7 @@ CONFIG_HW_RANDOM_VIRTIO=m
 CONFIG_I2C_CHARDEV=y
 CONFIG_I2C_PIIX4=y
 CONFIG_I2C_GPIO=y
+CONFIG_I2C_LS2X=y
 CONFIG_SPI=y
 CONFIG_GPIO_SYSFS=y
 CONFIG_GPIO_LOONGSON=y
Signature · 1 line
2.39.0