# GPIO-based I2C Arbitration Using a Challenge & Response Mechanism

_Peios Kernel / Hardware and drivers / Device-tree binding reference / I2C bindings_

> Device-tree binding reference for GPIO-based I2C Arbitration Using a Challenge & Response Mechanism.

<!-- SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause -->


<a id="dt-root"></a>

**Schema identifier (<code>&#36;id</code>):** <span id="dt-09f478f44eb202ea573e"><code>&#34;http&#58;&#47;&#47;devicetree&#46;org&#47;schemas&#47;i2c&#47;i2c&#45;arb&#45;gpio&#45;challenge&#46;yaml&#35;&#34;</code></span>

**Schema dialect (<code>&#36;schema</code>):** <span id="dt-dcb375baab6014763a68"><code>&#34;http&#58;&#47;&#47;devicetree&#46;org&#47;meta&#45;schemas&#47;core&#46;yaml&#35;&#34;</code></span>

<a id="dt-e46b5a5dd81dbd751c9f"></a>

**Maintainers (<code>maintainers</code>):** <a id="dt-fbc39820abb8bb999095"></a> <span id="dt-fb78ddfc22abfc6fe56d"><code>&#34;Doug Anderson &#60;dianders&#64;chromium&#46;org&#62;&#34;</code></span>, <span id="dt-0f999bb9185dbf6b58d8"><code>&#34;Peter Rosin &#60;peda&#64;axentia&#46;se&#62;&#34;</code></span>

<div id="dt-6d1c5ef59f0239d38c02">
<p style="white-space: pre-wrap">This uses GPIO lines and a challenge &amp; response mechanism to arbitrate who is
the master of an I2C bus in a multimaster situation.</p>
<p style="white-space: pre-wrap">In many cases using GPIOs to arbitrate is not needed and a design can use the
standard I2C multi-master rules.  Using GPIOs is generally useful in the case
where there is a device on the bus that has errata and/or bugs that makes
standard multimaster mode not feasible.</p>
<pre><code>Note that this scheme works well enough but has some downsides:
 * It is nonstandard (not using standard I2C multimaster)
 * Having two masters on a bus in general makes it relatively hard to debug
   problems (hard to tell if i2c issues were caused by one master, another,
   or some device on the bus).</code></pre>
<p style="white-space: pre-wrap">Algorithm:
All masters on the bus have a 'bus claim' line which is an output that the
others can see. These are all active low with pull-ups enabled.  We'll
describe these lines as:
 * OUR_CLAIM: output from us signaling to other hosts that we want the bus
 * THEIR_CLAIMS: output from others signaling that they want the bus</p>
<p style="white-space: pre-wrap">The basic algorithm is to assert your line when you want the bus, then make
sure that the other side doesn't want it also.  A detailed explanation is
best done with an example.</p>
<pre><code>Let's say we want to claim the bus.  We:
1. Assert OUR_CLAIM.
2. Waits a little bit for the other sides to notice (slew time, say 10
   microseconds).
3. Check THEIR_CLAIMS.  If none are asserted then the we have the bus and we
   are done.
4. Otherwise, wait for a few milliseconds and see if THEIR_CLAIMS are released.
5. If not, back off, release the claim and wait for a few more milliseconds.
6. Go back to 1 (until retry time has expired).</code></pre>
</div>

<a id="dt-e1f655ed0ff4d595dadc"></a>

## Properties and child nodes (<code>properties</code>)

<a id="dt-5c1d81699dcbe840de83"></a>

### <code>compatible</code> — required here

**Exact value (<code>const</code>):** <span id="dt-1765195bf8e86c3ccec6"><code>&#34;i2c&#45;arb&#45;gpio&#45;challenge&#34;</code></span>

<a id="dt-c6eea454035b5f9302a4"></a>

### <code>i2c&#45;parent</code> — not listed as required here

**Shared schema rule (<code>&#36;ref</code>):** <span id="dt-483fdd435500ca1c14bd">[<code>&#47;schemas&#47;types&#46;yaml&#35;&#47;definitions&#47;phandle</code>](</kernel/hardware/devicetree-bindings/dt-shared/types.md#dt-2533fa46618221e83225>)</span>

<div id="dt-de3c238d7401b2094729">
<p style="white-space: pre-wrap">The I2C bus that this multiplexer's master-side port is connected to.</p>
</div>

<a id="dt-a8f8d838df9bac52b2cf"></a>

### <code>our&#45;claim&#45;gpios</code> — required here

**Maximum number of items (<code>maxItems</code>):** <span id="dt-3b9a7e6454fdaff5d967"><code>1</code></span>

<div id="dt-872ba405402dfb03b916">
<p style="white-space: pre-wrap">The GPIO that we use to claim the bus.</p>
</div>

<a id="dt-678795f55be7dfa97f43"></a>

### <code>slew&#45;delay&#45;us</code> — not listed as required here

**Default value (<code>default</code>):** <span id="dt-8b852bd51d265f81fe91"><code>10</code></span>

<div id="dt-1799c72da3cae6fb4eb2">
<p style="white-space: pre-wrap">Time to wait for a GPIO to go high.</p>
</div>

<a id="dt-eca8002cb81a7ae52b7a"></a>

### <code>their&#45;claim&#45;gpios</code> — required here

**Minimum number of items (<code>minItems</code>):** <span id="dt-c3257299096128362e81"><code>1</code></span>

**Maximum number of items (<code>maxItems</code>):** <span id="dt-98293c6d7148fc5247f3"><code>8</code></span>

<div id="dt-843ffbd65b95dc1d1f09">
<p style="white-space: pre-wrap">The GPIOs that the other sides use to claim the bus.  Note that some implementations may only support a single other master.</p>
</div>

<a id="dt-fa74d2ae4a31aecb64ed"></a>

### <code>wait&#45;free&#45;us</code> — not listed as required here

**Default value (<code>default</code>):** <span id="dt-942b963c62cca9e41bf4"><code>50000</code></span>

<div id="dt-f3120dcd343cdf265d18">
<p style="white-space: pre-wrap">We'll give up after this many microseconds.</p>
</div>

<a id="dt-307b8a4ce6236cfc9a7c"></a>

### <code>wait&#45;retry&#45;us</code> — not listed as required here

**Default value (<code>default</code>):** <span id="dt-6ee4b28bf721c4d6a7d0"><code>3000</code></span>

<div id="dt-3ce3c897b472b6acc9a9">
<p style="white-space: pre-wrap">We'll attempt another claim after this many microseconds.</p>
</div>

<a id="dt-da98180ec267f69463e6"></a>

### <code>i2c&#45;arb</code> — required here

**Value type (<code>type</code>):** <span id="dt-3c7eec91044e7efc978e"><code>&#34;object&#34;</code></span>

**Shared schema rule (<code>&#36;ref</code>):** <span id="dt-2f0256c8caaa049fa64e">[<code>&#47;schemas&#47;i2c&#47;i2c&#45;controller&#46;yaml</code>](</kernel/hardware/devicetree-bindings/dt-shared/i2c/i2c-controller.md#dt-root>)</span>

<a id="dt-88a671e59d603764ff18"></a>

#### Properties not evaluated by applicable rules (<code>unevaluatedProperties</code>)

<code>false</code>

Not allowed by this rule.

<div id="dt-4173698b909bfefe2188">
<p style="white-space: pre-wrap">I2C arbitration bus node.</p>
</div>

**Required in this object (<code>required</code>):** <a id="dt-8313173ff1c9b300d560"></a> <span id="dt-048b70ee865d6847aa3d"><code>&#34;compatible&#34;</code></span>, <span id="dt-ee7433925c1528c16b99"><code>&#34;i2c&#45;arb&#34;</code></span>, <span id="dt-f3765998c4e103e45f2f"><code>&#34;our&#45;claim&#45;gpios&#34;</code></span>, <span id="dt-329d9b3604d5b98bc19d"><code>&#34;their&#45;claim&#45;gpios&#34;</code></span>

<a id="dt-738c4b4f9e483441138b"></a>

## Properties not matched by properties or patternProperties in this schema (<code>additionalProperties</code>)

<code>false</code>

Not allowed by this rule.

<a id="dt-1a130cabaa8a47b058bf"></a>

## Examples (<code>examples</code>)

<pre id="dt-0bd6510295af0c95ff2d"><code class="language-dts">#include &lt;dt-bindings/gpio/gpio.h&gt;
#include &lt;dt-bindings/interrupt-controller/irq.h&gt;

i2c-arbitrator {
    compatible = "i2c-arb-gpio-challenge";
    i2c-parent = &lt;&amp;i2c_4&gt;;

    our-claim-gpios = &lt;&amp;gpf0 3 GPIO_ACTIVE_LOW&gt;;
    their-claim-gpios = &lt;&amp;gpe0 4 GPIO_ACTIVE_LOW&gt;;
    slew-delay-us = &lt;10&gt;;
    wait-retry-us = &lt;3000&gt;;
    wait-free-us = &lt;50000&gt;;

    i2c-arb {
        #address-cells = &lt;1&gt;;
        #size-cells = &lt;0&gt;;

        sbs-battery@b {
            compatible = "sbs,sbs-battery";
            reg = &lt;0xb&gt;;
            sbs,poll-retry-count = &lt;1&gt;;
        };

        embedded-controller@1e {
            compatible = "google,cros-ec-i2c";
            reg = &lt;0x1e&gt;;
            interrupts = &lt;6 IRQ_TYPE_LEVEL_HIGH&gt;;
            interrupt-parent = &lt;&amp;gpx1&gt;;
            pinctrl-names = "default";
            pinctrl-0 = &lt;&amp;ec_irq&gt;;
            wakeup-source;
        };
    };
};
</code></pre>

## Source notes

<details>
<summary>Annotations retained from the schema source</summary>

<p id="dt-comment-0"><strong>Line 1:</strong> <span> SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause</span></p>

</details>
