Skip to contentSkip to conversation

ARM: Add GXP I2C Support

PATCH Superseded [email protected] 4 participants 11 messages Jan 20, 2023 – Jan 23, 2023

Subsystems (4)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

v3 cover ARM: Add GXP I2C Support

From: Nick Hawkins <[email protected]>

The GXP SoC supports 10 I2C engines. Each I2C engine is completely independent and can function both as an I2C master and I2C slave. The I2C master can operate in a multi master environment. The engines support a scalable speed from 8kHZ to 1.5 Mhz.

---

Changes since v2:
*Disable IRQ on a device remove
*Remove use of I2C_CLASS_DEPRECATED
*Use i2c_parse_fw_timings instead of of_property_read_u32 *Remove redundant dev_err_probe as platform_get_irq already has one *Used __iomem instead of res->start to find physical address *Use BIT in gxp_i2c_irq_handler
*Made value u8 instead of u16 for u8 read
*Provided a better description of Phandle in yaml
Changes since v1:
*Removed yaml documentation of hpe,gxp-sysreg as it has been
applied to syscon.yaml
*Made i2cX a generic node name i2c in dts file
*Added status field to the dtsi and the dts for i2c bus *Removed unnecessary size-cells and address-cells from yaml *Removed phandle from hpe,sysreg-phandle
*Changed hpe,i2c-max-bus-freq to clock-frequency *Removed rogue tab in structure definition
*Removed use of __iomem *base local variables as it was
unnecessary
*Switched #if IS_ENABLED() -> if (IS_ENABLED()) inside
functions
*Removed use of pr_* functions
*Removed informational prints in register and unregister
functions
*Removed print from interrupt handler
*Removed informational prints from probe function *Switched dev_err -> dev_err_probe in probe function *Used the respective helper for mapping the resource to
__iomem

Nick Hawkins (5):
i2c: hpe: Add GXP SoC I2C Controller
dt-bindings: i2c: Add hpe,gxp-i2c
ARM: dts: hpe: Add I2C Topology
ARM: multi_v7_defconfig: add gxp i2c module
MAINTAINERS: Add HPE GXP I2C Support

 .../devicetree/bindings/i2c/hpe,gxp-i2c.yaml  |  57 ++
 MAINTAINERS                                   |   2 +
 arch/arm/boot/dts/hpe-bmc-dl360gen10.dts      | 109 ++++
 arch/arm/boot/dts/hpe-gxp.dtsi                | 125 ++++
 arch/arm/configs/multi_v7_defconfig           |   1 +
 drivers/i2c/busses/Kconfig                    |   7 +
 drivers/i2c/busses/Makefile                   |   1 +
 drivers/i2c/busses/i2c-gxp.c                  | 602 ++++++++++++++++++
 8 files changed, 904 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/i2c/hpe,gxp-i2c.yaml
 create mode 100644 drivers/i2c/busses/i2c-gxp.c
Signature · 1 line
2.17.1
author maintainer
#1 lore raw

PATCH v3 1/5 i2c: hpe: Add GXP SoC I2C Controller

From: Nick Hawkins <[email protected]>

The GXP SoC supports 10 I2C engines. Each I2C engine is completely independent and can function both as an I2C master and I2C slave. The I2C master can operate in a multi master environment. The engines support a scalable speed from 8kHZ to 1.5 Mhz.

---

v3:
*Disable IRQ on device remove
*Remove use of I2C_CLASS_DEPRECATED
*Use i2c_parse_fw_timings instead of of_property_read_u32 *Remove redundant dev_err_probe as platform_get_irq already has one *Used __iomem instead of res->start to find physical address *Use BIT in gxp_i2c_irq_handler
*Made value u8 instead of u16
v2:
*Removed rogue tab in structure
*Removed use of __iomem base local variables as it was unnecessary *Switched #if IS_ENABLED() -> if (IS_ENABLED()) inside functions *Removed use of pr_* functions
*Removed informational prints in register and unregister functions *Removed print from interrupt handler
*No informational prints in probe function
*Switched dev_err for dev_err_probe in probe function *Use respective helper for mapping the resource to __iomem

---
 drivers/i2c/busses/Kconfig   |   7 +
 drivers/i2c/busses/Makefile  |   1 +
 drivers/i2c/busses/i2c-gxp.c | 602 +++++++++++++++++++++++++++++++++++
 3 files changed, 610 insertions(+)
 create mode 100644 drivers/i2c/busses/i2c-gxp.c
drivers/i2c/busses/Kconfig +7 -0
index e50f9603d189..8b3951e0ca5c 100644
@@ -1457,4 +1457,11 @@ config I2C_VIRTIO
           This driver can also be built as a module. If so, the module
           will be called i2c-virtio.
 
