Stelian Pop | 7d42a22 | 2008-01-31 21:15:53 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2007 |
Stelian Pop | 5ee0c7f | 2011-11-01 00:00:39 +0100 | [diff] [blame] | 3 | * Stelian Pop <stelian@popies.net> |
Stelian Pop | 7d42a22 | 2008-01-31 21:15:53 +0000 | [diff] [blame] | 4 | * Lead Tech Design <www.leadtechdesign.com> |
Jean-Christophe PLAGNIOL-VILLARD | 23164f1 | 2009-04-16 21:30:44 +0200 | [diff] [blame] | 5 | * Copyright (C) 2009 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> |
Stelian Pop | 7d42a22 | 2008-01-31 21:15:53 +0000 | [diff] [blame] | 6 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 7 | * SPDX-License-Identifier: GPL-2.0+ |
Stelian Pop | 7d42a22 | 2008-01-31 21:15:53 +0000 | [diff] [blame] | 8 | */ |
| 9 | #ifndef __ASM_ARM_ARCH_CLK_H__ |
| 10 | #define __ASM_ARM_ARCH_CLK_H__ |
| 11 | |
| 12 | #include <asm/arch/hardware.h> |
Bo Shen | 5864590 | 2014-11-10 15:24:02 +0800 | [diff] [blame] | 13 | #include <asm/arch/at91_pmc.h> |
Andreas Bießmann | f4c9f92 | 2011-06-12 01:49:11 +0000 | [diff] [blame] | 14 | #include <asm/global_data.h> |
| 15 | |
Wenyou Yang | 522f5a6 | 2015-10-30 09:47:02 +0800 | [diff] [blame] | 16 | #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 | |
Wenyou Yang | dcc8a84 | 2016-04-11 16:41:32 +0800 | [diff] [blame] | 23 | #define AT91_UTMI_PLL_CLK_FREQ 480000000 |
| 24 | |
Andreas Bießmann | f4c9f92 | 2011-06-12 01:49:11 +0000 | [diff] [blame] | 25 | static inline unsigned long get_cpu_clk_rate(void) |
| 26 | { |
| 27 | DECLARE_GLOBAL_DATA_PTR; |
Simon Glass | e61accc | 2012-12-13 20:48:31 +0000 | [diff] [blame] | 28 | return gd->arch.cpu_clk_rate_hz; |
Andreas Bießmann | f4c9f92 | 2011-06-12 01:49:11 +0000 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | static inline unsigned long get_main_clk_rate(void) |
| 32 | { |
| 33 | DECLARE_GLOBAL_DATA_PTR; |
Simon Glass | e61accc | 2012-12-13 20:48:31 +0000 | [diff] [blame] | 34 | return gd->arch.main_clk_rate_hz; |
Andreas Bießmann | f4c9f92 | 2011-06-12 01:49:11 +0000 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | static inline unsigned long get_mck_clk_rate(void) |
| 38 | { |
| 39 | DECLARE_GLOBAL_DATA_PTR; |
Simon Glass | e61accc | 2012-12-13 20:48:31 +0000 | [diff] [blame] | 40 | return gd->arch.mck_rate_hz; |
Andreas Bießmann | f4c9f92 | 2011-06-12 01:49:11 +0000 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | static inline unsigned long get_plla_clk_rate(void) |
| 44 | { |
| 45 | DECLARE_GLOBAL_DATA_PTR; |
Simon Glass | e61accc | 2012-12-13 20:48:31 +0000 | [diff] [blame] | 46 | return gd->arch.plla_rate_hz; |
Andreas Bießmann | f4c9f92 | 2011-06-12 01:49:11 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | static inline unsigned long get_pllb_clk_rate(void) |
| 50 | { |
| 51 | DECLARE_GLOBAL_DATA_PTR; |
Simon Glass | e61accc | 2012-12-13 20:48:31 +0000 | [diff] [blame] | 52 | return gd->arch.pllb_rate_hz; |
Andreas Bießmann | f4c9f92 | 2011-06-12 01:49:11 +0000 | [diff] [blame] | 53 | } |
Stelian Pop | 7d42a22 | 2008-01-31 21:15:53 +0000 | [diff] [blame] | 54 | |
Andreas Bießmann | f4c9f92 | 2011-06-12 01:49:11 +0000 | [diff] [blame] | 55 | static inline u32 get_pllb_init(void) |
| 56 | { |
| 57 | DECLARE_GLOBAL_DATA_PTR; |
Simon Glass | e61accc | 2012-12-13 20:48:31 +0000 | [diff] [blame] | 58 | return gd->arch.at91_pllb_usb_init; |
Andreas Bießmann | f4c9f92 | 2011-06-12 01:49:11 +0000 | [diff] [blame] | 59 | } |
Jean-Christophe PLAGNIOL-VILLARD | 23164f1 | 2009-04-16 21:30:44 +0200 | [diff] [blame] | 60 | |
Bo Shen | 5864590 | 2014-11-10 15:24:02 +0800 | [diff] [blame] | 61 | #ifdef CPU_HAS_H32MXDIV |
| 62 | static inline unsigned int get_h32mxdiv(void) |
| 63 | { |
| 64 | struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC; |
| 65 | |
| 66 | return readl(&pmc->mckr) & AT91_PMC_MCKR_H32MXDIV; |
| 67 | } |
| 68 | #else |
| 69 | static inline unsigned int get_h32mxdiv(void) |
| 70 | { |
| 71 | return 0; |
| 72 | } |
| 73 | #endif |
| 74 | |
Stelian Pop | 7d42a22 | 2008-01-31 21:15:53 +0000 | [diff] [blame] | 75 | static inline unsigned long get_macb_pclk_rate(unsigned int dev_id) |
| 76 | { |
Bo Shen | 5864590 | 2014-11-10 15:24:02 +0800 | [diff] [blame] | 77 | if (get_h32mxdiv()) |
| 78 | return get_mck_clk_rate() / 2; |
| 79 | else |
| 80 | return get_mck_clk_rate(); |
Stelian Pop | 7d42a22 | 2008-01-31 21:15:53 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | static inline unsigned long get_usart_clk_rate(unsigned int dev_id) |
| 84 | { |
Bo Shen | 5864590 | 2014-11-10 15:24:02 +0800 | [diff] [blame] | 85 | if (get_h32mxdiv()) |
| 86 | return get_mck_clk_rate() / 2; |
| 87 | else |
| 88 | return get_mck_clk_rate(); |
Stelian Pop | 7d42a22 | 2008-01-31 21:15:53 +0000 | [diff] [blame] | 89 | } |
| 90 | |
Stelian Pop | f6f8665 | 2008-05-09 21:57:18 +0200 | [diff] [blame] | 91 | static inline unsigned long get_lcdc_clk_rate(unsigned int dev_id) |
| 92 | { |
Jean-Christophe PLAGNIOL-VILLARD | 23164f1 | 2009-04-16 21:30:44 +0200 | [diff] [blame] | 93 | return get_mck_clk_rate(); |
Stelian Pop | f6f8665 | 2008-05-09 21:57:18 +0200 | [diff] [blame] | 94 | } |
| 95 | |
Sedji Gaouaou | 538566d | 2009-07-09 10:16:29 +0200 | [diff] [blame] | 96 | static inline unsigned long get_spi_clk_rate(unsigned int dev_id) |
| 97 | { |
Bo Shen | 5864590 | 2014-11-10 15:24:02 +0800 | [diff] [blame] | 98 | if (get_h32mxdiv()) |
| 99 | return get_mck_clk_rate() / 2; |
| 100 | else |
| 101 | return get_mck_clk_rate(); |
Sedji Gaouaou | 538566d | 2009-07-09 10:16:29 +0200 | [diff] [blame] | 102 | } |
| 103 | |
Jean-Christophe PLAGNIOL-VILLARD | 23164f1 | 2009-04-16 21:30:44 +0200 | [diff] [blame] | 104 | static inline unsigned long get_twi_clk_rate(unsigned int dev_id) |
| 105 | { |
Bo Shen | 5864590 | 2014-11-10 15:24:02 +0800 | [diff] [blame] | 106 | if (get_h32mxdiv()) |
| 107 | return get_mck_clk_rate() / 2; |
| 108 | else |
| 109 | return get_mck_clk_rate(); |
Jean-Christophe PLAGNIOL-VILLARD | 23164f1 | 2009-04-16 21:30:44 +0200 | [diff] [blame] | 110 | } |
Stelian Pop | f6f8665 | 2008-05-09 21:57:18 +0200 | [diff] [blame] | 111 | |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 112 | static inline unsigned long get_mci_clk_rate(void) |
| 113 | { |
Bo Shen | 5864590 | 2014-11-10 15:24:02 +0800 | [diff] [blame] | 114 | if (get_h32mxdiv()) |
| 115 | return get_mck_clk_rate() / 2; |
| 116 | else |
| 117 | return get_mck_clk_rate(); |
| 118 | } |
| 119 | |
| 120 | static inline unsigned long get_pit_clk_rate(void) |
| 121 | { |
| 122 | if (get_h32mxdiv()) |
| 123 | return get_mck_clk_rate() / 2; |
| 124 | else |
| 125 | return get_mck_clk_rate(); |
Reinhard Meyer | c718a56 | 2010-08-13 10:31:06 +0200 | [diff] [blame] | 126 | } |
| 127 | |
Jean-Christophe PLAGNIOL-VILLARD | 23164f1 | 2009-04-16 21:30:44 +0200 | [diff] [blame] | 128 | int at91_clock_init(unsigned long main_clock); |
Bo Shen | 60f3dd3 | 2013-05-12 22:40:54 +0000 | [diff] [blame] | 129 | void at91_periph_clk_enable(int id); |
Bo Shen | 52e0009 | 2014-08-06 17:24:54 +0800 | [diff] [blame] | 130 | void at91_periph_clk_disable(int id); |
Wenyou Yang | 522f5a6 | 2015-10-30 09:47:02 +0800 | [diff] [blame] | 131 | int at91_enable_periph_generated_clk(u32 id, u32 clk_source, u32 div); |
| 132 | u32 at91_get_periph_generated_clk(u32 id); |
Wenyou Yang | 49c68c2 | 2016-02-03 10:16:48 +0800 | [diff] [blame] | 133 | void at91_system_clk_enable(int sys_clk); |
| 134 | void at91_system_clk_disable(int sys_clk); |
Wenyou Yang | 335c548 | 2016-02-02 11:11:51 +0800 | [diff] [blame] | 135 | int at91_upll_clk_enable(void); |
| 136 | int at91_upll_clk_disable(void); |
| 137 | void at91_usb_clk_init(u32 value); |
Wenyou Yang | 0a30fcb | 2016-02-03 10:20:43 +0800 | [diff] [blame] | 138 | int at91_pllb_clk_enable(u32 pllbr); |
| 139 | int at91_pllb_clk_disable(void); |
Wenyou Yang | e6092b5 | 2016-02-02 12:46:12 +0800 | [diff] [blame] | 140 | void at91_pllicpr_init(u32 icpr); |
Wenyou Yang | 522f5a6 | 2015-10-30 09:47:02 +0800 | [diff] [blame] | 141 | |
Stelian Pop | 7d42a22 | 2008-01-31 21:15:53 +0000 | [diff] [blame] | 142 | #endif /* __ASM_ARM_ARCH_CLK_H__ */ |