static int imx_chipidea_probe_dt(struct imx_chipidea *ci) { const void *out_args; struct device_node *usbmisc_np; enum usb_dr_mode mode; enum usb_phy_interface phymode; of_parse_phandles_with_args(ci->dev->device_node, "fsl,usbmisc", "#index-cells", 0, &usbmisc_np, &out_args); ci->portno = be32_to_cpup(out_args); ci->flags = MXC_EHCI_MODE_UTMI_8BIT; mode = of_usb_get_dr_mode(ci->dev->device_node, NULL); switch (mode) { case USB_DR_MODE_HOST: default: ci->mode = IMX_USB_MODE_HOST; break; case USB_DR_MODE_PERIPHERAL: ci->mode = IMX_USB_MODE_DEVICE; break; } phymode = of_usb_get_phy_mode(ci->dev->device_node, NULL); switch (phymode) { case USBPHY_INTERFACE_MODE_UTMI: ci->flags = MXC_EHCI_MODE_UTMI_8BIT; break; case USBPHY_INTERFACE_MODE_UTMIW: ci->flags = MXC_EHCI_MODE_UTMI_16_BIT; break; case USBPHY_INTERFACE_MODE_ULPI: ci->flags = MXC_EHCI_MODE_ULPI; break; case USBPHY_INTERFACE_MODE_SERIAL: ci->flags = MXC_EHCI_MODE_SERIAL; break; case USBPHY_INTERFACE_MODE_HSIC: ci->flags = MXC_EHCI_MODE_HSIC; break; default: dev_err(ci->dev, "no or invalid phy mode setting\n"); return -EINVAL; } if (of_find_property(ci->dev->device_node, "disable-over-current")) ci->flags |= MXC_EHCI_DISABLE_OVERCURRENT; return 0; }
/** * of_get_named_gpio_flags() - Get a GPIO number and flags to use with GPIO API * @np: device node to get GPIO from * @propname: property name containing gpio specifier(s) * @index: index of the GPIO * @flags: a flags pointer to fill in * * Returns GPIO number to use with Linux generic GPIO API, or one of the errno * value on the error condition. If @flags is not NULL the function also fills * in flags for the GPIO. */ int of_get_named_gpio_flags(struct device_node *np, const char *propname, int index, enum of_gpio_flags *flags) { int ret; struct device_node *gpio_np; struct gpio_chip *gc; int size; const void *gpio_spec; const __be32 *gpio_cells; ret = of_parse_phandles_with_args(np, propname, "#gpio-cells", index, &gpio_np, &gpio_spec); if (ret) { pr_debug("%s: can't parse gpios property\n", __func__); goto err0; } gc = of_node_to_gpiochip(gpio_np); if (!gc) { pr_debug("%s: gpio controller %s isn't registered\n", np->full_name, gpio_np->full_name); ret = -ENODEV; goto err1; } gpio_cells = of_get_property(gpio_np, "#gpio-cells", &size); if (!gpio_cells || size != sizeof(*gpio_cells) || be32_to_cpup(gpio_cells) != gc->of_gpio_n_cells) { pr_debug("%s: wrong #gpio-cells for %s\n", np->full_name, gpio_np->full_name); ret = -EINVAL; goto err1; } /* .xlate might decide to not fill in the flags, so clear it. */ if (flags) *flags = 0; ret = gc->of_xlate(gc, np, gpio_spec, flags); if (ret < 0) goto err1; ret += gc->base; err1: of_node_put(gpio_np); err0: pr_debug("%s exited with status %d\n", __func__, ret); return ret; }
/** * of_gpio_count - Count GPIOs for a device * @np: device node to count GPIOs for * * The function returns the count of GPIOs specified for a node. * * Note that the empty GPIO specifiers counts too. For example, * * gpios = <0 * &pio1 1 2 * 0 * &pio2 3 4>; * * defines four GPIOs (so this function will return 4), two of which * are not specified. */ unsigned int of_gpio_count(struct device_node *np) { unsigned int cnt = 0; do { int ret; ret = of_parse_phandles_with_args(np, "gpios", "#gpio-cells", cnt, NULL, NULL); /* A hole in the gpios = <> counts anyway. */ if (ret < 0 && ret != -EEXIST) break; } while (++cnt); return cnt; }
static int of_reset_gpio_handle(void) { int ret; /* variable which stored handle reset gpio pin */ struct device_node *root; /* root node */ struct device_node *gpio; /* gpio node */ struct gpio_chip *gc; u32 flags; const void *gpio_spec; /* find out root node */ root = of_find_node_by_path("/"); /* give me handle for gpio node to be possible allocate pin */ ret = of_parse_phandles_with_args(root, "hard-reset-gpios", "#gpio-cells", 0, &gpio, &gpio_spec); if (ret) { pr_debug("%s: can't parse gpios property\n", __func__); goto err0; } gc = of_node_to_gpiochip(gpio); if (!gc) { pr_debug("%s: gpio controller %s isn't registered\n", root->full_name, gpio->full_name); ret = -ENODEV; goto err1; } ret = gc->of_xlate(gc, root, gpio_spec, &flags); if (ret < 0) goto err1; ret += gc->base; err1: of_node_put(gpio); err0: pr_debug("%s exited with status %d\n", __func__, ret); return ret; }