2 * MPC8xx support functions
4 * Author: Scott Wood <scottwood@freescale.com>
6 * Copyright (c) 2007 Freescale Semiconductor, Inc.
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.
20 #define MPC8XX_PLPRCR (0x284/4) /* PLL and Reset Control Register */
22 /* Return system clock from crystal frequency */
23 u32 mpc885_get_clock(u32 crystal)
27 int mfi, mfn, mfd, pdf, div;
30 immr = fsl_get_immr();
32 printf("mpc885_get_clock: Couldn't get IMMR base.\r\n");
36 plprcr = in_be32(&immr[MPC8XX_PLPRCR]);
38 mfi = (plprcr >> 16) & 15;
40 printf("Warning: PLPRCR[MFI] value of %d out-of-bounds\r\n",
45 pdf = (plprcr >> 1) & 0xf;
46 div = (plprcr >> 20) & 3;
47 mfd = (plprcr >> 22) & 0x1f;
48 mfn = (plprcr >> 27) & 0x1f;
53 ret += crystal * mfn / (mfd + 1);
55 return ret / (pdf + 1);
58 /* Set common device tree fields based on the given clock frequencies. */
59 void mpc8xx_set_clocks(u32 sysclk)
63 dt_fixup_cpu_clocks(sysclk, sysclk / 16, sysclk);
65 node = finddevice("/soc/cpm");
67 setprop(node, "clock-frequency", &sysclk, 4);
69 node = finddevice("/soc/cpm/brg");
71 setprop(node, "clock-frequency", &sysclk, 4);
74 int mpc885_fixup_clocks(u32 crystal)
76 u32 sysclk = mpc885_get_clock(crystal);
80 mpc8xx_set_clocks(sysclk);