Path: blob/master/Documentation/devicetree/bindings/i2c/i2c-arb-gpio-challenge.yaml
26307 views
# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause1%YAML 1.22---3$id: http://devicetree.org/schemas/i2c/i2c-arb-gpio-challenge.yaml#4$schema: http://devicetree.org/meta-schemas/core.yaml#56title: GPIO-based I2C Arbitration Using a Challenge & Response Mechanism78maintainers:9- Doug Anderson <dianders@chromium.org>10- Peter Rosin <peda@axentia.se>1112description: |13This uses GPIO lines and a challenge & response mechanism to arbitrate who is14the master of an I2C bus in a multimaster situation.1516In many cases using GPIOs to arbitrate is not needed and a design can use the17standard I2C multi-master rules. Using GPIOs is generally useful in the case18where there is a device on the bus that has errata and/or bugs that makes19standard multimaster mode not feasible.2021Note that this scheme works well enough but has some downsides:22* It is nonstandard (not using standard I2C multimaster)23* Having two masters on a bus in general makes it relatively hard to debug24problems (hard to tell if i2c issues were caused by one master, another,25or some device on the bus).2627Algorithm:28All masters on the bus have a 'bus claim' line which is an output that the29others can see. These are all active low with pull-ups enabled. We'll30describe these lines as:31* OUR_CLAIM: output from us signaling to other hosts that we want the bus32* THEIR_CLAIMS: output from others signaling that they want the bus3334The basic algorithm is to assert your line when you want the bus, then make35sure that the other side doesn't want it also. A detailed explanation is36best done with an example.3738Let's say we want to claim the bus. We:391. Assert OUR_CLAIM.402. Waits a little bit for the other sides to notice (slew time, say 1041microseconds).423. Check THEIR_CLAIMS. If none are asserted then the we have the bus and we43are done.444. Otherwise, wait for a few milliseconds and see if THEIR_CLAIMS are released.455. If not, back off, release the claim and wait for a few more milliseconds.466. Go back to 1 (until retry time has expired).4748properties:49compatible:50const: i2c-arb-gpio-challenge5152i2c-parent:53$ref: /schemas/types.yaml#/definitions/phandle54description:55The I2C bus that this multiplexer's master-side port is connected to.5657our-claim-gpios:58maxItems: 159description:60The GPIO that we use to claim the bus.6162slew-delay-us:63default: 1064description:65Time to wait for a GPIO to go high.6667their-claim-gpios:68minItems: 169maxItems: 870description:71The GPIOs that the other sides use to claim the bus. Note that some72implementations may only support a single other master.7374wait-free-us:75default: 5000076description:77We'll give up after this many microseconds.7879wait-retry-us:80default: 300081description:82We'll attempt another claim after this many microseconds.8384i2c-arb:85type: object86$ref: /schemas/i2c/i2c-controller.yaml87unevaluatedProperties: false88description:89I2C arbitration bus node.9091required:92- compatible93- i2c-arb94- our-claim-gpios95- their-claim-gpios9697additionalProperties: false9899examples:100- |101#include <dt-bindings/gpio/gpio.h>102#include <dt-bindings/interrupt-controller/irq.h>103104i2c-arbitrator {105compatible = "i2c-arb-gpio-challenge";106i2c-parent = <&i2c_4>;107108our-claim-gpios = <&gpf0 3 GPIO_ACTIVE_LOW>;109their-claim-gpios = <&gpe0 4 GPIO_ACTIVE_LOW>;110slew-delay-us = <10>;111wait-retry-us = <3000>;112wait-free-us = <50000>;113114i2c-arb {115#address-cells = <1>;116#size-cells = <0>;117118sbs-battery@b {119compatible = "sbs,sbs-battery";120reg = <0xb>;121sbs,poll-retry-count = <1>;122};123124embedded-controller@1e {125compatible = "google,cros-ec-i2c";126reg = <0x1e>;127interrupts = <6 IRQ_TYPE_LEVEL_HIGH>;128interrupt-parent = <&gpx1>;129pinctrl-names = "default";130pinctrl-0 = <&ec_irq>;131wakeup-source;132};133};134};135136137