Skip to contentSkip to conversation

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

PATCH Applied Binbin Zhou 5 participants 18 messages Nov 30, 2022 – Dec 5, 2022

Subsystems (5)

v4 of 11 Applied Latest is v11 →

lore
Share & tools
lore

Binbin Zhou

author maintainer
#0 lore raw

v4 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 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, such as dropping quotes and checking with

    dt_binding_check (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 (5):
i2c: gpio: Fix potential unused warning for 'i2c_gpio_dt_ids'
i2c: gpio: Add support on ACPI-based system
dt-bindings: i2c: add bindings for Loongson LS2X I2C
i2c: ls2x: Add driver for Loongson-2K/LS7A I2C controller
LoongArch: Enable LS2X I2C in loongson3_defconfig

 .../bindings/i2c/loongson,ls2x-i2c.yaml       |  49 +++
 arch/loongarch/configs/loongson3_defconfig    |   1 +
 drivers/i2c/busses/Kconfig                    |  11 +
 drivers/i2c/busses/Makefile                   |   1 +
 drivers/i2c/busses/i2c-gpio.c                 |  30 +-
 drivers/i2c/busses/i2c-ls2x.c                 | 402 ++++++++++++++++++
 6 files changed, 482 insertions(+), 12 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/i2c/loongson,ls2x-i2c.yaml
 create mode 100644 drivers/i2c/busses/i2c-ls2x.c
Signature · 1 line
2.31.1
author maintainer
#1 lore raw

PATCH v4 1/5 i2c: gpio: Fix potential unused warning for 'i2c_gpio_dt_ids'

Dropping a matching #ifdef check along with dropping of_match_ptr() is just a cleanup, while dropping of_match_ptr() that has no corresponding #ifdef fixes an actual warning.

---
 drivers/i2c/busses/i2c-gpio.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/i2c/busses/i2c-gpio.c +1 -3
index b1985c1667e1..0e4385a9bcf7 100644
@@ -482,19 +482,17 @@ static int i2c_gpio_remove(struct platform_device *pdev)
 	return 0;
 }
 
-#if defined(CONFIG_OF)
 static const struct of_device_id i2c_gpio_dt_ids[] = {
 	{ .compatible = "i2c-gpio", },
 	{ /* sentinel */ }
 };
 
 MODULE_DEVICE_TABLE(of, i2c_gpio_dt_ids);
-#endif
 
 static struct platform_driver i2c_gpio_driver = {
 	.driver		= {
 		.name	= "i2c-gpio",
-		.of_match_table	= of_match_ptr(i2c_gpio_dt_ids),
+		.of_match_table	= i2c_gpio_dt_ids,
 	},
 	.probe		= i2c_gpio_probe,
 	.remove		= i2c_gpio_remove,
Signature · 1 line
2.31.1
author maintainer
#4 lore raw

PATCH v4 2/5 i2c: gpio: Add support on ACPI-based system

In reply to Binbin Zhou

Add support for the ACPI-based device registration, so that the driver can be also enabled through ACPI table.

---
 drivers/i2c/busses/i2c-gpio.c | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)
drivers/i2c/busses/i2c-gpio.c +17 -9
index 0e4385a9bcf7..33634d5e4c35 100644
@@ -300,22 +300,23 @@ static inline void i2c_gpio_fault_injector_init(struct platform_device *pdev) {}
 static inline void i2c_gpio_fault_injector_exit(struct platform_device *pdev) {}
 #endif /* CONFIG_I2C_GPIO_FAULT_INJECTOR*/
 
