David Brownell | 4506400 | 2009-05-15 23:47:12 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2004 Texas Instruments. |
| 3 | * Copyright (C) 2009 David Brownell |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 21 | */ |
| 22 | |
| 23 | #include <common.h> |
Ben Warren | 5301bbf | 2009-05-26 00:34:07 -0700 | [diff] [blame] | 24 | #include <netdev.h> |
David Brownell | 4506400 | 2009-05-15 23:47:12 +0200 | [diff] [blame] | 25 | #include <asm/arch/hardware.h> |
Sekhar Nori | 302fc2f | 2009-11-12 11:07:22 -0500 | [diff] [blame] | 26 | #include <asm/io.h> |
David Brownell | 4506400 | 2009-05-15 23:47:12 +0200 | [diff] [blame] | 27 | |
| 28 | /* offsets from PLL controller base */ |
| 29 | #define PLLC_PLLCTL 0x100 |
| 30 | #define PLLC_PLLM 0x110 |
| 31 | #define PLLC_PREDIV 0x114 |
| 32 | #define PLLC_PLLDIV1 0x118 |
| 33 | #define PLLC_PLLDIV2 0x11c |
| 34 | #define PLLC_PLLDIV3 0x120 |
| 35 | #define PLLC_POSTDIV 0x128 |
| 36 | #define PLLC_BPDIV 0x12c |
| 37 | #define PLLC_PLLDIV4 0x160 |
| 38 | #define PLLC_PLLDIV5 0x164 |
| 39 | #define PLLC_PLLDIV6 0x168 |
Sudhakar Rajashekhara | 0a7fbec | 2011-09-03 22:18:04 -0400 | [diff] [blame] | 40 | #define PLLC_PLLDIV7 0x16c |
David Brownell | 4506400 | 2009-05-15 23:47:12 +0200 | [diff] [blame] | 41 | #define PLLC_PLLDIV8 0x170 |
| 42 | #define PLLC_PLLDIV9 0x174 |
| 43 | |
| 44 | #define BIT(x) (1 << (x)) |
| 45 | |
| 46 | /* SOC-specific pll info */ |
| 47 | #ifdef CONFIG_SOC_DM355 |
| 48 | #define ARM_PLLDIV PLLC_PLLDIV1 |
| 49 | #define DDR_PLLDIV PLLC_PLLDIV1 |
| 50 | #endif |
| 51 | |
| 52 | #ifdef CONFIG_SOC_DM644X |
| 53 | #define ARM_PLLDIV PLLC_PLLDIV2 |
| 54 | #define DSP_PLLDIV PLLC_PLLDIV1 |
| 55 | #define DDR_PLLDIV PLLC_PLLDIV2 |
| 56 | #endif |
| 57 | |
Sandeep Paulraj | e313d9d | 2010-12-29 14:31:26 -0500 | [diff] [blame] | 58 | #ifdef CONFIG_SOC_DM646X |
| 59 | #define DSP_PLLDIV PLLC_PLLDIV1 |
| 60 | #define ARM_PLLDIV PLLC_PLLDIV2 |
| 61 | #define DDR_PLLDIV PLLC_PLLDIV1 |
| 62 | #endif |
| 63 | |
Sekhar Nori | 302fc2f | 2009-11-12 11:07:22 -0500 | [diff] [blame] | 64 | #ifdef CONFIG_SOC_DA8XX |
Sudhakar Rajashekhara | 0a7fbec | 2011-09-03 22:18:04 -0400 | [diff] [blame] | 65 | unsigned int sysdiv[9] = { |
| 66 | PLLC_PLLDIV1, PLLC_PLLDIV2, PLLC_PLLDIV3, PLLC_PLLDIV4, PLLC_PLLDIV5, |
| 67 | PLLC_PLLDIV6, PLLC_PLLDIV7, PLLC_PLLDIV8, PLLC_PLLDIV9 |
Sekhar Nori | 302fc2f | 2009-11-12 11:07:22 -0500 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | int clk_get(enum davinci_clk_ids id) |
| 71 | { |
| 72 | int pre_div; |
| 73 | int pllm; |
| 74 | int post_div; |
| 75 | int pll_out; |
Sudhakar Rajashekhara | 0a7fbec | 2011-09-03 22:18:04 -0400 | [diff] [blame] | 76 | unsigned int pll_base; |
Sekhar Nori | 302fc2f | 2009-11-12 11:07:22 -0500 | [diff] [blame] | 77 | |
| 78 | pll_out = CONFIG_SYS_OSCIN_FREQ; |
| 79 | |
| 80 | if (id == DAVINCI_AUXCLK_CLKID) |
| 81 | goto out; |
| 82 | |
Sudhakar Rajashekhara | 0a7fbec | 2011-09-03 22:18:04 -0400 | [diff] [blame] | 83 | if ((id >> 16) == 1) |
| 84 | pll_base = (unsigned int)davinci_pllc1_regs; |
| 85 | else |
| 86 | pll_base = (unsigned int)davinci_pllc0_regs; |
| 87 | |
| 88 | id &= 0xFFFF; |
| 89 | |
Sekhar Nori | 302fc2f | 2009-11-12 11:07:22 -0500 | [diff] [blame] | 90 | /* |
| 91 | * Lets keep this simple. Combining operations can result in |
| 92 | * unexpected approximations |
| 93 | */ |
Sudhakar Rajashekhara | 0a7fbec | 2011-09-03 22:18:04 -0400 | [diff] [blame] | 94 | pre_div = (readl(pll_base + PLLC_PREDIV) & |
| 95 | DAVINCI_PLLC_DIV_MASK) + 1; |
| 96 | pllm = readl(pll_base + PLLC_PLLM) + 1; |
Sekhar Nori | 302fc2f | 2009-11-12 11:07:22 -0500 | [diff] [blame] | 97 | |
| 98 | pll_out /= pre_div; |
| 99 | pll_out *= pllm; |
| 100 | |
| 101 | if (id == DAVINCI_PLLM_CLKID) |
| 102 | goto out; |
| 103 | |
Sudhakar Rajashekhara | 0a7fbec | 2011-09-03 22:18:04 -0400 | [diff] [blame] | 104 | post_div = (readl(pll_base + PLLC_POSTDIV) & |
| 105 | DAVINCI_PLLC_DIV_MASK) + 1; |
Sekhar Nori | 302fc2f | 2009-11-12 11:07:22 -0500 | [diff] [blame] | 106 | |
| 107 | pll_out /= post_div; |
| 108 | |
| 109 | if (id == DAVINCI_PLLC_CLKID) |
| 110 | goto out; |
| 111 | |
Sudhakar Rajashekhara | 0a7fbec | 2011-09-03 22:18:04 -0400 | [diff] [blame] | 112 | pll_out /= (readl(pll_base + sysdiv[id - 1]) & |
| 113 | DAVINCI_PLLC_DIV_MASK) + 1; |
Sekhar Nori | 302fc2f | 2009-11-12 11:07:22 -0500 | [diff] [blame] | 114 | |
| 115 | out: |
| 116 | return pll_out; |
| 117 | } |
Heiko Schocher | 6e2aa47 | 2011-09-14 19:59:39 +0000 | [diff] [blame] | 118 | #ifdef CONFIG_DISPLAY_CPUINFO |
| 119 | int print_cpuinfo(void) |
| 120 | { |
| 121 | printf("Cores: ARM %d MHz", |
| 122 | clk_get(DAVINCI_ARM_CLKID) / 1000000); |
| 123 | printf("\nDDR: %d MHz\n", |
| 124 | /* DDR PHY uses an x2 input clock */ |
| 125 | clk_get(0x10001) / 1000000); |
| 126 | return 0; |
| 127 | } |
| 128 | #endif |
| 129 | #else /* CONFIG_SOC_DA8XX */ |
David Brownell | 4506400 | 2009-05-15 23:47:12 +0200 | [diff] [blame] | 130 | |
| 131 | #ifdef CONFIG_DISPLAY_CPUINFO |
| 132 | |
| 133 | static unsigned pll_div(volatile void *pllbase, unsigned offset) |
| 134 | { |
| 135 | u32 div; |
| 136 | |
| 137 | div = REG(pllbase + offset); |
| 138 | return (div & BIT(15)) ? (1 + (div & 0x1f)) : 1; |
| 139 | } |
| 140 | |
| 141 | static inline unsigned pll_prediv(volatile void *pllbase) |
| 142 | { |
| 143 | #ifdef CONFIG_SOC_DM355 |
| 144 | /* this register read seems to fail on pll0 */ |
| 145 | if (pllbase == (volatile void *)DAVINCI_PLL_CNTRL0_BASE) |
| 146 | return 8; |
| 147 | else |
| 148 | return pll_div(pllbase, PLLC_PREDIV); |
Heiko Schocher | 59214f8 | 2011-11-01 20:00:33 +0000 | [diff] [blame^] | 149 | #elif defined(CONFIG_SOC_DM365) |
| 150 | return pll_div(pllbase, PLLC_PREDIV); |
David Brownell | 4506400 | 2009-05-15 23:47:12 +0200 | [diff] [blame] | 151 | #endif |
| 152 | return 1; |
| 153 | } |
| 154 | |
| 155 | static inline unsigned pll_postdiv(volatile void *pllbase) |
| 156 | { |
Heiko Schocher | 59214f8 | 2011-11-01 20:00:33 +0000 | [diff] [blame^] | 157 | #if defined(CONFIG_SOC_DM355) || defined(CONFIG_SOC_DM365) |
David Brownell | 4506400 | 2009-05-15 23:47:12 +0200 | [diff] [blame] | 158 | return pll_div(pllbase, PLLC_POSTDIV); |
| 159 | #elif defined(CONFIG_SOC_DM6446) |
| 160 | if (pllbase == (volatile void *)DAVINCI_PLL_CNTRL0_BASE) |
| 161 | return pll_div(pllbase, PLLC_POSTDIV); |
| 162 | #endif |
| 163 | return 1; |
| 164 | } |
| 165 | |
| 166 | static unsigned pll_sysclk_mhz(unsigned pll_addr, unsigned div) |
| 167 | { |
| 168 | volatile void *pllbase = (volatile void *) pll_addr; |
Sandeep Paulraj | e313d9d | 2010-12-29 14:31:26 -0500 | [diff] [blame] | 169 | #ifdef CONFIG_SOC_DM646X |
| 170 | unsigned base = CFG_REFCLK_FREQ / 1000; |
| 171 | #else |
David Brownell | 4506400 | 2009-05-15 23:47:12 +0200 | [diff] [blame] | 172 | unsigned base = CONFIG_SYS_HZ_CLOCK / 1000; |
Sandeep Paulraj | e313d9d | 2010-12-29 14:31:26 -0500 | [diff] [blame] | 173 | #endif |
David Brownell | 4506400 | 2009-05-15 23:47:12 +0200 | [diff] [blame] | 174 | |
| 175 | /* the PLL might be bypassed */ |
Heiko Schocher | 59214f8 | 2011-11-01 20:00:33 +0000 | [diff] [blame^] | 176 | if (readl(pllbase + PLLC_PLLCTL) & BIT(0)) { |
David Brownell | 4506400 | 2009-05-15 23:47:12 +0200 | [diff] [blame] | 177 | base /= pll_prediv(pllbase); |
Heiko Schocher | 59214f8 | 2011-11-01 20:00:33 +0000 | [diff] [blame^] | 178 | #if defined(CONFIG_SOC_DM365) |
| 179 | base *= 2 * (readl(pllbase + PLLC_PLLM) & 0x0ff); |
| 180 | #else |
David Brownell | 4506400 | 2009-05-15 23:47:12 +0200 | [diff] [blame] | 181 | base *= 1 + (REG(pllbase + PLLC_PLLM) & 0x0ff); |
Heiko Schocher | 59214f8 | 2011-11-01 20:00:33 +0000 | [diff] [blame^] | 182 | #endif |
David Brownell | 4506400 | 2009-05-15 23:47:12 +0200 | [diff] [blame] | 183 | base /= pll_postdiv(pllbase); |
| 184 | } |
| 185 | return DIV_ROUND_UP(base, 1000 * pll_div(pllbase, div)); |
| 186 | } |
| 187 | |
| 188 | int print_cpuinfo(void) |
| 189 | { |
| 190 | /* REVISIT fetch and display CPU ID and revision information |
| 191 | * too ... that will matter as more revisions appear. |
| 192 | */ |
Heiko Schocher | 59214f8 | 2011-11-01 20:00:33 +0000 | [diff] [blame^] | 193 | #if defined(CONFIG_SOC_DM365) |
| 194 | printf("Cores: ARM %d MHz", |
| 195 | pll_sysclk_mhz(DAVINCI_PLL_CNTRL1_BASE, ARM_PLLDIV)); |
| 196 | #else |
David Brownell | 4506400 | 2009-05-15 23:47:12 +0200 | [diff] [blame] | 197 | printf("Cores: ARM %d MHz", |
| 198 | pll_sysclk_mhz(DAVINCI_PLL_CNTRL0_BASE, ARM_PLLDIV)); |
Heiko Schocher | 59214f8 | 2011-11-01 20:00:33 +0000 | [diff] [blame^] | 199 | #endif |
David Brownell | 4506400 | 2009-05-15 23:47:12 +0200 | [diff] [blame] | 200 | |
| 201 | #ifdef DSP_PLLDIV |
| 202 | printf(", DSP %d MHz", |
| 203 | pll_sysclk_mhz(DAVINCI_PLL_CNTRL0_BASE, DSP_PLLDIV)); |
| 204 | #endif |
| 205 | |
| 206 | printf("\nDDR: %d MHz\n", |
| 207 | /* DDR PHY uses an x2 input clock */ |
Heiko Schocher | 59214f8 | 2011-11-01 20:00:33 +0000 | [diff] [blame^] | 208 | #if defined(CONFIG_SOC_DM365) |
| 209 | pll_sysclk_mhz(DAVINCI_PLL_CNTRL0_BASE, DDR_PLLDIV) |
| 210 | / 2); |
| 211 | #else |
David Brownell | 4506400 | 2009-05-15 23:47:12 +0200 | [diff] [blame] | 212 | pll_sysclk_mhz(DAVINCI_PLL_CNTRL1_BASE, DDR_PLLDIV) |
| 213 | / 2); |
Heiko Schocher | 59214f8 | 2011-11-01 20:00:33 +0000 | [diff] [blame^] | 214 | #endif |
David Brownell | 4506400 | 2009-05-15 23:47:12 +0200 | [diff] [blame] | 215 | return 0; |
| 216 | } |
| 217 | |
Sandeep Paulraj | e313d9d | 2010-12-29 14:31:26 -0500 | [diff] [blame] | 218 | #ifdef DAVINCI_DM6467EVM |
| 219 | unsigned int davinci_arm_clk_get() |
| 220 | { |
| 221 | return pll_sysclk_mhz(DAVINCI_PLL_CNTRL0_BASE, ARM_PLLDIV) * 1000000; |
| 222 | } |
| 223 | #endif |
Heiko Schocher | 59214f8 | 2011-11-01 20:00:33 +0000 | [diff] [blame^] | 224 | |
| 225 | #if defined(CONFIG_SOC_DM365) |
| 226 | unsigned int davinci_clk_get(unsigned int div) |
| 227 | { |
| 228 | return pll_sysclk_mhz(DAVINCI_PLL_CNTRL0_BASE, div) * 1000000; |
| 229 | } |
| 230 | #endif |
Heiko Schocher | 6e2aa47 | 2011-09-14 19:59:39 +0000 | [diff] [blame] | 231 | #endif /* CONFIG_DISPLAY_CPUINFO */ |
| 232 | #endif /* !CONFIG_SOC_DA8XX */ |
David Brownell | 4506400 | 2009-05-15 23:47:12 +0200 | [diff] [blame] | 233 | |
Ben Warren | 5301bbf | 2009-05-26 00:34:07 -0700 | [diff] [blame] | 234 | /* |
| 235 | * Initializes on-chip ethernet controllers. |
| 236 | * to override, implement board_eth_init() |
| 237 | */ |
| 238 | int cpu_eth_init(bd_t *bis) |
| 239 | { |
| 240 | #if defined(CONFIG_DRIVER_TI_EMAC) |
| 241 | davinci_emac_initialize(); |
| 242 | #endif |
| 243 | return 0; |
| 244 | } |