Module Name:    src
Committed By:   skrll
Date:           Fri Jan  6 14:55:37 UTC 2017

Modified Files:
        src/sys/arch/arm/broadcom: bcm2835_plcom.c
        src/sys/arch/evbarm/rpi: rpi_machdep.c

Log Message:
Use the VC property mailbox to request the UART clock rate and use it
appropriately

Newer firmwares use 48MHz


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/arm/broadcom/bcm2835_plcom.c
cvs rdiff -u -r1.69 -r1.70 src/sys/arch/evbarm/rpi/rpi_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/arm/broadcom/bcm2835_plcom.c
diff -u src/sys/arch/arm/broadcom/bcm2835_plcom.c:1.3 src/sys/arch/arm/broadcom/bcm2835_plcom.c:1.4
--- src/sys/arch/arm/broadcom/bcm2835_plcom.c:1.3	Wed Jul 29 14:22:49 2015
+++ src/sys/arch/arm/broadcom/bcm2835_plcom.c	Fri Jan  6 14:55:37 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: bcm2835_plcom.c,v 1.3 2015/07/29 14:22:49 skrll Exp $	*/
+/*	$NetBSD: bcm2835_plcom.c,v 1.4 2017/01/06 14:55:37 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 /* Interface to plcom (PL011) serial driver. */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bcm2835_plcom.c,v 1.3 2015/07/29 14:22:49 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bcm2835_plcom.c,v 1.4 2017/01/06 14:55:37 skrll Exp $");
 
 #include <sys/types.h>
 #include <sys/device.h>
