xref: /freebsd/share/man/man4/gpioiic.4 (revision fa9896e082a1046ff4fbc75fcba4d18d1f2efc19)
18ce07fe7SLuiz Otavio O Souza.\" Copyright (c) 2013, Luiz Otavio O Souza <loos@FreeBSD.org>
28ce07fe7SLuiz Otavio O Souza.\" All rights reserved.
38ce07fe7SLuiz Otavio O Souza.\"
48ce07fe7SLuiz Otavio O Souza.\" Redistribution and use in source and binary forms, with or without
58ce07fe7SLuiz Otavio O Souza.\" modification, are permitted provided that the following conditions
68ce07fe7SLuiz Otavio O Souza.\" are met:
78ce07fe7SLuiz Otavio O Souza.\" 1. Redistributions of source code must retain the above copyright
88ce07fe7SLuiz Otavio O Souza.\"    notice, this list of conditions and the following disclaimer.
98ce07fe7SLuiz Otavio O Souza.\" 2. Redistributions in binary form must reproduce the above copyright
108ce07fe7SLuiz Otavio O Souza.\"    notice, this list of conditions and the following disclaimer in the
118ce07fe7SLuiz Otavio O Souza.\"    documentation and/or other materials provided with the distribution.
128ce07fe7SLuiz Otavio O Souza.\"
138ce07fe7SLuiz Otavio O Souza.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
148ce07fe7SLuiz Otavio O Souza.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
158ce07fe7SLuiz Otavio O Souza.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
168ce07fe7SLuiz Otavio O Souza.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
178ce07fe7SLuiz Otavio O Souza.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
188ce07fe7SLuiz Otavio O Souza.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
198ce07fe7SLuiz Otavio O Souza.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
208ce07fe7SLuiz Otavio O Souza.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
218ce07fe7SLuiz Otavio O Souza.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
228ce07fe7SLuiz Otavio O Souza.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
238ce07fe7SLuiz Otavio O Souza.\" SUCH DAMAGE.
248ce07fe7SLuiz Otavio O Souza.\"
25*56ad49b2SIan Lepore.Dd December 1, 2019
268ce07fe7SLuiz Otavio O Souza.Dt GPIOIIC 4
278ce07fe7SLuiz Otavio O Souza.Os
288ce07fe7SLuiz Otavio O Souza.Sh NAME
298ce07fe7SLuiz Otavio O Souza.Nm gpioiic
308ce07fe7SLuiz Otavio O Souza.Nd GPIO I2C bit-banging device driver
318ce07fe7SLuiz Otavio O Souza.Sh SYNOPSIS
326a6ce390SChristian BruefferTo compile this driver into the kernel,
336a6ce390SChristian Bruefferplace the following lines in your
346a6ce390SChristian Bruefferkernel configuration file:
356a6ce390SChristian Brueffer.Bd -ragged -offset indent
368ce07fe7SLuiz Otavio O Souza.Cd "device gpio"
378ce07fe7SLuiz Otavio O Souza.Cd "device gpioiic"
388ce07fe7SLuiz Otavio O Souza.Cd "device iicbb"
398ce07fe7SLuiz Otavio O Souza.Cd "device iicbus"
406a6ce390SChristian Brueffer.Ed
41*56ad49b2SIan Lepore.Pp
42*56ad49b2SIan LeporeAlternatively, to load the driver as a
43*56ad49b2SIan Leporemodule at boot time, place the following line in
44*56ad49b2SIan Lepore.Xr loader.conf 5 :
45*56ad49b2SIan Lepore.Bd -literal -offset indent
46*56ad49b2SIan Leporegpioiic_load="YES"
47*56ad49b2SIan Lepore.Ed
488ce07fe7SLuiz Otavio O Souza.Sh DESCRIPTION
498ce07fe7SLuiz Otavio O SouzaThe
506a6ce390SChristian Brueffer.Nm
518ce07fe7SLuiz Otavio O Souzadriver provides an IIC bit-banging interface using two GPIO pins for the
52*56ad49b2SIan LeporeSCL and SDA lines on the bus.
538ce07fe7SLuiz Otavio O Souza.Pp
54*56ad49b2SIan Lepore.Nm
55*56ad49b2SIan Leporesimulates an open collector kind of output when managing the pins on the
56*56ad49b2SIan Leporebus, even on systems which don't directly support configuring gpio pins
57*56ad49b2SIan Leporein that mode.
58*56ad49b2SIan LeporeThe pins are never driven to the logical value of '1'.
59*56ad49b2SIan LeporeThey are driven to '0' or switched to input mode (Hi-Z/tri-state), and
60*56ad49b2SIan Leporean external pullup resistor pulls the line to the 1 state unless some
61*56ad49b2SIan Leporeother device on the bus is driving it to 0.
62*56ad49b2SIan Lepore.Sh HINTS CONFIGURATION
636a6ce390SChristian BruefferOn a
646a6ce390SChristian Brueffer.Xr device.hints 5
65*56ad49b2SIan Leporebased system, such as MIPS, these values are configurable for
666a6ce390SChristian Brueffer.Nm :
678ce07fe7SLuiz Otavio O Souza.Bl -tag -width ".Va hint.gpioiic.%d.atXXX"
688ce07fe7SLuiz Otavio O Souza.It Va hint.gpioiic.%d.at
696a6ce390SChristian BruefferThe
706a6ce390SChristian Brueffer.Nm gpiobus
716a6ce390SChristian Bruefferyou are attaching to.
72*56ad49b2SIan LeporeNormally just gpiobus0 on systems with a single bank of gpio pins.
738ce07fe7SLuiz Otavio O Souza.It Va hint.gpioiic.%d.pins
748ce07fe7SLuiz Otavio O SouzaThis is a bitmask of the pins on the
756a6ce390SChristian Brueffer.Nm gpiobus
768ce07fe7SLuiz Otavio O Souzathat are to be used for SCLOCK and SDATA from the GPIO IIC
778ce07fe7SLuiz Otavio O Souzabit-banging bus.
788ce07fe7SLuiz Otavio O SouzaTo configure pin 0 and 7, use the bitmask of
799a2a079aSLuiz Otavio O Souza0b10000001 and convert it to a hexadecimal value of 0x0081.
808ce07fe7SLuiz Otavio O SouzaPlease note that this mask should only ever have two bits set
816a6ce390SChristian Brueffer(any other bits - i.e., pins - will be ignored).
82*56ad49b2SIan LeporeBecause
83*56ad49b2SIan Lepore.Nm
84*56ad49b2SIan Leporemust be a child of the gpiobus, both gpio pins must be part of that bus.
858ce07fe7SLuiz Otavio O Souza.It Va hint.gpioiic.%d.scl
868ce07fe7SLuiz Otavio O SouzaIndicates which bit in the
878ce07fe7SLuiz Otavio O Souza.Va hint.gpioiic.%d.pins
888ce07fe7SLuiz Otavio O Souzashould be used as the SCLOCK
898ce07fe7SLuiz Otavio O Souzasource.
909a2a079aSLuiz Otavio O SouzaOptional, defaults to 0.
918ce07fe7SLuiz Otavio O Souza.It Va hint.gpioiic.%d.sda
928ce07fe7SLuiz Otavio O SouzaIndicates which bit in the
938ce07fe7SLuiz Otavio O Souza.Va hint.gpioiic.%d.pins
948ce07fe7SLuiz Otavio O Souzashould be used as the SDATA
958ce07fe7SLuiz Otavio O Souzasource.
969a2a079aSLuiz Otavio O SouzaOptional, defaults to 1.
979a2a079aSLuiz Otavio O Souza.El
98*56ad49b2SIan Lepore.Sh FDT CONFIGURATION
99*56ad49b2SIan LeporeOn an
1009a2a079aSLuiz Otavio O Souza.Xr FDT 4
101*56ad49b2SIan Leporebased system, such as ARM, the DTS node for
1029a2a079aSLuiz Otavio O Souza.Nm gpioiic
103*56ad49b2SIan Leporeconforms to the standard bindings document i2c/i2c-gpio.yaml.
104*56ad49b2SIan LeporeThe device node typically appears at the root of the device tree.
105*56ad49b2SIan LeporeThe following is an example of a
106*56ad49b2SIan Lepore.Nm
107*56ad49b2SIan Leporenode with one slave device
108*56ad49b2SIan Leporeon the IIC bus:
1099a2a079aSLuiz Otavio O Souza.Bd -literal
110*56ad49b2SIan Lepore/ {
1119a2a079aSLuiz Otavio O Souza	gpioiic0 {
112*56ad49b2SIan Lepore		compatible = "i2c-gpio";
113*56ad49b2SIan Lepore		pinctrl-names = "default";
114*56ad49b2SIan Lepore		pinctrl-0 = <&pinctrl_gpioiic0>;
115*56ad49b2SIan Lepore		scl-gpios = <&gpio1  5 GPIO_ACTIVE_HIGH>;
116*56ad49b2SIan Lepore		sda-gpios = <&gpio7 11 GPIO_ACTIVE_HIGH>;
117*56ad49b2SIan Lepore		status = "okay";
1189a2a079aSLuiz Otavio O Souza
119*56ad49b2SIan Lepore		/* One slave device on the i2c bus. */
120*56ad49b2SIan Lepore		rtc@51 {
121*56ad49b2SIan Lepore			compatible="nxp,pcf2127";
122*56ad49b2SIan Lepore			reg = <0x51>;
123*56ad49b2SIan Lepore			status = "okay";
1249a2a079aSLuiz Otavio O Souza		};
1259a2a079aSLuiz Otavio O Souza	};
1269a2a079aSLuiz Otavio O Souza};
1279a2a079aSLuiz Otavio O Souza.Ed
1289a2a079aSLuiz Otavio O Souza.Pp
1299a2a079aSLuiz Otavio O SouzaWhere:
1309a2a079aSLuiz Otavio O Souza.Bl -tag -width ".Va compatible"
1319a2a079aSLuiz Otavio O Souza.It Va compatible
132*56ad49b2SIan LeporeShould be set to "i2c-gpio".
133*56ad49b2SIan LeporeThe deprecated string "gpioiic" is also accepted for backwards compatibility.
134*56ad49b2SIan Lepore.It Va scl-gpios Va sda-gpios
135*56ad49b2SIan LeporeThese properties indicate which GPIO pins should be used for clock
136*56ad49b2SIan Leporeand data on the GPIO IIC bit-banging bus.
137*56ad49b2SIan LeporeThere is no requirement that the two pins belong to the same gpio controller.
138*56ad49b2SIan Lepore.It Va pinctrl-names pinctrl-0
139*56ad49b2SIan LeporeThese properties may be required to configure the chosen pins as gpio
140*56ad49b2SIan Leporepins, unless the pins default to that state on your system.
1418ce07fe7SLuiz Otavio O Souza.El
1428ce07fe7SLuiz Otavio O Souza.Sh SEE ALSO
1439a2a079aSLuiz Otavio O Souza.Xr fdt 4 ,
1448ce07fe7SLuiz Otavio O Souza.Xr gpio 4 ,
1458ce07fe7SLuiz Otavio O Souza.Xr iic 4 ,
1468ce07fe7SLuiz Otavio O Souza.Xr iicbb 4 ,
1478ce07fe7SLuiz Otavio O Souza.Xr iicbus 4
1488ce07fe7SLuiz Otavio O Souza.Sh HISTORY
1498ce07fe7SLuiz Otavio O SouzaThe
1508ce07fe7SLuiz Otavio O Souza.Nm
1518ce07fe7SLuiz Otavio O Souzamanual page first appeared in
152b6d2fa3eSLuiz Otavio O Souza.Fx 10.1 .
1538ce07fe7SLuiz Otavio O Souza.Sh AUTHORS
1548ce07fe7SLuiz Otavio O SouzaThis
1558ce07fe7SLuiz Otavio O Souzamanual page was written by
1568ce07fe7SLuiz Otavio O Souza.An Luiz Otavio O Souza .
157