blob: 64dec5223691f7efafbe042b77d19a4769fa5461 [file] [log] [blame]
Stelian Pop7d42a222008-01-31 21:15:53 +00001/*
2 * (C) Copyright 2007
Stelian Pop5ee0c7f2011-11-01 00:00:39 +01003 * Stelian Pop <stelian@popies.net>
Stelian Pop7d42a222008-01-31 21:15:53 +00004 * Lead Tech Design <www.leadtechdesign.com>
Jean-Christophe PLAGNIOL-VILLARD23164f12009-04-16 21:30:44 +02005 * Copyright (C) 2009 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Stelian Pop7d42a222008-01-31 21:15:53 +00006 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02007 * SPDX-License-Identifier: GPL-2.0+
Stelian Pop7d42a222008-01-31 21:15:53 +00008 */
9#ifndef __ASM_ARM_ARCH_CLK_H__
10#define __ASM_ARM_ARCH_CLK_H__
11
12#include <asm/arch/hardware.h>
Bo Shen58645902014-11-10 15:24:02 +080013#include <asm/arch/at91_pmc.h>
Andreas Bießmannf4c9f922011-06-12 01:49:11 +000014#include <asm/global_data.h>
15
Wenyou Yang522f5a62015-10-30 09:47:02 +080016#define GCK_CSS_SLOW_CLK 0
17#define GCK_CSS_MAIN_CLK 1
18#define GCK_CSS_PLLA_CLK 2
19#define GCK_CSS_UPLL_CLK 3
20#define GCK_CSS_MCK_CLK 4
21#define GCK_CSS_AUDIO_CLK 5
22
Andreas Bießmannf4c9f922011-06-12 01:49:11 +000023static inline unsigned long get_cpu_clk_rate(void)
24{
25 DECLARE_GLOBAL_DATA_PTR;
Simon Glasse61accc2012-12-13 20:48:31 +000026 return gd->arch.cpu_clk_rate_hz;
Andreas Bießmannf4c9f922011-06-12 01:49:11 +000027}
28
29static inline unsigned long get_main_clk_rate(void)
30{
31 DECLARE_GLOBAL_DATA_PTR;
Simon Glasse61accc2012-12-13 20:48:31 +000032 return gd->arch.main_clk_rate_hz;
Andreas Bießmannf4c9f922011-06-12 01:49:11 +000033}
34
35static inline unsigned long get_mck_clk_rate(void)
36{
37 DECLARE_GLOBAL_DATA_PTR;
Simon Glasse61accc2012-12-13 20:48:31 +000038 return gd->arch.mck_rate_hz;
Andreas Bießmannf4c9f922011-06-12 01:49:11 +000039}
40
41static inline unsigned long get_plla_clk_rate(void)
42{
43 DECLARE_GLOBAL_DATA_PTR;
Simon Glasse61accc2012-12-13 20:48:31 +000044 return gd->arch.plla_rate_hz;
Andreas Bießmannf4c9f922011-06-12 01:49:11 +000045}
46
47static inline unsigned long get_pllb_clk_rate(void)
48{
49 DECLARE_GLOBAL_DATA_PTR;
Simon Glasse61accc2012-12-13 20:48:31 +000050 return gd->arch.pllb_rate_hz;
Andreas Bießmannf4c9f922011-06-12 01:49:11 +000051}
Stelian Pop7d42a222008-01-31 21:15:53 +000052
Andreas Bießmannf4c9f922011-06-12 01:49:11 +000053static inline u32 get_pllb_init(void)
54{
55 DECLARE_GLOBAL_DATA_PTR;
Simon Glasse61accc2012-12-13 20:48:31 +000056 return gd->arch.at91_pllb_usb_init;
Andreas Bießmannf4c9f922011-06-12 01:49:11 +000057}
Jean-Christophe PLAGNIOL-VILLARD23164f12009-04-16 21:30:44 +020058
Bo Shen58645902014-11-10 15:24:02 +080059#ifdef CPU_HAS_H32MXDIV
60static inline unsigned int get_h32mxdiv(void)
61{
62 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
63
64 return readl(&pmc->mckr) & AT91_PMC_MCKR_H32MXDIV;
65}
66#else
67static inline unsigned int get_h32mxdiv(void)
68{
69 return 0;
70}
71#endif
72
Stelian Pop7d42a222008-01-31 21:15:53 +000073static inline unsigned long get_macb_pclk_rate(unsigned int dev_id)
74{
Bo Shen58645902014-11-10 15:24:02 +080075 if (get_h32mxdiv())
76 return get_mck_clk_rate() / 2;
77 else
78 return get_mck_clk_rate();
Stelian Pop7d42a222008-01-31 21:15:53 +000079}
80
81static inline unsigned long get_usart_clk_rate(unsigned int dev_id)
82{
Bo Shen58645902014-11-10 15:24:02 +080083 if (get_h32mxdiv())
84 return get_mck_clk_rate() / 2;
85 else
86 return get_mck_clk_rate();
Stelian Pop7d42a222008-01-31 21:15:53 +000087}
88
Stelian Popf6f86652008-05-09 21:57:18 +020089static inline unsigned long get_lcdc_clk_rate(unsigned int dev_id)
90{
Jean-Christophe PLAGNIOL-VILLARD23164f12009-04-16 21:30:44 +020091 return get_mck_clk_rate();
Stelian Popf6f86652008-05-09 21:57:18 +020092}
93
Sedji Gaouaou538566d2009-07-09 10:16:29 +020094static inline unsigned long get_spi_clk_rate(unsigned int dev_id)
95{
Bo Shen58645902014-11-10 15:24:02 +080096 if (get_h32mxdiv())
97 return get_mck_clk_rate() / 2;
98 else
99 return get_mck_clk_rate();
Sedji Gaouaou538566d2009-07-09 10:16:29 +0200100}
101
Jean-Christophe PLAGNIOL-VILLARD23164f12009-04-16 21:30:44 +0200102static inline unsigned long get_twi_clk_rate(unsigned int dev_id)
103{
Bo Shen58645902014-11-10 15:24:02 +0800104 if (get_h32mxdiv())
105 return get_mck_clk_rate() / 2;
106 else
107 return get_mck_clk_rate();
Jean-Christophe PLAGNIOL-VILLARD23164f12009-04-16 21:30:44 +0200108}
Stelian Popf6f86652008-05-09 21:57:18 +0200109
Reinhard Meyerc718a562010-08-13 10:31:06 +0200110static inline unsigned long get_mci_clk_rate(void)
111{
Bo Shen58645902014-11-10 15:24:02 +0800112 if (get_h32mxdiv())
113 return get_mck_clk_rate() / 2;
114 else
115 return get_mck_clk_rate();
116}
117
118static inline unsigned long get_pit_clk_rate(void)
119{
120 if (get_h32mxdiv())
121 return get_mck_clk_rate() / 2;
122 else
123 return get_mck_clk_rate();
Reinhard Meyerc718a562010-08-13 10:31:06 +0200124}
125
Jean-Christophe PLAGNIOL-VILLARD23164f12009-04-16 21:30:44 +0200126int at91_clock_init(unsigned long main_clock);
Bo Shen60f3dd32013-05-12 22:40:54 +0000127void at91_periph_clk_enable(int id);
Bo Shen52e00092014-08-06 17:24:54 +0800128void at91_periph_clk_disable(int id);
Wenyou Yang522f5a62015-10-30 09:47:02 +0800129int at91_enable_periph_generated_clk(u32 id, u32 clk_source, u32 div);
130u32 at91_get_periph_generated_clk(u32 id);
Wenyou Yang49c68c22016-02-03 10:16:48 +0800131void at91_system_clk_enable(int sys_clk);
132void at91_system_clk_disable(int sys_clk);
Wenyou Yang335c5482016-02-02 11:11:51 +0800133int at91_upll_clk_enable(void);
134int at91_upll_clk_disable(void);
135void at91_usb_clk_init(u32 value);
Wenyou Yang0a30fcb2016-02-03 10:20:43 +0800136int at91_pllb_clk_enable(u32 pllbr);
137int at91_pllb_clk_disable(void);
Wenyou Yang522f5a62015-10-30 09:47:02 +0800138
Stelian Pop7d42a222008-01-31 21:15:53 +0000139#endif /* __ASM_ARM_ARCH_CLK_H__ */