+config I2C_GXP
+	tristate "GXP I2C Interface"
+	depends on ARCH_HPE_GXP || COMPILE_TEST
+	help
+	  This enables support for GXP I2C interface. The I2C engines can be
+	  either I2C master or I2C slaves.
+
 endmenu
drivers/i2c/busses/Makefile +1 -0
index e73cdb1d2b5a..dcc96eab6d68 100644
@@ -127,6 +127,7 @@ obj-$(CONFIG_I2C_THUNDERX)	+= i2c-thunderx.o
 obj-$(CONFIG_I2C_XILINX)	+= i2c-xiic.o
 obj-$(CONFIG_I2C_XLP9XX)	+= i2c-xlp9xx.o
 obj-$(CONFIG_I2C_RCAR)		+= i2c-rcar.o
+obj-$(CONFIG_I2C_GXP)		+= i2c-gxp.o
 
 # External I2C/SMBus adapter drivers
 obj-$(CONFIG_I2C_DIOLAN_U2C)	+= i2c-diolan-u2c.o
drivers/i2c/busses/i2c-gxp.c new file +602 -0

602 lines not on this page · raw message

Signature · 1 line
2.17.1
#2 lore raw

Re: [PATCH v3 1/5] i2c: hpe: Add GXP SoC I2C Controller

I love your patch! Perhaps something to improve:

Hi,

I love your patch! Perhaps something to improve:

