Skip to contentSkip to conversation

GPIO-based hotplug i2c bus

PATCH Superseded Svyatoslav Ryhel 4 participants 11 messages Jun 19, 2023 – Jun 21, 2023

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover GPIO-based hotplug i2c bus

ASUS Transformers require this driver for proper work with their dock. Dock is controlled by EC and its presence is detected by a GPIO.

---
Changes in v2:
- adjusted documentation
---

Michał Mirosław (1):
i2c: Add GPIO-based hotplug gate

Svyatoslav Ryhel (1):
dt-bindings: i2c: add binding for i2c-hotplug-gpio

 .../bindings/i2c/i2c-hotplug-gpio.yaml        |  65 +++++
 drivers/i2c/Kconfig                           |  11 +
 drivers/i2c/Makefile                          |   1 +
 drivers/i2c/i2c-hotplug-gpio.c                | 266 ++++++++++++++++++
 4 files changed, 343 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/i2c/i2c-hotplug-gpio.yaml
 create mode 100644 drivers/i2c/i2c-hotplug-gpio.c
Signature · 1 line
2.39.2
#1 lore raw

PATCH v2 1/2 dt-bindings: i2c: add binding for i2c-hotplug-gpio

Document device tree schema which describes hot-pluggable via GPIO i2c bus.

---
 .../bindings/i2c/i2c-hotplug-gpio.yaml        | 65 +++++++++++++++++++
 1 file changed, 65 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/i2c/i2c-hotplug-gpio.yaml
Documentation/devicetree/bindings/i2c/i2c-hotplug-gpio.yaml new file +65 -0
new file mode 100644
index 000000000000..21f2b74ca6c1
@@ -0,0 +1,65 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/i2c/i2c-hotplug-gpio.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: GPIO detected hot-plugged I2C bus
+
+maintainers:
+  - Michał Mirosław <[email protected]>
+
+description:
+  Driver for hot-plugged I2C busses, where some devices on a bus
+  are hot-pluggable and their presence is indicated by GPIO line.
+
+properties:
+  compatible:
+    items:
+      - const: i2c-hotplug-gpio
+
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 0
+
+  interrupts-extended:
+    minItems: 1
+
+  detect-gpios:
+    maxItems: 1
+
+  i2c-parent:
+    maxItems: 1
+
+required:
+  - compatible
+  - '#address-cells'
+  - '#size-cells'
+  - interrupts-extended
+  - detect-gpios
+  - i2c-parent
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    /*
+     * Asus Transformers use I2C hotplug for attachable dock keyboard
+     */
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    i2c-dock {
+        compatible = "i2c-hotplug-gpio";
+
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        interrupts-extended = <&gpio 164 IRQ_TYPE_EDGE_BOTH>;
+        detect-gpios = <&gpio 164 GPIO_ACTIVE_LOW>;
+
+        i2c-parent = <&gen2_i2c>;
+    };
+...
Signature · 1 line
2.39.2
#2 lore raw

Re: [PATCH v2 1/2] dt-bindings: i2c: add binding for i2c-hotplug-gpio

Quoted 4 lines · Svyatoslav Ryhel

Document device tree schema which describes hot-pluggable via GPIO i2c bus.

1. Don't send new version before discussion finishes. v2 after one hour is definitely not enough. Usually one day.

2. Test the patches before sending...

What changed here?

Quoted 14 lines
---
 .../bindings/i2c/i2c-hotplug-gpio.yaml        | 65 +++++++++++++++++++
 1 file changed, 65 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/i2c/i2c-hotplug-gpio.yaml
Documentation/devicetree/bindings/i2c/i2c-hotplug-gpio.yaml new file +3 -0
new file mode 100644
index 000000000000..21f2b74ca6c1
@@ -0,0 +1,65 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---

Documentation/devicetree/bindings/i2c/i2c-hotplug-gpio.yaml line 13

