1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2015 Atmel Corporation
4 * Wenyou Yang <wenyou.yang@atmel.com>
11 #include <asm/arch/hardware.h>
12 #include <asm/arch/at91_pmc.h>
13 #include <asm/arch/at91_wdt.h>
15 #define EN_UPLL_TIMEOUT 500
17 void at91_periph_clk_enable(int id)
19 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
25 if (id > AT91_PMC_PCR_PID_MASK)
28 writel(id, &pmc->pcr);
30 div_value = readl(&pmc->pcr) & AT91_PMC_PCR_DIV;
32 regval = AT91_PMC_PCR_EN | AT91_PMC_PCR_CMD_WRITE | id | div_value;
34 writel(regval, &pmc->pcr);
36 writel(0x01 << id, &pmc->pcer);
40 void at91_periph_clk_disable(int id)
42 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
47 if (id > AT91_PMC_PCR_PID_MASK)
50 regval = AT91_PMC_PCR_CMD_WRITE | id;
52 writel(regval, &pmc->pcr);
54 writel(0x01 << id, &pmc->pcdr);
58 void at91_system_clk_enable(int sys_clk)
60 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
62 writel(sys_clk, &pmc->scer);
65 void at91_system_clk_disable(int sys_clk)
67 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
69 writel(sys_clk, &pmc->scdr);
72 int at91_upll_clk_enable(void)
74 struct at91_pmc *pmc = (at91_pmc_t *)ATMEL_BASE_PMC;
75 ulong start_time, tmp_time;
77 if ((readl(&pmc->uckr) & AT91_PMC_UPLLEN) == AT91_PMC_UPLLEN)
80 start_time = get_timer(0);
81 writel(AT91_PMC_UPLLEN | AT91_PMC_BIASEN, &pmc->uckr);
82 while ((readl(&pmc->sr) & AT91_PMC_LOCKU) != AT91_PMC_LOCKU) {
83 tmp_time = get_timer(0);
84 if ((tmp_time - start_time) > EN_UPLL_TIMEOUT) {
85 printf("ERROR: failed to enable UPLL\n");
93 int at91_upll_clk_disable(void)
95 struct at91_pmc *pmc = (at91_pmc_t *)ATMEL_BASE_PMC;
96 ulong start_time, tmp_time;
98 start_time = get_timer(0);
99 writel(readl(&pmc->uckr) & ~AT91_PMC_UPLLEN, &pmc->uckr);
100 while ((readl(&pmc->sr) & AT91_PMC_LOCKU) == AT91_PMC_LOCKU) {
101 tmp_time = get_timer(0);
102 if ((tmp_time - start_time) > EN_UPLL_TIMEOUT) {
103 printf("ERROR: failed to stop UPLL\n");
111 void at91_usb_clk_init(u32 value)
113 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
115 writel(value, &pmc->usb);
118 void at91_pllicpr_init(u32 icpr)
120 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
122 writel(icpr, &pmc->pllicpr);