X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=drivers%2Fserial%2Farm_dcc.c;h=dfcb6fd698122d4f38174f4d75dff465c57043f5;hb=c9baea6d0e96eb4bf55061d516e91e22236ed198;hp=c217c88e59aec10c47bb547520d5eb7a1e61906c;hpb=9a32084ea0cf55d22384f083002ee9932e074f31;p=oweals%2Fu-boot.git diff --git a/drivers/serial/arm_dcc.c b/drivers/serial/arm_dcc.c index c217c88e59..dfcb6fd698 100644 --- a/drivers/serial/arm_dcc.c +++ b/drivers/serial/arm_dcc.c @@ -1,19 +1,8 @@ +// SPDX-License-Identifier: GPL-2.0 /* * Copyright (C) 2004-2007 ARM Limited. * Copyright (C) 2008 Jean-Christophe PLAGNIOL-VILLARD - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Copyright (C) 2015 - 2016 Xilinx, Inc, Michal Simek * * As a special exception, if other files instantiate templates or use macros * or inline functions from this file, or you compile this file and link it @@ -27,11 +16,12 @@ */ #include -#include +#include +#include -#if defined(CONFIG_CPU_V6) +#if defined(CONFIG_CPU_V6) || defined(CONFIG_CPU_V7A) || defined(CONFIG_CPU_V7R) /* - * ARMV6 + * ARMV6 & ARMV7 */ #define DCC_RBIT (1 << 30) #define DCC_WBIT (1 << 29) @@ -61,6 +51,22 @@ #define status_dcc(x) \ __asm__ volatile ("mrc p14, 0, %0, c14, c0, 0\n" : "=r" (x)) +#elif defined(CONFIG_CPU_ARMV8) +/* + * ARMV8 + */ +#define DCC_RBIT (1 << 30) +#define DCC_WBIT (1 << 29) + +#define write_dcc(x) \ + __asm__ volatile ("msr dbgdtrtx_el0, %0\n" : : "r" (x)) + +#define read_dcc(x) \ + __asm__ volatile ("mrs %0, dbgdtrrx_el0\n" : "=r" (x)) + +#define status_dcc(x) \ + __asm__ volatile ("mrs %0, mdccsr_el0\n" : "=r" (x)) + #else #define DCC_RBIT (1 << 0) #define DCC_WBIT (1 << 1) @@ -89,12 +95,7 @@ #define TIMEOUT_COUNT 0x4000000 -int arm_dcc_init(void) -{ - return 0; -} - -int arm_dcc_getc(void) +static int arm_dcc_getc(struct udevice *dev) { int ch; register unsigned int reg; @@ -107,7 +108,7 @@ int arm_dcc_getc(void) return ch; } -void arm_dcc_putc(char ch) +static int arm_dcc_putc(struct udevice *dev, char ch) { register unsigned int reg; unsigned int timeout_count = TIMEOUT_COUNT; @@ -118,42 +119,56 @@ void arm_dcc_putc(char ch) break; } if (timeout_count == 0) - return; + return -EAGAIN; else write_dcc(ch); -} -void arm_dcc_puts(const char *s) -{ - while (*s) - arm_dcc_putc(*s++); + return 0; } -int arm_dcc_tstc(void) +static int arm_dcc_pending(struct udevice *dev, bool input) { register unsigned int reg; - can_read_dcc(reg); + if (input) { + can_read_dcc(reg); + } else { + can_write_dcc(reg); + } return reg; } -static struct stdio_dev arm_dcc_dev; +static const struct dm_serial_ops arm_dcc_ops = { + .putc = arm_dcc_putc, + .pending = arm_dcc_pending, + .getc = arm_dcc_getc, +}; -int drv_arm_dcc_init(void) +static const struct udevice_id arm_dcc_ids[] = { + { .compatible = "arm,dcc", }, + { } +}; + +U_BOOT_DRIVER(serial_dcc) = { + .name = "arm_dcc", + .id = UCLASS_SERIAL, + .of_match = arm_dcc_ids, + .ops = &arm_dcc_ops, +}; + +#ifdef CONFIG_DEBUG_UART_ARM_DCC + +#include + +static inline void _debug_uart_init(void) { - strcpy(arm_dcc_dev.name, "dcc"); - arm_dcc_dev.ext = 0; /* No extensions */ - arm_dcc_dev.flags = DEV_FLAGS_INPUT | DEV_FLAGS_OUTPUT; - arm_dcc_dev.tstc = arm_dcc_tstc; /* 'tstc' function */ - arm_dcc_dev.getc = arm_dcc_getc; /* 'getc' function */ - arm_dcc_dev.putc = arm_dcc_putc; /* 'putc' function */ - arm_dcc_dev.puts = arm_dcc_puts; /* 'puts' function */ - - return stdio_register(&arm_dcc_dev); } -__weak struct serial_device *default_serial_console(void) +static inline void _debug_uart_putc(int ch) { - return NULL; + arm_dcc_putc(NULL, ch); } + +DEBUG_UART_FUNCS +#endif