Patch by TsiChung Liew, 23 Sep 2004:
[oweals/u-boot.git] / cpu / mpc8220 / speed.c
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
28 typedef struct pllmultiplier {
29         u8 hid1;
30         int multi;
31         int vco_div;
32 } pllcfg_t;
33
34 /* ------------------------------------------------------------------------- */
35
36 /*
37  *
38  */
39
40 int get_clocks (void)
41 {
42         DECLARE_GLOBAL_DATA_PTR;
43
44         pllcfg_t bus2core[] = {
45                 {0x10, 2, 8},   /* 1 */
46                 {0x08, 2, 4},
47                 {0x60, 3, 8},   /* 1.5 */
48                 {0x00, 3, 4},
49                 {0xc0, 3, 2},
50                 {0x28, 4, 4},   /* 2 */
51                 {0x20, 4, 2},
52                 {0x88, 5, 4},   /* 2.5 */
53                 {0x30, 5, 2},
54                 {0x80, 6, 4},   /* 3 */
55                 {0x40, 6, 2},
56                 {0x70, 7, 2},   /* 3.5 */
57                 {0x50, 8, 2},   /* 4 */
58                 {0x38, 9, 2},   /* 4.5 */
59                 {0x58, 10, 2},  /* 5 */
60                 {0x48, 11, 2},  /* 5.5 */
61                 {0x68, 12, 2},  /* 6 */
62                 {0x90, 13, 2},  /* 6.5 */
63                 {0xa0, 14, 2},  /* 7 */
64                 {0xb0, 15, 2},  /* 7.5 */
65                 {0xe0, 16, 2}   /* 8 */
66         };
67         u32 hid1;
68         int i, size;
69
70 #if !defined(CFG_MPC8220_CLKIN)
71 #error clock measuring not implemented yet - define CFG_MPC8220_CLKIN
72 #endif
73
74         gd->inp_clk = CFG_MPC8220_CLKIN;
75
76         /* Bus clock is fixed at 120Mhz for now */
77         /* will do dynamic in the future */
78         gd->bus_clk = CFG_MPC8220_CLKIN * 4;
79
80         /* PCI clock is same as input clock */
81         gd->pci_clk = CFG_MPC8220_CLKIN;
82
83         /* FlexBus is temporary set as the same as input clock */
84         /* will do dynamic in the future */
85         gd->flb_clk = CFG_MPC8220_CLKIN;
86
87         /* CPU Clock - Read HID1 */
88         asm volatile ("mfspr %0, 1009":"=r" (hid1):);
89
90         size = sizeof (bus2core) / sizeof (pllcfg_t);
91         hid1 >>= 24;
92
93         for (i = 0; i < size; i++)
94                 if (hid1 == bus2core[i].hid1) {
95                         gd->cpu_clk = (bus2core[i].multi * gd->bus_clk) >> 1;
96                         /* Input Multiplier is determined by MPLL,
97                            hardcoded for now at 16 */
98                         gd->vco_clk = gd->pci_clk * 16;
99                         break;
100                 }
101
102         /* hardcoded 81MHz for now */
103         gd->pev_clk = 81000000;
104
105         return (0);
106 }
107
108 int prt_mpc8220_clks (void)
109 {
110         DECLARE_GLOBAL_DATA_PTR;
111
112         printf ("       Bus %ld MHz, CPU %ld MHz, PCI %ld MHz, VCO %ld MHz\n",
113                 gd->bus_clk / 1000000, gd->cpu_clk / 1000000,
114                 gd->pci_clk / 1000000, gd->vco_clk / 1000000);
115
116         return (0);
117 }
118
119 /* ------------------------------------------------------------------------- */