1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
|
Index: u-boot-1.3.2/board/freescale/mpc8313erdb/mpc8313erdb.c
===================================================================
--- u-boot-1.3.2.orig/board/freescale/mpc8313erdb/mpc8313erdb.c
+++ u-boot-1.3.2/board/freescale/mpc8313erdb/mpc8313erdb.c
@@ -29,6 +29,7 @@
#include <pci.h>
#include <mpc83xx.h>
#include <spi.h>
+#include <gpio.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -44,6 +45,48 @@ int board_early_init_f(void)
return 0;
}
+int misc_init_f(void)
+{
+ uchar value;
+ uchar i;
+
+#ifdef PRE_INIT_GPIO
+ value=PRE_INIT_GPIO;
+
+ for(i=0;i<MAX_GPIO_OUT;i++)
+ {
+ if(value&(1<<i))
+ {
+ gpio_set(i);
+ }
+ else
+ {
+ gpio_clear(i);
+ }
+ }
+ udelay(1000);
+#endif
+
+
+#ifdef INIT_GPIO
+ value=INIT_GPIO;
+ for(i=0;i<MAX_GPIO_OUT;i++)
+ {
+ if(value&(1<<i))
+ {
+ gpio_set(i);
+ }
+ else
+ {
+ gpio_clear(i);
+ }
+ }
+ puts("GPIO: ready\n");
+#endif
+
+ return 0;
+}
+
int checkboard(void)
{
puts("Board: Freescale MPC8313ERDB\n");
@@ -109,7 +152,42 @@ void ft_board_setup(void *blob, bd_t *bd
}
#endif
+#ifdef CONFIG_CMD_GPIO
+void gpio_set(unsigned char ucGpio)
+{
+ unsigned long ulMask=0;
+ volatile gpio83xx_t *iopd = &((immap_t *)CFG_IMMR)->gpio[0];
+ if(ucGpio<32)
+ {
+ ulMask=1<<(31-ucGpio);
+ iopd->dir |= ulMask;
+ iopd->dat |= ulMask;
+ }
+}
+
+void gpio_clear(unsigned char ucGpio)
+{
+ unsigned long ulMask=0;
+ volatile gpio83xx_t *iopd = &((immap_t *)CFG_IMMR)->gpio[0];
+ if(ucGpio<32)
+ {
+ ulMask=1<<(31-ucGpio);
+ iopd->dir |= ulMask;
+ iopd->dat &= ~ulMask;
+ }
+}
+char gpio_get(unsigned char ucGpio)
+{
+ unsigned long ulMask=0;
+ volatile gpio83xx_t *iopd = &((immap_t *)CFG_IMMR)->gpio[0];
+ if(ucGpio<32)
+ {
+ ulMask=1<<(31-ucGpio);
+ }
+ return (iopd->dat& ulMask)? 1:0;
+}
+#endif
/*
* The following are used to control the SPI chip selects for the SPI command.
*/
Index: u-boot-1.3.2/common/cmd_gpio.c
===================================================================
--- /dev/null
+++ u-boot-1.3.2/common/cmd_gpio.c
@@ -0,0 +1,76 @@
+/*
+ * (C) Copyright 2001
+ * Alexandre Coffignal, CenoSYS, alexandre.coffignal@cenosys.com
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+
+#include <common.h>
+#include <config.h>
+#include <command.h>
+#include <gpio.h>
+
+
+int do_gpio (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
+{
+ unsigned char ucGpio;
+
+ if (argc < 3)
+ goto usage;
+
+ ucGpio = simple_strtoul (argv[2], NULL, 10);
+
+ if (!strncmp(argv[1], "set", 3))
+ {
+ gpio_set(ucGpio);
+ }
+ else
+ if (!strncmp(argv[1], "clear", 5))
+ {
+ gpio_clear(ucGpio);
+ }
+ else
+ if (!strncmp(argv[1], "get", 3))
+ {
+ printf("%s %s %d = %d\n",argv[0],argv[1],ucGpio, gpio_get(ucGpio));
+ return 0;
+ }
+ else
+ goto usage;
+
+ printf("%s %s %d\n",argv[0],argv[1],ucGpio);
+
+ return 0;
+
+usage :
+ printf ("Usage:\n%s\n", cmdtp->usage);
+ return 1;
+} /* do_gpio() */
+
+/***************************************************/
+
+U_BOOT_CMD(
+ gpio, 3, 1, do_gpio,
+ "gpio - General Purpose Input/Output\n",
+ " - Set or clear General Purpose Output.\n"
+ "<set/clear/get> - Set or clear General Purpose Output.\n"
+ "<gpio> - number of gpio to be set/clear/get \n"
+);
+
Index: u-boot-1.3.2/common/Makefile
===================================================================
--- u-boot-1.3.2.orig/common/Makefile
+++ u-boot-1.3.2/common/Makefile
@@ -50,6 +50,7 @@ endif
COBJS-$(CONFIG_CMD_DISPLAY) += cmd_display.o
COBJS-$(CONFIG_CMD_DOC) += cmd_doc.o
COBJS-$(CONFIG_CMD_DTT) += cmd_dtt.o
+COBJS-$(CONFIG_CMD_GPIO) += cmd_gpio.o
COBJS-y += cmd_eeprom.o
COBJS-$(CONFIG_CMD_ELF) += cmd_elf.o
COBJS-$(CONFIG_CMD_EXT2) += cmd_ext2.o
Index: u-boot-1.3.2/include/configs/MPC8313ERDB.h
===================================================================
--- u-boot-1.3.2.orig/include/configs/MPC8313ERDB.h
+++ u-boot-1.3.2/include/configs/MPC8313ERDB.h
@@ -49,6 +49,7 @@
#define CONFIG_SYS_CLK_FREQ CONFIG_83XX_CLKIN
#define CONFIG_BOARD_EARLY_INIT_F /* call board_pre_init */
+#define CONFIG_MISC_INIT_F
#define CFG_IMMR 0xE0000000
@@ -370,6 +371,7 @@
#define CONFIG_CMD_NAND
#define CONFIG_CMD_JFFS2
#define CONFIG_CMD_SPI
+#define CONFIG_CMD_GPIO
#if defined(CFG_RAMBOOT)
#undef CONFIG_CMD_ENV
@@ -392,6 +394,11 @@
#define CONFIG_HARD_SPI /* SPI with hardware support */
#undef CONFIG_SOFT_SPI /* SPI bit-banged */
+/* GPIO */
+#define PRE_INIT_GPIO 0x28
+#define INIT_GPIO 0x08
+#define MAX_GPIO_OUT 7
+
/*
* Miscellaneous configurable options
*/
@@ -457,7 +464,7 @@
/* System IO Config */
#define CFG_SICRH (SICRH_TSOBI1 | SICRH_TSOBI2) /* RGMII */
-#define CFG_SICRL SICRL_USBDR /* Enable Internal USB Phy */
+#define CFG_SICRL (SICRL_USBDR |SICRL_LBC) /* Enable Internal USB Phy */
#define CFG_HID0_INIT 0x000000000
#define CFG_HID0_FINAL (HID0_ENABLE_MACHINE_CHECK | \
Index: u-boot-1.3.2/include/gpio.h
===================================================================
--- /dev/null
+++ u-boot-1.3.2/include/gpio.h
@@ -0,0 +1,9 @@
+#ifndef __GPIO_H__
+#define __GPIO_H__
+
+extern void gpio_set(unsigned char ucGpio);
+extern void gpio_clear(unsigned char ucGpio);
+extern char gpio_get(unsigned char ucGpio);
+
+#endif /* __GPIO_H__ */
+
|