Quoted 10 lines
Documentation/devicetree/bindings/i2c/i2c-hotplug-gpio.yaml new file +10 -0
+$id: http://devicetree.org/schemas/i2c/i2c-hotplug-gpio.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: GPIO detected hot-plugged I2C bus
+
+maintainers:
+  - Michał Mirosław <[email protected]>
+
+description:
+  Driver for hot-plugged I2C busses, where some devices on a bus

"Driver" so SW? Bindings are for hardware, not for drivers.

Documentation/devicetree/bindings/i2c/i2c-hotplug-gpio.yaml line 18

Quoted 5 lines
Documentation/devicetree/bindings/i2c/i2c-hotplug-gpio.yaml new file +5 -0
+  are hot-pluggable and their presence is indicated by GPIO line.
+
+properties:
+  compatible:
+    items:

Drop items.

Documentation/devicetree/bindings/i2c/i2c-hotplug-gpio.yaml line 27

Quoted 9 lines
Documentation/devicetree/bindings/i2c/i2c-hotplug-gpio.yaml new file +9 -0
+      - const: i2c-hotplug-gpio
+
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 0
+
+  interrupts-extended:

I missed last time - this is wrong. Just interrupts.

Documentation/devicetree/bindings/i2c/i2c-hotplug-gpio.yaml line 28

Quoted 1 line
Documentation/devicetree/bindings/i2c/i2c-hotplug-gpio.yaml new file +1 -0
+    minItems: 1

maxItems

Documentation/devicetree/bindings/i2c/i2c-hotplug-gpio.yaml line 34

Quoted 6 lines
Documentation/devicetree/bindings/i2c/i2c-hotplug-gpio.yaml new file +6 -0
+
+  detect-gpios:
+    maxItems: 1
+
+  i2c-parent:
+    maxItems: 1

Discussion from v1 stands - this is a software construct, not a real device.

Documentation/devicetree/bindings/i2c/i2c-hotplug-gpio.yaml line 44

Quoted 10 lines
Documentation/devicetree/bindings/i2c/i2c-hotplug-gpio.yaml new file +10 -0
+
+required:
+  - compatible
+  - '#address-cells'
+  - '#size-cells'
+  - interrupts-extended
+  - detect-gpios
+  - i2c-parent
+
+unevaluatedProperties: false

instead additionalProperties: false

Anyway, don't send v3, before the discussion about the entire concept finishes. You create a software/virtual device, instead of adding these properties to bindings for a real hardware.

Quoted 7 lines
Documentation/devicetree/bindings/i2c/i2c-hotplug-gpio.yaml new file +7 -0
+
+examples:
+  - |
+    /*
+     * Asus Transformers use I2C hotplug for attachable dock keyboard
+     */
+    #include <dt-bindings/gpio/gpio.h>

Documentation/devicetree/bindings/i2c/i2c-hotplug-gpio.yaml line 61

Quoted 10 lines
Documentation/devicetree/bindings/i2c/i2c-hotplug-gpio.yaml new file +10 -0
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    i2c-dock {
+        compatible = "i2c-hotplug-gpio";
+
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        interrupts-extended = <&gpio 164 IRQ_TYPE_EDGE_BOTH>;
+        detect-gpios = <&gpio 164 GPIO_ACTIVE_LOW>;

I don't think you can have both interrupt and GPIO on the same line.

Documentation/devicetree/bindings/i2c/i2c-hotplug-gpio.yaml line 65

Quoted 4 lines
Documentation/devicetree/bindings/i2c/i2c-hotplug-gpio.yaml new file +4 -0
+
+        i2c-parent = <&gen2_i2c>;
+    };
+...

Best regards,
Krzysztof

#3 lore raw

Re: [PATCH v2 1/2] dt-bindings: i2c: add binding for i2c-hotplug-gpio

Quoted 5 lines · Krzysztof Kozlowski
Quoted 4 lines · Svyatoslav Ryhel

Document device tree schema which describes hot-pluggable via GPIO i2c bus.

