All of lore.kernel.org
 help / color / mirror / Atom feed
From: Scott Wood <scottwood@freescale.com>
To: galak@kernel.crashing.org
Cc: linuxppc-dev@ozlabs.org
Subject: [PATCH 07/28] bootwrapper: Add fsl_get_immr() and 8xx/pq2 clock functions.
Date: Mon, 17 Sep 2007 11:57:36 -0500	[thread overview]
Message-ID: <20070917165736.GG6563@loki.buserror.net> (raw)
In-Reply-To: <20070917165643.GA6545@loki.buserror.net>

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>
---
 arch/powerpc/boot/Makefile  |    2 +-
 arch/powerpc/boot/fsl-soc.c |   57 ++++++++++++++++++++++++
 arch/powerpc/boot/fsl-soc.h |    8 +++
 arch/powerpc/boot/mpc8xx.c  |   82 ++++++++++++++++++++++++++++++++++
 arch/powerpc/boot/mpc8xx.h  |   11 +++++
 arch/powerpc/boot/pq2.c     |  102 +++++++++++++++++++++++++++++++++++++++++++
 arch/powerpc/boot/pq2.h     |   11 +++++
 7 files changed, 272 insertions(+), 1 deletions(-)
 create mode 100644 arch/powerpc/boot/fsl-soc.c
 create mode 100644 arch/powerpc/boot/fsl-soc.h
 create mode 100644 arch/powerpc/boot/mpc8xx.c
 create mode 100644 arch/powerpc/boot/mpc8xx.h
 create mode 100644 arch/powerpc/boot/pq2.c
 create mode 100644 arch/powerpc/boot/pq2.h

diff --git a/arch/powerpc/boot/Makefile b/arch/powerpc/boot/Makefile
index 9ec785c..932492a 100644
--- a/arch/powerpc/boot/Makefile
+++ b/arch/powerpc/boot/Makefile
@@ -45,7 +45,7 @@ src-wlib := string.S crt0.S stdio.c main.c flatdevtree.c flatdevtree_misc.c \
 		ns16550.c serial.c simple_alloc.c div64.S util.S \
 		gunzip_util.c elf_util.c $(zlib) devtree.c oflib.c ofconsole.c \
 		4xx.c ebony.c mv64x60.c mpsc.c mv64x60_i2c.c cuboot.c bamboo.c \
-		cpm-serial.c stdlib.c planetcore.c
+		cpm-serial.c stdlib.c planetcore.c fsl-soc.c mpc8xx.c pq2.c
 src-plat := of.c cuboot-83xx.c cuboot-85xx.c holly.c \
 		cuboot-ebony.c treeboot-ebony.c prpmc2800.c \
 		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 0000000..b835ed6
