blob: 336c55126324e303445b19c3527f875df17472a2 [file] [log] [blame]
Stefan Roesea34997d2005-09-22 09:16:57 +02001/*
2 * (C) Copyright 2005
3 * Matthias Fuchs, esd gmbh germany, matthias.fuchs@esd-electronics.com
4 *
Wolfgang Denkbd8ec7e2013-10-07 13:07:26 +02005 * SPDX-License-Identifier: GPL-2.0+
Stefan Roesea34997d2005-09-22 09:16:57 +02006 */
7
8#include <common.h>
9#include <asm/processor.h>
Matthias Fuchsfaac7432009-02-20 10:19:18 +010010#include <asm/io.h>
Stefan Roesea34997d2005-09-22 09:16:57 +020011#include <command.h>
12#include <malloc.h>
13
Wolfgang Denk6405a152006-03-31 18:32:53 +020014DECLARE_GLOBAL_DATA_PTR;
15
Stefan Roesea34997d2005-09-22 09:16:57 +020016int board_early_init_f (void)
17{
Stefan Roese918010a2009-09-09 16:25:29 +020018 unsigned long CPC0_CR0Reg;
Stefan Roesea34997d2005-09-22 09:16:57 +020019
20 /*
Stefan Roese1c671a92006-01-18 20:03:15 +010021 * Setup GPIO pins
Stefan Roesea34997d2005-09-22 09:16:57 +020022 */
Stefan Roese918010a2009-09-09 16:25:29 +020023 CPC0_CR0Reg = mfdcr(CPC0_CR0);
24 mtdcr(CPC0_CR0, CPC0_CR0Reg |
Matthias Fuchsfaac7432009-02-20 10:19:18 +010025 ((CONFIG_SYS_EEPROM_WP | CONFIG_SYS_PB_LED |
26 CONFIG_SYS_SELF_RST | CONFIG_SYS_INTA_FAKE) << 5));
Stefan Roesea34997d2005-09-22 09:16:57 +020027
Wolfgang Denk67777b92006-03-06 13:03:37 +010028 /* set output pins to high */
Matthias Fuchsfaac7432009-02-20 10:19:18 +010029 out_be32((void *)GPIO0_OR, CONFIG_SYS_EEPROM_WP);
Wolfgang Denk67777b92006-03-06 13:03:37 +010030 /* setup for output (LED=off) */
Matthias Fuchsfaac7432009-02-20 10:19:18 +010031 out_be32((void *)GPIO0_TCR, CONFIG_SYS_EEPROM_WP | CONFIG_SYS_PB_LED);
Stefan Roesea34997d2005-09-22 09:16:57 +020032
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 Roese707fd362009-09-24 09:55:50 +020045 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 Roesea34997d2005-09-22 09:16:57 +020049
Stefan Roese707fd362009-09-24 09:55:50 +020050 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 Roesea34997d2005-09-22 09:16:57 +020053
54 return 0;
55}
56
Stefan Roesea34997d2005-09-22 09:16:57 +020057int misc_init_r (void)
58{
Stefan Roese918010a2009-09-09 16:25:29 +020059 unsigned long CPC0_CR0Reg;
Stefan Roesea34997d2005-09-22 09:16:57 +020060
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 Roese918010a2009-09-09 16:25:29 +020068 CPC0_CR0Reg = mfdcr(CPC0_CR0);
69 mtdcr(CPC0_CR0, CPC0_CR0Reg | 0x00001000);
Stefan Roesea34997d2005-09-22 09:16:57 +020070
71 return (0);
72}
73
74
75/*
76 * Check Board Identity:
77 */
78int checkboard (void)
79{
Wolfgang Denk7fb52662005-10-13 16:45:02 +020080 char str[64];
Wolfgang Denk76af2782010-07-24 21:55:43 +020081 int i = getenv_f("serial#", str, sizeof(str));
Stefan Roesea34997d2005-09-22 09:16:57 +020082
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-VILLARD03836942008-10-16 15:01:15 +020098#if defined(CONFIG_SYS_EEPROM_WREN)
Stefan Roesea34997d2005-09-22 09:16:57 +020099/* Input: <dev_addr> I2C address of EEPROM device to enable.
Wolfgang Denkf6a692b2005-12-04 00:40:34 +0100100 * <state> -1: deliver current state
101 * 0: disable write
Stefan Roesea34997d2005-09-22 09:16:57 +0200102 * 1: enable write
Wolfgang Denkf6a692b2005-12-04 00:40:34 +0100103 * Returns: -1: wrong device address
104 * 0: dis-/en- able done
Stefan Roesea34997d2005-09-22 09:16:57 +0200105 * 0/1: current state if <state> was -1.
106 */
107int eeprom_write_enable (unsigned dev_addr, int state) {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200108 if (CONFIG_SYS_I2C_EEPROM_ADDR != dev_addr) {
Stefan Roesea34997d2005-09-22 09:16:57 +0200109 return -1;
Wolfgang Denkf6a692b2005-12-04 00:40:34 +0100110 } else {
Stefan Roesea34997d2005-09-22 09:16:57 +0200111 switch (state) {
112 case 1:
113 /* Enable write access, clear bit GPIO_SINT2. */
Matthias Fuchsfaac7432009-02-20 10:19:18 +0100114 out_be32((void *)GPIO0_OR,
115 in_be32((void *)GPIO0_OR) & ~CONFIG_SYS_EEPROM_WP);
Stefan Roesea34997d2005-09-22 09:16:57 +0200116 state = 0;
117 break;
118 case 0:
119 /* Disable write access, set bit GPIO_SINT2. */
Matthias Fuchsfaac7432009-02-20 10:19:18 +0100120 out_be32((void *)GPIO0_OR,
121 in_be32((void *)GPIO0_OR) | CONFIG_SYS_EEPROM_WP);
Stefan Roesea34997d2005-09-22 09:16:57 +0200122 state = 0;
123 break;
124 default:
125 /* Read current status back. */
Matthias Fuchsfaac7432009-02-20 10:19:18 +0100126 state = (0 == (in_be32((void *)GPIO0_OR) &
127 CONFIG_SYS_EEPROM_WP));
Stefan Roesea34997d2005-09-22 09:16:57 +0200128 break;
129 }
130 }
131 return state;
132}
133#endif
134
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200135#if defined(CONFIG_SYS_EEPROM_WREN)
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200136int do_eep_wren (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Stefan Roesea34997d2005-09-22 09:16:57 +0200137{
138 int query = argc == 1;
139 int state = 0;
140
141 if (query) {
142 /* Query write access state. */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200143 state = eeprom_write_enable (CONFIG_SYS_I2C_EEPROM_ADDR, -1);
Stefan Roesea34997d2005-09-22 09:16:57 +0200144 if (state < 0) {
145 puts ("Query of write access state failed.\n");
Wolfgang Denkf6a692b2005-12-04 00:40:34 +0100146 } else {
Stefan Roesea34997d2005-09-22 09:16:57 +0200147 printf ("Write access for device 0x%0x is %sabled.\n",
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200148 CONFIG_SYS_I2C_EEPROM_ADDR, state ? "en" : "dis");
Stefan Roesea34997d2005-09-22 09:16:57 +0200149 state = 0;
150 }
Wolfgang Denkf6a692b2005-12-04 00:40:34 +0100151 } else {
Stefan Roesea34997d2005-09-22 09:16:57 +0200152 if ('0' == argv[1][0]) {
153 /* Disable write access. */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200154 state = eeprom_write_enable (CONFIG_SYS_I2C_EEPROM_ADDR, 0);
Wolfgang Denkf6a692b2005-12-04 00:40:34 +0100155 } else {
Stefan Roesea34997d2005-09-22 09:16:57 +0200156 /* Enable write access. */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200157 state = eeprom_write_enable (CONFIG_SYS_I2C_EEPROM_ADDR, 1);
Stefan Roesea34997d2005-09-22 09:16:57 +0200158 }
159 if (state < 0) {
160 puts ("Setup of write access state failed.\n");
161 }
162 }
163
164 return state;
165}
166
167U_BOOT_CMD(
Stefan Roese1c671a92006-01-18 20:03:15 +0100168 eepwren, 2, 0, do_eep_wren,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600169 "Enable / disable / query EEPROM write access",
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200170 ""
171);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200172#endif /* #if defined(CONFIG_SYS_EEPROM_WREN) */