wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1 | /* |
Wolfgang Denk | c80857e | 2006-07-21 11:56:05 +0200 | [diff] [blame] | 2 | * (C) Copyright 2000-2006 |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
Stefan Roese | 3ddce57 | 2010-09-20 16:05:31 +0200 | [diff] [blame] | 5 | * (C) Copyright 2010 |
| 6 | * Stefan Roese, DENX Software Engineering, sr@denx.de. |
| 7 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 8 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 9 | */ |
Stefan Roese | 1a47115 | 2007-10-22 16:22:40 +0200 | [diff] [blame] | 10 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 11 | /* |
Josh Boyer | 471573b | 2009-08-07 13:53:20 -0400 | [diff] [blame] | 12 | * This source code is dual-licensed. You may use it under the terms of the |
| 13 | * GNU General Public License version 2, or under the license below. |
| 14 | * |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 15 | * This source code has been made available to you by IBM on an AS-IS |
| 16 | * basis. Anyone receiving this source is licensed under IBM |
| 17 | * copyrights to use it in any way he or she deems fit, including |
| 18 | * copying it, modifying it, compiling it, and redistributing it either |
| 19 | * with or without modifications. No license under IBM patents or |
| 20 | * patent applications is to be implied by the copyright license. |
| 21 | * |
| 22 | * Any user of this software should understand that IBM cannot provide |
| 23 | * technical support for this software and will not be responsible for |
| 24 | * any consequences resulting from the use of this software. |
| 25 | * |
| 26 | * Any person who transfers this source code or any derivative work |
| 27 | * must include the IBM copyright notice, this paragraph, and the |
| 28 | * preceding two paragraphs in the transferred software. |
| 29 | * |
| 30 | * COPYRIGHT I B M CORPORATION 1995 |
| 31 | * LICENSED MATERIAL - PROGRAM PROPERTY OF I B M |
| 32 | */ |
Stefan Roese | 1a47115 | 2007-10-22 16:22:40 +0200 | [diff] [blame] | 33 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 34 | #include <common.h> |
| 35 | #include <commproc.h> |
| 36 | #include <asm/processor.h> |
Stefan Roese | 1a47115 | 2007-10-22 16:22:40 +0200 | [diff] [blame] | 37 | #include <asm/io.h> |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 38 | #include <watchdog.h> |
Stefan Roese | 247e9d7 | 2010-09-09 19:18:00 +0200 | [diff] [blame] | 39 | #include <asm/ppc4xx.h> |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 40 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 41 | DECLARE_GLOBAL_DATA_PTR; |
| 42 | |
Stefan Roese | 17ffbc8 | 2007-03-21 13:38:59 +0100 | [diff] [blame] | 43 | #if defined(CONFIG_405GP) || defined(CONFIG_405CR) || \ |
| 44 | defined(CONFIG_405EP) || defined(CONFIG_405EZ) || \ |
Stefan Roese | 153b3e2 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 45 | defined(CONFIG_405EX) || defined(CONFIG_440) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 46 | |
| 47 | #if defined(CONFIG_440) |
Stefan Roese | bdd13d1 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 48 | |
Stefan Roese | 42fbddd | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 49 | #if defined(CONFIG_440GP) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 50 | #define CR0_MASK 0x3fff0000 |
| 51 | #define CR0_EXTCLK_ENA 0x00600000 |
| 52 | #define CR0_UDIV_POS 16 |
Stefan Roese | 42fbddd | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 53 | #define UDIV_SUBTRACT 1 |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 54 | #define UART0_SDR CPC0_CR0 |
Stefan Roese | 42fbddd | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 55 | #define MFREG(a, d) d = mfdcr(a) |
| 56 | #define MTREG(a, d) mtdcr(a, d) |
| 57 | #else /* #if defined(CONFIG_440GP) */ |
| 58 | /* all other 440 PPC's access clock divider via sdr register */ |
| 59 | #define CR0_MASK 0xdfffffff |
| 60 | #define CR0_EXTCLK_ENA 0x00800000 |
| 61 | #define CR0_UDIV_POS 0 |
| 62 | #define UDIV_SUBTRACT 0 |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 63 | #define UART0_SDR SDR0_UART0 |
| 64 | #define UART1_SDR SDR0_UART1 |
Stefan Roese | 422853e | 2008-06-06 16:10:41 +0200 | [diff] [blame] | 65 | #if defined(CONFIG_440EP) || defined(CONFIG_440EPX) || \ |
| 66 | defined(CONFIG_440GR) || defined(CONFIG_440GRX) || \ |
| 67 | defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \ |
Stefan Roese | bdd13d1 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 68 | defined(CONFIG_460EX) || defined(CONFIG_460GT) |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 69 | #define UART2_SDR SDR0_UART2 |
Stefan Roese | 42fbddd | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 70 | #endif |
Stefan Roese | 422853e | 2008-06-06 16:10:41 +0200 | [diff] [blame] | 71 | #if defined(CONFIG_440EP) || defined(CONFIG_440EPX) || \ |
| 72 | defined(CONFIG_440GR) || defined(CONFIG_440GRX) || \ |
Stefan Roese | bdd13d1 | 2008-03-11 15:05:26 +0100 | [diff] [blame] | 73 | defined(CONFIG_460EX) || defined(CONFIG_460GT) |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 74 | #define UART3_SDR SDR0_UART3 |
Stefan Roese | 42fbddd | 2006-09-07 11:51:23 +0200 | [diff] [blame] | 75 | #endif |
| 76 | #define MFREG(a, d) mfsdr(a, d) |
| 77 | #define MTREG(a, d) mtsdr(a, d) |
| 78 | #endif /* #if defined(CONFIG_440GP) */ |
Stefan Roese | 17ffbc8 | 2007-03-21 13:38:59 +0100 | [diff] [blame] | 79 | #elif defined(CONFIG_405EP) || defined(CONFIG_405EZ) |
stroese | 937d667 | 2003-05-23 11:25:57 +0000 | [diff] [blame] | 80 | #define UCR0_MASK 0x0000007f |
| 81 | #define UCR1_MASK 0x00007f00 |
| 82 | #define UCR0_UDIV_POS 0 |
| 83 | #define UCR1_UDIV_POS 8 |
| 84 | #define UDIV_MAX 127 |
Stefan Roese | 153b3e2 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 85 | #elif defined(CONFIG_405EX) |
Stefan Roese | 3ddce57 | 2010-09-20 16:05:31 +0200 | [diff] [blame] | 86 | #define MFREG(a, d) mfsdr(a, d) |
| 87 | #define MTREG(a, d) mtsdr(a, d) |
Stefan Roese | 153b3e2 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 88 | #define CR0_MASK 0x000000ff |
| 89 | #define CR0_EXTCLK_ENA 0x00800000 |
| 90 | #define CR0_UDIV_POS 0 |
| 91 | #define UDIV_SUBTRACT 0 |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 92 | #define UART0_SDR SDR0_UART0 |
| 93 | #define UART1_SDR SDR0_UART1 |
stroese | 937d667 | 2003-05-23 11:25:57 +0000 | [diff] [blame] | 94 | #else /* CONFIG_405GP || CONFIG_405CR */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 95 | #define CR0_MASK 0x00001fff |
stroese | 85d0fec | 2003-02-17 16:06:06 +0000 | [diff] [blame] | 96 | #define CR0_EXTCLK_ENA 0x000000c0 |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 97 | #define CR0_UDIV_POS 1 |
stroese | 937d667 | 2003-05-23 11:25:57 +0000 | [diff] [blame] | 98 | #define UDIV_MAX 32 |
| 99 | #endif |
| 100 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 101 | #if defined(CONFIG_405EP) && defined(CONFIG_SYS_EXT_SERIAL_CLOCK) |
Wolfgang Denk | 0ee7077 | 2005-09-23 11:05:55 +0200 | [diff] [blame] | 102 | #error "External serial clock not supported on AMCC PPC405EP!" |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 103 | #endif |
| 104 | |
Stefan Roese | 3ddce57 | 2010-09-20 16:05:31 +0200 | [diff] [blame] | 105 | #if (defined(CONFIG_405EX) || defined(CONFIG_405EZ) || \ |
| 106 | defined(CONFIG_440)) && !defined(CONFIG_SYS_EXT_SERIAL_CLOCK) |
| 107 | /* |
| 108 | * For some SoC's, the cpu clock is on divider chain A, UART on |
| 109 | * divider chain B ... so cpu clock is irrelevant. Get the |
| 110 | * "optimized" values that are subject to the 1/2 opb clock |
| 111 | * constraint. |
| 112 | */ |
| 113 | static u16 serial_bdiv(int baudrate, u32 *udiv) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 114 | { |
Stefan Roese | 17ffbc8 | 2007-03-21 13:38:59 +0100 | [diff] [blame] | 115 | sys_info_t sysinfo; |
Stefan Roese | 3ddce57 | 2010-09-20 16:05:31 +0200 | [diff] [blame] | 116 | u32 div; /* total divisor udiv * bdiv */ |
| 117 | u32 umin; /* minimum udiv */ |
| 118 | u16 diff; /* smallest diff */ |
| 119 | u16 idiff; /* current diff */ |
| 120 | u16 ibdiv; /* current bdiv */ |
| 121 | u32 i; |
| 122 | u32 est; /* current estimate */ |
| 123 | u32 max; |
| 124 | #if defined(CONFIG_405EZ) |
| 125 | u32 cpr_pllc; |
| 126 | u32 plloutb; |
| 127 | u32 reg; |
| 128 | #endif |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 129 | |
Stefan Roese | 17ffbc8 | 2007-03-21 13:38:59 +0100 | [diff] [blame] | 130 | get_sys_info(&sysinfo); |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 131 | |
Stefan Roese | 3ddce57 | 2010-09-20 16:05:31 +0200 | [diff] [blame] | 132 | #if defined(CONFIG_405EZ) |
Stefan Roese | 87476ba | 2007-08-13 09:05:33 +0200 | [diff] [blame] | 133 | /* check the pll feedback source */ |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 134 | mfcpr(CPR0_PLLC, cpr_pllc); |
Stefan Roese | 3dae28e | 2007-08-14 15:03:17 +0200 | [diff] [blame] | 135 | plloutb = ((CONFIG_SYS_CLK_FREQ * ((cpr_pllc & PLLC_SRC_MASK) ? |
Stefan Roese | 1a47115 | 2007-10-22 16:22:40 +0200 | [diff] [blame] | 136 | sysinfo.pllFwdDivB : sysinfo.pllFwdDiv) * |
| 137 | sysinfo.pllFbkDiv) / sysinfo.pllFwdDivB); |
Stefan Roese | 17ffbc8 | 2007-03-21 13:38:59 +0100 | [diff] [blame] | 138 | div = plloutb / (16 * baudrate); /* total divisor */ |
| 139 | umin = (plloutb / get_OPB_freq()) << 1; /* 2 x OPB divisor */ |
Stefan Roese | 3ddce57 | 2010-09-20 16:05:31 +0200 | [diff] [blame] | 140 | max = 256; /* highest possible */ |
| 141 | #else /* 405EZ */ |
| 142 | div = sysinfo.freqPLB / (16 * baudrate); /* total divisor */ |
| 143 | umin = sysinfo.pllOpbDiv << 1; /* 2 x OPB divisor */ |
| 144 | max = 32; /* highest possible */ |
| 145 | #endif /* 405EZ */ |
| 146 | |
| 147 | *udiv = diff = max; |
Stefan Roese | 17ffbc8 | 2007-03-21 13:38:59 +0100 | [diff] [blame] | 148 | |
Stefan Roese | 3ddce57 | 2010-09-20 16:05:31 +0200 | [diff] [blame] | 149 | /* |
| 150 | * i is the test udiv value -- start with the largest |
| 151 | * possible (max) to minimize serial clock and constrain |
Stefan Roese | 17ffbc8 | 2007-03-21 13:38:59 +0100 | [diff] [blame] | 152 | * search to umin. |
| 153 | */ |
Stefan Roese | 3ddce57 | 2010-09-20 16:05:31 +0200 | [diff] [blame] | 154 | for (i = max; i > umin; i--) { |
Stefan Roese | 17ffbc8 | 2007-03-21 13:38:59 +0100 | [diff] [blame] | 155 | ibdiv = div / i; |
| 156 | est = i * ibdiv; |
Stefan Roese | 3ddce57 | 2010-09-20 16:05:31 +0200 | [diff] [blame] | 157 | idiff = (est > div) ? (est - div) : (div - est); |
Stefan Roese | 17ffbc8 | 2007-03-21 13:38:59 +0100 | [diff] [blame] | 158 | if (idiff == 0) { |
Stefan Roese | 3ddce57 | 2010-09-20 16:05:31 +0200 | [diff] [blame] | 159 | *udiv = i; |
| 160 | break; /* can't do better */ |
Stefan Roese | 17ffbc8 | 2007-03-21 13:38:59 +0100 | [diff] [blame] | 161 | } else if (idiff < diff) { |
Stefan Roese | 3ddce57 | 2010-09-20 16:05:31 +0200 | [diff] [blame] | 162 | *udiv = i; /* best so far */ |
| 163 | diff = idiff; /* update lowest diff*/ |
Stefan Roese | 17ffbc8 | 2007-03-21 13:38:59 +0100 | [diff] [blame] | 164 | } |
| 165 | } |
| 166 | |
Stefan Roese | 3ddce57 | 2010-09-20 16:05:31 +0200 | [diff] [blame] | 167 | #if defined(CONFIG_405EZ) |
Stefan Roese | 8cb251a | 2010-09-12 06:21:37 +0200 | [diff] [blame] | 168 | mfcpr(CPR0_PERD0, reg); |
Stefan Roese | 17ffbc8 | 2007-03-21 13:38:59 +0100 | [diff] [blame] | 169 | reg &= ~0x0000ffff; |
Stefan Roese | 3ddce57 | 2010-09-20 16:05:31 +0200 | [diff] [blame] | 170 | reg |= ((*udiv - 0) << 8) | (*udiv - 0); |
Stefan Roese | 8cb251a | 2010-09-12 06:21:37 +0200 | [diff] [blame] | 171 | mtcpr(CPR0_PERD0, reg); |
Stefan Roese | 3ddce57 | 2010-09-20 16:05:31 +0200 | [diff] [blame] | 172 | #endif |
| 173 | |
| 174 | return div / *udiv; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 175 | } |
Stefan Roese | 3ddce57 | 2010-09-20 16:05:31 +0200 | [diff] [blame] | 176 | #endif /* #if (defined(CONFIG_405EP) ... */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 177 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 178 | /* |
Stefan Roese | 3ddce57 | 2010-09-20 16:05:31 +0200 | [diff] [blame] | 179 | * This function returns the UART clock used by the common |
| 180 | * NS16550 driver. Additionally the SoC internal divisors for |
| 181 | * optimal UART baudrate are configured. |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 182 | */ |
Stefan Roese | 3ddce57 | 2010-09-20 16:05:31 +0200 | [diff] [blame] | 183 | int get_serial_clock(void) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 184 | { |
Stefan Roese | 3ddce57 | 2010-09-20 16:05:31 +0200 | [diff] [blame] | 185 | u32 clk; |
| 186 | u32 udiv; |
Stefan Roese | 3ddce57 | 2010-09-20 16:05:31 +0200 | [diff] [blame] | 187 | #if !defined(CONFIG_405EZ) |
| 188 | u32 reg; |
wdenk | 96c7a8c | 2005-01-09 22:28:56 +0000 | [diff] [blame] | 189 | #endif |
Stefan Roese | 3ddce57 | 2010-09-20 16:05:31 +0200 | [diff] [blame] | 190 | #if !defined(CONFIG_SYS_EXT_SERIAL_CLOCK) |
| 191 | PPC4xx_SYS_INFO sys_info; |
Stefan Roese | 153b3e2 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 192 | #endif |
Stefan Roese | 153b3e2 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 193 | |
| 194 | /* |
Stefan Roese | 3ddce57 | 2010-09-20 16:05:31 +0200 | [diff] [blame] | 195 | * Programming of the internal divisors is SoC specific. |
| 196 | * Let's handle this in some #ifdef's for the SoC's. |
Stefan Roese | 153b3e2 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 197 | */ |
Stefan Roese | 153b3e2 | 2007-10-05 17:10:59 +0200 | [diff] [blame] | 198 | |
Stefan Roese | 3ddce57 | 2010-09-20 16:05:31 +0200 | [diff] [blame] | 199 | #if defined(CONFIG_405CR) || defined(CONFIG_405GP) |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 200 | reg = mfdcr(CPC0_CR0) & ~CR0_MASK; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 201 | #ifdef CONFIG_SYS_EXT_SERIAL_CLOCK |
| 202 | clk = CONFIG_SYS_EXT_SERIAL_CLOCK; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 203 | udiv = 1; |
| 204 | reg |= CR0_EXTCLK_ENA; |
Stefan Roese | 3ddce57 | 2010-09-20 16:05:31 +0200 | [diff] [blame] | 205 | #else /* CONFIG_SYS_EXT_SERIAL_CLOCK */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 206 | clk = gd->cpu_clk; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 207 | #ifdef CONFIG_SYS_405_UART_ERRATA_59 |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 208 | udiv = 31; /* Errata 59: stuck at 31 */ |
Stefan Roese | 3ddce57 | 2010-09-20 16:05:31 +0200 | [diff] [blame] | 209 | #else /* CONFIG_SYS_405_UART_ERRATA_59 */ |
Wolfgang Denk | df59292 | 2011-10-29 09:37:52 +0000 | [diff] [blame] | 210 | { |
| 211 | u32 tmp = CONFIG_SYS_BASE_BAUD * 16; |
| 212 | |
| 213 | udiv = (clk + tmp / 2) / tmp; |
| 214 | } |
stroese | 937d667 | 2003-05-23 11:25:57 +0000 | [diff] [blame] | 215 | if (udiv > UDIV_MAX) /* max. n bits for udiv */ |
| 216 | udiv = UDIV_MAX; |
Stefan Roese | 3ddce57 | 2010-09-20 16:05:31 +0200 | [diff] [blame] | 217 | #endif /* CONFIG_SYS_405_UART_ERRATA_59 */ |
| 218 | #endif /* CONFIG_SYS_EXT_SERIAL_CLOCK */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 219 | reg |= (udiv - 1) << CR0_UDIV_POS; /* set the UART divisor */ |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 220 | mtdcr (CPC0_CR0, reg); |
Stefan Roese | 3ddce57 | 2010-09-20 16:05:31 +0200 | [diff] [blame] | 221 | #ifdef CONFIG_SYS_EXT_SERIAL_CLOCK |
| 222 | clk = CONFIG_SYS_EXT_SERIAL_CLOCK; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 223 | #else |
Stefan Roese | 3ddce57 | 2010-09-20 16:05:31 +0200 | [diff] [blame] | 224 | clk = CONFIG_SYS_BASE_BAUD * 16; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 225 | #endif |
Stefan Roese | 3ddce57 | 2010-09-20 16:05:31 +0200 | [diff] [blame] | 226 | #endif /* CONFIG_405CR */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 227 | |
Stefan Roese | 3ddce57 | 2010-09-20 16:05:31 +0200 | [diff] [blame] | 228 | #if defined(CONFIG_405EP) |
Wolfgang Denk | df59292 | 2011-10-29 09:37:52 +0000 | [diff] [blame] | 229 | { |
| 230 | u32 tmp = CONFIG_SYS_BASE_BAUD * 16; |
| 231 | |
| 232 | reg = mfdcr(CPC0_UCR) & ~(UCR0_MASK | UCR1_MASK); |
| 233 | clk = gd->cpu_clk; |
| 234 | udiv = (clk + tmp / 2) / tmp; |
| 235 | if (udiv > UDIV_MAX) /* max. n bits for udiv */ |
| 236 | udiv = UDIV_MAX; |
| 237 | } |
Stefan Roese | 3ddce57 | 2010-09-20 16:05:31 +0200 | [diff] [blame] | 238 | reg |= udiv << UCR0_UDIV_POS; /* set the UART divisor */ |
| 239 | reg |= udiv << UCR1_UDIV_POS; /* set the UART divisor */ |
| 240 | mtdcr(CPC0_UCR, reg); |
| 241 | clk = CONFIG_SYS_BASE_BAUD * 16; |
| 242 | #endif /* CONFIG_405EP */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 243 | |
Stefan Roese | 3ddce57 | 2010-09-20 16:05:31 +0200 | [diff] [blame] | 244 | #if defined(CONFIG_405EX) || defined(CONFIG_440) |
| 245 | MFREG(UART0_SDR, reg); |
| 246 | reg &= ~CR0_MASK; |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 247 | |
Stefan Roese | 3ddce57 | 2010-09-20 16:05:31 +0200 | [diff] [blame] | 248 | #ifdef CONFIG_SYS_EXT_SERIAL_CLOCK |
| 249 | reg |= CR0_EXTCLK_ENA; |
| 250 | udiv = 1; |
| 251 | clk = CONFIG_SYS_EXT_SERIAL_CLOCK; |
| 252 | #else /* CONFIG_SYS_EXT_SERIAL_CLOCK */ |
| 253 | clk = gd->baudrate * serial_bdiv(gd->baudrate, &udiv) * 16; |
| 254 | #endif /* CONFIG_SYS_EXT_SERIAL_CLOCK */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 255 | |
Stefan Roese | 3ddce57 | 2010-09-20 16:05:31 +0200 | [diff] [blame] | 256 | reg |= (udiv - UDIV_SUBTRACT) << CR0_UDIV_POS; /* set the UART divisor */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 257 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 258 | /* |
Stefan Roese | 3ddce57 | 2010-09-20 16:05:31 +0200 | [diff] [blame] | 259 | * Configure input clock to baudrate generator for all |
| 260 | * available serial ports here |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 261 | */ |
Stefan Roese | 3ddce57 | 2010-09-20 16:05:31 +0200 | [diff] [blame] | 262 | MTREG(UART0_SDR, reg); |
| 263 | #if defined(UART1_SDR) |
| 264 | MTREG(UART1_SDR, reg); |
Jon Loeliger | 07efe2a | 2007-07-10 10:27:39 -0500 | [diff] [blame] | 265 | #endif |
Stefan Roese | 3ddce57 | 2010-09-20 16:05:31 +0200 | [diff] [blame] | 266 | #if defined(UART2_SDR) |
| 267 | MTREG(UART2_SDR, reg); |
| 268 | #endif |
| 269 | #if defined(UART3_SDR) |
| 270 | MTREG(UART3_SDR, reg); |
| 271 | #endif |
| 272 | #endif /* CONFIG_405EX ... */ |
wdenk | 96c7a8c | 2005-01-09 22:28:56 +0000 | [diff] [blame] | 273 | |
Stefan Roese | 3ddce57 | 2010-09-20 16:05:31 +0200 | [diff] [blame] | 274 | #if defined(CONFIG_405EZ) |
| 275 | clk = gd->baudrate * serial_bdiv(gd->baudrate, &udiv) * 16; |
| 276 | #endif /* CONFIG_405EZ */ |
wdenk | 96c7a8c | 2005-01-09 22:28:56 +0000 | [diff] [blame] | 277 | |
Stefan Roese | 3ddce57 | 2010-09-20 16:05:31 +0200 | [diff] [blame] | 278 | /* |
| 279 | * Correct UART frequency in bd-info struct now that |
| 280 | * the UART divisor is available |
| 281 | */ |
| 282 | #ifdef CONFIG_SYS_EXT_SERIAL_CLOCK |
Simon Glass | 004cc85 | 2012-12-13 20:48:59 +0000 | [diff] [blame] | 283 | gd->arch.uart_clk = CONFIG_SYS_EXT_SERIAL_CLOCK; |
Stefan Roese | 1a47115 | 2007-10-22 16:22:40 +0200 | [diff] [blame] | 284 | #else |
Stefan Roese | 3ddce57 | 2010-09-20 16:05:31 +0200 | [diff] [blame] | 285 | get_sys_info(&sys_info); |
Simon Glass | 004cc85 | 2012-12-13 20:48:59 +0000 | [diff] [blame] | 286 | gd->arch.uart_clk = sys_info.freqUART / udiv; |
Stefan Roese | 3ddce57 | 2010-09-20 16:05:31 +0200 | [diff] [blame] | 287 | #endif |
Stefan Roese | 1a47115 | 2007-10-22 16:22:40 +0200 | [diff] [blame] | 288 | |
Stefan Roese | 3ddce57 | 2010-09-20 16:05:31 +0200 | [diff] [blame] | 289 | return clk; |
Stefan Roese | 1a47115 | 2007-10-22 16:22:40 +0200 | [diff] [blame] | 290 | } |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 291 | #endif /* CONFIG_405GP || CONFIG_405CR */ |