[...]

Quoted 18 lines
Quoted 6 lines
Documentation/devicetree/bindings/i2c/i2c-hotplug-gpio.yaml new file +3 -0
@@ -0,0 +1,65 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---

Documentation/devicetree/bindings/i2c/i2c-hotplug-gpio.yaml line 13

Quoted 10 lines
Documentation/devicetree/bindings/i2c/i2c-hotplug-gpio.yaml new file +10 -0
+$id: http://devicetree.org/schemas/i2c/i2c-hotplug-gpio.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: GPIO detected hot-plugged I2C bus
+
+maintainers:
+  - Michał Mirosław <[email protected]>
+
+description:
+  Driver for hot-plugged I2C busses, where some devices on a bus

"Driver" so SW? Bindings are for hardware, not for drivers.

[...]

Quoted 7 lines

Documentation/devicetree/bindings/i2c/i2c-hotplug-gpio.yaml line 34

Quoted 5 lines
Documentation/devicetree/bindings/i2c/i2c-hotplug-gpio.yaml new file +5 -0
+  detect-gpios:
+    maxItems: 1
+
+  i2c-parent:
+    maxItems: 1

Discussion from v1 stands - this is a software construct, not a real device.

[...]

Quoted 3 lines

Anyway, don't send v3, before the discussion about the entire concept finishes. You create a software/virtual device, instead of adding these properties to bindings for a real hardware.

Hi,

In this case it's hard for me to tell the difference if this is real or virtual hardware.

The Transformers have a connector that's used for USB, charging or for attaching a keyboard (called a dock; it also has a battery and a touchpad). This connector probably (I don't have the means to verify that) has an I2C bus lines and a "detect" line (pulled low on the dock side) among the pins. I guess there is either no additional chip or a transparent bridge/buffer chip, but nothing that could be controlled by software. For DT this setup could be modelled like an I2C gate or 2-port mux with enable joining two I2C busses (one "closer" to the CPU -- parent).

