1*4882a593SmuzhiyunGPIO-based I2C Arbitration Using a Challenge & Response Mechanism 2*4882a593Smuzhiyun================================================================= 3*4882a593SmuzhiyunThis uses GPIO lines and a challenge & response mechanism to arbitrate who is 4*4882a593Smuzhiyunthe master of an I2C bus in a multimaster situation. 5*4882a593Smuzhiyun 6*4882a593SmuzhiyunIn many cases using GPIOs to arbitrate is not needed and a design can use 7*4882a593Smuzhiyunthe standard I2C multi-master rules. Using GPIOs is generally useful in 8*4882a593Smuzhiyunthe case where there is a device on the bus that has errata and/or bugs 9*4882a593Smuzhiyunthat makes standard multimaster mode not feasible. 10*4882a593Smuzhiyun 11*4882a593SmuzhiyunNote that this scheme works well enough but has some downsides: 12*4882a593Smuzhiyun* It is nonstandard (not using standard I2C multimaster) 13*4882a593Smuzhiyun* Having two masters on a bus in general makes it relatively hard to debug 14*4882a593Smuzhiyun problems (hard to tell if i2c issues were caused by one master, another, or 15*4882a593Smuzhiyun some device on the bus). 16*4882a593Smuzhiyun 17*4882a593Smuzhiyun 18*4882a593SmuzhiyunAlgorithm: 19*4882a593Smuzhiyun 20*4882a593SmuzhiyunAll masters on the bus have a 'bus claim' line which is an output that the 21*4882a593Smuzhiyunothers can see. These are all active low with pull-ups enabled. We'll 22*4882a593Smuzhiyundescribe these lines as: 23*4882a593Smuzhiyun 24*4882a593Smuzhiyun- OUR_CLAIM: output from us signaling to other hosts that we want the bus 25*4882a593Smuzhiyun- THEIR_CLAIMS: output from others signaling that they want the bus 26*4882a593Smuzhiyun 27*4882a593SmuzhiyunThe basic algorithm is to assert your line when you want the bus, then make 28*4882a593Smuzhiyunsure that the other side doesn't want it also. A detailed explanation is best 29*4882a593Smuzhiyundone with an example. 30*4882a593Smuzhiyun 31*4882a593SmuzhiyunLet's say we want to claim the bus. We: 32*4882a593Smuzhiyun1. Assert OUR_CLAIM. 33*4882a593Smuzhiyun2. Waits a little bit for the other sides to notice (slew time, say 10 34*4882a593Smuzhiyun microseconds). 35*4882a593Smuzhiyun3. Check THEIR_CLAIMS. If none are asserted then the we have the bus and we are 36*4882a593Smuzhiyun done. 37*4882a593Smuzhiyun4. Otherwise, wait for a few milliseconds and see if THEIR_CLAIMS are released. 38*4882a593Smuzhiyun5. If not, back off, release the claim and wait for a few more milliseconds. 39*4882a593Smuzhiyun6. Go back to 1 (until retry time has expired). 40*4882a593Smuzhiyun 41*4882a593Smuzhiyun 42*4882a593SmuzhiyunRequired properties: 43*4882a593Smuzhiyun- compatible: i2c-arb-gpio-challenge 44*4882a593Smuzhiyun- our-claim-gpio: The GPIO that we use to claim the bus. 45*4882a593Smuzhiyun- their-claim-gpios: The GPIOs that the other sides use to claim the bus. 46*4882a593Smuzhiyun Note that some implementations may only support a single other master. 47*4882a593Smuzhiyun- I2C arbitration bus node. See i2c-arb.txt in this directory. 48*4882a593Smuzhiyun 49*4882a593SmuzhiyunOptional properties: 50*4882a593Smuzhiyun- slew-delay-us: microseconds to wait for a GPIO to go high. Default is 10 us. 51*4882a593Smuzhiyun- wait-retry-us: we'll attempt another claim after this many microseconds. 52*4882a593Smuzhiyun Default is 3000 us. 53*4882a593Smuzhiyun- wait-free-us: we'll give up after this many microseconds. Default is 50000 us. 54*4882a593Smuzhiyun 55*4882a593Smuzhiyun 56*4882a593SmuzhiyunExample: 57*4882a593Smuzhiyun i2c@12ca0000 { 58*4882a593Smuzhiyun compatible = "acme,some-i2c-device"; 59*4882a593Smuzhiyun #address-cells = <1>; 60*4882a593Smuzhiyun #size-cells = <0>; 61*4882a593Smuzhiyun }; 62*4882a593Smuzhiyun 63*4882a593Smuzhiyun i2c-arbitrator { 64*4882a593Smuzhiyun compatible = "i2c-arb-gpio-challenge"; 65*4882a593Smuzhiyun 66*4882a593Smuzhiyun i2c-parent = <&{/i2c@12CA0000}>; 67*4882a593Smuzhiyun 68*4882a593Smuzhiyun our-claim-gpio = <&gpf0 3 1>; 69*4882a593Smuzhiyun their-claim-gpios = <&gpe0 4 1>; 70*4882a593Smuzhiyun slew-delay-us = <10>; 71*4882a593Smuzhiyun wait-retry-us = <3000>; 72*4882a593Smuzhiyun wait-free-us = <50000>; 73*4882a593Smuzhiyun 74*4882a593Smuzhiyun i2c-arb { 75*4882a593Smuzhiyun #address-cells = <1>; 76*4882a593Smuzhiyun #size-cells = <0>; 77*4882a593Smuzhiyun 78*4882a593Smuzhiyun i2c@52 { 79*4882a593Smuzhiyun // Normal I2C device 80*4882a593Smuzhiyun }; 81*4882a593Smuzhiyun }; 82*4882a593Smuzhiyun }; 83