blob: 3349db7eef83ec4b24e2cfcf7e2b9e6a73b65f3b [file] [log] [blame]
Brian Swetland2500aa12009-01-01 04:33:55 -08001/*
Brian Swetlandddf61a22009-01-29 20:46:14 -08002 * Copyright (c) 2009, Google Inc.
Brian Swetland2500aa12009-01-01 04:33:55 -08003 * All rights reserved.
Deepa Dinamani72125892013-05-06 16:50:38 -07004 * Copyright (c) 2009-2013, The Linux Foundation. All rights reserved.
Brian Swetland2500aa12009-01-01 04:33:55 -08005 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 * * Neither the name of Google, Inc. nor the names of its contributors
16 * may be used to endorse or promote products derived from this
17 * software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
29 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
Pavel Nedev94eaaad2013-06-10 14:50:59 +030033#include <stdlib.h>
Brian Swetland2500aa12009-01-01 04:33:55 -080034#include <debug.h>
35#include <printf.h>
36#include <arch/arm/dcc.h>
Dima Zavin6e274c22009-01-28 17:28:41 -080037#include <dev/fbcon.h>
Brian Swetland2500aa12009-01-01 04:33:55 -080038#include <dev/uart.h>
Deepa Dinamani72125892013-05-06 16:50:38 -070039#include <platform/timer.h>
Pavel Nedev420ecf52013-05-14 14:04:22 +030040#include <platform.h>
Brian Swetland2500aa12009-01-01 04:33:55 -080041
Deepa Dinamani72125892013-05-06 16:50:38 -070042static void write_dcc(char c)
43{
44 uint32_t timeout = 10;
45
46 /* Note: Smallest sampling rate for DCC is 50us.
47 * This can be changed by SNOOPer.Rate on T32 window.
48 */
49 while (timeout)
50 {
51 if (dcc_putc(c) == 0)
52 break;
53 udelay(50);
54 timeout--;
55 }
56}
Pavel Nedev94eaaad2013-06-10 14:50:59 +030057
58#if WITH_DEBUG_LOG_BUF
59
60#ifndef LK_LOG_BUF_SIZE
61#define LK_LOG_BUF_SIZE (4096) /* align on 4k */
62#endif
63
64#define LK_LOG_COOKIE 0x474f4c52 /* "RLOG" in ASCII */
65
66struct lk_log {
67 struct lk_log_header {
68 unsigned cookie;
69 unsigned max_size;
70 unsigned size_written;
71 unsigned idx;
72 } header;
73 char data[LK_LOG_BUF_SIZE];
74};
75
76static struct lk_log log = {
77 .header = {
78 .cookie = LK_LOG_COOKIE,
79 .max_size = sizeof(log.data),
80 .size_written = 0,
81 .idx = 0,
82 },
83 .data = {0}
84};
85
86static void log_putc(char c)
87{
88 log.data[log.header.idx++] = c;
89 log.header.size_written++;
90 if (unlikely(log.header.idx >= log.header.max_size))
91 log.header.idx = 0;
92}
93#endif /* WITH_DEBUG_LOG_BUF */
94
Brian Swetland2500aa12009-01-01 04:33:55 -080095void _dputc(char c)
96{
Pavel Nedev94eaaad2013-06-10 14:50:59 +030097#if WITH_DEBUG_LOG_BUF
98 log_putc(c);
99#endif
Brian Swetlandddf61a22009-01-29 20:46:14 -0800100#if WITH_DEBUG_DCC
Brian Swetland2500aa12009-01-01 04:33:55 -0800101 if (c == '\n') {
Deepa Dinamani72125892013-05-06 16:50:38 -0700102 write_dcc('\r');
Brian Swetland2500aa12009-01-01 04:33:55 -0800103 }
Deepa Dinamani72125892013-05-06 16:50:38 -0700104 write_dcc(c) ;
Brian Swetland2500aa12009-01-01 04:33:55 -0800105#endif
Brian Swetlandddf61a22009-01-29 20:46:14 -0800106#if WITH_DEBUG_UART
107 uart_putc(0, c);
108#endif
109#if WITH_DEBUG_FBCON && WITH_DEV_FBCON
Dima Zavin6e274c22009-01-28 17:28:41 -0800110 fbcon_putc(c);
111#endif
Ajay Dudani168f6cb2009-12-07 19:04:02 -0800112#if WITH_DEBUG_JTAG
113 jtag_dputc(c);
114#endif
Brian Swetland2500aa12009-01-01 04:33:55 -0800115}
116
Travis Geiselbrechtdbc2c682009-06-28 12:18:39 -0700117int dgetc(char *c, bool wait)
Brian Swetland2500aa12009-01-01 04:33:55 -0800118{
Brian Swetlandc82fda92009-01-02 01:53:42 -0800119 int n;
Brian Swetlandddf61a22009-01-29 20:46:14 -0800120#if WITH_DEBUG_DCC
Brian Swetlandc82fda92009-01-02 01:53:42 -0800121 n = dcc_getc();
Brian Swetlandddf61a22009-01-29 20:46:14 -0800122#elif WITH_DEBUG_UART
123 n = uart_getc(0, 0);
Brian Swetlandc82fda92009-01-02 01:53:42 -0800124#else
Brian Swetlandddf61a22009-01-29 20:46:14 -0800125 n = -1;
Brian Swetlandc82fda92009-01-02 01:53:42 -0800126#endif
Brian Swetland2500aa12009-01-01 04:33:55 -0800127 if (n < 0) {
128 return -1;
129 } else {
130 *c = n;
131 return 0;
132 }
Brian Swetland2500aa12009-01-01 04:33:55 -0800133}
134
135void platform_halt(void)
136{
Pavel Nedev420ecf52013-05-14 14:04:22 +0300137 if (set_download_mode(NORMAL_DLOAD) == 0)
138 {
139 dprintf(CRITICAL, "HALT: reboot into dload mode...\n");
140 reboot_device(0);
141 dprintf(CRITICAL, "HALT: reboot_device failed\n");
142 }
143 else
144 {
145 dprintf(CRITICAL, "HALT: set_download_mode not supported\n");
146 }
147 dprintf(CRITICAL, "HALT: spinning forever...\n");
Ajay Dudanib01e5062011-12-03 23:23:42 -0800148 for (;;) ;
Brian Swetland2500aa12009-01-01 04:33:55 -0800149}