David Brownell | 7a4f511 | 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 | 8453587 | 2009-05-26 00:34:07 -0700 | [diff] [blame] | 24 | #include <netdev.h> |
David Brownell | 7a4f511 | 2009-05-15 23:47:12 +0200 | [diff] [blame] | 25 | #include <asm/arch/hardware.h> |
Sekhar Nori | 91172ba | 2009-11-12 11:07:22 -0500 | [diff] [blame] | 26 | #include <asm/io.h> |
David Brownell | 7a4f511 | 2009-05-15 23:47:12 +0200 | [diff] [blame] | 27 | |
Hadli, Manjunath | 8f5d468 | 2012-02-06 00:30:44 +0000 | [diff] [blame^] | 28 | DECLARE_GLOBAL_DATA_PTR; |
| 29 | |
David Brownell | 7a4f511 | 2009-05-15 23:47:12 +0200 | [diff] [blame] | 30 | /* offsets from PLL controller base */ |
| 31 | #define PLLC_PLLCTL 0x100 |
| 32 | #define PLLC_PLLM 0x110 |
| 33 | #define PLLC_PREDIV 0x114 |
| 34 | #define PLLC_PLLDIV1 0x118 |
| 35 | #define PLLC_PLLDIV2 0x11c |
| 36 | #define PLLC_PLLDIV3 0x120 |
| 37 | #define PLLC_POSTDIV 0x128 |
| 38 | #define PLLC_BPDIV 0x12c |
| 39 | #define PLLC_PLLDIV4 0x160 |
| 40 | #define PLLC_PLLDIV5 0x164 |
| 41 | #define PLLC_PLLDIV6 0x168 |
Sudhakar Rajashekhara | b7e6843 | 2011-09-03 22:18:04 -0400 | [diff] [blame] | 42 | #define PLLC_PLLDIV7 0x16c |
David Brownell | 7a4f511 | 2009-05-15 23:47:12 +0200 | [diff] [blame] | 43 | #define PLLC_PLLDIV8 0x170 |
| 44 | #define PLLC_PLLDIV9 0x174 |
| 45 | |
| 46 | #define BIT(x) (1 << (x)) |
| 47 | |
| 48 | /* SOC-specific pll info */ |
| 49 | #ifdef CONFIG_SOC_DM355 |
| 50 | #define ARM_PLLDIV PLLC_PLLDIV1 |
| 51 | #define DDR_PLLDIV PLLC_PLLDIV1 |
| 52 | #endif |
| 53 | |
| 54 | #ifdef CONFIG_SOC_DM644X |
| 55 | #define ARM_PLLDIV PLLC_PLLDIV2 |
| 56 | #define DSP_PLLDIV PLLC_PLLDIV1 |
| 57 | #define DDR_PLLDIV PLLC_PLLDIV2 |
| 58 | #endif |
| 59 | |
Sandeep Paulraj | 5342a71 | 2010-12-29 14:31:26 -0500 | [diff] [blame] | 60 | #ifdef CONFIG_SOC_DM646X |
| 61 | #define DSP_PLLDIV PLLC_PLLDIV1 |
| 62 | #define ARM_PLLDIV PLLC_PLLDIV2 |
| 63 | #define DDR_PLLDIV PLLC_PLLDIV1 |
| 64 | #endif |
| 65 | |
Sekhar Nori | 91172ba | 2009-11-12 11:07:22 -0500 | [diff] [blame] | 66 | #ifdef CONFIG_SOC_DA8XX |
Sudhakar Rajashekhara | b7e6843 | 2011-09-03 22:18:04 -0400 | [diff] [blame] | 67 | unsigned int sysdiv[9] = { |
| 68 | PLLC_PLLDIV1, PLLC_PLLDIV2, PLLC_PLLDIV3, PLLC_PLLDIV4, PLLC_PLLDIV5, |
| 69 | PLLC_PLLDIV6, PLLC_PLLDIV7, PLLC_PLLDIV8, PLLC_PLLDIV9 |
Sekhar Nori | 91172ba | 2009-11-12 11:07:22 -0500 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | int clk_get(enum davinci_clk_ids id) |
| 73 | { |
| 74 | int pre_div; |
| 75 | int pllm; |
| 76 | int post_div; |
| 77 | int pll_out; |
Sudhakar Rajashekhara | b7e6843 | 2011-09-03 22:18:04 -0400 | [diff] [blame] | 78 | unsigned int pll_base; |
Sekhar Nori | 91172ba | 2009-11-12 11:07:22 -0500 | [diff] [blame] | 79 | |
| 80 | pll_out = CONFIG_SYS_OSCIN_FREQ; |
| 81 | |
| 82 | if (id == DAVINCI_AUXCLK_CLKID) |
| 83 | goto out; |
| 84 | |
Sudhakar Rajashekhara | b7e6843 | 2011-09-03 22:18:04 -0400 | [diff] [blame] | 85 | if ((id >> 16) == 1) |
| 86 | pll_base = (unsigned int)davinci_pllc1_regs; |
| 87 | else |
| 88 | pll_base = (unsigned int)davinci_pllc0_regs; |
| 89 | |
| 90 | id &= 0xFFFF; |
| 91 | |
Sekhar Nori | 91172ba | 2009-11-12 11:07:22 -0500 | [diff] [blame] | 92 | /* |
| 93 | * Lets keep this simple. Combining operations can result in |
| 94 | * unexpected approximations |
| 95 | */ |
Sudhakar Rajashekhara | b7e6843 | 2011-09-03 22:18:04 -0400 | [diff] [blame] | 96 | pre_div = (readl(pll_base + PLLC_PREDIV) & |
| 97 | DAVINCI_PLLC_DIV_MASK) + 1; |
| 98 | pllm = readl(pll_base + PLLC_PLLM) + 1; |
Sekhar Nori | 91172ba | 2009-11-12 11:07:22 -0500 | [diff] [blame] | 99 | |
| 100 | pll_out /= pre_div; |
| 101 | pll_out *= pllm; |
| 102 | |
| 103 | if (id == DAVINCI_PLLM_CLKID) |
| 104 | goto out; |
| 105 | |
Sudhakar Rajashekhara | b7e6843 | 2011-09-03 22:18:04 -0400 | [diff] [blame] | 106 | post_div = (readl(pll_base + PLLC_POSTDIV) & |
| 107 | DAVINCI_PLLC_DIV_MASK) + 1; |
Sekhar Nori | 91172ba | 2009-11-12 11:07:22 -0500 | [diff] [blame] | 108 | |
| 109 | pll_out /= post_div; |
| 110 | |
| 111 | if (id == DAVINCI_PLLC_CLKID) |
| 112 | goto out; |
| 113 | |
Sudhakar Rajashekhara | b7e6843 | 2011-09-03 22:18:04 -0400 | [diff] [blame] | 114 | pll_out /= (readl(pll_base + sysdiv[id - 1]) & |
| 115 | DAVINCI_PLLC_DIV_MASK) + 1; |
Sekhar Nori | 91172ba | 2009-11-12 11:07:22 -0500 | [diff] [blame] | 116 | |
| 117 | out: |
| 118 | return pll_out; |
| 119 | } |
Heiko Schocher | 0a0522c | 2011-09-14 19:59:39 +0000 | [diff] [blame] | 120 | #else /* CONFIG_SOC_DA8XX */ |
David Brownell | 7a4f511 | 2009-05-15 23:47:12 +0200 | [diff] [blame] | 121 | |
David Brownell | 7a4f511 | 2009-05-15 23:47:12 +0200 | [diff] [blame] | 122 | static unsigned pll_div(volatile void *pllbase, unsigned offset) |
| 123 | { |
| 124 | u32 div; |
| 125 | |
| 126 | div = REG(pllbase + offset); |
| 127 | return (div & BIT(15)) ? (1 + (div & 0x1f)) : 1; |
| 128 | } |
| 129 | |
| 130 | static inline unsigned pll_prediv(volatile void *pllbase) |
| 131 | { |
| 132 | #ifdef CONFIG_SOC_DM355 |
| 133 | /* this register read seems to fail on pll0 */ |
| 134 | if (pllbase == (volatile void *)DAVINCI_PLL_CNTRL0_BASE) |
| 135 | return 8; |
| 136 | else |
| 137 | return pll_div(pllbase, PLLC_PREDIV); |
Heiko Schocher | 29b0bef | 2011-11-01 20:00:33 +0000 | [diff] [blame] | 138 | #elif defined(CONFIG_SOC_DM365) |
| 139 | return pll_div(pllbase, PLLC_PREDIV); |
David Brownell | 7a4f511 | 2009-05-15 23:47:12 +0200 | [diff] [blame] | 140 | #endif |
| 141 | return 1; |
| 142 | } |
| 143 | |
| 144 | static inline unsigned pll_postdiv(volatile void *pllbase) |
| 145 | { |
Heiko Schocher | 29b0bef | 2011-11-01 20:00:33 +0000 | [diff] [blame] | 146 | #if defined(CONFIG_SOC_DM355) || defined(CONFIG_SOC_DM365) |
David Brownell | 7a4f511 | 2009-05-15 23:47:12 +0200 | [diff] [blame] | 147 | return pll_div(pllbase, PLLC_POSTDIV); |
| 148 | #elif defined(CONFIG_SOC_DM6446) |
| 149 | if (pllbase == (volatile void *)DAVINCI_PLL_CNTRL0_BASE) |
| 150 | return pll_div(pllbase, PLLC_POSTDIV); |
| 151 | #endif |
| 152 | return 1; |
| 153 | } |
| 154 | |
| 155 | static unsigned pll_sysclk_mhz(unsigned pll_addr, unsigned div) |
| 156 | { |
| 157 | volatile void *pllbase = (volatile void *) pll_addr; |
Sandeep Paulraj | 5342a71 | 2010-12-29 14:31:26 -0500 | [diff] [blame] | 158 | #ifdef CONFIG_SOC_DM646X |
| 159 | unsigned base = CFG_REFCLK_FREQ / 1000; |
| 160 | #else |
David Brownell | 7a4f511 | 2009-05-15 23:47:12 +0200 | [diff] [blame] | 161 | unsigned base = CONFIG_SYS_HZ_CLOCK / 1000; |
Sandeep Paulraj | 5342a71 | 2010-12-29 14:31:26 -0500 | [diff] [blame] | 162 | #endif |
David Brownell | 7a4f511 | 2009-05-15 23:47:12 +0200 | [diff] [blame] | 163 | |
| 164 | /* the PLL might be bypassed */ |
Heiko Schocher | 29b0bef | 2011-11-01 20:00:33 +0000 | [diff] [blame] | 165 | if (readl(pllbase + PLLC_PLLCTL) & BIT(0)) { |
David Brownell | 7a4f511 | 2009-05-15 23:47:12 +0200 | [diff] [blame] | 166 | base /= pll_prediv(pllbase); |
Heiko Schocher | 29b0bef | 2011-11-01 20:00:33 +0000 | [diff] [blame] | 167 | #if defined(CONFIG_SOC_DM365) |
| 168 | base *= 2 * (readl(pllbase + PLLC_PLLM) & 0x0ff); |
| 169 | #else |
David Brownell | 7a4f511 | 2009-05-15 23:47:12 +0200 | [diff] [blame] | 170 | base *= 1 + (REG(pllbase + PLLC_PLLM) & 0x0ff); |
Heiko Schocher | 29b0bef | 2011-11-01 20:00:33 +0000 | [diff] [blame] | 171 | #endif |
David Brownell | 7a4f511 | 2009-05-15 23:47:12 +0200 | [diff] [blame] | 172 | base /= pll_postdiv(pllbase); |
| 173 | } |
| 174 | return DIV_ROUND_UP(base, 1000 * pll_div(pllbase, div)); |
| 175 | } |
| 176 | |
Sandeep Paulraj | 5342a71 | 2010-12-29 14:31:26 -0500 | [diff] [blame] | 177 | #ifdef DAVINCI_DM6467EVM |
| 178 | unsigned int davinci_arm_clk_get() |
| 179 | { |
| 180 | return pll_sysclk_mhz(DAVINCI_PLL_CNTRL0_BASE, ARM_PLLDIV) * 1000000; |
| 181 | } |
| 182 | #endif |
Heiko Schocher | 29b0bef | 2011-11-01 20:00:33 +0000 | [diff] [blame] | 183 | |
| 184 | #if defined(CONFIG_SOC_DM365) |
| 185 | unsigned int davinci_clk_get(unsigned int div) |
| 186 | { |
| 187 | return pll_sysclk_mhz(DAVINCI_PLL_CNTRL0_BASE, div) * 1000000; |
| 188 | } |
| 189 | #endif |
Heiko Schocher | 0a0522c | 2011-09-14 19:59:39 +0000 | [diff] [blame] | 190 | #endif /* !CONFIG_SOC_DA8XX */ |
David Brownell | 7a4f511 | 2009-05-15 23:47:12 +0200 | [diff] [blame] | 191 | |
Hadli, Manjunath | 8f5d468 | 2012-02-06 00:30:44 +0000 | [diff] [blame^] | 192 | int set_cpu_clk_info(void) |
| 193 | { |
| 194 | #ifdef CONFIG_SOC_DA8XX |
| 195 | gd->bd->bi_arm_freq = clk_get(DAVINCI_ARM_CLKID) / 1000000; |
| 196 | /* DDR PHY uses an x2 input clock */ |
| 197 | gd->bd->bi_ddr_freq = clk_get(0x10001) / 1000000; |
| 198 | #else |
| 199 | |
| 200 | unsigned int pllbase = DAVINCI_PLL_CNTRL0_BASE; |
| 201 | #if defined(CONFIG_SOC_DM365) |
| 202 | pllbase = DAVINCI_PLL_CNTRL1_BASE; |
| 203 | #endif |
| 204 | gd->bd->bi_arm_freq = pll_sysclk_mhz(pllbase, ARM_PLLDIV); |
| 205 | |
| 206 | #ifdef DSP_PLLDIV |
| 207 | gd->bd->bi_dsp_freq = |
| 208 | pll_sysclk_mhz(DAVINCI_PLL_CNTRL0_BASE, DSP_PLLDIV); |
| 209 | #else |
| 210 | gd->bd->bi_dsp_freq = 0; |
| 211 | #endif |
| 212 | |
| 213 | pllbase = DAVINCI_PLL_CNTRL1_BASE; |
| 214 | #if defined(CONFIG_SOC_DM365) |
| 215 | pllbase = DAVINCI_PLL_CNTRL0_BASE; |
| 216 | #endif |
| 217 | gd->bd->bi_ddr_freq = pll_sysclk_mhz(pllbase, DDR_PLLDIV) / 2; |
| 218 | #endif |
| 219 | return 0; |
| 220 | } |
| 221 | |
Ben Warren | 8453587 | 2009-05-26 00:34:07 -0700 | [diff] [blame] | 222 | /* |
| 223 | * Initializes on-chip ethernet controllers. |
| 224 | * to override, implement board_eth_init() |
| 225 | */ |
| 226 | int cpu_eth_init(bd_t *bis) |
| 227 | { |
| 228 | #if defined(CONFIG_DRIVER_TI_EMAC) |
| 229 | davinci_emac_initialize(); |
| 230 | #endif |
| 231 | return 0; |
| 232 | } |