Skip to contentSkip to conversation

hw/ppc: e500: Use a macro for the platform clock frequency

PATCH Applied Bin Meng 2 participants 6 messages Feb 3, 2021 – Feb 5, 2021

lore
Share & tools
lore

Bin Meng

author
#0 lore raw

PATCH v2 1/2 hw/ppc: e500: Use a macro for the platform clock frequency

From: Bin Meng <[email protected]>

At present the platform clock frequency is using a magic number. Convert it to a macro and use it everywhere.

---

Changes in v2:
- Rename the macro per Philippe's comments

 hw/ppc/e500.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
hw/ppc/e500.c +5 -3
index c64b5d0..c795276 100644
@@ -74,6 +74,8 @@
 #define MPC8544_I2C_IRQ            43
 #define RTC_REGS_OFFSET            0x68
 
+#define PLATFORM_CLK_FREQ_HZ       (400 * 1000 * 1000)
+
 struct boot_info
 {
     uint32_t dt_base;
@@ -320,8 +322,8 @@ static int ppce500_load_device_tree(PPCE500MachineState *pms,
     int fdt_size;
     void *fdt;
     uint8_t hypercall[16];
-    uint32_t clock_freq = 400000000;
-    uint32_t tb_freq = 400000000;
+    uint32_t clock_freq = PLATFORM_CLK_FREQ_HZ;
+    uint32_t tb_freq = PLATFORM_CLK_FREQ_HZ;
     int i;
     char compatible_sb[] = "fsl,mpc8544-immr\0simple-bus";
     char *soc;
@@ -890,7 +892,7 @@ void ppce500_init(MachineState *machine)
         env->spr_cb[SPR_BOOKE_PIR].default_value = cs->cpu_index = i;
         env->mpic_iack = pmc->ccsrbar_base + MPC8544_MPIC_REGS_OFFSET + 0xa0;
 
-        ppc_booke_timers_init(cpu, 400000000, PPC_TIMER_E500);
+        ppc_booke_timers_init(cpu, PLATFORM_CLK_FREQ_HZ, PPC_TIMER_E500);
 
         /* Register reset handler */
         if (!i) {
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH v2 2/2 hw/ppc: e500: Fill in correct <clock-frequency> for the serial nodes

From: Bin Meng <[email protected]>

At present the <clock-frequency> property of the serial node is populated with value zero. U-Boot's ns16550 driver is not happy about this, so let's fill in a meaningful value.

---

(no changes since v1)

 hw/ppc/e500.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/ppc/e500.c +1 -1
index c795276..01517a6 100644
@@ -126,7 +126,7 @@ static void dt_serial_create(void *fdt, unsigned long long offset,
     qemu_fdt_setprop_string(fdt, ser, "compatible", "ns16550");
     qemu_fdt_setprop_cells(fdt, ser, "reg", offset, 0x100);
     qemu_fdt_setprop_cell(fdt, ser, "cell-index", idx);
-    qemu_fdt_setprop_cell(fdt, ser, "clock-frequency", 0);
+    qemu_fdt_setprop_cell(fdt, ser, "clock-frequency", PLATFORM_CLK_FREQ_HZ);
     qemu_fdt_setprop_cells(fdt, ser, "interrupts", 42, 2);
     qemu_fdt_setprop_phandle(fdt, ser, "interrupt-parent", mpic);
     qemu_fdt_setprop_string(fdt, "/aliases", alias, ser);
Signature · 1 line
2.7.4
#2 lore raw

Re: [PATCH v2 2/2] hw/ppc: e500: Fill in correct <clock-frequency> for the serial nodes

Quoted 5 lines · Bin Meng

From: Bin Meng <[email protected]>

At present the <clock-frequency> property of the serial node is populated with value zero. U-Boot's ns16550 driver is not happy about this, so let's fill in a meaningful value.

Are you sure this is correct - that is that the serial clock is really the same as the overall system clock? Quite often there's some kind of divider in between.

Quoted 24 lines

---

(no changes since v1)

 hw/ppc/e500.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/ppc/e500.c +1 -1
index c795276..01517a6 100644
@@ -126,7 +126,7 @@ static void dt_serial_create(void *fdt, unsigned long long offset,
     qemu_fdt_setprop_string(fdt, ser, "compatible", "ns16550");
     qemu_fdt_setprop_cells(fdt, ser, "reg", offset, 0x100);
     qemu_fdt_setprop_cell(fdt, ser, "cell-index", idx);
-    qemu_fdt_setprop_cell(fdt, ser, "clock-frequency", 0);
+    qemu_fdt_setprop_cell(fdt, ser, "clock-frequency", PLATFORM_CLK_FREQ_HZ);
     qemu_fdt_setprop_cells(fdt, ser, "interrupts", 42, 2);
     qemu_fdt_setprop_phandle(fdt, ser, "interrupt-parent", mpic);
     qemu_fdt_setprop_string(fdt, "/aliases", alias, ser);
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
author
#3 lore raw

Re: [PATCH v2 2/2] hw/ppc: e500: Fill in correct <clock-frequency> for the serial nodes

Quoted 4 lines · David Gibson
Quoted 2 lines · Bin Meng

From: Bin Meng <[email protected]>

Quoted 8 lines
Quoted 3 lines

At present the <clock-frequency> property of the serial node is populated with value zero. U-Boot's ns16550 driver is not happy about this, so let's fill in a meaningful value.

Are you sure this is correct - that is that the serial clock is really the same as the overall system clock? Quite often there's some kind of divider in between.

Yes, see the U-Boot codes include/configs/qemu-ppce500.h

#define CONFIG_SYS_NS16550_CLK (get_bus_freq(0))

get_bus_freq(0) eventually returns the platform clock frequency which is 400MHz.

But the value doesn't matter anyway for QEMU. We don't emulate any baud rate specific thing for a serial port. We only need a sane value that is non-zero.

Regards,
Bin

#4 lore raw

Re: [PATCH v2 2/2] hw/ppc: e500: Fill in correct <clock-frequency> for the serial nodes

Quoted 17 lines · Bin Meng
Quoted 4 lines · David Gibson
Quoted 2 lines · Bin Meng

From: Bin Meng <[email protected]>

Quoted 8 lines
Quoted 3 lines

At present the <clock-frequency> property of the serial node is populated with value zero. U-Boot's ns16550 driver is not happy about this, so let's fill in a meaningful value.

Are you sure this is correct - that is that the serial clock is really the same as the overall system clock? Quite often there's some kind of divider in between.

Yes, see the U-Boot codes include/configs/qemu-ppce500.h

Quoted 7 lines

#define CONFIG_SYS_NS16550_CLK (get_bus_freq(0))

get_bus_freq(0) eventually returns the platform clock frequency which is 400MHz.

But the value doesn't matter anyway for QEMU. We don't emulate any baud rate specific thing for a serial port. We only need a sane value that is non-zero.

Understood. Applied to ppc-for-6.0.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
Applied
#5 lore raw
In reply to Bin Meng
Quoted 7 lines · Bin Meng

From: Bin Meng <[email protected]>

At present the platform clock frequency is using a magic number. Convert it to a macro and use it everywhere.

Applied to ppc-for-6.0, thanks.

Quoted 42 lines

---

Changes in v2:
- Rename the macro per Philippe's comments

 hw/ppc/e500.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
hw/ppc/e500.c +5 -3
index c64b5d0..c795276 100644
@@ -74,6 +74,8 @@
 #define MPC8544_I2C_IRQ            43
 #define RTC_REGS_OFFSET            0x68
 
+#define PLATFORM_CLK_FREQ_HZ       (400 * 1000 * 1000)
+
 struct boot_info
 {
     uint32_t dt_base;
@@ -320,8 +322,8 @@ static int ppce500_load_device_tree(PPCE500MachineState *pms,
     int fdt_size;
     void *fdt;
     uint8_t hypercall[16];
-    uint32_t clock_freq = 400000000;
-    uint32_t tb_freq = 400000000;
+    uint32_t clock_freq = PLATFORM_CLK_FREQ_HZ;
+    uint32_t tb_freq = PLATFORM_CLK_FREQ_HZ;
     int i;
     char compatible_sb[] = "fsl,mpc8544-immr\0simple-bus";
     char *soc;
@@ -890,7 +892,7 @@ void ppce500_init(MachineState *machine)
         env->spr_cb[SPR_BOOKE_PIR].default_value = cs->cpu_index = i;
         env->mpic_iack = pmc->ccsrbar_base + MPC8544_MPIC_REGS_OFFSET + 0xa0;
 
-        ppc_booke_timers_init(cpu, 400000000, PPC_TIMER_E500);
+        ppc_booke_timers_init(cpu, PLATFORM_CLK_FREQ_HZ, PPC_TIMER_E500);
 
         /* Register reset handler */
         if (!i) {
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson