wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2003 |
| 3 | * Josef Baumgartner <josef.baumgartner@telex.de> |
| 4 | * |
Heiko Schocher | 9acb626 | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 5 | * MCF5282 additionals |
| 6 | * (C) Copyright 2005 |
| 7 | * BuS Elektronik GmbH & Co. KG <esw@bus-elektronik.de> |
| 8 | * |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 9 | * See file CREDITS for list of people who contributed to this |
| 10 | * project. |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License as |
| 14 | * published by the Free Software Foundation; either version 2 of |
| 15 | * the License, or (at your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program; if not, write to the Free Software |
| 24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 25 | * MA 02111-1307 USA |
| 26 | */ |
| 27 | |
| 28 | #include <common.h> |
| 29 | #include <watchdog.h> |
| 30 | #include <command.h> |
TsiChungLiew | 83ec20b | 2007-08-15 19:21:21 -0500 | [diff] [blame^] | 31 | #include <asm/immap.h> |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 32 | |
Zachary P. Landau | eacbd31 | 2006-01-26 17:35:56 -0500 | [diff] [blame] | 33 | #ifdef CONFIG_M5271 |
Bartlomiej Sieka | 363d1d8 | 2007-01-23 13:25:22 +0100 | [diff] [blame] | 34 | /* |
| 35 | * Both MCF5270 and MCF5271 are members of the MPC5271 family. Try to |
| 36 | * determine which one we are running on, based on the Chip Identification |
| 37 | * Register (CIR). |
| 38 | */ |
TsiChungLiew | 83ec20b | 2007-08-15 19:21:21 -0500 | [diff] [blame^] | 39 | int checkcpu(void) |
Zachary P. Landau | eacbd31 | 2006-01-26 17:35:56 -0500 | [diff] [blame] | 40 | { |
Marian Balakowicz | b75ef85 | 2006-05-09 11:45:31 +0200 | [diff] [blame] | 41 | char buf[32]; |
Bartlomiej Sieka | 363d1d8 | 2007-01-23 13:25:22 +0100 | [diff] [blame] | 42 | unsigned short cir; /* Chip Identification Register */ |
| 43 | unsigned short pin; /* Part identification number */ |
| 44 | unsigned char prn; /* Part revision number */ |
| 45 | char *cpu_model; |
Marian Balakowicz | b75ef85 | 2006-05-09 11:45:31 +0200 | [diff] [blame] | 46 | |
Bartlomiej Sieka | 363d1d8 | 2007-01-23 13:25:22 +0100 | [diff] [blame] | 47 | cir = mbar_readShort(MCF_CCM_CIR); |
| 48 | pin = cir >> MCF_CCM_CIR_PIN_LEN; |
| 49 | prn = cir & MCF_CCM_CIR_PRN_MASK; |
| 50 | |
| 51 | switch (pin) { |
| 52 | case MCF_CCM_CIR_PIN_MCF5270: |
| 53 | cpu_model = "5270"; |
| 54 | break; |
| 55 | case MCF_CCM_CIR_PIN_MCF5271: |
| 56 | cpu_model = "5271"; |
| 57 | break; |
| 58 | default: |
| 59 | cpu_model = NULL; |
| 60 | break; |
| 61 | } |
| 62 | |
| 63 | if (cpu_model) |
| 64 | printf("CPU: Freescale ColdFire MCF%s rev. %hu, at %s MHz\n", |
TsiChungLiew | 83ec20b | 2007-08-15 19:21:21 -0500 | [diff] [blame^] | 65 | cpu_model, prn, strmhz(buf, CFG_CLK)); |
Bartlomiej Sieka | 363d1d8 | 2007-01-23 13:25:22 +0100 | [diff] [blame] | 66 | else |
| 67 | printf("CPU: Unknown - Freescale ColdFire MCF5271 family" |
TsiChungLiew | 83ec20b | 2007-08-15 19:21:21 -0500 | [diff] [blame^] | 68 | " (PIN: 0x%x) rev. %hu, at %s MHz\n", |
| 69 | pin, prn, strmhz(buf, CFG_CLK)); |
Bartlomiej Sieka | 363d1d8 | 2007-01-23 13:25:22 +0100 | [diff] [blame] | 70 | |
Zachary P. Landau | eacbd31 | 2006-01-26 17:35:56 -0500 | [diff] [blame] | 71 | return 0; |
| 72 | } |
| 73 | |
TsiChungLiew | 83ec20b | 2007-08-15 19:21:21 -0500 | [diff] [blame^] | 74 | int do_reset(cmd_tbl_t * cmdtp, bd_t * bd, int flag, int argc, char *argv[]) |
| 75 | { |
Zachary P. Landau | eacbd31 | 2006-01-26 17:35:56 -0500 | [diff] [blame] | 76 | mbar_writeByte(MCF_RCM_RCR, |
TsiChungLiew | 83ec20b | 2007-08-15 19:21:21 -0500 | [diff] [blame^] | 77 | MCF_RCM_RCR_SOFTRST | MCF_RCM_RCR_FRCRSTOUT); |
Zachary P. Landau | eacbd31 | 2006-01-26 17:35:56 -0500 | [diff] [blame] | 78 | return 0; |
| 79 | }; |
| 80 | |
| 81 | #if defined(CONFIG_WATCHDOG) |
TsiChungLiew | 83ec20b | 2007-08-15 19:21:21 -0500 | [diff] [blame^] | 82 | void watchdog_reset(void) |
Zachary P. Landau | eacbd31 | 2006-01-26 17:35:56 -0500 | [diff] [blame] | 83 | { |
| 84 | mbar_writeShort(MCF_WTM_WSR, 0x5555); |
| 85 | mbar_writeShort(MCF_WTM_WSR, 0xAAAA); |
| 86 | } |
| 87 | |
TsiChungLiew | 83ec20b | 2007-08-15 19:21:21 -0500 | [diff] [blame^] | 88 | int watchdog_disable(void) |
Zachary P. Landau | eacbd31 | 2006-01-26 17:35:56 -0500 | [diff] [blame] | 89 | { |
| 90 | mbar_writeShort(MCF_WTM_WCR, 0); |
| 91 | return (0); |
| 92 | } |
| 93 | |
TsiChungLiew | 83ec20b | 2007-08-15 19:21:21 -0500 | [diff] [blame^] | 94 | int watchdog_init(void) |
Zachary P. Landau | eacbd31 | 2006-01-26 17:35:56 -0500 | [diff] [blame] | 95 | { |
Zachary P. Landau | eacbd31 | 2006-01-26 17:35:56 -0500 | [diff] [blame] | 96 | mbar_writeShort(MCF_WTM_WCR, MCF_WTM_WCR_EN); |
| 97 | return (0); |
| 98 | } |
TsiChungLiew | 83ec20b | 2007-08-15 19:21:21 -0500 | [diff] [blame^] | 99 | #endif /* #ifdef CONFIG_WATCHDOG */ |
Zachary P. Landau | eacbd31 | 2006-01-26 17:35:56 -0500 | [diff] [blame] | 100 | |
| 101 | #endif |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 102 | |
| 103 | #ifdef CONFIG_M5272 |
TsiChungLiew | 83ec20b | 2007-08-15 19:21:21 -0500 | [diff] [blame^] | 104 | int do_reset(cmd_tbl_t * cmdtp, bd_t * bd, int flag, int argc, char *argv[]) |
| 105 | { |
| 106 | volatile wdog_t *wdp = (wdog_t *) (MMAP_WDOG); |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 107 | |
| 108 | wdp->wdog_wrrr = 0; |
TsiChungLiew | 83ec20b | 2007-08-15 19:21:21 -0500 | [diff] [blame^] | 109 | udelay(1000); |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 110 | |
| 111 | /* enable watchdog, set timeout to 0 and wait */ |
| 112 | wdp->wdog_wrrr = 1; |
TsiChungLiew | 83ec20b | 2007-08-15 19:21:21 -0500 | [diff] [blame^] | 113 | while (1) ; |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 114 | |
| 115 | /* we don't return! */ |
| 116 | return 0; |
| 117 | }; |
| 118 | |
TsiChungLiew | 83ec20b | 2007-08-15 19:21:21 -0500 | [diff] [blame^] | 119 | int checkcpu(void) |
| 120 | { |
| 121 | volatile sysctrl_t *sysctrl = (sysctrl_t *) (MMAP_CFG); |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 122 | uchar msk; |
TsiChungLiew | 83ec20b | 2007-08-15 19:21:21 -0500 | [diff] [blame^] | 123 | char *suf; |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 124 | |
TsiChungLiew | 83ec20b | 2007-08-15 19:21:21 -0500 | [diff] [blame^] | 125 | puts("CPU: "); |
| 126 | msk = (sysctrl->sc_dir > 28) & 0xf; |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 127 | switch (msk) { |
TsiChungLiew | 83ec20b | 2007-08-15 19:21:21 -0500 | [diff] [blame^] | 128 | case 0x2: |
| 129 | suf = "1K75N"; |
| 130 | break; |
| 131 | case 0x4: |
| 132 | suf = "3K75N"; |
| 133 | break; |
| 134 | default: |
| 135 | suf = NULL; |
| 136 | printf("Freescale MCF5272 (Mask:%01x)\n", msk); |
| 137 | break; |
| 138 | } |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 139 | |
| 140 | if (suf) |
TsiChungLiew | 83ec20b | 2007-08-15 19:21:21 -0500 | [diff] [blame^] | 141 | printf("Freescale MCF5272 %s\n", suf); |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 142 | return 0; |
| 143 | }; |
| 144 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 145 | #if defined(CONFIG_WATCHDOG) |
| 146 | /* Called by macro WATCHDOG_RESET */ |
TsiChungLiew | 83ec20b | 2007-08-15 19:21:21 -0500 | [diff] [blame^] | 147 | void watchdog_reset(void) |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 148 | { |
TsiChungLiew | 83ec20b | 2007-08-15 19:21:21 -0500 | [diff] [blame^] | 149 | volatile wdog_t *wdt = (volatile wdog_t *)(MMAP_WDOG); |
| 150 | wdt->wdog_wcr = 0; |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 151 | } |
| 152 | |
TsiChungLiew | 83ec20b | 2007-08-15 19:21:21 -0500 | [diff] [blame^] | 153 | int watchdog_disable(void) |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 154 | { |
TsiChungLiew | 83ec20b | 2007-08-15 19:21:21 -0500 | [diff] [blame^] | 155 | volatile wdog_t *wdt = (volatile wdog_t *)(MMAP_WDOG); |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 156 | |
TsiChungLiew | 83ec20b | 2007-08-15 19:21:21 -0500 | [diff] [blame^] | 157 | wdt->wdog_wcr = 0; /* reset watchdog counter */ |
| 158 | wdt->wdog_wirr = 0; /* disable watchdog interrupt */ |
| 159 | wdt->wdog_wrrr = 0; /* disable watchdog timer */ |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 160 | |
TsiChungLiew | 83ec20b | 2007-08-15 19:21:21 -0500 | [diff] [blame^] | 161 | puts("WATCHDOG:disabled\n"); |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 162 | return (0); |
| 163 | } |
| 164 | |
TsiChungLiew | 83ec20b | 2007-08-15 19:21:21 -0500 | [diff] [blame^] | 165 | int watchdog_init(void) |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 166 | { |
TsiChungLiew | 83ec20b | 2007-08-15 19:21:21 -0500 | [diff] [blame^] | 167 | volatile wdog_t *wdt = (volatile wdog_t *)(MMAP_WDOG); |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 168 | |
TsiChungLiew | 83ec20b | 2007-08-15 19:21:21 -0500 | [diff] [blame^] | 169 | wdt->wdog_wirr = 0; /* disable watchdog interrupt */ |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 170 | |
| 171 | /* set timeout and enable watchdog */ |
TsiChungLiew | 83ec20b | 2007-08-15 19:21:21 -0500 | [diff] [blame^] | 172 | wdt->wdog_wrrr = |
| 173 | ((CONFIG_WATCHDOG_TIMEOUT * CFG_HZ) / (32768 * 1000)) - 1; |
| 174 | wdt->wdog_wcr = 0; /* reset watchdog counter */ |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 175 | |
TsiChungLiew | 83ec20b | 2007-08-15 19:21:21 -0500 | [diff] [blame^] | 176 | puts("WATCHDOG:enabled\n"); |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 177 | return (0); |
| 178 | } |
TsiChungLiew | 83ec20b | 2007-08-15 19:21:21 -0500 | [diff] [blame^] | 179 | #endif /* #ifdef CONFIG_WATCHDOG */ |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 180 | |
TsiChungLiew | 83ec20b | 2007-08-15 19:21:21 -0500 | [diff] [blame^] | 181 | #endif /* #ifdef CONFIG_M5272 */ |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 182 | |
| 183 | #ifdef CONFIG_M5282 |
TsiChungLiew | 83ec20b | 2007-08-15 19:21:21 -0500 | [diff] [blame^] | 184 | int checkcpu(void) |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 185 | { |
Wolfgang Denk | 4176c79 | 2006-06-10 19:27:47 +0200 | [diff] [blame] | 186 | unsigned char resetsource = MCFRESET_RSR; |
Heiko Schocher | 9acb626 | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 187 | |
TsiChungLiew | 83ec20b | 2007-08-15 19:21:21 -0500 | [diff] [blame^] | 188 | printf("CPU: Freescale Coldfire MCF5282 (PIN: %2.2x REV: %2.2x)\n", |
| 189 | MCFCCM_CIR >> 8, MCFCCM_CIR & MCFCCM_CIR_PRN_MASK); |
| 190 | printf("Reset:%s%s%s%s%s%s%s\n", |
| 191 | (resetsource & MCFRESET_RSR_LOL) ? " Loss of Lock" : "", |
| 192 | (resetsource & MCFRESET_RSR_LOC) ? " Loss of Clock" : "", |
| 193 | (resetsource & MCFRESET_RSR_EXT) ? " External" : "", |
| 194 | (resetsource & MCFRESET_RSR_POR) ? " Power On" : "", |
| 195 | (resetsource & MCFRESET_RSR_WDR) ? " Watchdog" : "", |
| 196 | (resetsource & MCFRESET_RSR_SOFT) ? " Software" : "", |
| 197 | (resetsource & MCFRESET_RSR_LVD) ? " Low Voltage" : ""); |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 198 | return 0; |
| 199 | } |
| 200 | |
TsiChungLiew | 83ec20b | 2007-08-15 19:21:21 -0500 | [diff] [blame^] | 201 | int do_reset(cmd_tbl_t * cmdtp, bd_t * bd, int flag, int argc, char *argv[]) |
Heiko Schocher | 9acb626 | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 202 | { |
| 203 | MCFRESET_RCR = MCFRESET_RCR_SOFTRST; |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 204 | return 0; |
| 205 | }; |
| 206 | #endif |
stroese | 8c725b9 | 2004-12-16 18:09:49 +0000 | [diff] [blame] | 207 | |
TsiChungLiew | 83ec20b | 2007-08-15 19:21:21 -0500 | [diff] [blame^] | 208 | #ifdef CONFIG_M5249 /* test-only: todo... */ |
| 209 | int checkcpu(void) |
stroese | 8c725b9 | 2004-12-16 18:09:49 +0000 | [diff] [blame] | 210 | { |
| 211 | char buf[32]; |
| 212 | |
TsiChungLiew | 83ec20b | 2007-08-15 19:21:21 -0500 | [diff] [blame^] | 213 | printf("CPU: Freescale Coldfire MCF5249 at %s MHz\n", |
| 214 | strmhz(buf, CFG_CLK)); |
stroese | 8c725b9 | 2004-12-16 18:09:49 +0000 | [diff] [blame] | 215 | return 0; |
| 216 | } |
| 217 | |
TsiChungLiew | 83ec20b | 2007-08-15 19:21:21 -0500 | [diff] [blame^] | 218 | int do_reset(cmd_tbl_t * cmdtp, bd_t * bd, int flag, int argc, char *argv[]) |
| 219 | { |
stroese | 8c725b9 | 2004-12-16 18:09:49 +0000 | [diff] [blame] | 220 | /* enable watchdog, set timeout to 0 and wait */ |
| 221 | mbar_writeByte(MCFSIM_SYPCR, 0xc0); |
TsiChungLiew | 83ec20b | 2007-08-15 19:21:21 -0500 | [diff] [blame^] | 222 | while (1) ; |
stroese | 8c725b9 | 2004-12-16 18:09:49 +0000 | [diff] [blame] | 223 | |
| 224 | /* we don't return! */ |
| 225 | return 0; |
| 226 | }; |
| 227 | #endif |