Stefan Roese | a34997d | 2005-09-22 09:16:57 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2005 |
| 3 | * Matthias Fuchs, esd gmbh germany, matthias.fuchs@esd-electronics.com |
| 4 | * |
Wolfgang Denk | bd8ec7e | 2013-10-07 13:07:26 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Stefan Roese | a34997d | 2005-09-22 09:16:57 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <asm/processor.h> |
Matthias Fuchs | faac743 | 2009-02-20 10:19:18 +0100 | [diff] [blame] | 10 | #include <asm/io.h> |
Stefan Roese | a34997d | 2005-09-22 09:16:57 +0200 | [diff] [blame] | 11 | #include <command.h> |
| 12 | #include <malloc.h> |
| 13 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 14 | DECLARE_GLOBAL_DATA_PTR; |
| 15 | |
Stefan Roese | a34997d | 2005-09-22 09:16:57 +0200 | [diff] [blame] | 16 | int board_early_init_f (void) |
| 17 | { |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 18 | unsigned long CPC0_CR0Reg; |
Stefan Roese | a34997d | 2005-09-22 09:16:57 +0200 | [diff] [blame] | 19 | |
| 20 | /* |
Stefan Roese | 1c671a9 | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 21 | * Setup GPIO pins |
Stefan Roese | a34997d | 2005-09-22 09:16:57 +0200 | [diff] [blame] | 22 | */ |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 23 | CPC0_CR0Reg = mfdcr(CPC0_CR0); |
| 24 | mtdcr(CPC0_CR0, CPC0_CR0Reg | |
Matthias Fuchs | faac743 | 2009-02-20 10:19:18 +0100 | [diff] [blame] | 25 | ((CONFIG_SYS_EEPROM_WP | CONFIG_SYS_PB_LED | |
| 26 | CONFIG_SYS_SELF_RST | CONFIG_SYS_INTA_FAKE) << 5)); |
Stefan Roese | a34997d | 2005-09-22 09:16:57 +0200 | [diff] [blame] | 27 | |
Wolfgang Denk | 67777b9 | 2006-03-06 13:03:37 +0100 | [diff] [blame] | 28 | /* set output pins to high */ |
Matthias Fuchs | faac743 | 2009-02-20 10:19:18 +0100 | [diff] [blame] | 29 | out_be32((void *)GPIO0_OR, CONFIG_SYS_EEPROM_WP); |
Wolfgang Denk | 67777b9 | 2006-03-06 13:03:37 +0100 | [diff] [blame] | 30 | /* setup for output (LED=off) */ |
Matthias Fuchs | faac743 | 2009-02-20 10:19:18 +0100 | [diff] [blame] | 31 | out_be32((void *)GPIO0_TCR, CONFIG_SYS_EEPROM_WP | CONFIG_SYS_PB_LED); |
Stefan Roese | a34997d | 2005-09-22 09:16:57 +0200 | [diff] [blame] | 32 | |
| 33 | /* |
| 34 | * IRQ 0-15 405GP internally generated; active high; level sensitive |
| 35 | * IRQ 16 405GP internally generated; active low; level sensitive |
| 36 | * IRQ 17-24 RESERVED |
| 37 | * IRQ 25 (EXT IRQ 0) PB0; active low; level sensitive |
| 38 | * IRQ 26 (EXT IRQ 1) PB1; active low; level sensitive |
| 39 | * IRQ 27 (EXT IRQ 2) PCI SLOT 0; active low; level sensitive |
| 40 | * IRQ 28 (EXT IRQ 3) PCI SLOT 1; active low; level sensitive |
| 41 | * IRQ 29 (EXT IRQ 4) PCI SLOT 2; active low; level sensitive |
| 42 | * IRQ 30 (EXT IRQ 5) PCI SLOT 3; active low; level sensitive |
| 43 | * IRQ 31 (EXT IRQ 6) unused |
| 44 | */ |
Stefan Roese | 707fd36 | 2009-09-24 09:55:50 +0200 | [diff] [blame] | 45 | mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */ |
| 46 | mtdcr(UIC0ER, 0x00000000); /* disable all ints */ |
| 47 | mtdcr(UIC0CR, 0x00000000); /* set all to be non-critical*/ |
| 48 | mtdcr(UIC0PR, 0xFFFFFF81); /* set int polarities */ |
Stefan Roese | a34997d | 2005-09-22 09:16:57 +0200 | [diff] [blame] | 49 | |
Stefan Roese | 707fd36 | 2009-09-24 09:55:50 +0200 | [diff] [blame] | 50 | mtdcr(UIC0TR, 0x10000000); /* set int trigger levels */ |
| 51 | mtdcr(UIC0VCR, 0x00000001); /* set vect base=0,INT0 highest priority*/ |
| 52 | mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */ |
Stefan Roese | a34997d | 2005-09-22 09:16:57 +0200 | [diff] [blame] | 53 | |
| 54 | return 0; |
| 55 | } |
| 56 | |
Stefan Roese | a34997d | 2005-09-22 09:16:57 +0200 | [diff] [blame] | 57 | int misc_init_r (void) |
| 58 | { |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 59 | unsigned long CPC0_CR0Reg; |
Stefan Roese | a34997d | 2005-09-22 09:16:57 +0200 | [diff] [blame] | 60 | |
| 61 | /* adjust flash start and offset */ |
| 62 | gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize; |
| 63 | gd->bd->bi_flashoffset = 0; |
| 64 | |
| 65 | /* |
| 66 | * Select cts (and not dsr) on uart1 |
| 67 | */ |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 68 | CPC0_CR0Reg = mfdcr(CPC0_CR0); |
| 69 | mtdcr(CPC0_CR0, CPC0_CR0Reg | 0x00001000); |
Stefan Roese | a34997d | 2005-09-22 09:16:57 +0200 | [diff] [blame] | 70 | |
| 71 | return (0); |
| 72 | } |
| 73 | |
| 74 | |
| 75 | /* |
| 76 | * Check Board Identity: |
| 77 | */ |
| 78 | int checkboard (void) |
| 79 | { |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 80 | char str[64]; |
Wolfgang Denk | 76af278 | 2010-07-24 21:55:43 +0200 | [diff] [blame] | 81 | int i = getenv_f("serial#", str, sizeof(str)); |
Stefan Roese | a34997d | 2005-09-22 09:16:57 +0200 | [diff] [blame] | 82 | |
| 83 | puts ("Board: "); |
| 84 | |
| 85 | if (i == -1) { |
| 86 | puts ("### No HW ID - assuming CPCI2DP"); |
| 87 | } else { |
| 88 | puts(str); |
| 89 | } |
| 90 | |
| 91 | printf(" (Ver 1.0)"); |
| 92 | |
| 93 | putc ('\n'); |
| 94 | |
| 95 | return 0; |
| 96 | } |
| 97 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 98 | #if defined(CONFIG_SYS_EEPROM_WREN) |
Stefan Roese | a34997d | 2005-09-22 09:16:57 +0200 | [diff] [blame] | 99 | /* Input: <dev_addr> I2C address of EEPROM device to enable. |
Wolfgang Denk | f6a692b | 2005-12-04 00:40:34 +0100 | [diff] [blame] | 100 | * <state> -1: deliver current state |
| 101 | * 0: disable write |
Stefan Roese | a34997d | 2005-09-22 09:16:57 +0200 | [diff] [blame] | 102 | * 1: enable write |
Wolfgang Denk | f6a692b | 2005-12-04 00:40:34 +0100 | [diff] [blame] | 103 | * Returns: -1: wrong device address |
| 104 | * 0: dis-/en- able done |
Stefan Roese | a34997d | 2005-09-22 09:16:57 +0200 | [diff] [blame] | 105 | * 0/1: current state if <state> was -1. |
| 106 | */ |
| 107 | int eeprom_write_enable (unsigned dev_addr, int state) { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 108 | if (CONFIG_SYS_I2C_EEPROM_ADDR != dev_addr) { |
Stefan Roese | a34997d | 2005-09-22 09:16:57 +0200 | [diff] [blame] | 109 | return -1; |
Wolfgang Denk | f6a692b | 2005-12-04 00:40:34 +0100 | [diff] [blame] | 110 | } else { |
Stefan Roese | a34997d | 2005-09-22 09:16:57 +0200 | [diff] [blame] | 111 | switch (state) { |
| 112 | case 1: |
| 113 | /* Enable write access, clear bit GPIO_SINT2. */ |
Matthias Fuchs | faac743 | 2009-02-20 10:19:18 +0100 | [diff] [blame] | 114 | out_be32((void *)GPIO0_OR, |
| 115 | in_be32((void *)GPIO0_OR) & ~CONFIG_SYS_EEPROM_WP); |
Stefan Roese | a34997d | 2005-09-22 09:16:57 +0200 | [diff] [blame] | 116 | state = 0; |
| 117 | break; |
| 118 | case 0: |
| 119 | /* Disable write access, set bit GPIO_SINT2. */ |
Matthias Fuchs | faac743 | 2009-02-20 10:19:18 +0100 | [diff] [blame] | 120 | out_be32((void *)GPIO0_OR, |
| 121 | in_be32((void *)GPIO0_OR) | CONFIG_SYS_EEPROM_WP); |
Stefan Roese | a34997d | 2005-09-22 09:16:57 +0200 | [diff] [blame] | 122 | state = 0; |
| 123 | break; |
| 124 | default: |
| 125 | /* Read current status back. */ |
Matthias Fuchs | faac743 | 2009-02-20 10:19:18 +0100 | [diff] [blame] | 126 | state = (0 == (in_be32((void *)GPIO0_OR) & |
| 127 | CONFIG_SYS_EEPROM_WP)); |
Stefan Roese | a34997d | 2005-09-22 09:16:57 +0200 | [diff] [blame] | 128 | break; |
| 129 | } |
| 130 | } |
| 131 | return state; |
| 132 | } |
| 133 | #endif |
| 134 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 135 | #if defined(CONFIG_SYS_EEPROM_WREN) |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 136 | int do_eep_wren (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
Stefan Roese | a34997d | 2005-09-22 09:16:57 +0200 | [diff] [blame] | 137 | { |
| 138 | int query = argc == 1; |
| 139 | int state = 0; |
| 140 | |
| 141 | if (query) { |
| 142 | /* Query write access state. */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 143 | state = eeprom_write_enable (CONFIG_SYS_I2C_EEPROM_ADDR, -1); |
Stefan Roese | a34997d | 2005-09-22 09:16:57 +0200 | [diff] [blame] | 144 | if (state < 0) { |
| 145 | puts ("Query of write access state failed.\n"); |
Wolfgang Denk | f6a692b | 2005-12-04 00:40:34 +0100 | [diff] [blame] | 146 | } else { |
Stefan Roese | a34997d | 2005-09-22 09:16:57 +0200 | [diff] [blame] | 147 | printf ("Write access for device 0x%0x is %sabled.\n", |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 148 | CONFIG_SYS_I2C_EEPROM_ADDR, state ? "en" : "dis"); |
Stefan Roese | a34997d | 2005-09-22 09:16:57 +0200 | [diff] [blame] | 149 | state = 0; |
| 150 | } |
Wolfgang Denk | f6a692b | 2005-12-04 00:40:34 +0100 | [diff] [blame] | 151 | } else { |
Stefan Roese | a34997d | 2005-09-22 09:16:57 +0200 | [diff] [blame] | 152 | if ('0' == argv[1][0]) { |
| 153 | /* Disable write access. */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 154 | state = eeprom_write_enable (CONFIG_SYS_I2C_EEPROM_ADDR, 0); |
Wolfgang Denk | f6a692b | 2005-12-04 00:40:34 +0100 | [diff] [blame] | 155 | } else { |
Stefan Roese | a34997d | 2005-09-22 09:16:57 +0200 | [diff] [blame] | 156 | /* Enable write access. */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 157 | state = eeprom_write_enable (CONFIG_SYS_I2C_EEPROM_ADDR, 1); |
Stefan Roese | a34997d | 2005-09-22 09:16:57 +0200 | [diff] [blame] | 158 | } |
| 159 | if (state < 0) { |
| 160 | puts ("Setup of write access state failed.\n"); |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | return state; |
| 165 | } |
| 166 | |
| 167 | U_BOOT_CMD( |
Stefan Roese | 1c671a9 | 2006-01-18 20:03:15 +0100 | [diff] [blame] | 168 | eepwren, 2, 0, do_eep_wren, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 169 | "Enable / disable / query EEPROM write access", |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 170 | "" |
| 171 | ); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 172 | #endif /* #if defined(CONFIG_SYS_EEPROM_WREN) */ |