git: 299b6c9cb1a9 - main - uart_bus_acpi: Read clock frequency from bus

From: Kornel Dulęba <kd_at_FreeBSD.org>
Date: Wed, 07 Sep 2022 07:59:39 UTC
The branch main has been updated by kd:

URL: https://cgit.FreeBSD.org/src/commit/?id=299b6c9cb1a9a3e3a7a59913dc4f1ea5dff040d5

commit 299b6c9cb1a9a3e3a7a59913dc4f1ea5dff040d5
Author:     Mateusz Kozyra <mkoz@semihalf.com>
AuthorDate: 2022-09-06 14:54:00 +0000
Commit:     Kornel Dulęba <kd@FreeBSD.org>
CommitDate: 2022-09-07 07:44:58 +0000

    uart_bus_acpi: Read clock frequency from bus
    
    It is stored in the clock-frequency property.
    In case of failure, fallback to the harcoded value stored in the
    compat data.
    Also, while here improve style.
    Tested on LS1046ARDB and x86 PC.
    
    Reviewed by:    mw
    Obtained from:  Semihalf
    Differential Revision: https://reviews.freebsd.org/D36326
---
 sys/dev/uart/uart_bus_acpi.c | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/sys/dev/uart/uart_bus_acpi.c b/sys/dev/uart/uart_bus_acpi.c
index 1018412392dd..8a2eec143577 100644
--- a/sys/dev/uart/uart_bus_acpi.c
+++ b/sys/dev/uart/uart_bus_acpi.c
@@ -83,19 +83,29 @@ uart_acpi_find_device(device_t dev)
 static int
 uart_acpi_probe(device_t dev)
 {
-	struct uart_softc *sc;
 	struct acpi_uart_compat_data *cd;
+	struct uart_softc *sc;
+	uint32_t rclk;
+	ssize_t size;
 
 	sc = device_get_softc(dev);
+	rclk = 0;
 
-	if ((cd = uart_acpi_find_device(dev)) != NULL) {
-		sc->sc_class = cd->cd_class;
-		if (cd->cd_desc != NULL)
-			device_set_desc(dev, cd->cd_desc);
-		return (uart_bus_probe(dev, cd->cd_regshft, cd->cd_regiowidth,
-		    cd->cd_rclk, 0, 0, cd->cd_quirks));
-	}
-	return (ENXIO);
+	cd = uart_acpi_find_device(dev);
+	if (cd == NULL)
+		return (ENXIO);
+
+	sc->sc_class = cd->cd_class;
+	if (cd->cd_desc != NULL)
+		device_set_desc(dev, cd->cd_desc);
+
+	size = device_get_property(dev, "clock-frequency", &rclk,
+	    sizeof(rclk), DEVICE_PROP_UINT32);
+	if (size < 0 || rclk == 0)
+		rclk = cd->cd_rclk;
+
+	return (uart_bus_probe(dev, cd->cd_regshft, cd->cd_regiowidth,
+	    rclk, 0, 0, cd->cd_quirks));
 }
 
 DRIVER_MODULE(uart, acpi, uart_acpi_driver, 0, 0);