9
0
Fork 0
barebox/include/driver.h

119 lines
3.3 KiB
C
Raw Normal View History

2007-07-05 16:01:23 +00:00
#ifndef DRIVER_H
#define DRIVER_H
2007-07-05 16:01:34 +00:00
#include <net.h>
2007-07-05 16:01:23 +00:00
#define MAX_DRIVER_NAME 16
#define MAP_READ 1
#define MAP_WRITE 2
2007-07-05 16:01:34 +00:00
#define PARAM_TYPE_STRING 1
#define PARAM_TYPE_ULONG 2
#define PARAM_TYPE_IPADDR 3
#define PARAM_FLAG_RO (1 << 0)
typedef union {
char *val_str;
ulong val_ulong;
IPaddr_t val_ip;
} value_t;
struct param_d {
2007-07-05 16:01:34 +00:00
struct param_d* (*get)(struct device_d *, struct param_d *param);
int (*set)(struct device_d *, struct param_d *param, value_t val);
ulong type;
ulong flags;
char *name;
ulong cookie;
struct param_d *next;
2007-07-05 16:01:34 +00:00
value_t value;
};
2007-07-05 16:01:23 +00:00
2007-07-05 16:01:24 +00:00
#define DEVICE_TYPE_UNKNOWN 0
#define DEVICE_TYPE_ETHER 1
#define DEVICE_TYPE_STDIO 2
#define DEVICE_TYPE_DRAM 3
#define MAX_DEVICE_TYPE 3
2007-07-05 16:01:24 +00:00
2007-07-05 16:01:23 +00:00
struct device_d {
char name[MAX_DRIVER_NAME];
2007-07-05 16:01:24 +00:00
char id[MAX_DRIVER_NAME];
2007-07-05 16:01:23 +00:00
unsigned long size;
/* For devices which are directly mapped into memory, i.e. NOR Flash or
* SDRAM.
*/
unsigned long map_base;
void *platform_data;
2007-07-05 16:01:24 +00:00
void *priv;
2007-07-05 16:01:23 +00:00
/* The driver for this device */
struct driver_d *driver;
struct device_d *next;
2007-07-05 16:01:24 +00:00
unsigned long type;
struct param_d *param;
2007-07-05 16:01:23 +00:00
};
struct driver_d {
char name[MAX_DRIVER_NAME];
struct driver_d *next;
int (*probe) (struct device_d *);
2007-07-05 16:01:24 +00:00
ssize_t (*read) (struct device_d*, void* buf, size_t count, ulong offset, ulong flags);
ssize_t (*write) (struct device_d*, void* buf, size_t count, ulong offset, ulong flags);
ssize_t (*erase) (struct device_d*, size_t count, unsigned long offset);
void (*info) (struct device_d *);
void (*shortinfo) (struct device_d *);
2007-07-05 16:01:24 +00:00
2007-07-05 16:01:34 +00:00
int (*get) (struct device_d*, struct param_d *);
int (*set) (struct device_d*, struct param_d *, value_t val);
2007-07-05 16:01:24 +00:00
unsigned long type;
void *type_data;
2007-07-05 16:01:23 +00:00
};
2007-07-05 16:01:24 +00:00
#define RW_SIZE(x) (x)
#define RW_SIZE_MASK 0x7
2007-07-05 16:01:23 +00:00
int register_driver(struct driver_d *);
int register_device(struct device_d *);
void unregister_device(struct device_d *);
struct device_d *device_from_spec_str(const char *str, char **endp);
struct device_d *get_device_by_name(char *name);
struct device_d *get_device_by_type(ulong type, struct device_d *last);
2007-07-05 16:01:24 +00:00
ssize_t read(struct device_d *dev, void *buf, size_t count, ulong offset, ulong flags);
ssize_t write(struct device_d *dev, void *buf, size_t count, ulong offset, ulong flags);
ssize_t erase(struct device_d *dev, size_t count, unsigned long offset);
2007-07-05 16:01:34 +00:00
struct param_d* dev_get_param(struct device_d *dev, char *name);
int dev_set_param(struct device_d *dev, char *name, value_t val);
struct param_d *get_param_by_name(struct device_d *dev, char *name);
void print_param(struct param_d *param);
IPaddr_t dev_get_param_ip(struct device_d *dev, char *name);
int dev_set_param_ip(struct device_d *dev, char *name, IPaddr_t ip);
int dev_add_parameter(struct device_d *dev, struct param_d *par);
2007-07-05 16:01:24 +00:00
ssize_t mem_read(struct device_d *dev, void *buf, size_t count, ulong offset, ulong flags);
ssize_t mem_write(struct device_d *dev, void *buf, size_t count, ulong offset, ulong flags);
2007-07-05 16:01:24 +00:00
int register_device_type_handler(int(*handle)(struct device_d *), ulong device_type);
//void unregister_device_type_handler(struct device_d *);
int dummy_probe(struct device_d *);
int global_add_parameter(struct param_d *param);
2007-07-05 16:01:23 +00:00
#endif /* DRIVER_H */