[auto build test WARNING on wsa/i2c/for-next]
[also build test WARNING on robh/for-next linus/master v6.2-rc4 next-20230120] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/nick-hawkins-hpe-com/i2c-hpe-Add-GXP-SoC-I2C-Controller/20230121-030628
base:   https://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git i2c/for-next
patch link:    https://lore.kernel.org/r/20230120190159.23459-2-nick.hawkins%40hpe.com
patch subject: [PATCH v3 1/5] i2c: hpe: Add GXP SoC I2C Controller
config: sparc-allyesconfig (https://download.01.org/0day-ci/archive/20230121/[email protected]/config)
compiler: sparc64-linux-gcc (GCC) 12.1.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/944feebf5cf838fc72fae192e832e5fc96d1cad9
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review nick-hawkins-hpe-com/i2c-hpe-Add-GXP-SoC-I2C-Controller/20230121-030628 git checkout 944feebf5cf838fc72fae192e832e5fc96d1cad9
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=sparc olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=sparc SHELL=/bin/bash drivers/i2c/busses/

If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot <[email protected]>

All warnings (new ones prefixed by >>):

drivers/i2c/busses/i2c-gxp.c: In function 'gxp_i2c_probe':

>> drivers/i2c/busses/i2c-gxp.c:533:28: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
     533 |         drvdata->engine = ((u32)drvdata->base & 0xf00) >> 8;
         |                            ^

vim +533 drivers/i2c/busses/i2c-gxp.c

499
500 static int gxp_i2c_probe(struct platform_device *pdev)
501 {
502 struct gxp_i2c_drvdata *drvdata;
503 int rc;
504 struct i2c_adapter *adapter;
505
506 if (!i2c_global_init_done) {
507 i2cg_map = syscon_regmap_lookup_by_phandle(pdev->dev.of_node,
508 "hpe,sysreg");
509 if (IS_ERR(i2cg_map)) {
510 return dev_err_probe(&pdev->dev, IS_ERR(i2cg_map),
511 "failed to map i2cg_handle\n");
512 }
513
514 /* Disable interrupt */
515 regmap_update_bits(i2cg_map, GXP_I2CINTEN, 0x00000FFF, 0);
516 i2c_global_init_done = true;
517 }
518
519 drvdata = devm_kzalloc(&pdev->dev, sizeof(*drvdata),
520 GFP_KERNEL);
521 if (!drvdata)
522 return -ENOMEM;
523
524 platform_set_drvdata(pdev, drvdata);
525 drvdata->dev = &pdev->dev;
526 init_completion(&drvdata->completion);
527
528 drvdata->base = devm_platform_ioremap_resource(pdev, 0);
529 if (IS_ERR(drvdata->base))
530 return PTR_ERR(drvdata->base);
531
532 /* Use physical memory address to determine which I2C engine this is. */

 > 533		drvdata->engine = ((u32)drvdata->base & 0xf00) >> 8;

534
535 if (drvdata->engine >= GXP_MAX_I2C_ENGINE) {
536 return dev_err_probe(&pdev->dev, -EINVAL, "i2c engine% is unsupported\n",
537 drvdata->engine);
538 }
539
540 rc = platform_get_irq(pdev, 0);
541 if (rc < 0)
542 return rc;
543
544 drvdata->irq = rc;
545 rc = devm_request_irq(&pdev->dev, drvdata->irq, gxp_i2c_irq_handler,
546 IRQF_SHARED, gxp_i2c_name[drvdata->engine], drvdata);
547 if (rc < 0)
548 return dev_err_probe(&pdev->dev, rc, "irq request failed\n");
549
550 i2c_parse_fw_timings(&pdev->dev, &drvdata->t, true);
551
552 gxp_i2c_init(drvdata);
553
554 /* Enable interrupt */
555 regmap_update_bits(i2cg_map, GXP_I2CINTEN, BIT(drvdata->engine),
556 BIT(drvdata->engine));
557
558 adapter = &drvdata->adapter;
559 i2c_set_adapdata(adapter, drvdata);
560
561 adapter->owner = THIS_MODULE;
562 strscpy(adapter->name, "HPE GXP I2C adapter", sizeof(adapter->name));
563 adapter->algo = &gxp_i2c_algo;
564 adapter->dev.parent = &pdev->dev;
565 adapter->dev.of_node = pdev->dev.of_node;
566
567 rc = i2c_add_adapter(adapter);
568 if (rc)
569 return dev_err_probe(&pdev->dev, rc, "i2c add adapter failed\n");
570
571 return 0;
572 }
573

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests
#3 lore raw

Re: [PATCH v3 1/5] i2c: hpe: Add GXP SoC I2C Controller

In reply to [email protected]

drivers/i2c/busses/i2c-gxp.c line 578

Quoted 8 lines · On Fri, 20 Jan 2023 at 19:04, <[email protected]> wrote:

From: Nick Hawkins <[email protected]>

drivers/i2c/busses/i2c-gxp.c new file +5 -0
+static int gxp_i2c_remove(struct platform_device *pdev)
+{
+       struct gxp_i2c_drvdata *drvdata = platform_get_drvdata(pdev);
+
+       disable_irq(drvdata->irq);

The i2c core calls disable_irq for us (see i2c_device_shutdown) so you don't need that here.

In my review I wondered if you needed to do something like this:

+ regmap_update_bits(i2cg_map, GXP_I2CINTEN, 0x00000FFF, 0);

Quoted 5 lines
drivers/i2c/busses/i2c-gxp.c new file +5 -0
+       i2c_del_adapter(&drvdata->adapter);
+
+       return 0;
+}
+
author maintainer
#4 lore raw

Re: [PATCH v3 1/5] i2c: hpe: Add GXP SoC I2C Controller

Quoted 9 lines

The i2c core calls disable_irq for us (see i2c_device_shutdown) so you don't need that here.

In my review I wondered if you needed to do something like this:

+ regmap_update_bits(i2cg_map, GXP_I2CINTEN, 0x00000FFF, 0);

Thank you for pointing this out. I will correct this for the next patch set.

-Nick Hawkins

author maintainer
#5 lore raw

PATCH v3 2/5 dt-bindings: i2c: Add hpe,gxp-i2c

In reply to [email protected]

From: Nick Hawkins <[email protected]>

Document compatibility string to support I2C controller in GXP.

---

v3:
*Provide better description with use of Phandle
v2:
*Removed uneccessary size-cells and address-cells *Removed phandle from hpe,sysreg-phandle *Changed hpe,i2c-max-bus-freq to clock-frequency

---
 .../devicetree/bindings/i2c/hpe,gxp-i2c.yaml  | 57 +++++++++++++++++++
 1 file changed, 57 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/i2c/hpe,gxp-i2c.yaml
Documentation/devicetree/bindings/i2c/hpe,gxp-i2c.yaml new file +57 -0
new file mode 100644
index 000000000000..63bc69e92d0e
@@ -0,0 +1,57 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/i2c/hpe,gxp-i2c.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: HPE GXP SoC I2C Controller
+
+maintainers:
+  - Nick Hawkins <[email protected]>
+
+allOf:
+  - $ref: /schemas/i2c/i2c-controller.yaml#
+
+properties:
+  compatible:
+    const: hpe,gxp-i2c
+
+  interrupts:
+    maxItems: 1
+
+  reg:
+    maxItems: 1
+
+  clock-frequency:
+    default: 100000
+
+  hpe,sysreg:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description:
+      Phandle to a global status and enable registers shared
+      between each I2C controller instance. Each bit of the
+      registers represents an individual I2C engine.
+
+required:
+  - compatible
+  - reg
+  - interrupts
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    i2c@2600 {
+        compatible = "hpe,gxp-i2c";
+        reg = <0x2500 0x70>;
+        interrupts = <9>;
+        #address-cells = <1>;
+        #size-cells = <0>;
+        hpe,sysreg = <&sysreg_system_controller>;
+        clock-frequency = <10000>;
+
+        eeprom@50 {
+            compatible = "atmel,24c128";
+            reg = <0x50>;
+        };
+    };
Signature · 1 line
2.17.1
#6 lore raw

Re: [PATCH v3 2/5] dt-bindings: i2c: Add hpe,gxp-i2c

Quoted 49 lines · On 20/01/2023 20:01, [email protected] wrote:

From: Nick Hawkins <[email protected]>

Document compatibility string to support I2C controller in GXP.

---

v3:
*Provide better description with use of Phandle
v2:
*Removed uneccessary size-cells and address-cells *Removed phandle from hpe,sysreg-phandle *Changed hpe,i2c-max-bus-freq to clock-frequency

---
 .../devicetree/bindings/i2c/hpe,gxp-i2c.yaml  | 57 +++++++++++++++++++
 1 file changed, 57 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/i2c/hpe,gxp-i2c.yaml
Documentation/devicetree/bindings/i2c/hpe,gxp-i2c.yaml new file +23 -0
new file mode 100644
index 000000000000..63bc69e92d0e
@@ -0,0 +1,57 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/i2c/hpe,gxp-i2c.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: HPE GXP SoC I2C Controller
+
+maintainers:
+  - Nick Hawkins <[email protected]>
+
+allOf:
+  - $ref: /schemas/i2c/i2c-controller.yaml#
+
+properties:
+  compatible:
+    const: hpe,gxp-i2c
+
+  interrupts:
+    maxItems: 1
+
+  reg:
+    maxItems: 1

Documentation/devicetree/bindings/i2c/hpe,gxp-i2c.yaml line 33

Quoted 10 lines
Documentation/devicetree/bindings/i2c/hpe,gxp-i2c.yaml new file +10 -0
+
+  clock-frequency:
+    default: 100000
+
+  hpe,sysreg:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description:
+      Phandle to a global status and enable registers shared
+      between each I2C controller instance. Each bit of the
+      registers represents an individual I2C engine.

But what is the purpose? What is it doing? Why I2C controller needs it?

Documentation/devicetree/bindings/i2c/hpe,gxp-i2c.yaml line 38

Quoted 5 lines
Documentation/devicetree/bindings/i2c/hpe,gxp-i2c.yaml new file +5 -0
+
+required:
+  - compatible
+  - reg
+  - interrupts

Keep the same order as in properties:

Best regards,
Krzysztof

author maintainer
#7 lore raw

Re: [PATCH v3 2/5] dt-bindings: i2c: Add hpe,gxp-i2c

Quoted 9 lines
Quoted 6 lines

+ hpe,sysreg:
+ $ref: /schemas/types.yaml#/definitions/phandle
+ description:
+ Phandle to a global status and enable registers shared
+ between each I2C controller instance. Each bit of the
+ registers represents an individual I2C engine.

But what is the purpose? What is it doing? Why I2C controller needs it?

Here is an updated to describe the registers' purpose, and function.

description:
Phandle to the global status and enable interrupt registers shared between each I2C engine controller instance. It enables the I2C engine controller to act as both a master or slave by being able to arm and respond to interrupts from its engine. Each bit in the registers represent the respective bit position.

Thank you for your feedback,

-Nick Hawkins

author maintainer
#8 lore raw

PATCH v3 3/5 ARM: dts: hpe: Add I2C Topology

In reply to [email protected]

From: Nick Hawkins <[email protected]>

Add 9 I2C Engines, 2 MUXs, and a EEPROM to the device tree.

---

v3:
*No change
v2:
*Made i2cX a generic node name i2c in the dts
*Added status field to dtsi and dts for i2c bus

---
 arch/arm/boot/dts/hpe-bmc-dl360gen10.dts | 109 ++++++++++++++++++++
 arch/arm/boot/dts/hpe-gxp.dtsi           | 125 +++++++++++++++++++++++
 2 files changed, 234 insertions(+)
arch/arm/boot/dts/hpe-bmc-dl360gen10.dts +109 -0
index 3a7382ce40ef..1f2547fe9ae3 100644
@@ -23,4 +23,113 @@
 		device_type = "memory";
 		reg = <0x40000000 0x20000000>;
 	};
