mirror of
https://github.com/Fishwaldo/u-boot.git
synced 2025-03-28 10:01:32 +00:00
stdio: Provide functions to add/remove devices using stdio_dev
The current functions for adding and removing devices require a device name. This is not convenient for driver model, which wants to store a pointer to the relevant device. Add new functions which provide this feature and adjust the old ones to call these. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
ab7cd62790
commit
d97143a67c
2 changed files with 26 additions and 8 deletions
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <common.h>
|
#include <common.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include <stdio_dev.h>
|
#include <stdio_dev.h>
|
||||||
|
@ -148,32 +149,35 @@ struct stdio_dev* stdio_clone(struct stdio_dev *dev)
|
||||||
return _dev;
|
return _dev;
|
||||||
}
|
}
|
||||||
|
|
||||||
int stdio_register (struct stdio_dev * dev)
|
int stdio_register_dev(struct stdio_dev *dev, struct stdio_dev **devp)
|
||||||
{
|
{
|
||||||
struct stdio_dev *_dev;
|
struct stdio_dev *_dev;
|
||||||
|
|
||||||
_dev = stdio_clone(dev);
|
_dev = stdio_clone(dev);
|
||||||
if(!_dev)
|
if(!_dev)
|
||||||
return -1;
|
return -ENODEV;
|
||||||
list_add_tail(&(_dev->list), &(devs.list));
|
list_add_tail(&(_dev->list), &(devs.list));
|
||||||
|
if (devp)
|
||||||
|
*devp = _dev;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int stdio_register(struct stdio_dev *dev)
|
||||||
|
{
|
||||||
|
return stdio_register_dev(dev, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
/* deregister the device "devname".
|
/* deregister the device "devname".
|
||||||
* returns 0 if success, -1 if device is assigned and 1 if devname not found
|
* returns 0 if success, -1 if device is assigned and 1 if devname not found
|
||||||
*/
|
*/
|
||||||
#ifdef CONFIG_SYS_STDIO_DEREGISTER
|
#ifdef CONFIG_SYS_STDIO_DEREGISTER
|
||||||
int stdio_deregister(const char *devname)
|
int stdio_deregister_dev(struct stdio_dev *dev)
|
||||||
{
|
{
|
||||||
int l;
|
int l;
|
||||||
struct list_head *pos;
|
struct list_head *pos;
|
||||||
struct stdio_dev *dev;
|
|
||||||
char temp_names[3][16];
|
char temp_names[3][16];
|
||||||
|
|
||||||
dev = stdio_get_by_name(devname);
|
|
||||||
|
|
||||||
if(!dev) /* device not found */
|
|
||||||
return -1;
|
|
||||||
/* get stdio devices (ListRemoveItem changes the dev list) */
|
/* get stdio devices (ListRemoveItem changes the dev list) */
|
||||||
for (l=0 ; l< MAX_FILES; l++) {
|
for (l=0 ; l< MAX_FILES; l++) {
|
||||||
if (stdio_devices[l] == dev) {
|
if (stdio_devices[l] == dev) {
|
||||||
|
@ -197,6 +201,18 @@ int stdio_deregister(const char *devname)
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int stdio_deregister(const char *devname)
|
||||||
|
{
|
||||||
|
struct stdio_dev *dev;
|
||||||
|
|
||||||
|
dev = stdio_get_by_name(devname);
|
||||||
|
|
||||||
|
if (!dev) /* device not found */
|
||||||
|
return -ENODEV;
|
||||||
|
|
||||||
|
return stdio_deregister_dev(dev);
|
||||||
|
}
|
||||||
#endif /* CONFIG_SYS_STDIO_DEREGISTER */
|
#endif /* CONFIG_SYS_STDIO_DEREGISTER */
|
||||||
|
|
||||||
int stdio_init (void)
|
int stdio_init (void)
|
||||||
|
|
|
@ -77,10 +77,12 @@ extern char *stdio_names[MAX_FILES];
|
||||||
* PROTOTYPES
|
* PROTOTYPES
|
||||||
*/
|
*/
|
||||||
int stdio_register (struct stdio_dev * dev);
|
int stdio_register (struct stdio_dev * dev);
|
||||||
|
int stdio_register_dev(struct stdio_dev *dev, struct stdio_dev **devp);
|
||||||
int stdio_init (void);
|
int stdio_init (void);
|
||||||
void stdio_print_current_devices(void);
|
void stdio_print_current_devices(void);
|
||||||
#ifdef CONFIG_SYS_STDIO_DEREGISTER
|
#ifdef CONFIG_SYS_STDIO_DEREGISTER
|
||||||
int stdio_deregister(const char *devname);
|
int stdio_deregister(const char *devname);
|
||||||
|
int stdio_deregister_dev(struct stdio_dev *dev);
|
||||||
#endif
|
#endif
|
||||||
struct list_head* stdio_get_list(void);
|
struct list_head* stdio_get_list(void);
|
||||||
struct stdio_dev* stdio_get_by_name(const char* name);
|
struct stdio_dev* stdio_get_by_name(const char* name);
|
||||||
|
|
Loading…
Add table
Reference in a new issue