5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 #ifdef CONFIG_LOGBUFFER
32 #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
37 device_t *stdio_devices[] = { NULL, NULL, NULL };
38 char *stdio_names[MAX_FILES] = { "stdin", "stdout", "stderr" };
40 #ifdef CFG_DEVICE_NULLDEV
41 void nulldev_putc(const char c)
43 /* nulldev is empty! */
46 void nulldev_puts(const char *s)
48 /* nulldev is empty! */
51 int nulldev_input(void)
53 /* nulldev is empty! */
58 /**************************************************************************
60 **************************************************************************
63 static void drv_system_init (void)
67 memset (&dev, 0, sizeof (dev));
69 strcpy (dev.name, "serial");
70 dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT | DEV_FLAGS_SYSTEM;
71 #if CONFIG_SERIAL_SOFTWARE_FIFO
72 dev.putc = serial_buffered_putc;
73 dev.puts = serial_buffered_puts;
74 dev.getc = serial_buffered_getc;
75 dev.tstc = serial_buffered_tstc;
77 dev.putc = serial_putc;
78 dev.puts = serial_puts;
79 dev.getc = serial_getc;
80 dev.tstc = serial_tstc;
83 device_register (&dev);
85 #ifdef CFG_DEVICE_NULLDEV
86 memset (&dev, 0, sizeof (dev));
88 strcpy (dev.name, "nulldev");
89 dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT | DEV_FLAGS_SYSTEM;
90 dev.putc = nulldev_putc;
91 dev.puts = nulldev_puts;
92 dev.getc = nulldev_input;
93 dev.tstc = nulldev_input;
95 device_register (&dev);
99 /**************************************************************************
101 **************************************************************************
104 int device_register (device_t * dev)
106 ListInsertItem (devlist, dev, LIST_END);
110 /* deregister the device "devname".
111 * returns 0 if success, -1 if device is assigned and 1 if devname not found
113 #ifdef CFG_DEVICE_DEREGISTER
114 int device_deregister(char *devname)
117 device_t *dev = NULL;
118 char temp_names[3][8];
121 for (i=1; i<=ListNumItems(devlist); i++) {
122 dev = ListGetPtrToItem (devlist, i);
123 if(strcmp(dev->name,devname)==0) {
128 if(dev_index<0) /* device not found */
130 /* get stdio devices (ListRemoveItem changes the dev list) */
131 for (l=0 ; l< MAX_FILES; l++) {
132 if (stdio_devices[l] == dev) {
133 /* Device is assigned -> report error */
136 memcpy (&temp_names[l][0],
137 stdio_devices[l]->name,
138 sizeof(stdio_devices[l]->name));
140 ListRemoveItem(devlist,NULL,dev_index);
141 /* reassign Device list */
142 for (i=1; i<=ListNumItems(devlist); i++) {
143 dev = ListGetPtrToItem (devlist, i);
144 for (l=0 ; l< MAX_FILES; l++) {
145 if(strcmp(dev->name,temp_names[l])==0) {
146 stdio_devices[l] = dev;
152 #endif /* CFG_DEVICE_DEREGISTER */
154 int devices_init (void)
156 DECLARE_GLOBAL_DATA_PTR;
159 ulong relocation_offset = gd->reloc_off;
161 /* relocate device name pointers */
162 for (i = 0; i < (sizeof (stdio_names) / sizeof (char *)); ++i) {
163 stdio_names[i] = (char *) (((ulong) stdio_names[i]) +
167 /* Initialize the list */
168 devlist = ListCreate (sizeof (device_t));
170 if (devlist == NULL) {
171 eputs ("Cannot initialize the list of devices!\n");
174 #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
175 i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE);
183 #ifdef CONFIG_WL_4PPM_KEYBOARD
186 #ifdef CONFIG_LOGBUFFER
191 gd-> flags |= GD_FLG_DEVINIT; /* device initialization done */
196 int devices_done (void)
198 ListDispose (devlist);