1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2015 Atmel Corporation
4 * Wenyou Yang <wenyou.yang@atmel.com>
9 #include <asm/arch/hardware.h>
10 #include <asm/arch/at91_pmc.h>
12 #define EN_UPLL_TIMEOUT 500
14 void at91_periph_clk_enable(int id)
16 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
22 if (id > AT91_PMC_PCR_PID_MASK)
25 writel(id, &pmc->pcr);
27 div_value = readl(&pmc->pcr) & AT91_PMC_PCR_DIV;
29 regval = AT91_PMC_PCR_EN | AT91_PMC_PCR_CMD_WRITE | id | div_value;
31 writel(regval, &pmc->pcr);
33 writel(0x01 << id, &pmc->pcer);
37 void at91_periph_clk_disable(int id)
39 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
44 if (id > AT91_PMC_PCR_PID_MASK)
47 regval = AT91_PMC_PCR_CMD_WRITE | id;
49 writel(regval, &pmc->pcr);
51 writel(0x01 << id, &pmc->pcdr);
55 void at91_system_clk_enable(int sys_clk)
57 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
59 writel(sys_clk, &pmc->scer);
62 void at91_system_clk_disable(int sys_clk)
64 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
66 writel(sys_clk, &pmc->scdr);
69 int at91_upll_clk_enable(void)
71 struct at91_pmc *pmc = (at91_pmc_t *)ATMEL_BASE_PMC;
72 ulong start_time, tmp_time;
74 if ((readl(&pmc->uckr) & AT91_PMC_UPLLEN) == AT91_PMC_UPLLEN)
77 start_time = get_timer(0);
78 writel(AT91_PMC_UPLLEN | AT91_PMC_BIASEN, &pmc->uckr);
79 while ((readl(&pmc->sr) & AT91_PMC_LOCKU) != AT91_PMC_LOCKU) {
80 tmp_time = get_timer(0);
81 if ((tmp_time - start_time) > EN_UPLL_TIMEOUT) {
82 printf("ERROR: failed to enable UPLL\n");
90 int at91_upll_clk_disable(void)
92 struct at91_pmc *pmc = (at91_pmc_t *)ATMEL_BASE_PMC;
93 ulong start_time, tmp_time;
95 start_time = get_timer(0);
96 writel(readl(&pmc->uckr) & ~AT91_PMC_UPLLEN, &pmc->uckr);
97 while ((readl(&pmc->sr) & AT91_PMC_LOCKU) == AT91_PMC_LOCKU) {
98 tmp_time = get_timer(0);
99 if ((tmp_time - start_time) > EN_UPLL_TIMEOUT) {
100 printf("ERROR: failed to stop UPLL\n");
108 void at91_usb_clk_init(u32 value)
110 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
112 writel(value, &pmc->usb);
115 void at91_pllicpr_init(u32 icpr)
117 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
119 writel(icpr, &pmc->pllicpr);