static int tegra30_spi_ofdata_to_platdata(struct udevice *bus) { struct tegra_spi_platdata *plat = bus->platdata; const void *blob = gd->fdt_blob; int node = bus->of_offset; plat->base = fdtdec_get_addr(blob, node, "reg"); plat->periph_id = clock_decode_periph_id(blob, node); if (plat->periph_id == PERIPH_ID_NONE) { debug("%s: could not decode periph id %d\n", __func__, plat->periph_id); return -FDT_ERR_NOTFOUND; } /* Use 500KHz as a suitable default */ plat->frequency = fdtdec_get_int(blob, node, "spi-max-frequency", 500000); plat->deactivate_delay_us = fdtdec_get_int(blob, node, "spi-deactivate-delay", 0); debug("%s: base=%#08lx, periph_id=%d, max-frequency=%d, deactivate_delay=%d\n", __func__, plat->base, plat->periph_id, plat->frequency, plat->deactivate_delay_us); return 0; }
static int i2c_get_config(const void *blob, int node, struct i2c_bus *i2c_bus) { i2c_bus->regs = (struct i2c_ctlr *)fdtdec_get_addr(blob, node, "reg"); /* * We don't have a binding for pinmux yet. Leave it out for now. So * far no one needs anything other than the default. */ i2c_bus->pinmux_config = FUNCMUX_DEFAULT; i2c_bus->speed = fdtdec_get_int(blob, node, "clock-frequency", 0); i2c_bus->periph_id = clock_decode_periph_id(blob, node); /* * We can't specify the pinmux config in the fdt, so I2C2 will not * work on Seaboard. It normally has no devices on it anyway. * You could add in this little hack if you need to use it. * The correct solution is a pinmux binding in the fdt. * * if (i2c_bus->periph_id == PERIPH_ID_I2C2) * i2c_bus->pinmux_config = FUNCMUX_I2C2_PTA; */ if (i2c_bus->periph_id == -1) return -FDT_ERR_NOTFOUND; return 0; }
static int fdt_decode_usb(const void *blob, int node, struct fdt_usb *config) { const char *phy, *mode; config->reg = (struct usb_ctlr *)fdtdec_get_addr(blob, node, "reg"); mode = fdt_getprop(blob, node, "dr_mode", NULL); if (mode) { if (0 == strcmp(mode, "host")) config->dr_mode = DR_MODE_HOST; else if (0 == strcmp(mode, "peripheral")) config->dr_mode = DR_MODE_DEVICE; else if (0 == strcmp(mode, "otg")) config->dr_mode = DR_MODE_OTG; else { debug("%s: Cannot decode dr_mode '%s'\n", __func__, mode); return -FDT_ERR_NOTFOUND; } } else { config->dr_mode = DR_MODE_HOST; } phy = fdt_getprop(blob, node, "phy_type", NULL); config->utmi = phy && 0 == strcmp("utmi", phy); config->ulpi = phy && 0 == strcmp("ulpi", phy); config->enabled = fdtdec_get_is_enabled(blob, node); config->has_legacy_mode = fdtdec_get_bool(blob, node, "nvidia,has-legacy-mode"); if (config->has_legacy_mode) port_addr_clear_csc = (u32) config->reg; config->periph_id = clock_decode_periph_id(blob, node); if (config->periph_id == PERIPH_ID_NONE) { debug("%s: Missing/invalid peripheral ID\n", __func__); return -FDT_ERR_NOTFOUND; } fdtdec_decode_gpio(blob, node, "nvidia,vbus-gpio", &config->vbus_gpio); fdtdec_decode_gpio(blob, node, "nvidia,phy-reset-gpio", &config->phy_reset_gpio); debug("enabled=%d, legacy_mode=%d, utmi=%d, ulpi=%d, periph_id=%d, " "vbus=%d, phy_reset=%d, dr_mode=%d\n", config->enabled, config->has_legacy_mode, config->utmi, config->ulpi, config->periph_id, config->vbus_gpio.gpio, config->phy_reset_gpio.gpio, config->dr_mode); return 0; }
/** * Get the host address and peripheral ID for a node. * * @param blob fdt blob * @param node Device index (0-3) * @param host Structure to fill in (reg, width, mmc_id) */ static int mmc_get_config(const void *blob, int node, struct mmc_host *host, bool *removablep) { debug("%s: node = %d\n", __func__, node); host->enabled = fdtdec_get_is_enabled(blob, node); host->reg = (struct tegra_mmc *)fdtdec_get_addr(blob, node, "reg"); if ((fdt_addr_t)host->reg == FDT_ADDR_T_NONE) { debug("%s: no sdmmc base reg info found\n", __func__); return -FDT_ERR_NOTFOUND; } host->mmc_id = clock_decode_periph_id(blob, node); if (host->mmc_id == PERIPH_ID_NONE) { debug("%s: could not decode periph id\n", __func__); return -FDT_ERR_NOTFOUND; } /* * NOTE: mmc->bus_width is determined by mmc.c dynamically. * TBD: Override it with this value? */ host->width = fdtdec_get_int(blob, node, "bus-width", 0); if (!host->width) debug("%s: no sdmmc width found\n", __func__); /* These GPIOs are optional */ gpio_request_by_name_nodev(blob, node, "cd-gpios", 0, &host->cd_gpio, GPIOD_IS_IN); gpio_request_by_name_nodev(blob, node, "wp-gpios", 0, &host->wp_gpio, GPIOD_IS_IN); gpio_request_by_name_nodev(blob, node, "power-gpios", 0, &host->pwr_gpio, GPIOD_IS_OUT); *removablep = !fdtdec_get_bool(blob, node, "non-removable"); debug("%s: found controller at %p, width = %d, periph_id = %d\n", __func__, host->reg, host->width, host->mmc_id); return 0; }
/** * Get the host address and peripheral ID for a node. * * @param blob fdt blob * @param node Device index (0-3) * @param host Structure to fill in (reg, width, mmc_id) */ static int mmc_get_config(const void *blob, int node, struct mmc_host *host, bool *removablep) { debug("%s: node = %d\n", __func__, node); host->enabled = fdtdec_get_is_enabled(blob, node); host->reg = (struct tegra_mmc *)fdtdec_get_addr(blob, node, "reg"); if ((fdt_addr_t)host->reg == FDT_ADDR_T_NONE) { debug("%s: no sdmmc base reg info found\n", __func__); return -FDT_ERR_NOTFOUND; } #ifdef CONFIG_TEGRA186 { /* * FIXME: This variable should go away when the MMC device * actually is a udevice. */ struct udevice dev; int ret; dev.of_offset = node; ret = reset_get_by_name(&dev, "sdhci", &host->reset_ctl); if (ret) { debug("reset_get_by_name() failed: %d\n", ret); return ret; } ret = clk_get_by_index(&dev, 0, &host->clk); if (ret) { debug("clk_get_by_index() failed: %d\n", ret); return ret; } } #else host->mmc_id = clock_decode_periph_id(blob, node); if (host->mmc_id == PERIPH_ID_NONE) { debug("%s: could not decode periph id\n", __func__); return -FDT_ERR_NOTFOUND; } #endif /* * NOTE: mmc->bus_width is determined by mmc.c dynamically. * TBD: Override it with this value? */ host->width = fdtdec_get_int(blob, node, "bus-width", 0); if (!host->width) debug("%s: no sdmmc width found\n", __func__); /* These GPIOs are optional */ gpio_request_by_name_nodev(blob, node, "cd-gpios", 0, &host->cd_gpio, GPIOD_IS_IN); gpio_request_by_name_nodev(blob, node, "wp-gpios", 0, &host->wp_gpio, GPIOD_IS_IN); gpio_request_by_name_nodev(blob, node, "power-gpios", 0, &host->pwr_gpio, GPIOD_IS_OUT); *removablep = !fdtdec_get_bool(blob, node, "non-removable"); debug("%s: found controller at %p, width = %d, periph_id = %d\n", __func__, host->reg, host->width, #ifndef CONFIG_TEGRA186 host->mmc_id #else -1 #endif ); return 0; }