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 |
| 40 | #define PLLC_PLLDIV8 0x170 |
| 41 | #define PLLC_PLLDIV9 0x174 |
| 42 | |
| 43 | #define BIT(x) (1 << (x)) |
| 44 | |
| 45 | /* SOC-specific pll info */ |
| 46 | #ifdef CONFIG_SOC_DM355 |
| 47 | #define ARM_PLLDIV PLLC_PLLDIV1 |
| 48 | #define DDR_PLLDIV PLLC_PLLDIV1 |
| 49 | #endif |
| 50 | |
| 51 | #ifdef CONFIG_SOC_DM644X |
| 52 | #define ARM_PLLDIV PLLC_PLLDIV2 |
| 53 | #define DSP_PLLDIV PLLC_PLLDIV1 |
| 54 | #define DDR_PLLDIV PLLC_PLLDIV2 |
| 55 | #endif |
| 56 | |
| 57 | #ifdef CONFIG_SOC_DM6447 |
| 58 | #define ARM_PLLDIV PLLC_PLLDIV2 |
| 59 | #define DSP_PLLDIV PLLC_PLLDIV1 |
| 60 | #define DDR_PLLDIV PLLC_PLLDIV1 |
| 61 | #endif |
| 62 | |
Sandeep Paulraj | e313d9d | 2010-12-29 14:31:26 -0500 | [diff] [blame^] | 63 | #ifdef CONFIG_SOC_DM646X |
| 64 | #define DSP_PLLDIV PLLC_PLLDIV1 |
| 65 | #define ARM_PLLDIV PLLC_PLLDIV2 |
| 66 | #define DDR_PLLDIV PLLC_PLLDIV1 |
| 67 | #endif |
| 68 | |
Sekhar Nori | 302fc2f | 2009-11-12 11:07:22 -0500 | [diff] [blame] | 69 | #ifdef CONFIG_SOC_DA8XX |
| 70 | const dv_reg * const sysdiv[7] = { |
| 71 | &davinci_pllc_regs->plldiv1, &davinci_pllc_regs->plldiv2, |
| 72 | &davinci_pllc_regs->plldiv3, &davinci_pllc_regs->plldiv4, |
| 73 | &davinci_pllc_regs->plldiv5, &davinci_pllc_regs->plldiv6, |
| 74 | &davinci_pllc_regs->plldiv7 |
| 75 | }; |
| 76 | |
| 77 | int clk_get(enum davinci_clk_ids id) |
| 78 | { |
| 79 | int pre_div; |
| 80 | int pllm; |
| 81 | int post_div; |
| 82 | int pll_out; |
| 83 | |
| 84 | pll_out = CONFIG_SYS_OSCIN_FREQ; |
| 85 | |
| 86 | if (id == DAVINCI_AUXCLK_CLKID) |
| 87 | goto out; |
| 88 | |
| 89 | /* |
| 90 | * Lets keep this simple. Combining operations can result in |
| 91 | * unexpected approximations |
| 92 | */ |
| 93 | pre_div = (readl(&davinci_pllc_regs->prediv) & |
| 94 | DAVINCI_PLLC_DIV_MASK) + 1; |
| 95 | pllm = readl(&davinci_pllc_regs->pllm) + 1; |
| 96 | |
| 97 | pll_out /= pre_div; |
| 98 | pll_out *= pllm; |
| 99 | |
| 100 | if (id == DAVINCI_PLLM_CLKID) |
| 101 | goto out; |
| 102 | |
| 103 | post_div = (readl(&davinci_pllc_regs->postdiv) & |
| 104 | DAVINCI_PLLC_DIV_MASK) + 1; |
| 105 | |
| 106 | pll_out /= post_div; |
| 107 | |
| 108 | if (id == DAVINCI_PLLC_CLKID) |
| 109 | goto out; |
| 110 | |
| 111 | pll_out /= (readl(sysdiv[id - 1]) & DAVINCI_PLLC_DIV_MASK) + 1; |
| 112 | |
| 113 | out: |
| 114 | return pll_out; |
| 115 | } |
| 116 | #endif /* CONFIG_SOC_DA8XX */ |
David Brownell | 4506400 | 2009-05-15 23:47:12 +0200 | [diff] [blame] | 117 | |
| 118 | #ifdef CONFIG_DISPLAY_CPUINFO |
| 119 | |
| 120 | static unsigned pll_div(volatile void *pllbase, unsigned offset) |
| 121 | { |
| 122 | u32 div; |
| 123 | |
| 124 | div = REG(pllbase + offset); |
| 125 | return (div & BIT(15)) ? (1 + (div & 0x1f)) : 1; |
| 126 | } |
| 127 | |
| 128 | static inline unsigned pll_prediv(volatile void *pllbase) |
| 129 | { |
| 130 | #ifdef CONFIG_SOC_DM355 |
| 131 | /* this register read seems to fail on pll0 */ |
| 132 | if (pllbase == (volatile void *)DAVINCI_PLL_CNTRL0_BASE) |
| 133 | return 8; |
| 134 | else |
| 135 | return pll_div(pllbase, PLLC_PREDIV); |
| 136 | #endif |
| 137 | return 1; |
| 138 | } |
| 139 | |
| 140 | static inline unsigned pll_postdiv(volatile void *pllbase) |
| 141 | { |
| 142 | #ifdef CONFIG_SOC_DM355 |
| 143 | return pll_div(pllbase, PLLC_POSTDIV); |
| 144 | #elif defined(CONFIG_SOC_DM6446) |
| 145 | if (pllbase == (volatile void *)DAVINCI_PLL_CNTRL0_BASE) |
| 146 | return pll_div(pllbase, PLLC_POSTDIV); |
| 147 | #endif |
| 148 | return 1; |
| 149 | } |
| 150 | |
| 151 | static unsigned pll_sysclk_mhz(unsigned pll_addr, unsigned div) |
| 152 | { |
| 153 | volatile void *pllbase = (volatile void *) pll_addr; |
Sandeep Paulraj | e313d9d | 2010-12-29 14:31:26 -0500 | [diff] [blame^] | 154 | #ifdef CONFIG_SOC_DM646X |
| 155 | unsigned base = CFG_REFCLK_FREQ / 1000; |
| 156 | #else |
David Brownell | 4506400 | 2009-05-15 23:47:12 +0200 | [diff] [blame] | 157 | unsigned base = CONFIG_SYS_HZ_CLOCK / 1000; |
Sandeep Paulraj | e313d9d | 2010-12-29 14:31:26 -0500 | [diff] [blame^] | 158 | #endif |
David Brownell | 4506400 | 2009-05-15 23:47:12 +0200 | [diff] [blame] | 159 | |
| 160 | /* the PLL might be bypassed */ |
| 161 | if (REG(pllbase + PLLC_PLLCTL) & BIT(0)) { |
| 162 | base /= pll_prediv(pllbase); |
| 163 | base *= 1 + (REG(pllbase + PLLC_PLLM) & 0x0ff); |
| 164 | base /= pll_postdiv(pllbase); |
| 165 | } |
| 166 | return DIV_ROUND_UP(base, 1000 * pll_div(pllbase, div)); |
| 167 | } |
| 168 | |
| 169 | int print_cpuinfo(void) |
| 170 | { |
| 171 | /* REVISIT fetch and display CPU ID and revision information |
| 172 | * too ... that will matter as more revisions appear. |
| 173 | */ |
| 174 | printf("Cores: ARM %d MHz", |
| 175 | pll_sysclk_mhz(DAVINCI_PLL_CNTRL0_BASE, ARM_PLLDIV)); |
| 176 | |
| 177 | #ifdef DSP_PLLDIV |
| 178 | printf(", DSP %d MHz", |
| 179 | pll_sysclk_mhz(DAVINCI_PLL_CNTRL0_BASE, DSP_PLLDIV)); |
| 180 | #endif |
| 181 | |
| 182 | printf("\nDDR: %d MHz\n", |
| 183 | /* DDR PHY uses an x2 input clock */ |
| 184 | pll_sysclk_mhz(DAVINCI_PLL_CNTRL1_BASE, DDR_PLLDIV) |
| 185 | / 2); |
| 186 | return 0; |
| 187 | } |
| 188 | |
Sandeep Paulraj | e313d9d | 2010-12-29 14:31:26 -0500 | [diff] [blame^] | 189 | #ifdef DAVINCI_DM6467EVM |
| 190 | unsigned int davinci_arm_clk_get() |
| 191 | { |
| 192 | return pll_sysclk_mhz(DAVINCI_PLL_CNTRL0_BASE, ARM_PLLDIV) * 1000000; |
| 193 | } |
| 194 | #endif |
David Brownell | 4506400 | 2009-05-15 23:47:12 +0200 | [diff] [blame] | 195 | #endif |
| 196 | |
Ben Warren | 5301bbf | 2009-05-26 00:34:07 -0700 | [diff] [blame] | 197 | /* |
| 198 | * Initializes on-chip ethernet controllers. |
| 199 | * to override, implement board_eth_init() |
| 200 | */ |
| 201 | int cpu_eth_init(bd_t *bis) |
| 202 | { |
| 203 | #if defined(CONFIG_DRIVER_TI_EMAC) |
| 204 | davinci_emac_initialize(); |
| 205 | #endif |
| 206 | return 0; |
| 207 | } |