Brian Swetland | 2500aa1 | 2009-01-01 04:33:55 -0800 | [diff] [blame] | 1 | /* |
Brian Swetland | ddf61a2 | 2009-01-29 20:46:14 -0800 | [diff] [blame] | 2 | * Copyright (c) 2009, Google Inc. |
Brian Swetland | 2500aa1 | 2009-01-01 04:33:55 -0800 | [diff] [blame] | 3 | * All rights reserved. |
Matthew Qin | 7791fe8 | 2014-02-25 17:19:19 +0800 | [diff] [blame] | 4 | * Copyright (c) 2009-2014, The Linux Foundation. All rights reserved. |
Brian Swetland | 2500aa1 | 2009-01-01 04:33:55 -0800 | [diff] [blame] | 5 | * |
| 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 Nedev | 94eaaad | 2013-06-10 14:50:59 +0300 | [diff] [blame] | 33 | #include <stdlib.h> |
Brian Swetland | 2500aa1 | 2009-01-01 04:33:55 -0800 | [diff] [blame] | 34 | #include <debug.h> |
| 35 | #include <printf.h> |
| 36 | #include <arch/arm/dcc.h> |
Dima Zavin | 6e274c2 | 2009-01-28 17:28:41 -0800 | [diff] [blame] | 37 | #include <dev/fbcon.h> |
Brian Swetland | 2500aa1 | 2009-01-01 04:33:55 -0800 | [diff] [blame] | 38 | #include <dev/uart.h> |
Deepa Dinamani | 7212589 | 2013-05-06 16:50:38 -0700 | [diff] [blame] | 39 | #include <platform/timer.h> |
Pavel Nedev | 420ecf5 | 2013-05-14 14:04:22 +0300 | [diff] [blame] | 40 | #include <platform.h> |
Brian Swetland | 2500aa1 | 2009-01-01 04:33:55 -0800 | [diff] [blame] | 41 | |
Matthew Qin | 7791fe8 | 2014-02-25 17:19:19 +0800 | [diff] [blame] | 42 | #if PON_VIB_SUPPORT |
| 43 | #include <vibrator.h> |
| 44 | #endif |
| 45 | |
Deepa Dinamani | 7212589 | 2013-05-06 16:50:38 -0700 | [diff] [blame] | 46 | static void write_dcc(char c) |
| 47 | { |
| 48 | uint32_t timeout = 10; |
| 49 | |
| 50 | /* Note: Smallest sampling rate for DCC is 50us. |
| 51 | * This can be changed by SNOOPer.Rate on T32 window. |
| 52 | */ |
| 53 | while (timeout) |
| 54 | { |
| 55 | if (dcc_putc(c) == 0) |
| 56 | break; |
| 57 | udelay(50); |
| 58 | timeout--; |
| 59 | } |
| 60 | } |
Pavel Nedev | 94eaaad | 2013-06-10 14:50:59 +0300 | [diff] [blame] | 61 | |
| 62 | #if WITH_DEBUG_LOG_BUF |
| 63 | |
| 64 | #ifndef LK_LOG_BUF_SIZE |
| 65 | #define LK_LOG_BUF_SIZE (4096) /* align on 4k */ |
| 66 | #endif |
| 67 | |
| 68 | #define LK_LOG_COOKIE 0x474f4c52 /* "RLOG" in ASCII */ |
| 69 | |
| 70 | struct lk_log { |
| 71 | struct lk_log_header { |
| 72 | unsigned cookie; |
| 73 | unsigned max_size; |
| 74 | unsigned size_written; |
| 75 | unsigned idx; |
| 76 | } header; |
| 77 | char data[LK_LOG_BUF_SIZE]; |
| 78 | }; |
| 79 | |
| 80 | static struct lk_log log = { |
| 81 | .header = { |
| 82 | .cookie = LK_LOG_COOKIE, |
| 83 | .max_size = sizeof(log.data), |
| 84 | .size_written = 0, |
| 85 | .idx = 0, |
| 86 | }, |
| 87 | .data = {0} |
| 88 | }; |
| 89 | |
| 90 | static void log_putc(char c) |
| 91 | { |
| 92 | log.data[log.header.idx++] = c; |
| 93 | log.header.size_written++; |
| 94 | if (unlikely(log.header.idx >= log.header.max_size)) |
| 95 | log.header.idx = 0; |
| 96 | } |
| 97 | #endif /* WITH_DEBUG_LOG_BUF */ |
| 98 | |
Brian Swetland | 2500aa1 | 2009-01-01 04:33:55 -0800 | [diff] [blame] | 99 | void _dputc(char c) |
| 100 | { |
Pavel Nedev | 94eaaad | 2013-06-10 14:50:59 +0300 | [diff] [blame] | 101 | #if WITH_DEBUG_LOG_BUF |
| 102 | log_putc(c); |
| 103 | #endif |
Brian Swetland | ddf61a2 | 2009-01-29 20:46:14 -0800 | [diff] [blame] | 104 | #if WITH_DEBUG_DCC |
Brian Swetland | 2500aa1 | 2009-01-01 04:33:55 -0800 | [diff] [blame] | 105 | if (c == '\n') { |
Deepa Dinamani | 7212589 | 2013-05-06 16:50:38 -0700 | [diff] [blame] | 106 | write_dcc('\r'); |
Brian Swetland | 2500aa1 | 2009-01-01 04:33:55 -0800 | [diff] [blame] | 107 | } |
Deepa Dinamani | 7212589 | 2013-05-06 16:50:38 -0700 | [diff] [blame] | 108 | write_dcc(c) ; |
Brian Swetland | 2500aa1 | 2009-01-01 04:33:55 -0800 | [diff] [blame] | 109 | #endif |
Brian Swetland | ddf61a2 | 2009-01-29 20:46:14 -0800 | [diff] [blame] | 110 | #if WITH_DEBUG_UART |
| 111 | uart_putc(0, c); |
| 112 | #endif |
| 113 | #if WITH_DEBUG_FBCON && WITH_DEV_FBCON |
Dima Zavin | 6e274c2 | 2009-01-28 17:28:41 -0800 | [diff] [blame] | 114 | fbcon_putc(c); |
| 115 | #endif |
Ajay Dudani | 168f6cb | 2009-12-07 19:04:02 -0800 | [diff] [blame] | 116 | #if WITH_DEBUG_JTAG |
| 117 | jtag_dputc(c); |
| 118 | #endif |
Brian Swetland | 2500aa1 | 2009-01-01 04:33:55 -0800 | [diff] [blame] | 119 | } |
| 120 | |
Travis Geiselbrecht | dbc2c68 | 2009-06-28 12:18:39 -0700 | [diff] [blame] | 121 | int dgetc(char *c, bool wait) |
Brian Swetland | 2500aa1 | 2009-01-01 04:33:55 -0800 | [diff] [blame] | 122 | { |
Brian Swetland | c82fda9 | 2009-01-02 01:53:42 -0800 | [diff] [blame] | 123 | int n; |
Brian Swetland | ddf61a2 | 2009-01-29 20:46:14 -0800 | [diff] [blame] | 124 | #if WITH_DEBUG_DCC |
Brian Swetland | c82fda9 | 2009-01-02 01:53:42 -0800 | [diff] [blame] | 125 | n = dcc_getc(); |
Brian Swetland | ddf61a2 | 2009-01-29 20:46:14 -0800 | [diff] [blame] | 126 | #elif WITH_DEBUG_UART |
| 127 | n = uart_getc(0, 0); |
Brian Swetland | c82fda9 | 2009-01-02 01:53:42 -0800 | [diff] [blame] | 128 | #else |
Brian Swetland | ddf61a2 | 2009-01-29 20:46:14 -0800 | [diff] [blame] | 129 | n = -1; |
Brian Swetland | c82fda9 | 2009-01-02 01:53:42 -0800 | [diff] [blame] | 130 | #endif |
Brian Swetland | 2500aa1 | 2009-01-01 04:33:55 -0800 | [diff] [blame] | 131 | if (n < 0) { |
| 132 | return -1; |
| 133 | } else { |
| 134 | *c = n; |
| 135 | return 0; |
| 136 | } |
Brian Swetland | 2500aa1 | 2009-01-01 04:33:55 -0800 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | void platform_halt(void) |
| 140 | { |
Matthew Qin | 7791fe8 | 2014-02-25 17:19:19 +0800 | [diff] [blame] | 141 | #if PON_VIB_SUPPORT |
| 142 | vib_turn_off(); |
| 143 | #endif |
Pavel Nedev | 420ecf5 | 2013-05-14 14:04:22 +0300 | [diff] [blame] | 144 | if (set_download_mode(NORMAL_DLOAD) == 0) |
| 145 | { |
| 146 | dprintf(CRITICAL, "HALT: reboot into dload mode...\n"); |
| 147 | reboot_device(0); |
| 148 | dprintf(CRITICAL, "HALT: reboot_device failed\n"); |
| 149 | } |
| 150 | else |
| 151 | { |
| 152 | dprintf(CRITICAL, "HALT: set_download_mode not supported\n"); |
| 153 | } |
| 154 | dprintf(CRITICAL, "HALT: spinning forever...\n"); |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 155 | for (;;) ; |
Brian Swetland | 2500aa1 | 2009-01-01 04:33:55 -0800 | [diff] [blame] | 156 | } |