blob: 1d45e2dc112deda0f4a3d58745b8f088f22cdee9 [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
16static inline unsigned long get_cpu_clk_rate(void)
17{
18 DECLARE_GLOBAL_DATA_PTR;
Simon Glasse61accc2012-12-13 20:48:31 +000019 return gd->arch.cpu_clk_rate_hz;
Andreas Bießmannf4c9f922011-06-12 01:49:11 +000020}
21
22static inline unsigned long get_main_clk_rate(void)
23{
24 DECLARE_GLOBAL_DATA_PTR;
Simon Glasse61accc2012-12-13 20:48:31 +000025 return gd->arch.main_clk_rate_hz;
Andreas Bießmannf4c9f922011-06-12 01:49:11 +000026}
27
28static inline unsigned long get_mck_clk_rate(void)
29{
30 DECLARE_GLOBAL_DATA_PTR;
Simon Glasse61accc2012-12-13 20:48:31 +000031 return gd->arch.mck_rate_hz;
Andreas Bießmannf4c9f922011-06-12 01:49:11 +000032}
33
34static inline unsigned long get_plla_clk_rate(void)
35{
36 DECLARE_GLOBAL_DATA_PTR;
Simon Glasse61accc2012-12-13 20:48:31 +000037 return gd->arch.plla_rate_hz;
Andreas Bießmannf4c9f922011-06-12 01:49:11 +000038}
39
40static inline unsigned long get_pllb_clk_rate(void)
41{
42 DECLARE_GLOBAL_DATA_PTR;
Simon Glasse61accc2012-12-13 20:48:31 +000043 return gd->arch.pllb_rate_hz;
Andreas Bießmannf4c9f922011-06-12 01:49:11 +000044}
Stelian Pop7d42a222008-01-31 21:15:53 +000045
Andreas Bießmannf4c9f922011-06-12 01:49:11 +000046static inline u32 get_pllb_init(void)
47{
48 DECLARE_GLOBAL_DATA_PTR;
Simon Glasse61accc2012-12-13 20:48:31 +000049 return gd->arch.at91_pllb_usb_init;
Andreas Bießmannf4c9f922011-06-12 01:49:11 +000050}
Jean-Christophe PLAGNIOL-VILLARD23164f12009-04-16 21:30:44 +020051
Bo Shen58645902014-11-10 15:24:02 +080052#ifdef CPU_HAS_H32MXDIV
53static inline unsigned int get_h32mxdiv(void)
54{
55 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
56
57 return readl(&pmc->mckr) & AT91_PMC_MCKR_H32MXDIV;
58}
59#else
60static inline unsigned int get_h32mxdiv(void)
61{
62 return 0;
63}
64#endif
65
Stelian Pop7d42a222008-01-31 21:15:53 +000066static inline unsigned long get_macb_pclk_rate(unsigned int dev_id)
67{
Bo Shen58645902014-11-10 15:24:02 +080068 if (get_h32mxdiv())
69 return get_mck_clk_rate() / 2;
70 else
71 return get_mck_clk_rate();
Stelian Pop7d42a222008-01-31 21:15:53 +000072}
73
74static inline unsigned long get_usart_clk_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
Stelian Popf6f86652008-05-09 21:57:18 +020082static inline unsigned long get_lcdc_clk_rate(unsigned int dev_id)
83{
Jean-Christophe PLAGNIOL-VILLARD23164f12009-04-16 21:30:44 +020084 return get_mck_clk_rate();
Stelian Popf6f86652008-05-09 21:57:18 +020085}
86
Sedji Gaouaou538566d2009-07-09 10:16:29 +020087static inline unsigned long get_spi_clk_rate(unsigned int dev_id)
88{
Bo Shen58645902014-11-10 15:24:02 +080089 if (get_h32mxdiv())
90 return get_mck_clk_rate() / 2;
91 else
92 return get_mck_clk_rate();
Sedji Gaouaou538566d2009-07-09 10:16:29 +020093}
94
Jean-Christophe PLAGNIOL-VILLARD23164f12009-04-16 21:30:44 +020095static inline unsigned long get_twi_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();
Jean-Christophe PLAGNIOL-VILLARD23164f12009-04-16 21:30:44 +0200101}
Stelian Popf6f86652008-05-09 21:57:18 +0200102
Reinhard Meyerc718a562010-08-13 10:31:06 +0200103static inline unsigned long get_mci_clk_rate(void)
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();
109}
110
111static inline unsigned long get_pit_clk_rate(void)
112{
113 if (get_h32mxdiv())
114 return get_mck_clk_rate() / 2;
115 else
116 return get_mck_clk_rate();
Reinhard Meyerc718a562010-08-13 10:31:06 +0200117}
118
Jean-Christophe PLAGNIOL-VILLARD23164f12009-04-16 21:30:44 +0200119int at91_clock_init(unsigned long main_clock);
Bo Shen60f3dd32013-05-12 22:40:54 +0000120void at91_periph_clk_enable(int id);
Bo Shen52e00092014-08-06 17:24:54 +0800121void at91_periph_clk_disable(int id);
Stelian Pop7d42a222008-01-31 21:15:53 +0000122#endif /* __ASM_ARM_ARCH_CLK_H__ */