Lines Matching +full:pins +full:- +full:sda +full:- +full:scl
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
62 {"i2c-gpio", true}, /* Standard devicetree compat string */
83 node = ofw_bus_get_node(sc->dev); in gpioiic_setup_fdt_pins()
87 * property. The modern bindings specify separate scl-gpios and in gpioiic_setup_fdt_pins()
88 * sda-gpios properties. We cope with whichever is present. in gpioiic_setup_fdt_pins()
91 if ((err = gpio_pin_get_by_ofw_idx(sc->dev, node, in gpioiic_setup_fdt_pins()
92 GPIOIIC_SCL_DFLT, &sc->sclpin)) != 0) { in gpioiic_setup_fdt_pins()
93 device_printf(sc->dev, "invalid gpios property\n"); in gpioiic_setup_fdt_pins()
96 if ((err = gpio_pin_get_by_ofw_idx(sc->dev, node, in gpioiic_setup_fdt_pins()
97 GPIOIIC_SDA_DFLT, &sc->sdapin)) != 0) { in gpioiic_setup_fdt_pins()
98 device_printf(sc->dev, "ivalid gpios property\n"); in gpioiic_setup_fdt_pins()
102 if ((err = gpio_pin_get_by_ofw_property(sc->dev, node, in gpioiic_setup_fdt_pins()
103 "scl-gpios", &sc->sclpin)) != 0) { in gpioiic_setup_fdt_pins()
104 device_printf(sc->dev, "missing scl-gpios property\n"); in gpioiic_setup_fdt_pins()
107 if ((err = gpio_pin_get_by_ofw_property(sc->dev, node, in gpioiic_setup_fdt_pins()
108 "sda-gpios", &sc->sdapin)) != 0) { in gpioiic_setup_fdt_pins()
109 device_printf(sc->dev, "missing sda-gpios property\n"); in gpioiic_setup_fdt_pins()
124 devname = device_get_name(sc->dev); in gpioiic_setup_hinted_pins()
125 unit = device_get_unit(sc->dev); in gpioiic_setup_hinted_pins()
126 busdev = device_get_parent(sc->dev); in gpioiic_setup_hinted_pins()
139 /* Make sure there were hints for at least two pins. */ in gpioiic_setup_hinted_pins()
140 numpins = gpiobus_get_npins(sc->dev); in gpioiic_setup_hinted_pins()
151 device_printf(sc->dev, in gpioiic_setup_hinted_pins()
152 "invalid pins hint; it must contain at least %d pins\n", in gpioiic_setup_hinted_pins()
158 * Our parent bus has already parsed the pins hint and it will use that in gpioiic_setup_hinted_pins()
160 * handle the scl/sda index hints that tell us which of the two pins is in gpioiic_setup_hinted_pins()
164 if ((err = resource_int_value(devname, unit, "scl", &sclnum)) != 0) in gpioiic_setup_hinted_pins()
167 device_printf(sc->dev, "invalid scl hint %d\n", sclnum); in gpioiic_setup_hinted_pins()
170 if ((err = resource_int_value(devname, unit, "sda", &sdanum)) != 0) in gpioiic_setup_hinted_pins()
173 device_printf(sc->dev, "invalid sda hint %d\n", sdanum); in gpioiic_setup_hinted_pins()
177 /* Allocate gpiobus_pin structs for the pins we found above. */ in gpioiic_setup_hinted_pins()
178 if ((err = gpio_pin_get_by_child_index(sc->dev, sclnum, in gpioiic_setup_hinted_pins()
179 &sc->sclpin)) != 0) in gpioiic_setup_hinted_pins()
181 if ((err = gpio_pin_get_by_child_index(sc->dev, sdanum, in gpioiic_setup_hinted_pins()
182 &sc->sdapin)) != 0) in gpioiic_setup_hinted_pins()
194 gpio_pin_setflags(sc->sdapin, GPIO_PIN_INPUT); in gpioiic_setsda()
196 gpio_pin_setflags(sc->sdapin, in gpioiic_setsda()
198 gpio_pin_set_active(sc->sdapin, 0); in gpioiic_setsda()
208 gpio_pin_setflags(sc->sclpin, GPIO_PIN_INPUT); in gpioiic_setscl()
210 gpio_pin_setflags(sc->sclpin, in gpioiic_setscl()
212 gpio_pin_set_active(sc->sclpin, 0); in gpioiic_setscl()
222 gpio_pin_setflags(sc->sclpin, GPIO_PIN_INPUT); in gpioiic_getscl()
223 gpio_pin_is_active(sc->sclpin, &val); in gpioiic_getscl()
233 gpio_pin_setflags(sc->sdapin, GPIO_PIN_INPUT); in gpioiic_getsda()
234 gpio_pin_is_active(sc->sdapin, &val); in gpioiic_getsda()
243 /* Stop driving the bus pins. */ in gpioiic_reset()
244 gpio_pin_setflags(sc->sdapin, GPIO_PIN_INPUT); in gpioiic_reset()
245 gpio_pin_setflags(sc->sclpin, GPIO_PIN_INPUT); in gpioiic_reset()
255 device_delete_children(sc->dev); in gpioiic_cleanup()
257 if (sc->sclpin != NULL) in gpioiic_cleanup()
258 gpio_pin_release(sc->sclpin); in gpioiic_cleanup()
260 if (sc->sdapin != NULL) in gpioiic_cleanup()
261 gpio_pin_release(sc->sdapin); in gpioiic_cleanup()
278 ofw_bus_search_compatible(dev, compat_data)->ocd_data) in gpioiic_probe()
293 sc->dev = dev; in gpioiic_attach()
295 /* Acquire our gpio pins. */ in gpioiic_attach()
302 device_printf(sc->dev, "no pins configured\n"); in gpioiic_attach()
311 * that can provide our pins. in gpioiic_attach()
313 device_printf(dev, "SCL pin: %s:%d, SDA pin: %s:%d\n", in gpioiic_attach()
315 device_get_nameunit(GPIO_GET_BUS(sc->sclpin->dev)), sc->sclpin->pin, in gpioiic_attach()
316 device_get_nameunit(GPIO_GET_BUS(sc->sdapin->dev)), sc->sdapin->pin); in gpioiic_attach()
318 device_get_nameunit(device_get_parent(dev)), sc->sclpin->pin, in gpioiic_attach()
319 device_get_nameunit(device_get_parent(dev)), sc->sdapin->pin); in gpioiic_attach()
323 device_add_child(sc->dev, "iicbb", DEVICE_UNIT_ANY); in gpioiic_attach()