wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2003 |
| 3 | * Josef Baumgartner <josef.baumgartner@telex.de> |
| 4 | * |
Heiko Schocher | ac1956e | 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 | e65527f | 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> |
| 31 | |
Zachary P. Landau | 0bba862 | 2006-01-26 17:35:56 -0500 | [diff] [blame] | 32 | #ifdef CONFIG_M5271 |
| 33 | #include <asm/immap_5271.h> |
| 34 | #include <asm/m5271.h> |
| 35 | #endif |
| 36 | |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 37 | #ifdef CONFIG_M5272 |
| 38 | #include <asm/immap_5272.h> |
| 39 | #include <asm/m5272.h> |
| 40 | #endif |
| 41 | |
| 42 | #ifdef CONFIG_M5282 |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 43 | #include <asm/m5282.h> |
| 44 | #include <asm/immap_5282.h> |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 45 | #endif |
| 46 | |
stroese | 53395a2 | 2004-12-16 18:09:49 +0000 | [diff] [blame] | 47 | #ifdef CONFIG_M5249 |
| 48 | #include <asm/m5249.h> |
| 49 | #endif |
| 50 | |
Zachary P. Landau | 0bba862 | 2006-01-26 17:35:56 -0500 | [diff] [blame] | 51 | #ifdef CONFIG_M5271 |
Bartlomiej Sieka | ad87026 | 2007-01-23 13:25:22 +0100 | [diff] [blame] | 52 | /* |
| 53 | * Both MCF5270 and MCF5271 are members of the MPC5271 family. Try to |
| 54 | * determine which one we are running on, based on the Chip Identification |
| 55 | * Register (CIR). |
| 56 | */ |
Zachary P. Landau | 0bba862 | 2006-01-26 17:35:56 -0500 | [diff] [blame] | 57 | int checkcpu (void) |
| 58 | { |
Marian Balakowicz | ecb6d0b | 2006-05-09 11:45:31 +0200 | [diff] [blame] | 59 | char buf[32]; |
Bartlomiej Sieka | ad87026 | 2007-01-23 13:25:22 +0100 | [diff] [blame] | 60 | unsigned short cir; /* Chip Identification Register */ |
| 61 | unsigned short pin; /* Part identification number */ |
| 62 | unsigned char prn; /* Part revision number */ |
| 63 | char *cpu_model; |
| 64 | |
| 65 | cir = mbar_readShort(MCF_CCM_CIR); |
| 66 | pin = cir >> MCF_CCM_CIR_PIN_LEN; |
| 67 | prn = cir & MCF_CCM_CIR_PRN_MASK; |
| 68 | |
| 69 | switch (pin) { |
| 70 | case MCF_CCM_CIR_PIN_MCF5270: |
| 71 | cpu_model = "5270"; |
| 72 | break; |
| 73 | case MCF_CCM_CIR_PIN_MCF5271: |
| 74 | cpu_model = "5271"; |
| 75 | break; |
| 76 | default: |
| 77 | cpu_model = NULL; |
| 78 | break; |
| 79 | } |
| 80 | |
| 81 | if (cpu_model) |
| 82 | printf("CPU: Freescale ColdFire MCF%s rev. %hu, at %s MHz\n", |
| 83 | cpu_model, prn, strmhz(buf, CFG_CLK)); |
| 84 | else |
| 85 | printf("CPU: Unknown - Freescale ColdFire MCF5271 family" |
| 86 | " (PIN: 0x%x) rev. %hu, at %s MHz\n", |
| 87 | pin, prn, strmhz(buf, CFG_CLK)); |
Marian Balakowicz | ecb6d0b | 2006-05-09 11:45:31 +0200 | [diff] [blame] | 88 | |
Zachary P. Landau | 0bba862 | 2006-01-26 17:35:56 -0500 | [diff] [blame] | 89 | return 0; |
| 90 | } |
| 91 | |
| 92 | int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[]) { |
| 93 | mbar_writeByte(MCF_RCM_RCR, |
| 94 | MCF_RCM_RCR_SOFTRST | MCF_RCM_RCR_FRCRSTOUT); |
| 95 | return 0; |
| 96 | }; |
| 97 | |
| 98 | #if defined(CONFIG_WATCHDOG) |
| 99 | void watchdog_reset (void) |
| 100 | { |
| 101 | mbar_writeShort(MCF_WTM_WSR, 0x5555); |
| 102 | mbar_writeShort(MCF_WTM_WSR, 0xAAAA); |
| 103 | } |
| 104 | |
| 105 | int watchdog_disable (void) |
| 106 | { |
| 107 | mbar_writeShort(MCF_WTM_WCR, 0); |
| 108 | return (0); |
| 109 | } |
| 110 | |
| 111 | int watchdog_init (void) |
| 112 | { |
Zachary P. Landau | 0bba862 | 2006-01-26 17:35:56 -0500 | [diff] [blame] | 113 | mbar_writeShort(MCF_WTM_WCR, MCF_WTM_WCR_EN); |
| 114 | return (0); |
| 115 | } |
| 116 | #endif /* #ifdef CONFIG_WATCHDOG */ |
| 117 | |
| 118 | #endif |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 119 | |
| 120 | #ifdef CONFIG_M5272 |
| 121 | int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[]) { |
| 122 | volatile wdog_t * wdp = (wdog_t *)(CFG_MBAR + MCFSIM_WRRR); |
| 123 | |
| 124 | wdp->wdog_wrrr = 0; |
| 125 | udelay (1000); |
| 126 | |
| 127 | /* enable watchdog, set timeout to 0 and wait */ |
| 128 | wdp->wdog_wrrr = 1; |
| 129 | while (1); |
| 130 | |
| 131 | /* we don't return! */ |
| 132 | return 0; |
| 133 | }; |
| 134 | |
| 135 | int checkcpu(void) { |
| 136 | ulong *dirp = (ulong *)(CFG_MBAR + MCFSIM_DIR); |
| 137 | uchar msk; |
| 138 | char *suf; |
| 139 | |
| 140 | puts ("CPU: "); |
| 141 | msk = (*dirp > 28) & 0xf; |
| 142 | switch (msk) { |
| 143 | case 0x2: suf = "1K75N"; break; |
| 144 | case 0x4: suf = "3K75N"; break; |
| 145 | default: |
| 146 | suf = NULL; |
Marian Balakowicz | ecb6d0b | 2006-05-09 11:45:31 +0200 | [diff] [blame] | 147 | printf ("Freescale MCF5272 (Mask:%01x)\n", msk); |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 148 | break; |
| 149 | } |
| 150 | |
| 151 | if (suf) |
Marian Balakowicz | ecb6d0b | 2006-05-09 11:45:31 +0200 | [diff] [blame] | 152 | printf ("Freescale MCF5272 %s\n", suf); |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 153 | return 0; |
| 154 | }; |
| 155 | |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 156 | #if defined(CONFIG_WATCHDOG) |
| 157 | /* Called by macro WATCHDOG_RESET */ |
| 158 | void watchdog_reset (void) |
| 159 | { |
| 160 | volatile immap_t * regp = (volatile immap_t *)CFG_MBAR; |
| 161 | regp->wdog_reg.wdog_wcr = 0; |
| 162 | } |
| 163 | |
| 164 | int watchdog_disable (void) |
| 165 | { |
| 166 | volatile immap_t *regp = (volatile immap_t *)CFG_MBAR; |
| 167 | |
| 168 | regp->wdog_reg.wdog_wcr = 0; /* reset watchdog counter */ |
| 169 | regp->wdog_reg.wdog_wirr = 0; /* disable watchdog interrupt */ |
| 170 | regp->wdog_reg.wdog_wrrr = 0; /* disable watchdog timer */ |
| 171 | |
| 172 | puts ("WATCHDOG:disabled\n"); |
| 173 | return (0); |
| 174 | } |
| 175 | |
| 176 | int watchdog_init (void) |
| 177 | { |
| 178 | volatile immap_t *regp = (volatile immap_t *)CFG_MBAR; |
| 179 | |
| 180 | regp->wdog_reg.wdog_wirr = 0; /* disable watchdog interrupt */ |
| 181 | |
| 182 | /* set timeout and enable watchdog */ |
| 183 | regp->wdog_reg.wdog_wrrr = ((CONFIG_WATCHDOG_TIMEOUT * CFG_HZ) / (32768 * 1000)) - 1; |
| 184 | regp->wdog_reg.wdog_wcr = 0; /* reset watchdog counter */ |
| 185 | |
| 186 | puts ("WATCHDOG:enabled\n"); |
| 187 | return (0); |
| 188 | } |
| 189 | #endif /* #ifdef CONFIG_WATCHDOG */ |
| 190 | |
| 191 | #endif /* #ifdef CONFIG_M5272 */ |
| 192 | |
| 193 | |
| 194 | #ifdef CONFIG_M5282 |
| 195 | int checkcpu (void) |
| 196 | { |
Wolfgang Denk | b4b1c46 | 2006-06-10 19:27:47 +0200 | [diff] [blame] | 197 | unsigned char resetsource = MCFRESET_RSR; |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 198 | |
Wolfgang Denk | b4b1c46 | 2006-06-10 19:27:47 +0200 | [diff] [blame] | 199 | printf ("CPU: Freescale Coldfire MCF5282 (PIN: %2.2x REV: %2.2x)\n", |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 200 | MCFCCM_CIR>>8,MCFCCM_CIR & MCFCCM_CIR_PRN_MASK); |
Wolfgang Denk | b4b1c46 | 2006-06-10 19:27:47 +0200 | [diff] [blame] | 201 | printf ("Reset:%s%s%s%s%s%s%s\n", |
| 202 | (resetsource & MCFRESET_RSR_LOL) ? " Loss of Lock" : "", |
| 203 | (resetsource & MCFRESET_RSR_LOC) ? " Loss of Clock" : "", |
| 204 | (resetsource & MCFRESET_RSR_EXT) ? " External" : "", |
| 205 | (resetsource & MCFRESET_RSR_POR) ? " Power On" : "", |
| 206 | (resetsource & MCFRESET_RSR_WDR) ? " Watchdog" : "", |
| 207 | (resetsource & MCFRESET_RSR_SOFT) ? " Software" : "", |
| 208 | (resetsource & MCFRESET_RSR_LVD) ? " Low Voltage" : "" |
| 209 | ); |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 210 | return 0; |
| 211 | } |
| 212 | |
Heiko Schocher | ac1956e | 2006-04-20 08:42:42 +0200 | [diff] [blame] | 213 | int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[]) |
| 214 | { |
| 215 | MCFRESET_RCR = MCFRESET_RCR_SOFTRST; |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 216 | return 0; |
| 217 | }; |
| 218 | #endif |
stroese | 53395a2 | 2004-12-16 18:09:49 +0000 | [diff] [blame] | 219 | |
| 220 | #ifdef CONFIG_M5249 /* test-only: todo... */ |
| 221 | int checkcpu (void) |
| 222 | { |
| 223 | char buf[32]; |
| 224 | |
Marian Balakowicz | ecb6d0b | 2006-05-09 11:45:31 +0200 | [diff] [blame] | 225 | printf ("CPU: Freescale Coldfire MCF5249 at %s MHz\n", strmhz(buf, CFG_CLK)); |
stroese | 53395a2 | 2004-12-16 18:09:49 +0000 | [diff] [blame] | 226 | return 0; |
| 227 | } |
| 228 | |
| 229 | int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[]) { |
| 230 | /* enable watchdog, set timeout to 0 and wait */ |
| 231 | mbar_writeByte(MCFSIM_SYPCR, 0xc0); |
| 232 | while (1); |
| 233 | |
| 234 | /* we don't return! */ |
| 235 | return 0; |
| 236 | }; |
| 237 | #endif |