+int gpiochip_add_hog(struct gpio_chip *gc, struct fwnode_handle *fwnode)
+{
+ struct fwnode_handle *gc_node = dev_fwnode(&gc->gpiodev->dev);
+ struct fwnode_reference_args gpiospec;
+ enum gpiod_flags dflags;
+ struct gpio_desc *desc;
+ unsigned long lflags;
+ const char *name;
+ int ret, argc;
+ u32 gpios[3]; /* We support up to three-cell bindings. */
+ u32 cells;
+
+ lflags = GPIO_LOOKUP_FLAGS_DEFAULT;
+ dflags = GPIOD_ASIS;
+ name = NULL;
+
+ argc = fwnode_property_count_u32(fwnode, "gpios");
+ if (argc < 0)
+ return argc;
+ if (argc > 3)
+ return -EINVAL;
+
+ ret = fwnode_property_read_u32_array(fwnode, "gpios", gpios, argc);
+ if (ret < 0)
+ return ret;
+
+ if (is_of_node(fwnode)) {
+ /*
+ * OF-nodes need some additional special handling for
+ * translating of devicetree flags.
+ */
+ ret = fwnode_property_read_u32(gc_node, "#gpio-cells", &cells);
+ if (ret)
+ return ret;
+ if (!ret && argc != cells)
+ return -EINVAL;
+
+ memset(&gpiospec, 0, sizeof(gpiospec));
+ gpiospec.fwnode = fwnode;
+ gpiospec.nargs = argc;
+
+ for (int i = 0; i < argc; i++)
+ gpiospec.args[i] = gpios[i];
+
+ ret = of_gpiochip_get_lflags(gc, &gpiospec, &lflags);
+ if (ret)
+ return ret;
+ } else {
+ /*
+ * GPIO_ACTIVE_LOW is currently the only lookup flag
+ * supported for non-OF firmware nodes.
+ */
+ if (gpios[1])
+ lflags |= GPIO_ACTIVE_LOW;
+ }
+
+ if (fwnode_property_present(fwnode, "input"))
+ dflags |= GPIOD_IN;
+ else if (fwnode_property_present(fwnode, "output-low"))
+ dflags |= GPIOD_OUT_LOW;
+ else if (fwnode_property_present(fwnode, "output-high"))
+ dflags |= GPIOD_OUT_HIGH;
+ else
+ return -EINVAL;
+
+ fwnode_property_read_string(fwnode, "line-name", &name);
+
+ desc = gpiochip_get_desc(gc, gpios[0]);
+ if (IS_ERR(desc))
+ return PTR_ERR(desc);
+
+ return gpiod_hog(desc, name, lflags, dflags);
+}
+
+static int gpiochip_hog_lines(struct gpio_chip *gc)
+{
+ int ret;
+
+ device_for_each_child_node_scoped(&gc->gpiodev->dev, fwnode) {
+ if (!fwnode_property_present(fwnode, "gpio-hog"))
+ continue;
+
+ ret = gpiochip_add_hog(gc, fwnode);
+ if (ret)
+ return ret;
+ }
+
+ gpiochip_machine_hog_lines(gc);
+
+ return 0;
+}
+