qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Subject: [PULL 38/48] hw/misc/bcm2835_cprman: implement PLL channels behaviour
Date: Tue, 27 Oct 2020 11:44:28 +0000	[thread overview]
Message-ID: <20201027114438.17662-39-peter.maydell@linaro.org> (raw)
In-Reply-To: <20201027114438.17662-1-peter.maydell@linaro.org>

From: Luc Michel <luc@lmichel.fr>

A PLL channel is able to further divide the generated PLL frequency.
The divider is given in the CTRL_A2W register. Some channels have an
additional fixed divider which is always applied to the signal.

Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Luc Michel <luc@lmichel.fr>
Tested-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 hw/misc/bcm2835_cprman.c | 33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c
index 12fa78181b5..71c1d7b9e7b 100644
--- a/hw/misc/bcm2835_cprman.c
+++ b/hw/misc/bcm2835_cprman.c
@@ -134,9 +134,40 @@ static const TypeInfo cprman_pll_info = {
 
 /* PLL channel */
 
+static bool pll_channel_is_enabled(CprmanPllChannelState *channel)
+{
+    /*
+     * XXX I'm not sure of the purpose of the LOAD field. The Linux driver does
+     * not set it when enabling the channel, but does clear it when disabling
+     * it.
+     */
+    return !FIELD_EX32(*channel->reg_a2w_ctrl, A2W_PLLx_CHANNELy, DISABLE)
+        && !(*channel->reg_cm & channel->hold_mask);
+}
+
 static void pll_channel_update(CprmanPllChannelState *channel)
 {
-    clock_update(channel->out, 0);
+    uint64_t freq, div;
+
+    if (!pll_channel_is_enabled(channel)) {
+        clock_update(channel->out, 0);
+        return;
+    }
+
+    div = FIELD_EX32(*channel->reg_a2w_ctrl, A2W_PLLx_CHANNELy, DIV);
+
+    if (!div) {
+        /*
+         * It seems that when the divider value is 0, it is considered as
+         * being maximum by the hardware (see the Linux driver).
+         */
+        div = R_A2W_PLLx_CHANNELy_DIV_MASK;
+    }
+
+    /* Some channels have an additional fixed divider */
+    freq = clock_get_hz(channel->pll_in) / (div * channel->fixed_divider);
+
+    clock_update_hz(channel->out, freq);
 }
 
 /* Update a PLL and all its channels */
-- 
2.20.1



  parent reply	other threads:[~2020-10-27 13:12 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-27 11:43 [PULL 00/48] target-arm queue Peter Maydell
2020-10-27 11:43 ` [PULL 01/48] linux-user/aarch64: Reset btype for signals Peter Maydell
2020-10-27 11:43 ` [PULL 02/48] linux-user: Set PAGE_TARGET_1 for TARGET_PROT_BTI Peter Maydell
2020-10-27 11:43 ` [PULL 03/48] include/elf: Add defines related to GNU property notes for AArch64 Peter Maydell
2020-10-27 11:43 ` [PULL 04/48] linux-user/elfload: Avoid leaking interp_name using GLib memory API Peter Maydell
2020-10-27 11:43 ` [PULL 05/48] linux-user/elfload: Fix coding style in load_elf_image Peter Maydell
2020-10-27 11:43 ` [PULL 06/48] linux-user/elfload: Adjust iteration over phdr Peter Maydell
2020-10-27 11:43 ` [PULL 07/48] linux-user/elfload: Move PT_INTERP detection to first loop Peter Maydell
2020-10-27 11:43 ` [PULL 08/48] linux-user/elfload: Use Error for load_elf_image Peter Maydell
2020-10-27 11:43 ` [PULL 09/48] linux-user/elfload: Use Error for load_elf_interp Peter Maydell
2020-10-27 11:44 ` [PULL 10/48] linux-user/elfload: Parse NT_GNU_PROPERTY_TYPE_0 notes Peter Maydell
2020-10-27 11:44 ` [PULL 11/48] linux-user/elfload: Parse GNU_PROPERTY_AARCH64_FEATURE_1_AND Peter Maydell
2020-10-27 11:44 ` [PULL 12/48] tests/tcg/aarch64: Add bti smoke tests Peter Maydell
2020-10-27 11:44 ` [PULL 13/48] hw/arm/highbank: Silence warnings about missing fallthrough statements Peter Maydell
2020-10-27 11:44 ` [PULL 14/48] hw/arm: fix min_cpus for xlnx-versal-virt platform Peter Maydell
2020-10-27 11:44 ` [PULL 15/48] Move npcm7xx_timer_reached_zero call out of npcm7xx_timer_pause Peter Maydell
2020-10-27 11:44 ` [PULL 16/48] hw/timer: Adding watchdog for NPCM7XX Timer Peter Maydell
2020-10-27 11:44 ` [PULL 17/48] hw/misc: Add npcm7xx random number generator Peter Maydell
2020-10-27 11:44 ` [PULL 18/48] hw/arm/npcm7xx: Add EHCI and OHCI controllers Peter Maydell
2020-10-27 11:44 ` [PULL 19/48] hw/gpio: Add GPIO model for Nuvoton NPCM7xx Peter Maydell
2020-10-27 11:44 ` [PULL 20/48] hw/arm/smmuv3: Set the restoration priority of the vSMMUv3 explicitly Peter Maydell
2020-10-27 11:44 ` [PULL 21/48] hw/arm/bcm2836: Restrict BCM283XInfo declaration to C source Peter Maydell
2020-10-27 11:44 ` [PULL 22/48] hw/arm/bcm2836: QOM'ify more by adding class_init() to each SoC type Peter Maydell
2020-10-27 11:44 ` [PULL 23/48] hw/arm/bcm2836: Introduce BCM283XClass::core_count Peter Maydell
2020-10-27 11:44 ` [PULL 24/48] hw/arm/bcm2836: Only provide "enabled-cpus" property to multicore SoCs Peter Maydell
2020-10-27 11:44 ` [PULL 25/48] hw/arm/bcm2836: Split out common realize() code Peter Maydell
2020-10-27 11:44 ` [PULL 26/48] hw/arm/bcm2836: Introduce the BCM2835 SoC Peter Maydell
2020-10-27 11:44 ` [PULL 27/48] hw/arm/raspi: Add the Raspberry Pi A+ machine Peter Maydell
2020-10-27 11:44 ` [PULL 28/48] hw/arm/raspi: Add the Raspberry Pi Zero machine Peter Maydell
2020-10-27 11:44 ` [PULL 29/48] hw/arm/raspi: Add the Raspberry Pi 3 model A+ Peter Maydell
2020-10-27 11:44 ` [PULL 30/48] arm/trace: Fix hex printing Peter Maydell
2020-10-27 11:44 ` [PULL 31/48] hw/core/clock: provide the VMSTATE_ARRAY_CLOCK macro Peter Maydell
2020-10-27 11:44 ` [PULL 32/48] hw/core/clock: trace clock values in Hz instead of ns Peter Maydell
2020-10-27 11:44 ` [PULL 33/48] hw/arm/raspi: fix CPRMAN base address Peter Maydell
2020-10-27 11:44 ` [PULL 34/48] hw/arm/raspi: add a skeleton implementation of the CPRMAN Peter Maydell
2020-10-27 11:44 ` [PULL 35/48] hw/misc/bcm2835_cprman: add a PLL skeleton implementation Peter Maydell
2020-10-27 11:44 ` [PULL 36/48] hw/misc/bcm2835_cprman: implement PLLs behaviour Peter Maydell
2020-10-27 11:44 ` [PULL 37/48] hw/misc/bcm2835_cprman: add a PLL channel skeleton implementation Peter Maydell
2020-10-27 11:44 ` Peter Maydell [this message]
2020-10-27 11:44 ` [PULL 39/48] hw/misc/bcm2835_cprman: add a clock mux " Peter Maydell
2020-10-27 11:44 ` [PULL 40/48] hw/misc/bcm2835_cprman: implement clock mux behaviour Peter Maydell
2020-10-27 11:44 ` [PULL 41/48] hw/misc/bcm2835_cprman: add the DSI0HSCK multiplexer Peter Maydell
2020-10-27 11:44 ` [PULL 42/48] hw/misc/bcm2835_cprman: add sane reset values to the registers Peter Maydell
2020-10-27 11:44 ` [PULL 43/48] hw/char/pl011: add a clock input Peter Maydell
2020-10-27 11:44 ` [PULL 44/48] hw/arm/bcm2835_peripherals: connect the UART clock Peter Maydell
2020-10-27 11:44 ` [PULL 45/48] hw/watchdog: Implement SBSA watchdog device Peter Maydell
2020-10-27 11:44 ` [PULL 46/48] hw/arm/sbsa-ref: add " Peter Maydell
2020-10-27 11:44 ` [PULL 47/48] hw/core/ptimer: Support ptimer being disabled by timer callback Peter Maydell
2020-10-27 11:44 ` [PULL 48/48] hw/timer/armv7m_systick: Rewrite to use ptimers Peter Maydell
2020-11-04 10:03   ` Andrew Jones
2020-11-04 10:11     ` Philippe Mathieu-Daudé
2020-11-04 10:26       ` Andrew Jones
2020-10-27 13:22 ` [PULL 00/48] target-arm queue no-reply
2020-10-29 14:30 ` Peter Maydell

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=20201027114438.17662-39-peter.maydell@linaro.org \
    --to=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).