int board_late_init(void) { struct gpio_desc gpio = {}; int node; node = fdt_node_offset_by_compatible(gd->fdt_blob, 0, "st,led1"); if (node < 0) return -1; gpio_request_by_name_nodev(offset_to_ofnode(node), "led-gpio", 0, &gpio, GPIOD_IS_OUT); if (dm_gpio_is_valid(&gpio)) { dm_gpio_set_value(&gpio, 0); mdelay(10); dm_gpio_set_value(&gpio, 1); } /* read button 1*/ node = fdt_node_offset_by_compatible(gd->fdt_blob, 0, "st,button1"); if (node < 0) return -1; gpio_request_by_name_nodev(offset_to_ofnode(node), "button-gpio", 0, &gpio, GPIOD_IS_IN); if (dm_gpio_is_valid(&gpio)) { if (dm_gpio_get_value(&gpio)) puts("usr button is at HIGH LEVEL\n"); else puts("usr button is at LOW LEVEL\n"); } return 0; }
static int led_7seg_init(unsigned int segments) { int node; int ret; int i; struct gpio_desc desc[8]; node = fdt_node_offset_by_compatible(gd->fdt_blob, 0, "atl,of-led-7seg"); if (node < 0) return -ENODEV; ret = gpio_request_list_by_name_nodev(offset_to_ofnode(node), "segment-gpios", desc, ARRAY_SIZE(desc), GPIOD_IS_OUT); if (ret < 0) return ret; for (i = 0; i < ARRAY_SIZE(desc); i++) { ret = dm_gpio_set_value(&desc[i], !(segments & BIT(i))); if (ret) return ret; } return 0; }
/* Check for vol- button - if pressed - stop autoboot */ int misc_init_r(void) { struct udevice *pon; struct gpio_desc resin; int node, ret; ret = uclass_get_device_by_name(UCLASS_GPIO, "pm8916_pon@800", &pon); if (ret < 0) { printf("Failed to find PMIC pon node. Check device tree\n"); return 0; } node = fdt_subnode_offset(gd->fdt_blob, dev_of_offset(pon), "key_vol_down"); if (node < 0) { printf("Failed to find key_vol_down node. Check device tree\n"); return 0; } if (gpio_request_by_name_nodev(offset_to_ofnode(node), "gpios", 0, &resin, 0)) { printf("Failed to request key_vol_down button.\n"); return 0; } if (dm_gpio_get_value(&resin)) { env_set("bootdelay", "-1"); printf("Power button pressed - dropping to console.\n"); } return 0; }
static int ks2_eth_bind_slaves(struct udevice *dev, int gbe, int *gbe_0) { const void *fdt = gd->fdt_blob; struct udevice *sl_dev; int interfaces; int sec_slave; int slave; int ret; char *slave_name; interfaces = fdt_subnode_offset(fdt, gbe, "interfaces"); fdt_for_each_subnode(slave, fdt, interfaces) { int slave_no; slave_no = fdtdec_get_int(fdt, slave, "slave-port", -ENOENT); if (slave_no == -ENOENT) continue; if (slave_no == 0) { /* This is the current eth device */ *gbe_0 = slave; } else { /* Slave devices to be registered */ slave_name = malloc(20); snprintf(slave_name, 20, "netcp@slave-%d", slave_no); ret = device_bind_driver_to_node(dev, "eth_ks2_sl", slave_name, offset_to_ofnode(slave), &sl_dev); if (ret) { pr_err("ks2_net - not able to bind slave interfaces\n"); return ret; } } }
static int vf_usb_ofdata_to_platdata(struct udevice *dev) { struct ehci_vf_priv_data *priv = dev_get_priv(dev); const void *dt_blob = gd->fdt_blob; int node = dev_of_offset(dev); const char *mode; priv->portnr = dev->seq; priv->ehci = (struct usb_ehci *)devfdt_get_addr(dev); mode = fdt_getprop(dt_blob, node, "dr_mode", NULL); if (mode) { if (0 == strcmp(mode, "host")) { priv->dr_mode = DR_MODE_HOST; priv->init_type = USB_INIT_HOST; } else if (0 == strcmp(mode, "peripheral")) { priv->dr_mode = DR_MODE_DEVICE; priv->init_type = USB_INIT_DEVICE; } else if (0 == strcmp(mode, "otg")) { priv->dr_mode = DR_MODE_OTG; /* * We set init_type to device by default when OTG * mode is requested. If a valid gpio is provided * we will switch the init_type based on the state * of the gpio pin. */ priv->init_type = USB_INIT_DEVICE; } else { debug("%s: Cannot decode dr_mode '%s'\n", __func__, mode); return -EINVAL; } } else { priv->dr_mode = DR_MODE_HOST; priv->init_type = USB_INIT_HOST; } if (priv->dr_mode == DR_MODE_OTG) { gpio_request_by_name_nodev(offset_to_ofnode(node), "fsl,cdet-gpio", 0, &priv->cdet_gpio, GPIOD_IS_IN); if (dm_gpio_is_valid(&priv->cdet_gpio)) { if (dm_gpio_get_value(&priv->cdet_gpio)) priv->init_type = USB_INIT_DEVICE; else priv->init_type = USB_INIT_HOST; } } return 0; }
/** * at91_clk_sub_device_bind() - for the at91 clock driver * Recursively bind its children as clk devices. * * @return: 0 on success, or negative error code on failure */ int at91_clk_sub_device_bind(struct udevice *dev, const char *drv_name) { const void *fdt = gd->fdt_blob; int offset = dev_of_offset(dev); bool pre_reloc_only = !(gd->flags & GD_FLG_RELOC); const char *name; int ret; for (offset = fdt_first_subnode(fdt, offset); offset > 0; offset = fdt_next_subnode(fdt, offset)) { if (pre_reloc_only && !dm_ofnode_pre_reloc(offset_to_ofnode(offset))) continue; /* * If this node has "compatible" property, this is not * a clock sub-node, but a normal device. skip. */ fdt_get_property(fdt, offset, "compatible", &ret); if (ret >= 0) continue; if (ret != -FDT_ERR_NOTFOUND) return ret; name = fdt_get_name(fdt, offset, NULL); if (!name) return -EINVAL; ret = device_bind_driver_to_node(dev, drv_name, name, offset_to_ofnode(offset), NULL); if (ret) return ret; } return 0; }
fdt_for_each_subnode(slave, fdt, sec_slave) { int slave_no; slave_no = fdtdec_get_int(fdt, slave, "slave-port", -ENOENT); if (slave_no == -ENOENT) continue; /* Slave devices to be registered */ slave_name = malloc(20); snprintf(slave_name, 20, "netcp@slave-%d", slave_no); ret = device_bind_driver_to_node(dev, "eth_ks2_sl", slave_name, offset_to_ofnode(slave), &sl_dev); if (ret) { pr_err("ks2_net - not able to bind slave interfaces\n"); return ret; } }
int show_board_info(void) { struct regmap *regmap; int nodeoffset, ret; ofnode node; unsigned int socinfo; /* find the offset of compatible node */ nodeoffset = fdt_node_offset_by_compatible(gd->fdt_blob, -1, "amlogic,meson-gx-ao-secure"); if (nodeoffset < 0) return 0; /* check if chip-id is available */ if (!fdt_getprop(gd->fdt_blob, nodeoffset, "amlogic,has-chip-id", NULL)) return 0; /* get regmap from the syscon node */ node = offset_to_ofnode(nodeoffset); regmap = syscon_node_to_regmap(node); if (IS_ERR(regmap)) { printf("%s: failed to get regmap\n", __func__); return 0; } /* read soc info */ ret = regmap_read(regmap, AO_SEC_SOCINFO_OFFSET, &socinfo); if (ret && !socinfo) { printf("%s: invalid chipid value\n", __func__); return 0; } /* print board information */ print_board_model(); printf("Soc: Amlogic Meson %s (%s) Revision %x:%x (%x:%x)\n", socinfo_to_soc_id(socinfo), socinfo_to_package_id(socinfo), socinfo_to_major(socinfo), socinfo_to_minor(socinfo), socinfo_to_pack(socinfo), socinfo_to_misc(socinfo)); return 0; }
int notrace dm_timer_init(void) { __maybe_unused const void *blob = gd->fdt_blob; struct udevice *dev = NULL; int node = -ENOENT; int ret; if (gd->timer) return 0; #if !CONFIG_IS_ENABLED(OF_PLATDATA) /* Check for a chosen timer to be used for tick */ node = fdtdec_get_chosen_node(blob, "tick-timer"); #endif if (node < 0) { /* No chosen timer, trying first available timer */ ret = uclass_first_device_err(UCLASS_TIMER, &dev); if (ret) return ret; } else { if (uclass_get_device_by_of_offset(UCLASS_TIMER, node, &dev)) { /* * If the timer is not marked to be bound before * relocation, bind it anyway. */ if (node > 0 && !lists_bind_fdt(gd->dm_root, offset_to_ofnode(node), &dev)) { ret = device_probe(dev); if (ret) return ret; } } } if (dev) { gd->timer = dev; return 0; } return -ENODEV; }
static int serial_check_stdout(const void *blob, struct udevice **devp) { int node; /* Check for a chosen console */ node = fdtdec_get_chosen_node(blob, "stdout-path"); if (node < 0) { const char *str, *p, *name; /* * Deal with things like * stdout-path = "serial0:115200n8"; * * We need to look up the alias and then follow it to the * correct node. */ str = fdtdec_get_chosen_prop(blob, "stdout-path"); if (str) { p = strchr(str, ':'); name = fdt_get_alias_namelen(blob, str, p ? p - str : strlen(str)); if (name) node = fdt_path_offset(blob, name); } } if (node < 0) node = fdt_path_offset(blob, "console"); if (!uclass_get_device_by_of_offset(UCLASS_SERIAL, node, devp)) return 0; /* * If the console is not marked to be bound before relocation, bind it * anyway. */ if (node > 0 && !lists_bind_fdt(gd->dm_root, offset_to_ofnode(node), devp)) { if (!device_probe(*devp)) return 0; } return -ENODEV; }
static int ti_musb_wrapper_bind(struct udevice *parent) { const void *fdt = gd->fdt_blob; int node; int ret; for (node = fdt_first_subnode(fdt, dev_of_offset(parent)); node > 0; node = fdt_next_subnode(fdt, node)) { struct udevice *dev; const char *name = fdt_get_name(fdt, node, NULL); enum usb_dr_mode dr_mode; struct driver *drv; if (strncmp(name, "usb@", 4)) continue; dr_mode = usb_get_dr_mode(node); switch (dr_mode) { case USB_DR_MODE_PERIPHERAL: /* Bind MUSB device */ break; case USB_DR_MODE_HOST: /* Bind MUSB host */ ret = device_bind_driver_to_node(parent, "ti-musb-host", name, offset_to_ofnode(node), &dev); if (ret) { pr_err("musb - not able to bind usb host node\n"); return ret; } break; default: break; }; } return 0; }
int board_prepare_usb(enum usb_init_type type) { static struct udevice *pmic_gpio; static struct gpio_desc hub_reset, usb_sel; int ret = 0, node; if (!pmic_gpio) { ret = uclass_get_device_by_name(UCLASS_GPIO, "pm8916_gpios@c000", &pmic_gpio); if (ret < 0) { printf("Failed to find pm8916_gpios@c000 node.\n"); return ret; } } /* Try to request gpios needed to start usb host on dragonboard */ if (!dm_gpio_is_valid(&hub_reset)) { node = fdt_subnode_offset(gd->fdt_blob, dev_of_offset(pmic_gpio), "usb_hub_reset_pm"); if (node < 0) { printf("Failed to find usb_hub_reset_pm dt node.\n"); return node; } ret = gpio_request_by_name_nodev(offset_to_ofnode(node), "gpios", 0, &hub_reset, 0); if (ret < 0) { printf("Failed to request usb_hub_reset_pm gpio.\n"); return ret; } } if (!dm_gpio_is_valid(&usb_sel)) { node = fdt_subnode_offset(gd->fdt_blob, dev_of_offset(pmic_gpio), "usb_sw_sel_pm"); if (node < 0) { printf("Failed to find usb_sw_sel_pm dt node.\n"); return 0; } ret = gpio_request_by_name_nodev(offset_to_ofnode(node), "gpios", 0, &usb_sel, 0); if (ret < 0) { printf("Failed to request usb_sw_sel_pm gpio.\n"); return ret; } } if (type == USB_INIT_HOST) { /* Start USB Hub */ dm_gpio_set_dir_flags(&hub_reset, GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE); mdelay(100); /* Switch usb to host connectors */ dm_gpio_set_dir_flags(&usb_sel, GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE); mdelay(100); } else { /* Device */ /* Disable hub */ dm_gpio_set_dir_flags(&hub_reset, GPIOD_IS_OUT); /* Switch back to device connector */ dm_gpio_set_dir_flags(&usb_sel, GPIOD_IS_OUT); } return 0; }