Jean-Christophe PLAGNIOL-VILLARD | 4f57289 | 2009-02-22 15:49:28 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2004-2007 ARM Limited. |
| 3 | * Copyright (C) 2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License version 2 |
| 7 | * as published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | * |
| 18 | * As a special exception, if other files instantiate templates or use macros |
| 19 | * or inline functions from this file, or you compile this file and link it |
| 20 | * with other works to produce a work based on this file, this file does not |
| 21 | * by itself cause the resulting work to be covered by the GNU General Public |
| 22 | * License. However the source code for this file must still be made available |
| 23 | * in accordance with section (3) of the GNU General Public License. |
| 24 | |
| 25 | * This exception does not invalidate any other reasons why a work based on |
| 26 | * this file might be covered by the GNU General Public License. |
| 27 | */ |
| 28 | |
| 29 | #include <common.h> |
Jagannadha Sutradharudu Teki | a168d3a | 2013-08-04 01:22:25 +0530 | [diff] [blame] | 30 | #include <serial.h> |
Jean-Christophe PLAGNIOL-VILLARD | 4f57289 | 2009-02-22 15:49:28 +0100 | [diff] [blame] | 31 | |
Jean-Christophe PLAGNIOL-VILLARD | 66e8f9d | 2009-05-15 23:47:14 +0200 | [diff] [blame] | 32 | #if defined(CONFIG_CPU_V6) |
Jean-Christophe PLAGNIOL-VILLARD | 4f57289 | 2009-02-22 15:49:28 +0100 | [diff] [blame] | 33 | /* |
Jean-Christophe PLAGNIOL-VILLARD | 66e8f9d | 2009-05-15 23:47:14 +0200 | [diff] [blame] | 34 | * ARMV6 |
Jean-Christophe PLAGNIOL-VILLARD | 4f57289 | 2009-02-22 15:49:28 +0100 | [diff] [blame] | 35 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 66e8f9d | 2009-05-15 23:47:14 +0200 | [diff] [blame] | 36 | #define DCC_RBIT (1 << 30) |
| 37 | #define DCC_WBIT (1 << 29) |
Jean-Christophe PLAGNIOL-VILLARD | 4f57289 | 2009-02-22 15:49:28 +0100 | [diff] [blame] | 38 | |
Jean-Christophe PLAGNIOL-VILLARD | 66e8f9d | 2009-05-15 23:47:14 +0200 | [diff] [blame] | 39 | #define write_dcc(x) \ |
Jean-Christophe PLAGNIOL-VILLARD | 4f57289 | 2009-02-22 15:49:28 +0100 | [diff] [blame] | 40 | __asm__ volatile ("mcr p14, 0, %0, c0, c5, 0\n" : : "r" (x)) |
| 41 | |
Jean-Christophe PLAGNIOL-VILLARD | 66e8f9d | 2009-05-15 23:47:14 +0200 | [diff] [blame] | 42 | #define read_dcc(x) \ |
Jean-Christophe PLAGNIOL-VILLARD | 4f57289 | 2009-02-22 15:49:28 +0100 | [diff] [blame] | 43 | __asm__ volatile ("mrc p14, 0, %0, c0, c5, 0\n" : "=r" (x)) |
| 44 | |
Jean-Christophe PLAGNIOL-VILLARD | 66e8f9d | 2009-05-15 23:47:14 +0200 | [diff] [blame] | 45 | #define status_dcc(x) \ |
Jean-Christophe PLAGNIOL-VILLARD | 4f57289 | 2009-02-22 15:49:28 +0100 | [diff] [blame] | 46 | __asm__ volatile ("mrc p14, 0, %0, c0, c1, 0\n" : "=r" (x)) |
| 47 | |
Jean-Christophe PLAGNIOL-VILLARD | 65a76d4 | 2009-05-15 23:47:14 +0200 | [diff] [blame] | 48 | #elif defined(CONFIG_CPU_XSCALE) |
| 49 | /* |
| 50 | * XSCALE |
| 51 | */ |
| 52 | #define DCC_RBIT (1 << 31) |
| 53 | #define DCC_WBIT (1 << 28) |
| 54 | |
| 55 | #define write_dcc(x) \ |
| 56 | __asm__ volatile ("mcr p14, 0, %0, c8, c0, 0\n" : : "r" (x)) |
| 57 | |
| 58 | #define read_dcc(x) \ |
| 59 | __asm__ volatile ("mrc p14, 0, %0, c9, c0, 0\n" : "=r" (x)) |
| 60 | |
| 61 | #define status_dcc(x) \ |
| 62 | __asm__ volatile ("mrc p14, 0, %0, c14, c0, 0\n" : "=r" (x)) |
| 63 | |
Jean-Christophe PLAGNIOL-VILLARD | 66e8f9d | 2009-05-15 23:47:14 +0200 | [diff] [blame] | 64 | #else |
| 65 | #define DCC_RBIT (1 << 0) |
| 66 | #define DCC_WBIT (1 << 1) |
| 67 | |
| 68 | #define write_dcc(x) \ |
| 69 | __asm__ volatile ("mcr p14, 0, %0, c1, c0, 0\n" : : "r" (x)) |
| 70 | |
| 71 | #define read_dcc(x) \ |
| 72 | __asm__ volatile ("mrc p14, 0, %0, c1, c0, 0\n" : "=r" (x)) |
| 73 | |
| 74 | #define status_dcc(x) \ |
| 75 | __asm__ volatile ("mrc p14, 0, %0, c0, c0, 0\n" : "=r" (x)) |
| 76 | |
| 77 | #endif |
| 78 | |
| 79 | #define can_read_dcc(x) do { \ |
| 80 | status_dcc(x); \ |
| 81 | x &= DCC_RBIT; \ |
Jean-Christophe PLAGNIOL-VILLARD | 4f57289 | 2009-02-22 15:49:28 +0100 | [diff] [blame] | 82 | } while (0); |
| 83 | |
Jean-Christophe PLAGNIOL-VILLARD | 66e8f9d | 2009-05-15 23:47:14 +0200 | [diff] [blame] | 84 | #define can_write_dcc(x) do { \ |
| 85 | status_dcc(x); \ |
| 86 | x &= DCC_WBIT; \ |
| 87 | x = (x == 0); \ |
Jean-Christophe PLAGNIOL-VILLARD | 4f57289 | 2009-02-22 15:49:28 +0100 | [diff] [blame] | 88 | } while (0); |
| 89 | |
| 90 | #define TIMEOUT_COUNT 0x4000000 |
| 91 | |
Jagannadha Sutradharudu Teki | a168d3a | 2013-08-04 01:22:25 +0530 | [diff] [blame] | 92 | static int arm_dcc_init(void) |
Jean-Christophe PLAGNIOL-VILLARD | 4f57289 | 2009-02-22 15:49:28 +0100 | [diff] [blame] | 93 | { |
Jean-Christophe PLAGNIOL-VILLARD | 4f57289 | 2009-02-22 15:49:28 +0100 | [diff] [blame] | 94 | return 0; |
| 95 | } |
| 96 | |
Jagannadha Sutradharudu Teki | a168d3a | 2013-08-04 01:22:25 +0530 | [diff] [blame] | 97 | static int arm_dcc_getc(void) |
Jean-Christophe PLAGNIOL-VILLARD | 4f57289 | 2009-02-22 15:49:28 +0100 | [diff] [blame] | 98 | { |
| 99 | int ch; |
| 100 | register unsigned int reg; |
| 101 | |
Jean-Christophe PLAGNIOL-VILLARD | 66e8f9d | 2009-05-15 23:47:14 +0200 | [diff] [blame] | 102 | do { |
| 103 | can_read_dcc(reg); |
| 104 | } while (!reg); |
| 105 | read_dcc(ch); |
Jean-Christophe PLAGNIOL-VILLARD | 4f57289 | 2009-02-22 15:49:28 +0100 | [diff] [blame] | 106 | |
| 107 | return ch; |
| 108 | } |
| 109 | |
Jagannadha Sutradharudu Teki | a168d3a | 2013-08-04 01:22:25 +0530 | [diff] [blame] | 110 | static void arm_dcc_putc(char ch) |
Jean-Christophe PLAGNIOL-VILLARD | 4f57289 | 2009-02-22 15:49:28 +0100 | [diff] [blame] | 111 | { |
| 112 | register unsigned int reg; |
| 113 | unsigned int timeout_count = TIMEOUT_COUNT; |
| 114 | |
Jean-Christophe PLAGNIOL-VILLARD | 66e8f9d | 2009-05-15 23:47:14 +0200 | [diff] [blame] | 115 | while (--timeout_count) { |
| 116 | can_write_dcc(reg); |
| 117 | if (reg) |
| 118 | break; |
Jean-Christophe PLAGNIOL-VILLARD | 4f57289 | 2009-02-22 15:49:28 +0100 | [diff] [blame] | 119 | } |
Jean-Christophe PLAGNIOL-VILLARD | 66e8f9d | 2009-05-15 23:47:14 +0200 | [diff] [blame] | 120 | if (timeout_count == 0) |
| 121 | return; |
| 122 | else |
| 123 | write_dcc(ch); |
Jean-Christophe PLAGNIOL-VILLARD | 4f57289 | 2009-02-22 15:49:28 +0100 | [diff] [blame] | 124 | } |
| 125 | |
Jagannadha Sutradharudu Teki | a168d3a | 2013-08-04 01:22:25 +0530 | [diff] [blame] | 126 | static int arm_dcc_tstc(void) |
Jean-Christophe PLAGNIOL-VILLARD | 4f57289 | 2009-02-22 15:49:28 +0100 | [diff] [blame] | 127 | { |
| 128 | register unsigned int reg; |
| 129 | |
Jean-Christophe PLAGNIOL-VILLARD | 66e8f9d | 2009-05-15 23:47:14 +0200 | [diff] [blame] | 130 | can_read_dcc(reg); |
Jean-Christophe PLAGNIOL-VILLARD | 4f57289 | 2009-02-22 15:49:28 +0100 | [diff] [blame] | 131 | |
| 132 | return reg; |
| 133 | } |
| 134 | |
Jagannadha Sutradharudu Teki | a168d3a | 2013-08-04 01:22:25 +0530 | [diff] [blame] | 135 | static void arm_dcc_setbrg(void) |
| 136 | { |
| 137 | } |
| 138 | |
| 139 | static struct serial_device arm_dcc_drv = { |
| 140 | .name = "arm_dcc", |
| 141 | .start = arm_dcc_init, |
| 142 | .stop = NULL, |
| 143 | .setbrg = arm_dcc_setbrg, |
| 144 | .putc = arm_dcc_putc, |
Axel Lin | 012a2c1 | 2013-08-17 15:39:34 +0800 | [diff] [blame] | 145 | .puts = default_serial_puts, |
Jagannadha Sutradharudu Teki | a168d3a | 2013-08-04 01:22:25 +0530 | [diff] [blame] | 146 | .getc = arm_dcc_getc, |
| 147 | .tstc = arm_dcc_tstc, |
| 148 | }; |
| 149 | |
| 150 | void arm_dcc_initialize(void) |
| 151 | { |
| 152 | serial_register(&arm_dcc_drv); |
| 153 | } |
| 154 | |
Michal Simek | e70fb53 | 2013-01-22 23:40:06 +0000 | [diff] [blame] | 155 | __weak struct serial_device *default_serial_console(void) |
| 156 | { |
Jagannadha Sutradharudu Teki | a168d3a | 2013-08-04 01:22:25 +0530 | [diff] [blame] | 157 | return &arm_dcc_drv; |
Michal Simek | e70fb53 | 2013-01-22 23:40:06 +0000 | [diff] [blame] | 158 | } |