powerpc/uart: Choose which UART to use at build time, not runtime.

Microwatt may have firmware that places data in r3, which was used to
detect microwatt vs powernv.  This breaks the existing probing of the UART
type in this powerpc port.

Instead build only the appropriate UART into the firmware, selected by
passing the option UART=potato or UART=lpc_serial to the Makefile.

A future enhancement would be to parse the device tree and configure
MicroPython based on the settings.
This commit is contained in:
Joel Stanley 2020-05-26 12:59:55 +09:30 committed by Damien George
parent 50a7ba2348
commit f03d030080
6 changed files with 38 additions and 96 deletions

View File

@ -6,6 +6,9 @@ QSTR_DEFS = qstrdefsport.h
# include py core make definitions # include py core make definitions
include $(TOP)/py/py.mk include $(TOP)/py/py.mk
# potato or lpc_serial
UART ?= potato
ARCH = $(shell uname -m) ARCH = $(shell uname -m)
ifneq ("$(ARCH)", "ppc64") ifneq ("$(ARCH)", "ppc64")
ifneq ("$(ARCH)", "ppc64le") ifneq ("$(ARCH)", "ppc64le")
@ -30,9 +33,7 @@ LIBS =
SRC_C = \ SRC_C = \
main.c \ main.c \
uart_core.c \ uart_$(UART).c \
uart_potato.c \
uart_lpc_serial.c \
lib/utils/printf.c \ lib/utils/printf.c \
lib/utils/stdout_helpers.c \ lib/utils/stdout_helpers.c \
lib/utils/pyexec.c \ lib/utils/pyexec.c \

View File

@ -6,10 +6,14 @@ potato UART.
## Building ## Building
By default the port will be built for the host machine: By default the port will be built with the potato uart for microwatt:
$ make $ make
To instead build for a machine with LPC serial, such as QEMU powernv:
$ make UART=lpc_serial
## Cross compilation for POWERPC ## Cross compilation for POWERPC
If you need to cross compilers you'll want to grab a powerpc64le If you need to cross compilers you'll want to grab a powerpc64le

View File

@ -65,7 +65,6 @@ int main(int argc, char **argv) {
int stack_dummy; int stack_dummy;
stack_top = (char *)&stack_dummy; stack_top = (char *)&stack_dummy;
// microwatt has argc/r3 = 0 whereas QEMU has r3 set in head.S
uart_init_ppc(argc); uart_init_ppc(argc);
#if MICROPY_ENABLE_PYSTACK #if MICROPY_ENABLE_PYSTACK

View File

@ -1,73 +0,0 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2019, Michael Neuling, IBM Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <unistd.h>
#include <stdbool.h>
#include "py/mpconfig.h"
#include "uart_potato.h"
#include "uart_lpc_serial.h"
static int lpc_console;
static int potato_console;
void uart_init_ppc(int lpc) {
lpc_console = lpc;
if (!lpc_console) {
potato_console = 1;
potato_uart_init();
} else {
lpc_uart_init();
}
}
// Receive single character
int mp_hal_stdin_rx_chr(void) {
unsigned char c = 0;
if (lpc_console) {
c = lpc_uart_read();
} else if (potato_console) {
c = potato_uart_read();
}
return c;
}
// Send string of given length
void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
if (lpc_console) {
int i;
for (i = 0; i < len; i++) {
lpc_uart_write(str[i]);
}
} else if (potato_console) {
int i;
for (i = 0; i < len; i++) {
potato_uart_write(str[i]);
}
}
}

View File

@ -96,20 +96,24 @@ static int lpc_uart_rx_empty(void) {
return !(lpc_uart_reg_read(REG_LSR) & LSR_DR); return !(lpc_uart_reg_read(REG_LSR) & LSR_DR);
} }
void lpc_uart_init(void) { void uart_init_ppc(void) {
lpc_uart_base = LPC_UART_BASE; lpc_uart_base = LPC_UART_BASE;
} }
char lpc_uart_read(void) { int mp_hal_stdin_rx_chr(void) {
while (lpc_uart_rx_empty()) { while (lpc_uart_rx_empty()) {
; ;
} }
return lpc_uart_reg_read(REG_THR); return lpc_uart_reg_read(REG_THR);
} }
void lpc_uart_write(char c) {
void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
int i;
for (i = 0; i < len; i++) {
while (lpc_uart_tx_full()) { while (lpc_uart_tx_full()) {
; ;
} }
lpc_uart_reg_write(REG_RBR, c); lpc_uart_reg_write(REG_RBR, str[i]);
}
} }

View File

@ -34,10 +34,12 @@
#include <stdbool.h> #include <stdbool.h>
#include "py/mpconfig.h" #include "py/mpconfig.h"
#define PROC_FREQ 50000000 #define SYSCON_BASE 0xc0000000 /* System control regs */
#define SYS_REG_CLKINFO 0x20
#define UART_FREQ 115200 #define UART_FREQ 115200
#define POTATO_UART_BASE 0xc0002000 #define POTATO_UART_BASE 0xc0002000
uint64_t potato_uart_base; static uint64_t potato_uart_base;
#define POTATO_CONSOLE_TX 0x00 #define POTATO_CONSOLE_TX 0x00
#define POTATO_CONSOLE_RX 0x08 #define POTATO_CONSOLE_RX 0x08
@ -60,7 +62,7 @@ static uint64_t potato_uart_reg_read(int offset) {
return val; return val;
} }
void potato_uart_reg_write(int offset, uint64_t val) { static void potato_uart_reg_write(int offset, uint64_t val) {
uint64_t addr; uint64_t addr;
addr = potato_uart_base + offset; addr = potato_uart_base + offset;
@ -96,13 +98,16 @@ static unsigned long potato_uart_divisor(unsigned long proc_freq, unsigned long
return proc_freq / (uart_freq * 16) - 1; return proc_freq / (uart_freq * 16) - 1;
} }
void potato_uart_init(void) { void uart_init_ppc(void) {
uint64_t proc_freq;
potato_uart_base = POTATO_UART_BASE; potato_uart_base = POTATO_UART_BASE;
potato_uart_reg_write(POTATO_CONSOLE_CLOCK_DIV, potato_uart_divisor(PROC_FREQ, UART_FREQ)); proc_freq = *(volatile uint64_t *)(SYSCON_BASE + SYS_REG_CLKINFO);
potato_uart_reg_write(POTATO_CONSOLE_CLOCK_DIV, potato_uart_divisor(proc_freq, UART_FREQ));
} }
char potato_uart_read(void) { int mp_hal_stdin_rx_chr(void) {
uint64_t val; uint64_t val;
while (potato_uart_rx_empty()) { while (potato_uart_rx_empty()) {
@ -113,13 +118,15 @@ char potato_uart_read(void) {
return (char)(val & 0x000000ff); return (char)(val & 0x000000ff);
} }
void potato_uart_write(char c) { void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
uint64_t val; int i;
val = c; for (i = 0; i < len; i++) {
uint64_t val = str[i];
while (potato_uart_tx_full()) { while (potato_uart_tx_full()) {
; ;
} }
potato_uart_reg_write(POTATO_CONSOLE_TX, val); potato_uart_reg_write(POTATO_CONSOLE_TX, val);
} }
}