Lines Matching +full:a +full:- +full:child +full:- +full:node +full:- +full:property
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
71 rv = ofw_bus_parse_xref_list_alloc(cnode, prop_name, "#gpio-cells", in gpio_pin_get_by_ofw_propidx()
109 gpio_pin_get_by_ofw_idx(device_t consumer, phandle_t node, in gpio_pin_get_by_ofw_idx() argument
113 return (gpio_pin_get_by_ofw_propidx(consumer, node, "gpios", idx, pin)); in gpio_pin_get_by_ofw_idx()
117 gpio_pin_get_by_ofw_property(device_t consumer, phandle_t node, in gpio_pin_get_by_ofw_property() argument
121 return (gpio_pin_get_by_ofw_propidx(consumer, node, name, 0, pin)); in gpio_pin_get_by_ofw_property()
125 gpio_pin_get_by_ofw_name(device_t consumer, phandle_t node, in gpio_pin_get_by_ofw_name() argument
130 KASSERT(consumer != NULL && node > 0, in gpio_pin_get_by_ofw_name()
131 ("both consumer and node required")); in gpio_pin_get_by_ofw_name()
133 rv = ofw_bus_find_string_index(node, "gpio-names", name, &idx); in gpio_pin_get_by_ofw_name()
136 return (gpio_pin_get_by_ofw_idx(consumer, node, idx, pin)); in gpio_pin_get_by_ofw_name()
143 ofw_gpiobus_add_fdt_child(device_t bus, const char *drvname, phandle_t child) in ofw_gpiobus_add_fdt_child() argument
151 * Check to see if we already have a child for @p child, and if so in ofw_gpiobus_add_fdt_child()
154 childdev = ofw_bus_find_child_device_by_phandle(bus, child); in ofw_gpiobus_add_fdt_child()
159 * Set up the GPIO child and OFW bus layer devinfo and add it to bus. in ofw_gpiobus_add_fdt_child()
164 dinfo = ofw_gpiobus_setup_devinfo(bus, childdev, child); in ofw_gpiobus_add_fdt_child()
174 /* Use the child name as pin name. */ in ofw_gpiobus_add_fdt_child()
175 devi = &dinfo->opd_dinfo; in ofw_gpiobus_add_fdt_child()
176 for (i = 0; i < devi->npins; i++) in ofw_gpiobus_add_fdt_child()
177 GPIOBUS_PIN_SETNAME(bus, devi->pins[i], in ofw_gpiobus_add_fdt_child()
195 phandle_t node; in ofw_gpiobus_register_provider() local
197 node = ofw_bus_get_node(provider); in ofw_gpiobus_register_provider()
198 if (node != -1) in ofw_gpiobus_register_provider()
199 OF_device_register_xref(OF_xref_from_node(node), provider); in ofw_gpiobus_register_provider()
205 phandle_t node; in ofw_gpiobus_unregister_provider() local
207 node = ofw_bus_get_node(provider); in ofw_gpiobus_unregister_provider()
208 if (node != -1) in ofw_gpiobus_unregister_provider()
209 OF_device_register_xref(OF_xref_from_node(node), NULL); in ofw_gpiobus_unregister_provider()
213 ofw_gpiobus_setup_devinfo(device_t bus, device_t child, phandle_t node) in ofw_gpiobus_setup_devinfo() argument
225 if (ofw_bus_gen_setup_devinfo(&dinfo->opd_obdinfo, node) != 0) { in ofw_gpiobus_setup_devinfo()
229 /* Parse the gpios property for the child. */ in ofw_gpiobus_setup_devinfo()
230 npins = ofw_gpiobus_parse_gpios_impl(child, node, "gpios", sc, &pins); in ofw_gpiobus_setup_devinfo()
232 ofw_bus_gen_destroy_devinfo(&dinfo->opd_obdinfo); in ofw_gpiobus_setup_devinfo()
237 resource_list_init(&dinfo->opd_dinfo.rl); in ofw_gpiobus_setup_devinfo()
238 /* Allocate the child ivars and copy the parsed pin data. */ in ofw_gpiobus_setup_devinfo()
239 devi = &dinfo->opd_dinfo; in ofw_gpiobus_setup_devinfo()
240 devi->npins = (uint32_t)npins; in ofw_gpiobus_setup_devinfo()
246 for (i = 0; i < devi->npins; i++) in ofw_gpiobus_setup_devinfo()
247 devi->pins[i] = pins[i].pin; in ofw_gpiobus_setup_devinfo()
250 if (ofw_bus_intr_to_rl(bus, node, &dinfo->opd_dinfo.rl, NULL) != 0) { in ofw_gpiobus_setup_devinfo()
254 device_set_ivars(child, dinfo); in ofw_gpiobus_setup_devinfo()
267 devi = &dinfo->opd_dinfo; in ofw_gpiobus_destroy_devinfo()
268 for (i = 0; i < devi->npins; i++) { in ofw_gpiobus_destroy_devinfo()
269 if (devi->pins[i] > sc->sc_npins) in ofw_gpiobus_destroy_devinfo()
271 sc->sc_pins[devi->pins[i]].mapped = 0; in ofw_gpiobus_destroy_devinfo()
274 resource_list_free(&dinfo->opd_dinfo.rl); in ofw_gpiobus_destroy_devinfo()
275 ofw_bus_gen_destroy_devinfo(&dinfo->opd_obdinfo); in ofw_gpiobus_destroy_devinfo()
289 if (ncells == -1) { in ofw_gpiobus_parse_gpios_impl()
293 return (-1); in ofw_gpiobus_parse_gpios_impl()
296 * The gpio-specifier is controller independent, the first pcell has in ofw_gpiobus_parse_gpios_impl()
298 * Count the number of encoded gpio-specifiers on the first pass. in ofw_gpiobus_parse_gpios_impl()
312 if (ofw_bus_get_node(bussc->sc_dev) != gpio) in ofw_gpiobus_parse_gpios_impl()
315 * Check for gpio-controller property and read the #gpio-cells in ofw_gpiobus_parse_gpios_impl()
318 if (!OF_hasprop(gpio, "gpio-controller") || in ofw_gpiobus_parse_gpios_impl()
319 OF_getencprop(gpio, "#gpio-cells", &gpiocells, in ofw_gpiobus_parse_gpios_impl()
322 "gpio reference is not a gpio-controller.\n"); in ofw_gpiobus_parse_gpios_impl()
324 return (-1); in ofw_gpiobus_parse_gpios_impl()
326 if (ncells - i < gpiocells + 1) { in ofw_gpiobus_parse_gpios_impl()
328 "%s cells doesn't match #gpio-cells.\n", pname); in ofw_gpiobus_parse_gpios_impl()
329 return (-1); in ofw_gpiobus_parse_gpios_impl()
345 return (-1); in ofw_gpiobus_parse_gpios_impl()
358 /* Read gpio-cells property for this GPIO controller. */ in ofw_gpiobus_parse_gpios_impl()
359 if (OF_getencprop(gpio, "#gpio-cells", &gpiocells, in ofw_gpiobus_parse_gpios_impl()
362 "gpio does not have the #gpio-cells property.\n"); in ofw_gpiobus_parse_gpios_impl()
375 * the child is probed and attached. in ofw_gpiobus_parse_gpios_impl()
394 if (gpiobus_acquire_pin(bussc->sc_busdev, (*pins)[j].pin) != 0) in ofw_gpiobus_parse_gpios_impl()
406 return (-1); in ofw_gpiobus_parse_gpios_impl()
413 if (ofw_bus_get_node(dev) == -1) in ofw_gpiobus_probe()
424 phandle_t child; in ofw_gpiobus_attach() local
434 for (child = OF_child(ofw_bus_get_node(dev)); child != 0; in ofw_gpiobus_attach()
435 child = OF_peer(child)) { in ofw_gpiobus_attach()
436 if (OF_hasprop(child, "gpio-hog")) in ofw_gpiobus_attach()
438 if (!OF_hasprop(child, "gpios")) in ofw_gpiobus_attach()
440 if (ofw_gpiobus_add_fdt_child(dev, NULL, child) == NULL) in ofw_gpiobus_attach()
451 device_t child; in ofw_gpiobus_add_child() local
454 child = device_add_child_ordered(dev, order, name, unit); in ofw_gpiobus_add_child()
455 if (child == NULL) in ofw_gpiobus_add_child()
456 return (child); in ofw_gpiobus_add_child()
460 device_delete_child(dev, child); in ofw_gpiobus_add_child()
465 * NULL all the OFW-related parts of the ivars for non-OFW in ofw_gpiobus_add_child()
468 devi->opd_obdinfo.obd_node = -1; in ofw_gpiobus_add_child()
469 devi->opd_obdinfo.obd_name = NULL; in ofw_gpiobus_add_child()
470 devi->opd_obdinfo.obd_compat = NULL; in ofw_gpiobus_add_child()
471 devi->opd_obdinfo.obd_type = NULL; in ofw_gpiobus_add_child()
472 devi->opd_obdinfo.obd_model = NULL; in ofw_gpiobus_add_child()
474 device_set_ivars(child, devi); in ofw_gpiobus_add_child()
476 return (child); in ofw_gpiobus_add_child()
486 return (&dinfo->opd_obdinfo); in ofw_gpiobus_get_devinfo()