#include "dev.h"
+struct device devices[MAX_DEVICES];
+
struct file *dev_open(int major, int minor, unsigned int flags)
{
- return 0; /* TODO */
+ /* XXX temporary hack */
+ struct inode fakenode;
+ static struct file file;
+
+ fakenode.dev_major = major;
+ fakenode.dev_minor = minor;
+
+ if(!devices[major].fop) {
+ return 0;
+ }
+ if(devices[major].fop->open(&file, &fakenode, flags) < 0) {
+ return 0;
+ }
+ return &file;
}
#define UART_MCTL 4
#define UART_LSTAT 5
-#define DIV_9600 (115200 / 9600)
-#define DIV_38400 (115200 / 38400)
#define LCTL_8N1 0x03
#define LCTL_DLAB 0x80
#define FIFO_ENABLE_CLEAR 0x07
static int ser_ioctl(struct file *file, int ioc, long val);
static unsigned int uart_addr[2] = {UART1_BASE, UART2_BASE};
-static struct device serdev[2];
+static struct fileops fops;
static unsigned int devopen;
int ser_init(void)
{
- int i;
-
- for(i=0; i<2; i++) {
- serdev[i].fop->open = ser_open;
- serdev[i].fop->close = ser_close;
- serdev[i].fop->read = ser_read;
- serdev[i].fop->write = ser_write;
- serdev[i].fop->ioctl = ser_ioctl;
- }
+ fops.open = ser_open;
+ fops.close = ser_close;
+ fops.read = ser_read;
+ fops.write = ser_write;
+ fops.ioctl = ser_ioctl;
+
+ devices[DEV_SER].fop = &fops;
+
devopen = 0;
setuart(0, BAUD_9600);
memset(file, 0, sizeof *file);
file->type = FILE_CDEV;
file->inode = inode;
- file->dev = serdev + port;
+ file->dev = devices + DEV_SER;
devopen |= 1 << port;
return 0;