-static void of_i2c_gpio_get_props(struct device_node *np,
-				  struct i2c_gpio_platform_data *pdata)
+/* Get i2c-gpio props from DT or ACPI table */
+static void i2c_gpio_get_props(struct device *dev,
+				struct i2c_gpio_platform_data *pdata)
 {
 	u32 reg;
 
-	of_property_read_u32(np, "i2c-gpio,delay-us", &pdata->udelay);
+	device_property_read_u32(dev, "i2c-gpio,delay-us", &pdata->udelay);
 
-	if (!of_property_read_u32(np, "i2c-gpio,timeout-ms", &reg))
+	if (!device_property_read_u32(dev, "i2c-gpio,timeout-ms", &reg))
 		pdata->timeout = msecs_to_jiffies(reg);
 
 	pdata->sda_is_open_drain =
-		of_property_read_bool(np, "i2c-gpio,sda-open-drain");
+		device_property_read_bool(dev, "i2c-gpio,sda-open-drain");
 	pdata->scl_is_open_drain =
-		of_property_read_bool(np, "i2c-gpio,scl-open-drain");
+		device_property_read_bool(dev, "i2c-gpio,scl-open-drain");
 	pdata->scl_is_output_only =
-		of_property_read_bool(np, "i2c-gpio,scl-output-only");
+		device_property_read_bool(dev, "i2c-gpio,scl-output-only");
 }
 
 static struct gpio_desc *i2c_gpio_get_desc(struct device *dev,
@@ -373,8 +374,8 @@ static int i2c_gpio_probe(struct platform_device *pdev)
 	bit_data = &priv->bit_data;
 	pdata = &priv->pdata;
 
-	if (np) {
-		of_i2c_gpio_get_props(np, pdata);
+	if (dev_fwnode(dev)) {
+		i2c_gpio_get_props(dev, pdata);
 	} else {
 		/*
 		 * If all platform data settings are zero it is OK
@@ -489,10 +490,17 @@ static const struct of_device_id i2c_gpio_dt_ids[] = {
 
 MODULE_DEVICE_TABLE(of, i2c_gpio_dt_ids);
 
+static const struct acpi_device_id i2c_gpio_acpi_match[] = {
+	{ "LOON0005" }, /* LoongArch */
+	{ }
+};
+MODULE_DEVICE_TABLE(acpi, i2c_gpio_acpi_match);
+
 static struct platform_driver i2c_gpio_driver = {
 	.driver		= {
 		.name	= "i2c-gpio",
 		.of_match_table	= i2c_gpio_dt_ids,
+		.acpi_match_table = i2c_gpio_acpi_match,
 	},
 	.probe		= i2c_gpio_probe,
 	.remove		= i2c_gpio_remove,
Signature · 1 line
2.31.1
author maintainer
#6 lore raw

PATCH v4 3/5 dt-bindings: i2c: add bindings for Loongson LS2X I2C

In reply to Binbin Zhou

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

---
 .../bindings/i2c/loongson,ls2x-i2c.yaml       | 49 +++++++++++++++++++
 1 file changed, 49 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/i2c/loongson,ls2x-i2c.yaml
Documentation/devicetree/bindings/i2c/loongson,ls2x-i2c.yaml new file +49 -0
new file mode 100644
index 000000000000..5f36871e272f
@@ -0,0 +1,49 @@
+# 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:
+  - |
+    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.31.1
author maintainer
#8 lore raw

PATCH v4 4/5 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 | 402 ++++++++++++++++++++++++++++++++++
 3 files changed, 414 insertions(+)
 create mode 100644 drivers/i2c/busses/i2c-ls2x.c
drivers/i2c/busses/Kconfig +11 -0
index e50f9603d189..0e342cd5b079 100644
@@ -888,6 +888,17 @@ config I2C_OWL
 	  Say Y here if you want to use the I2C bus controller on
 	  the Actions Semiconductor Owl SoC's.
 
+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_PASEMI
 	tristate "PA Semi SMBus interface"
 	depends on PPC_PASEMI && PCI
drivers/i2c/busses/Makefile +1 -0
index e73cdb1d2b5a..df332ec3c489 100644
@@ -86,6 +86,7 @@ obj-$(CONFIG_I2C_MV64XXX)	+= i2c-mv64xxx.o
 obj-$(CONFIG_I2C_MXS)		+= i2c-mxs.o
 obj-$(CONFIG_I2C_NOMADIK)	+= i2c-nomadik.o
 obj-$(CONFIG_I2C_NPCM)		+= i2c-npcm7xx.o
+obj-$(CONFIG_I2C_LS2X)		+= i2c-ls2x.o
 obj-$(CONFIG_I2C_OCORES)	+= i2c-ocores.o
 obj-$(CONFIG_I2C_OMAP)		+= i2c-omap.o
 obj-$(CONFIG_I2C_OWL)		+= i2c-owl.o
drivers/i2c/busses/i2c-ls2x.c new file +402 -0

402 lines not on this page · raw message

Signature · 1 line
2.31.1
author maintainer
#16 lore raw

PATCH v4 5/5 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 cd8e003d885e..017eb0e36738 100644
@@ -600,6 +600,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.31.1
maintainer
#17 lore raw

Re: [PATCH V4 3/5] dt-bindings: i2c: add bindings for Loongson LS2X I2C

In reply to Binbin Zhou
Quoted 9 lines · Binbin Zhou

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

---
 .../bindings/i2c/loongson,ls2x-i2c.yaml       | 49 +++++++++++++++++++
 1 file changed, 49 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/i2c/loongson,ls2x-i2c.yaml

My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check' on your patch (DT_CHECKER_FLAGS is new in v5.13):

yamllint warnings/errors:

dtschema/dtc warnings/errors:
Error: Documentation/devicetree/bindings/i2c/loongson,ls2x-i2c.example.dts:25.30-31 syntax error FATAL ERROR: Unable to parse input tree
make[1]: *** [scripts/Makefile.lib:406: Documentation/devicetree/bindings/i2c/loongson,ls2x-i2c.example.dtb] Error 1 make[1]: *** Waiting for unfinished jobs....
make: *** [Makefile:1492: dt_binding_check] Error 2

doc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/8503ed054d5b4984b5d6e18891767cace2d36a31.1669777792.git.zhoubinbin@loongson.cn

The base for the series is generally the latest rc1. A different dependency should be noted in *this* patch.

If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:

pip3 install dtschema --upgrade

Please check and re-submit after running the above command yourself. Note that DT_SCHEMA_FILES can be set to your schema file to speed up checking your schema. However, it must be unset to test all examples with your schema.

Reviewed-by on v4 1/5
#2 lore raw

Re: [PATCH V4 1/5] i2c: gpio: Fix potential unused warning for 'i2c_gpio_dt_ids'

In reply to Binbin Zhou
Quoted 3 lines · Binbin Zhou

Dropping a matching #ifdef check along with dropping of_match_ptr() is just a cleanup, while dropping of_match_ptr() that has no corresponding #ifdef fixes an actual warning.

Quoted 35 lines
---
 drivers/i2c/busses/i2c-gpio.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/i2c/busses/i2c-gpio.c +1 -3
index b1985c1667e1..0e4385a9bcf7 100644
@@ -482,19 +482,17 @@ static int i2c_gpio_remove(struct platform_device *pdev)
 	return 0;
 }
 
-#if defined(CONFIG_OF)
 static const struct of_device_id i2c_gpio_dt_ids[] = {
 	{ .compatible = "i2c-gpio", },
 	{ /* sentinel */ }
 };
 
 MODULE_DEVICE_TABLE(of, i2c_gpio_dt_ids);
-#endif
 
 static struct platform_driver i2c_gpio_driver = {
 	.driver		= {
 		.name	= "i2c-gpio",
-		.of_match_table	= of_match_ptr(i2c_gpio_dt_ids),
+		.of_match_table	= i2c_gpio_dt_ids,
 	},
 	.probe		= i2c_gpio_probe,
 	.remove		= i2c_gpio_remove,
Signature · 1 line
2.31.1
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw

Re: [PATCH V4 2/5] i2c: gpio: Add support on ACPI-based system

In reply to Binbin Zhou
Quoted 2 lines · Binbin Zhou

Add support for the ACPI-based device registration, so that the driver can be also enabled through ACPI table.

...

The of.h is left with this patch. Is it still needed?

...

Quoted 1 line

+/* Get i2c-gpio props from DT or ACPI table */

properties

Quoted 1 line

+static void i2c_gpio_get_props(struct device *dev,

_properties

Quoted 1 line
drivers/i2c/busses/i2c-gpio.c +1 -0
+				struct i2c_gpio_platform_data *pdata)
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#9 lore raw

Re: [PATCH V4 4/5] i2c: ls2x: Add driver for Loongson-2K/LS7A I2C controller

In reply to Binbin Zhou
Quoted 2 lines · Binbin Zhou

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

Looks like some of my comments were not addressed. Are you sure you have read the previous reviews carefully?

...

Quoted 4 lines
drivers/i2c/busses/i2c-ls2x.c new file +4 -0
+static int ls2x_i2c_xfer(struct i2c_adapter *adap,
+			struct i2c_msg *msgs, int num)
+{
+	int ret, retry;

drivers/i2c/busses/i2c-ls2x.c line 211

Quoted 10 lines
drivers/i2c/busses/i2c-ls2x.c new file +9 -0
+	struct ls2x_i2c_priv *priv = i2c_get_adapdata(adap);
+
+	for (retry = 0; retry < adap->retries; retry++) {
+		ret = ls2x_i2c_doxfer(adap, msgs, num);
+		if (ret != -EAGAIN)
+			return ret;
+
+		dev_dbg(priv->dev, "Retrying transmission (%d)\n", retry);
 
+		udelay(100);

Why atomic? This long (esp. atomic) delay must be explained.

Quoted 4 lines
drivers/i2c/busses/i2c-ls2x.c new file +4 -0
+	}
+
+	return -EREMOTEIO;
+}

...

drivers/i2c/busses/i2c-ls2x.c line 269

Quoted 7 lines
drivers/i2c/busses/i2c-ls2x.c new file +7 -0
+static void ls2x_i2c_reginit(struct ls2x_i2c_priv *priv)
+{
+	u8 data;
+
+	/* Enable operations about frequency divider register */
+	data = readb(priv->base + I2C_LS2X_CTR);
+	writeb(data & ~0x80, priv->base + I2C_LS2X_CTR);

Magic number.

drivers/i2c/busses/i2c-ls2x.c line 275

Quoted 5 lines
drivers/i2c/busses/i2c-ls2x.c new file +5 -0
+	ls2x_i2c_adjust_bus_speed(priv);
+
+	/* Set to normal I2C operating mode and enable interrupts */
+	data = readb(priv->base + I2C_LS2X_CTR);
+	writeb(data | 0xe0, priv->base + I2C_LS2X_CTR);

Ditto.

Quoted 1 line

+}

...

drivers/i2c/busses/i2c-ls2x.c line 303

Quoted 2 lines
drivers/i2c/busses/i2c-ls2x.c new file +2 -0
+	r = devm_request_irq(dev, irq, ls2x_i2c_irq_handler,
+				IRQF_SHARED, "ls2x-i2c", priv);

Indentation.

Quoted 2 lines
drivers/i2c/busses/i2c-ls2x.c new file +2 -0
+	if (r < 0)
+		return dev_err_probe(dev, r, "Unable to request irq %d\n", irq);

...

drivers/i2c/busses/i2c-ls2x.c line 318

Quoted 1 line
drivers/i2c/busses/i2c-ls2x.c new file +1 -0
+	adap->dev.of_node = pdev->dev.of_node;

Why is this needed?

Quoted 1 line
drivers/i2c/busses/i2c-ls2x.c new file +1 -0
+	device_set_node(&adap->dev, dev_fwnode(dev));

...

drivers/i2c/busses/i2c-ls2x.c line 323

Quoted 2 lines
drivers/i2c/busses/i2c-ls2x.c new file +2 -0
+	/* i2c device drivers may be active on return from add_adapter() */
+	r = i2c_add_adapter(adap);

Why not use devm_ variant of this?

Quoted 2 lines
drivers/i2c/busses/i2c-ls2x.c new file +2 -0
+	if (r)
+		return dev_err_probe(dev, r, "Failure adding adapter\n");

...

drivers/i2c/busses/i2c-ls2x.c line 341

Quoted 4 lines
drivers/i2c/busses/i2c-ls2x.c new file +4 -0
+static int ls2x_i2c_suspend(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct ls2x_i2c_priv *priv = platform_get_drvdata(pdev);

Can't you use dev_get_drvdata() directly? Why?

drivers/i2c/busses/i2c-ls2x.c line 351

Quoted 10 lines
drivers/i2c/busses/i2c-ls2x.c new file +10 -0
+
+	priv->suspended = 1;
+
+	return 0;
+}
+
+static int ls2x_i2c_resume(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct ls2x_i2c_priv *priv = platform_get_drvdata(pdev);

Ditto.

Quoted 5 lines
drivers/i2c/busses/i2c-ls2x.c new file +5 -0
+	priv->suspended = 0;
+	ls2x_i2c_reginit(priv);
+
+	return 0;
+}

...

drivers/i2c/busses/i2c-ls2x.c line 361

Quoted 3 lines
drivers/i2c/busses/i2c-ls2x.c new file +3 -0
+static const struct dev_pm_ops ls2x_i2c_pm_ops = {
+	SET_SYSTEM_SLEEP_PM_OPS(ls2x_i2c_suspend, ls2x_i2c_resume)
+};

Use corresponding DEFINE_ macro.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author maintainer
#10 lore raw

Re: [PATCH V4 4/5] i2c: ls2x: Add driver for Loongson-2K/LS7A I2C controller

Hi Andy:

Quoted 8 lines · Andy Shevchenko
Quoted 2 lines · Binbin Zhou

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

Looks like some of my comments were not addressed. Are you sure you have read the previous reviews carefully?

...

Quoted 14 lines

drivers/i2c/busses/i2c-ls2x.c line 211

Quoted 13 lines
drivers/i2c/busses/i2c-ls2x.c new file +13 -0
+static int ls2x_i2c_xfer(struct i2c_adapter *adap,
+			struct i2c_msg *msgs, int num)
+{
+	int ret, retry;
+	struct ls2x_i2c_priv *priv = i2c_get_adapdata(adap);
+
+	for (retry = 0; retry < adap->retries; retry++) {
+		ret = ls2x_i2c_doxfer(adap, msgs, num);
+		if (ret != -EAGAIN)
+			return ret;
+
+		dev_dbg(priv->dev, "Retrying transmission (%d)\n", retry);
+		udelay(100);

Why atomic? This long (esp. atomic) delay must be explained.

The modification records for this part of the source code are no longer traceable.

Communicating with colleagues offline, I learned that this part of the code first appeared on Linux 2.6.36, which was done to circumvent the problem of probable failure to scan the device for i2c devices on some boards.

How about I add a comment here to explain the reason for this?

Quoted 15 lines
Quoted 4 lines
drivers/i2c/busses/i2c-ls2x.c new file +4 -0
+	}
+
+	return -EREMOTEIO;
+}

...

drivers/i2c/busses/i2c-ls2x.c line 269

Quoted 7 lines
drivers/i2c/busses/i2c-ls2x.c new file +7 -0
+static void ls2x_i2c_reginit(struct ls2x_i2c_priv *priv)
+{
+	u8 data;
+
+	/* Enable operations about frequency divider register */
+	data = readb(priv->base + I2C_LS2X_CTR);
+	writeb(data & ~0x80, priv->base + I2C_LS2X_CTR);

Magic number.

Quoted 6 lines

drivers/i2c/busses/i2c-ls2x.c line 275

Quoted 5 lines
drivers/i2c/busses/i2c-ls2x.c new file +5 -0
+	ls2x_i2c_adjust_bus_speed(priv);
+
+	/* Set to normal I2C operating mode and enable interrupts */
+	data = readb(priv->base + I2C_LS2X_CTR);
+	writeb(data | 0xe0, priv->base + I2C_LS2X_CTR);

Ditto.

OK.. I will use the macro to define the corresponding bit.

@@ -48,6 +48,11 @@
 #define LS2X_SR_TIP            BIT(1)
 #define LS2X_SR_IF             BIT(0)

+/* Control Register Bit */
+#define LS2X_CTR_EN             BIT(7) /* 0: Frequency setting operation */ +#define LS2X_CTR_IEN            BIT(6) /* Enable i2c interrupt */ +#define LS2X_CTR_MST            BIT(5) /* 0 = Slave 1 = Master */ +
 #define LS2X_I2C_MAX_RETRIES   5

 struct ls2x_i2c_priv {
@@ -266,13 +271,14 @@ static void ls2x_i2c_reginit(struct ls2x_i2c_priv *priv)

        /* Enable operations about frequency divider register */ data = readb(priv->base + I2C_LS2X_CTR);
-       writeb(data & ~0x80, priv->base + I2C_LS2X_CTR); +       writeb(data & ~LS2X_CTR_EN, priv->base + I2C_LS2X_CTR);

        ls2x_i2c_adjust_bus_speed(priv);

        /* Set to normal I2C operating mode and enable interrupts */ data = readb(priv->base + I2C_LS2X_CTR);
-       writeb(data | 0xe0, priv->base + I2C_LS2X_CTR);
+       writeb(data | LS2X_CTR_EN | LS2X_CTR_IEN | LS2X_CTR_MST, +                       priv->base + I2C_LS2X_CTR);

Quoted 6 lines
Quoted 1 line

+}

...

drivers/i2c/busses/i2c-ls2x.c line 303

Quoted 2 lines
drivers/i2c/busses/i2c-ls2x.c new file +2 -0
+	r = devm_request_irq(dev, irq, ls2x_i2c_irq_handler,
+				IRQF_SHARED, "ls2x-i2c", priv);

Indentation.

Do you mean  "IRQF_SHARE"  should be aligned to "dev"  ?

Quoted 43 lines
Quoted 2 lines
drivers/i2c/busses/i2c-ls2x.c new file +2 -0
+	if (r < 0)
+		return dev_err_probe(dev, r, "Unable to request irq %d\n", irq);

...

drivers/i2c/busses/i2c-ls2x.c line 318

Quoted 1 line
drivers/i2c/busses/i2c-ls2x.c new file +1 -0
+	adap->dev.of_node = pdev->dev.of_node;

Why is this needed?

Quoted 1 line
drivers/i2c/busses/i2c-ls2x.c new file +1 -0
+	device_set_node(&adap->dev, dev_fwnode(dev));

...

drivers/i2c/busses/i2c-ls2x.c line 323

Quoted 2 lines
drivers/i2c/busses/i2c-ls2x.c new file +2 -0
+	/* i2c device drivers may be active on return from add_adapter() */
+	r = i2c_add_adapter(adap);

Why not use devm_ variant of this?

Quoted 2 lines
drivers/i2c/busses/i2c-ls2x.c new file +2 -0
+	if (r)
+		return dev_err_probe(dev, r, "Failure adding adapter\n");

...

drivers/i2c/busses/i2c-ls2x.c line 341

Quoted 4 lines
drivers/i2c/busses/i2c-ls2x.c new file +4 -0
+static int ls2x_i2c_suspend(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct ls2x_i2c_priv *priv = platform_get_drvdata(pdev);

Can't you use dev_get_drvdata() directly? Why?

drivers/i2c/busses/i2c-ls2x.c line 351

Quoted 10 lines
drivers/i2c/busses/i2c-ls2x.c new file +10 -0
+
+	priv->suspended = 1;
+
+	return 0;
+}
+
+static int ls2x_i2c_resume(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct ls2x_i2c_priv *priv = platform_get_drvdata(pdev);

Ditto.

Quoted 5 lines
drivers/i2c/busses/i2c-ls2x.c new file +5 -0
+	priv->suspended = 0;
+	ls2x_i2c_reginit(priv);
+
+	return 0;
+}

...

Quoted 4 lines

drivers/i2c/busses/i2c-ls2x.c line 361

Quoted 3 lines
drivers/i2c/busses/i2c-ls2x.c new file +3 -0
+static const struct dev_pm_ops ls2x_i2c_pm_ops = {
+	SET_SYSTEM_SLEEP_PM_OPS(ls2x_i2c_suspend, ls2x_i2c_resume)
+};

Use corresponding DEFINE_ macro.

ok.

I will use

"static DEFINE_SIMPLE_DEV_PM_OPS(ls2x_i2c_pm_ops, ls2x_i2c_suspend, ls2x_i2c_resume);"  corresponding to  ".pm     = pm_ptr(&ls2x_i2c_pm_ops),"

Thanks.

Binbin

#11 lore raw

Re: [PATCH V4 4/5] i2c: ls2x: Add driver for Loongson-2K/LS7A I2C controller

Quoted 2 lines · Binbin Zhou
Quoted 1 line · Andy Shevchenko

On Wed, Nov 30, 2022 at 01:56:20PM +0800, Binbin Zhou wrote:

...

Quoted 9 lines
Quoted 8 lines

drivers/i2c/busses/i2c-ls2x.c line 211

Quoted 7 lines
drivers/i2c/busses/i2c-ls2x.c new file +7 -0
+	for (retry = 0; retry < adap->retries; retry++) {
+		ret = ls2x_i2c_doxfer(adap, msgs, num);
+		if (ret != -EAGAIN)
+			return ret;
+
+		dev_dbg(priv->dev, "Retrying transmission (%d)\n", retry);
+		udelay(100);

Why atomic? This long (esp. atomic) delay must be explained.

Quoted 8 lines

The modification records for this part of the source code are no longer traceable.

Communicating with colleagues offline, I learned that this part of the code first appeared on Linux 2.6.36, which was done to circumvent the problem of probable failure to scan the device for i2c devices on some boards.

How about I add a comment here to explain the reason for this?

Yes, that's what we want, and not what you said above. I.o.w. the comment like "reason is unknown" is not accepted.

Can you be more specific about the boards and why do you still need this delay?

And also why is it atomic?

Quoted 1 line
Quoted 1 line
Quoted 1 line
(quoted diff) +1 -0
+	}

...

Quoted 5 lines
Quoted 3 lines

drivers/i2c/busses/i2c-ls2x.c line 303

Quoted 2 lines
drivers/i2c/busses/i2c-ls2x.c new file +2 -0
+	r = devm_request_irq(dev, irq, ls2x_i2c_irq_handler,
+				IRQF_SHARED, "ls2x-i2c", priv);

Indentation.

Do you mean  "IRQF_SHARE"  should be aligned to "dev"  ?

Yes.

...

Quoted 11 lines
Quoted 4 lines

drivers/i2c/busses/i2c-ls2x.c line 361

Quoted 3 lines
drivers/i2c/busses/i2c-ls2x.c new file +3 -0
+static const struct dev_pm_ops ls2x_i2c_pm_ops = {
+	SET_SYSTEM_SLEEP_PM_OPS(ls2x_i2c_suspend, ls2x_i2c_resume)
+};

Use corresponding DEFINE_ macro.

ok.

I will use

"static DEFINE_SIMPLE_DEV_PM_OPS(ls2x_i2c_pm_ops, ls2x_i2c_suspend, ls2x_i2c_resume);"  corresponding to  ".pm     = pm_ptr(&ls2x_i2c_pm_ops),"

Shouldn't be pm_sleep_ptr()?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author maintainer
#12 lore raw

Re: [PATCH V4 4/5] i2c: ls2x: Add driver for Loongson-2K/LS7A I2C controller

In reply to Andy Shevchenko
Quoted 20 lines · Andy Shevchenko
Quoted 2 lines · Binbin Zhou
Quoted 1 line · Andy Shevchenko

On Wed, Nov 30, 2022 at 01:56:20PM +0800, Binbin Zhou wrote:

...

Quoted 15 lines
Quoted 8 lines

drivers/i2c/busses/i2c-ls2x.c line 211

Quoted 7 lines
drivers/i2c/busses/i2c-ls2x.c new file +7 -0
+	for (retry = 0; retry < adap->retries; retry++) {
+		ret = ls2x_i2c_doxfer(adap, msgs, num);
+		if (ret != -EAGAIN)
+			return ret;
+
+		dev_dbg(priv->dev, "Retrying transmission (%d)\n", retry);
+		udelay(100);

Why atomic? This long (esp. atomic) delay must be explained.

The modification records for this part of the source code are no longer traceable.

Communicating with colleagues offline, I learned that this part of the code first appeared on Linux 2.6.36, which was done to circumvent the problem of probable failure to scan the device for i2c devices on some boards.

Quoted 7 lines
Quoted 1 line

How about I add a comment here to explain the reason for this?

Yes, that's what we want, and not what you said above. I.o.w. the comment like "reason is unknown" is not accepted.

Can you be more specific about the boards and why do you still need this delay?

And also why is it atomic?

As we expected, the driver is geared towards Loongosn-2K and Loongson LS7A bridge chips, some of the older hardware still in use has scan failure issues and we expect to keep that part as compatible.

"Atomic" may not be necessary, It is expected to try a few more times when the scan device fails. Also, I think the corresponding part of the s3c2410 may have been referenced in the beginning.

I will try to drop the loop part to do the relevant i2c read/write tests.

Thanks.

Binbin

Quoted 24 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
(quoted diff) +1 -0
+	}

...

Quoted 4 lines
Quoted 3 lines

drivers/i2c/busses/i2c-ls2x.c line 303

Quoted 2 lines
drivers/i2c/busses/i2c-ls2x.c new file +2 -0
+	r = devm_request_irq(dev, irq, ls2x_i2c_irq_handler,
+				IRQF_SHARED, "ls2x-i2c", priv);

Indentation.

Do you mean  "IRQF_SHARE"  should be aligned to "dev"  ?

Yes.

...

Quoted 10 lines
Quoted 4 lines

drivers/i2c/busses/i2c-ls2x.c line 361

Quoted 3 lines
drivers/i2c/busses/i2c-ls2x.c new file +3 -0
+static const struct dev_pm_ops ls2x_i2c_pm_ops = {
+	SET_SYSTEM_SLEEP_PM_OPS(ls2x_i2c_suspend, ls2x_i2c_resume)
+};

Use corresponding DEFINE_ macro.

ok.

I will use

"static DEFINE_SIMPLE_DEV_PM_OPS(ls2x_i2c_pm_ops, ls2x_i2c_suspend, ls2x_i2c_resume);"  corresponding to  ".pm     = pm_ptr(&ls2x_i2c_pm_ops),"

Shouldn't be pm_sleep_ptr()?

#13 lore raw

Re: [PATCH V4 4/5] i2c: ls2x: Add driver for Loongson-2K/LS7A I2C controller

In reply to Binbin Zhou
Quoted 4 lines · Binbin Zhou

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

There are currently two people submitting a driver for this hardware. This is the other driver:

https://lore.kernel.org/all/[email protected]/

Can you guys please decide which one is "better" or combine the two to make a better one?

Thanks,

Wolfram

author maintainer
#14 lore raw

Re: [PATCH V4 4/5] i2c: ls2x: Add driver for Loongson-2K/LS7A I2C controller

Quoted 4 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 1 line

There are currently two people submitting a driver for this hardware. This is the other driver:

https://lore.kernel.org/all/[email protected]/

Can you guys please decide which one is "better" or combine the two to make a better one?

Hi Wolfram:

When Krzysztof found out about this, Yinbo and I had negotiated offline that I would follow up on this series of patchset submissions,

and this was Yinbo's previous response:

https://lore.kernel.org/all/[email protected]/ <https://lore.kernel.org/all/[email protected]/>

Here is my previous response:

https://lore.kernel.org/all/[email protected]/

Thanks.

Binbin

Quoted 5 lines

Thanks,

Wolfram

Applied
#3 lore raw

Re: [PATCH V4 1/5] i2c: gpio: Fix potential unused warning for 'i2c_gpio_dt_ids'

In reply to Binbin Zhou
Quoted 7 lines · Binbin Zhou

Dropping a matching #ifdef check along with dropping of_match_ptr() is just a cleanup, while dropping of_match_ptr() that has no corresponding #ifdef fixes an actual warning.

Applied to for-next, thanks!