blob: 0138f115c9c90297ff1d9c45bc90d5c63cdeee49 [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.
lijuang84dedfe2019-11-05 19:00:37 +08004 * Copyright (c) 2009-2016, 2018-2019, 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>
Maria Yu43bd26e2018-05-11 13:51:36 +080041#include <arch/ops.h>
Brian Swetland2500aa12009-01-01 04:33:55 -080042
Matthew Qin50341de2014-02-25 17:19:19 +080043#if PON_VIB_SUPPORT
44#include <vibrator.h>
45#endif
46
vijay kumarcb5499d2015-05-04 14:55:21 +053047
Deepa Dinamani72125892013-05-06 16:50:38 -070048static void write_dcc(char c)
49{
50 uint32_t timeout = 10;
51
52 /* Note: Smallest sampling rate for DCC is 50us.
53 * This can be changed by SNOOPer.Rate on T32 window.
54 */
55 while (timeout)
56 {
57 if (dcc_putc(c) == 0)
58 break;
59 udelay(50);
60 timeout--;
61 }
62}
Pavel Nedev94eaaad2013-06-10 14:50:59 +030063
64#if WITH_DEBUG_LOG_BUF
65
66#ifndef LK_LOG_BUF_SIZE
67#define LK_LOG_BUF_SIZE (4096) /* align on 4k */
68#endif
69
70#define LK_LOG_COOKIE 0x474f4c52 /* "RLOG" in ASCII */
71
72struct lk_log {
73 struct lk_log_header {
74 unsigned cookie;
75 unsigned max_size;
76 unsigned size_written;
77 unsigned idx;
78 } header;
79 char data[LK_LOG_BUF_SIZE];
80};
81
82static struct lk_log log = {
83 .header = {
84 .cookie = LK_LOG_COOKIE,
85 .max_size = sizeof(log.data),
86 .size_written = 0,
87 .idx = 0,
88 },
89 .data = {0}
90};
91
92static void log_putc(char c)
93{
94 log.data[log.header.idx++] = c;
95 log.header.size_written++;
96 if (unlikely(log.header.idx >= log.header.max_size))
97 log.header.idx = 0;
98}
99#endif /* WITH_DEBUG_LOG_BUF */
100
vijay kumarcb5499d2015-05-04 14:55:21 +0530101void display_fbcon_message(char *str)
102{
103#if ENABLE_FBCON_LOGGING
104 while(*str != 0) {
lijuang84dedfe2019-11-05 19:00:37 +0800105 fbcon_putc(*str++, 0);
vijay kumarcb5499d2015-05-04 14:55:21 +0530106 }
107#endif
108}
109
Brian Swetland2500aa12009-01-01 04:33:55 -0800110void _dputc(char c)
111{
Pavel Nedev94eaaad2013-06-10 14:50:59 +0300112#if WITH_DEBUG_LOG_BUF
113 log_putc(c);
114#endif
Brian Swetlandddf61a22009-01-29 20:46:14 -0800115#if WITH_DEBUG_DCC
Brian Swetland2500aa12009-01-01 04:33:55 -0800116 if (c == '\n') {
Deepa Dinamani72125892013-05-06 16:50:38 -0700117 write_dcc('\r');
Brian Swetland2500aa12009-01-01 04:33:55 -0800118 }
Deepa Dinamani72125892013-05-06 16:50:38 -0700119 write_dcc(c) ;
Brian Swetland2500aa12009-01-01 04:33:55 -0800120#endif
Brian Swetlandddf61a22009-01-29 20:46:14 -0800121#if WITH_DEBUG_UART
122 uart_putc(0, c);
123#endif
124#if WITH_DEBUG_FBCON && WITH_DEV_FBCON
lijuang84dedfe2019-11-05 19:00:37 +0800125 fbcon_putc(c, 0);
Dima Zavin6e274c22009-01-28 17:28:41 -0800126#endif
Ajay Dudani168f6cb2009-12-07 19:04:02 -0800127#if WITH_DEBUG_JTAG
128 jtag_dputc(c);
129#endif
Brian Swetland2500aa12009-01-01 04:33:55 -0800130}
131
Travis Geiselbrechtdbc2c682009-06-28 12:18:39 -0700132int dgetc(char *c, bool wait)
Brian Swetland2500aa12009-01-01 04:33:55 -0800133{
Brian Swetlandc82fda92009-01-02 01:53:42 -0800134 int n;
Brian Swetlandddf61a22009-01-29 20:46:14 -0800135#if WITH_DEBUG_DCC
Brian Swetlandc82fda92009-01-02 01:53:42 -0800136 n = dcc_getc();
Brian Swetlandddf61a22009-01-29 20:46:14 -0800137#elif WITH_DEBUG_UART
138 n = uart_getc(0, 0);
Brian Swetlandc82fda92009-01-02 01:53:42 -0800139#else
Brian Swetlandddf61a22009-01-29 20:46:14 -0800140 n = -1;
Brian Swetlandc82fda92009-01-02 01:53:42 -0800141#endif
Brian Swetland2500aa12009-01-01 04:33:55 -0800142 if (n < 0) {
143 return -1;
144 } else {
145 *c = n;
146 return 0;
147 }
Brian Swetland2500aa12009-01-01 04:33:55 -0800148}
149
150void platform_halt(void)
151{
Matthew Qin50341de2014-02-25 17:19:19 +0800152#if PON_VIB_SUPPORT
153 vib_turn_off();
154#endif
lijuang395b5e62015-11-19 17:39:44 +0800155 dprintf(CRITICAL, "HALT: reboot into dload mode...\n");
Maria Yu43bd26e2018-05-11 13:51:36 +0800156 arch_clean_cache_range(MEMBASE, MEMSIZE);
lijuang395b5e62015-11-19 17:39:44 +0800157 reboot_device(NORMAL_DLOAD);
158
Pavel Nedev420ecf52013-05-14 14:04:22 +0300159 dprintf(CRITICAL, "HALT: spinning forever...\n");
Ajay Dudanib01e5062011-12-03 23:23:42 -0800160 for (;;) ;
Brian Swetland2500aa12009-01-01 04:33:55 -0800161}