Quoted 11 lines
Quoted 11 lines
Documentation/devicetree/bindings/i2c/i2c-hotplug-gpio.yaml new file +11 -0
+
+examples:
+  - |
+    /*
+     * Asus Transformers use I2C hotplug for attachable dock keyboard
+     */
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    i2c-dock {
+        compatible = "i2c-hotplug-gpio";
Quoted 8 lines

Documentation/devicetree/bindings/i2c/i2c-hotplug-gpio.yaml line 61

Quoted 6 lines
Documentation/devicetree/bindings/i2c/i2c-hotplug-gpio.yaml new file +6 -0
+
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        interrupts-extended = <&gpio 164 IRQ_TYPE_EDGE_BOTH>;
+        detect-gpios = <&gpio 164 GPIO_ACTIVE_LOW>;

I don't think you can have both interrupt and GPIO on the same line.

This actually works as expected. There are multiple devices (and drivers) that depend on this, e.g. matrix-keypad and gpio-keys.

Best Regards
Michał Mirosław

#4 lore raw

PATCH v2 2/2 i2c: Add GPIO-based hotplug gate

In reply to Svyatoslav Ryhel

From: Michał Mirosław <[email protected]>

Implement driver for hot-plugged I2C busses, where some devices on a bus are hot-pluggable and their presence is indicated by GPIO line.

---
 drivers/i2c/Kconfig            |  11 ++
 drivers/i2c/Makefile           |   1 +
 drivers/i2c/i2c-hotplug-gpio.c | 266 +++++++++++++++++++++++++++++++++
 3 files changed, 278 insertions(+)
 create mode 100644 drivers/i2c/i2c-hotplug-gpio.c
drivers/i2c/Kconfig +11 -0
index 438905e2a1d0..3e3f7675ea4a 100644
@@ -98,6 +98,17 @@ config I2C_SMBUS
 source "drivers/i2c/algos/Kconfig"
 source "drivers/i2c/busses/Kconfig"
 
+config I2C_HOTPLUG_GPIO
+	tristate "Hot-plugged I2C bus detected by GPIO"
+	depends on GPIOLIB
+	depends on OF
+	help
+	  If you say yes to this option, support will be included for
+	  hot-plugging I2C devices with presence detected by GPIO pin value.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called i2c-hotplug-gpio.
+
 config I2C_STUB
 	tristate "I2C/SMBus Test Stub"
 	depends on m
drivers/i2c/Makefile +1 -0
index c1d493dc9bac..9fd44310835a 100644
@@ -14,6 +14,7 @@ obj-$(CONFIG_I2C_SMBUS)		+= i2c-smbus.o
 obj-$(CONFIG_I2C_CHARDEV)	+= i2c-dev.o
 obj-$(CONFIG_I2C_MUX)		+= i2c-mux.o
 obj-y				+= algos/ busses/ muxes/
+obj-$(CONFIG_I2C_HOTPLUG_GPIO)	+= i2c-hotplug-gpio.o
 obj-$(CONFIG_I2C_STUB)		+= i2c-stub.o
 obj-$(CONFIG_I2C_SLAVE_EEPROM)	+= i2c-slave-eeprom.o
 obj-$(CONFIG_I2C_SLAVE_TESTUNIT)	+= i2c-slave-testunit.o
drivers/i2c/i2c-hotplug-gpio.c new file +266 -0

266 lines not on this page · raw message

Signature · 1 line
2.39.2
maintainer
#5 lore raw

Re: [PATCH v2 2/2] i2c: Add GPIO-based hotplug gate

Hi,

Quoted 9 lines · Svyatoslav Ryhel

From: Michał Mirosław <[email protected]>

Implement driver for hot-plugged I2C busses, where some devices on a bus are hot-pluggable and their presence is indicated by GPIO line.

Quoted 6 lines
---
 drivers/i2c/Kconfig            |  11 ++
 drivers/i2c/Makefile           |   1 +
 drivers/i2c/i2c-hotplug-gpio.c | 266 +++++++++++++++++++++++++++++++++
 3 files changed, 278 insertions(+)
 create mode 100644 drivers/i2c/i2c-hotplug-gpio.c

without going through the code I am missing the big picture here.

What is this actually doing? Is this a new bus driver support? Is this a feature to existing drivers? Is the GPIO an irq line for signalling hoplugging and can be used by any driver or just this one?

Without further discussing technicalities, can you please explain better and more in detail what is the scope of this patch, why there is a need for such a patch, how this new driver/feature has been implemented and finally how it can be used.

This would help a lot so that I know already beforehand what I am going to read without figuring it out.

Thanks,
Andi

PS Please notice that my set of questions is even longer than your commit log :)

#6 lore raw

Re: [PATCH v2 2/2] i2c: Add GPIO-based hotplug gate

ср, 21 черв. 2023 р. о 13:32 Andi Shyti <[email protected]> пише:

Quoted 20 lines

Hi,

Quoted 9 lines · Svyatoslav Ryhel

From: Michał Mirosław <[email protected]>

Implement driver for hot-plugged I2C busses, where some devices on a bus are hot-pluggable and their presence is indicated by GPIO line.

Quoted 6 lines
---
 drivers/i2c/Kconfig            |  11 ++
 drivers/i2c/Makefile           |   1 +
 drivers/i2c/i2c-hotplug-gpio.c | 266 +++++++++++++++++++++++++++++++++
 3 files changed, 278 insertions(+)
 create mode 100644 drivers/i2c/i2c-hotplug-gpio.c
Quoted 3 lines

without going through the code I am missing the big picture here.

What is this actually doing?

Basically it duplicates the parent i2c bus once detection GPIO triggers and probes all hot-pluggable devices which are connected to it. Once GPIO triggers detach signal all hot-pluggable devices are unprobed and bus removed.

Quoted 1 line

Is this a new bus driver support?

