Use the VC property mailbox to request the UART clock rate and use it

appropriately

Newer firmwares use 48MHz
This commit is contained in:
skrll 2017-01-06 14:55:37 +00:00
parent 7ed3f784bc
commit 5dc9a27fcf
2 changed files with 66 additions and 6 deletions

View File

@ -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;

View File

@ -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, void *);
#define RPI_FB_HEIGHT 720
#endif
int uart_clk = BCM2835_UART0_CLK;
#define PLCONADDR BCM2835_UART0_BASE
#ifndef CONSDEVNAME
@ -175,6 +177,28 @@ static struct plcom_instance rpi_pi = {
/* Smallest amount of RAM start.elf could give us. */
#define RPI_MINIMUM_SPLIT (128U * 1024 * 1024)
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;
@ -390,6 +414,26 @@ static uint8_t cursor_mask[8 * 64], cursor_bitmap[8 * 64];
#endif
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)
{
@ -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 *aux)
}
#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,