Lines Matching +full:scl +full:- +full:gpios
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
62 {"i2c-gpio", true}, /* Standard devicetree compat string */
83 node = ofw_bus_get_node(sc->dev);
86 * Historically, we used the first two array elements of the gpios
87 * property. The modern bindings specify separate scl-gpios and
88 * sda-gpios properties. We cope with whichever is present.
90 if (OF_hasprop(node, "gpios")) {
91 if ((err = gpio_pin_get_by_ofw_idx(sc->dev, node,
92 GPIOIIC_SCL_DFLT, &sc->sclpin)) != 0) {
93 device_printf(sc->dev, "invalid gpios property\n");
96 if ((err = gpio_pin_get_by_ofw_idx(sc->dev, node,
97 GPIOIIC_SDA_DFLT, &sc->sdapin)) != 0) {
98 device_printf(sc->dev, "ivalid gpios property\n");
102 if ((err = gpio_pin_get_by_ofw_property(sc->dev, node,
103 "scl-gpios", &sc->sclpin)) != 0) {
104 device_printf(sc->dev, "missing scl-gpios property\n");
107 if ((err = gpio_pin_get_by_ofw_property(sc->dev, node,
108 "sda-gpios", &sc->sdapin)) != 0) {
109 device_printf(sc->dev, "missing sda-gpios property\n");
124 devname = device_get_name(sc->dev);
125 unit = device_get_unit(sc->dev);
126 busdev = device_get_parent(sc->dev);
140 numpins = gpiobus_get_npins(sc->dev);
151 device_printf(sc->dev,
160 * handle the scl/sda index hints that tell us which of the two pins is
164 if ((err = resource_int_value(devname, unit, "scl", &sclnum)) != 0)
167 device_printf(sc->dev, "invalid scl hint %d\n", sclnum);
173 device_printf(sc->dev, "invalid sda hint %d\n", sdanum);
178 if ((err = gpio_pin_get_by_child_index(sc->dev, sclnum,
179 &sc->sclpin)) != 0)
181 if ((err = gpio_pin_get_by_child_index(sc->dev, sdanum,
182 &sc->sdapin)) != 0)
194 gpio_pin_setflags(sc->sdapin, GPIO_PIN_INPUT);
196 gpio_pin_setflags(sc->sdapin,
198 gpio_pin_set_active(sc->sdapin, 0);
208 gpio_pin_setflags(sc->sclpin, GPIO_PIN_INPUT);
210 gpio_pin_setflags(sc->sclpin,
212 gpio_pin_set_active(sc->sclpin, 0);
222 gpio_pin_setflags(sc->sclpin, GPIO_PIN_INPUT);
223 gpio_pin_is_active(sc->sclpin, &val);
233 gpio_pin_setflags(sc->sdapin, GPIO_PIN_INPUT);
234 gpio_pin_is_active(sc->sdapin, &val);
244 gpio_pin_setflags(sc->sdapin, GPIO_PIN_INPUT);
245 gpio_pin_setflags(sc->sclpin, GPIO_PIN_INPUT);
255 device_delete_children(sc->dev);
257 if (sc->sclpin != NULL)
258 gpio_pin_release(sc->sclpin);
260 if (sc->sdapin != NULL)
261 gpio_pin_release(sc->sdapin);
278 ofw_bus_search_compatible(dev, compat_data)->ocd_data)
293 sc->dev = dev;
302 device_printf(sc->dev, "no pins configured\n");
313 device_printf(dev, "SCL pin: %s:%d, SDA pin: %s:%d\n",
315 device_get_nameunit(GPIO_GET_BUS(sc->sclpin->dev)), sc->sclpin->pin,
316 device_get_nameunit(GPIO_GET_BUS(sc->sdapin->dev)), sc->sdapin->pin);
318 device_get_nameunit(device_get_parent(dev)), sc->sclpin->pin,
319 device_get_nameunit(device_get_parent(dev)), sc->sdapin->pin);
323 device_add_child(sc->dev, "iicbb", DEVICE_UNIT_ANY);