Most likely not.

Quoted 1 line

Is this a feature to existing drivers?

Yes, it is more like i2c mux

Quoted 3 lines

Is the GPIO an irq line for signalling hoplugging and can be used by any driver or just this one?

It can be shared if necessary but usually all hot-pluggable devices are gathered in one container and are plugged simultaneously.

Quoted 4 lines

Without further discussing technicalities, can you please explain better and more in detail what is the scope of this patch, why there is a need for such a patch, how this new driver/feature has been implemented and finally how it can be used.

This patch is a predecessor of a possible larger patchset which should bring support for a asus-ec, a i2c mfd device programmed by Asus for their Transformers tablet line.

This is Michał Mirosław, original author quote about this driver:
"The Transformers have a connector that's used for USB, charging or for attaching a keyboard (called a dock; it also has a battery and a touchpad). This connector probably (I don't have the means to verify that) has an I2C bus lines and a "detect" line (pulled low on the dock side) among the pins. I guess there is either no additional chip or a transparent bridge/buffer chip, but nothing that could be controlled by software. For DT this setup could be modelled like an I2C gate or 2-port mux with enable joining two I2C busses (one "closer" to the CPU -- parent)."

Similar approach is used in Microsoft Surface RT for attachable Type Cover.

Quoted 8 lines

This would help a lot so that I know already beforehand what I am going to read without figuring it out.

Thanks,
Andi

PS Please notice that my set of questions is even longer than your commit log :)

#7 lore raw
In reply to Svyatoslav Ryhel
Quoted 6 lines · Svyatoslav Ryhel

ASUS Transformers require this driver for proper work with their dock. Dock is controlled by EC and its presence is detected by a GPIO.

---
Changes in v2:
- adjusted documentation

This is too generic. Everything can be adjustment. Be precise what you did here. What changed?

Best regards,
Krzysztof

#8 lore raw

пн, 19 черв. 2023 р. о 18:49 Krzysztof Kozlowski
<[email protected]> пише:

Quoted 12 lines · Svyatoslav Ryhel
Quoted 6 lines

ASUS Transformers require this driver for proper work with their dock. Dock is controlled by EC and its presence is detected by a GPIO.

---
Changes in v2:
- adjusted documentation

This is too generic. Everything can be adjustment. Be precise what you did here. What changed?

Everything that you asked for.

Quoted 3 lines

Best regards,
Krzysztof

#9 lore raw
Quoted 11 lines · Svyatoslav Ryhel

пн, 19 черв. 2023 р. о 18:49 Krzysztof Kozlowski
<[email protected]> пише:

Quoted 9 lines · Svyatoslav Ryhel
Quoted 6 lines

ASUS Transformers require this driver for proper work with their dock. Dock is controlled by EC and its presence is detected by a GPIO.

---
Changes in v2:
- adjusted documentation

Quoted 5 lines
Quoted 3 lines

This is too generic. Everything can be adjustment. Be precise what you did here. What changed?

Everything that you asked for.

And how other people can know it? That's not a proper changelog.

What changed? If you are going to ignore writing proper changelogs, I am going to ignore patches.

Best regards,
Krzysztof

maintainer
#10 lore raw
In reply to Svyatoslav Ryhel

Hi Svyatoslav,

Quoted 11 lines · Svyatoslav Ryhel

пн, 19 черв. 2023 р. о 18:49 Krzysztof Kozlowski
<[email protected]> пише:

Quoted 9 lines · Svyatoslav Ryhel
Quoted 6 lines

ASUS Transformers require this driver for proper work with their dock. Dock is controlled by EC and its presence is detected by a GPIO.

---
Changes in v2:
- adjusted documentation

Quoted 5 lines
Quoted 3 lines

This is too generic. Everything can be adjustment. Be precise what you did here. What changed?

Everything that you asked for.

please list all the changes you made trying to be as more specific as you can.

You make life to reviewers easier.

Thanks,
Andi