aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorScott Wood <scottwood@freescale.com>2007-08-27 14:46:38 -0400
committerKumar Gala <galak@kernel.crashing.org>2007-10-03 21:36:35 -0400
commitbbc6fac387f09e46a372e4aadbc935cba5a6b463 (patch)
tree930a30665c87ad0bd3c845ba892817f4a7b0ba19
parent568091512d464b06f17b88bfd2bdc1ec98a697bd (diff)
[POWERPC] bootwrapper: Add fsl_get_immr() and 8xx/pq2 clock functions.
fsl_get_immr() uses /soc/ranges to determine the immr. mpc885_get_clock() transforms a crystal frequency into a system frequency according to the PLL register settings. pq2_get_clocks() does the same as the above for the PowerQUICC II, except that it produces several different clocks. The mpc8xx/pq2 set_clocks() functions modify common properties in the device tree based on the given clock data. The mpc885/pq2 fixup_clocks() functions call get_clocks(), and pass the results to set_clocks(). Signed-off-by: Scott Wood <scottwood@freescale.com> Acked-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
-rw-r--r--arch/powerpc/boot/Makefile3
-rw-r--r--arch/powerpc/boot/fsl-soc.c57
-rw-r--r--arch/powerpc/boot/fsl-soc.h8
-rw-r--r--arch/powerpc/boot/mpc8xx.c82
-rw-r--r--arch/powerpc/boot/mpc8xx.h11
-rw-r--r--arch/powerpc/boot/pq2.c102
-rw-r--r--arch/powerpc/boot/pq2.h11
7 files changed, 273 insertions, 1 deletions
diff --git a/arch/powerpc/boot/Makefile b/arch/powerpc/boot/Makefile
index cf80db3ef78c..6d1935a06ee1 100644
--- a/arch/powerpc/boot/Makefile
+++ b/arch/powerpc/boot/Makefile
@@ -46,7 +46,8 @@ src-wlib := string.S crt0.S stdio.c main.c flatdevtree.c flatdevtree_misc.c \
46 ns16550.c serial.c simple_alloc.c div64.S util.S \ 46 ns16550.c serial.c simple_alloc.c div64.S util.S \
47 gunzip_util.c elf_util.c $(zlib) devtree.c oflib.c ofconsole.c \ 47 gunzip_util.c elf_util.c $(zlib) devtree.c oflib.c ofconsole.c \
48 4xx.c ebony.c mv64x60.c mpsc.c mv64x60_i2c.c cuboot.c bamboo.c \ 48 4xx.c ebony.c mv64x60.c mpsc.c mv64x60_i2c.c cuboot.c bamboo.c \
49 cpm-serial.c stdlib.c mpc52xx-psc.c planetcore.c uartlite.c 49 cpm-serial.c stdlib.c mpc52xx-psc.c planetcore.c uartlite.c \
50 fsl-soc.c mpc8xx.c pq2.c
50src-plat := of.c cuboot-52xx.c cuboot-83xx.c cuboot-85xx.c holly.c \ 51src-plat := of.c cuboot-52xx.c cuboot-83xx.c cuboot-85xx.c holly.c \
51 cuboot-ebony.c treeboot-ebony.c prpmc2800.c \ 52 cuboot-ebony.c treeboot-ebony.c prpmc2800.c \
52 ps3-head.S ps3-hvcall.S ps3.c treeboot-bamboo.c cuboot-8xx.c \ 53 ps3-head.S ps3-hvcall.S ps3.c treeboot-bamboo.c cuboot-8xx.c \
diff --git a/arch/powerpc/boot/fsl-soc.c b/arch/powerpc/boot/fsl-soc.c
new file mode 100644
index 000000000000..b835ed69e1a1
--- /dev/null
+++ b/arch/powerpc/boot/fsl-soc.c
@@ -0,0 +1,57 @@
1/*
2 * Freescale SOC support functions
3 *
4 * Author: Scott Wood <scottwood@freescale.com>
5 *
6 * Copyright (c) 2007 Freescale Semiconductor, Inc.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 as published
10 * by the Free Software Foundation.
11 */
12
13#include "ops.h"
14#include "types.h"
15#include "fsl-soc.h"
16#include "stdio.h"
17
18static u32 prop_buf[MAX_PROP_LEN / 4];
19
20u32 *fsl_get_immr(void)
21{
22 void *soc;
23 unsigned long ret = 0;
24
25 soc = find_node_by_devtype(NULL, "soc");
26 if (soc) {
27 int size;
28 u32 naddr;
29
30 size = getprop(soc, "#address-cells", prop_buf, MAX_PROP_LEN);
31 if (size == 4)
32 naddr = prop_buf[0];
33 else
34 naddr = 2;
35
36 if (naddr != 1 && naddr != 2)
37 goto err;
38
39 size = getprop(soc, "ranges", prop_buf, MAX_PROP_LEN);
40
41 if (size < 12)
42 goto err;
43 if (prop_buf[0] != 0)
44 goto err;
45 if (naddr == 2 && prop_buf[1] != 0)
46 goto err;
47
48 if (!dt_xlate_addr(soc, prop_buf + naddr, 8, &ret))
49 ret = 0;
50 }
51
52err:
53 if (!ret)
54 printf("fsl_get_immr: Failed to find immr base\r\n");
55
56 return (u32 *)ret;
57}
diff --git a/arch/powerpc/boot/fsl-soc.h b/arch/powerpc/boot/fsl-soc.h
new file mode 100644
index 000000000000..5da26fc6e3cf
--- /dev/null
+++ b/arch/powerpc/boot/fsl-soc.h
@@ -0,0 +1,8 @@
1#ifndef _PPC_BOOT_FSL_SOC_H_
2#define _PPC_BOOT_FSL_SOC_H_
3
4#include "types.h"
5
6u32 *fsl_get_immr(void);
7
8#endif
diff --git a/arch/powerpc/boot/mpc8xx.c b/arch/powerpc/boot/mpc8xx.c
new file mode 100644
index 000000000000..add55a7f184f
--- /dev/null
+++ b/arch/powerpc/boot/mpc8xx.c
@@ -0,0 +1,82 @@
1/*
2 * MPC8xx support functions
3 *
4 * Author: Scott Wood <scottwood@freescale.com>
5 *
6 * Copyright (c) 2007 Freescale Semiconductor, Inc.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 as published
10 * by the Free Software Foundation.
11 */
12
13#include "ops.h"
14#include "types.h"
15#include "fsl-soc.h"
16#include "mpc8xx.h"
17#include "stdio.h"
18#include "io.h"
19
20#define MPC8XX_PLPRCR (0x284/4) /* PLL and Reset Control Register */
21
22/* Return system clock from crystal frequency */
23u32 mpc885_get_clock(u32 crystal)
24{
25 u32 *immr;
26 u32 plprcr;
27 int mfi, mfn, mfd, pdf, div;
28 u32 ret;
29
30 immr = fsl_get_immr();
31 if (!immr) {
32 printf("mpc885_get_clock: Couldn't get IMMR base.\r\n");
33 return 0;
34 }
35
36 plprcr = in_be32(&immr[MPC8XX_PLPRCR]);
37
38 mfi = (plprcr >> 16) & 15;
39 if (mfi < 5) {
40 printf("Warning: PLPRCR[MFI] value of %d out-of-bounds\r\n",
41 mfi);
42 mfi = 5;
43 }
44
45 pdf = (plprcr >> 1) & 0xf;
46 div = (plprcr >> 20) & 3;
47 mfd = (plprcr >> 22) & 0x1f;
48 mfn = (plprcr >> 27) & 0x1f;
49
50 ret = crystal * mfi;
51
52 if (mfn != 0)
53 ret += crystal * mfn / (mfd + 1);
54
55 return ret / (pdf + 1);
56}
57
58/* Set common device tree fields based on the given clock frequencies. */
59void mpc8xx_set_clocks(u32 sysclk)
60{
61 void *node;
62
63 dt_fixup_cpu_clocks(sysclk, sysclk / 16, sysclk);
64
65 node = finddevice("/soc/cpm");
66 if (node)
67 setprop(node, "clock-frequency", &sysclk, 4);
68
69 node = finddevice("/soc/cpm/brg");
70 if (node)
71 setprop(node, "clock-frequency", &sysclk, 4);
72}
73
74int mpc885_fixup_clocks(u32 crystal)
75{
76 u32 sysclk = mpc885_get_clock(crystal);
77 if (!sysclk)
78 return 0;
79
80 mpc8xx_set_clocks(sysclk);
81 return 1;
82}
diff --git a/arch/powerpc/boot/mpc8xx.h b/arch/powerpc/boot/mpc8xx.h
new file mode 100644
index 000000000000..3f59901ab1c0
--- /dev/null
+++ b/arch/powerpc/boot/mpc8xx.h
@@ -0,0 +1,11 @@
1#ifndef _PPC_BOOT_MPC8xx_H_
2#define _PPC_BOOT_MPC8xx_H_
3
4#include "types.h"
5
6void mpc8xx_set_clocks(u32 sysclk);
7
8u32 mpc885_get_clock(u32 crystal);
9int mpc885_fixup_clocks(u32 crystal);
10
11#endif
diff --git a/arch/powerpc/boot/pq2.c b/arch/powerpc/boot/pq2.c
new file mode 100644
index 000000000000..f6d118558f1d
--- /dev/null
+++ b/arch/powerpc/boot/pq2.c
@@ -0,0 +1,102 @@
1/*
2 * PowerQUICC II support functions
3 *
4 * Author: Scott Wood <scottwood@freescale.com>
5 *
6 * Copyright (c) 2007 Freescale Semiconductor, Inc.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 as published
10 * by the Free Software Foundation.
11 */
12
13#include "ops.h"
14#include "types.h"
15#include "fsl-soc.h"
16#include "pq2.h"
17#include "stdio.h"
18#include "io.h"
19
20#define PQ2_SCCR (0x10c80/4) /* System Clock Configuration Register */
21#define PQ2_SCMR (0x10c88/4) /* System Clock Mode Register */
22
23static int pq2_corecnf_map[] = {
24 3, 2, 2, 2, 4, 4, 5, 9, 6, 11, 8, 10, 3, 12, 7, -1,
25 6, 5, 13, 2, 14, 4, 15, 9, 0, 11, 8, 10, 16, 12, 7, -1
26};
27
28/* Get various clocks from crystal frequency.
29 * Returns zero on failure and non-zero on success.
30 */
31int pq2_get_clocks(u32 crystal, u32 *sysfreq, u32 *corefreq,
32 u32 *timebase, u32 *brgfreq)
33{
34 u32 *immr;
35 u32 sccr, scmr, mainclk, busclk;
36 int corecnf, busdf, plldf, pllmf, dfbrg;
37
38 immr = fsl_get_immr();
39 if (!immr) {
40 printf("pq2_get_clocks: Couldn't get IMMR base.\r\n");
41 return 0;
42 }
43
44 sccr = in_be32(&immr[PQ2_SCCR]);
45 scmr = in_be32(&immr[PQ2_SCMR]);
46
47 dfbrg = sccr & 3;
48 corecnf = (scmr >> 24) & 0x1f;
49 busdf = (scmr >> 20) & 0xf;
50 plldf = (scmr >> 12) & 1;
51 pllmf = scmr & 0xfff;
52
53 mainclk = crystal * (pllmf + 1) / (plldf + 1);
54 busclk = mainclk / (busdf + 1);
55
56 if (sysfreq)
57 *sysfreq = mainclk / 2;
58 if (timebase)
59 *timebase = busclk / 4;
60 if (brgfreq)
61 *brgfreq = mainclk / (1 << ((dfbrg + 1) * 2));
62
63 if (corefreq) {
64 int coremult = pq2_corecnf_map[corecnf];
65
66 if (coremult < 0)
67 *corefreq = mainclk / 2;
68 else if (coremult == 0)
69 return 0;
70 else
71 *corefreq = busclk * coremult / 2;
72 }
73
74 return 1;
75}
76
77/* Set common device tree fields based on the given clock frequencies. */
78void pq2_set_clocks(u32 sysfreq, u32 corefreq, u32 timebase, u32 brgfreq)
79{
80 void *node;
81
82 dt_fixup_cpu_clocks(corefreq, timebase, sysfreq);
83
84 node = finddevice("/soc/cpm");
85 if (node)
86 setprop(node, "clock-frequency", &sysfreq, 4);
87
88 node = finddevice("/soc/cpm/brg");
89 if (node)
90 setprop(node, "clock-frequency", &brgfreq, 4);
91}
92
93int pq2_fixup_clocks(u32 crystal)
94{
95 u32 sysfreq, corefreq, timebase, brgfreq;
96
97 if (!pq2_get_clocks(crystal, &sysfreq, &corefreq, &timebase, &brgfreq))
98 return 0;
99
100 pq2_set_clocks(sysfreq, corefreq, timebase, brgfreq);
101 return 1;
102}
diff --git a/arch/powerpc/boot/pq2.h b/arch/powerpc/boot/pq2.h
new file mode 100644
index 000000000000..481698c7a51a
--- /dev/null
+++ b/arch/powerpc/boot/pq2.h
@@ -0,0 +1,11 @@
1#ifndef _PPC_BOOT_PQ2_H_
2#define _PPC_BOOT_PQ2_H_
3
4#include "types.h"
5
6int pq2_get_clocks(u32 crystal, u32 *sysfreq, u32 *corefreq,
7 u32 *timebase, u32 *brgfreq);
8void pq2_set_clocks(u32 sysfreq, u32 corefreq, u32 timebase, u32 brgfreq);
9int pq2_fixup_clocks(u32 crystal);
10
11#endif