GPIOIIC(4)

πŸ“¦
version 15.1 Β· 3 versions
, in freebsd 14.5, freebsd 15.1, nixpkgs unstable

πŸ’… GPIOIIC(4) πŸ’…

okay bestie, so this one's a gpioiic man page β€” it's the GPIO I2C bit-banging device driver and honestly it's giving main character energy for your embedded projects ✨


πŸŽ€ SYNOPSIS πŸŽ€

so if you wanna bake this driver right into your kernel, drop these lines in your kernel configuration file fr fr:

device gpio
device gpioiic
device iicbb
device iicbus

or, if you'd rather just load it as a module at boot time (lowkey the easier vibe), put this line in loader.conf(5):

gpioiic_load="YES"

✨ DESCRIPTION ✨

okay so the gpioiic driver is out here giving you an IIC bit-banging interface using just two GPIO pins for the SCL and SDA lines on the bus. iconic behavior honestly πŸ¦‹

here's the tea though: gpioiic simulates an open collector kind of output when it's managing the pins on the bus β€” even on systems that don't directly support configuring gpio pins in that mode. and like, it's very mindful about it: the pins are never driven to the logical value of '1'. nope. they get driven to '0' or switched to input mode (Hi-Z/tri-state), and then an external pullup resistor pulls the line to the 1 state β€” unless some other device on the bus is out here driving it to 0. teamwork makes the dream work πŸ’–


🌸 HINTS CONFIGURATION 🌸

on a device.hints(5) based system (like MIPS), these values are configurable for gpioiic:

  • hint.gpioiic.%d.at β€” the gpiobus you're attaching to. normally it's just gpiobus0 on systems with a single bank of gpio pins.
  • hint.gpioiic.%d.pins β€” this is a bitmask of the pins on the gpiobus that get used for SCLOCK and SDATA from the GPIO IIC bit-banging bus. so to configure pin 0 and 7, you use the bitmask of 0b10000001 and convert it to a hexadecimal value of 0x0081. also ⚠️ please note this mask should only ever have two bits set (any other bits β€” i.e. pins β€” will just be ignored). and because gpioiic must be a child of the gpiobus, both gpio pins must be part of that bus. no exceptions bestie.
  • hint.gpioiic.%d.scl β€” indicates which bit in the hint.gpioiic.%d.pins should be used as the SCLOCK source. it's optional and defaults to 0.
  • hint.gpioiic.%d.sda β€” indicates which bit in the hint.gpioiic.%d.pins should be used as the SDATA source. also optional, defaults to 1.

πŸ¦‹ FDT CONFIGURATION πŸ¦‹

on an FDT(4) based system (like ARM), the DTS node for gpioiic conforms to the standard bindings document i2c/i2c-gpio.yaml. the device node typically appears at the root of the device tree. here's an example of a gpioiic node with one slave device on the IIC bus:

/ {
        gpioiic0 {
                compatible = "i2c-gpio";
                pinctrl-names = "default";
                pinctrl-0 = <&pinctrl_gpioiic0>;
                scl-gpios = <&gpio1  5 GPIO_ACTIVE_HIGH>;
                sda-gpios = <&gpio7 11 GPIO_ACTIVE_HIGH>;
                status = "okay";

                /* One slave device on the i2c bus. */
                rtc@51 {
                        compatible="nxp,pcf2127";
                        reg = <0x51>;
                        status = "okay";
                };
        };
};

so what's what:

  • compatible β€” should be set to "i2c-gpio". but heads up: the deprecated string "gpioiic" is also accepted for backwards compatibility. we love a nostalgic moment πŸ’€
  • scl-gpios / sda-gpios β€” these properties indicate which GPIO pins should be used for clock and data on the GPIO IIC bit-banging bus. and like, there's no requirement that the two pins belong to the same gpio controller. they can be from totally different friend groups, it's fine 🫢
  • pinctrl-names / pinctrl-0 β€” these properties may be required to configure the chosen pins as gpio pins, unless the pins already default to that state on your system. iykyk.

πŸ’œ SEE ALSO πŸ’œ

fdt(4), gpio(4), iic(4), iicbb(4), iicbus(4)


⭐ HISTORY ⭐

the gpioiic manual page first appeared in FreeBSD 10.1. a whole era πŸ’…


πŸ‘‘ AUTHORS πŸ‘‘

this manual page was written by Luiz Otavio O Souza. respect the icon who wrote it πŸ™Œ


alright bestie, that's the whole page! this version is from Debian, dated December 1, 2019 β€” and honestly the Debian folks ate with this one. now go forth and bit-bang responsibly 🧚✨

πŸ“¦ where this page comes from