2 * Copyright (C) 2015 Atmel Corporation
3 * Wenyou Yang <wenyou.yang@atmel.com>
5 * SPDX-License-Identifier: GPL-2.0+
10 #include <asm/arch/hardware.h>
11 #include <asm/arch/at91_pmc.h>
13 #define EN_UPLL_TIMEOUT 500
15 void at91_periph_clk_enable(int id)
17 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
23 if (id > AT91_PMC_PCR_PID_MASK)
26 writel(id, &pmc->pcr);
28 div_value = readl(&pmc->pcr) & AT91_PMC_PCR_DIV;
30 regval = AT91_PMC_PCR_EN | AT91_PMC_PCR_CMD_WRITE | id | div_value;
32 writel(regval, &pmc->pcr);
34 writel(0x01 << id, &pmc->pcer);
38 void at91_periph_clk_disable(int id)
40 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
45 if (id > AT91_PMC_PCR_PID_MASK)
48 regval = AT91_PMC_PCR_CMD_WRITE | id;
50 writel(regval, &pmc->pcr);
52 writel(0x01 << id, &pmc->pcdr);
56 void at91_system_clk_enable(int sys_clk)
58 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
60 writel(sys_clk, &pmc->scer);
63 void at91_system_clk_disable(int sys_clk)
65 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
67 writel(sys_clk, &pmc->scdr);
70 int at91_upll_clk_enable(void)
72 struct at91_pmc *pmc = (at91_pmc_t *)ATMEL_BASE_PMC;
73 ulong start_time, tmp_time;
75 if ((readl(&pmc->uckr) & AT91_PMC_UPLLEN) == AT91_PMC_UPLLEN)
78 start_time = get_timer(0);
79 writel(AT91_PMC_UPLLEN | AT91_PMC_BIASEN, &pmc->uckr);
80 while ((readl(&pmc->sr) & AT91_PMC_LOCKU) != AT91_PMC_LOCKU) {
81 tmp_time = get_timer(0);
82 if ((tmp_time - start_time) > EN_UPLL_TIMEOUT) {
83 printf("ERROR: failed to enable UPLL\n");
91 int at91_upll_clk_disable(void)
93 struct at91_pmc *pmc = (at91_pmc_t *)ATMEL_BASE_PMC;
94 ulong start_time, tmp_time;
96 start_time = get_timer(0);
97 writel(readl(&pmc->uckr) & ~AT91_PMC_UPLLEN, &pmc->uckr);
98 while ((readl(&pmc->sr) & AT91_PMC_LOCKU) == AT91_PMC_LOCKU) {
99 tmp_time = get_timer(0);
100 if ((tmp_time - start_time) > EN_UPLL_TIMEOUT) {
101 printf("ERROR: failed to stop UPLL\n");
109 void at91_usb_clk_init(u32 value)
111 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
113 writel(value, &pmc->usb);
116 void at91_pllicpr_init(u32 icpr)
118 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
120 writel(icpr, &pmc->pllicpr);