1 /*
2 * arch/ppc/syslib/ibm440gp_common.c
3 *
4 * PPC440GP system library
5 *
6 * Matt Porter <mporter@mvista.com>
7 * Copyright 2002-2003 MontaVista Software Inc.
8 *
9 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
10 * Copyright (c) 2003 Zultys Technologies
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
16 *
17 */
18 #include <linux/config.h>
19 #include <linux/types.h>
20 #include <asm/ibm44x.h>
21 #include <asm/mmu.h>
22 #include <asm/processor.h>
23 #include <kernel/ibm440gp_common.h>
24
25 /*
26 * Calculate 440GP clocks
27 */
ibm440gp_get_clocks(struct ibm44x_clocks * p,unsigned int sys_clk,unsigned int ser_clk)28 void __init ibm440gp_get_clocks(struct ibm44x_clocks* p, unsigned int sys_clk,
29 unsigned int ser_clk)
30 {
31 u32 cpc0_sys0 = mfdcr(DCRN_CPC0_SYS0);
32 u32 cpc0_cr0 = mfdcr(DCRN_CPC0_CR0);
33 u32 opdv, epdv;
34
35 if (cpc0_sys0 & 0x2){
36 /* Bypass system PLL */
37 p->cpu = p->plb = sys_clk;
38 }
39 else {
40 u32 fbdv, fwdva, fwdvb, m, vco;
41
42 fbdv = (cpc0_sys0 >> 18) & 0x0f;
43 if (!fbdv)
44 fbdv = 16;
45
46 fwdva = 8 - ((cpc0_sys0 >> 15) & 0x7);
47 fwdvb = 8 - ((cpc0_sys0 >> 12) & 0x7);
48
49 /* Feedback path */
50 if (cpc0_sys0 & 0x00000080){
51 /* PerClk */
52 m = fwdvb * opdv * epdv;
53 }
54 else {
55 /* CPU clock */
56 m = fbdv * fwdva;
57 }
58 vco = sys_clk * m;
59 p->cpu = vco / fwdva;
60 p->plb = vco / fwdvb;
61 }
62
63 opdv = ((cpc0_sys0 >> 10) & 0x3) + 1;
64 epdv = ((cpc0_sys0 >> 8) & 0x3) + 1;
65
66 p->opb = p->plb / opdv;
67 p->ebc = p->opb / epdv;
68
69 if (cpc0_cr0 & 0x00400000){
70 /* External UART clock */
71 p->uart0 = p->uart1 = ser_clk;
72 }
73 else {
74 /* Internal UART clock */
75 u32 uart_div = ((cpc0_cr0 >> 16) & 0x1f) + 1;
76 p->uart0 = p->uart1 = p->plb / uart_div;
77 }
78 }
79