xref: /openbmc/linux/Documentation/devicetree/bindings/i2c/i2c-arb-gpio-challenge.yaml (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
1*5578e751SKrzysztof Kozlowski# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
2*5578e751SKrzysztof Kozlowski%YAML 1.2
3*5578e751SKrzysztof Kozlowski---
4*5578e751SKrzysztof Kozlowski$id: http://devicetree.org/schemas/i2c/i2c-arb-gpio-challenge.yaml#
5*5578e751SKrzysztof Kozlowski$schema: http://devicetree.org/meta-schemas/core.yaml#
6*5578e751SKrzysztof Kozlowski
7*5578e751SKrzysztof Kozlowskititle: GPIO-based I2C Arbitration Using a Challenge & Response Mechanism
8*5578e751SKrzysztof Kozlowski
9*5578e751SKrzysztof Kozlowskimaintainers:
10*5578e751SKrzysztof Kozlowski  - Doug Anderson <dianders@chromium.org>
11*5578e751SKrzysztof Kozlowski  - Peter Rosin <peda@axentia.se>
12*5578e751SKrzysztof Kozlowski
13*5578e751SKrzysztof Kozlowskidescription: |
14*5578e751SKrzysztof Kozlowski  This uses GPIO lines and a challenge & response mechanism to arbitrate who is
15*5578e751SKrzysztof Kozlowski  the master of an I2C bus in a multimaster situation.
16*5578e751SKrzysztof Kozlowski
17*5578e751SKrzysztof Kozlowski  In many cases using GPIOs to arbitrate is not needed and a design can use the
18*5578e751SKrzysztof Kozlowski  standard I2C multi-master rules.  Using GPIOs is generally useful in the case
19*5578e751SKrzysztof Kozlowski  where there is a device on the bus that has errata and/or bugs that makes
20*5578e751SKrzysztof Kozlowski  standard multimaster mode not feasible.
21*5578e751SKrzysztof Kozlowski
22*5578e751SKrzysztof Kozlowski  Note that this scheme works well enough but has some downsides:
23*5578e751SKrzysztof Kozlowski   * It is nonstandard (not using standard I2C multimaster)
24*5578e751SKrzysztof Kozlowski   * Having two masters on a bus in general makes it relatively hard to debug
25*5578e751SKrzysztof Kozlowski     problems (hard to tell if i2c issues were caused by one master, another,
26*5578e751SKrzysztof Kozlowski     or some device on the bus).
27*5578e751SKrzysztof Kozlowski
28*5578e751SKrzysztof Kozlowski  Algorithm:
29*5578e751SKrzysztof Kozlowski  All masters on the bus have a 'bus claim' line which is an output that the
30*5578e751SKrzysztof Kozlowski  others can see. These are all active low with pull-ups enabled.  We'll
31*5578e751SKrzysztof Kozlowski  describe these lines as:
32*5578e751SKrzysztof Kozlowski   * OUR_CLAIM: output from us signaling to other hosts that we want the bus
33*5578e751SKrzysztof Kozlowski   * THEIR_CLAIMS: output from others signaling that they want the bus
34*5578e751SKrzysztof Kozlowski
35*5578e751SKrzysztof Kozlowski  The basic algorithm is to assert your line when you want the bus, then make
36*5578e751SKrzysztof Kozlowski  sure that the other side doesn't want it also.  A detailed explanation is
37*5578e751SKrzysztof Kozlowski  best done with an example.
38*5578e751SKrzysztof Kozlowski
39*5578e751SKrzysztof Kozlowski  Let's say we want to claim the bus.  We:
40*5578e751SKrzysztof Kozlowski  1. Assert OUR_CLAIM.
41*5578e751SKrzysztof Kozlowski  2. Waits a little bit for the other sides to notice (slew time, say 10
42*5578e751SKrzysztof Kozlowski     microseconds).
43*5578e751SKrzysztof Kozlowski  3. Check THEIR_CLAIMS.  If none are asserted then the we have the bus and we
44*5578e751SKrzysztof Kozlowski     are done.
45*5578e751SKrzysztof Kozlowski  4. Otherwise, wait for a few milliseconds and see if THEIR_CLAIMS are released.
46*5578e751SKrzysztof Kozlowski  5. If not, back off, release the claim and wait for a few more milliseconds.
47*5578e751SKrzysztof Kozlowski  6. Go back to 1 (until retry time has expired).
48*5578e751SKrzysztof Kozlowski
49*5578e751SKrzysztof Kozlowskiproperties:
50*5578e751SKrzysztof Kozlowski  compatible:
51*5578e751SKrzysztof Kozlowski    const: i2c-arb-gpio-challenge
52*5578e751SKrzysztof Kozlowski
53*5578e751SKrzysztof Kozlowski  i2c-parent:
54*5578e751SKrzysztof Kozlowski    $ref: /schemas/types.yaml#/definitions/phandle
55*5578e751SKrzysztof Kozlowski    description:
56*5578e751SKrzysztof Kozlowski      The I2C bus that this multiplexer's master-side port is connected to.
57*5578e751SKrzysztof Kozlowski
58*5578e751SKrzysztof Kozlowski  our-claim-gpios:
59*5578e751SKrzysztof Kozlowski    maxItems: 1
60*5578e751SKrzysztof Kozlowski    description:
61*5578e751SKrzysztof Kozlowski      The GPIO that we use to claim the bus.
62*5578e751SKrzysztof Kozlowski
63*5578e751SKrzysztof Kozlowski  slew-delay-us:
64*5578e751SKrzysztof Kozlowski    default: 10
65*5578e751SKrzysztof Kozlowski    description:
66*5578e751SKrzysztof Kozlowski      Time to wait for a GPIO to go high.
67*5578e751SKrzysztof Kozlowski
68*5578e751SKrzysztof Kozlowski  their-claim-gpios:
69*5578e751SKrzysztof Kozlowski    minItems: 1
70*5578e751SKrzysztof Kozlowski    maxItems: 8
71*5578e751SKrzysztof Kozlowski    description:
72*5578e751SKrzysztof Kozlowski      The GPIOs that the other sides use to claim the bus.  Note that some
73*5578e751SKrzysztof Kozlowski      implementations may only support a single other master.
74*5578e751SKrzysztof Kozlowski
75*5578e751SKrzysztof Kozlowski  wait-free-us:
76*5578e751SKrzysztof Kozlowski    default: 50000
77*5578e751SKrzysztof Kozlowski    description:
78*5578e751SKrzysztof Kozlowski      We'll give up after this many microseconds.
79*5578e751SKrzysztof Kozlowski
80*5578e751SKrzysztof Kozlowski  wait-retry-us:
81*5578e751SKrzysztof Kozlowski    default: 3000
82*5578e751SKrzysztof Kozlowski    description:
83*5578e751SKrzysztof Kozlowski      We'll attempt another claim after this many microseconds.
84*5578e751SKrzysztof Kozlowski
85*5578e751SKrzysztof Kozlowski  i2c-arb:
86*5578e751SKrzysztof Kozlowski    type: object
87*5578e751SKrzysztof Kozlowski    $ref: /schemas/i2c/i2c-controller.yaml
88*5578e751SKrzysztof Kozlowski    unevaluatedProperties: false
89*5578e751SKrzysztof Kozlowski    description:
90*5578e751SKrzysztof Kozlowski      I2C arbitration bus node.
91*5578e751SKrzysztof Kozlowski
92*5578e751SKrzysztof Kozlowskirequired:
93*5578e751SKrzysztof Kozlowski  - compatible
94*5578e751SKrzysztof Kozlowski  - i2c-arb
95*5578e751SKrzysztof Kozlowski  - our-claim-gpios
96*5578e751SKrzysztof Kozlowski  - their-claim-gpios
97*5578e751SKrzysztof Kozlowski
98*5578e751SKrzysztof KozlowskiadditionalProperties: false
99*5578e751SKrzysztof Kozlowski
100*5578e751SKrzysztof Kozlowskiexamples:
101*5578e751SKrzysztof Kozlowski  - |
102*5578e751SKrzysztof Kozlowski    #include <dt-bindings/gpio/gpio.h>
103*5578e751SKrzysztof Kozlowski    #include <dt-bindings/interrupt-controller/irq.h>
104*5578e751SKrzysztof Kozlowski
105*5578e751SKrzysztof Kozlowski    i2c-arbitrator {
106*5578e751SKrzysztof Kozlowski        compatible = "i2c-arb-gpio-challenge";
107*5578e751SKrzysztof Kozlowski        i2c-parent = <&i2c_4>;
108*5578e751SKrzysztof Kozlowski
109*5578e751SKrzysztof Kozlowski        our-claim-gpios = <&gpf0 3 GPIO_ACTIVE_LOW>;
110*5578e751SKrzysztof Kozlowski        their-claim-gpios = <&gpe0 4 GPIO_ACTIVE_LOW>;
111*5578e751SKrzysztof Kozlowski        slew-delay-us = <10>;
112*5578e751SKrzysztof Kozlowski        wait-retry-us = <3000>;
113*5578e751SKrzysztof Kozlowski        wait-free-us = <50000>;
114*5578e751SKrzysztof Kozlowski
115*5578e751SKrzysztof Kozlowski        i2c-arb {
116*5578e751SKrzysztof Kozlowski            #address-cells = <1>;
117*5578e751SKrzysztof Kozlowski            #size-cells = <0>;
118*5578e751SKrzysztof Kozlowski
119*5578e751SKrzysztof Kozlowski            sbs-battery@b {
120*5578e751SKrzysztof Kozlowski                compatible = "sbs,sbs-battery";
121*5578e751SKrzysztof Kozlowski                reg = <0xb>;
122*5578e751SKrzysztof Kozlowski                sbs,poll-retry-count = <1>;
123*5578e751SKrzysztof Kozlowski            };
124*5578e751SKrzysztof Kozlowski
125*5578e751SKrzysztof Kozlowski            embedded-controller@1e {
126*5578e751SKrzysztof Kozlowski                compatible = "google,cros-ec-i2c";
127*5578e751SKrzysztof Kozlowski                reg = <0x1e>;
128*5578e751SKrzysztof Kozlowski                interrupts = <6 IRQ_TYPE_LEVEL_HIGH>;
129*5578e751SKrzysztof Kozlowski                interrupt-parent = <&gpx1>;
130*5578e751SKrzysztof Kozlowski                pinctrl-names = "default";
131*5578e751SKrzysztof Kozlowski                pinctrl-0 = <&ec_irq>;
132*5578e751SKrzysztof Kozlowski                wakeup-source;
133*5578e751SKrzysztof Kozlowski            };
134*5578e751SKrzysztof Kozlowski        };
135*5578e751SKrzysztof Kozlowski    };
136