ARM: tegra: Introduce define DEBUG_UART_SHIFT
Subsystems (3)
PATCH v2 1/4 ARM: tegra: Introduce define DEBUG_UART_SHIFT
From: Doug Anderson <[email protected]>
This removes the need for the variable "shift" in all functions in uncompress.h.
---
This patch series depends on patch "[PATCH V2] arm/tegra: Support Tegra30 in decompressor UART setup" for context.
This series allows a Tegra zImage to automatically select the UART to use for the zImage decompressor and early printk, based on information from the bootloader. The code scans each UART, looking for one that is clocked, is out of reset, and that the bootloader has written 'D' (for 'D'ebug) to the scratch register.
At present, the ChromiumOS branch of U-Boot sets up UARTs in this way. If this patch is accepted into the kernel, I'll upstream the U-Boot change to mainline U-Boot.
This is important, since different boards use different UARTs, and it's nice not to have to configure the kernel differently when switching boards.
arch/arm/mach-tegra/include/mach/uncompress.h | 18 ++++++++++-------- 1 files changed, 10 insertions(+), 8 deletions(-)
arch/arm/mach-tegra/include/mach/uncompress.h +10 -8
@@ -2,10 +2,12 @@* arch/arm/mach-tegra/include/mach/uncompress.h * * Copyright (C) 2010 Google, Inc. +* Copyright (C) 2011 Google, Inc. * * Author: * Colin Cross <[email protected]> * Erik Gilling <[email protected]> +* Doug Anderson <[email protected]> * * This software is licensed under the terms of the GNU General Public * License version 2, as published by the Free Software Foundation, and
@@ -26,17 +28,18 @@#include <mach/iomap.h> +#define DEBUG_UART_SHIFT 2 +static void putc (int c) {volatile u8 *uart = (volatile u8 *)TEGRA_DEBUG_UART_BASE ; -int shift =2 ;if (uart ==NULL )return ; -while (!(uart[UART_LSR << shift] &UART_LSR_THRE )) +while (!(uart[UART_LSR <<DEBUG_UART_SHIFT ] &UART_LSR_THRE ))barrier (); - uart[UART_TX << shift] = c; + uart[UART_TX <<DEBUG_UART_SHIFT ] = c; }static inline void flush (void )
@@ -48,7 +51,6 @@ static inline void arch_decomp_setup(void)volatile u32 *apb_misc = (volatile u32 *)TEGRA_APB_MISC_BASE ;u32 chip, div;volatile u8 *uart = (volatile u8 *)TEGRA_DEBUG_UART_BASE ; -int shift =2 ;if (uart ==NULL )return ;
@@ -59,10 +61,10 @@ static inline void arch_decomp_setup(void)else div =0x00dd ; - uart[UART_LCR << shift] |=UART_LCR_DLAB ; - uart[UART_DLL << shift] = div &0xff ; - uart[UART_DLM << shift] = div >>8 ; - uart[UART_LCR << shift] =3 ; + uart[UART_LCR <<DEBUG_UART_SHIFT ] |=UART_LCR_DLAB ; + uart[UART_DLL <<DEBUG_UART_SHIFT ] = div &0xff ; + uart[UART_DLM <<DEBUG_UART_SHIFT ] = div >>8 ; + uart[UART_LCR <<DEBUG_UART_SHIFT ] =3 ; }static inline void arch_decomp_wdog (void )
Signature · 1 line
1.7.0.4
PATCH v2 2/4 ARM: tegra: uncompress.h: Store UART address in a variable
From: Doug Anderson <[email protected]>
This will allow a future change to auto-detect which UART to use.
--- arch/arm/mach-tegra/include/mach/uncompress.h | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
arch/arm/mach-tegra/include/mach/uncompress.h +3 -3
@@ -30,10 +30,10 @@#define DEBUG_UART_SHIFT 2 +volatile u8 *uart; +static void putc (int c) { -volatile u8 *uart = (volatile u8 *)TEGRA_DEBUG_UART_BASE ; -if (uart ==NULL )return ;
@@ -50,8 +50,8 @@ static inline void arch_decomp_setup(void) {volatile u32 *apb_misc = (volatile u32 *)TEGRA_APB_MISC_BASE ;u32 chip, div; -volatile u8 *uart = (volatile u8 *)TEGRA_DEBUG_UART_BASE ; + uart = (volatile u8 *)TEGRA_DEBUG_UART_BASE ;if (uart ==NULL )return ;
Signature · 1 line
1.7.0.4
PATCH v2 3/4 ARM: tegra: uncompress.h: Choose a UART at runtime
In reply to Stephen WarrenWith this change we automatically detect which UART to use for for printing during decompression. The detection involves coordination with the bootloader: it's expected that the bootloader will leave a 'D' (for [D]ebug) in the UART scratchpad register for whichever UART we should use for debugging.
If we don't find any such UART, we fall back to the UART that was specified during config time: CONFIG_TEGRA_DEBUG_UART_XXX.
As a side effect of this change, uncompress debug messages will work if you've specified CONFIG_TEGRA_DEBUG_UART_NONE, provided the bootloader obeys the protocol.
This change is in line with what is documented inDocumentation/arm/Booting.
Other approaches considered:
* Hardcode based on machine ID (as many other ARM boards do). OK, but nice to not have yet another place to add per-board code. Better to have bootloader parse device tree and pass us this info.
* Check for TXE bit (like SA1110). Nice (and doesn't require a bootloader change), but a little less explicit. Also: if bootloader (for some reason) uses another UART, it needs to remember to turn it off before jumping to the kernel or we may print to it. NOTE: adapting this patch to check TXE too would be easy if desired.
---
v2: Include <linux/kernel.h>
--- arch/arm/mach-tegra/include/mach/uncompress.h | 75 ++++++++++++++++++++++++- 1 files changed, 74 insertions(+), 1 deletions(-)
arch/arm/mach-tegra/include/mach/uncompress.h +74 -1
@@ -3,11 +3,13 @@* * Copyright (C) 2010 Google, Inc. * Copyright (C) 2011 Google, Inc. +* Copyright (C) 2011 NVIDIA CORPORATION. All Rights Reserved. * * Author: * Colin Cross <[email protected]> * Erik Gilling <[email protected]> * Doug Anderson <[email protected]> +* Stephen Warren <[email protected]> * * This software is licensed under the terms of the GNU General Public * License version 2, as published by the Free Software Foundation, and
@@ -23,6 +25,7 @@#ifndef __MACH_TEGRA_UNCOMPRESS_H#define __MACH_TEGRA_UNCOMPRESS_H +#include <linux/kernel.h> #include <linux/types.h> #include <linux/serial_reg.h>
@@ -46,12 +49,82 @@ static inline void flush(void) { } +/* +* Setup before decompression. This is where we do UART selection for +* earlyprintk and init the uart_base register. +*/ static inline void arch_decomp_setup (void ) { +static const struct { +u32 base; +u32 reset_reg; +u32 clock_reg; +u32 bit; + } uarts[] = { + { +TEGRA_UARTA_BASE , +TEGRA_CLK_RESET_BASE +0x04 , +TEGRA_CLK_RESET_BASE +0x10 , +6 , + }, + { +TEGRA_UARTB_BASE , +TEGRA_CLK_RESET_BASE +0x04 , +TEGRA_CLK_RESET_BASE +0x10 , +7 , + }, + { +TEGRA_UARTC_BASE , +TEGRA_CLK_RESET_BASE +0x08 , +TEGRA_CLK_RESET_BASE +0x14 , +23 , + }, + { +TEGRA_UARTD_BASE , +TEGRA_CLK_RESET_BASE +0x0c , +TEGRA_CLK_RESET_BASE +0x18 , +1 , + }, + { +TEGRA_UARTE_BASE , +TEGRA_CLK_RESET_BASE +0x0c , +TEGRA_CLK_RESET_BASE +0x18 , +2 , + }, + }; +int i;volatile u32 *apb_misc = (volatile u32 *)TEGRA_APB_MISC_BASE ;u32 chip, div; - uart = (volatile u8 *)TEGRA_DEBUG_UART_BASE ; +/* +* Look for the first UART that: +* a) Is not in reset. +* b) Is clocked. +* c) Has a 'D' in the scratchpad register. +* +* Note that on Tegra30, the first two conditions are required, since +* if not true, accesses to the UART scratch register will hang. +* Tegra20 doesn't have this issue. +* +* The intent is that the bootloader will tell the kernel which UART +* to use by setting up those conditions. If nothing found, we'll fall +* back to what's specified in TEGRA_DEBUG_UART_BASE. +*/ +for (i =0 ; i <ARRAY_SIZE (uarts); i++) { +if (*(u8 *)uarts[i].reset_reg &BIT (uarts[i].bit)) +continue ; + +if (!(*(u8 *)uarts[i].clock_reg &BIT (uarts[i].bit))) +continue ; + + uart = (volatile u8 *)uarts[i].base; +if (uart[UART_SCR <<DEBUG_UART_SHIFT ] !='D' ) +continue ; + +break ; + } +if (i ==ARRAY_SIZE (uarts)) + uart = (volatile u8 *)TEGRA_DEBUG_UART_BASE ;if (uart ==NULL )return ;
Signature · 1 line
1.7.0.4
PATCH v2 4/4 ARM: tegra: Pass uncompress.h UART selection to DEBUG_LL
In reply to Stephen Warrenuncompress.h now saves the selected UART's physical address in Tegra's IRAM, along with a cookie to indicate validity.
The first time it's run, macro addruart in debug-macro.S looks for this cookie, and if it's present, uses the UART address stored there. If not, the static value TEGRA_DEBUG_UART_BASE is used, as was previous behaviour. The static behaviour will thus be used when not booting using a zImage.
This work was inspired by work by Doug Anderson <[email protected]>; see http://lkml.org/lkml/2011/9/26/284. However, this patch relies on the data passing describe above, rather than duplicating the UART selection logic in debug-macro.S; the latest selection logic is more complex due to the need to check reset/clock bits too.
---
v2: Created <mach/irammap.h> to document IRAM usage.
--- arch/arm/mach-tegra/common.c | 17 +++++ arch/arm/mach-tegra/include/mach/debug-macro.S | 88 +++++++++++++++++++++--- arch/arm/mach-tegra/include/mach/irammap.h | 35 +++++++++ arch/arm/mach-tegra/include/mach/uncompress.h | 15 ++++- 4 files changed, 143 insertions(+), 12 deletions(-) create mode 100644 arch/arm/mach-tegra/include/mach/irammap.h
arch/arm/mach-tegra/common.c +17 -0
@@ -32,6 +32,23 @@#include "clock.h" #include "fuse.h" +/* +* Storage for debug-macro.S's state. +* +* This must be in .data not .bss so that it gets initialized each time the +* kernel is loaded. The data is declared here rather than debug-macro.S so +* that multiple inclusions of debug-macro.S point at the same data. +*/ +#define TEGRA_DEBUG_UART_OFFSET (TEGRA_DEBUG_UART_BASE & 0xFFFF) +u32 tegra_uart_config[3 ] = { +/* Debug UART initialization required */ +1 , +/* Debug UART physical address */ + (u32)(IO_APB_PHYS +TEGRA_DEBUG_UART_OFFSET ), +/* Debug UART virtual address */ + (u32)(IO_APB_VIRT +TEGRA_DEBUG_UART_OFFSET ), +}; +#ifdef CONFIG_OF static const struct of_device_id tegra_dt_irq_match[]__initconst = { { .compatible = "arm,cortex-a9-gic", .data = gic_of_init },
arch/arm/mach-tegra/include/mach/debug-macro.S +77 -11
106 lines not on this page · raw message
arch/arm/mach-tegra/include/mach/irammap.h new file +35 -0
@@ -0,0 +1,35 @@ +/* +* Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved. +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope 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, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef __MACH_TEGRA_IRAMMAP_H +#define __MACH_TEGRA_IRAMMAP_H + +#include <asm/sizes.h> + +/* The first 1K of IRAM is permanently reserved for the CPU reset handler */ +#define TEGRA_IRAM_RESET_HANDLER_OFFSET 0 +#define TEGRA_IRAM_RESET_HANDLER_SIZE SZ_1K + +/* +* These locations are written to by uncompress.h, and read by debug-macro.S. +* The first word holds the cookie value if the data is valid. The second +* word holds the UART physical address. +*/ +#define TEGRA_IRAM_DEBUG_UART_OFFSET SZ_1K +#define TEGRA_IRAM_DEBUG_UART_SIZE 8 +#define TEGRA_IRAM_DEBUG_UART_COOKIE 0x55415254 + +#endif
arch/arm/mach-tegra/include/mach/uncompress.h +14 -1
@@ -3,7 +3,7 @@* * Copyright (C) 2010 Google, Inc. * Copyright (C) 2011 Google, Inc. -* Copyright (C) 2011 NVIDIA CORPORATION. All Rights Reserved. +* Copyright (C) 2011-2012 NVIDIA CORPORATION. All Rights Reserved. * * Author: * Colin Cross <[email protected]>
@@ -30,6 +30,7 @@#include <linux/serial_reg.h> #include <mach/iomap.h> +#include <mach/irammap.h> #define DEBUG_UART_SHIFT 2
@@ -49,6 +50,17 @@ static inline void flush(void) { } +static inline void save_uart_address (void ) +{ +u32 *buf = (u32 *)(TEGRA_IRAM_BASE +TEGRA_IRAM_DEBUG_UART_OFFSET ); + +if (uart) { + buf[0 ] =TEGRA_IRAM_DEBUG_UART_COOKIE ; + buf[1 ] = (u32 )uart; + }else + buf[0 ] =0 ; +} +/* * Setup before decompression. This is where we do UART selection for * earlyprintk and init the uart_base register.
@@ -125,6 +137,7 @@ static inline void arch_decomp_setup(void) }if (i ==ARRAY_SIZE (uarts)) uart = (volatile u8 *)TEGRA_DEBUG_UART_BASE ; +save_uart_address ();if (uart ==NULL )return ;
Signature · 1 line
1.7.0.4
PATCH v2 1/4 ARM: tegra: Introduce define DEBUG_UART_SHIFT
In reply to Stephen WarrenQuoted 9 lines · Stephen Warren
From: Doug Anderson <[email protected]>
This removes the need for the variable "shift" in all functions in
uncompress.h.Signed-off-by Doug Anderson <[email protected]>[swarren: Extracted from a larger patch by Doug]Signed-off-by Stephen Warren <[email protected]>
For the series (patch V2 1-4):
Thank you again!
-Doug