blob: c1d92739e47207c35d4e40692b8b7a14a548d94c [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Stelian Pop7d42a222008-01-31 21:15:53 +00002/*
3 * (C) Copyright 2007
Stelian Pop5ee0c7f2011-11-01 00:00:39 +01004 * Stelian Pop <stelian@popies.net>
Stelian Pop7d42a222008-01-31 21:15:53 +00005 * Lead Tech Design <www.leadtechdesign.com>
Jean-Christophe PLAGNIOL-VILLARD23164f12009-04-16 21:30:44 +02006 * Copyright (C) 2009 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Stelian Pop7d42a222008-01-31 21:15:53 +00007 */
8#ifndef __ASM_ARM_ARCH_CLK_H__
9#define __ASM_ARM_ARCH_CLK_H__
10
11#include <asm/arch/hardware.h>
Bo Shen58645902014-11-10 15:24:02 +080012#include <asm/arch/at91_pmc.h>
Andreas Bießmannf4c9f922011-06-12 01:49:11 +000013#include <asm/global_data.h>
14
Wenyou Yang522f5a62015-10-30 09:47:02 +080015#define GCK_CSS_SLOW_CLK 0
16#define GCK_CSS_MAIN_CLK 1
17#define GCK_CSS_PLLA_CLK 2
18#define GCK_CSS_UPLL_CLK 3
19#define GCK_CSS_MCK_CLK 4
20#define GCK_CSS_AUDIO_CLK 5
21
Wenyou Yangdcc8a842016-04-11 16:41:32 +080022#define AT91_UTMI_PLL_CLK_FREQ 480000000
23
Andreas Bießmannf4c9f922011-06-12 01:49:11 +000024static inline unsigned long get_cpu_clk_rate(void)
25{
26 DECLARE_GLOBAL_DATA_PTR;
Simon Glasse61accc2012-12-13 20:48:31 +000027 return gd->arch.cpu_clk_rate_hz;
Andreas Bießmannf4c9f922011-06-12 01:49:11 +000028}
29
30static inline unsigned long get_main_clk_rate(void)
31{
32 DECLARE_GLOBAL_DATA_PTR;
Simon Glasse61accc2012-12-13 20:48:31 +000033 return gd->arch.main_clk_rate_hz;
Andreas Bießmannf4c9f922011-06-12 01:49:11 +000034}
35
36static inline unsigned long get_mck_clk_rate(void)
37{
38 DECLARE_GLOBAL_DATA_PTR;
Simon Glasse61accc2012-12-13 20:48:31 +000039 return gd->arch.mck_rate_hz;
Andreas Bießmannf4c9f922011-06-12 01:49:11 +000040}
41
42static inline unsigned long get_plla_clk_rate(void)
43{
44 DECLARE_GLOBAL_DATA_PTR;
Simon Glasse61accc2012-12-13 20:48:31 +000045 return gd->arch.plla_rate_hz;
Andreas Bießmannf4c9f922011-06-12 01:49:11 +000046}
47
48static inline unsigned long get_pllb_clk_rate(void)
49{
50 DECLARE_GLOBAL_DATA_PTR;
Simon Glasse61accc2012-12-13 20:48:31 +000051 return gd->arch.pllb_rate_hz;
Andreas Bießmannf4c9f922011-06-12 01:49:11 +000052}
Stelian Pop7d42a222008-01-31 21:15:53 +000053
Andreas Bießmannf4c9f922011-06-12 01:49:11 +000054static inline u32 get_pllb_init(void)
55{
56 DECLARE_GLOBAL_DATA_PTR;
Simon Glasse61accc2012-12-13 20:48:31 +000057 return gd->arch.at91_pllb_usb_init;
Andreas Bießmannf4c9f922011-06-12 01:49:11 +000058}
Jean-Christophe PLAGNIOL-VILLARD23164f12009-04-16 21:30:44 +020059
Bo Shen58645902014-11-10 15:24:02 +080060#ifdef CPU_HAS_H32MXDIV
61static inline unsigned int get_h32mxdiv(void)
62{
63 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
64
65 return readl(&pmc->mckr) & AT91_PMC_MCKR_H32MXDIV;
66}
67#else
68static inline unsigned int get_h32mxdiv(void)
69{
70 return 0;
71}
72#endif
73
Stelian Pop7d42a222008-01-31 21:15:53 +000074static inline unsigned long get_macb_pclk_rate(unsigned int dev_id)
75{
Bo Shen58645902014-11-10 15:24:02 +080076 if (get_h32mxdiv())
77 return get_mck_clk_rate() / 2;
78 else
79 return get_mck_clk_rate();
Stelian Pop7d42a222008-01-31 21:15:53 +000080}
81
82static inline unsigned long get_usart_clk_rate(unsigned int dev_id)
83{
Bo Shen58645902014-11-10 15:24:02 +080084 if (get_h32mxdiv())
85 return get_mck_clk_rate() / 2;
86 else
87 return get_mck_clk_rate();
Stelian Pop7d42a222008-01-31 21:15:53 +000088}
89
Stelian Popf6f86652008-05-09 21:57:18 +020090static inline unsigned long get_lcdc_clk_rate(unsigned int dev_id)
91{
Jean-Christophe PLAGNIOL-VILLARD23164f12009-04-16 21:30:44 +020092 return get_mck_clk_rate();
Stelian Popf6f86652008-05-09 21:57:18 +020093}
94
Sedji Gaouaou538566d2009-07-09 10:16:29 +020095static inline unsigned long get_spi_clk_rate(unsigned int dev_id)
96{
Bo Shen58645902014-11-10 15:24:02 +080097 if (get_h32mxdiv())
98 return get_mck_clk_rate() / 2;
99 else
100 return get_mck_clk_rate();
Sedji Gaouaou538566d2009-07-09 10:16:29 +0200101}
102
Jean-Christophe PLAGNIOL-VILLARD23164f12009-04-16 21:30:44 +0200103static inline unsigned long get_twi_clk_rate(unsigned int dev_id)
104{
Bo Shen58645902014-11-10 15:24:02 +0800105 if (get_h32mxdiv())
106 return get_mck_clk_rate() / 2;
107 else
108 return get_mck_clk_rate();
Jean-Christophe PLAGNIOL-VILLARD23164f12009-04-16 21:30:44 +0200109}
Stelian Popf6f86652008-05-09 21:57:18 +0200110
Reinhard Meyerc718a562010-08-13 10:31:06 +0200111static inline unsigned long get_mci_clk_rate(void)
112{
Bo Shen58645902014-11-10 15:24:02 +0800113 if (get_h32mxdiv())
114 return get_mck_clk_rate() / 2;
115 else
116 return get_mck_clk_rate();
117}
118
119static inline unsigned long get_pit_clk_rate(void)
120{
121 if (get_h32mxdiv())
122 return get_mck_clk_rate() / 2;
123 else
124 return get_mck_clk_rate();
Reinhard Meyerc718a562010-08-13 10:31:06 +0200125}
126
Jean-Christophe PLAGNIOL-VILLARD23164f12009-04-16 21:30:44 +0200127int at91_clock_init(unsigned long main_clock);
Bo Shen60f3dd32013-05-12 22:40:54 +0000128void at91_periph_clk_enable(int id);
Bo Shen52e00092014-08-06 17:24:54 +0800129void at91_periph_clk_disable(int id);
Wenyou Yang522f5a62015-10-30 09:47:02 +0800130int at91_enable_periph_generated_clk(u32 id, u32 clk_source, u32 div);
131u32 at91_get_periph_generated_clk(u32 id);
Wenyou Yang49c68c22016-02-03 10:16:48 +0800132void at91_system_clk_enable(int sys_clk);
133void at91_system_clk_disable(int sys_clk);
Wenyou Yang335c5482016-02-02 11:11:51 +0800134int at91_upll_clk_enable(void);
135int at91_upll_clk_disable(void);
136void at91_usb_clk_init(u32 value);
Wenyou Yang0a30fcb2016-02-03 10:20:43 +0800137int at91_pllb_clk_enable(u32 pllbr);
138int at91_pllb_clk_disable(void);
Wenyou Yange6092b52016-02-02 12:46:12 +0800139void at91_pllicpr_init(u32 icpr);
Wenyou Yang522f5a62015-10-30 09:47:02 +0800140
Stelian Pop7d42a222008-01-31 21:15:53 +0000141#endif /* __ASM_ARM_ARCH_CLK_H__ */