]> git.ipfire.org Git - people/ms/u-boot.git/blame - common/devices.c
* Vince Husovsky, 7 Nov 2002:
[people/ms/u-boot.git] / common / devices.c
CommitLineData
91d3256c
WD
1/*
2 * (C) Copyright 2000
3 * Paolo Scaffardi, AIRVENT SAM s.p.a - RIMINI(ITALY), arsenio@tin.it
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
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.
12 *
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.
17 *
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,
21 * MA 02111-1307 USA
22 */
23
24#include <config.h>
25#include <common.h>
26#include <stdarg.h>
27#include <malloc.h>
28#include <devices.h>
7f6c2cbc
WD
29#ifdef CONFIG_LOGBUFFER
30#include <logbuff.h>
31#endif
32#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
91d3256c 33#include <i2c.h>
7f6c2cbc 34#endif
91d3256c
WD
35
36list_t devlist = 0;
37device_t *stdio_devices[] = { NULL, NULL, NULL };
38char *stdio_names[MAX_FILES] = { "stdin", "stdout", "stderr" };
39
40#ifdef CFG_DEVICE_NULLDEV
41void nulldev_putc(const char c)
42{
43 /* nulldev is empty! */
44}
45
46void nulldev_puts(const char *s)
47{
48 /* nulldev is empty! */
49}
50
51int nulldev_input(void)
52{
53 /* nulldev is empty! */
54 return 0;
55}
56#endif
57
58/**************************************************************************
59 * SYSTEM DRIVERS
60 **************************************************************************
61 */
62
63static void drv_system_init (void)
64{
65 device_t dev;
66
67 memset (&dev, 0, sizeof (dev));
68
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;
76#else
77 dev.putc = serial_putc;
78 dev.puts = serial_puts;
79 dev.getc = serial_getc;
80 dev.tstc = serial_tstc;
81#endif
82
83 device_register (&dev);
84
85#ifdef CFG_DEVICE_NULLDEV
86 memset (&dev, 0, sizeof (dev));
87
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;
94
95 device_register (&dev);
96#endif
97}
98
99/**************************************************************************
100 * DEVICES
101 **************************************************************************
102 */
103
104int device_register (device_t * dev)
105{
106 ListInsertItem (devlist, dev, LIST_END);
107 return 0;
108}
109
110/* deregister the device "devname".
111 * returns 0 if success, -1 if device is assigned and 1 if devname not found
112 */
113#ifdef CFG_DEVICE_DEREGISTER
114int device_deregister(char *devname)
115{
116 int i,l,dev_index;
117 device_t *dev = NULL;
118 char temp_names[3][8];
119
120 dev_index=-1;
121 for (i=1; i<=ListNumItems(devlist); i++) {
122 dev = ListGetPtrToItem (devlist, i);
123 if(strcmp(dev->name,devname)==0) {
124 dev_index=i;
125 break;
126 }
127 }
128 if(dev_index<0) /* device not found */
129 return 0;
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 */
134 return -1;
135 }
136 memcpy (&temp_names[l][0],
137 stdio_devices[l]->name,
138 sizeof(stdio_devices[l]->name));
139 }
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;
147 }
148 }
149 }
150 return 0;
151}
152#endif /* CFG_DEVICE_DEREGISTER */
153
154int devices_init (void)
155{
156 DECLARE_GLOBAL_DATA_PTR;
157
158 int i;
159 ulong relocation_offset = gd->reloc_off;
160
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]) +
164 relocation_offset);
165 }
166
167 /* Initialize the list */
168 devlist = ListCreate (sizeof (device_t));
169
170 if (devlist == NULL) {
171 eputs ("Cannot initialize the list of devices!\n");
172 return -1;
173 }
174#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
175 i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE);
176#endif
177#ifdef CONFIG_LCD
178 drv_lcd_init ();
179#endif
180#ifdef CONFIG_VIDEO
181 drv_video_init ();
182#endif
183#ifdef CONFIG_WL_4PPM_KEYBOARD
184 drv_wlkbd_init ();
56f94be3
WD
185#endif
186#ifdef CONFIG_LOGBUFFER
187 drv_logbuff_init ();
91d3256c
WD
188#endif
189 drv_system_init ();
190
191 gd-> flags |= GD_FLG_DEVINIT; /* device initialization done */
192
193 return (0);
194}
195
196int devices_done (void)
197{
198 ListDispose (devlist);
199
200 return 0;
201}