boot/efi/dtb: implement clock frequency resolution for PL011

Factor out the code for clock frequency lookup to a separate function.

PL011 does not have clock-frequency property, it has a clocks property
instead, containing a phandle of the apb clock.

Change-Id: I5cbe2b4b2421afe1924c2804002ceef83ce37ef9
Reviewed-on: https://review.haiku-os.org/c/haiku/+/4734
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
David Karoly
2021-12-02 08:16:31 +00:00
committed by Adrien Destugues
parent ff9497b539
commit 326b5263de
+28 -3
View File
@@ -335,6 +335,33 @@ GetInterrupt(const void* fdt, int node, uint32 interruptCells)
}
static int64
GetClockFrequency(const void* fdt, int node)
{
uint32* prop;
int len = 0;
prop = (uint32*)fdt_getprop(fdt, node, "clock-frequency", NULL);
if (prop != NULL) {
return fdt32_to_cpu(*prop);
}
prop = (uint32*)fdt_getprop(fdt, node, "clocks", &len);
if (prop != NULL) {
uint32_t phandle = fdt32_to_cpu(*prop);
int offset = fdt_node_offset_by_phandle(fdt, phandle);
if (offset > 0) {
uint32* prop2 = (uint32*)fdt_getprop(fdt, offset, "clock-frequency", NULL);
if (prop2 != NULL) {
return fdt32_to_cpu(*prop2);
}
}
}
return 0;
}
static void
HandleFdt(const void* fdt, int node, uint32 addressCells, uint32 sizeCells,
uint32 interruptCells /* from parent node */)
@@ -400,9 +427,7 @@ HandleFdt(const void* fdt, int node, uint32 addressCells, uint32 sizeCells,
GetReg(fdt, node, addressCells, sizeCells, 0, uart.regs);
uart.irq = GetInterrupt(fdt, node, interruptCells);
const void* prop = fdt_getprop(fdt, node, "clock-frequency", NULL);
uart.clock = (prop == NULL) ? 0 : fdt32_to_cpu(*(uint32*)prop);
uart.clock = GetClockFrequency(fdt, node);
gUART = kSupportedUarts[i].uart_driver_init(uart.regs.start,
uart.clock);