+
+	i2cmux@4 {
+		compatible = "i2c-mux-reg";
+		i2c-parent = <&i2c4>;
+		reg = <0xd1000074 0x1>;
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		i2c@1 {
+			reg = <1>;
+			#address-cells = <1>;
+			#size-cells = <0>;
+		};
+
+		i2c@3 {
+			reg = <3>;
+			#address-cells = <1>;
+			#size-cells = <0>;
+		};
+
+		i2c@4 {
+			reg = <4>;
+			#address-cells = <1>;
+			#size-cells = <0>;
+		};
+	};
+
+	i2cmux@6 {
+		compatible = "i2c-mux-reg";
+		i2c-parent = <&i2c6>;
+		reg = <0xd1000076 0x1>;
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		i2c@1 {
+			reg = <1>;
+			#address-cells = <1>;
+			#size-cells = <0>;
+		};
+
+		i2c@2 {
+			reg = <2>;
+			#address-cells = <1>;
+			#size-cells = <0>;
+		};
+
+		i2c@3 {
+			reg = <3>;
+			#address-cells = <1>;
+			#size-cells = <0>;
+		};
+
+		i2c@4 {
+			reg = <4>;
+			#address-cells = <1>;
+			#size-cells = <0>;
+		};
+
+		i2c@5 {
+			reg = <5>;
+			#address-cells = <1>;
+			#size-cells = <0>;
+		};
+	};
+};
+
+&i2c0 {
+	status = "okay";
+};
+
+&i2c1 {
+	status = "okay";
+};
+
+&i2c2 {
+	status = "okay";
+	eeprom@50 {
+		compatible = "atmel,24c02";
+		pagesize = <8>;
+		reg = <0x50>;
+	};
+};
+
+&i2c3 {
+	status = "okay";
+};
+
+&i2c4 {
+	status = "okay";
+};
+
+&i2c5 {
+	status = "okay";
+};
+
+&i2c6 {
+	status = "okay";
+};
+
+&i2c7 {
+	status = "okay";
+};
+
+&i2c8 {
+	status = "okay";
+};
+
+&i2c9 {
+	status = "okay";
 };
arch/arm/boot/dts/hpe-gxp.dtsi +125 -0

131 lines not on this page · raw message

Signature · 1 line
2.17.1
author maintainer
#9 lore raw

PATCH v3 4/5 ARM: multi_v7_defconfig: add gxp i2c module

In reply to [email protected]

From: Nick Hawkins <[email protected]>

Add the CONFIG_I2C_GXP symbol to enable the GXP SoC I2C capabilities.

---

v3:
*No change
v2:
*No change

---
 arch/arm/configs/multi_v7_defconfig | 1 +
 1 file changed, 1 insertion(+)
arch/arm/configs/multi_v7_defconfig +1 -0
index b61b2e3d116b..8a19b1dc10d0 100644
@@ -411,6 +411,7 @@ CONFIG_I2C_DAVINCI=y
 CONFIG_I2C_DESIGNWARE_PLATFORM=y
 CONFIG_I2C_DIGICOLOR=m
 CONFIG_I2C_EMEV2=m
+CONFIG_I2C_GXP=m
 CONFIG_I2C_IMX=y
 CONFIG_I2C_MESON=y
 CONFIG_I2C_MV64XXX=y
Signature · 1 line
2.17.1
author maintainer
#10 lore raw

PATCH v3 5/5 MAINTAINERS: Add HPE GXP I2C Support

In reply to [email protected]

From: Nick Hawkins <[email protected]>

Add the I2C controller source and bindings.

---

v3:
*No change
v2:
*No change

---
 MAINTAINERS | 2 ++
 1 file changed, 2 insertions(+)
MAINTAINERS +2 -0
index 1daadaa4d48b..d671a8b6968e 100644
@@ -2217,12 +2217,14 @@ M:	Jean-Marie Verdun <[email protected]>
 M:	Nick Hawkins <[email protected]>
 S:	Maintained
 F:	Documentation/devicetree/bindings/arm/hpe,gxp.yaml
+F:	Documentation/devicetree/bindings/i2c/hpe,gxp-i2c.yaml
 F:	Documentation/devicetree/bindings/spi/hpe,gxp-spifi.yaml
 F:	Documentation/devicetree/bindings/timer/hpe,gxp-timer.yaml
 F:	arch/arm/boot/dts/hpe-bmc*
 F:	arch/arm/boot/dts/hpe-gxp*
 F:	arch/arm/mach-hpe/
 F:	drivers/clocksource/timer-gxp.c
+F:	drivers/i2c/busses/i2c-gxp.c
 F:	drivers/spi/spi-gxp.c
 F:	drivers/watchdog/gxp-wdt.c
 
Signature · 1 line
2.17.1