@@ -69,11 +69,19 @@ static void
 bcm2835_plcom_attach(device_t parent, device_t self, void *aux)
 {
 	struct plcom_softc *sc = device_private(self);
+	prop_dictionary_t dict = device_properties(self);
 	struct amba_attach_args *aaa = aux;
 	void *ih;
 
 	sc->sc_dev = self;
 	sc->sc_frequency = BCM2835_UART0_CLK;
+
+        /* Fetch the UART clock frequency from property if set. */
+	prop_number_t frequency = prop_dictionary_get(dict, "frequency");
+        if (frequency != NULL) {
+		sc->sc_frequency = prop_number_integer_value(frequency);
+        }
+
 	sc->sc_hwflags = PLCOM_HW_TXFIFO_DISABLE;
 	sc->sc_swflags = 0;
 	sc->sc_set_mcr = NULL;

Index: src/sys/arch/evbarm/rpi/rpi_machdep.c
diff -u src/sys/arch/evbarm/rpi/rpi_machdep.c:1.69 src/sys/arch/evbarm/rpi/rpi_machdep.c:1.70
--- src/sys/arch/evbarm/rpi/rpi_machdep.c:1.69	Fri Jan  6 14:53:32 2017
+++ src/sys/arch/evbarm/rpi/rpi_machdep.c	Fri Jan  6 14:55:37 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: rpi_machdep.c,v 1.69 2017/01/06 14:53:32 skrll Exp $	*/
+/*	$NetBSD: rpi_machdep.c,v 1.70 2017/01/06 14:55:37 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rpi_machdep.c,v 1.69 2017/01/06 14:53:32 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rpi_machdep.c,v 1.70 2017/01/06 14:55:37 skrll Exp $");
 
 #include "opt_arm_debug.h"
 #include "opt_bcm283x.h"
@@ -131,6 +131,8 @@ static void rpi_device_register(device_t
 #define RPI_FB_HEIGHT	720
 #endif
 
+int uart_clk = BCM2835_UART0_CLK;
+
 #define	PLCONADDR BCM2835_UART0_BASE
 
 #ifndef CONSDEVNAME
@@ -177,6 +179,28 @@ static struct plcom_instance rpi_pi = {
 
 static struct __aligned(16) {
 	struct vcprop_buffer_hdr	vb_hdr;
+	struct vcprop_tag_clockrate	vbt_uartclockrate;
+	struct vcprop_tag end;
+} vb_uart = {
+	.vb_hdr = {
+		.vpb_len = sizeof(vb_uart),
+		.vpb_rcode = VCPROP_PROCESS_REQUEST,
+	},
+	.vbt_uartclockrate = {
+		.tag = {
+			.vpt_tag = VCPROPTAG_GET_CLOCKRATE,
+			.vpt_len = VCPROPTAG_LEN(vb_uart.vbt_uartclockrate),
+			.vpt_rcode = VCPROPTAG_REQUEST
+		},
+		.id = VCPROP_CLK_UART
+	},
+	.end = {
+		.vpt_tag = VCPROPTAG_NULL
+	}
+};
+
+static struct __aligned(16) {
+	struct vcprop_buffer_hdr	vb_hdr;
 	struct vcprop_tag_fwrev		vbt_fwrev;
 	struct vcprop_tag_boardmodel	vbt_boardmodel;
 	struct vcprop_tag_boardrev	vbt_boardrev;
@@ -391,6 +415,26 @@ static uint8_t cursor_mask[8 * 64], curs
 
 
 static void
+rpi_uartinit(void)
+{
+	const paddr_t pa = BCM2835_PERIPHERALS_BUS_TO_PHYS(BCM2835_ARMMBOX_BASE);
+	const bus_space_tag_t iot = &bcm2835_bs_tag;
+	const bus_space_handle_t ioh = BCM2835_IOPHYSTOVIRT(pa);
+	uint32_t res;
+
+	bcm2835_mbox_write(iot, ioh, BCMMBOX_CHANARM2VC, KERN_VTOPHYS(&vb_uart));
+
+	bcm2835_mbox_read(iot, ioh, BCMMBOX_CHANARM2VC, &res);
+
+	cpu_dcache_inv_range((vaddr_t)&vb, sizeof(vb));
+
+	if (vcprop_tag_success_p(&vb_uart.vbt_uartclockrate.tag))
+		uart_clk = vb_uart.vbt_uartclockrate.rate;
+}
+
+
+
+static void
 rpi_bootparams(void)
 {
 	const paddr_t pa = BCM2835_PERIPHERALS_BUS_TO_PHYS(BCM2835_ARMMBOX_BASE);
@@ -596,6 +640,8 @@ initarm(void *arg)
 
 	cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
 
+	rpi_uartinit();
+
 	consinit();
 
 	/* Talk to the user */
@@ -704,7 +750,7 @@ consinit(void)
 	 */
 	rpi_pi.pi_iobase = consaddr;
 
-	plcomcnattach(&rpi_pi, plcomcnspeed, BCM2835_UART0_CLK,
+	plcomcnattach(&rpi_pi, plcomcnspeed, uart_clk,
 	    plcomcnmode, PLCOMCNUNIT);
 
 #endif
@@ -728,7 +774,7 @@ static kgdb_port_init(void)
 
 	rpi_pi.pi_iobase = consaddr;
 
-	res = plcom_kgdb_attach(&rpi_pi, KGDB_DEVRATE, BCM2835_UART0_CLK,
+	res = plcom_kgdb_attach(&rpi_pi, KGDB_DEVRATE, uart_clk,
 	    KGDB_CONMODE, KGDB_PLCOMUNIT);
 	if (res)
 		panic("KGDB uart can not be initialized, err=%d.", res);
@@ -1085,6 +1131,12 @@ rpi_device_register(device_t dev, void *
 	}
 #endif
 
+	if (device_is_a(dev, "plcom") &&
+	    vcprop_tag_success_p(&vb_uart.vbt_uartclockrate.tag) &&
+	    vb_uart.vbt_uartclockrate.rate > 0) {
+		prop_dictionary_set_uint32(dict,
+		    "frequency", vb_uart.vbt_uartclockrate.rate);
+	}
 	if (device_is_a(dev, "bcmdmac") &&
 	    vcprop_tag_success_p(&vb.vbt_dmachan.tag)) {
 		prop_dictionary_set_uint32(dict,

Reply via email to