wdenk | 983fda8 | 2004-10-28 00:09:35 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2004, Freescale, Inc |
| 3 | * TsiChung Liew, Tsi-Chung.Liew@freescale.com. |
| 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 |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (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., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #include <common.h> |
| 25 | #include <mpc8220.h> |
| 26 | #include <asm/processor.h> |
| 27 | |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 28 | DECLARE_GLOBAL_DATA_PTR; |
| 29 | |
wdenk | 983fda8 | 2004-10-28 00:09:35 +0000 | [diff] [blame] | 30 | typedef struct pllmultiplier { |
| 31 | u8 hid1; |
| 32 | int multi; |
| 33 | int vco_div; |
| 34 | } pllcfg_t; |
| 35 | |
| 36 | /* ------------------------------------------------------------------------- */ |
| 37 | |
| 38 | /* |
| 39 | * |
| 40 | */ |
| 41 | |
| 42 | int get_clocks (void) |
| 43 | { |
wdenk | 983fda8 | 2004-10-28 00:09:35 +0000 | [diff] [blame] | 44 | pllcfg_t bus2core[] = { |
wdenk | 12b43d5 | 2005-04-05 21:57:18 +0000 | [diff] [blame] | 45 | {0x02, 2, 8}, /* 1 */ |
| 46 | {0x01, 2, 4}, |
| 47 | {0x0C, 3, 8}, /* 1.5 */ |
wdenk | 983fda8 | 2004-10-28 00:09:35 +0000 | [diff] [blame] | 48 | {0x00, 3, 4}, |
wdenk | 12b43d5 | 2005-04-05 21:57:18 +0000 | [diff] [blame] | 49 | {0x18, 3, 2}, |
| 50 | {0x05, 4, 4}, /* 2 */ |
| 51 | {0x04, 4, 2}, |
| 52 | {0x11, 5, 4}, /* 2.5 */ |
| 53 | {0x06, 5, 2}, |
| 54 | {0x10, 6, 4}, /* 3 */ |
| 55 | {0x08, 6, 2}, |
| 56 | {0x0E, 7, 2}, /* 3.5 */ |
| 57 | {0x0A, 8, 2}, /* 4 */ |
| 58 | {0x07, 9, 2}, /* 4.5 */ |
| 59 | {0x0B, 10, 2}, /* 5 */ |
| 60 | {0x09, 11, 2}, /* 5.5 */ |
| 61 | {0x0D, 12, 2}, /* 6 */ |
| 62 | {0x12, 13, 2}, /* 6.5 */ |
| 63 | {0x14, 14, 2}, /* 7 */ |
| 64 | {0x16, 15, 2}, /* 7.5 */ |
| 65 | {0x1C, 16, 2} /* 8 */ |
wdenk | 983fda8 | 2004-10-28 00:09:35 +0000 | [diff] [blame] | 66 | }; |
| 67 | u32 hid1; |
wdenk | 12b43d5 | 2005-04-05 21:57:18 +0000 | [diff] [blame] | 68 | int i, size, pci2bus; |
wdenk | 983fda8 | 2004-10-28 00:09:35 +0000 | [diff] [blame] | 69 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 70 | #if !defined(CONFIG_SYS_MPC8220_CLKIN) |
| 71 | #error clock measuring not implemented yet - define CONFIG_SYS_MPC8220_CLKIN |
wdenk | 983fda8 | 2004-10-28 00:09:35 +0000 | [diff] [blame] | 72 | #endif |
| 73 | |
Simon Glass | 1c35613 | 2012-12-13 20:48:55 +0000 | [diff] [blame] | 74 | gd->arch.inp_clk = CONFIG_SYS_MPC8220_CLKIN; |
wdenk | 983fda8 | 2004-10-28 00:09:35 +0000 | [diff] [blame] | 75 | |
wdenk | 12b43d5 | 2005-04-05 21:57:18 +0000 | [diff] [blame] | 76 | /* Read XLB to PCI(INP) clock multiplier */ |
wdenk | 3c2b3d4 | 2005-04-05 23:32:21 +0000 | [diff] [blame] | 77 | pci2bus = (*((volatile u32 *)PCI_REG_PCIGSCR) & |
wdenk | 12b43d5 | 2005-04-05 21:57:18 +0000 | [diff] [blame] | 78 | PCI_REG_PCIGSCR_PCI2XLB_CLK_MASK)>>PCI_REG_PCIGSCR_PCI2XLB_CLK_BIT; |
| 79 | |
| 80 | /* XLB bus clock */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 81 | gd->bus_clk = CONFIG_SYS_MPC8220_CLKIN * pci2bus; |
wdenk | 983fda8 | 2004-10-28 00:09:35 +0000 | [diff] [blame] | 82 | |
| 83 | /* PCI clock is same as input clock */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 84 | gd->pci_clk = CONFIG_SYS_MPC8220_CLKIN; |
wdenk | 983fda8 | 2004-10-28 00:09:35 +0000 | [diff] [blame] | 85 | |
| 86 | /* FlexBus is temporary set as the same as input clock */ |
| 87 | /* will do dynamic in the future */ |
Simon Glass | 1c35613 | 2012-12-13 20:48:55 +0000 | [diff] [blame] | 88 | gd->arch.flb_clk = CONFIG_SYS_MPC8220_CLKIN; |
wdenk | 983fda8 | 2004-10-28 00:09:35 +0000 | [diff] [blame] | 89 | |
| 90 | /* CPU Clock - Read HID1 */ |
| 91 | asm volatile ("mfspr %0, 1009":"=r" (hid1):); |
| 92 | |
| 93 | size = sizeof (bus2core) / sizeof (pllcfg_t); |
wdenk | 12b43d5 | 2005-04-05 21:57:18 +0000 | [diff] [blame] | 94 | |
| 95 | hid1 >>= 27; |
wdenk | 983fda8 | 2004-10-28 00:09:35 +0000 | [diff] [blame] | 96 | |
| 97 | for (i = 0; i < size; i++) |
| 98 | if (hid1 == bus2core[i].hid1) { |
| 99 | gd->cpu_clk = (bus2core[i].multi * gd->bus_clk) >> 1; |
Simon Glass | 1c35613 | 2012-12-13 20:48:55 +0000 | [diff] [blame] | 100 | gd->arch.vco_clk = |
| 101 | CONFIG_SYS_MPC8220_SYSPLL_VCO_MULTIPLIER * |
| 102 | (gd->pci_clk * bus2core[i].vco_div) / 2; |
wdenk | 983fda8 | 2004-10-28 00:09:35 +0000 | [diff] [blame] | 103 | break; |
| 104 | } |
| 105 | |
| 106 | /* hardcoded 81MHz for now */ |
Simon Glass | 1c35613 | 2012-12-13 20:48:55 +0000 | [diff] [blame] | 107 | gd->arch.pev_clk = 81000000; |
wdenk | 983fda8 | 2004-10-28 00:09:35 +0000 | [diff] [blame] | 108 | |
| 109 | return (0); |
| 110 | } |
| 111 | |
| 112 | int prt_mpc8220_clks (void) |
| 113 | { |
Wolfgang Denk | 08ef89e | 2008-10-19 02:35:49 +0200 | [diff] [blame] | 114 | char buf1[32], buf2[32], buf3[32], buf4[32]; |
wdenk | 983fda8 | 2004-10-28 00:09:35 +0000 | [diff] [blame] | 115 | |
Wolfgang Denk | 08ef89e | 2008-10-19 02:35:49 +0200 | [diff] [blame] | 116 | printf (" Bus %s MHz, CPU %s MHz, PCI %s MHz, VCO %s MHz\n", |
| 117 | strmhz(buf1, gd->bus_clk), |
| 118 | strmhz(buf2, gd->cpu_clk), |
| 119 | strmhz(buf3, gd->pci_clk), |
Simon Glass | 1c35613 | 2012-12-13 20:48:55 +0000 | [diff] [blame] | 120 | strmhz(buf4, gd->arch.vco_clk) |
Wolfgang Denk | 08ef89e | 2008-10-19 02:35:49 +0200 | [diff] [blame] | 121 | ); |
wdenk | 983fda8 | 2004-10-28 00:09:35 +0000 | [diff] [blame] | 122 | return (0); |
| 123 | } |
| 124 | |
| 125 | /* ------------------------------------------------------------------------- */ |