int __weak soc_clk_dump(void) { #if defined(CONFIG_DM) && defined(CONFIG_CLK) struct udevice *dev; struct uclass *uc; struct clk clk; int ret; /* Device addresses start at 1 */ ret = uclass_get(UCLASS_CLK, &uc); if (ret) return ret; uclass_foreach_dev(dev, uc) { memset(&clk, 0, sizeof(clk)); ret = device_probe(dev); if (ret) { printf("%-30.30s : ? Hz\n", dev->name); continue; } ret = clk_request(dev, &clk); if (ret) { printf("%-30.30s : ? Hz\n", dev->name); continue; } printf("%-30.30s : %lu Hz\n", dev->name, clk_get_rate(&clk)); clk_free(&clk); }
static int rcar_gpio_probe(struct udevice *dev) { struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev); struct rcar_gpio_priv *priv = dev_get_priv(dev); struct fdtdec_phandle_args args; struct clk clk; int node = dev_of_offset(dev); int ret; priv->regs = (void __iomem *)devfdt_get_addr(dev); uc_priv->bank_name = dev->name; ret = fdtdec_parse_phandle_with_args(gd->fdt_blob, node, "gpio-ranges", NULL, 3, 0, &args); uc_priv->gpio_count = ret == 0 ? args.args[2] : RCAR_MAX_GPIO_PER_BANK; ret = clk_get_by_index(dev, 0, &clk); if (ret < 0) { dev_err(dev, "Failed to get GPIO bank clock\n"); return ret; } ret = clk_enable(&clk); clk_free(&clk); if (ret) { dev_err(dev, "Failed to enable GPIO bank clock\n"); return ret; } return 0; }
static int pic32_uart_probe(struct udevice *dev) { struct pic32_uart_priv *priv = dev_get_priv(dev); struct clk clk; fdt_addr_t addr; fdt_size_t size; int ret; /* get address */ addr = fdtdec_get_addr_size(gd->fdt_blob, dev->of_offset, "reg", &size); if (addr == FDT_ADDR_T_NONE) return -EINVAL; priv->base = ioremap(addr, size); /* get clock rate */ ret = clk_get_by_index(dev, 0, &clk); if (ret < 0) return ret; priv->uartclk = clk_get_rate(&clk); clk_free(&clk); /* initialize serial */ return pic32_serial_init(priv->base, priv->uartclk, CONFIG_BAUDRATE); }
static int at91_hlcdc_enable_clk(struct udevice *dev) { struct atmel_hlcdc_priv *priv = dev_get_priv(dev); struct clk clk; ulong clk_rate; int ret; ret = clk_get_by_index(dev, 0, &clk); if (ret) return -EINVAL; ret = clk_enable(&clk); if (ret) return ret; clk_rate = clk_get_rate(&clk); if (!clk_rate) { clk_disable(&clk); return -ENODEV; } priv->clk_rate = clk_rate; clk_free(&clk); return 0; }
static int at91_i2c_enable_clk(struct udevice *dev) { struct at91_i2c_bus *bus = dev_get_priv(dev); struct clk clk; ulong clk_rate; int ret; ret = clk_get_by_index(dev, 0, &clk); if (ret) return -EINVAL; ret = clk_enable(&clk); if (ret) return ret; clk_rate = clk_get_rate(&clk); if (!clk_rate) return -EINVAL; bus->bus_clk_rate = clk_rate; clk_free(&clk); return 0; }
static int atmel_spi_enable_clk(struct udevice *bus) { struct atmel_spi_priv *priv = dev_get_priv(bus); struct clk clk; ulong clk_rate; int ret; ret = clk_get_by_index(bus, 0, &clk); if (ret) return -EINVAL; ret = clk_enable(&clk); if (ret) return ret; clk_rate = clk_get_rate(&clk); if (!clk_rate) return -EINVAL; priv->bus_clk_rate = clk_rate; clk_free(&clk); return 0; }
static int atmel_serial_enable_clk(struct udevice *dev) { struct atmel_serial_priv *priv = dev_get_priv(dev); struct clk clk; ulong clk_rate; int ret; ret = clk_get_by_index(dev, 0, &clk); if (ret) return -EINVAL; if (dev_get_driver_data(dev) == CLK_TYPE_NORMAL) { ret = clk_enable(&clk); if (ret) return ret; } clk_rate = clk_get_rate(&clk); if (!clk_rate) return -EINVAL; priv->usart_clk_rate = clk_rate; clk_free(&clk); return 0; }
static int ehci_atmel_enable_clk(struct udevice *dev) { struct clk clk; int ret; ret = clk_get_by_index(dev, 0, &clk); if (ret) return ret; ret = clk_enable(&clk); if (ret) return ret; ret = clk_get_by_index(dev, 1, &clk); if (ret) return -EINVAL; ret = clk_enable(&clk); if (ret) return ret; clk_free(&clk); return 0; }
int soc_clk_ctl(const char *name, ulong *rate, enum clk_ctl_ops ctl) { int ret; ulong mhz_rate, priv_rate; struct clk clk; /* Dummy fmeas device, just to be able to use standard clk_* api */ struct udevice fmeas = { .name = "clk-fmeas", .node = ofnode_path("/clk-fmeas"), }; ret = clk_get_by_name(&fmeas, name, &clk); if (ret) { pr_err("clock '%s' not found, err=%d\n", name, ret); return ret; } if (ctl & CLK_ON) { ret = clk_enable(&clk); if (ret && ret != -ENOSYS && ret != -ENOTSUPP) return ret; } if ((ctl & CLK_SET) && rate) { priv_rate = ctl & CLK_MHZ ? (*rate) * HZ_IN_MHZ : *rate; ret = clk_set_rate(&clk, priv_rate); if (ret) return ret; } if (ctl & CLK_OFF) { ret = clk_disable(&clk); if (ret) { pr_err("clock '%s' can't be disabled, err=%d\n", name, ret); return ret; } } priv_rate = clk_get_rate(&clk); clk_free(&clk); mhz_rate = ceil(priv_rate, HZ_IN_MHZ); if (ctl & CLK_MHZ) priv_rate = mhz_rate; if ((ctl & CLK_GET) && rate) *rate = priv_rate; if ((ctl & CLK_PRINT) && (ctl & CLK_MHZ)) printf("HSDK: clock '%s' rate %lu MHz\n", name, priv_rate); else if (ctl & CLK_PRINT) printf("HSDK: clock '%s' rate %lu Hz\n", name, priv_rate); else debug("HSDK: clock '%s' rate %lu MHz\n", name, mhz_rate); return 0; }
static int do_clock(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { static const struct { char *name; int id; } clks[] = { { "osc", CLK_OSC }, { "apll", CLK_ARM }, { "dpll", CLK_DDR }, { "cpll", CLK_CODEC }, { "gpll", CLK_GENERAL }, #ifdef CONFIG_ROCKCHIP_RK3036 { "mpll", CLK_NEW }, #else { "npll", CLK_NEW }, #endif }; int ret, i; struct udevice *dev; ret = rockchip_get_clk(&dev); if (ret) { printf("clk-uclass not found\n"); return 0; } for (i = 0; i < ARRAY_SIZE(clks); i++) { struct clk clk; ulong rate; clk.id = clks[i].id; ret = clk_request(dev, &clk); if (ret < 0) continue; rate = clk_get_rate(&clk); printf("%s: %lu\n", clks[i].name, rate); clk_free(&clk); } return 0; }
int timer_init(void) { const u32 emask = SCUTIMER_CONTROL_AUTO_RELOAD_MASK | (TIMER_PRESCALE << SCUTIMER_CONTROL_PRESCALER_SHIFT) | SCUTIMER_CONTROL_ENABLE_MASK; struct udevice *dev; struct clk clk; int ret; ret = uclass_get_device_by_driver(UCLASS_CLK, DM_GET_DRIVER(zynq_clk), &dev); if (ret) return ret; clk.id = cpu_6or4x_clk; ret = clk_request(dev, &clk); if (ret < 0) return ret; gd->cpu_clk = clk_get_rate(&clk); clk_free(&clk); gd->arch.timer_rate_hz = (gd->cpu_clk / 2) / (TIMER_PRESCALE + 1); /* Load the timer counter register */ writel(0xFFFFFFFF, &timer_base->load); /* * Start the A9Timer device * Enable Auto reload mode, Clear prescaler control bits * Set prescaler value, Enable the decrementer */ clrsetbits_le32(&timer_base->control, SCUTIMER_CONTROL_PRESCALER_MASK, emask); /* Reset time */ gd->arch.lastinc = readl(&timer_base->counter) / (gd->arch.timer_rate_hz / CONFIG_SYS_HZ); gd->arch.tbl = 0; return 0; }
static ulong periph_get_rate(struct clk *clk) { struct udevice *dev; struct clk clk_dev; ulong clk_rate; int ret; dev = dev_get_parent(clk->dev); ret = clk_get_by_index(dev, 0, &clk_dev); if (ret) return ret; clk_rate = clk_get_rate(&clk_dev); clk_free(&clk_dev); return clk_rate; }
static int setup_arm_clock(void) { struct udevice *dev; struct clk clk; int ret; ret = rockchip_get_clk(&dev); if (ret) return ret; clk.id = CLK_ARM; ret = clk_request(dev, &clk); if (ret < 0) return ret; ret = clk_set_rate(&clk, 600000000); clk_free(&clk); return ret; }
int clk_release_all(struct clk *clk, int count) { int i, ret; for (i = 0; i < count; i++) { debug("%s(clk[%d]=%p)\n", __func__, i, &clk[i]); /* check if clock has been previously requested */ if (!clk[i].dev) continue; ret = clk_disable(&clk[i]); if (ret && ret != -ENOSYS) return ret; ret = clk_free(&clk[i]); if (ret && ret != -ENOSYS) return ret; } return 0; }
static int rk3288_clk_config(struct udevice *dev) { struct display_plat *uc_plat = dev_get_uclass_platdata(dev); struct clk clk; int ret; /* * Configure the maximum clock to permit whatever resolution the * monitor wants */ ret = clk_get_by_index(uc_plat->src_dev, 0, &clk); if (ret >= 0) { ret = clk_set_rate(&clk, 384000000); clk_free(&clk); } if (ret < 0) { debug("%s: Failed to set clock in source device '%s': ret=%d\n", __func__, uc_plat->src_dev->name, ret); return ret; } return 0; }
static int ehci_usb_probe(struct udevice *dev) { struct ehci_hccr *hccr; struct ehci_hcor *hcor; int i; for (i = 0; ; i++) { struct clk clk; int ret; ret = clk_get_by_index(dev, i, &clk); if (ret < 0) break; if (clk_enable(&clk)) printf("failed to enable clock %d\n", i); clk_free(&clk); } hccr = map_physmem(dev_get_addr(dev), 0x100, MAP_NOCACHE); hcor = (struct ehci_hcor *)((uintptr_t)hccr + HC_LENGTH(ehci_readl(&hccr->cr_capbase))); return ehci_register(dev, hccr, hcor, NULL, 0, USB_INIT_HOST); }
static int stm32_sdmmc2_probe(struct udevice *dev) { struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev); struct stm32_sdmmc2_plat *plat = dev_get_platdata(dev); struct stm32_sdmmc2_priv *priv = dev_get_priv(dev); struct mmc_config *cfg = &plat->cfg; int ret; priv->base = dev_read_addr(dev); if (priv->base == FDT_ADDR_T_NONE) return -EINVAL; if (dev_read_bool(dev, "st,negedge")) priv->clk_reg_msk |= SDMMC_CLKCR_NEGEDGE; if (dev_read_bool(dev, "st,dirpol")) priv->pwr_reg_msk |= SDMMC_POWER_DIRPOL; ret = clk_get_by_index(dev, 0, &priv->clk); if (ret) return ret; ret = clk_enable(&priv->clk); if (ret) goto clk_free; ret = reset_get_by_index(dev, 0, &priv->reset_ctl); if (ret) goto clk_disable; gpio_request_by_name(dev, "cd-gpios", 0, &priv->cd_gpio, GPIOD_IS_IN); cfg->f_min = 400000; cfg->f_max = dev_read_u32_default(dev, "max-frequency", 52000000); cfg->voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195; cfg->b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT; cfg->name = "STM32 SDMMC2"; cfg->host_caps = 0; if (cfg->f_max > 25000000) cfg->host_caps |= MMC_MODE_HS_52MHz | MMC_MODE_HS; switch (dev_read_u32_default(dev, "bus-width", 1)) { case 8: cfg->host_caps |= MMC_MODE_8BIT; case 4: cfg->host_caps |= MMC_MODE_4BIT; break; case 1: break; default: pr_err("invalid \"bus-width\" property, force to 1\n"); } upriv->mmc = &plat->mmc; return 0; clk_disable: clk_disable(&priv->clk); clk_free: clk_free(&priv->clk); return ret; }
static int ohci_usb_probe(struct udevice *dev) { struct ohci_regs *regs = (struct ohci_regs *)devfdt_get_addr(dev); struct generic_ohci *priv = dev_get_priv(dev); int i, err, ret, clock_nb, reset_nb; err = 0; priv->clock_count = 0; clock_nb = dev_count_phandle_with_args(dev, "clocks", "#clock-cells"); if (clock_nb > 0) { priv->clocks = devm_kcalloc(dev, clock_nb, sizeof(struct clk), GFP_KERNEL); if (!priv->clocks) return -ENOMEM; for (i = 0; i < clock_nb; i++) { err = clk_get_by_index(dev, i, &priv->clocks[i]); if (err < 0) break; err = clk_enable(&priv->clocks[i]); if (err) { pr_err("failed to enable clock %d\n", i); clk_free(&priv->clocks[i]); goto clk_err; } priv->clock_count++; } } else if (clock_nb != -ENOENT) { pr_err("failed to get clock phandle(%d)\n", clock_nb); return clock_nb; } priv->reset_count = 0; reset_nb = dev_count_phandle_with_args(dev, "resets", "#reset-cells"); if (reset_nb > 0) { priv->resets = devm_kcalloc(dev, reset_nb, sizeof(struct reset_ctl), GFP_KERNEL); if (!priv->resets) return -ENOMEM; for (i = 0; i < reset_nb; i++) { err = reset_get_by_index(dev, i, &priv->resets[i]); if (err < 0) break; err = reset_deassert(&priv->resets[i]); if (err) { pr_err("failed to deassert reset %d\n", i); reset_free(&priv->resets[i]); goto reset_err; } priv->reset_count++; } } else if (reset_nb != -ENOENT) { pr_err("failed to get reset phandle(%d)\n", reset_nb); goto clk_err; } err = generic_phy_get_by_index(dev, 0, &priv->phy); if (err) { if (err != -ENOENT) { pr_err("failed to get usb phy\n"); goto reset_err; } } else { err = generic_phy_init(&priv->phy); if (err) { pr_err("failed to init usb phy\n"); goto reset_err; } } err = ohci_register(dev, regs); if (err) goto phy_err; return 0; phy_err: if (generic_phy_valid(&priv->phy)) { ret = generic_phy_exit(&priv->phy); if (ret) pr_err("failed to release phy\n"); } reset_err: ret = reset_release_all(priv->resets, priv->reset_count); if (ret) pr_err("failed to assert all resets\n"); clk_err: ret = clk_release_all(priv->clocks, priv->clock_count); if (ret) pr_err("failed to disable all clocks\n"); return err; }
static int uniphier_sd_probe(struct udevice *dev) { struct uniphier_sd_priv *priv = dev_get_priv(dev); struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev); fdt_addr_t base; struct clk clk; int ret; base = dev_get_addr(dev); if (base == FDT_ADDR_T_NONE) return -EINVAL; priv->regbase = devm_ioremap(dev, base, SZ_2K); if (!priv->regbase) return -ENOMEM; ret = clk_get_by_index(dev, 0, &clk); if (ret < 0) { dev_err(dev, "failed to get host clock\n"); return ret; } /* set to max rate */ priv->mclk = clk_set_rate(&clk, ULONG_MAX); if (IS_ERR_VALUE(priv->mclk)) { dev_err(dev, "failed to set rate for host clock\n"); clk_free(&clk); return priv->mclk; } ret = clk_enable(&clk); clk_free(&clk); if (ret) { dev_err(dev, "failed to enable host clock\n"); return ret; } priv->cfg.name = dev->name; priv->cfg.host_caps = MMC_MODE_HS_52MHz | MMC_MODE_HS; switch (fdtdec_get_int(gd->fdt_blob, dev->of_offset, "bus-width", 1)) { case 8: priv->cfg.host_caps |= MMC_MODE_8BIT; break; case 4: priv->cfg.host_caps |= MMC_MODE_4BIT; break; case 1: break; default: dev_err(dev, "Invalid \"bus-width\" value\n"); return -EINVAL; } if (fdt_get_property(gd->fdt_blob, dev->of_offset, "non-removable", NULL)) priv->caps |= UNIPHIER_SD_CAP_NONREMOVABLE; priv->version = readl(priv->regbase + UNIPHIER_SD_VERSION) & UNIPHIER_SD_VERSION_IP; dev_dbg(dev, "version %x\n", priv->version); if (priv->version >= 0x10) { priv->caps |= UNIPHIER_SD_CAP_DMA_INTERNAL; priv->caps |= UNIPHIER_SD_CAP_DIV1024; } uniphier_sd_host_init(priv); priv->cfg.voltages = MMC_VDD_165_195 | MMC_VDD_32_33 | MMC_VDD_33_34; priv->cfg.f_min = priv->mclk / (priv->caps & UNIPHIER_SD_CAP_DIV1024 ? 1024 : 512); priv->cfg.f_max = priv->mclk; priv->cfg.b_max = U32_MAX; /* max value of UNIPHIER_SD_SECCNT */ priv->mmc = mmc_create(&priv->cfg, priv); if (!priv->mmc) return -EIO; upriv->mmc = priv->mmc; priv->mmc->dev = dev; return 0; }
static int ehci_usb_probe(struct udevice *dev) { struct generic_ehci *priv = dev_get_priv(dev); struct ehci_hccr *hccr; struct ehci_hcor *hcor; int i, err, ret, clock_nb, reset_nb; err = 0; priv->clock_count = 0; clock_nb = ofnode_count_phandle_with_args(dev_ofnode(dev), "clocks", "#clock-cells"); if (clock_nb > 0) { priv->clocks = devm_kcalloc(dev, clock_nb, sizeof(struct clk), GFP_KERNEL); if (!priv->clocks) return -ENOMEM; for (i = 0; i < clock_nb; i++) { err = clk_get_by_index(dev, i, &priv->clocks[i]); if (err < 0) break; err = clk_enable(&priv->clocks[i]); if (err) { pr_err("failed to enable clock %d\n", i); clk_free(&priv->clocks[i]); goto clk_err; } priv->clock_count++; } } else { if (clock_nb != -ENOENT) { pr_err("failed to get clock phandle(%d)\n", clock_nb); return clock_nb; } } priv->reset_count = 0; reset_nb = ofnode_count_phandle_with_args(dev_ofnode(dev), "resets", "#reset-cells"); if (reset_nb > 0) { priv->resets = devm_kcalloc(dev, reset_nb, sizeof(struct reset_ctl), GFP_KERNEL); if (!priv->resets) return -ENOMEM; for (i = 0; i < reset_nb; i++) { err = reset_get_by_index(dev, i, &priv->resets[i]); if (err < 0) break; if (reset_deassert(&priv->resets[i])) { pr_err("failed to deassert reset %d\n", i); reset_free(&priv->resets[i]); goto reset_err; } priv->reset_count++; } } else { if (reset_nb != -ENOENT) { pr_err("failed to get reset phandle(%d)\n", reset_nb); goto clk_err; } } err = generic_phy_get_by_index(dev, 0, &priv->phy); if (err) { if (err != -ENOENT) { pr_err("failed to get usb phy\n"); goto reset_err; } } else { err = generic_phy_init(&priv->phy); if (err) { pr_err("failed to init usb phy\n"); goto reset_err; } } hccr = map_physmem(dev_read_addr(dev), 0x100, MAP_NOCACHE); hcor = (struct ehci_hcor *)((uintptr_t)hccr + HC_LENGTH(ehci_readl(&hccr->cr_capbase))); err = ehci_register(dev, hccr, hcor, NULL, 0, USB_INIT_HOST); if (err) goto phy_err; return 0; phy_err: if (generic_phy_valid(&priv->phy)) { ret = generic_phy_exit(&priv->phy); if (ret) pr_err("failed to release phy\n"); } reset_err: ret = reset_release_all(priv->resets, priv->reset_count); if (ret) pr_err("failed to assert all resets\n"); clk_err: ret = clk_release_all(priv->clocks, priv->clock_count); if (ret) pr_err("failed to disable all clocks\n"); return err; }