From: Paul Cercueil <paul@crapouillou.net>
To: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: Paul Burton <paulburton@kernel.org>,
Siarhei Volkau <lis8215@gmail.com>,
linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org,
list@opendingux.net, Paul Cercueil <paul@crapouillou.net>
Subject: [PATCH 3/4] mips: ingenic: Enable EXT/2 divider on JZ4750/55/60 if EXT is 24 MHz
Date: Sun, 4 Jun 2023 14:26:54 +0200 [thread overview]
Message-ID: <20230604122655.69698-3-paul@crapouillou.net> (raw)
In-Reply-To: <20230604122655.69698-1-paul@crapouillou.net>
The JZ4750, JZ4755 and JZ4760 (non-B version) support using a 24 MHz
external crystal oscillator instead of the typical 12 MHz one.
However, most of the SoC's IP blocks only work with a 12 MHz clock.
Thanksfully, there is a /2 divider we can enable when a 24 MHz external
crystal is present.
Force-enable this /2 divider when the oscillator is 24 MHz, so that the
SoC always uses a 12 MHz clock internally.
It is done here, and not in the clocks driver, because we need the EXT
clock to be 12 MHz for the early console to work, and the clocks driver
probes way too late.
Signed-off-by: Paul Cercueil <paul@crapouillou.net>
---
arch/mips/generic/board-ingenic.c | 57 +++++++++++++++++++++++++++++++
1 file changed, 57 insertions(+)
diff --git a/arch/mips/generic/board-ingenic.c b/arch/mips/generic/board-ingenic.c
index 7a4fce06875d..1f4906875e7b 100644
--- a/arch/mips/generic/board-ingenic.c
+++ b/arch/mips/generic/board-ingenic.c
@@ -17,6 +17,7 @@
#include <linux/types.h>
#include <asm/bootinfo.h>
+#include <asm/io.h>
#include <asm/machine.h>
#include <asm/reboot.h>
@@ -60,6 +61,50 @@ static __init char *ingenic_get_system_type(unsigned long machtype)
}
}
+#define INGENIC_CGU_BASE 0x10000000
+#define JZ4750_CGU_CPCCR_ECS BIT(30)
+#define JZ4760_CGU_CPCCR_ECS BIT(31)
+
+static __init void ingenic_force_12M_ext(const void *fdt, unsigned int mask)
+{
+ const __be32 *prop;
+ unsigned int cpccr;
+ void __iomem *cgu;
+ bool use_div;
+ int offset;
+
+ offset = fdt_path_offset(fdt, "/ext");
+ if (offset < 0)
+ return;
+
+ prop = fdt_getprop(fdt, offset, "clock-frequency", NULL);
+ if (!prop)
+ return;
+
+ /*
+ * If the external oscillator is 24 MHz, enable the /2 divider to
+ * drive it down to 12 MHz, since this is what the hardware can work
+ * with.
+ * The 16 MHz cutoff value is arbitrary; setting it to 12 MHz would not
+ * work as the crystal frequency (as reported in the Device Tree) might
+ * be slightly above this value.
+ */
+ use_div = be32_to_cpup(prop) >= 16000000;
+
+ cgu = ioremap(INGENIC_CGU_BASE, 0x4);
+ if (!cgu)
+ return;
+
+ cpccr = ioread32(cgu);
+ if (use_div)
+ cpccr |= mask;
+ else
+ cpccr &= ~mask;
+ iowrite32(cpccr, cgu);
+
+ iounmap(cgu);
+}
+
static __init const void *ingenic_fixup_fdt(const void *fdt, const void *match_data)
{
/*
@@ -73,6 +118,18 @@ static __init const void *ingenic_fixup_fdt(const void *fdt, const void *match_d
mips_machtype = (unsigned long)match_data;
system_type = ingenic_get_system_type(mips_machtype);
+ switch (mips_machtype) {
+ case MACH_INGENIC_JZ4750:
+ case MACH_INGENIC_JZ4755:
+ ingenic_force_12M_ext(fdt, JZ4750_CGU_CPCCR_ECS);
+ break;
+ case MACH_INGENIC_JZ4760:
+ ingenic_force_12M_ext(fdt, JZ4760_CGU_CPCCR_ECS);
+ break;
+ default:
+ break;
+ }
+
return fdt;
}
--
2.39.2
next prev parent reply other threads:[~2023-06-04 12:27 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-04 12:26 [PATCH 1/4] MIPS: uaccess: emulate Ingenic LXW/LXH/LXHU uaccess Paul Cercueil
2023-06-04 12:26 ` [PATCH 2/4] mips: ingenic: Remove useless __maybe_unused Paul Cercueil
2023-06-09 8:22 ` Thomas Bogendoerfer
2023-06-04 12:26 ` Paul Cercueil [this message]
2023-06-09 8:23 ` [PATCH 3/4] mips: ingenic: Enable EXT/2 divider on JZ4750/55/60 if EXT is 24 MHz Thomas Bogendoerfer
2023-06-04 12:26 ` [PATCH 4/4] MIPS: DTS: qi_lb60: Don't use unit address for regulators Paul Cercueil
2023-06-09 8:23 ` Thomas Bogendoerfer
2023-06-09 8:22 ` [PATCH 1/4] MIPS: uaccess: emulate Ingenic LXW/LXH/LXHU uaccess Thomas Bogendoerfer
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=20230604122655.69698-3-paul@crapouillou.net \
--to=paul@crapouillou.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@vger.kernel.org \
--cc=lis8215@gmail.com \
--cc=list@opendingux.net \
--cc=paulburton@kernel.org \
--cc=tsbogend@alpha.franken.de \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®