]>
git.ipfire.org Git - people/ms/u-boot.git/blob - common/devices.c
3 * Paolo Scaffardi, AIRVENT SAM s.p.a - RIMINI(ITALY), arsenio@tin.it
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,
32 device_t
*stdio_devices
[] = { NULL
, NULL
, NULL
};
33 char *stdio_names
[MAX_FILES
] = { "stdin", "stdout", "stderr" };
35 #ifdef CFG_DEVICE_NULLDEV
36 void nulldev_putc(const char c
)
38 /* nulldev is empty! */
41 void nulldev_puts(const char *s
)
43 /* nulldev is empty! */
46 int nulldev_input(void)
48 /* nulldev is empty! */
53 /**************************************************************************
55 **************************************************************************
58 static void drv_system_init (void)
62 memset (&dev
, 0, sizeof (dev
));
64 strcpy (dev
.name
, "serial");
65 dev
.flags
= DEV_FLAGS_OUTPUT
| DEV_FLAGS_INPUT
| DEV_FLAGS_SYSTEM
;
66 #if CONFIG_SERIAL_SOFTWARE_FIFO
67 dev
.putc
= serial_buffered_putc
;
68 dev
.puts
= serial_buffered_puts
;
69 dev
.getc
= serial_buffered_getc
;
70 dev
.tstc
= serial_buffered_tstc
;
72 dev
.putc
= serial_putc
;
73 dev
.puts
= serial_puts
;
74 dev
.getc
= serial_getc
;
75 dev
.tstc
= serial_tstc
;
78 device_register (&dev
);
80 #ifdef CFG_DEVICE_NULLDEV
81 memset (&dev
, 0, sizeof (dev
));
83 strcpy (dev
.name
, "nulldev");
84 dev
.flags
= DEV_FLAGS_OUTPUT
| DEV_FLAGS_INPUT
| DEV_FLAGS_SYSTEM
;
85 dev
.putc
= nulldev_putc
;
86 dev
.puts
= nulldev_puts
;
87 dev
.getc
= nulldev_input
;
88 dev
.tstc
= nulldev_input
;
90 device_register (&dev
);
94 /**************************************************************************
96 **************************************************************************
99 int device_register (device_t
* dev
)
101 ListInsertItem (devlist
, dev
, LIST_END
);
105 /* deregister the device "devname".
106 * returns 0 if success, -1 if device is assigned and 1 if devname not found
108 #ifdef CFG_DEVICE_DEREGISTER
109 int device_deregister(char *devname
)
112 device_t
*dev
= NULL
;
113 char temp_names
[3][8];
116 for (i
=1; i
<=ListNumItems(devlist
); i
++) {
117 dev
= ListGetPtrToItem (devlist
, i
);
118 if(strcmp(dev
->name
,devname
)==0) {
123 if(dev_index
<0) /* device not found */
125 /* get stdio devices (ListRemoveItem changes the dev list) */
126 for (l
=0 ; l
< MAX_FILES
; l
++) {
127 if (stdio_devices
[l
] == dev
) {
128 /* Device is assigned -> report error */
131 memcpy (&temp_names
[l
][0],
132 stdio_devices
[l
]->name
,
133 sizeof(stdio_devices
[l
]->name
));
135 ListRemoveItem(devlist
,NULL
,dev_index
);
136 /* reassign Device list */
137 for (i
=1; i
<=ListNumItems(devlist
); i
++) {
138 dev
= ListGetPtrToItem (devlist
, i
);
139 for (l
=0 ; l
< MAX_FILES
; l
++) {
140 if(strcmp(dev
->name
,temp_names
[l
])==0) {
141 stdio_devices
[l
] = dev
;
147 #endif /* CFG_DEVICE_DEREGISTER */
149 int devices_init (void)
151 DECLARE_GLOBAL_DATA_PTR
;
154 ulong relocation_offset
= gd
->reloc_off
;
156 /* relocate device name pointers */
157 for (i
= 0; i
< (sizeof (stdio_names
) / sizeof (char *)); ++i
) {
158 stdio_names
[i
] = (char *) (((ulong
) stdio_names
[i
]) +
162 /* Initialize the list */
163 devlist
= ListCreate (sizeof (device_t
));
165 if (devlist
== NULL
) {
166 eputs ("Cannot initialize the list of devices!\n");
169 #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
170 i2c_init (CFG_I2C_SPEED
, CFG_I2C_SLAVE
);
178 #ifdef CONFIG_WL_4PPM_KEYBOARD
181 #ifdef CONFIG_LOGBUFFER
186 gd
-> flags
|= GD_FLG_DEVINIT
; /* device initialization done */
191 int devices_done (void)
193 ListDispose (devlist
);