raspi: add the bcm2835 cprman clock manager
Subsystems (3)
v3 cover raspi: add the bcm2835 cprman clock manager
v2 -> v3:
- patch 03: moved clock_new definition to hw/core/clock.c [Phil]
- patch 03: commit message typo [Clement]
- patch 10: clarifications around the CM_CTL/CM_DIBV mux registers. reg_cm replaced with reg_ctl and reg_div. Add some comments for clarity. [Phil]
- patch 10: fixed update_mux_from_cm not matching the CM_DIV offset correctly. [Phil]
- patch 11: replaced manual bitfield extraction with extract32 [Phil]
- patch 11: added a visual representation of CM_DIV for clarity [Phil]
- patch 11: added a missing return in clock_mux_update.
v1 -> v2:
- patch 05: Added a comment about MMIO .valid constraints [Phil]
- patch 05: Added MMIO .impl [Phil]
- patch 05: Moved init_internal_clock to the public clock API, renamed clock_new (new patch 03) [Phil]
- patch 11: use muldiv64 for clock mux frequency output computation [Phil]
- patch 11: add a check for null divisor (Phil: I dropped your r-b)
- Typos, formatting, naming, style [Phil]
Patches without review: 03, 11, 13
Hi,
This series add the BCM2835 CPRMAN clock manager peripheral to the Raspberry Pi machine.
Patches 1-4 are preliminary changes, patches 5-13 are the actual implementation.
The two last patches add a clock input to the PL011 and connect it to the CPRMAN.
This series has been tested with Linux 5.4.61 (the current raspios version). It fixes the kernel Oops at boot time due to invalid UART clock value, and other warnings/errors here and there because of bad clocks or lack of CPRMAN.
Here is the clock tree as seen by Linux when booted in QEMU:
(/sys/kernel/debug/clk/clk_summary with some columns removed)
enable prepare
clock count count rate
-----------------------------------------------------
otg 0 0 480000000
osc 5 5 19200000
gp2 1 1 32768
tsens 0 0 1920000
otp 0 0 4800000
timer 0 0 1000002
pllh 4 4 864000000
pllh_pix_prediv 1 1 3375000
pllh_pix 0 0 337500
pllh_aux 1 1 216000000
vec 0 0 108000000
pllh_rcal_prediv 1 1 3375000
pllh_rcal 0 0 337500
plld 3 3 2000000024
plld_dsi1 0 0 7812501
plld_dsi0 0 0 7812501
plld_per 3 3 500000006
gp1 1 1 25000000
uart 1 2 47999625
plld_core 2 2 500000006
sdram 0 0 166666668
pllc 3 3 2400000000
pllc_per 1 1 1200000000
emmc 0 0 200000000
pllc_core2 0 0 9375000
pllc_core1 0 0 9375000
pllc_core0 2 2 1200000000
vpu 1 1 700000000
aux_spi2 0 0 700000000
aux_spi1 0 0 700000000
aux_uart 0 0 700000000
peri_image 0 0 700000000
plla 2 2 2250000000
plla_ccp2 0 0 8789063
plla_dsi0 0 0 8789063
plla_core 1 1 750000000
h264 0 0 250000000
isp 0 0 250000000
dsi1p 0 0 0
dsi0p 0 0 0
dsi1e 0 0 0
dsi0e 0 0 0
cam1 0 0 0
cam0 0 0 0
dpi 0 0 0
tec 0 0 0
smi 0 0 0
slim 0 0 0
gp0 0 0 0
dft 0 0 0
aveo 0 0 0
pcm 0 0 0
pwm 0 0 0
hsm 0 0 0It shows small differences with real hardware due other missing peripherals for which the driver turn the clock off (like tsens).
Luc Michel (15):
hw/core/clock: provide the VMSTATE_ARRAY_CLOCK macro hw/core/clock: trace clock values in Hz instead of ns hw/core/clock: add the clock_new helper function hw/arm/raspi: fix CPRMAN base address
hw/arm/raspi: add a skeleton implementation of the CPRMAN hw/misc/bcm2835_cprman: add a PLL skeleton implementation hw/misc/bcm2835_cprman: implement PLLs behaviour hw/misc/bcm2835_cprman: add a PLL channel skeleton implementation hw/misc/bcm2835_cprman: implement PLL channels behaviour hw/misc/bcm2835_cprman: add a clock mux skeleton implementation hw/misc/bcm2835_cprman: implement clock mux behaviour hw/misc/bcm2835_cprman: add the DSI0HSCK multiplexer hw/misc/bcm2835_cprman: add sane reset values to the registers hw/char/pl011: add a clock input hw/arm/bcm2835_peripherals: connect the UART clock
include/hw/arm/bcm2835_peripherals.h | 5 +- include/hw/arm/raspi_platform.h | 5 +- include/hw/char/pl011.h | 1 + include/hw/clock.h | 18 + include/hw/misc/bcm2835_cprman.h | 210 ++++ include/hw/misc/bcm2835_cprman_internals.h | 1019 ++++++++++++++++++++ hw/arm/bcm2835_peripherals.c | 15 +- hw/char/pl011.c | 45 + hw/core/clock.c | 21 +- hw/misc/bcm2835_cprman.c | 808 ++++++++++++++++ hw/char/trace-events | 1 + hw/core/trace-events | 4 +- hw/misc/meson.build | 1 + hw/misc/trace-events | 5 + 14 files changed, 2146 insertions(+), 12 deletions(-) create mode 100644 include/hw/misc/bcm2835_cprman.h create mode 100644 include/hw/misc/bcm2835_cprman_internals.h create mode 100644 hw/misc/bcm2835_cprman.c
Signature · 1 line
2.28.0
PATCH v3 1/15 hw/core/clock: provide the VMSTATE_ARRAY_CLOCK macro
--- include/hw/clock.h | 5 +++++ 1 file changed, 5 insertions(+)
include/hw/clock.h +5 -0
@@ -79,10 +79,15 @@ struct Clock {extern const VMStateDescription vmstate_clock;#define VMSTATE_CLOCK (field, state) \ VMSTATE_CLOCK_V(field, state, 0)#define VMSTATE_CLOCK_V (field, state, version) \ VMSTATE_STRUCT_POINTER_V(field, state, version, vmstate_clock, Clock) +#define VMSTATE_ARRAY_CLOCK (field, state, num) \ + VMSTATE_ARRAY_CLOCK_V(field, state, num, 0) +#define VMSTATE_ARRAY_CLOCK_V (field, state, num, version) \ + VMSTATE_ARRAY_OF_POINTER_TO_STRUCT(field, state, num, version, \ + vmstate_clock, Clock)/** * clock_setup_canonical_path: * @clk: clock *
Signature · 1 line
2.28.0
PATCH v3 2/15 hw/core/clock: trace clock values in Hz instead of ns
In reply to Luc MichelThe nanosecond unit greatly limits the dynamic range we can display in clock value traces, for values in the order of 1GHz and more. The internal representation can go way beyond this value and it is quite common for today's clocks to be within those ranges.
For example, a frequency between 500MHz+ and 1GHz will be displayed as 1ns. Beyond 1GHz, it will show up as 0ns.
Replace nanosecond periods traces with frequencies in the Hz unit to have more dynamic range in the trace output.
--- hw/core/clock.c | 6 +++--- hw/core/trace-events | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-)
hw/core/clock.c +3 -3
@@ -37,12 +37,12 @@ void clock_clear_callback(Clock *clk)bool clock_set (Clock *clk,uint64_t period) {if (clk->period == period) {return false; } -trace_clock_set (CLOCK_PATH (clk),CLOCK_PERIOD_TO_NS (clk->period), -CLOCK_PERIOD_TO_NS (period)); +trace_clock_set (CLOCK_PATH (clk),CLOCK_PERIOD_TO_HZ (clk->period), +CLOCK_PERIOD_TO_HZ (period)); clk->period = period;return true; }
@@ -52,11 +52,11 @@ static void clock_propagate_period(Clock *clk, bool call_callbacks) QLIST_FOREACH(child, &clk->children, sibling) {if (child->period != clk->period) { child->period = clk->period;trace_clock_update (CLOCK_PATH (child),CLOCK_PATH (clk), -CLOCK_PERIOD_TO_NS (clk->period), +CLOCK_PERIOD_TO_HZ (clk->period), call_callbacks);if (call_callbacks && child->callback) { child->callback (child->callback_opaque); }clock_propagate_period (child, call_callbacks);
hw/core/trace-events +2 -2
@@ -29,8 +29,8 @@ resettable_phase_exit_end(void *obj, const char *objtype, unsigned count) "obj=% resettable_transitional_function(void *obj, const char *objtype) "obj=%p(%s)" # clock.c clock_set_source(const char *clk, const char *src) "'%s', src='%s'" clock_disconnect(const char *clk) "'%s'" -clock_set(const char *clk, uint64_t old, uint64_t new) "'%s', ns=%"PRIu64"->%"PRIu64 +clock_set(const char *clk, uint64_t old, uint64_t new) "'%s', %"PRIu64"Hz->%"PRIu64"Hz" clock_propagate(const char *clk) "'%s'" -clock_update(const char *clk, const char *src, uint64_t val, int cb) "'%s', src='%s', ns=%"PRIu64", cb=%d" +clock_update(const char *clk, const char *src, uint64_t hz, int cb) "'%s', src='%s', val=%"PRIu64"Hz cb=%d"
Signature · 1 line
2.28.0
Re: [PATCH v3 02/15] hw/core/clock: trace clock values in Hz instead of ns
Quoted 56 lines · Luc Michel
The nanosecond unit greatly limits the dynamic range we can display in clock value traces, for values in the order of 1GHz and more. The internal representation can go way beyond this value and it is quite common for today's clocks to be within those ranges.
For example, a frequency between 500MHz+ and 1GHz will be displayed as 1ns. Beyond 1GHz, it will show up as 0ns.
Replace nanosecond periods traces with frequencies in the Hz unit to have more dynamic range in the trace output.
Reviewed-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Damien Hedde <[email protected]>Signed-off-by Luc Michel <[email protected]>--- hw/core/clock.c | 6 +++--- hw/core/trace-events | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-)hw/core/clock.c +3
-3@@ -37,12 +37,12 @@ void clock_clear_callback(Clock *clk)bool clock_set (Clock *clk,uint64_t period) {if (clk->period == period) {return false; } -trace_clock_set (CLOCK_PATH (clk),CLOCK_PERIOD_TO_NS (clk->period), -CLOCK_PERIOD_TO_NS (period)); +trace_clock_set (CLOCK_PATH (clk),CLOCK_PERIOD_TO_HZ (clk->period), +CLOCK_PERIOD_TO_HZ (period)); clk->period = period;return true; }@@ -52,11 +52,11 @@ static void clock_propagate_period(Clock *clk, bool call_callbacks) QLIST_FOREACH(child, &clk->children, sibling) {if (child->period != clk->period) { child->period = clk->period;trace_clock_update (CLOCK_PATH (child),CLOCK_PATH (clk), -CLOCK_PERIOD_TO_NS (clk->period), +CLOCK_PERIOD_TO_HZ (clk->period), call_callbacks);if (call_callbacks && child->callback) { child->callback (child->callback_opaque); }clock_propagate_period (child, call_callbacks);hw/core/trace-events +0
-0
hw/core/trace-events resettable_phase_exit_end(void *obj, const char *objtype, unsigned count) "obj=% · line 34
Quoted 7 lines
hw/core/trace-events +1
-1@@ -29,8 +29,8 @@ resettable_phase_exit_end(void *obj, const char *objtype, unsigned count) "obj=% resettable_transitional_function(void *obj, const char *objtype) "obj=%p(%s)" # clock.c clock_set_source(const char *clk, const char *src) "'%s', src='%s'" clock_disconnect(const char *clk) "'%s'" -clock_set(const char *clk, uint64_t old, uint64_t new) "'%s', ns=%"PRIu64"->%"PRIu64 +clock_set(const char *clk, uint64_t old, uint64_t new) "'%s', %"PRIu64"Hz->%"PRIu64"Hz"
I find it easier to read/follow as: "'%s', %"PRIu64" -> %"PRIu64" Hz", you see the number directly, no need for the brain to extract the trailing "Hz".
Quoted 4 lines
hw/core/trace-events +1
-1clock_propagate(const char *clk) "'%s'" -clock_update(const char *clk, const char *src, uint64_t val, int cb) "'%s', src='%s', ns=%"PRIu64", cb=%d" +clock_update(const char *clk, const char *src, uint64_t hz, int cb) "'%s', src='%s', val=%"PRIu64"Hz cb=%d"
PATCH v3 3/15 hw/core/clock: add the clock_new helper function
In reply to Luc MichelThis function creates a clock and parents it to another object with a given name. It calls clock_setup_canonical_path before returning the new clock.
This function is useful to create clocks in devices when one doesn't want to expose it at the qdev level (as an input or an output).
--- include/hw/clock.h | 13 +++++++++++++ hw/core/clock.c | 15 +++++++++++++++ 2 files changed, 28 insertions(+)
include/hw/clock.h +13 -0
@@ -93,10 +93,23 @@ extern const VMStateDescription vmstate_clock;* * compute the canonical path of the clock (used by log messages) */ void clock_setup_canonical_path (Clock *clk); +/** +* clock_new: +* @parent: the clock parent +* @name: the clock object name +* +* Helper function to create a new clock and parent it to @parent. There is no +* need to call clock_setup_canonical_path on the returned clock as it is done +* by this function. +* +* @return the newly created clock +*/ +Clock *clock_new (Object *parent,const char *name); +/** * clock_set_callback: * @clk: the clock to register the callback into * @cb: the callback function * @opaque: the argument to the callback
hw/core/clock.c +15 -0
@@ -21,10 +21,25 @@ void clock_setup_canonical_path(Clock *clk) {g_free (clk->canonical_path); clk->canonical_path =object_get_canonical_path (OBJECT (clk)); } +Clock *clock_new (Object *parent,const char *name) +{ +Object *obj; +Clock *clk; + + obj =object_new (TYPE_CLOCK ); +object_property_add_child (parent, name, obj); +object_unref (obj); + + clk =CLOCK (obj); +clock_setup_canonical_path (clk); + +return clk; +} +void clock_set_callback (Clock *clk,ClockCallback *cb,void *opaque) { clk->callback = cb; clk->callback_opaque = opaque; }
Signature · 1 line
2.28.0
Re: [PATCH v3 03/15] hw/core/clock: add the clock_new helper function
Quoted 7 lines · Luc Michel
This function creates a clock and parents it to another object with a given name. It calls
clock_setup_canonical_pathbefore returning the new clock.This function is useful to create clocks in devices when one doesn't want to expose it at the qdev level (as an input or an output).
Quoted 6 lines
Suggested-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Luc Michel <[email protected]>--- include/hw/clock.h | 13 +++++++++++++ hw/core/clock.c | 15 +++++++++++++++ 2 files changed, 28 insertions(+)
Philippe Mathieu-Daudé
Tested-byRe: [PATCH v3 03/15] hw/core/clock: add the clock_new helper function
Quoted 8 lines · Philippe Mathieu-Daudé
Quoted 7 lines · Luc Michel
This function creates a clock and parents it to another object with a given name. It calls
clock_setup_canonical_pathbefore returning the new clock.This function is useful to create clocks in devices when one doesn't want to expose it at the qdev level (as an input or an output).
Quoted 8 lines
Quoted 6 lines
Suggested-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Luc Michel <[email protected]>---
include/hw/clock.h| 13 +++++++++++++
hw/core/clock.c | 15 +++++++++++++++2 files changed, 28 insertions(+)Reviewed-by Philippe Mathieu-Daudé <[email protected]>
PATCH v3 4/15 hw/arm/raspi: fix CPRMAN base address
In reply to Luc MichelThe CPRMAN (clock controller) was mapped at the watchdog/power manager address. It was also split into two unimplemented peripherals (CM and A2W) but this is really the same one, as shown by this extract of the Raspberry Pi 3 Linux device tree:
watchdog@7e100000 {
compatible = "brcm,bcm2835-pm\0brcm,bcm2835-pm-wdt";
[...]
reg = <0x7e100000 0x114 0x7e00a000 0x24>;
[...]
};
[...]
cprman@7e101000 {
compatible = "brcm,bcm2835-cprman";
[...]
reg = <0x7e101000 0x2000>;
[...]
};--- include/hw/arm/bcm2835_peripherals.h | 2 +- include/hw/arm/raspi_platform.h | 5 ++--- hw/arm/bcm2835_peripherals.c | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-)
include/hw/arm/bcm2835_peripherals.h +1 -1
@@ -45,12 +45,12 @@ struct BCM2835PeripheralState {BCM2835SystemTimerState systmr;BCM2835MphiState mphi;UnimplementedDeviceState txp;UnimplementedDeviceState armtmr; +UnimplementedDeviceState powermgt;UnimplementedDeviceState cprman; -UnimplementedDeviceState a2w;PL011State uart0;BCM2835AuxState aux;BCM2835FBState fb;BCM2835DMAState dma;BCM2835ICState ic;
include/hw/arm/raspi_platform.h +2 -3
@@ -43,13 +43,12 @@#define ARMCTRL_OFFSET (ARM_OFFSET + 0x000)#define ARMCTRL_IC_OFFSET (ARM_OFFSET + 0x200)/* Interrupt controller */ #define ARMCTRL_TIMER0_1_OFFSET (ARM_OFFSET + 0x400)/* Timer 0 and 1 (SP804) */ #define ARMCTRL_0_SBM_OFFSET (ARM_OFFSET + 0x800)/* User 0 (ARM) Semaphores * Doorbells & Mailboxes */ -#define CPRMAN_OFFSET 0x100000/* Power Management, Watchdog */ -#define CM_OFFSET 0x101000/* Clock Management */ -#define A2W_OFFSET 0x102000/* Reset controller */ +#define PM_OFFSET 0x100000/* Power Management */ +#define CPRMAN_OFFSET 0x101000/* Clock Management */ #define AVS_OFFSET 0x103000/* Audio Video Standard */ #define RNG_OFFSET 0x104000#define GPIO_OFFSET 0x200000#define UART0_OFFSET 0x201000/* PL011 */ #define MMCI0_OFFSET 0x202000/* Legacy MMC */
hw/arm/bcm2835_peripherals.c +2 -2
@@ -343,12 +343,12 @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)qdev_get_gpio_in_named (DEVICE (&s->ic),BCM2835_IC_GPU_IRQ , INTERRUPT_USB));create_unimp (s, &s->txp,"bcm2835-txp" ,TXP_OFFSET ,0x1000 );create_unimp (s, &s->armtmr,"bcm2835-sp804" ,ARMCTRL_TIMER0_1_OFFSET ,0x40 ); -create_unimp (s, &s->cprman,"bcm2835-cprman" ,CPRMAN_OFFSET ,0x1000 ); -create_unimp (s, &s->a2w,"bcm2835-a2w" ,A2W_OFFSET ,0x1000 ); +create_unimp (s, &s->powermgt,"bcm2835-powermgt" ,PM_OFFSET ,0x114 ); +create_unimp (s, &s->cprman,"bcm2835-cprman" ,CPRMAN_OFFSET ,0x2000 );create_unimp (s, &s->i2s,"bcm2835-i2s" ,I2S_OFFSET ,0x100 );create_unimp (s, &s->smi,"bcm2835-smi" ,SMI_OFFSET ,0x100 );create_unimp (s, &s->spi[0 ],"bcm2835-spi0" ,SPI0_OFFSET ,0x20 );create_unimp (s, &s->bscsl,"bcm2835-spis" ,BSC_SL_OFFSET ,0x100 );create_unimp (s, &s->i2c[0 ],"bcm2835-i2c0" ,BSC0_OFFSET ,0x20 );
Signature · 1 line
2.28.0
PATCH v3 5/15 hw/arm/raspi: add a skeleton implementation of the CPRMAN
In reply to Luc MichelThe BCM2835 CPRMAN is the clock manager of the SoC. It is composed of a main oscillator, and several sub-components (PLLs, multiplexers, ...) to generate the BCM2835 clock tree.
This commit adds a skeleton of the CPRMAN, with a dummy register read/write implementation. It embeds the main oscillator (xosc) from which all the clocks will be derived.
--- include/hw/arm/bcm2835_peripherals.h | 3 +- include/hw/misc/bcm2835_cprman.h | 37 +++++ include/hw/misc/bcm2835_cprman_internals.h | 24 +++ hw/arm/bcm2835_peripherals.c | 11 +- hw/misc/bcm2835_cprman.c | 163 +++++++++++++++++++++ hw/misc/meson.build | 1 + hw/misc/trace-events | 5 + 7 files changed, 242 insertions(+), 2 deletions(-) create mode 100644 include/hw/misc/bcm2835_cprman.h create mode 100644 include/hw/misc/bcm2835_cprman_internals.h create mode 100644 hw/misc/bcm2835_cprman.c
include/hw/arm/bcm2835_peripherals.h +2 -1
@@ -21,10 +21,11 @@#include "hw/misc/bcm2835_property.h" #include "hw/misc/bcm2835_rng.h" #include "hw/misc/bcm2835_mbox.h" #include "hw/misc/bcm2835_mphi.h" #include "hw/misc/bcm2835_thermal.h" +#include "hw/misc/bcm2835_cprman.h" #include "hw/sd/sdhci.h" #include "hw/sd/bcm2835_sdhost.h" #include "hw/gpio/bcm2835_gpio.h" #include "hw/timer/bcm2835_systmr.h" #include "hw/usb/hcd-dwc2.h"
@@ -46,11 +47,11 @@ struct BCM2835PeripheralState {BCM2835SystemTimerState systmr;BCM2835MphiState mphi;UnimplementedDeviceState txp;UnimplementedDeviceState armtmr;UnimplementedDeviceState powermgt; -UnimplementedDeviceState cprman; +BCM2835CprmanState cprman;PL011State uart0;BCM2835AuxState aux;BCM2835FBState fb;BCM2835DMAState dma;BCM2835ICState ic;
include/hw/misc/bcm2835_cprman.h new file +37 -0
@@ -0,0 +1,37 @@ +/* +* BCM2835 CPRMAN clock manager +* +* Copyright (c) 2020 Luc Michel <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef HW_MISC_CPRMAN_H +#define HW_MISC_CPRMAN_H + +#include "hw/sysbus.h" +#include "hw/qdev-clock.h" + +#define TYPE_BCM2835_CPRMAN "bcm2835-cprman" + +typedef struct BCM2835CprmanState BCM2835CprmanState ; + +DECLARE_INSTANCE_CHECKER (BCM2835CprmanState,CPRMAN , + TYPE_BCM2835_CPRMAN) + +#define CPRMAN_NUM_REGS (0x2000 / sizeof(uint32_t)) + +struct BCM2835CprmanState { +/*< private >*/ +SysBusDevice parent_obj; + +/*< public >*/ +MemoryRegion iomem; + +uint32_t regs[CPRMAN_NUM_REGS ]; +uint32_t xosc_freq; + +Clock *xosc; +}; + +#endif
include/hw/misc/bcm2835_cprman_internals.h new file +24 -0
@@ -0,0 +1,24 @@ +/* +* BCM2835 CPRMAN clock manager +* +* Copyright (c) 2020 Luc Michel <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef HW_MISC_CPRMAN_INTERNALS_H +#define HW_MISC_CPRMAN_INTERNALS_H + +#include "hw/registerfields.h" +#include "hw/misc/bcm2835_cprman.h" + +/* Register map */ + +/* +* This field is common to all registers. Each register write value must match +* the CPRMAN_PASSWORD magic value in its 8 MSB. +*/ +FIELD(CPRMAN, PASSWORD, 24, 8) +#define CPRMAN_PASSWORD 0x5a + +#endif
hw/arm/bcm2835_peripherals.c +10 -1
@@ -119,10 +119,13 @@ static void bcm2835_peripherals_init(Object *obj)object_initialize_child (obj,"mphi" , &s->mphi,TYPE_BCM2835_MPHI );/* DWC2 */ object_initialize_child (obj,"dwc2" , &s->dwc2,TYPE_DWC2_USB ); +/* CPRMAN clock manager */ +object_initialize_child (obj,"cprman" , &s->cprman,TYPE_BCM2835_CPRMAN ); +object_property_add_const_link (OBJECT (&s->dwc2),"dma-mr" ,OBJECT (&s->gpu_bus_mr)); }static void bcm2835_peripherals_realize (DeviceState *dev,Error **errp)
@@ -158,10 +161,17 @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)/* Interrupt Controller */ if (!sysbus_realize (SYS_BUS_DEVICE (&s->ic), errp)) {return ; } +/* CPRMAN clock manager */ +if (!sysbus_realize (SYS_BUS_DEVICE (&s->cprman), errp)) { +return ; + } +memory_region_add_subregion (&s->peri_mr,CPRMAN_OFFSET , +sysbus_mmio_get_region (SYS_BUS_DEVICE (&s->cprman),0 )); +memory_region_add_subregion (&s->peri_mr,ARMCTRL_IC_OFFSET ,sysbus_mmio_get_region (SYS_BUS_DEVICE (&s->ic),0 ));sysbus_pass_irq (SYS_BUS_DEVICE (s),SYS_BUS_DEVICE (&s->ic));/* Sys Timer */
@@ -344,11 +354,10 @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp) INTERRUPT_USB));create_unimp (s, &s->txp,"bcm2835-txp" ,TXP_OFFSET ,0x1000 );create_unimp (s, &s->armtmr,"bcm2835-sp804" ,ARMCTRL_TIMER0_1_OFFSET ,0x40 );create_unimp (s, &s->powermgt,"bcm2835-powermgt" ,PM_OFFSET ,0x114 ); -create_unimp (s, &s->cprman,"bcm2835-cprman" ,CPRMAN_OFFSET ,0x2000 );create_unimp (s, &s->i2s,"bcm2835-i2s" ,I2S_OFFSET ,0x100 );create_unimp (s, &s->smi,"bcm2835-smi" ,SMI_OFFSET ,0x100 );create_unimp (s, &s->spi[0 ],"bcm2835-spi0" ,SPI0_OFFSET ,0x20 );create_unimp (s, &s->bscsl,"bcm2835-spis" ,BSC_SL_OFFSET ,0x100 );create_unimp (s, &s->i2c[0 ],"bcm2835-i2c0" ,BSC0_OFFSET ,0x20 );
hw/misc/bcm2835_cprman.c new file +163 -0
163 lines not on this page · raw message
hw/misc/meson.build +1 -0
@@ -71,10 +71,11 @@ softmmu_ss.add(when: 'CONFIG_RASPI', if_true: files( 'bcm2835_mbox.c', 'bcm2835_mphi.c', 'bcm2835_property.c', 'bcm2835_rng.c', 'bcm2835_thermal.c', + 'bcm2835_cprman.c', )) softmmu_ss.add(when: 'CONFIG_SLAVIO', if_true: files('slavio_misc.c')) softmmu_ss.add(when: 'CONFIG_ZYNQ', if_true: files('zynq_slcr.c', 'zynq-xadc.c')) softmmu_ss.add(when: 'CONFIG_STM32F2XX_SYSCFG', if_true: files('stm32f2xx_syscfg.c')) softmmu_ss.add(when: 'CONFIG_STM32F4XX_SYSCFG', if_true: files('stm32f4xx_syscfg.c'))
hw/misc/trace-events +5 -0
@@ -224,5 +224,10 @@ grlib_ahb_pnp_read(uint64_t addr, uint32_t value) "AHB PnP read addr:0x%03"PRIx6 grlib_apb_pnp_read(uint64_t addr, uint32_t value) "APB PnP read addr:0x%03"PRIx64" data:0x%08x" # pca9552.c pca955x_gpio_status(const char *description, const char *buf) "%s GPIOs 0-15 [%s]" pca955x_gpio_change(const char *description, unsigned id, unsigned prev_state, unsigned current_state) "%s GPIO id:%u status: %u -> %u" + +# bcm2835_cprman.c +bcm2835_cprman_read(uint64_t offset, uint64_t value) "offset:0x%" PRIx64 " value:0x%" PRIx64 +bcm2835_cprman_write(uint64_t offset, uint64_t value) "offset:0x%" PRIx64 " value:0x%" PRIx64 +bcm2835_cprman_write_invalid_magic(uint64_t offset, uint64_t value) "offset:0x%" PRIx64 " value:0x%" PRIx64
Signature · 1 line
2.28.0
PATCH v3 6/15 hw/misc/bcm2835_cprman: add a PLL skeleton implementation
In reply to Luc MichelThere are 5 PLLs in the CPRMAN, namely PLL A, C, D, H and B. All of them take the xosc clock as input and produce a new clock.
This commit adds a skeleton implementation for the PLLs as sub-devices of the CPRMAN. The PLLs are instantiated and connected internally to the main oscillator.
Each PLL has 6 registers : CM, A2W_CTRL, A2W_ANA[0,1,2,3], A2W_FRAC. A write to any of them triggers a call to the (not yet implemented) pll_update function.
If the main oscillator changes frequency, an update is also triggered.
--- include/hw/misc/bcm2835_cprman.h | 29 +++++ include/hw/misc/bcm2835_cprman_internals.h | 144 +++++++++++++++++++++ hw/misc/bcm2835_cprman.c | 108 ++++++++++++++++ 3 files changed, 281 insertions(+)
include/hw/misc/bcm2835_cprman.h +29 -0
@@ -19,17 +19,46 @@ typedef struct BCM2835CprmanState BCM2835CprmanState;DECLARE_INSTANCE_CHECKER (BCM2835CprmanState,CPRMAN , TYPE_BCM2835_CPRMAN)#define CPRMAN_NUM_REGS (0x2000 / sizeof(uint32_t)) +typedef enum CprmanPll { +CPRMAN_PLLA =0 , +CPRMAN_PLLC , +CPRMAN_PLLD , +CPRMAN_PLLH , +CPRMAN_PLLB , + +CPRMAN_NUM_PLL +}CprmanPll ; + +typedef struct CprmanPllState { +/*< private >*/ +DeviceState parent_obj; + +/*< public >*/ +CprmanPll id; + +uint32_t *reg_cm; +uint32_t *reg_a2w_ctrl; +uint32_t *reg_a2w_ana;/* ANA[0] .. ANA[3] */ +uint32_t prediv_mask;/* prediv bit in ana[1] */ +uint32_t *reg_a2w_frac; + +Clock *xosc_in; +Clock *out; +}CprmanPllState ; +struct BCM2835CprmanState {/*< private >*/ SysBusDevice parent_obj;/*< public >*/ MemoryRegion iomem; +CprmanPllState plls[CPRMAN_NUM_PLL ]; +uint32_t regs[CPRMAN_NUM_REGS ];uint32_t xosc_freq;Clock *xosc; };
include/hw/misc/bcm2835_cprman_internals.h +144 -0
159 lines not on this page · raw message
hw/misc/bcm2835_cprman.c +108 -0
185 lines not on this page · raw message
Signature · 1 line
2.28.0
PATCH v3 7/15 hw/misc/bcm2835_cprman: implement PLLs behaviour
In reply to Luc MichelThe CPRMAN PLLs generate a clock based on a prescaler, a multiplier and a divider. The prescaler doubles the parent (xosc) frequency, then the multiplier/divider are applied. The multiplier has an integer and a fractional part.
This commit also implements the CPRMAN CM_LOCK register. This register reports which PLL is currently locked. We consider a PLL has being locked as soon as it is enabled (on real hardware, there is a delay after turning a PLL on, for it to stabilize).
--- include/hw/misc/bcm2835_cprman_internals.h | 8 +++ hw/misc/bcm2835_cprman.c | 64 +++++++++++++++++++++- 2 files changed, 71 insertions(+), 1 deletion(-)
include/hw/misc/bcm2835_cprman_internals.h +8 -0
@@ -98,10 +98,18 @@ REG32(A2W_PLLA_FRAC, 0x1200) REG32(A2W_PLLC_FRAC, 0x1220) REG32(A2W_PLLD_FRAC, 0x1240) REG32(A2W_PLLH_FRAC, 0x1260)REG32 (A2W_PLLB_FRAC ,0x12e0 ) +/* misc registers */ +REG32(CM_LOCK, 0x114) + FIELD(CM_LOCK, FLOCKH, 12, 1) + FIELD(CM_LOCK, FLOCKD, 11, 1) + FIELD(CM_LOCK, FLOCKC, 10, 1) + FIELD(CM_LOCK, FLOCKB, 9, 1) +FIELD (CM_LOCK ,FLOCKA ,8 ,1 ) +/* * This field is common to all registers. Each register write value must match * the CPRMAN_PASSWORD magic value in its 8 MSB. */FIELD (CPRMAN ,PASSWORD ,24 ,8 )
hw/misc/bcm2835_cprman.c +63 -1
94 lines not on this page · raw message
Signature · 1 line
2.28.0
PATCH v3 8/15 hw/misc/bcm2835_cprman: add a PLL channel skeleton implementation
In reply to Luc MichelPLLs are composed of multiple channels. Each channel outputs one clock signal. They are modeled as one device taking the PLL generated clock as input, and outputting a new clock.
A channel shares the CM register with its parent PLL, and has its own A2W_CTRL register. A write to the CM register will trigger an update of the PLL and all its channels, while a write to an A2W_CTRL channel register will update the required channel only.
--- include/hw/misc/bcm2835_cprman.h | 44 ++++++ include/hw/misc/bcm2835_cprman_internals.h | 146 +++++++++++++++++++ hw/misc/bcm2835_cprman.c | 155 +++++++++++++++++++-- 3 files changed, 337 insertions(+), 8 deletions(-)
include/hw/misc/bcm2835_cprman.h +44 -0
@@ -29,10 +29,35 @@ typedef enum CprmanPll {CPRMAN_PLLB , CPRMAN_NUM_PLL } CprmanPll; +typedef enum CprmanPllChannel { +CPRMAN_PLLA_CHANNEL_DSI0 =0 , +CPRMAN_PLLA_CHANNEL_CORE , +CPRMAN_PLLA_CHANNEL_PER , +CPRMAN_PLLA_CHANNEL_CCP2 , + +CPRMAN_PLLC_CHANNEL_CORE2 , +CPRMAN_PLLC_CHANNEL_CORE1 , +CPRMAN_PLLC_CHANNEL_PER , +CPRMAN_PLLC_CHANNEL_CORE0 , + +CPRMAN_PLLD_CHANNEL_DSI0 , +CPRMAN_PLLD_CHANNEL_CORE , +CPRMAN_PLLD_CHANNEL_PER , +CPRMAN_PLLD_CHANNEL_DSI1 , + +CPRMAN_PLLH_CHANNEL_AUX , +CPRMAN_PLLH_CHANNEL_RCAL , +CPRMAN_PLLH_CHANNEL_PIX , + +CPRMAN_PLLB_CHANNEL_ARM , + +CPRMAN_NUM_PLL_CHANNEL , +}CprmanPllChannel ; + typedef struct CprmanPllState { /*< private >*/ DeviceState parent_obj; /*< public >*/
@@ -46,18 +71,37 @@ typedef struct CprmanPllState {Clock *xosc_in;Clock *out; } CprmanPllState; +typedef struct CprmanPllChannelState { +/*< private >*/ +DeviceState parent_obj; + +/*< public >*/ +CprmanPllChannel id; +CprmanPll parent; + +uint32_t *reg_cm; +uint32_t hold_mask; +uint32_t load_mask; +uint32_t *reg_a2w_ctrl; +int fixed_divider; + +Clock *pll_in; +Clock *out; +}CprmanPllChannelState ; +struct BCM2835CprmanState {/*< private >*/ SysBusDevice parent_obj;/*< public >*/ MemoryRegion iomem;CprmanPllState plls[CPRMAN_NUM_PLL ]; +CprmanPllChannelState channels[CPRMAN_NUM_PLL_CHANNEL ];uint32_t regs[CPRMAN_NUM_REGS ];uint32_t xosc_freq;Clock *xosc;
include/hw/misc/bcm2835_cprman_internals.h +146 -0
175 lines not on this page · raw message
hw/misc/bcm2835_cprman.c +147 -8
240 lines not on this page · raw message
Signature · 1 line
2.28.0
Re: [PATCH v3 08/15] hw/misc/bcm2835_cprman: add a PLL channel skeleton implementation
Quoted 17 lines · Luc Michel
PLLs are composed of multiple channels. Each channel outputs one clock signal. They are modeled as one device taking the PLL generated clock as input, and outputting a new clock.
A channel shares the CM register with its parent PLL, and has its own
A2W_CTRLregister. A write to the CM register will trigger an update of the PLL and all its channels, while a write to anA2W_CTRLchannel register will update the required channel only.Reviewed-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Luc Michel <[email protected]>--- include/hw/misc/bcm2835_cprman.h | 44 ++++++ include/hw/misc/bcm2835_cprman_internals.h | 146 +++++++++++++++++++ hw/misc/bcm2835_cprman.c | 155 +++++++++++++++++++-- 3 files changed, 337 insertions(+), 8 deletions(-)
[...]
Quoted 81 lines
include/hw/misc/bcm2835_cprman_internals.h +46
-0@@ -11,13 +11,16 @@#include "hw/registerfields.h" #include "hw/misc/bcm2835_cprman.h" #define TYPE_CPRMAN_PLL "bcm2835-cprman-pll" +#define TYPE_CPRMAN_PLL_CHANNEL "bcm2835-cprman-pll-channel"DECLARE_INSTANCE_CHECKER (CprmanPllState,CPRMAN_PLL , TYPE_CPRMAN_PLL) +DECLARE_INSTANCE_CHECKER (CprmanPllChannelState,CPRMAN_PLL_CHANNEL , +TYPE_CPRMAN_PLL_CHANNEL )/* Register map */ /* PLLs */REG32 (CM_PLLA ,0x104 )@@ -98,10 +101,35 @@ REG32(A2W_PLLA_FRAC, 0x1200) REG32(A2W_PLLC_FRAC, 0x1220) REG32(A2W_PLLD_FRAC, 0x1240) REG32(A2W_PLLH_FRAC, 0x1260)REG32 (A2W_PLLB_FRAC ,0x12e0 ) +/* PLL channels */ +REG32(A2W_PLLA_DSI0, 0x1300) + FIELD(A2W_PLLx_CHANNELy, DIV, 0, 8) + FIELD(A2W_PLLx_CHANNELy, DISABLE, 8, 1) +REG32(A2W_PLLA_CORE, 0x1400) +REG32(A2W_PLLA_PER, 0x1500) +REG32(A2W_PLLA_CCP2, 0x1600) + +REG32(A2W_PLLC_CORE2, 0x1320) +REG32(A2W_PLLC_CORE1, 0x1420) +REG32(A2W_PLLC_PER, 0x1520) +REG32(A2W_PLLC_CORE0, 0x1620) + +REG32(A2W_PLLD_DSI0, 0x1340) +REG32(A2W_PLLD_CORE, 0x1440) +REG32(A2W_PLLD_PER, 0x1540) +REG32(A2W_PLLD_DSI1, 0x1640) + +REG32(A2W_PLLH_AUX, 0x1360) +REG32(A2W_PLLH_RCAL, 0x1460) +REG32(A2W_PLLH_PIX, 0x1560) +REG32(A2W_PLLH_STS, 0x1660) + +REG32 (A2W_PLLB_ARM ,0x13e0 ) + /* misc registers */ REG32(CM_LOCK, 0x114) FIELD(CM_LOCK, FLOCKH, 12, 1) FIELD(CM_LOCK, FLOCKD, 11, 1)FIELD (CM_LOCK ,FLOCKC ,10 ,1 )@@ -171,6 +199,124 @@ static inline void set_pll_init_info(BCM2835CprmanState *s, pll->reg_a2w_ana = &s->regs[PLL_INIT_INFO [id].a2w_ana_offset]; pll->prediv_mask =PLL_INIT_INFO [id].prediv_mask; pll->reg_a2w_frac = &s->regs[PLL_INIT_INFO [id].a2w_frac_offset]; } + +/* PLL channel init info */ +typedef struct PLLChannelInitInfo { +const char *name; +CprmanPll parent; +size_t cm_offset; +uint32_t cm_hold_mask; +uint32_t cm_load_mask; +size_t a2w_ctrl_offset; +unsigned int fixed_divider; +}PLLChannelInitInfo ; + +#define FILL_PLL_CHANNEL_INIT_INFO_common (pll_, channel_) \ + .parent = CPRMAN_ ## pll_, \ + .cm_offset = R_CM_ ## pll_, \ + .cm_load_mask = R_CM_ ## pll_ ## _ ## LOAD ## channel_ ## _MASK, \ + .a2w_ctrl_offset = R_A2W_ ## pll_ ## _ ## channel_ +
include/hw/misc/bcm2835_cprman_internals.h static inline void set_pll_init_info(BCM2835CprmanState *s, · line 231
Quoted 10 lines
include/hw/misc/bcm2835_cprman_internals.h +10
-0+#define FILL_PLL_CHANNEL_INIT_INFO (pll_, channel_) \ + FILL_PLL_CHANNEL_INIT_INFO_common(pll_, channel_), \ + .cm_hold_mask = R_CM_ ## pll_ ## _ ## HOLD ## channel_ ## _MASK, \ + .fixed_divider = 1 + +#define FILL_PLL_CHANNEL_INIT_INFO_nohold (pll_, channel_) \ + FILL_PLL_CHANNEL_INIT_INFO_common(pll_, channel_), \ + .cm_hold_mask = 0 + +static PLLChannelInitInfo PLL_CHANNEL_INIT_INFO [] = {
Hmm I missed this static definition in an header. As it is local and only include once, I'd prefer match the rest of the source tree style and name it .c.inc:
-- >8 --
hw/misc/bcm2835_cprman.c +1 -1
@@ -48,7 +48,7 @@#include "migration/vmstate.h" #include "hw/qdev-properties.h" #include "hw/misc/bcm2835_cprman.h" -#include "hw/misc/bcm2835_cprman_internals.h" +#include "bcm2835_cprman_internals.c.inc" #include "trace.h" /* PLL */
hw/misc/bcm2835_cprman_internals.c.inc renamed from include/hw/misc/bcm2835_cprman_internals.h +0 -0
---
Quoted 91 lines
include/hw/misc/bcm2835_cprman_internals.h +90
-0+ [CPRMAN_PLLA_CHANNEL_DSI0] = { + .name ="plla-dsi0" , + FILL_PLL_CHANNEL_INIT_INFO(PLLA, DSI0), + }, + [CPRMAN_PLLA_CHANNEL_CORE] = { + .name ="plla-core" , + FILL_PLL_CHANNEL_INIT_INFO(PLLA, CORE), + }, + [CPRMAN_PLLA_CHANNEL_PER] = { + .name ="plla-per" , + FILL_PLL_CHANNEL_INIT_INFO(PLLA, PER), + }, + [CPRMAN_PLLA_CHANNEL_CCP2] = { + .name ="plla-ccp2" , + FILL_PLL_CHANNEL_INIT_INFO(PLLA, CCP2), + }, + + [CPRMAN_PLLC_CHANNEL_CORE2] = { + .name ="pllc-core2" , + FILL_PLL_CHANNEL_INIT_INFO(PLLC, CORE2), + }, + [CPRMAN_PLLC_CHANNEL_CORE1] = { + .name ="pllc-core1" , + FILL_PLL_CHANNEL_INIT_INFO(PLLC, CORE1), + }, + [CPRMAN_PLLC_CHANNEL_PER] = { + .name ="pllc-per" , + FILL_PLL_CHANNEL_INIT_INFO(PLLC, PER), + }, + [CPRMAN_PLLC_CHANNEL_CORE0] = { + .name ="pllc-core0" , + FILL_PLL_CHANNEL_INIT_INFO(PLLC, CORE0), + }, + + [CPRMAN_PLLD_CHANNEL_DSI0] = { + .name ="plld-dsi0" , + FILL_PLL_CHANNEL_INIT_INFO(PLLD, DSI0), + }, + [CPRMAN_PLLD_CHANNEL_CORE] = { + .name ="plld-core" , + FILL_PLL_CHANNEL_INIT_INFO(PLLD, CORE), + }, + [CPRMAN_PLLD_CHANNEL_PER] = { + .name ="plld-per" , + FILL_PLL_CHANNEL_INIT_INFO(PLLD, PER), + }, + [CPRMAN_PLLD_CHANNEL_DSI1] = { + .name ="plld-dsi1" , + FILL_PLL_CHANNEL_INIT_INFO(PLLD, DSI1), + }, + + [CPRMAN_PLLH_CHANNEL_AUX] = { + .name ="pllh-aux" , + .fixed_divider = 1, + FILL_PLL_CHANNEL_INIT_INFO_nohold(PLLH, AUX), + }, + [CPRMAN_PLLH_CHANNEL_RCAL] = { + .name ="pllh-rcal" , + .fixed_divider = 10, + FILL_PLL_CHANNEL_INIT_INFO_nohold(PLLH, RCAL), + }, + [CPRMAN_PLLH_CHANNEL_PIX] = { + .name ="pllh-pix" , + .fixed_divider = 10, + FILL_PLL_CHANNEL_INIT_INFO_nohold(PLLH, PIX), + }, + + [CPRMAN_PLLB_CHANNEL_ARM] = { + .name ="pllb-arm" , + FILL_PLL_CHANNEL_INIT_INFO(PLLB, ARM), + }, +}; + +#undef FILL_PLL_CHANNEL_INIT_INFO_nohold +#undef FILL_PLL_CHANNEL_INIT_INFO +#undef FILL_PLL_CHANNEL_INIT_INFO_common + +static inline void set_pll_channel_init_info (BCM2835CprmanState *s, +CprmanPllChannelState *channel, +CprmanPllChannel id) +{ + channel->id = id; + channel->parent =PLL_CHANNEL_INIT_INFO [id].parent; + channel->reg_cm = &s->regs[PLL_CHANNEL_INIT_INFO [id].cm_offset]; + channel->hold_mask =PLL_CHANNEL_INIT_INFO [id].cm_hold_mask; + channel->load_mask =PLL_CHANNEL_INIT_INFO [id].cm_load_mask; + channel->reg_a2w_ctrl = &s->regs[PLL_CHANNEL_INIT_INFO [id].a2w_ctrl_offset]; + channel->fixed_divider =PLL_CHANNEL_INIT_INFO [id].fixed_divider; +} +#endif
[...]
Re: [PATCH v3 08/15] hw/misc/bcm2835_cprman: add a PLL channel skeleton implementation
Quoted 18 lines · Philippe Mathieu-Daudé
Quoted 17 lines · Luc Michel
PLLs are composed of multiple channels. Each channel outputs one clock signal. They are modeled as one device taking the PLL generated clock as input, and outputting a new clock.
A channel shares the CM register with its parent PLL, and has its own
A2W_CTRLregister. A write to the CM register will trigger an update of the PLL and all its channels, while a write to anA2W_CTRLchannel register will update the required channel only.Reviewed-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Luc Michel <[email protected]>---
include/hw/misc/bcm2835_cprman.h | 44 ++++++include/hw/misc/bcm2835_cprman_internals.h| 146 +++++++++++++++++++ hw/misc/bcm2835_cprman.c | 155 +++++++++++++++++++--3 files changed, 337 insertions(+), 8 deletions(-)
[...]
Quoted 39 lines
Quoted 6 lines
(quoted diff) +6
-0+#define FILL_PLL_CHANNEL_INIT_INFO_common(pll_, channel_) \ + .parent = CPRMAN_ ## pll_, \ + .cm_offset = R_CM_ ## pll_, \ + .cm_load_mask = R_CM_ ## pll_ ## _ ## LOAD ## channel_ ## _MASK, \ + .a2w_ctrl_offset = R_A2W_ ## pll_ ## _ ## channel_ +Review
Quoted 10 lines
(quoted diff) +10
-0+#define FILL_PLL_CHANNEL_INIT_INFO(pll_, channel_) \ + FILL_PLL_CHANNEL_INIT_INFO_common(pll_, channel_), \ + .cm_hold_mask = R_CM_ ## pll_ ## _ ## HOLD ## channel_ ## _MASK, \ + .fixed_divider = 1 + +#define FILL_PLL_CHANNEL_INIT_INFO_nohold(pll_, channel_) \ + FILL_PLL_CHANNEL_INIT_INFO_common(pll_, channel_), \ + .cm_hold_mask = 0 + +static PLLChannelInitInfo PLL_CHANNEL_INIT_INFO[] = {Hmm I missed this static definition in an header. As it is local and only include once, I'd prefer match the rest of the source tree style and name it .c.inc:
-- >8 --
hw/misc/bcm2835_cprman.c +1
-1@@ -48,7 +48,7 @@ #include "migration/vmstate.h" #include "hw/qdev-properties.h" #include "hw/misc/bcm2835_cprman.h" -#include "hw/misc/bcm2835_cprman_internals.h" +#include "bcm2835_cprman_internals.c.inc" #include "trace.h" /* PLL */hw/misc/bcm2835_cprman_internals.c.inc renamed from include/hw/misc/bcm2835_cprman_internals.h +0
-0
hw/misc/bcm2835_cprman_internals.c.inc
Quoted 1 line
hw/misc/bcm2835_cprman_internals.c.inc renamed from include/hw/misc/bcm2835_cprman_internals.h +0
-1---
This can be applied directly by Peter, or can
be cleaned later. This is not a blocker to get
this series merged.
PATCH v3 9/15 hw/misc/bcm2835_cprman: implement PLL channels behaviour
In reply to Luc MichelA 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.
--- hw/misc/bcm2835_cprman.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-)
hw/misc/bcm2835_cprman.c +32 -1
@@ -132,13 +132,44 @@ 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 */ static void pll_update_all_channels (BCM2835CprmanState *s,CprmanPllState *pll)
Signature · 1 line
2.28.0
PATCH v3 10/15 hw/misc/bcm2835_cprman: add a clock mux skeleton implementation
In reply to Luc MichelThe clock multiplexers are the last clock stage in the CPRMAN. Each mux outputs one clock signal that goes out of the CPRMAN to the SoC peripherals.
Each mux has at most 10 sources. The sources 0 to 3 are common to all muxes. They are:
0. ground (no clock signal)
1. the main oscillator (xosc)
2. "test debug 0" clock
3. "test debug 1" clock
Test debug 0 and 1 are actual clock muxes that can be used as sources to other muxes (for debug purpose).
Sources 4 to 9 are mux specific and can be unpopulated (grounded). Those sources are fed by the PLL channels outputs.
One corner case exists for DSI0E and DSI0P muxes. They have their source number 4 connected to an intermediate multiplexer that can select between PLLA-DSI0 and PLLD-DSI0 channel. This multiplexer is called DSI0HSCK and is not a clock mux as such. It is really a simple mux from the hardware point of view (see https://elinux.org/The_Undocumented_Pi).
This mux is not implemented in this commit.
Note that there is some muxes for which sources are unknown (because of a lack of documentation). For those cases all the sources are connected to ground in this implementation.
Each clock mux output is exported by the CPRMAN at the qdev level, adding the suffix '-out' to the mux name to form the output clock name. (E.g. the 'uart' mux sees its output exported as 'uart-out' at the CPRMAN level.)
--- include/hw/misc/bcm2835_cprman.h | 85 +++++ include/hw/misc/bcm2835_cprman_internals.h | 422 +++++++++++++++++++++ hw/misc/bcm2835_cprman.c | 151 ++++++++ 3 files changed, 658 insertions(+)
include/hw/misc/bcm2835_cprman.h +85 -0
@@ -52,12 +52,73 @@ typedef enum CprmanPllChannel {CPRMAN_PLLH_CHANNEL_PIX ,CPRMAN_PLLB_CHANNEL_ARM ,CPRMAN_NUM_PLL_CHANNEL , + +/* Special values used when connecting clock sources to clocks */ +CPRMAN_CLOCK_SRC_NORMAL =-1 , +CPRMAN_CLOCK_SRC_FORCE_GROUND =-2 , +CPRMAN_CLOCK_SRC_DSI0HSCK =-3 , } CprmanPllChannel; +typedef enum CprmanClockMux { +CPRMAN_CLOCK_GNRIC , +CPRMAN_CLOCK_VPU , +CPRMAN_CLOCK_SYS , +CPRMAN_CLOCK_PERIA , +CPRMAN_CLOCK_PERII , +CPRMAN_CLOCK_H264 , +CPRMAN_CLOCK_ISP , +CPRMAN_CLOCK_V3D , +CPRMAN_CLOCK_CAM0 , +CPRMAN_CLOCK_CAM1 , +CPRMAN_CLOCK_CCP2 , +CPRMAN_CLOCK_DSI0E , +CPRMAN_CLOCK_DSI0P , +CPRMAN_CLOCK_DPI , +CPRMAN_CLOCK_GP0 , +CPRMAN_CLOCK_GP1 , +CPRMAN_CLOCK_GP2 , +CPRMAN_CLOCK_HSM , +CPRMAN_CLOCK_OTP , +CPRMAN_CLOCK_PCM , +CPRMAN_CLOCK_PWM , +CPRMAN_CLOCK_SLIM , +CPRMAN_CLOCK_SMI , +CPRMAN_CLOCK_TEC , +CPRMAN_CLOCK_TD0 , +CPRMAN_CLOCK_TD1 , +CPRMAN_CLOCK_TSENS , +CPRMAN_CLOCK_TIMER , +CPRMAN_CLOCK_UART , +CPRMAN_CLOCK_VEC , +CPRMAN_CLOCK_PULSE , +CPRMAN_CLOCK_SDC , +CPRMAN_CLOCK_ARM , +CPRMAN_CLOCK_AVEO , +CPRMAN_CLOCK_EMMC , +CPRMAN_CLOCK_EMMC2 , + +CPRMAN_NUM_CLOCK_MUX +}CprmanClockMux ; + +typedef enum CprmanClockMuxSource { +CPRMAN_CLOCK_SRC_GND =0 , +CPRMAN_CLOCK_SRC_XOSC , +CPRMAN_CLOCK_SRC_TD0 , +CPRMAN_CLOCK_SRC_TD1 , +CPRMAN_CLOCK_SRC_PLLA , +CPRMAN_CLOCK_SRC_PLLC , +CPRMAN_CLOCK_SRC_PLLD , +CPRMAN_CLOCK_SRC_PLLH , +CPRMAN_CLOCK_SRC_PLLC_CORE1 , +CPRMAN_CLOCK_SRC_PLLC_CORE2 , + +CPRMAN_NUM_CLOCK_MUX_SRC +}CprmanClockMuxSource ; + typedef struct CprmanPllState { /*< private >*/ DeviceState parent_obj; /*< public >*/
@@ -89,22 +150,46 @@ typedef struct CprmanPllChannelState {Clock *pll_in; Clock *out; } CprmanPllChannelState; +typedef struct CprmanClockMuxState { +/*< private >*/ +DeviceState parent_obj; + +/*< public >*/ +CprmanClockMux id; + +uint32_t *reg_ctl; +uint32_t *reg_div; +int int_bits; +int frac_bits; + +Clock *srcs[CPRMAN_NUM_CLOCK_MUX_SRC ]; +Clock *out; + +/* +* Used by clock srcs update callback to retrieve both the clock and the +* source number. +*/ +struct CprmanClockMuxState *backref[CPRMAN_NUM_CLOCK_MUX_SRC ]; +}CprmanClockMuxState ; +struct BCM2835CprmanState {/*< private >*/ SysBusDevice parent_obj;/*< public >*/ MemoryRegion iomem;CprmanPllState plls[CPRMAN_NUM_PLL ];CprmanPllChannelState channels[CPRMAN_NUM_PLL_CHANNEL ]; +CprmanClockMuxState clock_muxes[CPRMAN_NUM_CLOCK_MUX ];uint32_t regs[CPRMAN_NUM_REGS ];uint32_t xosc_freq;Clock *xosc; +Clock *gnd; };#endif
include/hw/misc/bcm2835_cprman_internals.h +422 -0
453 lines not on this page · raw message
hw/misc/bcm2835_cprman.c +151 -0
236 lines not on this page · raw message
Signature · 1 line
2.28.0
PATCH v3 11/15 hw/misc/bcm2835_cprman: implement clock mux behaviour
In reply to Luc MichelA clock mux can be configured to select one of its 10 sources through the CM_CTL register. It also embeds yet another clock divider, composed of an integer part and a fractional part. The number of bits of each part is mux dependent.
--- hw/misc/bcm2835_cprman.c | 53 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-)
hw/misc/bcm2835_cprman.c +52 -1
@@ -229,19 +229,70 @@ static const TypeInfo cprman_pll_channel_info = { };/* clock mux */ +static bool clock_mux_is_enabled (CprmanClockMuxState *mux) +{ +return FIELD_EX32 (*mux->reg_ctl, CM_CLOCKx_CTL,ENABLE ); +} +static void clock_mux_update (CprmanClockMuxState *mux) { -clock_update (mux->out,0 ); +uint64_t freq; +uint32_t div, src =FIELD_EX32 (*mux->reg_ctl, CM_CLOCKx_CTL,SRC ); +bool enabled =clock_mux_is_enabled (mux); + + *mux->reg_ctl =FIELD_DP32 (*mux->reg_ctl, CM_CLOCKx_CTL,BUSY , enabled); + +if (!enabled) { +clock_update (mux->out,0 ); +return ; + } + + freq =clock_get_hz (mux->srcs[src]); + +if (mux->int_bits ==0 && mux->frac_bits ==0 ) { +clock_update_hz (mux->out, freq); +return ; + } + +/* +* The divider has an integer and a fractional part. The size of each part +* varies with the muxes (int_bits and frac_bits). Both parts are +* concatenated, with the integer part always starting at bit 12. +* +* 31 12 11 0 +* ------------------------------ +* CM_DIV | | int | frac | | +* ------------------------------ +* <-----> <------> +* int_bits frac_bits +*/ + div =extract32 (*mux->reg_div, + R_CM_CLOCKx_DIV_FRAC_LENGTH - mux->frac_bits, + mux->int_bits + mux->frac_bits); + +if (!div) { +clock_update (mux->out,0 ); +return ; + } + + freq =muldiv64 (freq,1 << mux->frac_bits, div); + +clock_update_hz (mux->out, freq); }static void clock_mux_src_update (void *opaque) {CprmanClockMuxState **backref = opaque;CprmanClockMuxState *s = *backref; +CprmanClockMuxSource src = backref - s->backref; + +if (FIELD_EX32 (*s->reg_ctl, CM_CLOCKx_CTL,SRC ) != src) { +return ; + }clock_mux_update (s); }static void clock_mux_init (Object *obj)
Signature · 1 line
2.28.0
Re: [PATCH v3 11/15] hw/misc/bcm2835_cprman: implement clock mux behaviour
Quoted 62 lines · Luc Michel
A clock mux can be configured to select one of its 10 sources through the
CM_CTLregister. It also embeds yet another clock divider, composed of an integer part and a fractional part. The number of bits of each part is mux dependent.Signed-off-by Luc Michel <[email protected]>--- hw/misc/bcm2835_cprman.c | 53 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-)hw/misc/bcm2835_cprman.c +38
-1@@ -229,19 +229,70 @@ static const TypeInfo cprman_pll_channel_info = { };/* clock mux */ +static bool clock_mux_is_enabled (CprmanClockMuxState *mux) +{ +return FIELD_EX32 (*mux->reg_ctl, CM_CLOCKx_CTL,ENABLE ); +} +static void clock_mux_update (CprmanClockMuxState *mux) { -clock_update (mux->out,0 ); +uint64_t freq; +uint32_t div, src =FIELD_EX32 (*mux->reg_ctl, CM_CLOCKx_CTL,SRC ); +bool enabled =clock_mux_is_enabled (mux); + + *mux->reg_ctl =FIELD_DP32 (*mux->reg_ctl, CM_CLOCKx_CTL,BUSY , enabled); + +if (!enabled) { +clock_update (mux->out,0 ); +return ; + } + + freq =clock_get_hz (mux->srcs[src]); + +if (mux->int_bits ==0 && mux->frac_bits ==0 ) { +clock_update_hz (mux->out, freq); +return ; + } + +/* +* The divider has an integer and a fractional part. The size of each part +* varies with the muxes (int_bits and frac_bits). Both parts are +* concatenated, with the integer part always starting at bit 12. +* +* 31 12 11 0 +* ------------------------------ +* CM_DIV | | int | frac | | +* ------------------------------ +* <-----> <------> +* int_bits frac_bits +*/ + div =extract32 (*mux->reg_div, + R_CM_CLOCKx_DIV_FRAC_LENGTH - mux->frac_bits, + mux->int_bits + mux->frac_bits);
hw/misc/bcm2835_cprman.c static const TypeInfo cprman_pll_channel_info = { · line 283
Quoted 10 lines
hw/misc/bcm2835_cprman.c +9
-0+ +if (!div) { +clock_update (mux->out,0 ); +return ; + } + + freq =muldiv64 (freq,1 << mux->frac_bits, div); + +clock_update_hz (mux->out, freq); }
Much nicer now, thanks :)
Quoted 16 lines
hw/misc/bcm2835_cprman.c +5
-0static void clock_mux_src_update (void *opaque) {CprmanClockMuxState **backref = opaque;CprmanClockMuxState *s = *backref; +CprmanClockMuxSource src = backref - s->backref; + +if (FIELD_EX32 (*s->reg_ctl, CM_CLOCKx_CTL,SRC ) != src) { +return ; + }clock_mux_update (s); }static void clock_mux_init (Object *obj)
PATCH v3 12/15 hw/misc/bcm2835_cprman: add the DSI0HSCK multiplexer
In reply to Luc MichelThis simple mux sits between the PLL channels and the DSI0E and DSI0P clock muxes. This mux selects between PLLA-DSI0 and PLLD-DSI0 channel and outputs the selected signal to source number 4 of DSI0E/P clock muxes. It is controlled by the cm_dsi0hsck register.
--- include/hw/misc/bcm2835_cprman.h | 15 +++++ include/hw/misc/bcm2835_cprman_internals.h | 6 ++ hw/misc/bcm2835_cprman.c | 74 +++++++++++++++++++++- 3 files changed, 94 insertions(+), 1 deletion(-)
include/hw/misc/bcm2835_cprman.h +15 -0
@@ -172,20 +172,35 @@ typedef struct CprmanClockMuxState {* source number. */ struct CprmanClockMuxState *backref[CPRMAN_NUM_CLOCK_MUX_SRC ]; } CprmanClockMuxState; +typedef struct CprmanDsi0HsckMuxState { +/*< private >*/ +DeviceState parent_obj; + +/*< public >*/ +CprmanClockMux id; + +uint32_t *reg_cm; + +Clock *plla_in; +Clock *plld_in; +Clock *out; +}CprmanDsi0HsckMuxState ; +struct BCM2835CprmanState {/*< private >*/ SysBusDevice parent_obj;/*< public >*/ MemoryRegion iomem;CprmanPllState plls[CPRMAN_NUM_PLL ];CprmanPllChannelState channels[CPRMAN_NUM_PLL_CHANNEL ];CprmanClockMuxState clock_muxes[CPRMAN_NUM_CLOCK_MUX ]; +CprmanDsi0HsckMuxState dsi0hsck_mux;uint32_t regs[CPRMAN_NUM_REGS ];uint32_t xosc_freq;Clock *xosc;
include/hw/misc/bcm2835_cprman_internals.h +6 -0
@@ -13,17 +13,20 @@#include "hw/misc/bcm2835_cprman.h" #define TYPE_CPRMAN_PLL "bcm2835-cprman-pll"#define TYPE_CPRMAN_PLL_CHANNEL "bcm2835-cprman-pll-channel"#define TYPE_CPRMAN_CLOCK_MUX "bcm2835-cprman-clock-mux" +#define TYPE_CPRMAN_DSI0HSCK_MUX "bcm2835-cprman-dsi0hsck-mux"DECLARE_INSTANCE_CHECKER (CprmanPllState,CPRMAN_PLL , TYPE_CPRMAN_PLL)DECLARE_INSTANCE_CHECKER (CprmanPllChannelState,CPRMAN_PLL_CHANNEL , TYPE_CPRMAN_PLL_CHANNEL)DECLARE_INSTANCE_CHECKER (CprmanClockMuxState,CPRMAN_CLOCK_MUX , TYPE_CPRMAN_CLOCK_MUX) +DECLARE_INSTANCE_CHECKER (CprmanDsi0HsckMuxState,CPRMAN_DSI0HSCK_MUX , +TYPE_CPRMAN_DSI0HSCK_MUX )/* Register map */ /* PLLs */REG32 (CM_PLLA ,0x104 )
@@ -221,10 +224,13 @@ REG32(CM_LOCK, 0x114) FIELD(CM_LOCK, FLOCKD, 11, 1) FIELD(CM_LOCK, FLOCKC, 10, 1) FIELD(CM_LOCK, FLOCKB, 9, 1) FIELD(CM_LOCK, FLOCKA, 8, 1) +REG32(CM_DSI0HSCK, 0x120) +FIELD (CM_DSI0HSCK ,SELPLLD ,0 ,1 ) +/* * This field is common to all registers. Each register write value must match * the CPRMAN_PASSWORD magic value in its 8 MSB. */FIELD (CPRMAN ,PASSWORD ,24 ,8 )
hw/misc/bcm2835_cprman.c +73 -1
142 lines not on this page · raw message
Signature · 1 line
2.28.0
PATCH v3 13/15 hw/misc/bcm2835_cprman: add sane reset values to the registers
In reply to Luc MichelThose reset values have been extracted from a Raspberry Pi 3 model B v1.2, using the 2020-08-20 version of raspios. The dump was done using the debugfs interface of the CPRMAN driver in Linux (under '/sys/kernel/debug/clk'). Each exposed clock tree stage (PLLs, channels and muxes) can be observed by reading the 'regdump' file (e.g. 'plla/regdump').
Those values are set by the Raspberry Pi firmware at boot time (Linux expects them to be set when it boots up).
Some stages are not exposed by the Linux driver (e.g. the PLL B). For those, the reset values are unknown and left to 0 which implies a disabled output.
Once booted in QEMU, the final clock tree is very similar to the one visible on real hardware. The differences come from some unimplemented devices for which the driver simply disable the corresponding clock.
--- include/hw/misc/bcm2835_cprman_internals.h | 269 +++++++++++++++++++++ hw/misc/bcm2835_cprman.c | 31 +++ 2 files changed, 300 insertions(+)
include/hw/misc/bcm2835_cprman_internals.h +269 -0
@@ -745,6 +745,275 @@ static inline void set_clock_mux_init_info(BCM2835CprmanState *s, mux->reg_div = &s->regs[CLOCK_MUX_INIT_INFO [id].cm_offset +1 ]; mux->int_bits =CLOCK_MUX_INIT_INFO [id].int_bits; mux->frac_bits = CLOCK_MUX_INIT_INFO[id].frac_bits; } + +/* +* Object reset info +* Those values have been dumped from a Raspberry Pi 3 Model B v1.2 using the +* clk debugfs interface in Linux. +*/ +typedef struct PLLResetInfo { +uint32_t cm; +uint32_t a2w_ctrl; +uint32_t a2w_ana[4 ]; +uint32_t a2w_frac; +}PLLResetInfo ; + +static const PLLResetInfo PLL_RESET_INFO [] = { + [CPRMAN_PLLA ] = { + .cm =0x0000008a , + .a2w_ctrl =0x0002103a , + .a2w_frac =0x00098000 , + .a2w_ana = {0x00000000 ,0x00144000 ,0x00000000 ,0x00000100 } + }, + + [CPRMAN_PLLC ] = { + .cm =0x00000228 , + .a2w_ctrl =0x0002103e , + .a2w_frac =0x00080000 , + .a2w_ana = {0x00000000 ,0x00144000 ,0x00000000 ,0x00000100 } + }, + + [CPRMAN_PLLD ] = { + .cm =0x0000020a , + .a2w_ctrl =0x00021034 , + .a2w_frac =0x00015556 , + .a2w_ana = {0x00000000 ,0x00144000 ,0x00000000 ,0x00000100 } + }, + + [CPRMAN_PLLH ] = { + .cm =0x00000000 , + .a2w_ctrl =0x0002102d , + .a2w_frac =0x00000000 , + .a2w_ana = {0x00900000 ,0x0000000c ,0x00000000 ,0x00000000 } + }, + + [CPRMAN_PLLB ] = { +/* unknown */ + .cm =0x00000000 , + .a2w_ctrl =0x00000000 , + .a2w_frac =0x00000000 , + .a2w_ana = {0x00000000 ,0x00000000 ,0x00000000 ,0x00000000 } + } +}; + +typedef struct PLLChannelResetInfo { +/* +* Even though a PLL channel has a CM register, it shares it with its +* parent PLL. The parent already takes care of the reset value. +*/ +uint32_t a2w_ctrl; +}PLLChannelResetInfo ; + +static const PLLChannelResetInfo PLL_CHANNEL_RESET_INFO [] = { + [CPRMAN_PLLA_CHANNEL_DSI0 ] = { .a2w_ctrl =0x00000100 }, + [CPRMAN_PLLA_CHANNEL_CORE ] = { .a2w_ctrl =0x00000003 }, + [CPRMAN_PLLA_CHANNEL_PER ] = { .a2w_ctrl =0x00000000 },/* unknown */ + [CPRMAN_PLLA_CHANNEL_CCP2 ] = { .a2w_ctrl =0x00000100 }, + + [CPRMAN_PLLC_CHANNEL_CORE2 ] = { .a2w_ctrl =0x00000100 }, + [CPRMAN_PLLC_CHANNEL_CORE1 ] = { .a2w_ctrl =0x00000100 }, + [CPRMAN_PLLC_CHANNEL_PER ] = { .a2w_ctrl =0x00000002 }, + [CPRMAN_PLLC_CHANNEL_CORE0 ] = { .a2w_ctrl =0x00000002 }, + + [CPRMAN_PLLD_CHANNEL_DSI0 ] = { .a2w_ctrl =0x00000100 }, + [CPRMAN_PLLD_CHANNEL_CORE ] = { .a2w_ctrl =0x00000004 }, + [CPRMAN_PLLD_CHANNEL_PER ] = { .a2w_ctrl =0x00000004 }, + [CPRMAN_PLLD_CHANNEL_DSI1 ] = { .a2w_ctrl =0x00000100 }, + + [CPRMAN_PLLH_CHANNEL_AUX ] = { .a2w_ctrl =0x00000004 }, + [CPRMAN_PLLH_CHANNEL_RCAL ] = { .a2w_ctrl =0x00000000 }, + [CPRMAN_PLLH_CHANNEL_PIX ] = { .a2w_ctrl =0x00000000 }, + + [CPRMAN_PLLB_CHANNEL_ARM ] = { .a2w_ctrl =0x00000000 },/* unknown */ +}; + +typedef struct ClockMuxResetInfo { +uint32_t cm_ctl; +uint32_t cm_div; +}ClockMuxResetInfo ; + +static const ClockMuxResetInfo CLOCK_MUX_RESET_INFO [] = { + [CPRMAN_CLOCK_GNRIC ] = { + .cm_ctl =0 ,/* unknown */ + .cm_div =0 + }, + + [CPRMAN_CLOCK_VPU ] = { + .cm_ctl =0x00000245 , + .cm_div =0x00003000 , + }, + + [CPRMAN_CLOCK_SYS ] = { + .cm_ctl =0 ,/* unknown */ + .cm_div =0 + }, + + [CPRMAN_CLOCK_PERIA ] = { + .cm_ctl =0 ,/* unknown */ + .cm_div =0 + }, + + [CPRMAN_CLOCK_PERII ] = { + .cm_ctl =0 ,/* unknown */ + .cm_div =0 + }, + + [CPRMAN_CLOCK_H264 ] = { + .cm_ctl =0x00000244 , + .cm_div =0x00003000 , + }, + + [CPRMAN_CLOCK_ISP ] = { + .cm_ctl =0x00000244 , + .cm_div =0x00003000 , + }, + + [CPRMAN_CLOCK_V3D ] = { + .cm_ctl =0 ,/* unknown */ + .cm_div =0 + }, + + [CPRMAN_CLOCK_CAM0 ] = { + .cm_ctl =0x00000000 , + .cm_div =0x00000000 , + }, + + [CPRMAN_CLOCK_CAM1 ] = { + .cm_ctl =0x00000000 , + .cm_div =0x00000000 , + }, + + [CPRMAN_CLOCK_CCP2 ] = { + .cm_ctl =0 ,/* unknown */ + .cm_div =0 + }, + + [CPRMAN_CLOCK_DSI0E ] = { + .cm_ctl =0x00000000 , + .cm_div =0x00000000 , + }, + + [CPRMAN_CLOCK_DSI0P ] = { + .cm_ctl =0x00000000 , + .cm_div =0x00000000 , + }, + + [CPRMAN_CLOCK_DPI ] = { + .cm_ctl =0x00000000 , + .cm_div =0x00000000 , + }, + + [CPRMAN_CLOCK_GP0 ] = { + .cm_ctl =0x00000200 , + .cm_div =0x00000000 , + }, + + [CPRMAN_CLOCK_GP1 ] = { + .cm_ctl =0x00000096 , + .cm_div =0x00014000 , + }, + + [CPRMAN_CLOCK_GP2 ] = { + .cm_ctl =0x00000291 , + .cm_div =0x00249f00 , + }, + + [CPRMAN_CLOCK_HSM ] = { + .cm_ctl =0x00000000 , + .cm_div =0x00000000 , + }, + + [CPRMAN_CLOCK_OTP ] = { + .cm_ctl =0x00000091 , + .cm_div =0x00004000 , + }, + + [CPRMAN_CLOCK_PCM ] = { + .cm_ctl =0x00000200 , + .cm_div =0x00000000 , + }, + + [CPRMAN_CLOCK_PWM ] = { + .cm_ctl =0x00000200 , + .cm_div =0x00000000 , + }, + + [CPRMAN_CLOCK_SLIM ] = { + .cm_ctl =0x00000200 , + .cm_div =0x00000000 , + }, + + [CPRMAN_CLOCK_SMI ] = { + .cm_ctl =0x00000000 , + .cm_div =0x00000000 , + }, + + [CPRMAN_CLOCK_TEC ] = { + .cm_ctl =0x00000000 , + .cm_div =0x00000000 , + }, + + [CPRMAN_CLOCK_TD0 ] = { + .cm_ctl =0 ,/* unknown */ + .cm_div =0 + }, + + [CPRMAN_CLOCK_TD1 ] = { + .cm_ctl =0 ,/* unknown */ + .cm_div =0 + }, + + [CPRMAN_CLOCK_TSENS ] = { + .cm_ctl =0x00000091 , + .cm_div =0x0000a000 , + }, + + [CPRMAN_CLOCK_TIMER ] = { + .cm_ctl =0x00000291 , + .cm_div =0x00013333 , + }, + + [CPRMAN_CLOCK_UART ] = { + .cm_ctl =0x00000296 , + .cm_div =0x0000a6ab , + }, + + [CPRMAN_CLOCK_VEC ] = { + .cm_ctl =0x00000097 , + .cm_div =0x00002000 , + }, + + [CPRMAN_CLOCK_PULSE ] = { + .cm_ctl =0 ,/* unknown */ + .cm_div =0 + }, + + [CPRMAN_CLOCK_SDC ] = { + .cm_ctl =0x00004006 , + .cm_div =0x00003000 , + }, + + [CPRMAN_CLOCK_ARM ] = { + .cm_ctl =0 ,/* unknown */ + .cm_div =0 + }, + + [CPRMAN_CLOCK_AVEO ] = { + .cm_ctl =0x00000000 , + .cm_div =0x00000000 , + }, + + [CPRMAN_CLOCK_EMMC ] = { + .cm_ctl =0x00000295 , + .cm_div =0x00006000 , + }, + + [CPRMAN_CLOCK_EMMC2 ] = { + .cm_ctl =0 ,/* unknown */ + .cm_div =0 + }, +}; +#endif
hw/misc/bcm2835_cprman.c +31 -0
@@ -51,10 +51,21 @@#include "hw/misc/bcm2835_cprman_internals.h" #include "trace.h" /* PLL */ +static void pll_reset (DeviceState *dev) +{ +CprmanPllState *s =CPRMAN_PLL (dev); +const PLLResetInfo *info = &PLL_RESET_INFO [s->id]; + + *s->reg_cm = info->cm; + *s->reg_a2w_ctrl = info->a2w_ctrl; +memcpy (s->reg_a2w_ana, info->a2w_ana,sizeof (info->a2w_ana)); + *s->reg_a2w_frac = info->a2w_frac; +} +static bool pll_is_locked (const CprmanPllState *pll) {return !FIELD_EX32 (*pll->reg_a2w_ctrl, A2W_PLLx_CTRL,PWRDN ) && !FIELD_EX32 (*pll->reg_cm, CM_PLLx,ANARST ); }
@@ -121,10 +132,11 @@ static const VMStateDescription pll_vmstate = {static void pll_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass); + dc->reset = pll_reset; dc->vmsd = &pll_vmstate; }static const TypeInfo cprman_pll_info = { .name =TYPE_CPRMAN_PLL ,
@@ -135,10 +147,18 @@ static const TypeInfo cprman_pll_info = { };/* PLL channel */ +static void pll_channel_reset (DeviceState *dev) +{ +CprmanPllChannelState *s =CPRMAN_PLL_CHANNEL (dev); +const PLLChannelResetInfo *info = &PLL_CHANNEL_RESET_INFO [s->id]; + + *s->reg_a2w_ctrl = info->a2w_ctrl; +} +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
@@ -215,10 +235,11 @@ static const VMStateDescription pll_channel_vmstate = {static void pll_channel_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass); + dc->reset = pll_channel_reset; dc->vmsd = &pll_channel_vmstate; }static const TypeInfo cprman_pll_channel_info = { .name =TYPE_CPRMAN_PLL_CHANNEL ,
@@ -293,10 +314,19 @@ static void clock_mux_src_update(void *opaque) }clock_mux_update (s); } +static void clock_mux_reset (DeviceState *dev) +{ +CprmanClockMuxState *clock =CPRMAN_CLOCK_MUX (dev); +const ClockMuxResetInfo *info = &CLOCK_MUX_RESET_INFO [clock->id]; + + *clock->reg_ctl = info->cm_ctl; + *clock->reg_div = info->cm_div; +} +static void clock_mux_init (Object *obj) {CprmanClockMuxState *s =CPRMAN_CLOCK_MUX (obj);size_t i;
@@ -325,10 +355,11 @@ static const VMStateDescription clock_mux_vmstate = {static void clock_mux_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass); + dc->reset = clock_mux_reset; dc->vmsd = &clock_mux_vmstate; }static const TypeInfo cprman_clock_mux_info = { .name =TYPE_CPRMAN_CLOCK_MUX ,
Signature · 1 line
2.28.0
Re: [PATCH v3 13/15] hw/misc/bcm2835_cprman: add sane reset values to the registers
Quoted 128 lines · Luc Michel
Those reset values have been extracted from a Raspberry Pi 3 model B v1.2, using the 2020-08-20 version of raspios. The dump was done using the debugfs interface of the CPRMAN driver in Linux (under '
/sys/kernel/debug/clk'). Each exposed clock tree stage (PLLs, channels and muxes) can be observed by reading the 'regdump' file (e.g. 'plla/regdump').Those values are set by the Raspberry Pi firmware at boot time (Linux expects them to be set when it boots up).
Some stages are not exposed by the Linux driver (e.g. the PLL B). For those, the reset values are unknown and left to 0 which implies a disabled output.
Once booted in QEMU, the final clock tree is very similar to the one visible on real hardware. The differences come from some unimplemented devices for which the driver simply disable the corresponding clock.
Signed-off-by Luc Michel <[email protected]>--- include/hw/misc/bcm2835_cprman_internals.h | 269 +++++++++++++++++++++ hw/misc/bcm2835_cprman.c | 31 +++ 2 files changed, 300 insertions(+)include/hw/misc/bcm2835_cprman_internals.h +93
-0@@ -745,6 +745,275 @@ static inline void set_clock_mux_init_info(BCM2835CprmanState *s, mux->reg_div = &s->regs[CLOCK_MUX_INIT_INFO [id].cm_offset +1 ]; mux->int_bits =CLOCK_MUX_INIT_INFO [id].int_bits; mux->frac_bits =CLOCK_MUX_INIT_INFO [id].frac_bits; } + +/* +* Object reset info +* Those values have been dumped from a Raspberry Pi 3 Model B v1.2 using the +* clk debugfs interface in Linux. +*/ +typedef struct PLLResetInfo { +uint32_t cm; +uint32_t a2w_ctrl; +uint32_t a2w_ana[4 ]; +uint32_t a2w_frac; +}PLLResetInfo ; + +static const PLLResetInfo PLL_RESET_INFO [] = { + [CPRMAN_PLLA ] = { + .cm =0x0000008a , + .a2w_ctrl =0x0002103a , + .a2w_frac =0x00098000 , + .a2w_ana = {0x00000000 ,0x00144000 ,0x00000000 ,0x00000100 } + }, + + [CPRMAN_PLLC ] = { + .cm =0x00000228 , + .a2w_ctrl =0x0002103e , + .a2w_frac =0x00080000 , + .a2w_ana = {0x00000000 ,0x00144000 ,0x00000000 ,0x00000100 } + }, + + [CPRMAN_PLLD ] = { + .cm =0x0000020a , + .a2w_ctrl =0x00021034 , + .a2w_frac =0x00015556 , + .a2w_ana = {0x00000000 ,0x00144000 ,0x00000000 ,0x00000100 } + }, + + [CPRMAN_PLLH ] = { + .cm =0x00000000 , + .a2w_ctrl =0x0002102d , + .a2w_frac =0x00000000 , + .a2w_ana = {0x00900000 ,0x0000000c ,0x00000000 ,0x00000000 } + }, + + [CPRMAN_PLLB ] = { +/* unknown */ + .cm =0x00000000 , + .a2w_ctrl =0x00000000 , + .a2w_frac =0x00000000 , + .a2w_ana = {0x00000000 ,0x00000000 ,0x00000000 ,0x00000000 } + } +}; + +typedef struct PLLChannelResetInfo { +/* +* Even though a PLL channel has a CM register, it shares it with its +* parent PLL. The parent already takes care of the reset value. +*/ +uint32_t a2w_ctrl; +}PLLChannelResetInfo ; + +static const PLLChannelResetInfo PLL_CHANNEL_RESET_INFO [] = { + [CPRMAN_PLLA_CHANNEL_DSI0 ] = { .a2w_ctrl =0x00000100 }, + [CPRMAN_PLLA_CHANNEL_CORE ] = { .a2w_ctrl =0x00000003 }, + [CPRMAN_PLLA_CHANNEL_PER ] = { .a2w_ctrl =0x00000000 },/* unknown */ + [CPRMAN_PLLA_CHANNEL_CCP2 ] = { .a2w_ctrl =0x00000100 }, + + [CPRMAN_PLLC_CHANNEL_CORE2 ] = { .a2w_ctrl =0x00000100 }, + [CPRMAN_PLLC_CHANNEL_CORE1 ] = { .a2w_ctrl =0x00000100 }, + [CPRMAN_PLLC_CHANNEL_PER ] = { .a2w_ctrl =0x00000002 }, + [CPRMAN_PLLC_CHANNEL_CORE0 ] = { .a2w_ctrl =0x00000002 }, + + [CPRMAN_PLLD_CHANNEL_DSI0 ] = { .a2w_ctrl =0x00000100 }, + [CPRMAN_PLLD_CHANNEL_CORE ] = { .a2w_ctrl =0x00000004 }, + [CPRMAN_PLLD_CHANNEL_PER ] = { .a2w_ctrl =0x00000004 }, + [CPRMAN_PLLD_CHANNEL_DSI1 ] = { .a2w_ctrl =0x00000100 }, + + [CPRMAN_PLLH_CHANNEL_AUX ] = { .a2w_ctrl =0x00000004 }, + [CPRMAN_PLLH_CHANNEL_RCAL ] = { .a2w_ctrl =0x00000000 }, + [CPRMAN_PLLH_CHANNEL_PIX ] = { .a2w_ctrl =0x00000000 }, + + [CPRMAN_PLLB_CHANNEL_ARM ] = { .a2w_ctrl =0x00000000 },/* unknown */ +}; + +typedef struct ClockMuxResetInfo { +uint32_t cm_ctl; +uint32_t cm_div; +}ClockMuxResetInfo ; + +static const ClockMuxResetInfo CLOCK_MUX_RESET_INFO [] = { + [CPRMAN_CLOCK_GNRIC ] = { + .cm_ctl =0 ,/* unknown */ + .cm_div =0 + }, +
[...]
Quoted 8 lines
include/hw/misc/bcm2835_cprman_internals.h +2
-0+}; +#endif hw/misc/bcm2835_cprman.c +0
-0
hw/misc/bcm2835_cprman.c line 59
Quoted 9 lines
hw/misc/bcm2835_cprman.c +4
-0@@ -51,10 +51,21 @@#include "hw/misc/bcm2835_cprman_internals.h" #include "trace.h" /* PLL */ +static void pll_reset (DeviceState *dev) +{ +CprmanPllState *s =CPRMAN_PLL (dev); +const PLLResetInfo *info = &PLL_RESET_INFO [s->id];
Hmm so we overwrite various values from PLL_INIT_INFO.
hw/misc/bcm2835_cprman.c line 64
Quoted 5 lines
hw/misc/bcm2835_cprman.c +5
-0+ + *s->reg_cm = info->cm; + *s->reg_a2w_ctrl = info->a2w_ctrl; +memcpy (s->reg_a2w_ana, info->a2w_ana,sizeof (info->a2w_ana)); + *s->reg_a2w_frac = info->a2w_frac;
set_pll_init_info() can be simplified as:
pll->id = id;
pll->prediv_mask = PLL_INIT_INFO[id].prediv_mask;Or directly in cprman_init():
&s->plls[i]->id = i;
&s->plls[i]->prediv_mask = PLL_INIT_INFO[i].prediv_mask;And the rest directly implemented in pll_reset().
Maybe not, but having pll_reset() added in patch #8/15 "bcm2835_cprman: add a PLL channel skeleton implementation" would make this patch review easier ;)
Quoted 8 lines
hw/misc/bcm2835_cprman.c +2
-0+} +static bool pll_is_locked (const CprmanPllState *pll) {return !FIELD_EX32 (*pll->reg_a2w_ctrl, A2W_PLLx_CTRL,PWRDN ) && !FIELD_EX32 (*pll->reg_cm, CM_PLLx,ANARST ); }
hw/misc/bcm2835_cprman.c static const VMStateDescription pll_vmstate = { · line 139
Quoted 8 lines
hw/misc/bcm2835_cprman.c +1
-0@@ -121,10 +132,11 @@ static const VMStateDescription pll_vmstate = {static void pll_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass); + dc->reset = pll_reset; dc->vmsd = &pll_vmstate; }
[...]
Similarly, implement clock_mux_reset() in patch #10/15 "bcm2835_cprman: add a clock mux skeleton implementation".
Regards,
Phil.
Re: [PATCH v3 13/15] hw/misc/bcm2835_cprman: add sane reset values to the registers
Quoted 159 lines · Philippe Mathieu-Daudé
Quoted 127 lines · Luc Michel
Those reset values have been extracted from a Raspberry Pi 3 model B v1.2, using the 2020-08-20 version of raspios. The dump was done using the debugfs interface of the CPRMAN driver in Linux (under '
/sys/kernel/debug/clk'). Each exposed clock tree stage (PLLs, channels and muxes) can be observed by reading the 'regdump' file (e.g. 'plla/regdump').Those values are set by the Raspberry Pi firmware at boot time (Linux expects them to be set when it boots up).
Some stages are not exposed by the Linux driver (e.g. the PLL B). For those, the reset values are unknown and left to 0 which implies a disabled output.
Once booted in QEMU, the final clock tree is very similar to the one visible on real hardware. The differences come from some unimplemented devices for which the driver simply disable the corresponding clock.
Signed-off-by Luc Michel <[email protected]>--- include/hw/misc/bcm2835_cprman_internals.h | 269 +++++++++++++++++++++ hw/misc/bcm2835_cprman.c | 31 +++ 2 files changed, 300 insertions(+)include/hw/misc/bcm2835_cprman_internals.h +93
-0@@ -745,6 +745,275 @@ static inline void set_clock_mux_init_info(BCM2835CprmanState *s, mux->reg_div = &s->regs[CLOCK_MUX_INIT_INFO [id].cm_offset +1 ]; mux->int_bits =CLOCK_MUX_INIT_INFO [id].int_bits; mux->frac_bits =CLOCK_MUX_INIT_INFO [id].frac_bits; } + +/* +* Object reset info +* Those values have been dumped from a Raspberry Pi 3 Model B v1.2 using the +* clk debugfs interface in Linux. +*/ +typedef struct PLLResetInfo { +uint32_t cm; +uint32_t a2w_ctrl; +uint32_t a2w_ana[4 ]; +uint32_t a2w_frac; +}PLLResetInfo ; + +static const PLLResetInfo PLL_RESET_INFO [] = { + [CPRMAN_PLLA ] = { + .cm =0x0000008a , + .a2w_ctrl =0x0002103a , + .a2w_frac =0x00098000 , + .a2w_ana = {0x00000000 ,0x00144000 ,0x00000000 ,0x00000100 } + }, + + [CPRMAN_PLLC ] = { + .cm =0x00000228 , + .a2w_ctrl =0x0002103e , + .a2w_frac =0x00080000 , + .a2w_ana = {0x00000000 ,0x00144000 ,0x00000000 ,0x00000100 } + }, + + [CPRMAN_PLLD ] = { + .cm =0x0000020a , + .a2w_ctrl =0x00021034 , + .a2w_frac =0x00015556 , + .a2w_ana = {0x00000000 ,0x00144000 ,0x00000000 ,0x00000100 } + }, + + [CPRMAN_PLLH ] = { + .cm =0x00000000 , + .a2w_ctrl =0x0002102d , + .a2w_frac =0x00000000 , + .a2w_ana = {0x00900000 ,0x0000000c ,0x00000000 ,0x00000000 } + }, + + [CPRMAN_PLLB ] = { +/* unknown */ + .cm =0x00000000 , + .a2w_ctrl =0x00000000 , + .a2w_frac =0x00000000 , + .a2w_ana = {0x00000000 ,0x00000000 ,0x00000000 ,0x00000000 } + } +}; + +typedef struct PLLChannelResetInfo { +/* +* Even though a PLL channel has a CM register, it shares it with its +* parent PLL. The parent already takes care of the reset value. +*/ +uint32_t a2w_ctrl; +}PLLChannelResetInfo ; + +static const PLLChannelResetInfo PLL_CHANNEL_RESET_INFO [] = { + [CPRMAN_PLLA_CHANNEL_DSI0 ] = { .a2w_ctrl =0x00000100 }, + [CPRMAN_PLLA_CHANNEL_CORE ] = { .a2w_ctrl =0x00000003 }, + [CPRMAN_PLLA_CHANNEL_PER ] = { .a2w_ctrl =0x00000000 },/* unknown */ + [CPRMAN_PLLA_CHANNEL_CCP2 ] = { .a2w_ctrl =0x00000100 }, + + [CPRMAN_PLLC_CHANNEL_CORE2 ] = { .a2w_ctrl =0x00000100 }, + [CPRMAN_PLLC_CHANNEL_CORE1 ] = { .a2w_ctrl =0x00000100 }, + [CPRMAN_PLLC_CHANNEL_PER ] = { .a2w_ctrl =0x00000002 }, + [CPRMAN_PLLC_CHANNEL_CORE0 ] = { .a2w_ctrl =0x00000002 }, + + [CPRMAN_PLLD_CHANNEL_DSI0 ] = { .a2w_ctrl =0x00000100 }, + [CPRMAN_PLLD_CHANNEL_CORE ] = { .a2w_ctrl =0x00000004 }, + [CPRMAN_PLLD_CHANNEL_PER ] = { .a2w_ctrl =0x00000004 }, + [CPRMAN_PLLD_CHANNEL_DSI1 ] = { .a2w_ctrl =0x00000100 }, + + [CPRMAN_PLLH_CHANNEL_AUX ] = { .a2w_ctrl =0x00000004 }, + [CPRMAN_PLLH_CHANNEL_RCAL ] = { .a2w_ctrl =0x00000000 }, + [CPRMAN_PLLH_CHANNEL_PIX ] = { .a2w_ctrl =0x00000000 }, + + [CPRMAN_PLLB_CHANNEL_ARM ] = { .a2w_ctrl =0x00000000 },/* unknown */ +}; + +typedef struct ClockMuxResetInfo { +uint32_t cm_ctl; +uint32_t cm_div; +}ClockMuxResetInfo ; + +static const ClockMuxResetInfo CLOCK_MUX_RESET_INFO [] = { + [CPRMAN_CLOCK_GNRIC ] = { + .cm_ctl =0 ,/* unknown */ + .cm_div =0 + }, +[...]
Quoted 8 lines
include/hw/misc/bcm2835_cprman_internals.h +2
-0+}; +#endif hw/misc/bcm2835_cprman.c +0
-0hw/misc/bcm2835_cprman.c line 57
Quoted 7 lines
hw/misc/bcm2835_cprman.c +4
-0@@ -51,10 +51,21 @@#include "hw/misc/bcm2835_cprman_internals.h" #include "trace.h" /* PLL */ +static void pll_reset (DeviceState *dev) +{ +CprmanPllState *s =CPRMAN_PLL (dev); +const PLLResetInfo *info = &PLL_RESET_INFO [s->id];Hmm so we overwrite various values from
PLL_INIT_INFO.hw/misc/bcm2835_cprman.c line 64
Quoted 5 lines
hw/misc/bcm2835_cprman.c +5
-0+ + *s->reg_cm = info->cm; + *s->reg_a2w_ctrl = info->a2w_ctrl; +memcpy (s->reg_a2w_ana, info->a2w_ana,sizeof (info->a2w_ana)); + *s->reg_a2w_frac = info->a2w_frac;
set_pll_init_info()can be simplified as:pll->id = id; pll->prediv_mask = PLL_INIT_INFO[id].prediv_mask;Or directly in
cprman_init():
Quoted 8 lines
&s->plls[i]->id = i; &s->plls[i]->prediv_mask = PLL_INIT_INFO[i].prediv_mask;And the rest directly implemented in
pll_reset().Maybe not, but having
pll_reset()added in patch #8/15 "bcm2835_cprman: add a PLL channel skeleton implementation" would make this patch review easier ;)
Hi Phil,
I think there is a misunderstanding here:
- set_xxx_init_info functions set (among others) register pointers to alias the common register array "regs" in BCM2835CprmanState. This is really an initialization step (in the sense of the QOM object). Those pointers won't move during the object's lifetime.
- xxx_reset however (like e.g. xxx_update) _dereferences_ those pointers to access the registers data (in this case to set their reset values).
Doing so greatly decreases code complexity because:
- read/write functions can directly access the common "regs" array without further decoding.
- Each PLL shares a register with all its channels (A2W_CTRL). With this scheme, they simply all have a pointer aliasing the same data.
- A lot a registers are unknown/unimplemented.
Thanks !
Signature · 1 line
Luc
Quoted 22 lines
Quoted 9 lines
hw/misc/bcm2835_cprman.c +2
-0+} +static bool pll_is_locked (const CprmanPllState *pll) {return !FIELD_EX32 (*pll->reg_a2w_ctrl, A2W_PLLx_CTRL,PWRDN ) && !FIELD_EX32 (*pll->reg_cm, CM_PLLx,ANARST ); }hw/misc/bcm2835_cprman.c static const VMStateDescription pll_vmstate = { · line 137
Quoted 6 lines
hw/misc/bcm2835_cprman.c +1
-0@@ -121,10 +132,11 @@ static const VMStateDescription pll_vmstate = {static void pll_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass); + dc->reset = pll_reset; dc->vmsd = &pll_vmstate; }[...]
Similarly, implementclock_mux_reset()in patch #10/15 "bcm2835_cprman: add a clock mux skeleton implementation".Regards,
Phil.
Re: [PATCH v3 13/15] hw/misc/bcm2835_cprman: add sane reset values to the registers
Quoted 180 lines · Luc Michel
Quoted 159 lines · Philippe Mathieu-Daudé
Quoted 127 lines · Luc Michel
Those reset values have been extracted from a Raspberry Pi 3 model B v1.2, using the 2020-08-20 version of raspios. The dump was done using the debugfs interface of the CPRMAN driver in Linux (under '
/sys/kernel/debug/clk'). Each exposed clock tree stage (PLLs, channels and muxes) can be observed by reading the 'regdump' file (e.g. 'plla/regdump').Those values are set by the Raspberry Pi firmware at boot time (Linux expects them to be set when it boots up).
Some stages are not exposed by the Linux driver (e.g. the PLL B). For those, the reset values are unknown and left to 0 which implies a disabled output.
Once booted in QEMU, the final clock tree is very similar to the one visible on real hardware. The differences come from some unimplemented devices for which the driver simply disable the corresponding clock.
Signed-off-by Luc Michel <[email protected]>--- include/hw/misc/bcm2835_cprman_internals.h | 269 +++++++++++++++++++++ hw/misc/bcm2835_cprman.c | 31 +++ 2 files changed, 300 insertions(+)include/hw/misc/bcm2835_cprman_internals.h +93
-0@@ -745,6 +745,275 @@ static inline void set_clock_mux_init_info(BCM2835CprmanState *s, mux->reg_div = &s->regs[CLOCK_MUX_INIT_INFO [id].cm_offset +1 ]; mux->int_bits =CLOCK_MUX_INIT_INFO [id].int_bits; mux->frac_bits =CLOCK_MUX_INIT_INFO [id].frac_bits; } + +/* +* Object reset info +* Those values have been dumped from a Raspberry Pi 3 Model B v1.2 using the +* clk debugfs interface in Linux. +*/ +typedef struct PLLResetInfo { +uint32_t cm; +uint32_t a2w_ctrl; +uint32_t a2w_ana[4 ]; +uint32_t a2w_frac; +}PLLResetInfo ; + +static const PLLResetInfo PLL_RESET_INFO [] = { + [CPRMAN_PLLA ] = { + .cm =0x0000008a , + .a2w_ctrl =0x0002103a , + .a2w_frac =0x00098000 , + .a2w_ana = {0x00000000 ,0x00144000 ,0x00000000 ,0x00000100 } + }, + + [CPRMAN_PLLC ] = { + .cm =0x00000228 , + .a2w_ctrl =0x0002103e , + .a2w_frac =0x00080000 , + .a2w_ana = {0x00000000 ,0x00144000 ,0x00000000 ,0x00000100 } + }, + + [CPRMAN_PLLD ] = { + .cm =0x0000020a , + .a2w_ctrl =0x00021034 , + .a2w_frac =0x00015556 , + .a2w_ana = {0x00000000 ,0x00144000 ,0x00000000 ,0x00000100 } + }, + + [CPRMAN_PLLH ] = { + .cm =0x00000000 , + .a2w_ctrl =0x0002102d , + .a2w_frac =0x00000000 , + .a2w_ana = {0x00900000 ,0x0000000c ,0x00000000 ,0x00000000 } + }, + + [CPRMAN_PLLB ] = { +/* unknown */ + .cm =0x00000000 , + .a2w_ctrl =0x00000000 , + .a2w_frac =0x00000000 , + .a2w_ana = {0x00000000 ,0x00000000 ,0x00000000 ,0x00000000 } + } +}; + +typedef struct PLLChannelResetInfo { +/* +* Even though a PLL channel has a CM register, it shares it with its +* parent PLL. The parent already takes care of the reset value. +*/ +uint32_t a2w_ctrl; +}PLLChannelResetInfo ; + +static const PLLChannelResetInfo PLL_CHANNEL_RESET_INFO [] = { + [CPRMAN_PLLA_CHANNEL_DSI0 ] = { .a2w_ctrl =0x00000100 }, + [CPRMAN_PLLA_CHANNEL_CORE ] = { .a2w_ctrl =0x00000003 }, + [CPRMAN_PLLA_CHANNEL_PER ] = { .a2w_ctrl =0x00000000 },/* unknown */ + [CPRMAN_PLLA_CHANNEL_CCP2 ] = { .a2w_ctrl =0x00000100 }, + + [CPRMAN_PLLC_CHANNEL_CORE2 ] = { .a2w_ctrl =0x00000100 }, + [CPRMAN_PLLC_CHANNEL_CORE1 ] = { .a2w_ctrl =0x00000100 }, + [CPRMAN_PLLC_CHANNEL_PER ] = { .a2w_ctrl =0x00000002 }, + [CPRMAN_PLLC_CHANNEL_CORE0 ] = { .a2w_ctrl =0x00000002 }, + + [CPRMAN_PLLD_CHANNEL_DSI0 ] = { .a2w_ctrl =0x00000100 }, + [CPRMAN_PLLD_CHANNEL_CORE ] = { .a2w_ctrl =0x00000004 }, + [CPRMAN_PLLD_CHANNEL_PER ] = { .a2w_ctrl =0x00000004 }, + [CPRMAN_PLLD_CHANNEL_DSI1 ] = { .a2w_ctrl =0x00000100 }, + + [CPRMAN_PLLH_CHANNEL_AUX ] = { .a2w_ctrl =0x00000004 }, + [CPRMAN_PLLH_CHANNEL_RCAL ] = { .a2w_ctrl =0x00000000 }, + [CPRMAN_PLLH_CHANNEL_PIX ] = { .a2w_ctrl =0x00000000 }, + + [CPRMAN_PLLB_CHANNEL_ARM ] = { .a2w_ctrl =0x00000000 },/* unknown */ +}; + +typedef struct ClockMuxResetInfo { +uint32_t cm_ctl; +uint32_t cm_div; +}ClockMuxResetInfo ; + +static const ClockMuxResetInfo CLOCK_MUX_RESET_INFO [] = { + [CPRMAN_CLOCK_GNRIC ] = { + .cm_ctl =0 ,/* unknown */ + .cm_div =0 + }, +[...]
Quoted 8 lines
include/hw/misc/bcm2835_cprman_internals.h +2
-0+}; +#endif hw/misc/bcm2835_cprman.c +0
-0hw/misc/bcm2835_cprman.c line 57
Quoted 7 lines
hw/misc/bcm2835_cprman.c +4
-0@@ -51,10 +51,21 @@#include "hw/misc/bcm2835_cprman_internals.h" #include "trace.h" /* PLL */ +static void pll_reset (DeviceState *dev) +{ +CprmanPllState *s =CPRMAN_PLL (dev); +const PLLResetInfo *info = &PLL_RESET_INFO [s->id];Hmm so we overwrite various values from
PLL_INIT_INFO.hw/misc/bcm2835_cprman.c line 64
Quoted 5 lines
hw/misc/bcm2835_cprman.c +5
-0+ + *s->reg_cm = info->cm; + *s->reg_a2w_ctrl = info->a2w_ctrl; +memcpy (s->reg_a2w_ana, info->a2w_ana,sizeof (info->a2w_ana)); + *s->reg_a2w_frac = info->a2w_frac;
set_pll_init_info()can be simplified as:pll->id = id; pll->prediv_mask = PLL_INIT_INFO[id].prediv_mask;Or directly in
cprman_init():Quoted 8 lines
&s->plls[i]->id = i; &s->plls[i]->prediv_mask = PLL_INIT_INFO[i].prediv_mask;And the rest directly implemented in
pll_reset().Maybe not, but having
pll_reset()added in patch #8/15 "bcm2835_cprman: add a PLL channel skeleton implementation" would make this patch review easier ;)Hi Phil,
I think there is a misunderstanding here:
-set_xxx_init_infofunctions set (among others) register pointers to alias the common register array "regs" in BCM2835CprmanState. This is really an initialization step (in the sense of the QOM object). Those pointers won't move during the object's lifetime.
-xxx_resethowever (like e.g.xxx_update) _dereferences_ those pointers to access the registers data (in this case to set their reset values).
Quoted 6 lines
Doing so greatly decreases code complexity because:
- read/write functions can directly access the common "regs" array without further decoding.
- Each PLL shares a register with all its channels (A2W_CTRL). With this scheme, they simply all have a pointer aliasing the same data.
- A lot a registers are unknown/unimplemented.
OK, thanks for clarifying.
(I wanted to split the boilerplate code from the dumped constants).
Philippe Mathieu-Daudé
Reviewed-byRe: [PATCH v3 13/15] hw/misc/bcm2835_cprman: add sane reset values to the registers
Quoted 21 lines · Philippe Mathieu-Daudé
Quoted 20 lines · Luc Michel
Quoted 19 lines · Philippe Mathieu-Daudé
Quoted 18 lines · Luc Michel
Those reset values have been extracted from a Raspberry Pi 3 model B v1.2, using the 2020-08-20 version of raspios. The dump was done using the debugfs interface of the CPRMAN driver in Linux (under '
/sys/kernel/debug/clk'). Each exposed clock tree stage (PLLs, channels and muxes) can be observed by reading the 'regdump' file (e.g. 'plla/regdump').Those values are set by the Raspberry Pi firmware at boot time (Linux expects them to be set when it boots up).
Some stages are not exposed by the Linux driver (e.g. the PLL B). For those, the reset values are unknown and left to 0 which implies a disabled output.
Once booted in QEMU, the final clock tree is very similar to the one visible on real hardware. The differences come from some unimplemented devices for which the driver simply disable the corresponding clock.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Signed-off-by Luc Michel <[email protected]>---
include/hw/misc/bcm2835_cprman_internals.h| 269
+++++++++++++++++++++
hw/misc/bcm2835_cprman.c | 31 +++2 files changed, 300 insertions(+)
[...]
I haven't verified the dumped values with real hardware, but for the rest this patch shouldn't introduce regression, and it helps to boot up to Linux kernel 5.7, so:
PATCH v3 14/15 hw/char/pl011: add a clock input
In reply to Luc MichelAdd a clock input to the PL011 UART so we can compute the current baud rate and trace it. This is intended for developers who wish to use QEMU to e.g. debug their firmware or to figure out the baud rate configured by an unknown/closed source binary.
--- include/hw/char/pl011.h | 1 + hw/char/pl011.c | 45 +++++++++++++++++++++++++++++++++++++++++ hw/char/trace-events | 1 + 3 files changed, 47 insertions(+)
include/hw/char/pl011.h +1 -0
@@ -47,10 +47,11 @@ struct PL011State {int read_pos;int read_count;int read_trigger;CharBackend chr;qemu_irq irq[6 ]; +Clock *clk;const unsigned char *id; }; static inline DeviceState *pl011_create(hwaddr addr, qemu_irq irq,
hw/char/pl011.c +45 -0
114 lines not on this page · raw message
hw/char/trace-events +1 -0
@@ -63,10 +63,11 @@ pl011_read(uint32_t addr, uint32_t value) "addr 0x%08x value 0x%08x" pl011_read_fifo(int read_count) "FIFO read, read_count now %d" pl011_write(uint32_t addr, uint32_t value) "addr 0x%08x value 0x%08x" pl011_can_receive(uint32_t lcr, int read_count, int r) "LCR 0x%08x read_count %d returning %d" pl011_put_fifo(uint32_t c, int read_count) "new char 0x%x read_count now %d" pl011_put_fifo_full(void) "FIFO now full, RXFF set" +pl011_baudrate_change(unsigned int baudrate, uint64_t clock, uint32_t ibrd, uint32_t fbrd) "new baudrate %u (clk: %" PRIu64 "hz, ibrd: %" PRIu32 ", fbrd: %" PRIu32 ")" # cmsdk-apb-uart.c cmsdk_apb_uart_read(uint64_t offset, uint64_t data, unsigned size) "CMSDK APB UART read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u" cmsdk_apb_uart_write(uint64_t offset, uint64_t data, unsigned size) "CMSDK APB UART write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u" cmsdk_apb_uart_reset(void) "CMSDK APB UART: reset"
Signature · 1 line
2.28.0
PATCH v3 15/15 hw/arm/bcm2835_peripherals: connect the UART clock
In reply to Luc MichelConnect the 'uart-out' clock from the CPRMAN to the PL011 instance.
--- hw/arm/bcm2835_peripherals.c | 2 ++ 1 file changed, 2 insertions(+)
hw/arm/bcm2835_peripherals.c +2 -0
@@ -167,10 +167,12 @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)if (!sysbus_realize (SYS_BUS_DEVICE (&s->cprman), errp)) {return ; }memory_region_add_subregion (&s->peri_mr,CPRMAN_OFFSET ,sysbus_mmio_get_region (SYS_BUS_DEVICE (&s->cprman),0 )); +qdev_connect_clock_in (DEVICE (&s->uart0),"clk" , +qdev_get_clock_out (DEVICE (&s->cprman),"uart-out" ));memory_region_add_subregion (&s->peri_mr,ARMCTRL_IC_OFFSET ,sysbus_mmio_get_region (SYS_BUS_DEVICE (&s->ic),0 ));sysbus_pass_irq (SYS_BUS_DEVICE (s),SYS_BUS_DEVICE (&s->ic));
Signature · 1 line
2.28.0
On 10/10/20 3:57 PM, Luc Michel wrote:
[...]
Quoted 4 lines
Hi,
This series add the BCM2835 CPRMAN clock manager peripheral to the Raspberry Pi machine.
Series:
Peter Maydell
AppliedQuoted 12 lines · Luc Michel
v2 -> v3:
- patch 03: movedclock_newdefinition tohw/core/clock.c[Phil]
- patch 03: commit message typo [Clement]
- patch 10: clarifications around the CM_CTL/CM_DIBV mux registers.reg_cmreplaced withreg_ctlandreg_div. Add some comments for clarity. [Phil]
- patch 10: fixedupdate_mux_from_cmnot matching theCM_DIVoffset correctly. [Phil]
- patch 11: replaced manual bitfield extraction with extract32 [Phil]
- patch 11: added a visual representation ofCM_DIVfor clarity [Phil]
- patch 11: added a missing return inclock_mux_update.
Applied to target-arm.next, thanks.
-- PMM
Quoted 17 lines · Peter Maydell
Quoted 12 lines · Luc Michel
v2 -> v3:
- patch 03: movedclock_newdefinition tohw/core/clock.c[Phil]
- patch 03: commit message typo [Clement]
- patch 10: clarifications around the CM_CTL/CM_DIBV mux registers.reg_cmreplaced withreg_ctlandreg_div. Add some comments for clarity. [Phil]
- patch 10: fixedupdate_mux_from_cmnot matching theCM_DIVoffset correctly. [Phil]
- patch 11: replaced manual bitfield extraction with extract32 [Phil]
- patch 11: added a visual representation ofCM_DIVfor clarity [Phil]
- patch 11: added a missing return inclock_mux_update.
Quoted 1 line
Applied to target-arm.next, thanks.
Dropped again due to segv in 'make check' when running with clang sanitizer, which I gather from irc that you're looking into.
thanks
-- PMM
Philippe Mathieu-Daudé
Tested-by Guenter RoeckHi Peter,
Quoted 18 lines · Peter Maydell
Quoted 17 lines · Peter Maydell
Quoted 12 lines · Luc Michel
v2 -> v3:
- patch 03: movedclock_newdefinition tohw/core/clock.c[Phil]
- patch 03: commit message typo [Clement]
- patch 10: clarifications around the CM_CTL/CM_DIBV mux registers.reg_cmreplaced withreg_ctlandreg_div. Add some comments for clarity. [Phil]
- patch 10: fixedupdate_mux_from_cmnot matching theCM_DIVoffset correctly. [Phil]
- patch 11: replaced manual bitfield extraction with extract32 [Phil]
- patch 11: added a visual representation ofCM_DIVfor clarity [Phil]
- patch 11: added a missing return inclock_mux_update.
Quoted 5 lines
Quoted 1 line
Applied to target-arm.next, thanks.
Dropped again due to segv in 'make check' when running with clang sanitizer, which I gather from irc that you're looking into.
The fix has been merged as commit a6e9b9123e7 ("hw/core/qdev-clock: add a reference on aliased clocks") and the series also got:
Hopefully it will make it for 5.2 :)
Thanks,
Phil.
Peter Maydell
AppliedQuoted 28 lines · Philippe Mathieu-Daudé
Hi Peter,
Quoted 18 lines · Peter Maydell
Quoted 17 lines · Peter Maydell
Quoted 12 lines · Luc Michel
v2 -> v3:
- patch 03: movedclock_newdefinition tohw/core/clock.c[Phil]
- patch 03: commit message typo [Clement]
- patch 10: clarifications around the CM_CTL/CM_DIBV mux registers.reg_cmreplaced withreg_ctlandreg_div. Add some comments for clarity. [Phil]
- patch 10: fixedupdate_mux_from_cmnot matching theCM_DIVoffset correctly. [Phil]
- patch 11: replaced manual bitfield extraction with extract32 [Phil]
- patch 11: added a visual representation ofCM_DIVfor clarity [Phil]
- patch 11: added a missing return inclock_mux_update.Quoted 5 lines
Quoted 1 line
Applied to target-arm.next, thanks.
Dropped again due to segv in 'make check' when running with clang sanitizer, which I gather from irc that you're looking into.
Quoted 6 lines
The fix has been merged as commit
a6e9b9123e7("hw/core/qdev-clock: add a reference on aliased clocks") and the series also got:Tested-by Guenter Roeck <[email protected]>Hopefully it will make it for 5.2 :)
Applied to target-arm.next, thanks.
-- PMM
Cc'ing Guenter who had a similar patch and might be interested to test :)
patch 16/15 fixup:
https://www.mail-archive.com/[email protected]/msg752113.html
Quoted 139 lines · Luc Michel
v2 -> v3:
- patch 03: movedclock_newdefinition tohw/core/clock.c[Phil]
- patch 03: commit message typo [Clement]
- patch 10: clarifications around the CM_CTL/CM_DIBV mux registers.reg_cmreplaced withreg_ctlandreg_div. Add some comments for clarity. [Phil]
- patch 10: fixedupdate_mux_from_cmnot matching theCM_DIVoffset correctly. [Phil]
- patch 11: replaced manual bitfield extraction with extract32 [Phil]
- patch 11: added a visual representation ofCM_DIVfor clarity [Phil]
- patch 11: added a missing return inclock_mux_update.v1 -> v2:
- patch 05: Added a comment about MMIO .valid constraints [Phil]
- patch 05: Added MMIO .impl [Phil]
- patch 05: Movedinit_internal_clockto the public clock API, renamedclock_new(new patch 03) [Phil]
- patch 11: use muldiv64 for clock mux frequency output computation [Phil]
- patch 11: add a check for null divisor (Phil: I dropped your r-b)
- Typos, formatting, naming, style [Phil]Patches without review: 03, 11, 13
Hi,
This series add the BCM2835 CPRMAN clock manager peripheral to the Raspberry Pi machine.
Patches 1-4 are preliminary changes, patches 5-13 are the actual implementation.
The two last patches add a clock input to the PL011 and connect it to the CPRMAN.
This series has been tested with Linux 5.4.61 (the current raspios version). It fixes the kernel Oops at boot time due to invalid UART clock value, and other warnings/errors here and there because of bad clocks or lack of CPRMAN.
Here is the clock tree as seen by Linux when booted in QEMU:
(/sys/kernel/debug/clk/clk_summarywith some columns removed)enable prepare
clock count count rate
-----------------------------------------------------otg 0 0 480000000 osc 5 5 19200000 gp2 1 1 32768 tsens 0 0 1920000 otp 0 0 4800000 timer 0 0 1000002 pllh 4 4 864000000 pllh_pix_prediv 1 1 3375000 pllh_pix 0 0 337500 pllh_aux 1 1 216000000 vec 0 0 108000000 pllh_rcal_prediv 1 1 3375000 pllh_rcal 0 0 337500 plld 3 3 2000000024 plld_dsi1 0 0 7812501 plld_dsi0 0 0 7812501 plld_per 3 3 500000006 gp1 1 1 25000000 uart 1 2 47999625 plld_core 2 2 500000006 sdram 0 0 166666668 pllc 3 3 2400000000 pllc_per 1 1 1200000000 emmc 0 0 200000000 pllc_core2 0 0 9375000 pllc_core1 0 0 9375000 pllc_core0 2 2 1200000000 vpu 1 1 700000000 aux_spi2 0 0 700000000 aux_spi1 0 0 700000000 aux_uart 0 0 700000000 peri_image 0 0 700000000 plla 2 2 2250000000 plla_ccp2 0 0 8789063 plla_dsi0 0 0 8789063 plla_core 1 1 750000000 h264 0 0 250000000 isp 0 0 250000000 dsi1p 0 0 0 dsi0p 0 0 0 dsi1e 0 0 0 dsi0e 0 0 0 cam1 0 0 0 cam0 0 0 0 dpi 0 0 0 tec 0 0 0 smi 0 0 0 slim 0 0 0 gp0 0 0 0 dft 0 0 0 aveo 0 0 0 pcm 0 0 0 pwm 0 0 0 hsm 0 0 0It shows small differences with real hardware due other missing peripherals for which the driver turn the clock off (like tsens).
Luc Michel (15):
hw/core/clock: provide theVMSTATE_ARRAY_CLOCKmacro hw/core/clock: trace clock values in Hz instead of ns hw/core/clock: add theclock_newhelper function hw/arm/raspi: fix CPRMAN base address
hw/arm/raspi: add a skeleton implementation of the CPRMAN hw/misc/bcm2835_cprman: add a PLL skeleton implementation hw/misc/bcm2835_cprman: implement PLLs behaviour hw/misc/bcm2835_cprman: add a PLL channel skeleton implementation hw/misc/bcm2835_cprman: implement PLL channels behaviour hw/misc/bcm2835_cprman: add a clock mux skeleton implementation hw/misc/bcm2835_cprman: implement clock mux behaviour hw/misc/bcm2835_cprman: add the DSI0HSCK multiplexer hw/misc/bcm2835_cprman: add sane reset values to the registers hw/char/pl011: add a clock input hw/arm/bcm2835_peripherals: connect the UART clockinclude/hw/arm/bcm2835_peripherals.h | 5 +- include/hw/arm/raspi_platform.h | 5 +- include/hw/char/pl011.h | 1 + include/hw/clock.h | 18 + include/hw/misc/bcm2835_cprman.h | 210 ++++ include/hw/misc/bcm2835_cprman_internals.h | 1019 ++++++++++++++++++++ hw/arm/bcm2835_peripherals.c | 15 +- hw/char/pl011.c | 45 + hw/core/clock.c | 21 +- hw/misc/bcm2835_cprman.c | 808 ++++++++++++++++ hw/char/trace-events | 1 + hw/core/trace-events | 4 +- hw/misc/meson.build | 1 + hw/misc/trace-events | 5 + 14 files changed, 2146 insertions(+), 12 deletions(-)create mode 100644
include/hw/misc/bcm2835_cprman.hcreate mode 100644include/hw/misc/bcm2835_cprman_internals.hcreate mode 100644hw/misc/bcm2835_cprman.c
Hi,
Quoted 3 lines · Philippe Mathieu-Daudé
Cc'ing Guenter who had a similar patch and might be interested to test :)
great. I think my patch doesn't work anymore since qemu 5.0 (at least not for raspi3), and it was pretty hackish anyway. I'll give the series a try.
Guenter
Quoted 143 lines
patch 16/15 fixup:
https://www.mail-archive.com/[email protected]/msg752113.htmlQuoted 139 lines · Luc Michel
v2 -> v3:
- patch 03: movedclock_newdefinition tohw/core/clock.c[Phil]
- patch 03: commit message typo [Clement]
- patch 10: clarifications around the CM_CTL/CM_DIBV mux registers.reg_cmreplaced withreg_ctlandreg_div. Add some comments for clarity. [Phil]
- patch 10: fixedupdate_mux_from_cmnot matching theCM_DIVoffset correctly. [Phil]
- patch 11: replaced manual bitfield extraction with extract32 [Phil]
- patch 11: added a visual representation ofCM_DIVfor clarity [Phil]
- patch 11: added a missing return inclock_mux_update.v1 -> v2:
- patch 05: Added a comment about MMIO .valid constraints [Phil]
- patch 05: Added MMIO .impl [Phil]
- patch 05: Movedinit_internal_clockto the public clock API, renamedclock_new(new patch 03) [Phil]
- patch 11: use muldiv64 for clock mux frequency output computation [Phil]
- patch 11: add a check for null divisor (Phil: I dropped your r-b)
- Typos, formatting, naming, style [Phil]Patches without review: 03, 11, 13
Hi,
This series add the BCM2835 CPRMAN clock manager peripheral to the Raspberry Pi machine.
Patches 1-4 are preliminary changes, patches 5-13 are the actual implementation.
The two last patches add a clock input to the PL011 and connect it to the CPRMAN.
This series has been tested with Linux 5.4.61 (the current raspios version). It fixes the kernel Oops at boot time due to invalid UART clock value, and other warnings/errors here and there because of bad clocks or lack of CPRMAN.
Here is the clock tree as seen by Linux when booted in QEMU:
(/sys/kernel/debug/clk/clk_summarywith some columns removed)enable prepare clock count count rate
-----------------------------------------------------
otg 0 0 480000000 osc 5 5 19200000 gp2 1 1 32768 tsens 0 0 1920000 otp 0 0 4800000 timer 0 0 1000002 pllh 4 4 864000000 pllh_pix_prediv 1 1 3375000 pllh_pix 0 0 337500 pllh_aux 1 1 216000000 vec 0 0 108000000 pllh_rcal_prediv 1 1 3375000 pllh_rcal 0 0 337500 plld 3 3 2000000024 plld_dsi1 0 0 7812501 plld_dsi0 0 0 7812501 plld_per 3 3 500000006 gp1 1 1 25000000 uart 1 2 47999625 plld_core 2 2 500000006 sdram 0 0 166666668 pllc 3 3 2400000000 pllc_per 1 1 1200000000 emmc 0 0 200000000 pllc_core2 0 0 9375000 pllc_core1 0 0 9375000 pllc_core0 2 2 1200000000 vpu 1 1 700000000 aux_spi2 0 0 700000000 aux_spi1 0 0 700000000 aux_uart 0 0 700000000 peri_image 0 0 700000000 plla 2 2 2250000000 plla_ccp2 0 0 8789063 plla_dsi0 0 0 8789063 plla_core 1 1 750000000 h264 0 0 250000000 isp 0 0 250000000 dsi1p 0 0 0 dsi0p 0 0 0 dsi1e 0 0 0 dsi0e 0 0 0 cam1 0 0 0 cam0 0 0 0 dpi 0 0 0 tec 0 0 0 smi 0 0 0 slim 0 0 0 gp0 0 0 0 dft 0 0 0 aveo 0 0 0 pcm 0 0 0 pwm 0 0 0 hsm 0 0 0It shows small differences with real hardware due other missing peripherals for which the driver turn the clock off (like tsens).
Luc Michel (15):
hw/core/clock: provide theVMSTATE_ARRAY_CLOCKmacro hw/core/clock: trace clock values in Hz instead of ns hw/core/clock: add theclock_newhelper function hw/arm/raspi: fix CPRMAN base address
hw/arm/raspi: add a skeleton implementation of the CPRMAN hw/misc/bcm2835_cprman: add a PLL skeleton implementation hw/misc/bcm2835_cprman: implement PLLs behaviour hw/misc/bcm2835_cprman: add a PLL channel skeleton implementation hw/misc/bcm2835_cprman: implement PLL channels behaviour hw/misc/bcm2835_cprman: add a clock mux skeleton implementation hw/misc/bcm2835_cprman: implement clock mux behaviour hw/misc/bcm2835_cprman: add the DSI0HSCK multiplexer hw/misc/bcm2835_cprman: add sane reset values to the registers hw/char/pl011: add a clock input hw/arm/bcm2835_peripherals: connect the UART clockinclude/hw/arm/bcm2835_peripherals.h | 5 +- include/hw/arm/raspi_platform.h | 5 +- include/hw/char/pl011.h | 1 + include/hw/clock.h | 18 + include/hw/misc/bcm2835_cprman.h | 210 ++++
include/hw/misc/bcm2835_cprman_internals.h| 1019 ++++++++++++++++++++ hw/arm/bcm2835_peripherals.c | 15 +- hw/char/pl011.c | 45 + hw/core/clock.c | 21 +- hw/misc/bcm2835_cprman.c | 808 ++++++++++++++++ hw/char/trace-events | 1 + hw/core/trace-events | 4 +- hw/misc/meson.build | 1 + hw/misc/trace-events | 5 +14 files changed, 2146 insertions(+), 12 deletions(-)create mode 100644
include/hw/misc/bcm2835_cprman.hcreate mode 100644include/hw/misc/bcm2835_cprman_internals.hcreate mode 100644hw/misc/bcm2835_cprman.c
Guenter Roeck
Tested-byQuoted 3 lines · Philippe Mathieu-Daudé
Cc'ing Guenter who had a similar patch and might be interested to test :)
I applied the series on top of qemu mainline and ran all my test with it (raspi2 with qemu-system-arm as well as qemu-system-aarch64, and raspi3 in both big endian and little endian mode with qemu-system-aarch64. All tests passed without error or kernel warning.
For the series:
Guenter
Quoted 143 lines
patch 16/15 fixup:
https://www.mail-archive.com/[email protected]/msg752113.htmlQuoted 139 lines · Luc Michel
v2 -> v3:
- patch 03: movedclock_newdefinition tohw/core/clock.c[Phil]
- patch 03: commit message typo [Clement]
- patch 10: clarifications around the CM_CTL/CM_DIBV mux registers.reg_cmreplaced withreg_ctlandreg_div. Add some comments for clarity. [Phil]
- patch 10: fixedupdate_mux_from_cmnot matching theCM_DIVoffset correctly. [Phil]
- patch 11: replaced manual bitfield extraction with extract32 [Phil]
- patch 11: added a visual representation ofCM_DIVfor clarity [Phil]
- patch 11: added a missing return inclock_mux_update.v1 -> v2:
- patch 05: Added a comment about MMIO .valid constraints [Phil]
- patch 05: Added MMIO .impl [Phil]
- patch 05: Movedinit_internal_clockto the public clock API, renamedclock_new(new patch 03) [Phil]
- patch 11: use muldiv64 for clock mux frequency output computation [Phil]
- patch 11: add a check for null divisor (Phil: I dropped your r-b)
- Typos, formatting, naming, style [Phil]Patches without review: 03, 11, 13
Hi,
This series add the BCM2835 CPRMAN clock manager peripheral to the Raspberry Pi machine.
Patches 1-4 are preliminary changes, patches 5-13 are the actual implementation.
The two last patches add a clock input to the PL011 and connect it to the CPRMAN.
This series has been tested with Linux 5.4.61 (the current raspios version). It fixes the kernel Oops at boot time due to invalid UART clock value, and other warnings/errors here and there because of bad clocks or lack of CPRMAN.
Here is the clock tree as seen by Linux when booted in QEMU:
(/sys/kernel/debug/clk/clk_summarywith some columns removed)enable prepare clock count count rate
-----------------------------------------------------
otg 0 0 480000000 osc 5 5 19200000 gp2 1 1 32768 tsens 0 0 1920000 otp 0 0 4800000 timer 0 0 1000002 pllh 4 4 864000000 pllh_pix_prediv 1 1 3375000 pllh_pix 0 0 337500 pllh_aux 1 1 216000000 vec 0 0 108000000 pllh_rcal_prediv 1 1 3375000 pllh_rcal 0 0 337500 plld 3 3 2000000024 plld_dsi1 0 0 7812501 plld_dsi0 0 0 7812501 plld_per 3 3 500000006 gp1 1 1 25000000 uart 1 2 47999625 plld_core 2 2 500000006 sdram 0 0 166666668 pllc 3 3 2400000000 pllc_per 1 1 1200000000 emmc 0 0 200000000 pllc_core2 0 0 9375000 pllc_core1 0 0 9375000 pllc_core0 2 2 1200000000 vpu 1 1 700000000 aux_spi2 0 0 700000000 aux_spi1 0 0 700000000 aux_uart 0 0 700000000 peri_image 0 0 700000000 plla 2 2 2250000000 plla_ccp2 0 0 8789063 plla_dsi0 0 0 8789063 plla_core 1 1 750000000 h264 0 0 250000000 isp 0 0 250000000 dsi1p 0 0 0 dsi0p 0 0 0 dsi1e 0 0 0 dsi0e 0 0 0 cam1 0 0 0 cam0 0 0 0 dpi 0 0 0 tec 0 0 0 smi 0 0 0 slim 0 0 0 gp0 0 0 0 dft 0 0 0 aveo 0 0 0 pcm 0 0 0 pwm 0 0 0 hsm 0 0 0It shows small differences with real hardware due other missing peripherals for which the driver turn the clock off (like tsens).
Luc Michel (15):
hw/core/clock: provide theVMSTATE_ARRAY_CLOCKmacro hw/core/clock: trace clock values in Hz instead of ns hw/core/clock: add theclock_newhelper function hw/arm/raspi: fix CPRMAN base address
hw/arm/raspi: add a skeleton implementation of the CPRMAN hw/misc/bcm2835_cprman: add a PLL skeleton implementation hw/misc/bcm2835_cprman: implement PLLs behaviour hw/misc/bcm2835_cprman: add a PLL channel skeleton implementation hw/misc/bcm2835_cprman: implement PLL channels behaviour hw/misc/bcm2835_cprman: add a clock mux skeleton implementation hw/misc/bcm2835_cprman: implement clock mux behaviour hw/misc/bcm2835_cprman: add the DSI0HSCK multiplexer hw/misc/bcm2835_cprman: add sane reset values to the registers hw/char/pl011: add a clock input hw/arm/bcm2835_peripherals: connect the UART clockinclude/hw/arm/bcm2835_peripherals.h | 5 +- include/hw/arm/raspi_platform.h | 5 +- include/hw/char/pl011.h | 1 + include/hw/clock.h | 18 + include/hw/misc/bcm2835_cprman.h | 210 ++++
include/hw/misc/bcm2835_cprman_internals.h| 1019 ++++++++++++++++++++ hw/arm/bcm2835_peripherals.c | 15 +- hw/char/pl011.c | 45 + hw/core/clock.c | 21 +- hw/misc/bcm2835_cprman.c | 808 ++++++++++++++++ hw/char/trace-events | 1 + hw/core/trace-events | 4 +- hw/misc/meson.build | 1 + hw/misc/trace-events | 5 +14 files changed, 2146 insertions(+), 12 deletions(-)create mode 100644
include/hw/misc/bcm2835_cprman.hcreate mode 100644include/hw/misc/bcm2835_cprman_internals.hcreate mode 100644hw/misc/bcm2835_cprman.c
Quoted 8 lines · Guenter Roeck
Quoted 3 lines · Philippe Mathieu-Daudé
Cc'ing Guenter who had a similar patch and might be interested to test :)
I applied the series on top of qemu mainline and ran all my test with it (raspi2 with qemu-system-arm as well as qemu-system-aarch64, and raspi3 in both big endian and little endian mode with qemu-system-aarch64. All tests passed without error or kernel warning.
Awesome :) I'm glad we finally get this complex part implemented.
Regards,
Phil.
Quoted 6 lines
For the series:
Tested-by Guenter Roeck <[email protected]>Guenter