--- /dev/null
+++ b/arch/powerpc/boot/fsl-soc.c
@@ -0,0 +1,57 @@
+/*
+ * Freescale SOC support functions
+ *
+ * Author: Scott Wood <scottwood@freescale.com>
+ *
+ * Copyright (c) 2007 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ */
+
+#include "ops.h"
+#include "types.h"
+#include "fsl-soc.h"
+#include "stdio.h"
+
+static u32 prop_buf[MAX_PROP_LEN / 4];
+
+u32 *fsl_get_immr(void)
+{
+	void *soc;
+	unsigned long ret = 0;
+
+	soc = find_node_by_devtype(NULL, "soc");
+	if (soc) {
+		int size;
+		u32 naddr;
+
+		size = getprop(soc, "#address-cells", prop_buf, MAX_PROP_LEN);
+		if (size == 4)
+			naddr = prop_buf[0];
+		else
+			naddr = 2;
+
+		if (naddr != 1 && naddr != 2)
+			goto err;
+
+		size = getprop(soc, "ranges", prop_buf, MAX_PROP_LEN);
+
+		if (size < 12)
+			goto err;
+		if (prop_buf[0] != 0)
+			goto err;
+		if (naddr == 2 && prop_buf[1] != 0)
+			goto err;
+
+		if (!dt_xlate_addr(soc, prop_buf + naddr, 8, &ret))
+			ret = 0;
+	}
+
+err:
+	if (!ret)
+		printf("fsl_get_immr: Failed to find immr base\r\n");
+
+	return (u32 *)ret;
+}
diff --git a/arch/powerpc/boot/fsl-soc.h b/arch/powerpc/boot/fsl-soc.h
new file mode 100644
index 0000000..5da26fc
--- /dev/null
+++ b/arch/powerpc/boot/fsl-soc.h
@@ -0,0 +1,8 @@
+#ifndef _PPC_BOOT_FSL_SOC_H_
+#define _PPC_BOOT_FSL_SOC_H_
+
+#include "types.h"
+
+u32 *fsl_get_immr(void);
+
+#endif
diff --git a/arch/powerpc/boot/mpc8xx.c b/arch/powerpc/boot/mpc8xx.c
new file mode 100644
index 0000000..add55a7
--- /dev/null
+++ b/arch/powerpc/boot/mpc8xx.c
@@ -0,0 +1,82 @@
+/*
+ * MPC8xx support functions
+ *
+ * Author: Scott Wood <scottwood@freescale.com>
+ *
+ * Copyright (c) 2007 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ */
+
+#include "ops.h"
+#include "types.h"
+#include "fsl-soc.h"
+#include "mpc8xx.h"
+#include "stdio.h"
+#include "io.h"
+
+#define MPC8XX_PLPRCR (0x284/4) /* PLL and Reset Control Register */
+
+/* Return system clock from crystal frequency */
+u32 mpc885_get_clock(u32 crystal)
+{
+	u32 *immr;
+	u32 plprcr;
+	int mfi, mfn, mfd, pdf, div;
+	u32 ret;
+
+	immr = fsl_get_immr();
+	if (!immr) {
+		printf("mpc885_get_clock: Couldn't get IMMR base.\r\n");
+		return 0;
+	}
+
+	plprcr = in_be32(&immr[MPC8XX_PLPRCR]);
+
+	mfi = (plprcr >> 16) & 15;
+	if (mfi < 5) {
+		printf("Warning: PLPRCR[MFI] value of %d out-of-bounds\r\n",
+		       mfi);
+		mfi = 5;
+	}
+
+	pdf = (plprcr >> 1) & 0xf;
+	div = (plprcr >> 20) & 3;
+	mfd = (plprcr >> 22) & 0x1f;
+	mfn = (plprcr >> 27) & 0x1f;
+
+	ret = crystal * mfi;
+
+	if (mfn != 0)
+		ret += crystal * mfn / (mfd + 1);
+
+	return ret / (pdf + 1);
+}
+
+/* Set common device tree fields based on the given clock frequencies. */
+void mpc8xx_set_clocks(u32 sysclk)
+{
+	void *node;
+
+	dt_fixup_cpu_clocks(sysclk, sysclk / 16, sysclk);
+
+	node = finddevice("/soc/cpm");
+	if (node)
+		setprop(node, "clock-frequency", &sysclk, 4);
+
+	node = finddevice("/soc/cpm/brg");
+	if (node)
+		setprop(node, "clock-frequency", &sysclk, 4);
+}
+
+int mpc885_fixup_clocks(u32 crystal)
+{
+	u32 sysclk = mpc885_get_clock(crystal);
+	if (!sysclk)
+		return 0;
+
+	mpc8xx_set_clocks(sysclk);
+	return 1;
+}
diff --git a/arch/powerpc/boot/mpc8xx.h b/arch/powerpc/boot/mpc8xx.h
new file mode 100644
index 0000000..3f59901
--- /dev/null
+++ b/arch/powerpc/boot/mpc8xx.h
@@ -0,0 +1,11 @@
+#ifndef _PPC_BOOT_MPC8xx_H_
+#define _PPC_BOOT_MPC8xx_H_
+
+#include "types.h"
+
+void mpc8xx_set_clocks(u32 sysclk);
+
+u32 mpc885_get_clock(u32 crystal);
+int mpc885_fixup_clocks(u32 crystal);
+
+#endif
diff --git a/arch/powerpc/boot/pq2.c b/arch/powerpc/boot/pq2.c
new file mode 100644
index 0000000..f6d1185
--- /dev/null
+++ b/arch/powerpc/boot/pq2.c
@@ -0,0 +1,102 @@
+/*
+ * PowerQUICC II support functions
+ *
+ * Author: Scott Wood <scottwood@freescale.com>
+ *
+ * Copyright (c) 2007 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ */
+
+#include "ops.h"
+#include "types.h"
+#include "fsl-soc.h"
+#include "pq2.h"
+#include "stdio.h"
+#include "io.h"
+
+#define PQ2_SCCR (0x10c80/4) /* System Clock Configuration Register */
+#define PQ2_SCMR (0x10c88/4) /* System Clock Mode Register */
+
+static int pq2_corecnf_map[] = {
+	3, 2, 2, 2, 4, 4, 5, 9, 6, 11, 8, 10, 3, 12, 7, -1,
+	6, 5, 13, 2, 14, 4, 15, 9, 0, 11, 8, 10, 16, 12, 7, -1
+};
+
+/* Get various clocks from crystal frequency.
+ * Returns zero on failure and non-zero on success.
+ */
+int pq2_get_clocks(u32 crystal, u32 *sysfreq, u32 *corefreq,
+                   u32 *timebase, u32 *brgfreq)
+{
+	u32 *immr;
+	u32 sccr, scmr, mainclk, busclk;
+	int corecnf, busdf, plldf, pllmf, dfbrg;
+
+	immr = fsl_get_immr();
+	if (!immr) {
+		printf("pq2_get_clocks: Couldn't get IMMR base.\r\n");
+		return 0;
+	}
+
+	sccr = in_be32(&immr[PQ2_SCCR]);
+	scmr = in_be32(&immr[PQ2_SCMR]);
+
+	dfbrg = sccr & 3;
+	corecnf = (scmr >> 24) & 0x1f;
+	busdf = (scmr >> 20) & 0xf;
+	plldf = (scmr >> 12) & 1;
+	pllmf = scmr & 0xfff;
+
+	mainclk = crystal * (pllmf + 1) / (plldf + 1);
+	busclk = mainclk / (busdf + 1);
+
+	if (sysfreq)
+		*sysfreq = mainclk / 2;
+	if (timebase)
+		*timebase = busclk / 4;
+	if (brgfreq)
+		*brgfreq = mainclk / (1 << ((dfbrg + 1) * 2));
+
+	if (corefreq) {
+		int coremult = pq2_corecnf_map[corecnf];
+
+		if (coremult < 0)
+			*corefreq = mainclk / 2;
+		else if (coremult == 0)
+			return 0;
+		else
+			*corefreq = busclk * coremult / 2;
+	}
+
+	return 1;
+}
+
+/* Set common device tree fields based on the given clock frequencies. */
+void pq2_set_clocks(u32 sysfreq, u32 corefreq, u32 timebase, u32 brgfreq)
+{
+	void *node;
+
+	dt_fixup_cpu_clocks(corefreq, timebase, sysfreq);
+
+	node = finddevice("/soc/cpm");
+	if (node)
+		setprop(node, "clock-frequency", &sysfreq, 4);
+
+	node = finddevice("/soc/cpm/brg");
+	if (node)
+		setprop(node, "clock-frequency", &brgfreq, 4);
+}
+
+int pq2_fixup_clocks(u32 crystal)
+{
+	u32 sysfreq, corefreq, timebase, brgfreq;
+
+	if (!pq2_get_clocks(crystal, &sysfreq, &corefreq, &timebase, &brgfreq))
+		return 0;
+
+	pq2_set_clocks(sysfreq, corefreq, timebase, brgfreq);
+	return 1;
+}
diff --git a/arch/powerpc/boot/pq2.h b/arch/powerpc/boot/pq2.h
new file mode 100644
index 0000000..481698c
--- /dev/null
+++ b/arch/powerpc/boot/pq2.h
@@ -0,0 +1,11 @@
+#ifndef _PPC_BOOT_PQ2_H_
+#define _PPC_BOOT_PQ2_H_
+
+#include "types.h"
+
+int pq2_get_clocks(u32 crystal, u32 *sysfreq, u32 *corefreq,
+                   u32 *timebase, u32 *brgfreq);
+void pq2_set_clocks(u32 sysfreq, u32 corefreq, u32 timebase, u32 brgfreq);
+int pq2_fixup_clocks(u32 crystal);
+
+#endif
-- 
1.5.3.1

  parent reply	other threads:[~2007-09-17 16:58 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-17 16:56 [PATCH 00/28] 8xx/82xx patches Scott Wood
2007-09-17 16:57 ` [PATCH 01/28] CPM: Change from fsl,brg-frequency to brg/clock-frequency Scott Wood
2007-09-18  6:11   ` [PATCH 01/28] CPM: Change from fsl, brg-frequency " David Gibson
2007-09-18 14:21     ` Scott Wood
2007-09-18 23:48       ` David Gibson
2007-09-17 16:57 ` [PATCH 02/28] Introduce new CPM device bindings Scott Wood
2007-09-18  6:13   ` David Gibson
2007-09-17 16:57 ` [PATCH 03/28] Document local bus nodes in the device tree Scott Wood
2007-09-18 15:03   ` Kumar Gala
2007-09-17 16:57 ` [PATCH 04/28] Add early debug console for CPM serial ports Scott Wood
2007-09-19  3:10   ` David Gibson
2007-09-17 16:57 ` [PATCH 05/28] bootwrapper: Support all-in-one PCI nodes in cuboot-pq2 Scott Wood
2007-09-19  3:11   ` David Gibson
2007-09-17 16:57 ` [PATCH 06/28] bootwrapper: Add PlanetCore firmware support Scott Wood
2007-09-19  3:15   ` David Gibson
2007-09-17 16:57 ` Scott Wood [this message]
2007-09-19  3:16   ` [PATCH 07/28] bootwrapper: Add fsl_get_immr() and 8xx/pq2 clock functions David Gibson
2007-09-17 16:57 ` [PATCH 08/28] bootwrapper: Use fsl_get_immr() in cuboot-pq2.c Scott Wood
2007-09-19  3:16   ` David Gibson
2007-09-17 16:57 ` [PATCH 09/28] cpm_uart: Be an of_platform device when CONFIG_PPC_CPM_NEW_BINDING is set Scott Wood
2007-09-18  4:19   ` Stephen Rothwell
2007-09-17 16:57 ` [PATCH 10/28] cpm_uart: sparse fixes Scott Wood
2007-09-17 16:57 ` [PATCH 11/28] cpm_uart: Issue STOP_TX command before initializing console Scott Wood
2007-09-17 16:57 ` [PATCH 12/28] 8xx: Fix CONFIG_PIN_TLB Scott Wood
2007-09-17 16:57 ` [PATCH 13/28] 8xx: Infrastructure code cleanup Scott Wood
2007-09-19  4:25   ` David Gibson
2007-09-19  5:28     ` Scott Wood
2007-09-17 16:57 ` [PATCH 14/28] 8xx: Add pin and clock setting functions Scott Wood
2007-09-17 16:57 ` [PATCH 15/28] 8xx: Work around CPU15 erratum Scott Wood
2007-09-17 16:57 ` [PATCH 16/28] 8xx: Don't call non-existent Soft_emulate_8xx from SoftwareEmulation Scott Wood
2007-09-18 15:08   ` Kumar Gala
2007-09-18 15:11     ` Scott Wood
2007-09-18 15:19       ` Kumar Gala
2007-09-18 15:23         ` Scott Wood
2007-09-18 16:21           ` Kumar Gala
2007-09-17 16:58 ` [PATCH 17/28] 8xx: Set initial memory limit Scott Wood
2007-09-17 16:58 ` [PATCH 18/28] 8xx: mpc885ads cleanup Scott Wood
2007-09-18 13:21   ` Stephen Rothwell
2007-09-17 16:58 ` [PATCH 19/28] 8xx: Embedded Planet EP88xC support Scott Wood
2007-09-17 16:58 ` [PATCH 20/28] cpm2: Infrastructure code cleanup Scott Wood
2007-09-17 16:58 ` [PATCH 21/28] cpm2: Add SCCs to cpm2_clk_setup(), and cpm2_smc_clk_setup() Scott Wood
2007-09-17 16:58 ` [PATCH 22/28] cpm2: Add cpm2_set_pin() Scott Wood
2007-09-17 16:58 ` [PATCH 23/28] mpc82xx: Define CPU_FTR_NEED_COHERENT Scott Wood
2007-09-18 14:34   ` Rune Torgersen
2007-09-18 14:55     ` Scott Wood
2007-09-17 16:58 ` [PATCH 24/28] mpc82xx: Remove a bunch of cruft that duplicates generic functionality Scott Wood
2007-09-18  6:48   ` David Gibson
2007-09-17 16:58 ` [PATCH 25/28] mpc82xx: Rename mpc82xx_ads to mpc8272_ads Scott Wood
2007-09-17 16:58 ` [PATCH 26/28] mpc8272ads: Change references from 82xx_ADS to 8272_ADS Scott Wood
2007-09-17 16:58 ` [PATCH 27/28] mpc82xx: Update mpc8272ads, and factor out PCI and reset Scott Wood
2007-09-17 16:58 ` [PATCH 28/28] mpc82xx: Add pq2fads board support Scott Wood

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070917165736.GG6563@loki.buserror.net \
    --to=scottwood@freescale.com \
    --cc=galak@kernel.crashing.org \
    --cc=linuxppc-dev@ozlabs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.